mtk 0.0.1 → 0.0.2
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 +9 -0
- data/INTRO.md +73 -0
- data/LICENSE.txt +27 -0
- data/README.md +93 -18
- data/Rakefile +13 -1
- data/examples/crescendo.rb +20 -0
- data/examples/dynamic_pattern.rb +39 -0
- data/examples/play_midi.rb +19 -0
- data/examples/print_midi.rb +13 -0
- data/examples/random_tone_row.rb +18 -0
- data/examples/tone_row_melody.rb +21 -0
- data/lib/mtk/_constants/durations.rb +80 -0
- data/lib/mtk/_constants/intensities.rb +81 -0
- data/lib/mtk/{constants → _constants}/intervals.rb +10 -1
- data/lib/mtk/_constants/pitch_classes.rb +35 -0
- data/lib/mtk/_constants/pitches.rb +49 -0
- data/lib/mtk/{numeric_extensions.rb → _numeric_extensions.rb} +0 -0
- data/lib/mtk/event.rb +14 -5
- data/lib/mtk/helper/collection.rb +114 -0
- data/lib/mtk/helper/event_builder.rb +85 -0
- data/lib/mtk/{constants → helper}/pseudo_constants.rb +7 -6
- data/lib/mtk/lang/grammar.rb +17 -0
- data/lib/mtk/lang/mtk_grammar.citrus +60 -0
- data/lib/mtk/midi/file.rb +10 -15
- data/lib/mtk/midi/jsound_input.rb +68 -0
- data/lib/mtk/midi/jsound_output.rb +80 -0
- data/lib/mtk/note.rb +22 -3
- data/lib/mtk/pattern/abstract_pattern.rb +132 -0
- data/lib/mtk/pattern/choice.rb +25 -9
- data/lib/mtk/pattern/cycle.rb +51 -0
- data/lib/mtk/pattern/enumerator.rb +26 -0
- data/lib/mtk/pattern/function.rb +46 -0
- data/lib/mtk/pattern/lines.rb +60 -0
- data/lib/mtk/pattern/palindrome.rb +42 -0
- data/lib/mtk/pattern/sequence.rb +15 -50
- data/lib/mtk/pitch.rb +45 -6
- data/lib/mtk/pitch_class.rb +36 -35
- data/lib/mtk/pitch_class_set.rb +46 -14
- data/lib/mtk/pitch_set.rb +20 -31
- data/lib/mtk/sequencer/abstract_sequencer.rb +85 -0
- data/lib/mtk/sequencer/rhythmic_sequencer.rb +29 -0
- data/lib/mtk/sequencer/step_sequencer.rb +26 -0
- data/lib/mtk/timeline.rb +75 -22
- data/lib/mtk/transform/invertible.rb +15 -0
- data/lib/mtk/{util → transform}/mappable.rb +6 -2
- data/lib/mtk/transform/set_theory_operations.rb +34 -0
- data/lib/mtk/transform/transposable.rb +14 -0
- data/lib/mtk.rb +56 -22
- data/spec/mtk/_constants/durations_spec.rb +118 -0
- data/spec/mtk/{constants/dynamics_spec.rb → _constants/intensities_spec.rb} +48 -17
- data/spec/mtk/{constants → _constants}/intervals_spec.rb +21 -0
- data/spec/mtk/_constants/pitch_classes_spec.rb +58 -0
- data/spec/mtk/_constants/pitches_spec.rb +52 -0
- data/spec/mtk/{numeric_extensions_spec.rb → _numeric_extensions_spec.rb} +0 -0
- data/spec/mtk/event_spec.rb +19 -0
- data/spec/mtk/helper/collection_spec.rb +291 -0
- data/spec/mtk/helper/event_builder_spec.rb +92 -0
- data/spec/mtk/helper/pseudo_constants_spec.rb +20 -0
- data/spec/mtk/lang/grammar_spec.rb +100 -0
- data/spec/mtk/midi/file_spec.rb +41 -6
- data/spec/mtk/note_spec.rb +53 -3
- data/spec/mtk/pattern/abstract_pattern_spec.rb +45 -0
- data/spec/mtk/pattern/choice_spec.rb +89 -3
- data/spec/mtk/pattern/cycle_spec.rb +133 -0
- data/spec/mtk/pattern/function_spec.rb +133 -0
- data/spec/mtk/pattern/lines_spec.rb +93 -0
- data/spec/mtk/pattern/note_cycle_spec.rb.bak +116 -0
- data/spec/mtk/pattern/palindrome_spec.rb +124 -0
- data/spec/mtk/pattern/pitch_cycle_spec.rb.bak +47 -0
- data/spec/mtk/pattern/pitch_sequence_spec.rb.bak +37 -0
- data/spec/mtk/pattern/sequence_spec.rb +128 -31
- data/spec/mtk/pitch_class_set_spec.rb +240 -7
- data/spec/mtk/pitch_class_spec.rb +84 -18
- data/spec/mtk/pitch_set_spec.rb +45 -10
- data/spec/mtk/pitch_spec.rb +59 -0
- data/spec/mtk/sequencer/abstract_sequencer_spec.rb +159 -0
- data/spec/mtk/sequencer/rhythmic_sequencer_spec.rb +49 -0
- data/spec/mtk/sequencer/step_sequencer_spec.rb +71 -0
- data/spec/mtk/timeline_spec.rb +118 -15
- data/spec/spec_helper.rb +4 -3
- metadata +59 -22
- data/lib/mtk/chord.rb +0 -47
- data/lib/mtk/constants/dynamics.rb +0 -56
- data/lib/mtk/constants/pitch_classes.rb +0 -18
- data/lib/mtk/constants/pitches.rb +0 -24
- data/lib/mtk/pattern/note_sequence.rb +0 -60
- data/lib/mtk/pattern/pitch_sequence.rb +0 -22
- data/lib/mtk/patterns.rb +0 -4
- data/spec/mtk/chord_spec.rb +0 -74
- data/spec/mtk/constants/pitch_classes_spec.rb +0 -35
- data/spec/mtk/constants/pitches_spec.rb +0 -23
- data/spec/mtk/pattern/note_sequence_spec.rb +0 -121
- data/spec/mtk/pattern/pitch_sequence_spec.rb +0 -47
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MTK::Pitches do
|
4
|
-
|
5
|
-
it "defines constants for the 128 notes in MIDI" do
|
6
|
-
Pitches.constants.length.should == 129 # there's also the PITCHES constant
|
7
|
-
Pitches::C_1.should == Pitch.from_s('C-1')
|
8
|
-
Pitches::D0.should == Pitch.from_s('D0')
|
9
|
-
Pitches::Eb1.should == Pitch.from_s('Eb1')
|
10
|
-
Pitches::G9.should == Pitch.from_s('g9')
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "PITCHES" do
|
14
|
-
it "contains all 128 pitch constants" do
|
15
|
-
Pitches::PITCHES.length.should == 128
|
16
|
-
Pitches::PITCHES.should include Pitches::C_1
|
17
|
-
Pitches::PITCHES.should include Pitches::D0
|
18
|
-
Pitches::PITCHES.should include Pitches::Eb1
|
19
|
-
Pitches::PITCHES.should include Pitches::G9
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MTK::Pattern::NoteSequence do
|
4
|
-
|
5
|
-
def note(pitch, intensity=mf, duration=1)
|
6
|
-
Note.new pitch,intensity,duration
|
7
|
-
end
|
8
|
-
|
9
|
-
def chord(pitches, intensity=mf, duration=1)
|
10
|
-
Chord.new pitches,intensity,duration
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "#new" do
|
14
|
-
it "allows default pitch to be specified"
|
15
|
-
it "allows default intensity to be specified"
|
16
|
-
it "allows default duration to be specified"
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#next" do
|
20
|
-
it "iterates through the pitch, intensity, and duration list in parallel to emit Notes" do
|
21
|
-
sequence = Pattern::NoteSequence.new [C4, D4, E4], [p, f], [1,2,3,4]
|
22
|
-
sequence.next.should == Note.new(C4, p, 1)
|
23
|
-
sequence.next.should == Note.new(D4, f, 2)
|
24
|
-
sequence.next.should == Note.new(E4, p, 3)
|
25
|
-
sequence.next.should == Note.new(C4, f, 4)
|
26
|
-
sequence.next.should == Note.new(D4, p, 1)
|
27
|
-
sequence.next.should == Note.new(E4, f, 2)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "defaults to Pitch 'C4' when no pitches are given" do
|
31
|
-
sequence = Pattern::NoteSequence.new [], [p,f], [1,2,3]
|
32
|
-
sequence.next.should == Note.new(C4, p, 1)
|
33
|
-
sequence.next.should == Note.new(C4, f, 2)
|
34
|
-
sequence.next.should == Note.new(C4, p, 3)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "defaults to intensity 'mf' when no intensities are given" do
|
38
|
-
sequence = Pattern::NoteSequence.new [C4, D4, E4], nil, [2]
|
39
|
-
sequence.next.should == Note.new(C4, mf, 2)
|
40
|
-
sequence.next.should == Note.new(D4, mf, 2)
|
41
|
-
sequence.next.should == Note.new(E4, mf, 2)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "defaults to duration 1 when no durations are given" do
|
45
|
-
sequence = Pattern::NoteSequence.new [C4, D4, E4], [p, f]
|
46
|
-
sequence.next.should == Note.new(C4, p, 1)
|
47
|
-
sequence.next.should == Note.new(D4, f, 1)
|
48
|
-
sequence.next.should == Note.new(E4, p, 1)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "uses the previous pitch/intensity/duration when it encounters a nil value" do
|
52
|
-
sequence = Pattern::NoteSequence.new [C4, D4, E4, F4, nil], [mp, mf, f, nil], [1, 2, nil]
|
53
|
-
sequence.next.should == Note.new(C4, mp, 1)
|
54
|
-
sequence.next.should == Note.new(D4, mf, 2)
|
55
|
-
sequence.next.should == Note.new(E4, f, 2)
|
56
|
-
sequence.next.should == Note.new(F4, f, 1)
|
57
|
-
sequence.next.should == Note.new(F4, mp, 2)
|
58
|
-
sequence.next.should == Note.new(C4, mf, 2)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "adds Numeric intervals in the pitch list to the previous pitch" do
|
62
|
-
sequence = Pattern::NoteSequence.new [C4, 1, 2, 3]
|
63
|
-
sequence.next.should == note(C4)
|
64
|
-
sequence.next.should == note(C4+1)
|
65
|
-
sequence.next.should == note(C4+1+2)
|
66
|
-
sequence.next.should == note(C4+1+2+3)
|
67
|
-
sequence.next.should == note(C4)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "goes to the nearest Pitch for any PitchClasses in the pitch list" do
|
71
|
-
sequence = Pattern::NoteSequence.new [C4, F, C, G, C]
|
72
|
-
sequence.next.should == note(C4)
|
73
|
-
sequence.next.should == note(F4)
|
74
|
-
sequence.next.should == note(C4)
|
75
|
-
sequence.next.should == note(G3)
|
76
|
-
sequence.next.should == note(C4)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "does not endlessly ascend or descend when alternating between two pitch classes a tritone apart" do
|
80
|
-
sequence = Pattern::NoteSequence.new [C4, Gb, C, Gb, C]
|
81
|
-
sequence.next.should == note(C4)
|
82
|
-
sequence.next.should == note(Gb4)
|
83
|
-
sequence.next.should == note(C4)
|
84
|
-
sequence.next.should == note(Gb4)
|
85
|
-
sequence.next.should == note(C4)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "sequences Chords for pitch list items that are PitchSets" do
|
89
|
-
sequence = Pattern::NoteSequence.new [PitchSet.new([C4, E4, G4]), C4, PitchSet.new([D4, F4, A4])]
|
90
|
-
sequence.next.should == chord([C4, E4, G4])
|
91
|
-
sequence.next.should == note(C4)
|
92
|
-
sequence.next.should == chord([D4, F4, A4])
|
93
|
-
end
|
94
|
-
|
95
|
-
it "adds numeric intervals to PitchSets" do
|
96
|
-
sequence = Pattern::NoteSequence.new [PitchSet.new([C4, E4, G4]), 2]
|
97
|
-
sequence.next.should == chord([C4, E4, G4])
|
98
|
-
sequence.next.should == chord([D4, Gb4, A4])
|
99
|
-
end
|
100
|
-
|
101
|
-
it "goes to the nearest Pitch relative to the lowest note in the PitchSet for any PitchClasses in the pitch list" do
|
102
|
-
sequence = Pattern::NoteSequence.new [PitchSet.new([C4, E4, G4]), F, D, Bb]
|
103
|
-
sequence.next.should == chord([C4, E4, G4])
|
104
|
-
sequence.next.should == chord([F4, A4, C5])
|
105
|
-
sequence.next.should == chord([D4, Gb4, A4])
|
106
|
-
sequence.next.should == chord([Bb3, D4, F4])
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe "#reset" do
|
111
|
-
it "resets the sequence to the beginning" do
|
112
|
-
sequence = Pattern::NoteSequence.new [C4, D4, E4], [p, f], [1,2,3,4]
|
113
|
-
sequence.next.should == Note.new(C4, p, 1)
|
114
|
-
sequence.next.should == Note.new(D4, f, 2)
|
115
|
-
sequence.reset
|
116
|
-
sequence.next.should == Note.new(C4, p, 1)
|
117
|
-
sequence.next.should == Note.new(D4, f, 2)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MTK::Pattern::PitchSequence do
|
4
|
-
|
5
|
-
describe "#next" do
|
6
|
-
it "enumerates Pitches" do
|
7
|
-
sequence = Pattern::PitchSequence.new [C4, D4, E4]
|
8
|
-
sequence.next.should == C4
|
9
|
-
sequence.next.should == D4
|
10
|
-
sequence.next.should == E4
|
11
|
-
end
|
12
|
-
|
13
|
-
it "adds Numeric elements (intervals) to the previous pitch" do
|
14
|
-
sequence = Pattern::PitchSequence.new [C4, 1, 2, 3]
|
15
|
-
sequence.next.should == C4
|
16
|
-
sequence.next.should == C4+1
|
17
|
-
sequence.next.should == C4+1+2
|
18
|
-
sequence.next.should == C4+1+2+3
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns a Pitch when encountering a Pitch after another type" do
|
22
|
-
sequence = Pattern::PitchSequence.new [C4, 1, C4]
|
23
|
-
sequence.next
|
24
|
-
sequence.next
|
25
|
-
sequence.next.should == C4
|
26
|
-
end
|
27
|
-
|
28
|
-
it "goes to the nearest Pitch for any PitchClasses in the pitch list" do
|
29
|
-
sequence = Pattern::PitchSequence.new [C4, F, C, G, C]
|
30
|
-
sequence.next.should == C4
|
31
|
-
sequence.next.should == F4
|
32
|
-
sequence.next.should == C4
|
33
|
-
sequence.next.should == G3
|
34
|
-
sequence.next.should == C4
|
35
|
-
end
|
36
|
-
|
37
|
-
it "does not endlessly ascend or descend when alternating between two pitch classes a tritone apart" do
|
38
|
-
sequencer = Pattern::PitchSequence.new [C4, Gb, C, Gb, C]
|
39
|
-
sequencer.next.should == C4
|
40
|
-
sequencer.next.should == Gb4
|
41
|
-
sequencer.next.should == C4
|
42
|
-
sequencer.next.should == Gb4
|
43
|
-
sequencer.next.should == C4
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|