mtk 0.0.3.2 → 0.0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +2 -2
- data/DEVELOPMENT_NOTES.md +20 -0
- data/README.md +9 -3
- data/Rakefile +47 -13
- data/bin/mtk +55 -20
- data/examples/crescendo.rb +4 -4
- data/examples/{drum_pattern1.rb → drum_pattern.rb} +8 -8
- data/examples/dynamic_pattern.rb +5 -5
- data/examples/gets_and_play.rb +3 -2
- data/examples/notation.rb +3 -3
- data/examples/play_midi.rb +4 -4
- data/examples/print_midi.rb +2 -2
- data/examples/random_tone_row.rb +3 -3
- data/examples/syntax_to_midi.rb +2 -2
- data/examples/test_output.rb +4 -5
- data/examples/tone_row_melody.rb +7 -5
- 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 +4 -4
- data/lib/mtk/events/note.rb +12 -12
- data/lib/mtk/events/timeline.rb +232 -0
- data/lib/mtk/groups/chord.rb +56 -0
- data/lib/mtk/{helpers → groups}/collection.rb +33 -1
- data/lib/mtk/groups/melody.rb +96 -0
- data/lib/mtk/groups/pitch_class_set.rb +163 -0
- data/lib/mtk/{helpers → groups}/pitch_collection.rb +1 -1
- data/lib/mtk/{midi → io}/dls_synth_device.rb +3 -1
- data/lib/mtk/{midi → io}/dls_synth_output.rb +10 -10
- data/lib/mtk/{midi → io}/jsound_input.rb +2 -2
- data/lib/mtk/{midi → io}/jsound_output.rb +9 -9
- data/lib/mtk/{midi/file.rb → io/midi_file.rb} +13 -13
- data/lib/mtk/{midi/input.rb → io/midi_input.rb} +4 -4
- data/lib/mtk/{midi/output.rb → io/midi_output.rb} +8 -8
- data/lib/mtk/{helpers/lilypond.rb → io/notation.rb} +5 -5
- data/lib/mtk/{midi → io}/unimidi_input.rb +2 -2
- data/lib/mtk/{midi → io}/unimidi_output.rb +14 -9
- data/lib/mtk/{constants → lang}/durations.rb +11 -11
- data/lib/mtk/{constants → lang}/intensities.rb +11 -11
- data/lib/mtk/{constants → lang}/intervals.rb +17 -17
- data/lib/mtk/lang/mtk_grammar.citrus +9 -9
- data/lib/mtk/{constants → lang}/pitch_classes.rb +5 -5
- data/lib/mtk/{constants → lang}/pitches.rb +7 -7
- data/lib/mtk/{helpers → lang}/pseudo_constants.rb +1 -1
- data/lib/mtk/{variable.rb → lang/variable.rb} +1 -1
- data/lib/mtk/numeric_extensions.rb +40 -47
- data/lib/mtk/patterns/for_each.rb +1 -1
- data/lib/mtk/patterns/pattern.rb +3 -3
- data/lib/mtk/sequencers/event_builder.rb +16 -15
- data/lib/mtk/sequencers/legato_sequencer.rb +1 -1
- data/lib/mtk/sequencers/rhythmic_sequencer.rb +1 -1
- data/lib/mtk/sequencers/sequencer.rb +8 -8
- data/lib/mtk/sequencers/step_sequencer.rb +2 -2
- data/lib/mtk.rb +33 -39
- data/spec/mtk/{duration_spec.rb → core/duration_spec.rb} +3 -3
- data/spec/mtk/{intensity_spec.rb → core/intensity_spec.rb} +3 -3
- data/spec/mtk/{interval_spec.rb → core/interval_spec.rb} +1 -1
- data/spec/mtk/{pitch_class_spec.rb → core/pitch_class_spec.rb} +1 -1
- data/spec/mtk/{pitch_spec.rb → core/pitch_spec.rb} +8 -8
- data/spec/mtk/events/event_spec.rb +4 -4
- data/spec/mtk/events/note_spec.rb +8 -8
- data/spec/mtk/{timeline_spec.rb → events/timeline_spec.rb} +47 -47
- data/spec/mtk/{chord_spec.rb → groups/chord_spec.rb} +18 -16
- data/spec/mtk/{helpers → groups}/collection_spec.rb +3 -3
- data/spec/mtk/{melody_spec.rb → groups/melody_spec.rb} +36 -34
- data/spec/mtk/{pitch_class_set_spec.rb → groups/pitch_class_set_spec.rb} +57 -55
- data/spec/mtk/{midi/file_spec.rb → io/midi_file_spec.rb} +17 -17
- data/spec/mtk/{midi/output_spec.rb → io/midi_output_spec.rb} +6 -6
- data/spec/mtk/{constants → lang}/durations_spec.rb +1 -1
- data/spec/mtk/{constants → lang}/intensities_spec.rb +1 -1
- data/spec/mtk/{constants → lang}/intervals_spec.rb +1 -1
- data/spec/mtk/lang/parser_spec.rb +12 -6
- data/spec/mtk/{constants → lang}/pitch_classes_spec.rb +1 -1
- data/spec/mtk/{constants → lang}/pitches_spec.rb +1 -1
- data/spec/mtk/{helpers → lang}/pseudo_constants_spec.rb +2 -2
- data/spec/mtk/{variable_spec.rb → lang/variable_spec.rb} +4 -4
- data/spec/mtk/numeric_extensions_spec.rb +35 -55
- data/spec/mtk/patterns/for_each_spec.rb +1 -1
- data/spec/mtk/patterns/sequence_spec.rb +1 -1
- data/spec/mtk/sequencers/legato_sequencer_spec.rb +2 -2
- data/spec/mtk/sequencers/rhythmic_sequencer_spec.rb +4 -4
- data/spec/mtk/sequencers/step_sequencer_spec.rb +5 -5
- data/spec/spec_helper.rb +7 -6
- metadata +75 -61
- data/ext/mkrf_conf.rb +0 -25
- data/lib/mtk/chord.rb +0 -55
- data/lib/mtk/duration.rb +0 -211
- data/lib/mtk/helpers/convert.rb +0 -36
- data/lib/mtk/helpers/output_selector.rb +0 -67
- data/lib/mtk/intensity.rb +0 -156
- data/lib/mtk/interval.rb +0 -155
- data/lib/mtk/melody.rb +0 -94
- data/lib/mtk/pitch.rb +0 -152
- data/lib/mtk/pitch_class.rb +0 -192
- data/lib/mtk/pitch_class_set.rb +0 -161
- data/lib/mtk/timeline.rb +0 -230
- data/spec/mtk/midi/jsound_input_spec.rb +0 -11
- data/spec/mtk/midi/jsound_output_spec.rb +0 -11
- data/spec/mtk/midi/unimidi_input_spec.rb +0 -11
- data/spec/mtk/midi/unimidi_output_spec.rb +0 -11
data/.yardopts
CHANGED
data/DEVELOPMENT_NOTES.md
CHANGED
@@ -113,3 +113,23 @@ or, to automatically refresh the documentation as you work:
|
|
113
113
|
|
114
114
|
bundle exec yard server -r
|
115
115
|
open http://localhost:8808
|
116
|
+
|
117
|
+
|
118
|
+
### Release the gems ###
|
119
|
+
|
120
|
+
To better handle the differing depdencies between CRuby and JRuby, there are two gems, mtk and jmtk.
|
121
|
+
You can build both gems with:
|
122
|
+
|
123
|
+
bundle exec gem:build
|
124
|
+
|
125
|
+
Do a local sanity check by installing
|
126
|
+
|
127
|
+
# Using CRuby 1.9 or 2.0:
|
128
|
+
gem install mtk-0.x.x.gem
|
129
|
+
... test mtk command ...
|
130
|
+
|
131
|
+
rvm use jruby
|
132
|
+
jgem install jmtk-0.x.x-java.gem
|
133
|
+
... test jmtk command ...
|
134
|
+
|
135
|
+
And then authorized users can push gems to rubygems.org.
|
data/README.md
CHANGED
@@ -19,20 +19,26 @@ Features
|
|
19
19
|
Getting Started
|
20
20
|
---------------
|
21
21
|
|
22
|
-
MTK works with Ruby 1.9, Ruby 2.0, and JRuby
|
22
|
+
MTK works with Ruby 1.9, Ruby 2.0, and JRuby 1.7+.
|
23
|
+
|
24
|
+
JRuby is recommended for Windows users.
|
23
25
|
|
24
26
|
0. Install
|
25
27
|
|
26
28
|
gem install mtk
|
27
29
|
|
28
|
-
|
30
|
+
Or for JRuby:
|
29
31
|
|
30
|
-
jgem install
|
32
|
+
jgem install jmtk
|
31
33
|
|
32
34
|
0. Learn the command-line interface:
|
33
35
|
|
34
36
|
mtk --help
|
35
37
|
|
38
|
+
Or for JRuby:
|
39
|
+
|
40
|
+
jmtk --help
|
41
|
+
|
36
42
|
0. Learn the MTK syntax: TODO... documentation forthcoming. In the meantime, see the unit tests @ https://github.com/adamjmurray/mtk/blob/master/spec/mtk/lang/parser_spec.rb
|
37
43
|
|
38
44
|
0. Check out examples: https://github.com/adamjmurray/mtk/tree/master/examples
|
data/Rakefile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
require 'rspec/core/rake_task'
|
2
2
|
require 'rake/clean'
|
3
3
|
|
4
|
+
GEM_VERSION = '0.0.3.3'
|
5
|
+
|
4
6
|
SUPPORTED_RUBIES = %w[ 1.9.3 2.0 jruby-1.7.4 ]
|
5
|
-
|
7
|
+
|
8
|
+
CLEAN.include('html','doc','coverage.data','coverage', '*.gemspec', '*.gem') # clean and clobber do the same thing for now
|
6
9
|
|
7
10
|
task :default => :test
|
8
11
|
|
9
|
-
CLEAN.include('html','doc','coverage.data','coverage', '*.gem') # clean and clobber do the same thing for now
|
10
12
|
|
11
13
|
desc "Run RSpec tests with full output"
|
12
14
|
RSpec::Core::RakeTask.new('test') do |spec|
|
@@ -16,17 +18,7 @@ RSpec::Core::RakeTask.new('test') do |spec|
|
|
16
18
|
spec.pattern = "spec/**/#{ARGV[1]}*"
|
17
19
|
end
|
18
20
|
end
|
19
|
-
|
20
|
-
task :spec => :test
|
21
|
-
|
22
|
-
|
23
|
-
namespace :gem do
|
24
|
-
desc "Install gems for supported versions of Ruby: #{SUPPORTED_RUBIES.join ', '}"
|
25
|
-
task :install_dependencies do
|
26
|
-
fail unless system("rvm #{SUPPORTED_RUBIES.join ','} do bundle install")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
21
|
+
task :spec => :test # alias test task as spec task
|
30
22
|
|
31
23
|
namespace :test do
|
32
24
|
desc "Run RSpec tests with summary output and fast failure"
|
@@ -64,3 +56,45 @@ begin
|
|
64
56
|
end
|
65
57
|
rescue Exception # yard is optional, so don't cause rake to fail if it's missing
|
66
58
|
end
|
59
|
+
|
60
|
+
|
61
|
+
namespace :gem do
|
62
|
+
desc "Install gems for supported versions of Ruby: #{SUPPORTED_RUBIES.join ', '}"
|
63
|
+
task :install_dependencies do
|
64
|
+
fail unless system("rvm #{SUPPORTED_RUBIES.join ','} do bundle install")
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "Build the CRuby and JRuby gems for distribution"
|
68
|
+
task :build do
|
69
|
+
gem_version = GEM_VERSION
|
70
|
+
|
71
|
+
gem_name = 'mtk'
|
72
|
+
platform_specific_depedencies = {unimidi:'~> 0.3'}
|
73
|
+
additional_gem_specifications = {}
|
74
|
+
generate_gemspec(binding)
|
75
|
+
|
76
|
+
gem_name = 'jmtk'
|
77
|
+
platform_specific_depedencies = {jsound:'~> 0.1'}
|
78
|
+
additional_gem_specifications = {platform:'java'}
|
79
|
+
generate_gemspec(binding)
|
80
|
+
end
|
81
|
+
|
82
|
+
def generate_gemspec(erb_bindings)
|
83
|
+
gem_name = erb_bindings.eval('gem_name')
|
84
|
+
|
85
|
+
erb = ERB.new(IO.read 'mtk.gemspec.erb')
|
86
|
+
gemspec = erb.result(erb_bindings)
|
87
|
+
|
88
|
+
gemspec_filename = "#{gem_name}.gemspec"
|
89
|
+
puts "Generating #{gemspec_filename}"
|
90
|
+
IO.write(gemspec_filename, gemspec)
|
91
|
+
|
92
|
+
if gem_name == 'jmtk'
|
93
|
+
`cp bin/mtk bin/jmtk` # jmtk gem uses this as the binary
|
94
|
+
end
|
95
|
+
puts "Building gem"
|
96
|
+
puts `gem build #{gemspec_filename}`
|
97
|
+
ensure
|
98
|
+
`rm bin/jmtk`
|
99
|
+
end
|
100
|
+
end
|
data/bin/mtk
CHANGED
@@ -23,13 +23,12 @@ option_parser = OptionParser.new do |opts|
|
|
23
23
|
|
24
24
|
opts.on('-e [syntax]', '--eval [syntax]', 'Convert the given MTK syntax String to MIDI',
|
25
25
|
'or start an interactive interpreter when [syntax] is omitted',
|
26
|
-
'
|
27
|
-
'if an --output is given, play the MIDI',
|
28
|
-
'otherwise print the MIDI') {|syntax| options[:eval] = syntax }
|
26
|
+
'Behaves like --convert when a --file or --output is given') {|syntax| options[:eval] = syntax }
|
29
27
|
|
30
28
|
opts.separator ''
|
31
29
|
|
32
|
-
opts.on('-f FILE', '--file FILE', 'Write the output of --convert, --eval, or --
|
30
|
+
opts.on('-f FILE', '--file FILE', 'Write the output of --convert, --eval, --input, or --watch to a file'
|
31
|
+
) {|file| options[:file] = file }
|
33
32
|
|
34
33
|
opts.separator ''
|
35
34
|
|
@@ -63,6 +62,9 @@ option_parser = OptionParser.new do |opts|
|
|
63
62
|
#
|
64
63
|
#opts.separator ''
|
65
64
|
|
65
|
+
opts.on('-w FILE', '--watch FILE', 'Watch an MTK syntax file for changes and automatically convert to MIDI',
|
66
|
+
'Behaves like --convert when a --file or --output is given') {|file| options[:watch] = file }
|
67
|
+
|
66
68
|
end
|
67
69
|
|
68
70
|
|
@@ -79,7 +81,7 @@ ERROR_INPUT_NOT_FOUND = 4
|
|
79
81
|
|
80
82
|
# Immediately trying to play output while Ruby is still "warming up" can cause timing issues with
|
81
83
|
# the first couple notes. So we play this "empty" Timeline containing a rest to address that issue.
|
82
|
-
WARMUP = MTK::Timeline.
|
84
|
+
WARMUP = MTK::Events::Timeline.from_h( {0 => MTK.Note(60,-1)} )
|
83
85
|
|
84
86
|
#######################################################################
|
85
87
|
|
@@ -88,20 +90,25 @@ begin
|
|
88
90
|
rescue OptionParser::MissingArgument, OptionParser::InvalidOption
|
89
91
|
puts "Invalid command, #{$!}"
|
90
92
|
puts "For command line help: #{$0} --help"
|
93
|
+
puts "For command line help: #{$0} --help"
|
91
94
|
exit ERROR_INVALID_COMMAND
|
92
95
|
end
|
93
96
|
|
94
97
|
|
95
98
|
def setup_io
|
96
|
-
require 'mtk/
|
97
|
-
require 'mtk/
|
99
|
+
require 'mtk/io/midi_input'
|
100
|
+
require 'mtk/io/midi_output'
|
98
101
|
end
|
99
102
|
|
100
103
|
|
101
104
|
def convert(mtk_syntax)
|
102
105
|
sequencer = MTK::Lang::Parser.parse(mtk_syntax)
|
103
|
-
|
104
|
-
|
106
|
+
if sequencer
|
107
|
+
timeline = sequencer.to_timeline
|
108
|
+
output(timeline)
|
109
|
+
end
|
110
|
+
rescue Citrus::ParseError
|
111
|
+
STDERR.puts $!
|
105
112
|
end
|
106
113
|
|
107
114
|
|
@@ -111,8 +118,8 @@ def output(timelines, print_header='Timeline')
|
|
111
118
|
@output.play WARMUP
|
112
119
|
@output.play timelines.first # TODO: support multiple timelines
|
113
120
|
elsif @file
|
114
|
-
require 'mtk/
|
115
|
-
MTK
|
121
|
+
require 'mtk/io/midi_file'
|
122
|
+
MTK.MIDIFile(@file).write timelines
|
116
123
|
else
|
117
124
|
puts print_header, timelines
|
118
125
|
puts
|
@@ -136,12 +143,20 @@ def record
|
|
136
143
|
end
|
137
144
|
|
138
145
|
|
146
|
+
def watch_file_updated?
|
147
|
+
mtime = File.stat(@watch_file).mtime
|
148
|
+
updated = @watch_file_mtime.nil? || @watch_file_mtime < mtime
|
149
|
+
@watch_file_mtime = mtime
|
150
|
+
updated
|
151
|
+
end
|
152
|
+
|
153
|
+
|
139
154
|
#######################################################################
|
140
155
|
|
141
156
|
if options[:list]
|
142
157
|
setup_io
|
143
|
-
input_names = MTK::
|
144
|
-
output_names = MTK::
|
158
|
+
input_names = MTK::IO::MIDIInput.devices_by_name.keys
|
159
|
+
output_names = MTK::IO::MIDIOutput.devices_by_name.keys
|
145
160
|
puts
|
146
161
|
puts (['INPUTS:'] + input_names).join("\n * ")
|
147
162
|
puts
|
@@ -158,7 +173,7 @@ end
|
|
158
173
|
if options[:input]
|
159
174
|
setup_io
|
160
175
|
input_name = options[:input]
|
161
|
-
@input = MTK::
|
176
|
+
@input = MTK::IO::MIDIInput.find_by_name /#{input_name}/
|
162
177
|
if @input
|
163
178
|
puts "Using input '#{@input.name}'"
|
164
179
|
else
|
@@ -170,7 +185,7 @@ end
|
|
170
185
|
if options[:output]
|
171
186
|
setup_io
|
172
187
|
output_name = options[:output]
|
173
|
-
@output = MTK::
|
188
|
+
@output = MTK::IO::MIDIOutput.find_by_name /#{output_name}/
|
174
189
|
if @output
|
175
190
|
puts "Using output '#{@output.name}'"
|
176
191
|
else
|
@@ -184,8 +199,8 @@ file = options[:file]
|
|
184
199
|
|
185
200
|
if options[:play]
|
186
201
|
filename = options[:play]
|
187
|
-
require 'mtk/
|
188
|
-
timelines = MTK
|
202
|
+
require 'mtk/io/midi_file'
|
203
|
+
timelines = MTK.MIDIFile(filename).to_timelines
|
189
204
|
output(timelines, "Timeline for #{filename}")
|
190
205
|
end
|
191
206
|
|
@@ -193,9 +208,13 @@ if options.has_key? :eval
|
|
193
208
|
mtk_syntax = options[:eval]
|
194
209
|
if mtk_syntax.nil?
|
195
210
|
puts "Starting the interactive interpreter."
|
196
|
-
|
197
|
-
|
198
|
-
|
211
|
+
begin
|
212
|
+
loop do
|
213
|
+
puts "Enter MTK syntax. Press Ctrl+C to exit."
|
214
|
+
convert(gets)
|
215
|
+
end
|
216
|
+
rescue SystemExit,Interrupt
|
217
|
+
Kernel.exit
|
199
218
|
end
|
200
219
|
else
|
201
220
|
convert(mtk_syntax)
|
@@ -208,6 +227,22 @@ if options[:convert]
|
|
208
227
|
convert(mtk_syntax)
|
209
228
|
end
|
210
229
|
|
230
|
+
if options[:watch]
|
231
|
+
@watch_file = options[:watch]
|
232
|
+
puts "Watching #{@watch_file}. Press Ctrl+C to exit."
|
233
|
+
watch_file_updated? # prime the watcher
|
234
|
+
begin
|
235
|
+
loop do
|
236
|
+
mtk_syntax = IO.read(@watch_file)
|
237
|
+
convert(mtk_syntax)
|
238
|
+
Kernel.sleep(0.5) until watch_file_updated?
|
239
|
+
puts "#{Time.new}: #{@watch_file} updated"
|
240
|
+
end
|
241
|
+
rescue SystemExit,Interrupt
|
242
|
+
Kernel.exit
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
211
246
|
#if options.has_key? :tutorial
|
212
247
|
# puts "TODO: tutorial"
|
213
248
|
#end
|
data/examples/crescendo.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
# NOTE: this blindly overwrites any existing MTK-crescendo.mid file, unless an argument is provided
|
4
4
|
|
5
5
|
require 'mtk'
|
6
|
-
require 'mtk/
|
6
|
+
require 'mtk/io/midi_file'
|
7
7
|
include MTK
|
8
|
-
include
|
9
|
-
include
|
8
|
+
include Lang::Pitches
|
9
|
+
include Lang::Intensities
|
10
10
|
|
11
11
|
file = ARGV[0] || 'MTK-crescendo.mid'
|
12
12
|
|
@@ -16,5 +16,5 @@ crescendo = Patterns.Lines pp, [fff, scale.length-1] # step from pp to fff over
|
|
16
16
|
sequencer = Sequencers.StepSequencer scale, crescendo
|
17
17
|
timeline = sequencer.to_timeline
|
18
18
|
|
19
|
-
|
19
|
+
MIDIFile(file).write timeline
|
20
20
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'mtk'
|
2
|
-
require 'mtk/
|
2
|
+
require 'mtk/io/midi_file'
|
3
3
|
include MTK
|
4
|
-
include
|
5
|
-
include
|
4
|
+
include Lang::Pitches
|
5
|
+
include Lang::Intensities
|
6
6
|
|
7
7
|
file = ARGV[0] || "MTK-#{File.basename(__FILE__,'.rb')}.mid"
|
8
8
|
|
@@ -10,14 +10,14 @@ _ = nil # defines _ as a rest
|
|
10
10
|
|
11
11
|
pattern = {# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
12
12
|
C2 => [fff, _, _, _, mf, _, _, _, o, _, _, _, mp, _, _, _], # kick
|
13
|
-
Db2 => [ _, _, o, _, _, _, mp, _, _, _, o, _, _, _, mf, _], #
|
14
|
-
D2 => [ _, mp, _, mp, _, mp, _, mf, _, mp, _, mp, _, pp, _, mf] #
|
13
|
+
Db2 => [ _, _, o, _, _, _, mp, _, _, _, o, _, _, _, mf, _], # rim shot
|
14
|
+
D2 => [ _, mp, _, mp, _, mp, _, mf, _, mp, _, mp, _, pp, _, mf] # snare
|
15
15
|
}
|
16
16
|
|
17
|
-
timeline = Timeline.new
|
17
|
+
timeline = Events::Timeline.new
|
18
18
|
for pitch,intensities in pattern
|
19
|
-
track = Sequencers::StepSequencer( Patterns.Sequence(intensities), default_pitch:
|
19
|
+
track = Sequencers::StepSequencer( Patterns.Sequence(intensities), default_pitch:pitch, channel:10 )
|
20
20
|
timeline.merge track.to_timeline
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
MIDIFile(file).write timeline
|
data/examples/dynamic_pattern.rb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
# NOTE: this blindly overwrites any existing MTK-dynamic_pattern.mid file, unless an argument is provided
|
4
4
|
|
5
5
|
require 'mtk'
|
6
|
-
require 'mtk/
|
6
|
+
require 'mtk/io/midi_file'
|
7
7
|
include MTK
|
8
|
-
include MTK::
|
9
|
-
include MTK::
|
10
|
-
include MTK::
|
8
|
+
include MTK::Lang::Pitches
|
9
|
+
include MTK::Lang::Intensities
|
10
|
+
include MTK::Lang::Intervals
|
11
11
|
|
12
12
|
file = ARGV[0] || "MTK-#{File.basename __FILE__,'.rb'}.mid"
|
13
13
|
|
@@ -33,4 +33,4 @@ intensities = Patterns.Choice( mp,mf,o,ff,fff, weights: [1,2,3,2,1], max_cycles:
|
|
33
33
|
|
34
34
|
sequencer = Sequencers.StepSequencer( pitches,intensities, step_size: 0.5, max_interval: 17 )
|
35
35
|
|
36
|
-
|
36
|
+
MIDIFile(file).write( sequencer.to_timeline )
|
data/examples/gets_and_play.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# Enter space-separated pitch classes (A,B,C,D,E,F,G) at the prompt and hear them play.
|
2
2
|
|
3
3
|
require 'mtk'
|
4
|
-
|
4
|
+
require_relative 'helpers/output_selector'
|
5
5
|
include MTK
|
6
|
+
include MTK::Core
|
6
7
|
|
7
|
-
output =
|
8
|
+
output = OutputSelector.ensure_output ARGV[0]
|
8
9
|
|
9
10
|
def get_pitch_classes
|
10
11
|
puts "Enter pitch classes:"
|
data/examples/notation.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'mtk'
|
2
|
-
require 'mtk/
|
2
|
+
require 'mtk/io/notation'
|
3
3
|
include MTK
|
4
4
|
|
5
5
|
def arg_error(error)
|
@@ -18,5 +18,5 @@ arg_error "The output_file must end in '.png', '.pdf', or '.ps'" unless file
|
|
18
18
|
|
19
19
|
sequencer = MTK::Lang::Parser.parse(syntax)
|
20
20
|
timeline = sequencer.to_timeline
|
21
|
-
#
|
22
|
-
|
21
|
+
# MTK::IO::Notation.open(file).write(timeline)
|
22
|
+
MTK::IO::Notation.open(file, dpi:300).write(timeline) # higher resolution PNG
|
data/examples/play_midi.rb
CHANGED
@@ -7,11 +7,11 @@ unless file
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'mtk'
|
10
|
-
require 'mtk/
|
11
|
-
|
10
|
+
require 'mtk/io/midi_file'
|
11
|
+
require_relative 'helpers/output_selector'
|
12
12
|
|
13
|
-
output =
|
13
|
+
output = OutputSelector.ensure_output(output_name)
|
14
14
|
|
15
|
-
timeline = MTK.
|
15
|
+
timeline = MTK.MIDIFile(file).to_timelines
|
16
16
|
|
17
17
|
output.play(timeline)
|
data/examples/print_midi.rb
CHANGED
data/examples/random_tone_row.rb
CHANGED
@@ -3,16 +3,16 @@
|
|
3
3
|
# NOTE: this blindly overwrites any existing MTK-random_tone_row.mid file, unless an argument is provided
|
4
4
|
|
5
5
|
require 'mtk'
|
6
|
-
require 'mtk/
|
6
|
+
require 'mtk/io/midi_file'
|
7
7
|
include MTK
|
8
8
|
|
9
9
|
file = ARGV[0] || 'MTK-random_tone_row.mid'
|
10
10
|
|
11
|
-
row = PitchClassSet.random_row
|
11
|
+
row = Groups::PitchClassSet.random_row
|
12
12
|
sequence = Patterns.Sequence *row
|
13
13
|
|
14
14
|
sequencer = Sequencers.StepSequencer sequence
|
15
15
|
timeline = sequencer.to_timeline
|
16
16
|
|
17
|
-
|
17
|
+
MIDIFile(file).write timeline
|
18
18
|
|
data/examples/syntax_to_midi.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# NOTE: this blindly overwrites any existing MTK-syntax_to_midi.mid file, unless a second argument is provided
|
4
4
|
|
5
5
|
require 'mtk'
|
6
|
-
require 'mtk/
|
6
|
+
require 'mtk/io/midi_file'
|
7
7
|
|
8
8
|
input = ARGV[0]
|
9
9
|
if input.nil?
|
@@ -24,5 +24,5 @@ syntax = IO.read(input)
|
|
24
24
|
sequencer = MTK::Lang::Parser.parse(syntax)
|
25
25
|
timeline = sequencer.to_timeline
|
26
26
|
|
27
|
-
MTK::
|
27
|
+
MTK::MIDIFile(output).write timeline
|
28
28
|
|
data/examples/test_output.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'mtk'
|
2
|
-
|
3
|
-
include MTK
|
4
|
-
include Constants::Pitches
|
2
|
+
require_relative 'helpers/output_selector'
|
3
|
+
include MTK::Lang::Pitches
|
5
4
|
|
6
|
-
output =
|
5
|
+
output = OutputSelector.ensure_output ARGV[0]
|
7
6
|
|
8
|
-
output.play Note(C4,1
|
7
|
+
output.play MTK.Note(C4,2,1)
|
data/examples/tone_row_melody.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
# NOTE: this blindly overwrites any existing MTK-tone_row_melody.mid file, unless an argument is provided
|
4
4
|
|
5
5
|
require 'mtk'
|
6
|
-
require 'mtk/
|
6
|
+
require 'mtk/io/midi_file'
|
7
7
|
include MTK
|
8
|
-
include MTK::
|
9
|
-
include MTK::
|
8
|
+
include MTK::Lang::PitchClasses
|
9
|
+
include MTK::Lang::Durations
|
10
10
|
|
11
11
|
file = ARGV[0] || 'MTK-tone_row_melody.mid'
|
12
12
|
|
@@ -14,8 +14,10 @@ row = PitchClassSet Db, G, Ab, F, Eb, E, D, C, B, Gb, A, Bb
|
|
14
14
|
pitch_pattern = Patterns.Cycle *row
|
15
15
|
rhythm_pattern = Patterns.Choice s, i, i+s, q # choose between sixteenth, eighth, dotted eighth, and quarter
|
16
16
|
|
17
|
-
|
17
|
+
chain = Patterns.Chain pitch_pattern, rhythm_pattern, min_elements: 36, max_elements: 36
|
18
|
+
|
19
|
+
sequencer = Sequencers.LegatoSequencer chain
|
18
20
|
timeline = sequencer.to_timeline
|
19
21
|
|
20
|
-
|
22
|
+
MIDIFile(file).write timeline
|
21
23
|
|