music-transcription 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/examples/hip.yml +86 -148
  3. data/examples/make_hip.rb +16 -53
  4. data/examples/make_missed_connection.rb +10 -55
  5. data/examples/make_song1.rb +17 -61
  6. data/examples/make_song2.rb +17 -47
  7. data/examples/missed_connection.yml +120 -196
  8. data/examples/song1.yml +168 -158
  9. data/examples/song2.yml +46 -180
  10. data/lib/music-transcription.rb +14 -13
  11. data/lib/music-transcription/{articulations.rb → model/articulations.rb} +0 -0
  12. data/lib/music-transcription/{change.rb → model/change.rb} +0 -0
  13. data/lib/music-transcription/{dynamics.rb → model/dynamics.rb} +0 -0
  14. data/lib/music-transcription/{link.rb → model/link.rb} +8 -0
  15. data/lib/music-transcription/{meter.rb → model/meter.rb} +0 -0
  16. data/lib/music-transcription/{meters.rb → model/meters.rb} +0 -0
  17. data/lib/music-transcription/{note.rb → model/note.rb} +1 -1
  18. data/lib/music-transcription/{part.rb → model/part.rb} +1 -1
  19. data/lib/music-transcription/{pitch.rb → model/pitch.rb} +0 -0
  20. data/lib/music-transcription/{pitches.rb → model/pitches.rb} +0 -0
  21. data/lib/music-transcription/{program.rb → model/program.rb} +0 -0
  22. data/lib/music-transcription/{score.rb → model/score.rb} +1 -1
  23. data/lib/music-transcription/{tempo.rb → model/tempo.rb} +0 -0
  24. data/lib/music-transcription/parsing/convenience_methods.rb +10 -0
  25. data/lib/music-transcription/parsing/meter_parsing.rb +84 -0
  26. data/lib/music-transcription/parsing/meter_parsing.treetop +19 -0
  27. data/lib/music-transcription/version.rb +1 -1
  28. data/spec/{change_spec.rb → model/change_spec.rb} +1 -1
  29. data/spec/{link_spec.rb → model/link_spec.rb} +1 -1
  30. data/spec/{meter_spec.rb → model/meter_spec.rb} +1 -1
  31. data/spec/{note_spec.rb → model/note_spec.rb} +8 -1
  32. data/spec/{part_spec.rb → model/part_spec.rb} +1 -1
  33. data/spec/{pitch_spec.rb → model/pitch_spec.rb} +1 -1
  34. data/spec/{program_spec.rb → model/program_spec.rb} +1 -1
  35. data/spec/{score_spec.rb → model/score_spec.rb} +1 -1
  36. data/spec/{tempo_spec.rb → model/tempo_spec.rb} +1 -1
  37. data/spec/parsing/convenience_methods_spec.rb +13 -2
  38. data/spec/parsing/meter_parsing_spec.rb +23 -0
  39. metadata +37 -33
data/examples/song2.yml CHANGED
@@ -7,9 +7,6 @@ start_meter: !ruby/object:Music::Transcription::Meter
7
7
  measure_duration: !ruby/object:Rational
8
8
  denominator: 1
9
9
  numerator: 1
10
- check_methods:
11
- - :check_beats_per_measure
12
- - :check_beat_duration
13
10
  start_tempo: 120
14
11
  meter_changes: {}
15
12
  tempo_changes: {}
@@ -17,7 +14,7 @@ parts:
17
14
  1: !ruby/object:Music::Transcription::Part
18
15
  notes:
19
16
  - !ruby/object:Music::Transcription::Note
20
- duration: &1 !ruby/object:Rational
17
+ duration: !ruby/object:Rational
21
18
  denominator: 1
22
19
  numerator: 1
23
20
  pitches:
@@ -27,21 +24,21 @@ parts:
27
24
  articulation: :normal
28
25
  accented: false
29
26
  links: {}
30
- check_methods:
31
- - :ensure_positive_duration
32
27
  - !ruby/object:Music::Transcription::Note
33
- duration: *1
28
+ duration: !ruby/object:Rational
29
+ denominator: 1
30
+ numerator: 1
34
31
  pitches:
35
- - &3 !ruby/object:Music::Transcription::Pitch
32
+ - !ruby/object:Music::Transcription::Pitch
36
33
  octave: 3
37
34
  semitone: 10
38
35
  articulation: :normal
39
36
  accented: false
40
37
  links: {}
41
- check_methods:
42
- - :ensure_positive_duration
43
38
  - !ruby/object:Music::Transcription::Note
44
- duration: *1
39
+ duration: !ruby/object:Rational
40
+ denominator: 1
41
+ numerator: 1
45
42
  pitches:
46
43
  - !ruby/object:Music::Transcription::Pitch
47
44
  octave: 3
@@ -49,10 +46,8 @@ parts:
49
46
  articulation: :normal
50
47
  accented: false
51
48
  links: {}
52
- check_methods:
53
- - :ensure_positive_duration
54
49
  - !ruby/object:Music::Transcription::Note
55
- duration: &2 !ruby/object:Rational
50
+ duration: !ruby/object:Rational
56
51
  denominator: 2
57
52
  numerator: 1
58
53
  pitches:
@@ -62,22 +57,19 @@ parts:
62
57
  articulation: :normal
63
58
  accented: false
64
59
  links: {}
65
- check_methods:
66
- - :ensure_positive_duration
67
60
  - !ruby/object:Music::Transcription::Note
68
- duration: *2
61
+ duration: !ruby/object:Rational
62
+ denominator: 2
63
+ numerator: 1
69
64
  pitches:
70
- - *3
65
+ - !ruby/object:Music::Transcription::Pitch
66
+ octave: 3
67
+ semitone: 10
71
68
  articulation: :normal
72
69
  accented: false
73
70
  links: {}
74
- check_methods:
75
- - :ensure_positive_duration
76
71
  start_dynamic: 0.625
77
72
  dynamic_changes: {}
78
- check_methods:
79
- - :ensure_start_dynamic
80
- - :ensure_dynamic_change_values_range
81
73
  2: !ruby/object:Music::Transcription::Part
82
74
  notes:
83
75
  - !ruby/object:Music::Transcription::Note
@@ -91,200 +83,74 @@ parts:
91
83
  articulation: :normal
92
84
  accented: false
93
85
  links: {}
94
- check_methods:
95
- - :ensure_positive_duration
96
86
  - !ruby/object:Music::Transcription::Note
97
- duration: *1
87
+ duration: !ruby/object:Rational
88
+ denominator: 1
89
+ numerator: 1
98
90
  pitches:
99
- - &5 !ruby/object:Music::Transcription::Pitch
91
+ - !ruby/object:Music::Transcription::Pitch
100
92
  octave: 5
101
93
  semitone: 2
102
94
  articulation: :normal
103
95
  accented: false
104
96
  links: {}
105
- check_methods:
106
- - :ensure_positive_duration
107
97
  - !ruby/object:Music::Transcription::Note
108
- duration: *1
98
+ duration: !ruby/object:Rational
99
+ denominator: 1
100
+ numerator: 1
109
101
  pitches:
110
- - &4 !ruby/object:Music::Transcription::Pitch
102
+ - !ruby/object:Music::Transcription::Pitch
111
103
  octave: 5
112
104
  semitone: 0
113
105
  articulation: :normal
114
106
  accented: false
115
107
  links: {}
116
- check_methods:
117
- - :ensure_positive_duration
118
108
  - !ruby/object:Music::Transcription::Note
119
109
  duration: !ruby/object:Rational
120
110
  denominator: 8
121
111
  numerator: 5
122
112
  pitches:
123
- - *4
124
- articulation: :normal
125
- accented: false
126
- links: {}
127
- check_methods:
128
- - :ensure_positive_duration
129
- - !ruby/object:Music::Transcription::Note
130
- duration: *2
131
- pitches:
132
- - *4
133
- articulation: :normal
134
- accented: false
135
- links: {}
136
- check_methods:
137
- - :ensure_positive_duration
138
- - !ruby/object:Music::Transcription::Note
139
- duration: *2
140
- pitches:
141
- - *5
142
- articulation: :normal
143
- accented: false
144
- links: {}
145
- check_methods:
146
- - :ensure_positive_duration
147
- start_dynamic: 0.625
148
- dynamic_changes: {}
149
- check_methods:
150
- - :ensure_start_dynamic
151
- - :ensure_dynamic_change_values_range
152
- 3: !ruby/object:Music::Transcription::Part
153
- notes:
154
- - !ruby/object:Music::Transcription::Note
155
- duration: &9 !ruby/object:Rational
156
- denominator: 8
157
- numerator: 1
158
- pitches: []
159
- articulation: :normal
160
- accented: false
161
- links: {}
162
- check_methods:
163
- - :ensure_positive_duration
164
- - !ruby/object:Music::Transcription::Note
165
- duration: &6 !ruby/object:Rational
166
- denominator: 4
167
- numerator: 1
168
- pitches:
169
113
  - !ruby/object:Music::Transcription::Pitch
170
114
  octave: 5
171
- semitone: 7
115
+ semitone: 0
172
116
  articulation: :normal
173
117
  accented: false
174
118
  links: {}
175
- check_methods:
176
- - :ensure_positive_duration
177
119
  - !ruby/object:Music::Transcription::Note
178
- duration: *2
120
+ duration: !ruby/object:Rational
121
+ denominator: 2
122
+ numerator: 1
179
123
  pitches:
180
- - &7 !ruby/object:Music::Transcription::Pitch
124
+ - !ruby/object:Music::Transcription::Pitch
181
125
  octave: 5
182
- semitone: 5
183
- articulation: :normal
184
- accented: false
185
- links: {}
186
- check_methods:
187
- - :ensure_positive_duration
188
- - !ruby/object:Music::Transcription::Note
189
- duration: *6
190
- pitches: []
191
- articulation: :normal
192
- accented: false
193
- links: {}
194
- check_methods:
195
- - :ensure_positive_duration
196
- - !ruby/object:Music::Transcription::Note
197
- duration: *6
198
- pitches:
199
- - *7
126
+ semitone: 0
200
127
  articulation: :normal
201
128
  accented: false
202
129
  links: {}
203
- check_methods:
204
- - :ensure_positive_duration
205
130
  - !ruby/object:Music::Transcription::Note
206
- duration: *2
131
+ duration: !ruby/object:Rational
132
+ denominator: 2
133
+ numerator: 1
207
134
  pitches:
208
- - &8 !ruby/object:Music::Transcription::Pitch
135
+ - !ruby/object:Music::Transcription::Pitch
209
136
  octave: 5
210
- semitone: 3
211
- articulation: :normal
212
- accented: false
213
- links: {}
214
- check_methods:
215
- - :ensure_positive_duration
216
- - !ruby/object:Music::Transcription::Note
217
- duration: *6
218
- pitches: []
219
- articulation: :normal
220
- accented: false
221
- links: {}
222
- check_methods:
223
- - :ensure_positive_duration
224
- - !ruby/object:Music::Transcription::Note
225
- duration: *6
226
- pitches:
227
- - *8
228
- articulation: :normal
229
- accented: false
230
- links: {}
231
- check_methods:
232
- - :ensure_positive_duration
233
- - !ruby/object:Music::Transcription::Note
234
- duration: *2
235
- pitches:
236
- - *8
237
- articulation: :normal
238
- accented: false
239
- links: {}
240
- check_methods:
241
- - :ensure_positive_duration
242
- - !ruby/object:Music::Transcription::Note
243
- duration: *9
244
- pitches: []
245
- articulation: :normal
246
- accented: false
247
- links: {}
248
- check_methods:
249
- - :ensure_positive_duration
250
- - !ruby/object:Music::Transcription::Note
251
- duration: *2
252
- pitches:
253
- - *8
254
- articulation: :normal
255
- accented: false
256
- links: {}
257
- check_methods:
258
- - :ensure_positive_duration
259
- - !ruby/object:Music::Transcription::Note
260
- duration: *2
261
- pitches:
262
- - *7
137
+ semitone: 2
263
138
  articulation: :normal
264
139
  accented: false
265
140
  links: {}
266
- check_methods:
267
- - :ensure_positive_duration
268
141
  start_dynamic: 0.625
269
142
  dynamic_changes: {}
270
- check_methods:
271
- - :ensure_start_dynamic
272
- - :ensure_dynamic_change_values_range
143
+ 3: !ruby/object:Music::Transcription::Part
144
+ notes: []
145
+ start_dynamic: 0.625
146
+ dynamic_changes: {}
273
147
  program: !ruby/object:Music::Transcription::Program
274
148
  segments:
275
- :segments:
276
- - !ruby/range
277
- begin: 0
278
- end: 4.0
279
- excl: true
280
- - !ruby/range
281
- begin: 0
282
- end: 4.0
283
- excl: true
284
- check_methods:
285
- - :ensure_increasing_segments
286
- - :ensure_nonnegative_segments
287
- check_methods:
288
- - :check_start_tempo
289
- - :check_tempo_changes
290
- - :check_meter_changes
149
+ - !ruby/range
150
+ begin: 0
151
+ end: 4.0
152
+ excl: true
153
+ - !ruby/range
154
+ begin: 0
155
+ end: 4.0
156
+ excl: true
@@ -4,19 +4,19 @@ require 'music-transcription/validatable'
4
4
  require 'music-transcription/errors'
5
5
 
6
6
  # code for transcribing (representing) music
7
- require 'music-transcription/pitch'
8
- require 'music-transcription/pitches'
9
- require 'music-transcription/link'
10
- require 'music-transcription/articulations'
11
- require 'music-transcription/note'
12
- require 'music-transcription/dynamics'
13
- require 'music-transcription/change'
14
- require 'music-transcription/part'
15
- require 'music-transcription/program'
16
- require 'music-transcription/tempo'
17
- require 'music-transcription/meter'
18
- require 'music-transcription/meters'
19
- require 'music-transcription/score'
7
+ require 'music-transcription/model/pitch'
8
+ require 'music-transcription/model/pitches'
9
+ require 'music-transcription/model/link'
10
+ require 'music-transcription/model/articulations'
11
+ require 'music-transcription/model/note'
12
+ require 'music-transcription/model/dynamics'
13
+ require 'music-transcription/model/change'
14
+ require 'music-transcription/model/part'
15
+ require 'music-transcription/model/program'
16
+ require 'music-transcription/model/tempo'
17
+ require 'music-transcription/model/meter'
18
+ require 'music-transcription/model/meters'
19
+ require 'music-transcription/model/score'
20
20
 
21
21
  require 'treetop'
22
22
  require 'music-transcription/parsing/nonnegative_integer_parsing'
@@ -30,4 +30,5 @@ require 'music-transcription/parsing/link_parsing'
30
30
  require 'music-transcription/parsing/link_nodes'
31
31
  require 'music-transcription/parsing/note_parsing'
32
32
  require 'music-transcription/parsing/note_nodes'
33
+ require 'music-transcription/parsing/meter_parsing'
33
34
  require 'music-transcription/parsing/convenience_methods'
@@ -17,6 +17,10 @@ class Link
17
17
  def ==(other)
18
18
  self.class == other.class
19
19
  end
20
+
21
+ def transpose! diff
22
+ # do nothing, of course
23
+ end
20
24
  end
21
25
 
22
26
  class TargetedLink < Link
@@ -29,6 +33,10 @@ class Link
29
33
  def ==(other)
30
34
  self.class == other.class && @target_pitch == other.target_pitch
31
35
  end
36
+
37
+ def transpose! diff
38
+ @target_pitch += diff
39
+ end
32
40
  end
33
41
 
34
42
  class Glissando < TargetedLink; end
@@ -50,7 +50,7 @@ class Note
50
50
  @pitches = @pitches.map {|pitch| pitch + diff}
51
51
  new_links = {}
52
52
  @links.each_pair do |k,v|
53
- v.target_pitch += diff
53
+ v.transpose! diff
54
54
  new_links[k + diff] = v
55
55
  end
56
56
  @links = new_links
@@ -6,7 +6,7 @@ module Transcription
6
6
  class Part
7
7
  include Validatable
8
8
 
9
- attr_reader :start_dynamic, :dynamic_changes, :notes
9
+ attr_accessor :start_dynamic, :dynamic_changes, :notes
10
10
 
11
11
  @@check_methods = [:ensure_start_dynamic, :ensure_dynamic_change_values_range ]
12
12
  def initialize start_dynamic, notes: [], dynamic_changes: {}
@@ -4,7 +4,7 @@ module Transcription
4
4
  class Score
5
5
  include Validatable
6
6
 
7
- attr_reader :start_meter, :start_tempo, :parts, :program, :meter_changes, :tempo_changes
7
+ attr_accessor :start_meter, :start_tempo, :parts, :program, :meter_changes, :tempo_changes
8
8
 
9
9
  @@check_methods = [ :check_start_tempo, :check_tempo_changes, :check_meter_changes ]
10
10
  def initialize start_meter, start_tempo, meter_changes: {}, tempo_changes: {}, parts: {}, program: Program.new
@@ -4,6 +4,7 @@ module Parsing
4
4
  DURATION_PARSER = DurationParser.new
5
5
  PITCH_PARSER = PitchParser.new
6
6
  NOTE_PARSER = NoteParser.new
7
+ METER_PARSER = MeterParser.new
7
8
 
8
9
  def duration dur_str
9
10
  DURATION_PARSER.parse(dur_str).to_r
@@ -44,6 +45,11 @@ module Parsing
44
45
  end
45
46
  end
46
47
  module_function :notes
48
+
49
+ def meter meter_str
50
+ METER_PARSER.parse(meter_str).to_meter
51
+ end
52
+ module_function :meter
47
53
  end
48
54
  end
49
55
  end
@@ -80,4 +86,8 @@ class String
80
86
  Music::Transcription::Parsing::notes(self)
81
87
  end
82
88
  alias :to_ns :to_notes
89
+
90
+ def to_meter
91
+ Music::Transcription::Parsing::meter(self)
92
+ end
83
93
  end