module Midi::Event
Constants
- NOTE
- OCTAVE_UNIT
Public Instance Methods
to_bin()
click to toggle source
# File lib/kuromusic/IO/MIDI/Event.rb, line 35 def to_bin() #p self.args if @args[:type] == ::Event::EventType::NOTE return note_to_bin elsif @args[:type] == ::Event::EventType::META return meta_to_bin end end
Private Instance Methods
meta_to_bin()
click to toggle source
# File lib/kuromusic/IO/MIDI/Event.rb, line 23 def meta_to_bin() case @args[:method] when ::Event::EventType::Meta::SET_TEMPO tempo = 60000000 / @args[:tempo] return [0, 0xff, 0x51, 0x03, tempo >> 16, tempo >> 8, tempo % 256] end end
note_to_bin()
click to toggle source
# File lib/kuromusic/IO/MIDI/Event.rb, line 9 def note_to_bin() case @args[:method] when ::Event::EventType::Note::REST dur = var_len(@args[:dur]) return dur when ::Event::EventType::Note::OFF note_num = NOTE[@args[:note]] + @args[:octave] * OCTAVE_UNIT return [0x80, note_num, 0] when ::Event::EventType::Note::ON note_num = NOTE[@args[:note]] + @args[:octave] * OCTAVE_UNIT return [0x90, note_num, @args[:velocity]] end end
var_len(n)
click to toggle source
# File lib/kuromusic/IO/MIDI/Event.rb, line 5 def var_len n n < 0x80 ? [n] : [(n>>7|0x80), n % 0x80] end