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

- (Message) initialize(state)

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

- (Object) control_change(id, value, opts = {}) 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

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

create a note message



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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) 
    string_opts = { :octave => id.scan(/-?\d\z/).first }
    n = id.split(/-?\d\z/).first
    string_props = @state.message_properties(string_opts, :octave)
    note_string = "#{n}#{string_props[:octave].to_s}"
    NoteOn[note_string].new(props[:channel], props[:velocity])
  end
  @state.last_note = note
  note
end

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

create a note off message



38
39
40
41
# File 'lib/micromidi/instructions/message.rb', line 38

def note_off(id, opts = {})
  props = @state.message_properties(opts, :channel, :velocity)
  id.kind_of?(Numeric) ? NoteOff.new(props[:channel], id, props[:velocity]) : NoteOff[id].new(props[:channel], props[:velocity])
end

- (Object) off Also known as: o

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



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

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

- (Object) parse(message)

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



44
45
46
# File 'lib/micromidi/instructions/message.rb', line 44

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

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

create a program change message



49
50
51
52
# File 'lib/micromidi/instructions/message.rb', line 49

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