Class: MicroMIDI::Instructions::Message

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

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ Message

Returns a new instance of Message.



11
12
13
# File 'lib/micromidi/instructions/message.rb', line 11

def initialize(state)
  @state = state
end

Instance Method Details

#channel_aftertouch(value, opts = {}) ⇒ Object Also known as: channel_pressure, ca

create a channel pressure message



64
65
66
67
# File 'lib/micromidi/instructions/message.rb', line 64

def channel_aftertouch(value, opts = {})
  props = @state.message_properties(opts, :channel)
  MIDIMessage::ChannelAftertouch.new(props[:channel], value)
end

#control_change(id, value, opts = {}) ⇒ Object Also known as: c, cc

create a control change message



16
17
18
19
# File 'lib/micromidi/instructions/message.rb', line 16

def control_change(id, value, opts = {})
  props = @state.message_properties(opts, :channel)
  id.kind_of?(Numeric) ? ControlChange.new(props[:channel], id, value) : ControlChange[id].new(props[:channel], value)
end

#note(id, opts = {}) ⇒ Object Also known as: n

create a note message



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/micromidi/instructions/message.rb', line 22

def note(id, opts = {})
  props = @state.message_properties(opts, :channel, :velocity)
  note = if id.kind_of?(Numeric) 
    NoteOn.new(props[:channel], id, props[:velocity])
  elsif id.kind_of?(String) || id.kind_of?(Symbol)
    note_string = parse_note_name(id)
    NoteOn[note_string].new(props[:channel], props[:velocity])
  end
  @state.last_note = note
  note
end

#note_off(id, opts = {}) ⇒ Object Also known as: no

create a note off message



35
36
37
38
39
40
41
42
43
# File 'lib/micromidi/instructions/message.rb', line 35

def note_off(id, opts = {})
  props = @state.message_properties(opts, :channel, :velocity)
  if id.kind_of?(Numeric) 
    NoteOff.new(props[:channel], id, props[:velocity])
  elsif id.kind_of?(String) || id.kind_of?(Symbol)
    note_string = parse_note_name(id)
    NoteOff[parse_note_name(id)].new(props[:channel], props[:velocity])
  end
end

#offObject Also known as: o

create a note-off message from the last note-on message



57
58
59
60
61
# File 'lib/micromidi/instructions/message.rb', line 57

def off
  o = @state.last_note.to_note_off unless @state.last_note.nil?
  @state.last_note = nil
  o
end

#parse(message) ⇒ Object

create a MIDI message from a byte string, array of bytes, or list of bytes



46
47
48
# File 'lib/micromidi/instructions/message.rb', line 46

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

#pitch_bend(low, high, opts = {}) ⇒ Object Also known as: bend, pitchbend, pb



79
80
81
82
# File 'lib/micromidi/instructions/message.rb', line 79

def pitch_bend(low, high, opts = {})
  props = @state.message_properties(opts, :channel)
  MIDIMessage::PitchBend.new(props[:channel], low, high)
end

#polyphonic_aftertouch(note, value, opts = {}) ⇒ Object Also known as: poly_aftertouch, polyphonic_pressure, poly_pressure, pa

create a poly pressure message



71
72
73
74
# File 'lib/micromidi/instructions/message.rb', line 71

def polyphonic_aftertouch(note, value, opts = {})
  props = @state.message_properties(opts, :channel)
  MIDIMessage::PolyphonicAftertouch.new(props[:channel], note, value)
end

#program_change(program, opts = {}) ⇒ Object Also known as: pc

create a program change message



51
52
53
54
# File 'lib/micromidi/instructions/message.rb', line 51

def program_change(program, opts = {})
  props = @state.message_properties(opts, :channel)
  MIDIMessage::ProgramChange.new(props[:channel], program)
end