-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
song_spec.es6
94 lines (80 loc) · 2.49 KB
/
song_spec.es6
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import "jasmine_boot"
import {SongNoteList, SongNote} from "st/song_note_list"
import {AutoChords} from "st/auto_chords"
let stripIds = notes =>
notes.map(n => Object.assign({}, n, {id: undefined}))
let matchNotes = (have, expected) =>
expect(stripIds(have)).toEqual(stripIds(expected))
describe("song", function() {
it("creates an empty song notes", function() {
let song = new SongNoteList()
expect(song.getStopInBeats()).toEqual(0)
})
it("gets duration from song with notes", function() {
let song = new SongNoteList()
song.push(new SongNote("C5", 2, 1))
song.push(new SongNote("D5", 0, 1))
expect(song.getStartInBeats()).toEqual(0)
expect(song.getStopInBeats()).toEqual(3)
})
it("gets notes in time range", function() {
let song = SongNoteList.newSong([
["C5", 0, 1],
["D5", 1, 1],
["E5", 3, 1],
["D5", 5, 1],
["F5", 1, 5], // overlap (1 - 6)
["F5", 1, 3], // overlap start (1 - 4)
["F5", 4, 2], // overlap end (4 - 6)
])
let range = song.notesInRange(3,5)
matchNotes(range, [
new SongNote("E5", 3, 1),
new SongNote("F5", 1, 5),
new SongNote("F5", 1, 3),
new SongNote("F5", 4, 2),
])
})
})
describe("autochords", function() {
describe("coerceChord", function() {
[
[undefined, () => AutoChords.coerceChord("hello world")],
[["G", "M"], () => AutoChords.coerceChord("g")],
[["A", "M"], () => AutoChords.coerceChord("aM")],
[["B", "m"], () => AutoChords.coerceChord("bm")],
[["Fb", "M"], () => AutoChords.coerceChord("fbM")],
[["G#", "m"], () => AutoChords.coerceChord("g#m")],
[["Cb", "dimM7"], () => AutoChords.coerceChord("cbdimM7")],
].map(function([expected, fn]) {
let name = (expected && expected.join) ? expected.join("") : "non-chord"
it(`coerces chord ${name}`, function() {
expect(fn()).toEqual(expected)
})
})
})
it("finds chord blocks for basic song", function() {
let song = SongNoteList.newSong([
["C5", 0, 1],
["D5", 1, 1],
["E5", 3, 1],
["D5", 5, 1]
])
song.metadata = {
beatsPerMeasure: 2,
}
song.autoChords = [
[0, "g"],
[1, "d"],
[2, "c"],
[4, "d"]
]
let chordBlocks = new AutoChords(song).findChordBlocks()
expect(chordBlocks).toEqual([
{chord: "g", start: 0, stop: 1},
{chord: "d", start: 1, stop: 2},
{chord: "c", start: 2, stop: 4},
{chord: "d", start: 4, stop: 6},
])
})
})