Class: Archaeopteryx::Midi::LiveMIDI
- Inherits:
-
Object
- Object
- Archaeopteryx::Midi::LiveMIDI
- Defined in:
- lib/midi/live_midi.rb
Overview
this object wraps MIDIator's interface with some extra awesomeness
Constant Summary
- CONTROLLER =
arbitrary controller message
0xB0
Instance Attribute Summary (collapse)
-
- (Object) interval
readonly
this is a totally misleading variable name! real interval lives on Clock.
-
- (Object) timer
readonly
Returns the value of attribute timer.
Instance Method Summary (collapse)
-
- (LiveMIDI) initialize(options)
constructor
A new instance of LiveMIDI.
- - (Object) note_off(midi_note)
- - (Object) note_on(midi_note)
- - (Object) play(midi_note, on_time = @clock.time)
- - (Object) program_change(channel, preset)
- - (Object) pulse(channel, controller_id, value) (also: #control)
- - (Object) send_controller_message(midi_channel, controller_number, value, on_time = @clock.time)
- - (Object) to_code
Constructor Details
- (LiveMIDI) initialize(options)
A new instance of LiveMIDI
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/midi/live_midi.rb', line 17 def initialize() @clock = [:clock] @logging = [:logging] @midi_destination = [:midi_destination] || 0 if @logging puts <<LOG_PLAYBACK require 'lib/archaeopteryx' @midi = #{self.to_code} LOG_PLAYBACK end @interval = 60.0/120 # this is just a polling interval for the Thread - not a musical one @timer = MIDIator::Timer.new(@interval/1000) @interface = MIDIator::Interface.new @interface.autodetect_driver end |
Instance Attribute Details
- (Object) interval (readonly)
this is a totally misleading variable name! real interval lives on Clock
8 9 10 |
# File 'lib/midi/live_midi.rb', line 8 def interval @interval end |
- (Object) timer (readonly)
Returns the value of attribute timer
9 10 11 |
# File 'lib/midi/live_midi.rb', line 9 def timer @timer end |
Instance Method Details
- (Object) note_off(midi_note)
54 55 56 |
# File 'lib/midi/live_midi.rb', line 54 def note_off(midi_note) @interface.note_off( midi_note.number, midi_note.channel, midi_note.velocity ) end |
- (Object) note_on(midi_note)
50 51 52 |
# File 'lib/midi/live_midi.rb', line 50 def note_on(midi_note) @interface.note_on( midi_note.number, midi_note.channel, midi_note.velocity ) end |
- (Object) play(midi_note, on_time = @clock.time)
33 34 35 36 37 38 39 40 |
# File 'lib/midi/live_midi.rb', line 33 def play(midi_note, on_time = @clock.time) if @logging puts "@midi.play(#{midi_note.to_code}, #{on_time})" end on_time += @clock.start @timer.at(on_time) {note_on(midi_note)} @timer.at(on_time + midi_note.duration) {note_off(midi_note)} end |
- (Object) program_change(channel, preset)
58 59 60 |
# File 'lib/midi/live_midi.rb', line 58 def program_change(channel, preset) @interface.program_change( channel, preset ) end |
- (Object) pulse(channel, controller_id, value) Also known as: control
62 63 64 65 66 |
# File 'lib/midi/live_midi.rb', line 62 def pulse(channel, controller_id, value) # puts "sending now: #{Time.now.to_f}" if @logging # puts "#{[channel, controller_id, value].inspect}" if @logging @interface.(CONTROLLER | channel, controller_id, value) end |
- (Object) send_controller_message(midi_channel, controller_number, value, on_time = @clock.time)
42 43 44 45 46 47 48 |
# File 'lib/midi/live_midi.rb', line 42 def (midi_channel, controller_number, value, on_time = @clock.time) on_time += @clock.start # puts "scheduling for #{on_time}" if @logging @timer.at(on_time) do control(midi_channel, controller_number, value) end end |
- (Object) to_code
13 14 15 |
# File 'lib/midi/live_midi.rb', line 13 def to_code "LiveMIDI.new(:clock => @clock = attributes[:clock], :logging => false)" end |