Module: MicroMIDI::Instructions::Composite

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

Overview

Commands that are composites of other commands

Instance Method Summary collapse

Instance Method Details

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

Send a note off message for every note on every channel

Returns:

  • (Boolean)

33
34
35
36
37
38
39
40
# File 'lib/micromidi/instructions/composite.rb', line 33

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) ⇒ Array<MIDIMessage::NoteOn>, MIDIMessage::NoteOn Also known as: p

Play a note or notes, for the given duration.

The first argument must be: [Array<String>, Array<MIDIMessage::NoteOn>, String, MIDIMessage::NoteOn] The last argument must be [Numeric] representing the duration

Additional arguments can be [Array<String>, Array<MIDIMessage::NoteOn>, String, MIDIMessage::NoteOn] and will be played as a chord simultaneously with the first argument.

Parameters:

  • args (*Object)

Returns:

  • (Array<MIDIMessage::NoteOn>, MIDIMessage::NoteOn)

19
20
21
22
23
24
25
26
27
28
29
# File 'lib/micromidi/instructions/composite.rb', line 19

def play(*args)
  raise "Last argument must be a Numeric duration" unless args.last.kind_of?(Numeric)
  args = args.dup
  duration = args.pop
  note_or_notes = [args].flatten
  messages = as_note_messages(note_or_notes)
  sleep(duration)
  send_note_offs(messages)

  messages.count > 1 ? messages : messages.first
end