midi_lyrics 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/lib/midi_lyrics.rb +9 -0
- data/lib/midi_lyrics/version.rb +1 -1
- data/spec/midi_lyrics_spec.rb +61 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25ee2f178ba21c7e16bb86db9680b65d30f76324
|
4
|
+
data.tar.gz: 979f7dfe084d8db529566e5bef20a30cf7ff68d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40915a6ffdc72a025f4b1b86947b619c3a2f8dc44e93b0e928e3851e59e54d4c383e150625513985829571f6114cbe872d405678c4c86c623adcf67e993634cd
|
7
|
+
data.tar.gz: 023708cf54f7a8efd256bdd5f892b92cf3e68f409e076dd598c18e5e31938323a24353f1cfe229ea8ee6ecec89bab078567283838a20da3b615becf4fb984e80
|
data/README.md
CHANGED
@@ -20,7 +20,13 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
MidiLyrics::Parser.new("test.mid").extract
|
23
|
+
>> MidiLyrics::Parser.new("test.mid").extract
|
24
|
+
=> [
|
25
|
+
{ text: "Test", start: 0, start2: 0.0, duration: 0.417 },
|
26
|
+
{ text: "ing ", start: 0.5, start2: 0.0, duration: 0.417 },
|
27
|
+
{ text: "\r", start: 0.917, start2: 0.0, duration: 0 },
|
28
|
+
{ text: "\n", start: 0.917, start2: 0.0, duration: 0 }
|
29
|
+
]
|
24
30
|
|
25
31
|
## Contributing
|
26
32
|
|
data/lib/midi_lyrics.rb
CHANGED
@@ -32,6 +32,15 @@ module MidiLyrics
|
|
32
32
|
self.duration_in_pulses == another.duration_in_pulses && self.text == another.text
|
33
33
|
end
|
34
34
|
|
35
|
+
def as_json
|
36
|
+
{
|
37
|
+
text: text,
|
38
|
+
start: start,
|
39
|
+
start2: start2,
|
40
|
+
duration: duration
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
35
44
|
private
|
36
45
|
def format_time(time)
|
37
46
|
@sequence.pulses_to_seconds(time.to_f).round(3)
|
data/lib/midi_lyrics/version.rb
CHANGED
data/spec/midi_lyrics_spec.rb
CHANGED
@@ -8,11 +8,47 @@ describe MidiLyrics do
|
|
8
8
|
expect(MidiLyrics::Parser.new("spec/fixtures/one_note_one_syllable.mid").extract).to be_kind_of(Array)
|
9
9
|
end
|
10
10
|
|
11
|
-
context "
|
11
|
+
context "accessing LyricSyllable attributes" do
|
12
|
+
let(:lyrics) { MidiLyrics::Parser.new("spec/fixtures/repeating_lyrics.mid").extract }
|
13
|
+
|
14
|
+
it "has text method" do
|
15
|
+
expect(lyrics[1].text).to eq("ing ")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has start_in_pulses method" do
|
19
|
+
expect(lyrics[1].start_in_pulses).to eq(192)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has start method" do
|
23
|
+
expect(lyrics[1].start).to eq(0.5)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has start2_in_pulses method" do
|
27
|
+
expect(lyrics[1].start2_in_pulses).to eq(1152)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has start2 method" do
|
31
|
+
expect(lyrics[1].start2).to eq(3.0)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has duration_in_pulses method" do
|
35
|
+
expect(lyrics[1].duration_in_pulses).to eq(160)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has duration method" do
|
39
|
+
expect(lyrics[1].duration).to eq(QUARTER_NOTE_DURATION)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has as_json method" do
|
43
|
+
expect(lyrics[1].as_json).to eq({text: "ing ", start: 0.5, start2: 3.0, duration: 0.417})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "file parsing" do
|
12
48
|
it "parses one_note_one_syllable.mid correctly" do
|
13
|
-
|
14
|
-
|
15
|
-
|
49
|
+
expect(
|
50
|
+
MidiLyrics::Parser.new("spec/fixtures/one_note_one_syllable.mid").extract.collect(&:as_json)
|
51
|
+
).to eq([
|
16
52
|
{ text: "Test ", start: 0.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
17
53
|
{ text: "\r", start: QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
|
18
54
|
{ text: "\n", start: QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
|
@@ -20,9 +56,9 @@ describe MidiLyrics do
|
|
20
56
|
end
|
21
57
|
|
22
58
|
it "parses two_notes_one_syllable.mid correctly" do
|
23
|
-
|
24
|
-
|
25
|
-
|
59
|
+
expect(
|
60
|
+
MidiLyrics::Parser.new("spec/fixtures/two_notes_one_syllable.mid").extract.collect(&:as_json)
|
61
|
+
).to eq([
|
26
62
|
{ text: "Test ", start: 0, start2: 0.0, duration: 0.5 + QUARTER_NOTE_DURATION },
|
27
63
|
{ text: "\r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0 },
|
28
64
|
{ text: "\n", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0 }
|
@@ -30,9 +66,9 @@ describe MidiLyrics do
|
|
30
66
|
end
|
31
67
|
|
32
68
|
it "parses two_notes_two_syllables.mid correctly" do
|
33
|
-
|
34
|
-
|
35
|
-
|
69
|
+
expect(
|
70
|
+
MidiLyrics::Parser.new("spec/fixtures/two_notes_two_syllables.mid").extract.collect(&:as_json)
|
71
|
+
).to eq([
|
36
72
|
{ text: "Test", start: 0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
37
73
|
{ text: "ing ", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
38
74
|
{ text: "\r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0 },
|
@@ -41,9 +77,9 @@ describe MidiLyrics do
|
|
41
77
|
end
|
42
78
|
|
43
79
|
it "parses spaces_and_returns.mid correctly" do
|
44
|
-
|
45
|
-
|
46
|
-
|
80
|
+
expect(
|
81
|
+
MidiLyrics::Parser.new("spec/fixtures/spaces_and_returns.mid").extract.collect(&:as_json)
|
82
|
+
).to eq([
|
47
83
|
{ text: "Test", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
48
84
|
{ text: "ing ", start: 1, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
49
85
|
{ text: "\r", start: 1 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0 },
|
@@ -56,9 +92,9 @@ describe MidiLyrics do
|
|
56
92
|
end
|
57
93
|
|
58
94
|
it "parses repeating_lyrics.mid correctly repeating" do
|
59
|
-
|
60
|
-
|
61
|
-
|
95
|
+
expect(
|
96
|
+
MidiLyrics::Parser.new("spec/fixtures/repeating_lyrics.mid", repeating: true).extract.collect(&:as_json)
|
97
|
+
).to eq([
|
62
98
|
{ text: "Test", start: 0.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
63
99
|
{ text: "ing ", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
|
64
100
|
{ text: "\r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
|
@@ -79,9 +115,9 @@ describe MidiLyrics do
|
|
79
115
|
end
|
80
116
|
|
81
117
|
it "parses repeating_lyrics.mid correctly not repeating" do
|
82
|
-
|
83
|
-
|
84
|
-
|
118
|
+
expect(
|
119
|
+
MidiLyrics::Parser.new("spec/fixtures/repeating_lyrics.mid").extract.collect(&:as_json)
|
120
|
+
).to eq([
|
85
121
|
{ text: "Test", start: 0.0, start2: 2.5, duration: QUARTER_NOTE_DURATION },
|
86
122
|
{ text: "ing ", start: 0.5, start2: 3.0, duration: QUARTER_NOTE_DURATION },
|
87
123
|
{ text: "\r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 3.0 + QUARTER_NOTE_DURATION, duration: 0.0 },
|
@@ -115,15 +151,15 @@ describe MidiLyrics do
|
|
115
151
|
end
|
116
152
|
|
117
153
|
it "parses complete_example.mid correctly repeating" do
|
118
|
-
|
119
|
-
|
120
|
-
|
154
|
+
expect(
|
155
|
+
MidiLyrics::Parser.new("spec/fixtures/complete_example.mid").extract.collect(&:as_json)
|
156
|
+
).to eq(parsed_complete_example)
|
121
157
|
end
|
122
158
|
|
123
159
|
it "parses complete_example.mid correctly not repeating" do
|
124
|
-
|
125
|
-
|
126
|
-
|
160
|
+
expect(
|
161
|
+
MidiLyrics::Parser.new("spec/fixtures/complete_example.mid", repeating: true).extract.collect(&:as_json)
|
162
|
+
).to eq(parsed_complete_example)
|
127
163
|
end
|
128
164
|
end
|
129
165
|
|