1use crate::{Note, Song};
7
8pub fn echo(song: &Song, delay: f64, decay: f32) -> Song {
9 let mut echoed_notes = Vec::new();
10
11 for note in &song.notes {
12 echoed_notes.push(note.clone());
13
14 if note.dur > delay {
16 let echo_note = Note {
17 vol: note.vol * decay,
18 dur: note.dur - delay,
19 ..*note
20 };
21 echoed_notes.push(echo_note);
22 }
23 }
24
25 Song::new(echoed_notes, song.bpm)
26}
27
28pub fn reverse(song: &Song) -> Song {
29 let mut reversed_notes = song.notes.clone();
30 reversed_notes.reverse();
31 Song::new(reversed_notes, song.bpm)
32}
33
34pub fn speed_up(song: &Song, factor: f64) -> Song {
35 let speed_notes: Vec<Note> = song
36 .notes
37 .iter()
38 .map(|note| Note {
39 dur: note.dur / factor,
40 ..*note
41 })
42 .collect();
43
44 Song::new(speed_notes, song.bpm)
45}