Module: MIDIInstrument::Message
Overview
Helper for converting MIDI messages
Instance Method Summary collapse
-
#bytes?(object) ⇒ Boolean
Does this object look like a MIDI byte?.
-
#to_bytes(*args) ⇒ Array<Fixnum>
Convert the input to bytes.
-
#to_messages(*args) ⇒ Array<MIDIMessage>
Convert the input to MIDI messages.
-
#to_note_offs(*args) ⇒ Array<MIDIMessage::NoteOn, nil>
Convert the input to MIDI note off messages.
-
#to_note_ons(*args) ⇒ Array<MIDIMessage::NoteOn, nil>
Convert the input to MIDI note on messages.
Instance Method Details
#bytes?(object) ⇒ Boolean
Does this object look like a MIDI byte?
70 71 72 |
# File 'lib/midi-instrument/message.rb', line 70 def bytes?(object) object.kind_of?(Fixnum) && object >= 0x00 && object <= 0xFF end |
#to_bytes(*args) ⇒ Array<Fixnum>
Convert the input to bytes
23 24 25 26 27 28 29 30 |
# File 'lib/midi-instrument/message.rb', line 23 def to_bytes(*args) = (*args) if !.nil? .map(&:to_bytes).flatten elsif args.all? { |arg| bytes?(arg)} args end end |
#to_messages(*args) ⇒ Array<MIDIMessage>
Convert the input to MIDI messages
11 12 13 14 15 16 17 18 |
# File 'lib/midi-instrument/message.rb', line 11 def (*args) data = [args.dup].flatten if data.all? { |item| note?(item) } Message.to_note_ons(*data) # string note names elsif data.all? { |item| (item) } data # messages end end |
#to_note_offs(*args) ⇒ Array<MIDIMessage::NoteOn, nil>
Convert the input to MIDI note off messages
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/midi-instrument/message.rb', line 38 def to_note_offs(*args) notes = [args.dup].flatten = notes.last.kind_of?(Hash) ? notes.pop : {} notes.map do |note| case note when String then string_to_note_off(note, ) if note?(note) when MIDIMessage::NoteOff then note when MIDIMessage::NoteOn then note.to_note_off end end end |
#to_note_ons(*args) ⇒ Array<MIDIMessage::NoteOn, nil>
Convert the input to MIDI note on messages
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/midi-instrument/message.rb', line 56 def to_note_ons(*args) notes = [args.dup].flatten = notes.last.kind_of?(Hash) ? notes.pop : {} notes.map do |note| case note when String then string_to_note_on(note, ) if note?(note) when MIDIMessage::NoteOn then note end end end |