class MicroMIDI::Instructions::Message
Commands that deal with MIDI
messages
Public Class Methods
@param [State] state
# File lib/micromidi/instructions/message.rb, line 9 def initialize(state) @state = state end
Public Instance Methods
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
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
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
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
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
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
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
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
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
Protected Instance Methods
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
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