Class: Archaeopteryx::Midi::LiveMIDI

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ LiveMIDI

Returns 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(options)
  @clock = options[:clock]
  @logging = options[:logging]
  @midi_destination = options[: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

#intervalObject (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

#timerObject (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

#note_off(midi_note) ⇒ Object



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

#note_on(midi_note) ⇒ Object



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

#play(midi_note, on_time = @clock.time) ⇒ Object



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

#program_change(channel, preset) ⇒ Object



58
59
60
# File 'lib/midi/live_midi.rb', line 58

def program_change(channel, preset)
  @interface.program_change( channel, preset )
end

#pulse(channel, controller_id, value) ⇒ Object 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.message(CONTROLLER | channel, controller_id, value)
end

#send_controller_message(midi_channel, controller_number, value, on_time = @clock.time) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/midi/live_midi.rb', line 42

def send_controller_message(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

#to_codeObject



13
14
15
# File 'lib/midi/live_midi.rb', line 13

def to_code
  "LiveMIDI.new(:clock => @clock = attributes[:clock], :logging => false)"
end