Class: MIDIWinMM::Output
- Inherits:
-
Object
- Object
- MIDIWinMM::Output
- Includes:
- Device
- Defined in:
- lib/midi-winmm/output.rb
Overview
Output device class for the WinMM driver interface
Constant Summary collapse
- BufferSize =
2048
Constants included from Device
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Attributes included from Device
#enabled, #id, #info, #name, #type
Class Method Summary collapse
Instance Method Summary collapse
-
#close ⇒ Object
close this device.
-
#enable(options = {}, &block) ⇒ Object
(also: #start, #open)
initialize this device.
-
#puts(*a) ⇒ Object
send a message of an indeterminate type.
-
#puts_bytes(*message_bytes) ⇒ Object
send a message consisting of Numeric bytes.
-
#puts_s(data) ⇒ Object
(also: #puts_bytestr, #puts_hex)
send a message consisisting of a String of hex digits.
- #reset ⇒ Object
-
#volume ⇒ Object
returns a hash of fixnum values { :left => n, :right => n2 }.
-
#volume=(val) ⇒ Object
accepts either a hash of fixnums { :left => n, :right => n2 } or a single fixnum that will be applied to both channels.
Methods included from Device
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
13 14 15 |
# File 'lib/midi-winmm/output.rb', line 13 def buffer @buffer end |
Class Method Details
.all ⇒ Object
109 110 111 |
# File 'lib/midi-winmm/output.rb', line 109 def self.all Device.all_by_type[:output] end |
Instance Method Details
#close ⇒ Object
close this device
35 36 37 38 |
# File 'lib/midi-winmm/output.rb', line 35 def close Map.winmm_func(:midiOutClose, @handle) @enabled = false end |
#enable(options = {}, &block) ⇒ Object Also known as: start, open
initialize this device
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/midi-winmm/output.rb', line 16 def enable( = {}, &block) init_output_buffer Map.winmm_func(:midiOutOpen, Output::HandlePointer, @id, Output::EventCallback, 0, Device::WinmmCallbackFlag) @handle = HandlePointer.read_int @enabled = true unless block.nil? begin yield(self) ensure close end else self end end |
#puts(*a) ⇒ Object
send a message of an indeterminate type
64 65 66 67 68 69 70 |
# File 'lib/midi-winmm/output.rb', line 64 def puts(*a) case a.first when Array then puts_bytes(*a.first) when Numeric then puts_bytes(*a) when String then puts_s(*a) end end |
#puts_bytes(*message_bytes) ⇒ Object
send a message consisting of Numeric bytes
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/midi-winmm/output.rb', line 73 def puts_bytes(*) format = "C" * .size packed = .pack(format) data_pointer = FFI::MemoryPointer.new(.size).put_bytes(0, packed) @header[:dwBufferLength] = .size @header[:dwBytesRecorded] = .size @header[:lpData] = data_pointer Map.winmm_func(:midiOutPrepareHeader, @handle, @header.pointer, @header.size) Map.winmm_func(:midiOutLongMsg, @handle, @header.pointer, @header.size) end |
#puts_s(data) ⇒ Object Also known as: puts_bytestr, puts_hex
send a message consisisting of a String of hex digits
90 91 92 93 94 95 96 97 |
# File 'lib/midi-winmm/output.rb', line 90 def puts_s(data) data = data.dup output = [] until (str = data.slice!(0,2)).eql?("") output << str.hex end puts_bytes(*output) end |
#reset ⇒ Object
59 60 61 |
# File 'lib/midi-winmm/output.rb', line 59 def reset Map.winmm_func(:midiOutReset, @handle) end |
#volume ⇒ Object
returns a hash of fixnum values { :left => n, :right => n2 }
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/midi-winmm/output.rb', line 41 def volume volume = FFI::MemoryPointer.new(FFI.type_size(:ulong)) Map.winmm_func(:midiOutGetVolume, @handle, volume) str = dwmsg_to_array_of_bytes(volume.read_ulong) left = str.slice!(0,4) { :left => left.hex, :right => str.hex } end |
#volume=(val) ⇒ Object
accepts either a hash of fixnums { :left => n, :right => n2 } or a single fixnum that will be applied to both channels
54 55 56 57 |
# File 'lib/midi-winmm/output.rb', line 54 def volume=(val) vol = val.kind_of?(Hash) ? (val[:left] + (val[:right] << 16)) : (val + (val << 16)) Map.winmm_func(:midiOutSetVolume, @handle, vol) end |