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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8091e1c24da61a2790de90896d716a9f2960bc36
4
- data.tar.gz: 4cae82d9652f322c1951d227d3f2b0fac5a4499a
3
+ metadata.gz: 25ee2f178ba21c7e16bb86db9680b65d30f76324
4
+ data.tar.gz: 979f7dfe084d8db529566e5bef20a30cf7ff68d0
5
5
  SHA512:
6
- metadata.gz: 73c50e8170abeb02e49dcb2b7f58aa4119e2ed451623d98a176b0f872bdb047349e83f6b6c6790094e2fdae4d74fb8d55a857e1126759d569f7822fc06afc9e4
7
- data.tar.gz: 741c155d2f592a7ebbc0390567a32a2ce2a991f405f050d69920f75adabfa0f0e4d3082aa124f69dda199d8ddbd2ef7c7a0d44ad3ccd5282096c341c517700cf
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)
@@ -1,3 +1,3 @@
1
1
  module MidiLyrics
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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 "parsing" do
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/one_note_one_syllable.mid").extract
14
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
15
- expect(lyrics).to eq([
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/two_notes_one_syllable.mid").extract
24
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
25
- expect(lyrics).to eq([
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/two_notes_two_syllables.mid").extract
34
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
35
- expect(lyrics).to eq([
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/spaces_and_returns.mid").extract
45
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
46
- expect(lyrics).to eq([
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/repeating_lyrics.mid", repeating: true).extract
60
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
61
- expect(lyrics).to eq([
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/repeating_lyrics.mid").extract
83
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
84
- expect(lyrics).to eq([
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/complete_example.mid").extract
119
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
120
- expect(lyrics).to eq(parsed_complete_example)
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
- lyrics = MidiLyrics::Parser.new("spec/fixtures/complete_example.mid", repeating: true).extract
125
- lyrics = lyrics.collect{|x| { text: x.text, start: x.start, start2: x.start2, duration: x.duration } }
126
- expect(lyrics).to eq(parsed_complete_example)
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
 
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateus Del Bianco