class MicroMIDI::Instructions::Message

Commands that deal with MIDI messages

Public Class Methods

new(state) click to toggle source

@param [State] state

# File lib/micromidi/instructions/message.rb, line 9
def initialize(state)
  @state = state
end

Public Instance Methods

bend(low, high, options = {})
Alias for: pitch_bend
c(id, value, options = {})
Alias for: control_change
ca(value, options = {})
Alias for: channel_aftertouch
cc(id, value, options = {})
Alias for: control_change
channel_aftertouch(value, options = {}) click to toggle source

Create a MIDI channel pressure message @param [Fixnum] value @param [Hash] options @option options [Fixnum] :channel @return [MIDIMessage::ChannelAftertouch]

# File lib/micromidi/instructions/message.rb, line 82
def channel_aftertouch(value, options = {})
  properties = @state.message_properties(options, :channel)
  MIDIMessage::ChannelAftertouch.new(properties[:channel], value)
end
Also aliased as: channel_pressure, ca
channel_pressure(value, options = {})
Alias for: channel_aftertouch
control_change(id, value, options = {}) click to toggle source

Create a MIDI control change message @param [Fixnum, String] id Control name or index @param [Fixnum] value @param [Hash] options @option options [Fixnum] :channel @return [MIDIMessage::ControlChange]

# File lib/micromidi/instructions/message.rb, line 19
def control_change(id, value, options = {})
  properties = @state.message_properties(options, :channel)
  if id.kind_of?(Fixnum)
    MIDIMessage::ControlChange.new(properties[:channel], id, value)
  else
    MIDIMessage::ControlChange[id].new(properties[:channel], value)
  end
end
Also aliased as: c, cc
n(id, options = {})
Alias for: note
no(id, options = {})
Alias for: note_off
note(id, options = {}) click to toggle source

Create a MIDI note on message @param [Fixnum, String] id Note name or index @param [Hash] options @option options [Fixnum] :channel @option options [Fixnum] :velocity @return [MIDIMessage::NoteOn]

# File lib/micromidi/instructions/message.rb, line 34
def note(id, options = {})
  properties = @state.message_properties(options, :channel, :velocity)
  note = note_message(MIDIMessage::NoteOn, id, properties)
  @state.last_note = note
  note
end
Also aliased as: n
note_off(id, options = {}) click to toggle source

Create a MIDI note off message @param [Fixnum, String] id Note name or index @param [Hash] options @option options [Fixnum] :channel @option options [Fixnum] :velocity @return [MIDIMessage::NoteOff]

# File lib/micromidi/instructions/message.rb, line 47
def note_off(id, options = {})
  properties = @state.message_properties(options, :channel, :velocity)
  note_message(MIDIMessage::NoteOff, id, properties)
end
Also aliased as: no
o()
Alias for: off
off() click to toggle source

Create a MIDI note-off message from the last note-on message @return [MIDIMessage::NoteOff]

# File lib/micromidi/instructions/message.rb, line 71
def off
  note_off = @state.last_note.to_note_off unless @state.last_note.nil?
  @state.last_note = nil
  note_off
end
Also aliased as: o
pa(note, value, options = {})
parse(message) click to toggle source

Create a MIDI message from raw bytes @param [Array<Fixnum>, Array<String>, String] message Byte string or array of numeric/string bytes @return [MIDIMessage]

# File lib/micromidi/instructions/message.rb, line 55
def parse(message)
  MIDIMessage.parse(message)
end
pb(low, high, options = {})
Alias for: pitch_bend
pc(program, options = {})
Alias for: program_change
pitch_bend(low, high, options = {}) click to toggle source

Create a MIDI pitch bend message @param [Fixnum] low @param [Fixnum] high @param [Hash] options @option options [Fixnum] :channel @return [MIDIMessage::PitchBend]

# File lib/micromidi/instructions/message.rb, line 108
def pitch_bend(low, high, options = {})
  properties = @state.message_properties(options, :channel)
  MIDIMessage::PitchBend.new(properties[:channel], low, high)
end
Also aliased as: bend, pitchbend, pb
pitchbend(low, high, options = {})
Alias for: pitch_bend
poly_aftertouch(note, value, options = {})
poly_pressure(note, value, options = {})
polyphonic_aftertouch(note, value, options = {}) click to toggle source

Create a MIDI poly pressure message @param [Fixnum, String] note @param [Fixnum] value @param [Hash] options @option options [Fixnum] :channel @return [MIDIMessage::PolyphonicAftertouch]

# File lib/micromidi/instructions/message.rb, line 94
def polyphonic_aftertouch(note, value, options = {})
  properties = @state.message_properties(options, :channel)
  MIDIMessage::PolyphonicAftertouch.new(properties[:channel], note, value)
end
polyphonic_pressure(note, value, options = {})
program_change(program, options = {}) click to toggle source

Create a MIDI program change message @param [Fixnum] program @param [Hash] options @option options [Fixnum] :channel @return [MIDIMessage::ProgramChange]

# File lib/micromidi/instructions/message.rb, line 64
def program_change(program, options = {})
  properties = @state.message_properties(options, :channel)
  MIDIMessage::ProgramChange.new(properties[:channel], program)
end
Also aliased as: pc

Protected Instance Methods

parse_note_name(name) click to toggle source

Parse a note name string eg “C4” @param [String] name @return [String]

# File lib/micromidi/instructions/message.rb, line 120
def parse_note_name(name)
  name = name.to_s
  octave = name.scan(/-?\d\z/).first
  string_options = { :octave => octave }
  note = name.split(/-?\d\z/).first
  string_properties = @state.message_properties(string_options, :octave)
  "#{note}#{string_properties[:octave].to_s}"
end

Private Instance Methods

note_message(klass, id, properties) click to toggle source

Create a MIDI note on or note off message @param [Class] klass @param [Fixnum, String] id @param [Hash] properties @return [MIDIMessage::NoteOn, MIDIMessage::NoteOff]

# File lib/micromidi/instructions/message.rb, line 136
def note_message(klass, id, properties)
  if id.kind_of?(Numeric)
    klass.new(properties[:channel], id, properties[:velocity])
  elsif id.kind_of?(String) || id.kind_of?(Symbol)
    note_name = parse_note_name(id)
    klass[note_name].new(properties[:channel], properties[:velocity])
  end
end