Module: MicroMIDI::Instructions::Composite

Included in:
Context
Defined in:
lib/micromidi/instructions/composite.rb,
lib/micromidi/instructions/shorthand.rb

Instance Method Summary collapse

Instance Method Details

#all_offObject Also known as: quiet!, q!, x

sends a note off message for every note on every channel



38
39
40
41
42
43
44
45
# File 'lib/micromidi/instructions/composite.rb', line 38

def all_off
  (0..15).each do |channel|
    (0..127).each do |note_num|
      note_off(note_num, :channel => channel)
    end
  end
  true
end

#play(*args) ⇒ Object Also known as: p

plays a note or notes, for a certain duration.

the first argument must be a note name (String), MIDIMessage::NoteOn object, or array of either the last argument must be a Numeric (representing the duration)

additional arguments should be note names or MIDIMessage::NoteOn objects and will be played as a chord with the first argument



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/micromidi/instructions/composite.rb', line 18

def play(*args)
  raise "last argument must be a Numeric duration" unless args.last.kind_of?(Numeric)
  
  duration = args.pop
  note_or_notes = [args].flatten
  
  msgs = note_or_notes.map do |n|
    case n
      when Numeric, String then note(n)
      when MIDIMessage then n 
    end
  end
  
  sleep(duration)
  msgs.each { |msg| note_off(msg.note, :channel => msg.channel, :velocity => msg.velocity) }
  
  msgs.size > 1 ? msgs : msgs.first
end