Class: MicroMIDI::Instructions::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/micromidi/instructions/message.rb,
lib/micromidi/instructions/shorthand.rb

Overview

Commands that deal with MIDI messages

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ Message

Returns a new instance of Message.

Parameters:


9
10
11
# File 'lib/micromidi/instructions/message.rb', line 9

def initialize(state)
  @state = state
end

Instance Method Details

#channel_aftertouch(value, options = {}) ⇒ MIDIMessage::ChannelAftertouch Also known as: channel_pressure, ca

Create a MIDI channel pressure message

Parameters:

  • value (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)

Returns:

  • (MIDIMessage::ChannelAftertouch)

82
83
84
85
# 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

#control_change(id, value, options = {}) ⇒ MIDIMessage::ControlChange Also known as: c, cc

Create a MIDI control change message

Parameters:

  • id (Fixnum, String)

    Control name or index

  • value (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)

Returns:

  • (MIDIMessage::ControlChange)

19
20
21
22
23
24
25
26
# 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

#note(id, options = {}) ⇒ MIDIMessage::NoteOn Also known as: n

Create a MIDI note on message

Parameters:

  • id (Fixnum, String)

    Note name or index

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)

Returns:

  • (MIDIMessage::NoteOn)

34
35
36
37
38
39
# 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

#note_off(id, options = {}) ⇒ MIDIMessage::NoteOff Also known as: no

Create a MIDI note off message

Parameters:

  • id (Fixnum, String)

    Note name or index

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)
  • :velocity (Fixnum)

Returns:

  • (MIDIMessage::NoteOff)

47
48
49
50
# 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

#offMIDIMessage::NoteOff Also known as: o

Create a MIDI note-off message from the last note-on message

Returns:

  • (MIDIMessage::NoteOff)

71
72
73
74
75
# 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

#parse(message) ⇒ MIDIMessage

Create a MIDI message from raw bytes

Parameters:

  • message (Array<Fixnum>, Array<String>, String)

    Byte string or array of numeric/string bytes

Returns:

  • (MIDIMessage)

55
56
57
# File 'lib/micromidi/instructions/message.rb', line 55

def parse(message)
  MIDIMessage.parse(message)
end

#pitch_bend(low, high, options = {}) ⇒ MIDIMessage::PitchBend Also known as: bend, pitchbend, pb

Create a MIDI pitch bend message

Parameters:

  • low (Fixnum)
  • high (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)

Returns:

  • (MIDIMessage::PitchBend)

108
109
110
111
# 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

#polyphonic_aftertouch(note, value, options = {}) ⇒ MIDIMessage::PolyphonicAftertouch Also known as: poly_aftertouch, polyphonic_pressure, poly_pressure, pa

Create a MIDI poly pressure message

Parameters:

  • note (Fixnum, String)
  • value (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)

Returns:

  • (MIDIMessage::PolyphonicAftertouch)

94
95
96
97
# 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

#program_change(program, options = {}) ⇒ MIDIMessage::ProgramChange Also known as: pc

Create a MIDI program change message

Parameters:

  • program (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :channel (Fixnum)

Returns:

  • (MIDIMessage::ProgramChange)

64
65
66
67
# 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