midi_lyrics 0.0.8 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a310168013f34acd05cac16d712dd0d8e8cc23e
4
- data.tar.gz: cd5b78485d19c94f551e67142f2c22690ff19e2e
3
+ metadata.gz: f2d3244f48a9396a092d757b43cf05e3aadd4968
4
+ data.tar.gz: d4e2d6d87f15bac459768ef2a5958a8d6ca4d6e6
5
5
  SHA512:
6
- metadata.gz: 1d57f45820e56a7d6ab6ee2f0d327bc89c0e1327c09b68bc9249bc610def44dfcfc61b45f896d171dac12e6943c620a976f597e2ccfbcf124d2057111ddaf8a0
7
- data.tar.gz: 343f76df6de80b0a407932feae49bc36126211ed7a2fa96f9ccab3c4c8873da808ca7ccc048314f78a5c5e3c2c58616f7e85da765412da7ef4e434ce2e08577b
6
+ metadata.gz: 86f4b34f63cc01bdb978c24c7e34396b32b3c6d5b64e79cd8942aa91a4a3e853dfd57bb4f9aaf75f20e7ff6d3d9692f0b49f1a031a3ea2f66380260ad2f07cb5
7
+ data.tar.gz: d2bb17884dd4ec0a0ffd2f9c8d6cf4e3d0fea338b69d44b1c0e88ed24c34951a3591b8f3f1d47033a6d0892a9a961c1ae1f2ad45d50b1308d3394888002be92f
@@ -1,3 +1,3 @@
1
1
  module MidiLyrics
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/midi_lyrics.rb CHANGED
@@ -28,6 +28,10 @@ module MidiLyrics
28
28
  format_time(duration_in_pulses)
29
29
  end
30
30
 
31
+ def end_in_pulses
32
+ start_in_pulses + duration_in_pulses
33
+ end
34
+
31
35
  def blank?
32
36
  text.gsub('-', '').strip == ""
33
37
  end
@@ -73,6 +77,7 @@ module MidiLyrics
73
77
  consolidate_empty_syllables
74
78
  remove_lines_trailing_spaces
75
79
  remove_repeating unless repeating
80
+ fix_durations
76
81
  @lyrics.collect(&:as_json)
77
82
  end
78
83
 
@@ -140,18 +145,13 @@ module MidiLyrics
140
145
  new_lyrics = []
141
146
  @lyrics.each do |l|
142
147
  if l.blank?
143
- # if new_lyrics.last
144
- if new_lyrics.last.blank?
145
- new_lyrics.last.text += l.text
146
- else
147
- l.start_in_pulses = new_lyrics.last.start_in_pulses + new_lyrics.last.duration_in_pulses
148
- l.duration_in_pulses = 0.0
149
- new_lyrics << l
150
- end
151
- # else
152
- # l.duration_in_pulses = 0.0
153
- # new_lyrics << l
154
- # end
148
+ if new_lyrics.last.blank?
149
+ new_lyrics.last.text += l.text
150
+ else
151
+ l.start_in_pulses = new_lyrics.last.start_in_pulses + new_lyrics.last.duration_in_pulses
152
+ l.duration_in_pulses = 0.0
153
+ new_lyrics << l
154
+ end
155
155
  else
156
156
  new_lyrics << l
157
157
  end
@@ -187,5 +187,17 @@ module MidiLyrics
187
187
  merge_half_lyrics
188
188
  end
189
189
  end
190
+
191
+ def lyric_starting_at time_in_pulses
192
+ @lyrics.find{ |l| l.duration_in_pulses != 0.0 && l.start_in_pulses == time_in_pulses }
193
+ end
194
+
195
+ def fix_durations
196
+ @lyrics.each do |lyric|
197
+ while @durations.has_key?(lyric.end_in_pulses) && lyric_starting_at(lyric.end_in_pulses).nil?
198
+ lyric.duration_in_pulses += @durations[lyric.end_in_pulses]
199
+ end
200
+ end
201
+ end
190
202
  end
191
203
  end
@@ -18,9 +18,9 @@ describe MidiLyrics do
18
18
  ])
19
19
  end
20
20
 
21
- it "parses one_note_two_syllable.mid correctly" do
21
+ it "parses one_note_two_syllables.mid correctly" do
22
22
  expect(
23
- MidiLyrics::Parser.new("spec/fixtures/one_note_two_syllable.mid").extract
23
+ MidiLyrics::Parser.new("spec/fixtures/one_note_two_syllables.mid").extract
24
24
  ).to eq([
25
25
  { text: "Test One", start: 0.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
26
26
  { text: "\r\n", start: QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
@@ -66,6 +66,38 @@ describe MidiLyrics do
66
66
  ])
67
67
  end
68
68
 
69
+ it "parses three_notes_two_syllables.mid correctly" do
70
+ expect(
71
+ MidiLyrics::Parser.new("spec/fixtures/three_notes_two_syllables.mid").extract
72
+ ).to eq([
73
+ { text: "Test", start: 0, start2: 0.0, duration: 0.5 + QUARTER_NOTE_DURATION },
74
+ { text: "ing", start: 1, start2: 0.0, duration: QUARTER_NOTE_DURATION },
75
+ { text: "\r\n", start: 1 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
76
+ ])
77
+ end
78
+
79
+ it "parses three_notes_two_syllables_with_pause.mid correctly" do
80
+ expect(
81
+ MidiLyrics::Parser.new("spec/fixtures/three_notes_two_syllables_with_pause.mid").extract
82
+ ).to eq([
83
+ { text: "Test", start: 0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
84
+ { text: "ing", start: 1, start2: 0.0, duration: QUARTER_NOTE_DURATION },
85
+ { text: "\r\n", start: 1 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
86
+ ])
87
+ end
88
+
89
+ it "parses three_notes_three_syllables.mid correctly" do
90
+ expect(
91
+ MidiLyrics::Parser.new("spec/fixtures/three_notes_three_syllables.mid").extract
92
+ ).to eq([
93
+ { text: "Hi,", start: 0.0, start2: 0.0, duration: 0.5 },
94
+ { text: " ", start: 0.5, start2: 0.0, duration: 0.0 },
95
+ { text: "test", start: 0.5, start2: 0.0, duration: 0.5 },
96
+ { text: "ing", start: 1.0, start2: 0.0, duration: 0.5 },
97
+ { text: "\r\n", start: 1.5, start2: 0.0, duration: 0.0 }
98
+ ])
99
+ end
100
+
69
101
  it "parses spaces_and_returns.mid correctly" do
70
102
  expect(
71
103
  MidiLyrics::Parser.new("spec/fixtures/spaces_and_returns.mid").extract
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midi_lyrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateus Del Bianco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-18 00:00:00.000000000 Z
11
+ date: 2013-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,12 +89,18 @@ files:
89
89
  - spec/fixtures/complete_example.nwc
90
90
  - spec/fixtures/one_note_one_syllable.mid
91
91
  - spec/fixtures/one_note_one_syllable.nwc
92
- - spec/fixtures/one_note_two_syllable.mid
93
- - spec/fixtures/one_note_two_syllable.nwc
92
+ - spec/fixtures/one_note_two_syllables.mid
93
+ - spec/fixtures/one_note_two_syllables.nwc
94
94
  - spec/fixtures/repeating_lyrics.mid
95
95
  - spec/fixtures/repeating_lyrics.nwc
96
96
  - spec/fixtures/spaces_and_returns.mid
97
97
  - spec/fixtures/spaces_and_returns.nwc
98
+ - spec/fixtures/three_notes_three_syllables.mid
99
+ - spec/fixtures/three_notes_three_syllables.nwc
100
+ - spec/fixtures/three_notes_two_syllables.mid
101
+ - spec/fixtures/three_notes_two_syllables.nwc
102
+ - spec/fixtures/three_notes_two_syllables_with_pause.mid
103
+ - spec/fixtures/three_notes_two_syllables_with_pause.nwc
98
104
  - spec/fixtures/two_notes_one_syllable.mid
99
105
  - spec/fixtures/two_notes_one_syllable.nwc
100
106
  - spec/fixtures/two_notes_three_syllables.mid
@@ -134,12 +140,18 @@ test_files:
134
140
  - spec/fixtures/complete_example.nwc
135
141
  - spec/fixtures/one_note_one_syllable.mid
136
142
  - spec/fixtures/one_note_one_syllable.nwc
137
- - spec/fixtures/one_note_two_syllable.mid
138
- - spec/fixtures/one_note_two_syllable.nwc
143
+ - spec/fixtures/one_note_two_syllables.mid
144
+ - spec/fixtures/one_note_two_syllables.nwc
139
145
  - spec/fixtures/repeating_lyrics.mid
140
146
  - spec/fixtures/repeating_lyrics.nwc
141
147
  - spec/fixtures/spaces_and_returns.mid
142
148
  - spec/fixtures/spaces_and_returns.nwc
149
+ - spec/fixtures/three_notes_three_syllables.mid
150
+ - spec/fixtures/three_notes_three_syllables.nwc
151
+ - spec/fixtures/three_notes_two_syllables.mid
152
+ - spec/fixtures/three_notes_two_syllables.nwc
153
+ - spec/fixtures/three_notes_two_syllables_with_pause.mid
154
+ - spec/fixtures/three_notes_two_syllables_with_pause.nwc
143
155
  - spec/fixtures/two_notes_one_syllable.mid
144
156
  - spec/fixtures/two_notes_one_syllable.nwc
145
157
  - spec/fixtures/two_notes_three_syllables.mid