Class: Portmidi::Output
- Inherits:
-
Object
- Object
- Portmidi::Output
- Defined in:
- lib/portmidi/output.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(device_id = 0, buffer_size = 0, latency = 0) ⇒ Output
constructor
open a device with the given ID.
- #write(messages) ⇒ Object
-
#write_short(status, data1, data2) ⇒ Object
write a single three byte message.
-
#write_sysex(sysex) ⇒ Object
sends the sysex, the message should be an array of byte values.
Constructor Details
#initialize(device_id = 0, buffer_size = 0, latency = 0) ⇒ Output
open a device with the given ID
7 8 9 10 11 12 13 14 |
# File 'lib/portmidi/output.rb', line 7 def initialize(device_id = 0, buffer_size = 0, latency = 0) out_stream_ptr = FFI::MemoryPointer.new(:pointer) if (errnum = PM_Map.Pm_OpenOutput(out_stream_ptr, device_id, nil, buffer_size, nil, nil, latency)) == 0 @out_stream = out_stream_ptr.read_pointer else raise Portmidi::DeviceError, errnum, "Could not open Device #{device_id} as output device" end end |
Instance Method Details
#close ⇒ Object
16 17 18 |
# File 'lib/portmidi/output.rb', line 16 def close PM_Map.Pm_Close(@out_stream) end |
#write(messages) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/portmidi/output.rb', line 28 def write() buffer = FFI::MemoryPointer.new(PM_Map::Event, .length) .length.times do |i| event = PM_Map::Event.new(buffer[i]) event[:timestamp] = [i][:timestamp] event[:message] = packEvent([i][:message]) end PM_Map.Pm_Write(@out_stream, buffer, .length) end |
#write_short(status, data1, data2) ⇒ Object
write a single three byte message
24 25 26 |
# File 'lib/portmidi/output.rb', line 24 def write_short(status, data1, data2) PM_Map.Pm_WriteShort(@out_stream, 0, PM_Map.(status, data1, data2)) end |
#write_sysex(sysex) ⇒ Object
sends the sysex, the message should be an array of byte values
43 44 45 46 47 48 49 50 |
# File 'lib/portmidi/output.rb', line 43 def write_sysex(sysex) raise "Invalid Sysex Format" if (sysex.first != 0xF0 || sysex.last != 0xF7) msg = FFI::Buffer.alloc_in(:uchar, sysex.length) sysex.each_with_index do |sysx, i| msg.put_uchar(i, sysx & 0xFF) end PM_Map.Pm_WriteSysEx(@out_stream, 0, msg) end |