Class: Music::Transcription::MeasureScore
- Inherits:
-
NoteScore
- Object
- NoteScore
- Music::Transcription::MeasureScore
show all
- Defined in:
- lib/music-transcription/model/measure_score.rb,
lib/music-transcription/packing/measure_score_packing.rb
Instance Attribute Summary collapse
Attributes inherited from NoteScore
#parts, #program, #start_tempo, #tempo_changes
Attributes included from Validatable
#errors
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NoteScore
#check_start_tempo_type, #check_tempo_change_types, #clone, #duration
#invalid?, #valid?, #validate
Constructor Details
#initialize(start_meter, start_tempo, meter_changes: {}, tempo_changes: {}, parts: {}, program: Program.new) {|_self| ... } ⇒ MeasureScore
Returns a new instance of MeasureScore.
7
8
9
10
11
12
13
|
# File 'lib/music-transcription/model/measure_score.rb', line 7
def initialize start_meter, start_tempo, meter_changes: {}, tempo_changes: {}, parts: {}, program: Program.new
@start_meter = start_meter
@meter_changes = meter_changes
super(start_tempo, tempo_changes: tempo_changes, program: program, parts: parts)
yield(self) if block_given?
end
|
Instance Attribute Details
#meter_changes ⇒ Object
Returns the value of attribute meter_changes.
5
6
7
|
# File 'lib/music-transcription/model/measure_score.rb', line 5
def meter_changes
@meter_changes
end
|
#start_meter ⇒ Object
Returns the value of attribute start_meter.
5
6
7
|
# File 'lib/music-transcription/model/measure_score.rb', line 5
def start_meter
@start_meter
end
|
Class Method Details
.unpack(packing) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/music-transcription/packing/measure_score_packing.rb', line 16
def self.unpack packing
unpacked_start_meter = Meter.parse(packing["start_meter"])
unpacked_mcs = Hash[ packing["meter_changes"].map do |k,v|
v = v.clone
v[0] = Meter.parse(v[0])
[k, Change.from_ary(v) ]
end ]
note_score = NoteScore.unpack(packing)
new(unpacked_start_meter, note_score.start_tempo,
meter_changes: unpacked_mcs, tempo_changes: note_score.tempo_changes,
program: note_score.program, parts: note_score.parts
)
end
|
Instance Method Details
#==(other) ⇒ Object
48
49
50
51
|
# File 'lib/music-transcription/model/measure_score.rb', line 48
def ==(other)
return super() && @start_meter == other.start_meter &&
@meter_changes == other.meter_changes
end
|
#check_meterchange_durs ⇒ Object
41
42
43
44
45
46
|
# File 'lib/music-transcription/model/measure_score.rb', line 41
def check_meterchange_durs
nonzero_duration = @meter_changes.select {|k,v| v.duration != 0 }
if nonzero_duration.any?
raise NonZeroError, "meter changes #{nonzero_duration} have non-zero duration"
end
end
|
#check_meterchange_types ⇒ Object
34
35
36
37
38
39
|
# File 'lib/music-transcription/model/measure_score.rb', line 34
def check_meterchange_types
badtypes = @meter_changes.select {|k,v| !v.value.is_a?(Meter) }
if badtypes.any?
raise TypeError, "meter change values #{nonmeter_values} are not Meter objects"
end
end
|
#check_methods ⇒ Object
15
16
17
|
# File 'lib/music-transcription/model/measure_score.rb', line 15
def check_methods
super() + [:check_startmeter_type, :check_meterchange_types, :check_meterchange_durs]
end
|
#check_startmeter_type ⇒ Object
28
29
30
31
32
|
# File 'lib/music-transcription/model/measure_score.rb', line 28
def check_startmeter_type
unless @start_meter.is_a? Meter
raise TypeError, "start meter #{@start_meter} is not a Meter object"
end
end
|
#pack ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/music-transcription/packing/measure_score_packing.rb', line 5
def pack
hash = super()
hash["start_meter"] = start_meter.to_s
hash["meter_changes"] = Hash[ meter_changes.map do |offset,change|
a = change.pack
a[0] = a[0].to_s
[offset,a]
end ]
return hash
end
|
#to_note_score ⇒ Object
Convert to NoteScore object by first converting measure-based offsets to note-based offsets, and eliminating the use of meters. Also, tempo is converted from beats-per-minute to notes-per-minute.
56
57
58
|
# File 'lib/music-transcription/model/measure_score.rb', line 56
def to_note_score
end
|
#valid_tempo_types ⇒ Object
24
25
26
|
# File 'lib/music-transcription/model/measure_score.rb', line 24
def valid_tempo_types
super() + [ Tempo::BPM ]
end
|
#validatables ⇒ Object
19
20
21
22
|
# File 'lib/music-transcription/model/measure_score.rb', line 19
def validatables
super() + [ @start_meter ] + @meter_changes.values +
@meter_changes.values.map {|v| v.value}
end
|