midi_lyrics 0.0.4 → 0.0.6

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: f734c528919168e0348b3b936bd4dbd8c0e7041a
4
- data.tar.gz: ace7320df7fbaab6d2bda807e1220368cdf1273e
3
+ metadata.gz: de1fc14ed163e13a3b05eaddfcb29bd9b9d50948
4
+ data.tar.gz: 07a79b70ea64ecfde9b52ac275a679c9f5995352
5
5
  SHA512:
6
- metadata.gz: c216ecd753faf7535e8044b3a93204623039ab741dbe9f24ea51e8c1cb2e889a14ef00aab78422b7e87d83832902ea97f6af48f7285c9e5058835f817b62bcce
7
- data.tar.gz: 3a554fef7e8359b4983b6f192e23e9913cd116630843c3d2b8ecd08de11c4c94531943b63fa6064746a8b5fd4958a7601c456b4cf491a78c7245c3273ec09066
6
+ metadata.gz: e54f4f09be1608c63ea990e0c7952b305ab2b152cb027bb7cfe502712e95579ed55049551c4d2f5e25503a33a7efb997f95d37cc6888b2e97c9f8d98c795c7cd
7
+ data.tar.gz: 482259a6013bb46532c15dbaee7395b81d2712d720a0b17ca540401a026082e51cdb27b9edb2532b2ed56a60a064e62e46043b0b1bad13048ee12af65a606010
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
  => [
25
25
  { text: "Test", start: 0, start2: 0.0, duration: 0.417 },
26
26
  { text: "ing", start: 0.5, start2: 0.0, duration: 0.417 },
27
- { text: " \r\n", start: 0.917, start2: 0.0, duration: 0 }
27
+ { text: "\r\n", start: 0.917, start2: 0.0, duration: 0 }
28
28
  ]
29
29
 
30
30
  ## Contributing
@@ -1,3 +1,3 @@
1
1
  module MidiLyrics
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/midi_lyrics.rb CHANGED
@@ -95,22 +95,24 @@ module MidiLyrics
95
95
  def load_lyrics
96
96
  @lyrics = []
97
97
  @lyrics_track.each do |event|
98
- parts = event.data.collect{|x| x.chr(Encoding::UTF_8)}.join.match(/([^\s]*)(\s*)/)
99
- if parts[1] != ""
100
- @lyrics << LyricSyllable.new(
101
- sequence: @sequence,
102
- start_in_pulses: event.time_from_start,
103
- duration_in_pulses: @durations[event.time_from_start],
104
- text: parts[1]
105
- )
106
- end
107
- if parts[2] != ""
108
- @lyrics << LyricSyllable.new(
109
- sequence: @sequence,
110
- start_in_pulses: event.time_from_start,
111
- duration_in_pulses: 0,
112
- text: parts[2]
113
- )
98
+ event_text = event.data.collect{|x| x.chr(Encoding::UTF_8)}.join
99
+ letters = event_text.gsub(/^\s+|\s+$/, '')
100
+
101
+ heading_space = event_text.match(/^(\s+)[^\s]/)
102
+ heading_space = heading_space[1] unless heading_space.nil?
103
+
104
+ trailing_space = event_text.match(/(\s+)$/)
105
+ trailing_space = trailing_space[1] unless trailing_space.nil?
106
+
107
+ [heading_space, letters, trailing_space].each do |text|
108
+ unless text.nil?
109
+ @lyrics << LyricSyllable.new(
110
+ sequence: @sequence,
111
+ start_in_pulses: event.time_from_start,
112
+ duration_in_pulses: @durations[event.time_from_start],
113
+ text: text
114
+ )
115
+ end
114
116
  end
115
117
  end
116
118
  end
@@ -139,6 +141,12 @@ module MidiLyrics
139
141
  @lyrics = new_lyrics
140
142
  end
141
143
 
144
+ def remove_lines_trailing_spaces
145
+ @lyrics.each do |l|
146
+ l.text.gsub!(/^ ([\r\n])/, '\1')
147
+ end
148
+ end
149
+
142
150
  def half_is_equal
143
151
  half = @lyrics.count / 2
144
152
  (0..(half-1)).each do |x|
@@ -169,6 +177,7 @@ module MidiLyrics
169
177
  load_lyrics
170
178
  remove_heading_blank_lines
171
179
  consolidate_empty_syllables
180
+ remove_lines_trailing_spaces
172
181
  remove_repeating unless repeating
173
182
  @lyrics
174
183
  end
@@ -50,7 +50,16 @@ describe MidiLyrics do
50
50
  MidiLyrics::Parser.new("spec/fixtures/one_note_one_syllable.mid").extract.collect(&:as_json)
51
51
  ).to eq([
52
52
  { text: "Test", start: 0.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
53
- { text: " \r\n", start: QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
53
+ { text: "\r\n", start: QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
54
+ ])
55
+ end
56
+
57
+ it "parses one_note_two_syllable.mid correctly" do
58
+ expect(
59
+ MidiLyrics::Parser.new("spec/fixtures/one_note_two_syllable.mid").extract.collect(&:as_json)
60
+ ).to eq([
61
+ { text: "Test One", start: 0.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
62
+ { text: "\r\n", start: QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
54
63
  ])
55
64
  end
56
65
 
@@ -59,7 +68,7 @@ describe MidiLyrics do
59
68
  MidiLyrics::Parser.new("spec/fixtures/two_notes_one_syllable.mid").extract.collect(&:as_json)
60
69
  ).to eq([
61
70
  { text: "Test", start: 0, start2: 0.0, duration: 0.5 + QUARTER_NOTE_DURATION },
62
- { text: " \r\n", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
71
+ { text: "\r\n", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
63
72
  ])
64
73
  end
65
74
 
@@ -69,7 +78,17 @@ describe MidiLyrics do
69
78
  ).to eq([
70
79
  { text: "Test", start: 0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
71
80
  { text: "ing", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
72
- { text: " \r\n", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
81
+ { text: "\r\n", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
82
+ ])
83
+ end
84
+
85
+ it "parses two_notes_three_syllables.mid correctly" do
86
+ expect(
87
+ MidiLyrics::Parser.new("spec/fixtures/two_notes_three_syllables.mid").extract.collect(&:as_json)
88
+ ).to eq([
89
+ { text: "Hello, test", start: 0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
90
+ { text: "ing", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
91
+ { text: "\r\n", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
73
92
  ])
74
93
  end
75
94
 
@@ -79,13 +98,13 @@ describe MidiLyrics do
79
98
  ).to eq([
80
99
  { text: "Test", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
81
100
  { text: "ing", start: 1, start2: 0.0, duration: QUARTER_NOTE_DURATION },
82
- { text: " \r", start: 1 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
101
+ { text: "\r", start: 1 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
83
102
  { text: "One", start: 1.5, start2: 0.0, duration: HALF_NOTE_DURATION },
84
103
  { text: " ", start: 1.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
85
104
  { text: "Two", start: 2.5, start2: 0.0, duration: HALF_NOTE_DURATION },
86
105
  { text: " ", start: 2.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
87
106
  { text: "Three", start: 3.5, start2: 0.0, duration: HALF_NOTE_DURATION },
88
- { text: " \r\n", start: 3.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 }
107
+ { text: "\r\n", start: 3.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 }
89
108
  ])
90
109
  end
91
110
 
@@ -95,22 +114,22 @@ describe MidiLyrics do
95
114
  ).to eq([
96
115
  { text: "Test", start: 0.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
97
116
  { text: "ing", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
98
- { text: " \r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
117
+ { text: "\r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
99
118
  { text: "One", start: 1.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
100
119
  { text: " ", start: 1.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
101
120
  { text: "Two", start: 1.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
102
121
  { text: " ", start: 1.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
103
122
  { text: "Three", start: 2.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
104
- { text: " \r\n", start: 2.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
123
+ { text: "\r\n", start: 2.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
105
124
  { text: "Test", start: 2.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
106
125
  { text: "ing", start: 3.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
107
- { text: " \r", start: 3.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
126
+ { text: "\r", start: 3.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
108
127
  { text: "One", start: 3.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
109
128
  { text: " ", start: 3.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
110
129
  { text: "Two", start: 4.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
111
130
  { text: " ", start: 4.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
112
131
  { text: "Three", start: 4.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
113
- { text: " \r\n", start: 4.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
132
+ { text: "\r\n", start: 4.5 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 }
114
133
  ])
115
134
  end
116
135
 
@@ -120,13 +139,13 @@ describe MidiLyrics do
120
139
  ).to eq([
121
140
  { text: "Test", start: 0.0, start2: 2.5, duration: QUARTER_NOTE_DURATION },
122
141
  { text: "ing", start: 0.5, start2: 3.0, duration: QUARTER_NOTE_DURATION },
123
- { text: " \r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 3.0 + QUARTER_NOTE_DURATION, duration: 0.0 },
142
+ { text: "\r", start: 0.5 + QUARTER_NOTE_DURATION, start2: 3.0 + QUARTER_NOTE_DURATION, duration: 0.0 },
124
143
  { text: "One", start: 1.0, start2: 3.5, duration: QUARTER_NOTE_DURATION },
125
144
  { text: " ", start: 1.0 + QUARTER_NOTE_DURATION, start2: 3.5 + QUARTER_NOTE_DURATION, duration: 0.0 },
126
145
  { text: "Two", start: 1.5, start2: 4.0, duration: QUARTER_NOTE_DURATION },
127
146
  { text: " ", start: 1.5 + QUARTER_NOTE_DURATION, start2: 4.0 + QUARTER_NOTE_DURATION, duration: 0.0 },
128
147
  { text: "Three", start: 2.0, start2: 4.5, duration: QUARTER_NOTE_DURATION },
129
- { text: " \r\n", start: 2.0 + QUARTER_NOTE_DURATION, start2: 4.5 + QUARTER_NOTE_DURATION, duration: 0.0 }
148
+ { text: "\r\n", start: 2.0 + QUARTER_NOTE_DURATION, start2: 4.5 + QUARTER_NOTE_DURATION, duration: 0.0 }
130
149
  ])
131
150
  end
132
151
 
@@ -134,22 +153,22 @@ describe MidiLyrics do
134
153
  [
135
154
  { text: "Test", start: 0.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
136
155
  { text: "ing", start: 1.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
137
- { text: " \r", start: 1.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
156
+ { text: "\r", start: 1.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
138
157
  { text: "One", start: 1.5, start2: 0.0, duration: HALF_NOTE_DURATION },
139
158
  { text: " ", start: 1.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
140
159
  { text: "Two", start: 2.5, start2: 0.0, duration: HALF_NOTE_DURATION },
141
160
  { text: " ", start: 2.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
142
161
  { text: "Three", start: 3.5, start2: 0.0, duration: HALF_NOTE_DURATION },
143
- { text: " \r\n", start: 3.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
162
+ { text: "\r\n", start: 3.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
144
163
  { text: "Test", start: 4.5, start2: 0.0, duration: QUARTER_NOTE_DURATION },
145
164
  { text: "ing", start: 5.0, start2: 0.0, duration: QUARTER_NOTE_DURATION },
146
- { text: " \r", start: 5.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
165
+ { text: "\r", start: 5.0 + QUARTER_NOTE_DURATION, start2: 0.0, duration: 0.0 },
147
166
  { text: "Four", start: 5.5, start2: 0.0, duration: HALF_NOTE_DURATION },
148
167
  { text: " ", start: 5.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
149
168
  { text: "Five", start: 6.5, start2: 0.0, duration: HALF_NOTE_DURATION },
150
169
  { text: " ", start: 6.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
151
170
  { text: "Six", start: 7.5, start2: 0.0, duration: HALF_NOTE_DURATION },
152
- { text: " \r\n", start: 7.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
171
+ { text: "\r\n", start: 7.5 + HALF_NOTE_DURATION, start2: 0.0, duration: 0.0 },
153
172
  ]
154
173
  end
155
174
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midi_lyrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateus Del Bianco
@@ -89,12 +89,16 @@ 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
94
  - spec/fixtures/repeating_lyrics.mid
93
95
  - spec/fixtures/repeating_lyrics.nwc
94
96
  - spec/fixtures/spaces_and_returns.mid
95
97
  - spec/fixtures/spaces_and_returns.nwc
96
98
  - spec/fixtures/two_notes_one_syllable.mid
97
99
  - spec/fixtures/two_notes_one_syllable.nwc
100
+ - spec/fixtures/two_notes_three_syllables.mid
101
+ - spec/fixtures/two_notes_three_syllables.nwc
98
102
  - spec/fixtures/two_notes_two_syllables.mid
99
103
  - spec/fixtures/two_notes_two_syllables.nwc
100
104
  - spec/midi_lyrics_spec.rb
@@ -128,12 +132,16 @@ test_files:
128
132
  - spec/fixtures/complete_example.nwc
129
133
  - spec/fixtures/one_note_one_syllable.mid
130
134
  - spec/fixtures/one_note_one_syllable.nwc
135
+ - spec/fixtures/one_note_two_syllable.mid
136
+ - spec/fixtures/one_note_two_syllable.nwc
131
137
  - spec/fixtures/repeating_lyrics.mid
132
138
  - spec/fixtures/repeating_lyrics.nwc
133
139
  - spec/fixtures/spaces_and_returns.mid
134
140
  - spec/fixtures/spaces_and_returns.nwc
135
141
  - spec/fixtures/two_notes_one_syllable.mid
136
142
  - spec/fixtures/two_notes_one_syllable.nwc
143
+ - spec/fixtures/two_notes_three_syllables.mid
144
+ - spec/fixtures/two_notes_three_syllables.nwc
137
145
  - spec/fixtures/two_notes_two_syllables.mid
138
146
  - spec/fixtures/two_notes_two_syllables.nwc
139
147
  - spec/midi_lyrics_spec.rb