jmtk 0.0.3.3-java
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.
- data/.yardopts +10 -0
- data/DEVELOPMENT_NOTES.md +115 -0
- data/INTRO.md +129 -0
- data/LICENSE.txt +27 -0
- data/README.md +50 -0
- data/Rakefile +102 -0
- data/bin/jmtk +250 -0
- data/bin/mtk +250 -0
- data/examples/crescendo.rb +20 -0
- data/examples/drum_pattern.rb +23 -0
- data/examples/dynamic_pattern.rb +36 -0
- data/examples/gets_and_play.rb +27 -0
- data/examples/notation.rb +22 -0
- data/examples/play_midi.rb +17 -0
- data/examples/print_midi.rb +13 -0
- data/examples/random_tone_row.rb +18 -0
- data/examples/syntax_to_midi.rb +28 -0
- data/examples/test_output.rb +7 -0
- data/examples/tone_row_melody.rb +23 -0
- data/lib/mtk.rb +76 -0
- data/lib/mtk/core/duration.rb +213 -0
- data/lib/mtk/core/intensity.rb +158 -0
- data/lib/mtk/core/interval.rb +157 -0
- data/lib/mtk/core/pitch.rb +154 -0
- data/lib/mtk/core/pitch_class.rb +194 -0
- data/lib/mtk/events/event.rb +119 -0
- data/lib/mtk/events/note.rb +112 -0
- data/lib/mtk/events/parameter.rb +54 -0
- data/lib/mtk/events/timeline.rb +232 -0
- data/lib/mtk/groups/chord.rb +56 -0
- data/lib/mtk/groups/collection.rb +196 -0
- data/lib/mtk/groups/melody.rb +96 -0
- data/lib/mtk/groups/pitch_class_set.rb +163 -0
- data/lib/mtk/groups/pitch_collection.rb +23 -0
- data/lib/mtk/io/dls_synth_device.rb +146 -0
- data/lib/mtk/io/dls_synth_output.rb +62 -0
- data/lib/mtk/io/jsound_input.rb +87 -0
- data/lib/mtk/io/jsound_output.rb +82 -0
- data/lib/mtk/io/midi_file.rb +209 -0
- data/lib/mtk/io/midi_input.rb +97 -0
- data/lib/mtk/io/midi_output.rb +195 -0
- data/lib/mtk/io/notation.rb +162 -0
- data/lib/mtk/io/unimidi_input.rb +117 -0
- data/lib/mtk/io/unimidi_output.rb +140 -0
- data/lib/mtk/lang/durations.rb +57 -0
- data/lib/mtk/lang/intensities.rb +61 -0
- data/lib/mtk/lang/intervals.rb +73 -0
- data/lib/mtk/lang/mtk_grammar.citrus +237 -0
- data/lib/mtk/lang/parser.rb +29 -0
- data/lib/mtk/lang/pitch_classes.rb +29 -0
- data/lib/mtk/lang/pitches.rb +52 -0
- data/lib/mtk/lang/pseudo_constants.rb +26 -0
- data/lib/mtk/lang/variable.rb +32 -0
- data/lib/mtk/numeric_extensions.rb +66 -0
- data/lib/mtk/patterns/chain.rb +49 -0
- data/lib/mtk/patterns/choice.rb +43 -0
- data/lib/mtk/patterns/cycle.rb +18 -0
- data/lib/mtk/patterns/for_each.rb +71 -0
- data/lib/mtk/patterns/function.rb +39 -0
- data/lib/mtk/patterns/lines.rb +54 -0
- data/lib/mtk/patterns/palindrome.rb +45 -0
- data/lib/mtk/patterns/pattern.rb +171 -0
- data/lib/mtk/patterns/sequence.rb +20 -0
- data/lib/mtk/sequencers/event_builder.rb +132 -0
- data/lib/mtk/sequencers/legato_sequencer.rb +24 -0
- data/lib/mtk/sequencers/rhythmic_sequencer.rb +28 -0
- data/lib/mtk/sequencers/sequencer.rb +111 -0
- data/lib/mtk/sequencers/step_sequencer.rb +26 -0
- data/spec/mtk/core/duration_spec.rb +372 -0
- data/spec/mtk/core/intensity_spec.rb +289 -0
- data/spec/mtk/core/interval_spec.rb +265 -0
- data/spec/mtk/core/pitch_class_spec.rb +343 -0
- data/spec/mtk/core/pitch_spec.rb +297 -0
- data/spec/mtk/events/event_spec.rb +234 -0
- data/spec/mtk/events/note_spec.rb +174 -0
- data/spec/mtk/events/parameter_spec.rb +220 -0
- data/spec/mtk/events/timeline_spec.rb +430 -0
- data/spec/mtk/groups/chord_spec.rb +85 -0
- data/spec/mtk/groups/collection_spec.rb +374 -0
- data/spec/mtk/groups/melody_spec.rb +225 -0
- data/spec/mtk/groups/pitch_class_set_spec.rb +340 -0
- data/spec/mtk/io/midi_file_spec.rb +243 -0
- data/spec/mtk/io/midi_output_spec.rb +102 -0
- data/spec/mtk/lang/durations_spec.rb +89 -0
- data/spec/mtk/lang/intensities_spec.rb +101 -0
- data/spec/mtk/lang/intervals_spec.rb +143 -0
- data/spec/mtk/lang/parser_spec.rb +603 -0
- data/spec/mtk/lang/pitch_classes_spec.rb +62 -0
- data/spec/mtk/lang/pitches_spec.rb +56 -0
- data/spec/mtk/lang/pseudo_constants_spec.rb +20 -0
- data/spec/mtk/lang/variable_spec.rb +52 -0
- data/spec/mtk/numeric_extensions_spec.rb +83 -0
- data/spec/mtk/patterns/chain_spec.rb +110 -0
- data/spec/mtk/patterns/choice_spec.rb +97 -0
- data/spec/mtk/patterns/cycle_spec.rb +123 -0
- data/spec/mtk/patterns/for_each_spec.rb +136 -0
- data/spec/mtk/patterns/function_spec.rb +120 -0
- data/spec/mtk/patterns/lines_spec.rb +77 -0
- data/spec/mtk/patterns/palindrome_spec.rb +108 -0
- data/spec/mtk/patterns/pattern_spec.rb +132 -0
- data/spec/mtk/patterns/sequence_spec.rb +203 -0
- data/spec/mtk/sequencers/event_builder_spec.rb +245 -0
- data/spec/mtk/sequencers/legato_sequencer_spec.rb +45 -0
- data/spec/mtk/sequencers/rhythmic_sequencer_spec.rb +84 -0
- data/spec/mtk/sequencers/sequencer_spec.rb +215 -0
- data/spec/mtk/sequencers/step_sequencer_spec.rb +93 -0
- data/spec/spec_coverage.rb +2 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/test.mid +0 -0
- metadata +226 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MTK::Patterns::Cycle do
|
4
|
+
|
5
|
+
CYCLE = MTK::Patterns::Cycle
|
6
|
+
|
7
|
+
let(:elements) { [1, 2, 3] }
|
8
|
+
let(:cycle) { CYCLE.new elements }
|
9
|
+
|
10
|
+
describe "#next" do
|
11
|
+
it "iterates through the list of elements and emits them one at a time" do
|
12
|
+
cycle.next.should == elements[0]
|
13
|
+
cycle.next.should == elements[1]
|
14
|
+
cycle.next.should == elements[2]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "starts at the beginning of the list of elements after the end of the list is reached" do
|
18
|
+
elements.length.times do
|
19
|
+
cycle.next
|
20
|
+
end
|
21
|
+
cycle.next.should == elements.first
|
22
|
+
end
|
23
|
+
|
24
|
+
it "enumerates nested sequences" do
|
25
|
+
cycle = CYCLE.new [1, MTK::Patterns.Sequence(2,3), 4]
|
26
|
+
nexts = []
|
27
|
+
6.times { nexts << cycle.next }
|
28
|
+
nexts.should == [1,2,3,4,1,2]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "@max_cycles" do
|
33
|
+
it "is the :max_cycles option the pattern was constructed with" do
|
34
|
+
CYCLE.new([], :max_cycles => 1).max_cycles.should == 1
|
35
|
+
end
|
36
|
+
|
37
|
+
it "is nil by default" do
|
38
|
+
cycle.max_cycles.should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "loops indefinitely when it's nil" do
|
42
|
+
lambda { 100.times { cycle.next } }.should_not raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "causes a StopIteration exception after the number of cycles has completed" do
|
46
|
+
cycle = CYCLE.new(elements, :max_cycles => 2)
|
47
|
+
2.times do
|
48
|
+
elements.length.times { cycle.next } # one full cycle
|
49
|
+
end
|
50
|
+
lambda { cycle.next }.should raise_error
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "@max_elements" do
|
55
|
+
it "causes a StopIteration exception after the number of elements have been emitted, with a higher max_cycles" do
|
56
|
+
cycle = CYCLE.new(elements, max_cycles:2, max_elements:5)
|
57
|
+
5.times { cycle.next }
|
58
|
+
lambda { cycle.next }.should raise_error StopIteration
|
59
|
+
end
|
60
|
+
|
61
|
+
it "causes a StopIteration exception after the number of elements have been emitted" do
|
62
|
+
cycle = CYCLE.new(elements, max_elements:5)
|
63
|
+
5.times { cycle.next }
|
64
|
+
lambda { cycle.next }.should raise_error StopIteration
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#rewind" do
|
69
|
+
it "restarts the cycle" do
|
70
|
+
(elements.length - 1).times do
|
71
|
+
cycle.next
|
72
|
+
end
|
73
|
+
cycle.rewind
|
74
|
+
cycle.next.should == elements.first
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
describe MTK::Patterns do
|
82
|
+
|
83
|
+
describe "#Cycle" do
|
84
|
+
it "creates a Cycle" do
|
85
|
+
MTK::Patterns.Cycle(1,2,3).should be_a MTK::Patterns::Cycle
|
86
|
+
end
|
87
|
+
|
88
|
+
it "sets #elements from the varargs" do
|
89
|
+
MTK::Patterns.Cycle(1,2,3).elements.should == [1,2,3]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#PitchCycle" do
|
94
|
+
it "creates a Cycle" do
|
95
|
+
MTK::Patterns.PitchCycle(1,2,3).should be_a MTK::Patterns::Cycle
|
96
|
+
end
|
97
|
+
|
98
|
+
it "sets #elements from the varargs" do
|
99
|
+
MTK::Patterns.PitchCycle(1,2,3).elements.should == [Pitch(1),Pitch(2),Pitch(3)]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#IntensityCycle" do
|
104
|
+
it "creates a Cycle" do
|
105
|
+
MTK::Patterns.IntensityCycle(1,2,3).should be_a MTK::Patterns::Cycle
|
106
|
+
end
|
107
|
+
|
108
|
+
it "sets #elements from the varargs" do
|
109
|
+
MTK::Patterns.IntensityCycle(1,2,3).elements.should == [Intensity(1),Intensity(2),Intensity(3)]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#DurationCycle" do
|
114
|
+
it "creates a Cycle" do
|
115
|
+
MTK::Patterns.DurationCycle(1,2,3).should be_a MTK::Patterns::Cycle
|
116
|
+
end
|
117
|
+
|
118
|
+
it "sets #elements from the varargs" do
|
119
|
+
MTK::Patterns.DurationCycle(1,2,3).elements.should == [Duration(1),Duration(2),Duration(3)]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MTK::Patterns::ForEach do
|
4
|
+
|
5
|
+
FOREACH = ::MTK::Patterns::ForEach
|
6
|
+
|
7
|
+
def var(name)
|
8
|
+
::MTK::Lang::Variable.new(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def seq(*args)
|
12
|
+
::MTK::Patterns.Sequence(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
def chain(*args)
|
16
|
+
::MTK::Patterns.Chain(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe "#elements" do
|
21
|
+
it "is the array the sequence was constructed with" do
|
22
|
+
FOREACH.new([seq(1,2),seq(3,4)]).elements.should == [seq(1,2),seq(3,4)]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#next" do
|
27
|
+
it "enumerates each element in the second pattern for each element in the first, with variable '$' as the first pattern's current element" do
|
28
|
+
foreach = FOREACH.new [ seq(C,D,E), seq(var('$'),G,A) ]
|
29
|
+
vals = []
|
30
|
+
9.times{ vals << foreach.next }
|
31
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
32
|
+
vals.should == [C,G,A,D,G,A,E,G,A]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "enumerates the foreach construct with a variable in the middle of the second pattern" do
|
36
|
+
foreach = FOREACH.new [ seq(C,D,E), seq(G,var('$'),A) ]
|
37
|
+
vals = []
|
38
|
+
9.times{ vals << foreach.next }
|
39
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
40
|
+
vals.should == [G,C,A,G,D,A,G,E,A]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "enumerates the foreach construct with multiple variables" do
|
44
|
+
foreach = FOREACH.new [ seq(C,D,E), seq(G,var('$'),A,var('$')) ]
|
45
|
+
vals = []
|
46
|
+
12.times{ vals << foreach.next }
|
47
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
48
|
+
vals.should == [G,C,A,C,G,D,A,D,G,E,A,E]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "handles 3-level nesting" do
|
52
|
+
foreach = FOREACH.new [ seq(C,D), seq(var('$'),F), seq(G,var('$')) ]
|
53
|
+
vals = []
|
54
|
+
8.times{ vals << foreach.next }
|
55
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
56
|
+
vals.should == [G,C,G,F,G,D,G,F]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "handles 4-level nesting" do
|
60
|
+
foreach = FOREACH.new [ seq(C,D), seq(var('$'),E), seq(F,var('$')), seq(var('$'),G) ]
|
61
|
+
vals = []
|
62
|
+
16.times{ vals << foreach.next }
|
63
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
64
|
+
vals.should == [F,G,C,G,F,G,E,G,F,G,D,G,F,G,E,G]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "evaluates the '$$' var by going back 2 levels in the variables stack" do
|
68
|
+
foreach = FOREACH.new [ seq(C,D), seq(E,F), seq(var('$$'),var('$')) ]
|
69
|
+
vals = []
|
70
|
+
8.times{ vals << foreach.next }
|
71
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
72
|
+
vals.should == [C,E,C,F,D,E,D,F]
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
it "evaluates the '$$$' var by going back 3 levels in the variables stack" do
|
77
|
+
foreach = FOREACH.new [ seq(C,D), seq(E,F), seq(G,A), seq(var('$$$'),var('$$'),var('$')) ]
|
78
|
+
vals = []
|
79
|
+
24.times{ vals << foreach.next }
|
80
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
81
|
+
vals.should == [C,E,G,C,E,A,C,F,G,C,F,A,D,E,G,D,E,A,D,F,G,D,F,A]
|
82
|
+
end
|
83
|
+
|
84
|
+
it "evaluates nested variables" do
|
85
|
+
# (C4 Bb Ab G)@( (C D C $):(q i i)*4:(mp mf) )
|
86
|
+
foreach = FOREACH.new( [seq(G,A), chain(seq(C,D,var('$')),seq(q,i,s))] )
|
87
|
+
vals = []
|
88
|
+
6.times{ vals << foreach.next }
|
89
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
90
|
+
vals.should == [[C,q],[D,i],[G,s],[C,q],[D,i],[A,s]]
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
describe "#rewind" do
|
98
|
+
it "restarts at the beginning of the sequence" do
|
99
|
+
foreach = FOREACH.new [ seq(C,D,E), seq(var('$'),G,A) ]
|
100
|
+
6.times{ foreach.next }
|
101
|
+
foreach.next.should == E
|
102
|
+
foreach.rewind
|
103
|
+
vals = []
|
104
|
+
9.times{ vals << foreach.next }
|
105
|
+
lambda{ foreach.next }.should raise_error StopIteration
|
106
|
+
vals.should == [C,G,A,D,G,A,E,G,A]
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns self, so it can be chained to #next" do
|
110
|
+
foreach = FOREACH.new [ seq(C,D,E), seq(var('$'),G,A) ]
|
111
|
+
first = foreach.next
|
112
|
+
foreach.rewind.next.should == first
|
113
|
+
foreach.rewind.next.should == first
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
describe MTK::Patterns do
|
121
|
+
|
122
|
+
def seq(*args)
|
123
|
+
::MTK::Patterns.Sequence(*args)
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#ForEach" do
|
127
|
+
it "creates a Sequence" do
|
128
|
+
MTK::Patterns.ForEach(seq(1,2),seq(3,4)).should be_a MTK::Patterns::ForEach
|
129
|
+
end
|
130
|
+
|
131
|
+
it "sets #elements from the varargs" do
|
132
|
+
MTK::Patterns.ForEach(seq(1,2),seq(3,4)).elements.should == [seq(1,2),seq(3,4)]
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MTK::Patterns::Function do
|
4
|
+
|
5
|
+
FUNCTION = MTK::Patterns::Function
|
6
|
+
|
7
|
+
describe "#next" do
|
8
|
+
it "calls a lambda to produce elements" do
|
9
|
+
function = FUNCTION.new lambda{ 1 + 1 }
|
10
|
+
function.next.should == 2
|
11
|
+
function.next.should == 2
|
12
|
+
end
|
13
|
+
|
14
|
+
it "calls a 1-arg lambda with the previous value" do
|
15
|
+
function = FUNCTION.new lambda{|prev| (prev || 0) + 1 }
|
16
|
+
function.next.should == 1
|
17
|
+
function.next.should == 2
|
18
|
+
function.next.should == 3
|
19
|
+
end
|
20
|
+
|
21
|
+
it "stops looping when the lambda raises StopIteration" do
|
22
|
+
function = FUNCTION.new lambda{|prev| raise StopIteration if prev == 2; (prev || 0) + 1 }
|
23
|
+
nexts = []
|
24
|
+
loop do
|
25
|
+
nexts << function.next
|
26
|
+
end
|
27
|
+
nexts.should == [1,2]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "calls a 2-arg lambda with the previous value and function call count (starting from 0)" do
|
31
|
+
function = FUNCTION.new lambda{|prev,index| [prev,index] }
|
32
|
+
function.next.should == [nil, 0]
|
33
|
+
function.next.should == [[nil,0], 1]
|
34
|
+
function.next.should == [[[nil,0],1], 2]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "calls a 3-arg lambda with the previous value, function call count (starting from 0), and element count (starting from 0)" do
|
38
|
+
function = FUNCTION.new lambda{|prev,call_index,elem_index| prev.nil? ? MTK::Patterns.Sequence(1,2,3,4) : [call_index,elem_index] }
|
39
|
+
function.next.should == 1
|
40
|
+
function.next.should == 2
|
41
|
+
function.next.should == 3
|
42
|
+
function.next.should == 4
|
43
|
+
function.next.should == [1,4]
|
44
|
+
end
|
45
|
+
|
46
|
+
it "can generate other Patterns, which will be iterated over before re-calling the function" do
|
47
|
+
function = FUNCTION.new lambda{|prev,index| MTK::Patterns.Sequence(index,2,3) }
|
48
|
+
function.next.should == 0
|
49
|
+
function.next.should == 2
|
50
|
+
function.next.should == 3
|
51
|
+
function.next.should == 1 # end of sequence, now a new one is generated, this time starting with 1
|
52
|
+
function.next.should == 2
|
53
|
+
function.next.should == 3
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#rewind" do
|
58
|
+
it "resets previous value and element count" do
|
59
|
+
function = FUNCTION.new lambda{|prev,index| [prev,index] }
|
60
|
+
function.next.should == [nil, 0]
|
61
|
+
function.next.should == [[nil,0], 1]
|
62
|
+
function.rewind
|
63
|
+
function.next.should == [nil, 0]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
describe MTK::Patterns do
|
71
|
+
|
72
|
+
let(:mock_lambda) { lambda{|_|:mock_value} }
|
73
|
+
|
74
|
+
describe "#Function" do
|
75
|
+
it "creates a Function" do
|
76
|
+
MTK::Patterns.Function(nil).should be_a MTK::Patterns::Function
|
77
|
+
end
|
78
|
+
|
79
|
+
it "sets #elements from the varargs" do
|
80
|
+
MTK::Patterns.Function(:mock_lambda).function.should == :mock_lambda
|
81
|
+
end
|
82
|
+
|
83
|
+
it "doesn't wrap a lambda in the varargs Array" do
|
84
|
+
function = MTK::Patterns.Function( lambda{ 1 + 1 } )
|
85
|
+
function.next.should == 2
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#PitchFunction" do
|
90
|
+
it "creates a Function" do
|
91
|
+
MTK::Patterns.PitchFunction(mock_lambda).should be_a MTK::Patterns::Function
|
92
|
+
end
|
93
|
+
|
94
|
+
it "sets #elements from the varargs" do
|
95
|
+
func = mock_lambda
|
96
|
+
MTK::Patterns.PitchFunction(func).function.should == func
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#IntensityFunction" do
|
101
|
+
it "creates a Function" do
|
102
|
+
MTK::Patterns.IntensityFunction(mock_lambda).should be_a MTK::Patterns::Function
|
103
|
+
end
|
104
|
+
|
105
|
+
it "sets #elements from the varargs" do
|
106
|
+
MTK::Patterns.IntensityFunction(mock_lambda).function.should == mock_lambda
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#DurationFunction" do
|
111
|
+
it "creates a Function" do
|
112
|
+
MTK::Patterns.DurationFunction(mock_lambda).should be_a MTK::Patterns::Function
|
113
|
+
end
|
114
|
+
|
115
|
+
it "sets #elements from the varargs" do
|
116
|
+
MTK::Patterns.DurationFunction(mock_lambda).function.should == mock_lambda
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MTK::Patterns::Lines do
|
4
|
+
|
5
|
+
LINES = MTK::Patterns::Lines
|
6
|
+
|
7
|
+
let(:elements) { [0, [10,5], [5,10]] }
|
8
|
+
let(:lines) { LINES.new elements }
|
9
|
+
|
10
|
+
describe "#next" do
|
11
|
+
it "interpolates between values, treating each element as [value, steps_to_value] pairs" do
|
12
|
+
nexts = []
|
13
|
+
loop do
|
14
|
+
nexts << lines.next
|
15
|
+
end
|
16
|
+
nexts.should == [0, 2,4,6,8,10, 9.5,9,8.5,8,7.5,7,6.5,6,5.5,5]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#rewind" do
|
21
|
+
it "starts the pattern from the beginning" do
|
22
|
+
10.times { lines.next }
|
23
|
+
lines.rewind
|
24
|
+
nexts = []
|
25
|
+
loop do
|
26
|
+
nexts << lines.next
|
27
|
+
end
|
28
|
+
nexts.should == [0, 2,4,6,8,10, 9.5,9,8.5,8,7.5,7,6.5,6,5.5,5]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe MTK::Patterns do
|
36
|
+
|
37
|
+
describe "#Lines" do
|
38
|
+
it "creates a Lines" do
|
39
|
+
MTK::Patterns.Lines(1,2,3).should be_a MTK::Patterns::Lines
|
40
|
+
end
|
41
|
+
|
42
|
+
it "sets #elements from the varargs" do
|
43
|
+
MTK::Patterns.Lines(1,2,3).elements.should == [1,2,3]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#PitchLines" do
|
48
|
+
it "creates a Lines" do
|
49
|
+
MTK::Patterns.PitchLines(1,2,3).should be_a MTK::Patterns::Lines
|
50
|
+
end
|
51
|
+
|
52
|
+
it "sets #elements from the varargs" do
|
53
|
+
MTK::Patterns.PitchLines(1,2,3).elements.should == [Pitch(1),Pitch(2),Pitch(3)]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#IntensityLines" do
|
58
|
+
it "creates a Lines" do
|
59
|
+
MTK::Patterns.IntensityLines(1,2,3).should be_a MTK::Patterns::Lines
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sets #elements from the varargs" do
|
63
|
+
MTK::Patterns.IntensityLines(1,2,3).elements.should == [Intensity(1),Intensity(2),Intensity(3)]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#DurationLines" do
|
68
|
+
it "creates a Lines" do
|
69
|
+
MTK::Patterns.DurationLines(1,2,3).should be_a MTK::Patterns::Lines
|
70
|
+
end
|
71
|
+
|
72
|
+
it "sets #elements from the varargs" do
|
73
|
+
MTK::Patterns.DurationLines(1,2,3).elements.should == [Duration(1),Duration(2),Duration(3)]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|