/
SongMapper.elm
45 lines (38 loc) · 1.06 KB
/
SongMapper.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module SongMapper where
import Models exposing (Planet)
import Notes
songToPlanets : Notes.Song -> List Planet
songToPlanets song =
let
speed = song.speed
delayBetweenChords = song.delayBetweenChords
untimedChords = (toPlanetsFromChords speed) song
timedChords = List.indexedMap (delayChord delayBetweenChords) untimedChords
in
List.concat timedChords
toPlanetsFromChords : Float -> Notes.Song -> List (List Planet)
toPlanetsFromChords speed song =
List.map (toNotes speed) (List.reverse song.chords)
toNotes : Float -> Notes.Chord -> List Planet
toNotes speed chord =
List.map (toPlanet2 speed) chord
toPlanet2 : Float -> Float -> Planet
toPlanet2 speed note =
let
toPlanet (note) = {
radius = note,
speed = speed,
ticksSinceHit = 100,
angle = 0,
instrument = "bass"
}
in
toPlanet note
delayChord : Float -> Int -> List Planet -> List Planet
delayChord delayBetweenChords index list =
let
delay (note) = {
note | angle = (toFloat index) * delayBetweenChords
}
in
List.map delay list