Class: MicroMIDI::Instructions::Message
- Inherits:
-
Object
- Object
- MicroMIDI::Instructions::Message
- Includes:
- MIDIMessage
- Defined in:
- lib/micromidi/instructions/message.rb,
lib/micromidi/instructions/shorthand.rb
Instance Method Summary (collapse)
-
- (Object) control_change(id, value, opts = {})
(also: #c, #cc)
create a control change message.
-
- (Message) initialize(state)
constructor
A new instance of Message.
-
- (Object) note(id, opts = {})
(also: #n)
create a note message.
-
- (Object) note_off(id, opts = {})
(also: #no)
create a note off message.
-
- (Object) off
(also: #o)
create a note-off message from the last note-on message.
-
- (Object) parse(message)
create a MIDI message from a byte string, array of bytes, or list of bytes.
-
- (Object) program_change(program, opts = {})
(also: #pc)
create a program change message.
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.(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.(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.(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.(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() MIDIMessage.parse() 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.(opts, :channel) MIDIMessage::ProgramChange.new(props[:channel], program) end |