music-transcription 0.17.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/hip.rb +4 -4
- data/examples/missed_connection.rb +3 -3
- data/examples/song1.rb +6 -6
- data/examples/song2.rb +3 -3
- data/lib/music-transcription.rb +8 -2
- data/lib/music-transcription/model/change.rb +9 -3
- data/lib/music-transcription/model/measure_score.rb +62 -0
- data/lib/music-transcription/model/meter.rb +5 -1
- data/lib/music-transcription/model/note.rb +4 -1
- data/lib/music-transcription/model/note_score.rb +60 -0
- data/lib/music-transcription/model/part.rb +4 -1
- data/lib/music-transcription/model/program.rb +5 -2
- data/lib/music-transcription/model/tempo.rb +13 -23
- data/lib/music-transcription/packing/measure_score_packing.rb +34 -0
- data/lib/music-transcription/packing/{score_packing.rb → note_score_packing.rb} +12 -21
- data/lib/music-transcription/packing/part_packing.rb +1 -1
- data/lib/music-transcription/packing/program_packing.rb +1 -1
- data/lib/music-transcription/parsing/convenience_methods.rb +37 -58
- data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.rb +172 -59
- data/lib/music-transcription/parsing/numbers/nonnegative_float_parsing.treetop +13 -1
- data/lib/music-transcription/parsing/numbers/positive_float_parsing.rb +505 -0
- data/lib/music-transcription/parsing/numbers/positive_float_parsing.treetop +35 -0
- data/lib/music-transcription/parsing/numbers/positive_integer_parsing.rb +2 -0
- data/lib/music-transcription/parsing/numbers/positive_integer_parsing.treetop +2 -0
- data/lib/music-transcription/parsing/numbers/positive_rational_parsing.rb +86 -0
- data/lib/music-transcription/parsing/numbers/positive_rational_parsing.treetop +21 -0
- data/lib/music-transcription/parsing/parseable.rb +32 -0
- data/lib/music-transcription/parsing/tempo_parsing.rb +396 -0
- data/lib/music-transcription/parsing/tempo_parsing.treetop +49 -0
- data/lib/music-transcription/validatable.rb +5 -18
- data/lib/music-transcription/version.rb +1 -1
- data/spec/model/measure_score_spec.rb +85 -0
- data/spec/model/note_score_spec.rb +68 -0
- data/spec/model/tempo_spec.rb +15 -15
- data/spec/packing/{score_packing_spec.rb → measure_score_packing_spec.rb} +13 -7
- data/spec/packing/note_score_packing_spec.rb +100 -0
- data/spec/packing/part_packing_spec.rb +1 -1
- data/spec/parsing/convenience_methods_spec.rb +80 -81
- data/spec/parsing/numbers/nonnegative_float_spec.rb +19 -2
- data/spec/parsing/numbers/positive_float_spec.rb +28 -0
- data/spec/parsing/numbers/positive_integer_spec.rb +13 -2
- data/spec/parsing/numbers/positive_rational_spec.rb +28 -0
- data/spec/parsing/tempo_parsing_spec.rb +21 -0
- metadata +27 -8
- data/lib/music-transcription/model/score.rb +0 -68
- data/spec/model/score_spec.rb +0 -69
@@ -1,68 +0,0 @@
|
|
1
|
-
module Music
|
2
|
-
module Transcription
|
3
|
-
|
4
|
-
class Score
|
5
|
-
include Validatable
|
6
|
-
|
7
|
-
attr_accessor :start_meter, :start_tempo, :parts, :program, :meter_changes, :tempo_changes
|
8
|
-
|
9
|
-
@@check_methods = [ :check_start_tempo, :check_tempo_changes, :check_meter_changes ]
|
10
|
-
def initialize start_meter, start_tempo, meter_changes: {}, tempo_changes: {}, parts: {}, program: Program.new
|
11
|
-
@start_meter = start_meter
|
12
|
-
@start_tempo = start_tempo
|
13
|
-
@meter_changes = meter_changes
|
14
|
-
@tempo_changes = tempo_changes
|
15
|
-
@parts = parts
|
16
|
-
@program = program
|
17
|
-
|
18
|
-
yield(self) if block_given?
|
19
|
-
end
|
20
|
-
|
21
|
-
def validatables
|
22
|
-
return [ @program, @start_meter ] +
|
23
|
-
@tempo_changes.values +
|
24
|
-
@meter_changes.values +
|
25
|
-
@meter_changes.values.map {|v| v.value} +
|
26
|
-
@parts.values
|
27
|
-
end
|
28
|
-
|
29
|
-
def check_start_tempo
|
30
|
-
unless @start_tempo > 0
|
31
|
-
raise NonPositiveError, "start tempo #{@start_tempo} is not positive"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def check_tempo_changes
|
36
|
-
not_positive = @tempo_changes.select {|k,v| v.value <= 0}
|
37
|
-
if not_positive.any?
|
38
|
-
raise NonPositiveError, "tempo changes #{not_positive} are not positive"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def check_meter_changes
|
43
|
-
nonzero_duration = @meter_changes.select {|k,v| v.duration != 0 }
|
44
|
-
if nonzero_duration.any?
|
45
|
-
raise NonZeroError, "meter changes #{nonzero_duration} have non-zero duration"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def clone
|
50
|
-
Marshal.load(Marshal.dump(self))
|
51
|
-
end
|
52
|
-
|
53
|
-
def ==(other)
|
54
|
-
return @start_meter == other.start_meter &&
|
55
|
-
@start_tempo == other.start_tempo &&
|
56
|
-
@meter_changes == other.meter_changes &&
|
57
|
-
@tempo_changes == other.tempo_changes &&
|
58
|
-
@parts == other.parts &&
|
59
|
-
@program == other.program
|
60
|
-
end
|
61
|
-
|
62
|
-
def duration
|
63
|
-
@parts.map {|p| p.duration }.max
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
data/spec/model/score_spec.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Score do
|
4
|
-
describe '#initialize' do
|
5
|
-
it 'should use empty containers for parameters not given' do
|
6
|
-
s = Score.new(FOUR_FOUR,120)
|
7
|
-
s.parts.should be_empty
|
8
|
-
s.program.segments.should be_empty
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should assign given parameters' do
|
12
|
-
m = FOUR_FOUR
|
13
|
-
s = Score.new(m,120)
|
14
|
-
s.start_meter.should eq m
|
15
|
-
s.start_tempo.should eq 120
|
16
|
-
|
17
|
-
parts = { "piano (LH)" => Samples::SAMPLE_PART }
|
18
|
-
program = Program.new [0...0.75, 0...0.75]
|
19
|
-
mcs = { 1 => Change::Immediate.new(THREE_FOUR) }
|
20
|
-
tcs = { 1 => Change::Immediate.new(100) }
|
21
|
-
|
22
|
-
s = Score.new(m,120,
|
23
|
-
parts: parts,
|
24
|
-
program: program,
|
25
|
-
meter_changes: mcs,
|
26
|
-
tempo_changes: tcs
|
27
|
-
)
|
28
|
-
s.parts.should eq parts
|
29
|
-
s.program.should eq program
|
30
|
-
s.meter_changes.should eq mcs
|
31
|
-
s.tempo_changes.should eq tcs
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#valid?' do
|
36
|
-
{
|
37
|
-
'just valid start meter and tempo' => [ FOUR_FOUR, 120 ],
|
38
|
-
'valid meter changes' => [ FOUR_FOUR, 120,
|
39
|
-
:meter_changes => { 1 => Change::Immediate.new(TWO_FOUR) } ],
|
40
|
-
'valid tempo changes' => [ FOUR_FOUR, 120,
|
41
|
-
:tempo_changes => { 1 => Change::Gradual.new(200, 2), 2 => Change::Immediate.new(300) } ],
|
42
|
-
'valid part' => [ FOUR_FOUR, 120, :parts => { "piano" => Samples::SAMPLE_PART }],
|
43
|
-
'valid program' => [ FOUR_FOUR, 120, :program => Program.new([0..2,0..2]) ]
|
44
|
-
}.each do |context_str,args|
|
45
|
-
context context_str do
|
46
|
-
it 'should return true' do
|
47
|
-
Score.new(*args).should be_valid
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
{
|
53
|
-
'invalid start tempo' => [ FOUR_FOUR, -1],
|
54
|
-
'invalid start meter' => [ Meter.new(-1,"1/4".to_r), 120],
|
55
|
-
'invalid meter in change' => [ FOUR_FOUR, 120,
|
56
|
-
:meter_changes => { 1 => Change::Immediate.new(Meter.new(-2,"1/4".to_r)) } ],
|
57
|
-
'non-immediate meter change' => [ FOUR_FOUR, 120,
|
58
|
-
:meter_changes => { 1 => Change::Gradual.new(TWO_FOUR,1) } ],
|
59
|
-
'invalid part' => [ FOUR_FOUR, 120, :parts => { "piano" => Part.new(-0.1) }],
|
60
|
-
'invalid program' => [ FOUR_FOUR, 120, :program => Program.new([2..0]) ],
|
61
|
-
}.each do |context_str,args|
|
62
|
-
context context_str do
|
63
|
-
it 'should return false' do
|
64
|
-
Score.new(*args).should be_invalid
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|