musicality 0.11.1 → 0.12.0
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 +5 -5
- data/.coveralls.yml +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +4 -0
- data/ChangeLog.md +11 -0
- data/README.md +3 -0
- data/Rakefile +11 -3
- data/lib/musicality/composition/model/rhythm.rb +33 -0
- data/lib/musicality/composition/model/rhythm_class.rb +30 -0
- data/lib/musicality/composition/sequencing/drum_machine/drum_kit.rb +18 -0
- data/lib/musicality/composition/sequencing/drum_machine/drum_machine.rb +59 -0
- data/lib/musicality/composition/sequencing/drum_machine/drum_parts.rb +21 -0
- data/lib/musicality/composition/sequencing/drum_machine/drum_pattern.rb +66 -0
- data/lib/musicality/composition/sequencing/drum_machine/drum_patterns/pop_drum_patterns.rb +146 -0
- data/lib/musicality/composition/sequencing/note_array.rb +33 -0
- data/lib/musicality/composition/sequencing/note_fifo.rb +73 -0
- data/lib/musicality/composition/sequencing/sequenceable.rb +9 -0
- data/lib/musicality/composition/sequencing/sequencer.rb +35 -0
- data/lib/musicality/errors.rb +2 -2
- data/lib/musicality/notation/model/dynamics.rb +2 -2
- data/lib/musicality/notation/model/key.rb +42 -91
- data/lib/musicality/notation/model/keys.rb +35 -34
- data/lib/musicality/notation/model/note.rb +31 -9
- data/lib/musicality/notation/model/pitch.rb +2 -2
- data/lib/musicality/notation/parsing/convenience_methods.rb +23 -12
- data/lib/musicality/notation/parsing/duration_parsing.rb +3 -3
- data/lib/musicality/notation/parsing/key_parsing.rb +150 -0
- data/lib/musicality/notation/parsing/key_parsing.treetop +37 -0
- data/lib/musicality/notation/parsing/meter_parsing.rb +3 -3
- data/lib/musicality/notation/parsing/numbers/nonnegative_float_parsing.rb +3 -1
- data/lib/musicality/notation/parsing/numbers/nonnegative_integer_parsing.rb +1 -0
- data/lib/musicality/notation/parsing/numbers/nonnegative_rational_parsing.rb +1 -1
- data/lib/musicality/notation/parsing/numbers/positive_float_parsing.rb +4 -1
- data/lib/musicality/notation/parsing/numbers/positive_rational_parsing.rb +1 -1
- data/lib/musicality/notation/parsing/parseable.rb +13 -17
- data/lib/musicality/notation/parsing/pitch_parsing.rb +7 -0
- data/lib/musicality/notation/parsing/segment_parsing.rb +3 -0
- data/lib/musicality/performance/conversion/note_sequence_extractor.rb +82 -134
- data/lib/musicality/performance/model/note_sequence.rb +22 -3
- data/lib/musicality/performance/supercollider/performer.rb +2 -2
- data/lib/musicality/performance/supercollider/sc_drum_kits.rb +29 -0
- data/lib/musicality/performance/supercollider/synthdefs/bass.rb +211 -0
- data/lib/musicality/performance/supercollider/synthdefs/claps.rb +80 -0
- data/lib/musicality/performance/supercollider/synthdefs/cymbals.rb +57 -0
- data/lib/musicality/performance/supercollider/synthdefs/hihats.rb +67 -0
- data/lib/musicality/performance/supercollider/synthdefs/kicks.rb +158 -0
- data/lib/musicality/performance/supercollider/synthdefs/mario.rb +49 -0
- data/lib/musicality/performance/supercollider/{synthdefs.rb → synthdefs/other.rb} +0 -767
- data/lib/musicality/performance/supercollider/synthdefs/pianos.rb +46 -0
- data/lib/musicality/performance/supercollider/synthdefs/snares.rb +169 -0
- data/lib/musicality/performance/supercollider/synthdefs/toms.rb +25 -0
- data/lib/musicality/performance/supercollider/synthdefs/volume.rb +20 -0
- data/lib/musicality/pitch_class.rb +1 -1
- data/lib/musicality/pitch_classes.rb +3 -5
- data/lib/musicality/version.rb +1 -1
- data/lib/musicality.rb +25 -1
- data/musicality.gemspec +3 -2
- data/spec/composition/convenience_methods_spec.rb +8 -8
- data/spec/composition/generation/random_rhythm_generator_spec.rb +5 -5
- data/spec/composition/model/pitch_class_spec.rb +22 -16
- data/spec/composition/model/pitch_classes_spec.rb +5 -5
- data/spec/composition/model/rhythm_class_spec.rb +42 -0
- data/spec/composition/model/rhythm_spec.rb +43 -0
- data/spec/composition/model/scale_class_spec.rb +26 -26
- data/spec/composition/model/scale_spec.rb +38 -38
- data/spec/composition/sequencing/drum_machine/drum_machine_spec.rb +67 -0
- data/spec/composition/sequencing/drum_machine/drum_pattern_spec.rb +58 -0
- data/spec/composition/sequencing/note_array_spec.rb +94 -0
- data/spec/composition/sequencing/note_fifo_spec.rb +183 -0
- data/spec/composition/sequencing/sequencer_spec.rb +76 -0
- data/spec/composition/util/adding_sequence_spec.rb +33 -33
- data/spec/composition/util/compound_sequence_spec.rb +6 -6
- data/spec/composition/util/note_generation_spec.rb +34 -34
- data/spec/composition/util/probabilities_spec.rb +7 -7
- data/spec/composition/util/random_sampler_spec.rb +3 -3
- data/spec/composition/util/repeating_sequence_spec.rb +28 -28
- data/spec/musicality_spec.rb +1 -1
- data/spec/notation/conversion/change_conversion_spec.rb +87 -87
- data/spec/notation/conversion/note_time_converter_spec.rb +22 -22
- data/spec/notation/conversion/score_conversion_spec.rb +1 -1
- data/spec/notation/conversion/score_converter_spec.rb +31 -31
- data/spec/notation/conversion/tempo_conversion_spec.rb +11 -11
- data/spec/notation/model/change_spec.rb +80 -80
- data/spec/notation/model/key_spec.rb +135 -69
- data/spec/notation/model/link_spec.rb +27 -27
- data/spec/notation/model/meter_spec.rb +28 -28
- data/spec/notation/model/note_spec.rb +68 -47
- data/spec/notation/model/part_spec.rb +19 -19
- data/spec/notation/model/pitch_spec.rb +69 -68
- data/spec/notation/model/score_spec.rb +50 -47
- data/spec/notation/parsing/articulation_parsing_spec.rb +4 -4
- data/spec/notation/parsing/convenience_methods_spec.rb +49 -10
- data/spec/notation/parsing/duration_nodes_spec.rb +13 -13
- data/spec/notation/parsing/duration_parsing_spec.rb +10 -10
- data/spec/notation/parsing/key_parsing_spec.rb +19 -0
- data/spec/notation/parsing/link_nodes_spec.rb +7 -7
- data/spec/notation/parsing/link_parsing_spec.rb +4 -4
- data/spec/notation/parsing/meter_parsing_spec.rb +5 -5
- data/spec/notation/parsing/note_node_spec.rb +19 -19
- data/spec/notation/parsing/note_parsing_spec.rb +4 -4
- data/spec/notation/parsing/numbers/nonnegative_float_spec.rb +8 -8
- data/spec/notation/parsing/numbers/nonnegative_integer_spec.rb +2 -2
- data/spec/notation/parsing/numbers/nonnegative_rational_spec.rb +1 -1
- data/spec/notation/parsing/numbers/positive_float_spec.rb +8 -8
- data/spec/notation/parsing/numbers/positive_integer_spec.rb +6 -6
- data/spec/notation/parsing/numbers/positive_rational_spec.rb +6 -6
- data/spec/notation/parsing/pitch_node_spec.rb +7 -7
- data/spec/notation/parsing/pitch_parsing_spec.rb +2 -2
- data/spec/notation/parsing/segment_parsing_spec.rb +3 -3
- data/spec/notation/util/function_spec.rb +15 -15
- data/spec/notation/util/transition_spec.rb +12 -12
- data/spec/notation/util/value_computer_spec.rb +35 -36
- data/spec/performance/conversion/glissando_converter_spec.rb +24 -24
- data/spec/performance/conversion/note_sequence_extractor_spec.rb +39 -39
- data/spec/performance/conversion/portamento_converter_spec.rb +23 -23
- data/spec/performance/midi/midi_util_spec.rb +41 -41
- data/spec/performance/midi/part_sequencer_spec.rb +10 -10
- data/spec/performance/midi/score_sequencer_spec.rb +15 -15
- data/spec/performance/midi/score_sequencing_spec.rb +2 -2
- data/spec/performance/util/optimization_spec.rb +9 -9
- data/spec/printing/note_engraving_spec.rb +16 -16
- data/spec/printing/score_engraver_spec.rb +5 -5
- data/spec/spec_helper.rb +5 -0
- metadata +85 -30
@@ -14,21 +14,21 @@ describe PortamentoConverter do
|
|
14
14
|
].each do |start,finish,step_size|
|
15
15
|
context "start at #{start.to_s}, end at #{finish.to_s}" do
|
16
16
|
pitches = PortamentoConverter.portamento_pitches(start,finish,step_size)
|
17
|
-
|
17
|
+
|
18
18
|
it 'should begin at start pitch' do
|
19
|
-
pitches.first.
|
19
|
+
expect(pitches.first).to eq(start)
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it 'should space pitches using given cent step size' do
|
23
23
|
(1...pitches.size).each do |i|
|
24
24
|
diff = pitches[i].total_cents - pitches[i-1].total_cents
|
25
|
-
diff.
|
25
|
+
expect(diff).to eq(step_size)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it 'should end where one more step would be >= target pitch' do
|
30
30
|
diff = finish.total_cents - pitches.last.total_cents
|
31
|
-
diff.
|
31
|
+
expect(diff).to be <= step_size
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -44,50 +44,50 @@ describe PortamentoConverter do
|
|
44
44
|
].each do |start,finish,step_size|
|
45
45
|
context "start at #{start.to_s}, end at #{finish.to_s}" do
|
46
46
|
pitches = PortamentoConverter.portamento_pitches(start,finish,step_size)
|
47
|
-
|
47
|
+
|
48
48
|
it 'should begin at start pitch' do
|
49
|
-
pitches.first.
|
49
|
+
expect(pitches.first).to eq(start)
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
it 'should space pitches using negative of given cent step size' do
|
53
53
|
(1...pitches.size).each do |i|
|
54
54
|
diff = pitches[i-1].total_cents - pitches[i].total_cents
|
55
|
-
diff.
|
55
|
+
expect(diff).to eq(step_size)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
it 'should end where one more step would be <= target pitch' do
|
60
60
|
diff = pitches.last.total_cents - finish.total_cents
|
61
|
-
diff.
|
61
|
+
expect(diff).to be <= step_size
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
describe '.portamento_elements' do
|
69
69
|
before :all do
|
70
70
|
@dur = Rational(3,2)
|
71
71
|
@att = Attack::NONE
|
72
72
|
@els = PortamentoConverter.portamento_elements(C4,F4,25,@dur,@att)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it 'should return an array of NoteSequence::Element objects' do
|
76
|
-
@els.each {|el| el.
|
76
|
+
@els.each {|el| expect(el).to be_a NoteSequence::Element }
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it 'should split up duration among elements' do
|
80
80
|
sum = @els.map {|el| el.duration }.inject(0,:+)
|
81
|
-
sum.
|
81
|
+
expect(sum).to eq(@dur)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
it 'should set attack as given for first element only and set others to NONE' do
|
85
85
|
els = PortamentoConverter.portamento_elements(C4,D4,10,1,Attack::ACCENT)
|
86
|
-
els.first.attack.
|
87
|
-
els[1..-1].each {|el| el.attack.
|
86
|
+
expect(els.first.attack).to eq(Attack::ACCENT)
|
87
|
+
els[1..-1].each {|el| expect(el.attack).to eq(Attack::NONE) }
|
88
88
|
els = PortamentoConverter.portamento_elements(C4,D4,10,1,Attack::TENUTO)
|
89
|
-
els.first.attack.
|
90
|
-
els[1..-1].each {|el| el.attack.
|
89
|
+
expect(els.first.attack).to eq(Attack::TENUTO)
|
90
|
+
els[1..-1].each {|el| expect(el.attack).to eq(Attack::NONE) }
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|
@@ -4,38 +4,38 @@ describe MidiUtil do
|
|
4
4
|
describe '.pitch_to_notenum' do
|
5
5
|
context 'given C4' do
|
6
6
|
it 'should return 60' do
|
7
|
-
MidiUtil.pitch_to_notenum(C4).
|
7
|
+
expect(MidiUtil.pitch_to_notenum(C4)).to eq(60)
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
context 'given A4' do
|
12
12
|
it 'should return 69' do
|
13
|
-
MidiUtil.pitch_to_notenum(A4).
|
13
|
+
expect(MidiUtil.pitch_to_notenum(A4)).to eq(69)
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
context 'given octave below C0' do
|
18
18
|
it 'should return 0' do
|
19
|
-
MidiUtil.pitch_to_notenum(Pitch.new(octave:-1)).
|
19
|
+
expect(MidiUtil.pitch_to_notenum(Pitch.new(octave:-1))).to eq(0)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
context 'given G9' do
|
24
24
|
it 'should return 127' do
|
25
|
-
MidiUtil.pitch_to_notenum(G9).
|
25
|
+
expect(MidiUtil.pitch_to_notenum(G9)).to eq(127)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
context 'given pitch between C-1 to G9 range' do
|
30
30
|
it 'should pitch diff from C4 should equal notenum diff' do
|
31
31
|
c4_nn = MidiUtil.pitch_to_notenum(C4)
|
32
32
|
[C2,D2,Eb2,F2,A2,Bb3,C3,G3,Gb4,F5,A5,Bb5,C6].each do |pitch|
|
33
33
|
nn = MidiUtil.pitch_to_notenum(pitch)
|
34
|
-
C4.diff(pitch).
|
34
|
+
expect(C4.diff(pitch)).to eq(c4_nn - nn)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
context 'given pitch outside C-1 to G9 range' do
|
40
40
|
it 'should raise error' do
|
41
41
|
expect { MidiUtil.pitch_to_notenum(Pitch.new(octave:-2)) }.to raise_error(KeyError)
|
@@ -47,103 +47,103 @@ describe MidiUtil do
|
|
47
47
|
describe '.notenum_to_pitch' do
|
48
48
|
context 'given 60' do
|
49
49
|
it 'should return C4' do
|
50
|
-
MidiUtil.notenum_to_pitch(60).
|
50
|
+
expect(MidiUtil.notenum_to_pitch(60)).to eq(C4)
|
51
51
|
end
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
context 'given 69' do
|
55
55
|
it 'should return A4' do
|
56
|
-
MidiUtil.notenum_to_pitch(69).
|
56
|
+
expect(MidiUtil.notenum_to_pitch(69)).to eq(A4)
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
context 'given 0' do
|
61
61
|
it 'should return octave below C0' do
|
62
|
-
MidiUtil.notenum_to_pitch(0).
|
62
|
+
expect(MidiUtil.notenum_to_pitch(0)).to eq(Pitch.new(octave:-1))
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
context 'given 127' do
|
67
67
|
it 'should return G9' do
|
68
|
-
MidiUtil.notenum_to_pitch(127).
|
68
|
+
expect(MidiUtil.notenum_to_pitch(127)).to eq(G9)
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
describe '.dynamic_to_volume' do
|
74
74
|
context 'given 0' do
|
75
75
|
it 'should return 0' do
|
76
|
-
MidiUtil.dynamic_to_volume(0).
|
76
|
+
expect(MidiUtil.dynamic_to_volume(0)).to eq(0)
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
context 'given 1' do
|
81
81
|
it 'should return 0' do
|
82
|
-
MidiUtil.dynamic_to_volume(1).
|
82
|
+
expect(MidiUtil.dynamic_to_volume(1)).to eq(127)
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
context 'given 0.5' do
|
87
87
|
it 'should return 64' do
|
88
|
-
MidiUtil.dynamic_to_volume(0.5).
|
88
|
+
expect(MidiUtil.dynamic_to_volume(0.5)).to eq(64)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
describe 'note_velocity' do
|
94
94
|
context 'given Attack::NORMAL' do
|
95
95
|
it 'should return a value at least that of when given Attack::NONE' do
|
96
|
-
MidiUtil.note_velocity(Attack::NORMAL).
|
96
|
+
expect(MidiUtil.note_velocity(Attack::NORMAL)).to be >= MidiUtil.note_velocity(Attack::NONE)
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'should return a value between 0 and 127' do
|
100
|
-
MidiUtil.note_velocity(Attack::NORMAL).
|
100
|
+
expect(MidiUtil.note_velocity(Attack::NORMAL)).to be_between(0,127)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
context 'given Attack::TENUTO' do
|
105
105
|
it 'should return a higher value than when given Attack::NORMAL' do
|
106
|
-
MidiUtil.note_velocity(Attack::TENUTO).
|
106
|
+
expect(MidiUtil.note_velocity(Attack::TENUTO)).to be > MidiUtil.note_velocity(Attack::NORMAL)
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
it 'should return a value between 0 and 127' do
|
110
|
-
MidiUtil.note_velocity(Attack::TENUTO).
|
110
|
+
expect(MidiUtil.note_velocity(Attack::TENUTO)).to be_between(0,127)
|
111
111
|
end
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
context 'given Attack::ACCENT' do
|
115
115
|
it 'should return a higher value than when given Attack::TENUTO' do
|
116
|
-
MidiUtil.note_velocity(Attack::ACCENT).
|
116
|
+
expect(MidiUtil.note_velocity(Attack::ACCENT)).to be > MidiUtil.note_velocity(Attack::TENUTO)
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'should return a value between 0 and 127' do
|
120
|
-
MidiUtil.note_velocity(Attack::ACCENT).
|
120
|
+
expect(MidiUtil.note_velocity(Attack::ACCENT)).to be_between(0,127)
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
describe '.delta' do
|
126
126
|
context 'given 1/4' do
|
127
127
|
it 'should return the given ppqn' do
|
128
|
-
MidiUtil.delta(Rational(1,4),20).
|
128
|
+
expect(MidiUtil.delta(Rational(1,4),20)).to eq(20)
|
129
129
|
end
|
130
130
|
end
|
131
|
-
|
131
|
+
|
132
132
|
context 'given 1/2' do
|
133
133
|
it 'should return twice the given ppqn' do
|
134
|
-
MidiUtil.delta(Rational(1,2),20).
|
134
|
+
expect(MidiUtil.delta(Rational(1,2),20)).to eq(40)
|
135
135
|
end
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
context 'given 1/8' do
|
139
139
|
it 'should return half the given ppqn' do
|
140
|
-
MidiUtil.delta(Rational(1,8),20).
|
140
|
+
expect(MidiUtil.delta(Rational(1,8),20)).to eq(10)
|
141
141
|
end
|
142
142
|
end
|
143
|
-
|
143
|
+
|
144
144
|
it 'should return an integer' do
|
145
145
|
(0.1...1.1).step(0.1).each do |dur|
|
146
|
-
MidiUtil.delta(dur,100).
|
146
|
+
expect(MidiUtil.delta(dur,100)).to be_an(Integer)
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
@@ -12,30 +12,30 @@ describe PartSequencer do
|
|
12
12
|
@program_num = 22
|
13
13
|
@track = PartSequencer.new(part).make_midi_track(@midi_seq,@part_name,@channel,@ppqn,@program_num)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it 'should return MIDI::Track' do
|
17
|
-
@track.
|
17
|
+
expect(@track).to be_a MIDI::Track
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it 'should assign part name to track name' do
|
21
|
-
@track.name.
|
21
|
+
expect(@track.name).to eq(@part_name)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it 'should assign program number (less one) via ProgramChange event' do
|
25
25
|
event = @track.events.select { |x| x.is_a? MIDI::ProgramChange }.first
|
26
|
-
event.program.
|
26
|
+
expect(event.program).to eq(@program_num-1)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it 'should assign the given channel number to all channel events' do
|
30
30
|
@track.events.each do |event|
|
31
31
|
if event.is_a? MIDI::ChannelEvent
|
32
|
-
event.channel.
|
32
|
+
expect(event.channel).to eq(@channel)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it 'should not add the track to the given midi seq' do
|
38
|
-
@midi_seq.tracks.
|
38
|
+
expect(@midi_seq.tracks).to_not include(@track)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -3,12 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
3
3
|
describe ScoreSequencer do
|
4
4
|
describe '#initialize' do
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
describe '#make_midi_seq' do
|
8
8
|
before :all do
|
9
9
|
@part1_name = "abc"
|
10
10
|
@part2_name = "def"
|
11
|
-
@part1 = Part.new(Dynamics::PP, notes: "/4C4 /4D4 /8 /8D4 /8E4 3/8C4".to_notes * 2,
|
11
|
+
@part1 = Part.new(Dynamics::PP, notes: "/4C4 /4D4 /8 /8D4 /8E4 3/8C4".to_notes * 2,
|
12
12
|
settings: [ MidiSettings::ELECTRIC_BASS_PICK ])
|
13
13
|
@part2 = Part.new(Dynamics::FF, notes: "/4E4 3/4F4 /4E4".to_notes * 2,
|
14
14
|
settings: [ MidiSettings::ELECTRIC_GUITAR_JAZZ ])
|
@@ -16,35 +16,35 @@ describe ScoreSequencer do
|
|
16
16
|
parts: {@part1_name => @part1, @part2_name => @part2})
|
17
17
|
@midi_seq = ScoreSequencer.new(@score).make_midi_seq
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it 'should return MIDI::Sequence' do
|
21
|
-
@midi_seq.
|
21
|
+
expect(@midi_seq).to be_a MIDI::Sequence
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it 'should have 1 track for each part, plus one for score meta events' do
|
25
|
-
@midi_seq.tracks.size.
|
25
|
+
expect(@midi_seq.tracks.size).to eq(@score.parts.size + 1)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it 'should add a midi track for each part' do
|
29
|
-
@midi_seq.tracks[1].name.
|
30
|
-
@midi_seq.tracks[2].name.
|
29
|
+
expect(@midi_seq.tracks[1].name).to eq(@part1_name)
|
30
|
+
expect(@midi_seq.tracks[2].name).to eq(@part2_name)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it 'should assign program number (starts at 0) from part midi program number (starts at 1)' do
|
34
34
|
prog_event = @midi_seq.tracks[1].events.select {|x| x.is_a? MIDI::ProgramChange }.first
|
35
|
-
prog_event.program.
|
35
|
+
expect(prog_event.program).to eq(@part1.midi_settings.program - 1)
|
36
36
|
|
37
37
|
prog_event = @midi_seq.tracks[2].events.select {|x| x.is_a? MIDI::ProgramChange }.first
|
38
|
-
prog_event.program.
|
38
|
+
expect(prog_event.program).to eq(@part2.midi_settings.program - 1)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it 'should assign different channel to each part track' do
|
42
42
|
chs_so_far = []
|
43
43
|
[ @midi_seq.tracks[1], @midi_seq.tracks[2] ].each do |track|
|
44
44
|
channel_events = track.events.select {|x| x.is_a? MIDI::ChannelEvent }
|
45
45
|
chs = channel_events.map {|event| event.channel }.uniq
|
46
|
-
chs.size.
|
47
|
-
chs_so_far.
|
46
|
+
expect(chs.size).to eq 1
|
47
|
+
expect(chs_so_far).to_not include(chs[0])
|
48
48
|
chs_so_far.push chs[0]
|
49
49
|
end
|
50
50
|
end
|
@@ -16,7 +16,7 @@ describe Score::Timed do
|
|
16
16
|
describe '#to_midi_seq' do
|
17
17
|
it 'should produce a MIDI::Sequence' do
|
18
18
|
seq = @score.to_midi_seq
|
19
|
-
seq.
|
19
|
+
expect(seq).to be_a MIDI::Sequence
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -39,7 +39,7 @@ describe Score::Tempo do
|
|
39
39
|
describe '#to_midi_seq' do
|
40
40
|
it 'should produce a MIDI::Sequence' do
|
41
41
|
seq = @score.to_midi_seq 200
|
42
|
-
seq.
|
42
|
+
expect(seq).to be_a MIDI::Sequence
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -7,14 +7,14 @@ describe Optimization do
|
|
7
7
|
[ C4, Bb4, G2, A3 ].each do |p1|
|
8
8
|
[ C4, Bb4, G2, A3 ].each do |p2|
|
9
9
|
sol = Optimization.linking([p1], [p2])
|
10
|
-
sol.size.
|
11
|
-
sol.
|
12
|
-
sol[p1].
|
10
|
+
expect(sol.size).to eq 1
|
11
|
+
expect(sol).to have_key p1
|
12
|
+
expect(sol[p1]).to eq p2
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
context 'two unlinked, one untargeted' do
|
19
19
|
it 'should map the closest unlinked to the one untargeted' do
|
20
20
|
unlinked = [C4,G4]
|
@@ -26,11 +26,11 @@ describe Optimization do
|
|
26
26
|
[Bb3] => {C4 => Bb3}
|
27
27
|
}.each do |untargeted, expected_map|
|
28
28
|
sol = Optimization.linking(unlinked, untargeted)
|
29
|
-
sol.
|
29
|
+
expect(sol).to eq expected_map
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
context 'one unlinked, two untargeted' do
|
35
35
|
it 'should map the one unlinked to the closest untargeted' do
|
36
36
|
unlinked = [C4]
|
@@ -41,11 +41,11 @@ describe Optimization do
|
|
41
41
|
[G3,G4] => {C4 => G3}
|
42
42
|
}.each do |untargeted, expected_map|
|
43
43
|
sol = Optimization.linking(unlinked, untargeted)
|
44
|
-
sol.
|
44
|
+
expect(sol).to eq expected_map
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
context 'many unlinked, many untargeted' do
|
50
50
|
it 'should map [unlinked.size, untargeted.size].min unlinked to untargeted, such that total pitch diffs is minimized' do
|
51
51
|
{
|
@@ -65,7 +65,7 @@ describe Optimization do
|
|
65
65
|
}.each do |unlinked_untargeted, expected_map|
|
66
66
|
unlinked,untargeted = unlinked_untargeted
|
67
67
|
sol = Optimization.linking(unlinked, untargeted)
|
68
|
-
sol.
|
68
|
+
expect(sol).to eq expected_map
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -6,7 +6,7 @@ describe Note do
|
|
6
6
|
it 'should return empty array' do
|
7
7
|
[1,2,3,4,7,11].each do |dur|
|
8
8
|
subdurs = Note.new(dur).fractional_subdurs(Rational(1,32))
|
9
|
-
subdurs.
|
9
|
+
expect(subdurs).to be_empty
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -23,11 +23,11 @@ describe Note do
|
|
23
23
|
subdurs2 = n.fractional_subdurs(Rational(1,512))
|
24
24
|
|
25
25
|
it 'should return descending power-of-two fractions' do
|
26
|
-
subdurs2.
|
26
|
+
expect(subdurs2).to eq subdurs2.sort.reverse
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should return fractions that sum to note duration' do
|
30
|
-
subdurs2.inject(0.to_r,:+).
|
30
|
+
expect(subdurs2.inject(0.to_r,:+)).to eq(dur)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -44,7 +44,7 @@ describe Note do
|
|
44
44
|
subdurs2 = n.fractional_subdurs(Rational(1,1024))
|
45
45
|
|
46
46
|
it 'should return fractions that sum to fractional note duration' do
|
47
|
-
subdurs2.inject(0.to_r,:+).
|
47
|
+
expect(subdurs2.inject(0.to_r,:+)).to eq(dur - dur.to_i)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -83,7 +83,7 @@ describe Note do
|
|
83
83
|
# it 'should return a string with "r" plus the duration denominator' do
|
84
84
|
# [1,0.5,0.25,0.125,0.0625].each do |dur|
|
85
85
|
# n = Note.new(dur.to_r)
|
86
|
-
# n.to_lilypond.
|
86
|
+
# expect(n.to_lilypond).to eq("r" + n.duration.denominator.to_s)
|
87
87
|
# end
|
88
88
|
# end
|
89
89
|
# end
|
@@ -92,7 +92,7 @@ describe Note do
|
|
92
92
|
# it 'should return a string with "r" plus half the duration denominator plus a "."' do
|
93
93
|
# [0.75,0.375].each do |dur|
|
94
94
|
# n = Note.new(dur.to_r)
|
95
|
-
# n.to_lilypond.
|
95
|
+
# expect(n.to_lilypond).to eq("r" + (n.duration.denominator/2).to_s + ".")
|
96
96
|
# end
|
97
97
|
# end
|
98
98
|
# end
|
@@ -108,9 +108,9 @@ describe Note do
|
|
108
108
|
# dur = subdurs.inject(0.to_r,:+)
|
109
109
|
# n = Note.new(dur)
|
110
110
|
# strs = n.to_lilypond.split
|
111
|
-
# strs.size.
|
111
|
+
# expect(strs.size).to eq subdurs.size
|
112
112
|
# strs.each_with_index do |str,i|
|
113
|
-
# str.
|
113
|
+
# expect(str).to eq("r" + subdurs[i].to_r.denominator.to_s)
|
114
114
|
# end
|
115
115
|
# end
|
116
116
|
# end
|
@@ -120,7 +120,7 @@ describe Note do
|
|
120
120
|
# it 'should return "r" + 3/2 duration enclosed inside \tuplet 3/2 {}' do
|
121
121
|
# [Rational(1,6),Rational(1,3),Rational(1,12)].each do |dur|
|
122
122
|
# n = Note.new(dur.to_r)
|
123
|
-
# n.to_lilypond.
|
123
|
+
# expect(n.to_lilypond).to eq("\\tuplet 3/2 {r#{(1.5.to_r*dur).denominator}}")
|
124
124
|
# end
|
125
125
|
# end
|
126
126
|
# end
|
@@ -132,7 +132,7 @@ describe Note do
|
|
132
132
|
# [1,0.5,0.25,0.125,0.0625].each do |dur|
|
133
133
|
# [C3,Eb2,G4].each do |pitch|
|
134
134
|
# n = Note.new(dur.to_r, pitch)
|
135
|
-
# n.to_lilypond.
|
135
|
+
# expect(n.to_lilypond).to eq(pitch.to_lilypond + n.duration.denominator.to_s)
|
136
136
|
# end
|
137
137
|
# end
|
138
138
|
# end
|
@@ -143,7 +143,7 @@ describe Note do
|
|
143
143
|
# [1,0.25,0.0625].each do |dur|
|
144
144
|
# pitch_group = [Eb2,C3,G4]
|
145
145
|
# n = Note.new(dur.to_r, pitch_group)
|
146
|
-
# n.to_lilypond.
|
146
|
+
# expect(n.to_lilypond).to eq("<" + pitch_group.map {|p| p.to_lilypond}.join(" ") + ">" + n.duration.denominator.to_s)
|
147
147
|
# end
|
148
148
|
# end
|
149
149
|
# end
|
@@ -155,7 +155,7 @@ describe Note do
|
|
155
155
|
# [0.75,0.375].each do |dur|
|
156
156
|
# [C3,Eb2,G4].each do |pitch|
|
157
157
|
# n = Note.new(dur.to_r, pitch)
|
158
|
-
# n.to_lilypond.
|
158
|
+
# expect(n.to_lilypond).to eq(pitch.to_lilypond + (n.duration.denominator/2).to_s + ".")
|
159
159
|
# end
|
160
160
|
# end
|
161
161
|
# end
|
@@ -166,7 +166,7 @@ describe Note do
|
|
166
166
|
# [0.75,0.375].each do |dur|
|
167
167
|
# pitch_group = [Eb2,C3,G4]
|
168
168
|
# n = Note.new(dur.to_r, pitch_group)
|
169
|
-
# n.to_lilypond.
|
169
|
+
# expect(n.to_lilypond).to eq("<" + pitch_group.map {|p| p.to_lilypond}.join(" ") + ">" + (n.duration.denominator/2).to_s + ".")
|
170
170
|
# end
|
171
171
|
# end
|
172
172
|
# end
|
@@ -186,12 +186,12 @@ describe Note do
|
|
186
186
|
# n = Note.new(dur,pitch)
|
187
187
|
# str = n.to_lilypond
|
188
188
|
# strs = str.split
|
189
|
-
# strs.size.
|
189
|
+
# expect(strs.size).to eq subdurs.size
|
190
190
|
# strs.each_with_index do |str,i|
|
191
191
|
# if i != (strs.size-1)
|
192
|
-
# str.
|
192
|
+
# expect(str).to eq(pitch.to_lilypond + subdurs[i].to_r.denominator.to_s + "~")
|
193
193
|
# else
|
194
|
-
# str.
|
194
|
+
# expect(str).to eq(pitch.to_lilypond + subdurs[i].to_r.denominator.to_s)
|
195
195
|
# end
|
196
196
|
# end
|
197
197
|
# end
|
@@ -4,7 +4,7 @@ describe ScoreEngraver do
|
|
4
4
|
describe '.part_titles' do
|
5
5
|
context 'parts all have different lilypond settings' do
|
6
6
|
it 'should return a map of part names to instrument names' do
|
7
|
-
parts = {
|
7
|
+
parts = {
|
8
8
|
:part1 => Part.new(Dynamics::MP, settings: [ LilypondSettings::ELECTRIC_PIANO ]),
|
9
9
|
:part2 => Part.new(Dynamics::MP, settings: [ LilypondSettings::ELECTRIC_BASS ]),
|
10
10
|
:part3 => Part.new(Dynamics::MP, settings: [ LilypondSettings::CLARINET ])
|
@@ -12,14 +12,14 @@ describe ScoreEngraver do
|
|
12
12
|
titles = ScoreEngraver.figure_part_titles(parts)
|
13
13
|
|
14
14
|
parts.each do |part_name, part|
|
15
|
-
titles[part_name].
|
15
|
+
expect(titles[part_name]).to eq(part.lilypond_settings.instrument_name)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'some parts have same lilypond settings' do
|
21
21
|
it 'should return a map of part names to numbered instrument names' do
|
22
|
-
parts = {
|
22
|
+
parts = {
|
23
23
|
:part1 => Part.new(Dynamics::MP, settings: [ LilypondSettings::ELECTRIC_PIANO ]),
|
24
24
|
:part2 => Part.new(Dynamics::MP, settings: [ LilypondSettings::ELECTRIC_PIANO ]),
|
25
25
|
:part3 => Part.new(Dynamics::MP, settings: [ LilypondSettings::ELECTRIC_PIANO ])
|
@@ -29,11 +29,11 @@ describe ScoreEngraver do
|
|
29
29
|
part_nums = []
|
30
30
|
parts.each do |part_name, part|
|
31
31
|
r = Regexp.new("#{part.lilypond_settings.instrument_name} (\\d)")
|
32
|
-
titles[part_name].
|
32
|
+
expect(titles[part_name]).to match r
|
33
33
|
m = titles[part_name].match(r)
|
34
34
|
part_nums.push m.captures.first.to_s.to_i
|
35
35
|
end
|
36
|
-
part_nums.sort.
|
36
|
+
expect(part_nums.sort).to eq((1..part_nums.size).to_a)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|