Class: AlsaRawMIDI::Output
- Inherits:
-
Object
- Object
- AlsaRawMIDI::Output
- Includes:
- Device
- Defined in:
- lib/alsa-rawmidi/output.rb
Overview
Output device class
Instance Attribute Summary
Attributes included from Device
#enabled, #id, #name, #subname, #system_id, #type
Class Method Summary collapse
-
.all ⇒ Array<Output>
All outputs.
-
.first ⇒ Output
The first available output.
-
.last ⇒ Output
The last available output.
Instance Method Summary collapse
-
#close ⇒ Boolean
Close this output.
-
#enable(_options = {}) ⇒ Output
(also: #open, #start)
Enable this device; yields.
-
#puts(*args) ⇒ Boolean
(also: #write)
Output the given MIDI message.
-
#puts_bytes(*data) ⇒ Boolean
Output a MIDI message in numeric byte format.
-
#puts_s(data) ⇒ Boolean
(also: #puts_bytestr, #puts_hex)
Output a MIDI message in hex string format.
Methods included from Device
Methods included from Device::ClassMethods
#all, #all_by_type, #first, #last
Class Method Details
.all ⇒ Array<Output>
All outputs
90 91 92 |
# File 'lib/alsa-rawmidi/output.rb', line 90 def self.all Device.all_by_type[:output] end |
Instance Method Details
#close ⇒ Boolean
Close this output
10 11 12 13 14 15 16 17 18 |
# File 'lib/alsa-rawmidi/output.rb', line 10 def close if @enabled API::Device.close(@resource) @enabled = false true else false end end |
#enable(_options = {}) ⇒ Output Also known as: open, start
Enable this device; yields
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/alsa-rawmidi/output.rb', line 59 def enable( = {}) unless @enabled @resource = API::Output.open(@system_id) @enabled = true end if block_given? begin yield(self) ensure close end end self end |
#puts(*args) ⇒ Boolean Also known as: write
Output the given MIDI message
46 47 48 49 50 51 52 |
# File 'lib/alsa-rawmidi/output.rb', line 46 def puts(*args) case args.first when Array then args.each { |arg| puts(*arg) } when Numeric then puts_bytes(*args) when String then puts_bytestr(*args) end end |
#puts_bytes(*data) ⇒ Boolean
Output a MIDI message in numeric byte format
38 39 40 41 |
# File 'lib/alsa-rawmidi/output.rb', line 38 def puts_bytes(*data) API::Output.puts(@resource, data) true end |
#puts_s(data) ⇒ Boolean Also known as: puts_bytestr, puts_hex
Output a MIDI message in hex string format
23 24 25 26 27 28 29 30 31 |
# File 'lib/alsa-rawmidi/output.rb', line 23 def puts_s(data) data = data.dup output = [] until (str = data.slice!(0, 2)) == '' output << str.hex end puts_bytes(*output) true end |