Class: MIDICommunications::Output
- Inherits:
-
Object
- Object
- MIDICommunications::Output
- Extended by:
- Device::ClassMethods
- Includes:
- Device::InstanceMethods
- Defined in:
- lib/midi-communications/output.rb
Overview
A MIDI output device for sending MIDI messages.
Output devices send MIDI data to external instruments, software synthesizers, or other MIDI destinations. Use the class methods to discover and select available output devices.
Instance Attribute Summary collapse
-
#direction ⇒ Symbol
included
from Device::InstanceMethods
readonly
The device direction (:input or :output).
-
#display_name ⇒ String
included
from Device::InstanceMethods
readonly
The device display name.
-
#enabled ⇒ Boolean
included
from Device::InstanceMethods
readonly
Whether the device is currently open.
-
#id ⇒ Integer
included
from Device::InstanceMethods
readonly
The device ID.
-
#manufacturer ⇒ String
included
from Device::InstanceMethods
readonly
The device manufacturer name.
-
#model ⇒ String
included
from Device::InstanceMethods
readonly
The device model name.
-
#name ⇒ String
included
from Device::InstanceMethods
readonly
The device name.
Class Method Summary collapse
-
.all ⇒ Array<Output>
Returns all available MIDI output devices.
-
.at(index) ⇒ Input, Output
(also: #[])
extended
from Device::ClassMethods
Returns the device at the given index without opening it.
-
.each {|device| ... } ⇒ Enumerator
extended
from Device::ClassMethods
Iterates over all devices of this type.
-
.find_by_name(name) ⇒ Input, ...
extended
from Device::ClassMethods
Finds a device by its name.
-
.first {|device| ... } ⇒ Input, Output
extended
from Device::ClassMethods
Selects and opens the first available device.
-
.gets {|device| ... } ⇒ Input, Output
extended
from Device::ClassMethods
Interactive console prompt for device selection.
-
.last {|device| ... } ⇒ Input, Output
extended
from Device::ClassMethods
Selects and opens the last available device.
-
.list ⇒ Array<String>
extended
from Device::ClassMethods
Prints the ID and name of each device to the console.
-
.use(index) {|device| ... } ⇒ Input, Output
(also: #open)
extended
from Device::ClassMethods
Selects and opens the device at the given index.
Instance Method Summary collapse
-
#close(*args) ⇒ Boolean
included
from Device::InstanceMethods
Closes the device.
-
#closed? ⇒ Boolean
included
from Device::InstanceMethods
Returns true if the device is closed (not enabled).
-
#enabled? ⇒ Boolean
included
from Device::InstanceMethods
Alias for Device::InstanceMethods#enabled.
-
#initialize(device) ⇒ Object
included
from Device::InstanceMethods
private
Creates a new device wrapper.
-
#open(*args) {|device| ... } ⇒ Input, Output
included
from Device::InstanceMethods
Opens the device for use.
-
#puts(*messages) ⇒ Array<Integer>, Array<String>
Sends a MIDI message to the output.
-
#puts_bytes(*messages) ⇒ Integer+
Sends a MIDI message as numeric bytes.
-
#puts_s(*messages) ⇒ String+
(also: #puts_bytestr, #puts_hex)
Sends a MIDI message as a hex string.
-
#type ⇒ Symbol
included
from Device::InstanceMethods
Alias for Device::InstanceMethods#direction.
Instance Attribute Details
#direction ⇒ Symbol (readonly) Originally defined in module Device::InstanceMethods
Returns the device direction (:input or :output).
#display_name ⇒ String (readonly) Originally defined in module Device::InstanceMethods
Returns the device display name.
#enabled ⇒ Boolean (readonly) Originally defined in module Device::InstanceMethods
Returns whether the device is currently open.
#id ⇒ Integer (readonly) Originally defined in module Device::InstanceMethods
Returns the device ID.
#manufacturer ⇒ String (readonly) Originally defined in module Device::InstanceMethods
Returns the device manufacturer name.
#model ⇒ String (readonly) Originally defined in module Device::InstanceMethods
Returns the device model name.
#name ⇒ String (readonly) Originally defined in module Device::InstanceMethods
Returns the device name.
Class Method Details
.all ⇒ Array<Output>
Returns all available MIDI output devices.
43 44 45 |
# File 'lib/midi-communications/output.rb', line 43 def self.all Loader.devices(direction: :output) end |
.at(index) ⇒ Input, Output Also known as: [] Originally defined in module Device::ClassMethods
Returns the device at the given index without opening it.
.each {|device| ... } ⇒ Enumerator Originally defined in module Device::ClassMethods
Iterates over all devices of this type.
.find_by_name(name) ⇒ Input, ... Originally defined in module Device::ClassMethods
Finds a device by its name.
.first {|device| ... } ⇒ Input, Output Originally defined in module Device::ClassMethods
Selects and opens the first available device.
.gets {|device| ... } ⇒ Input, Output Originally defined in module Device::ClassMethods
Interactive console prompt for device selection.
Displays available devices and waits for user input. When a valid selection is received, the device is opened and returned.
.last {|device| ... } ⇒ Input, Output Originally defined in module Device::ClassMethods
Selects and opens the last available device.
.list ⇒ Array<String> Originally defined in module Device::ClassMethods
Prints the ID and name of each device to the console.
.use(index) {|device| ... } ⇒ Input, Output Also known as: open Originally defined in module Device::ClassMethods
Selects and opens the device at the given index.
Instance Method Details
#close(*args) ⇒ Boolean Originally defined in module Device::InstanceMethods
Closes the device.
#closed? ⇒ Boolean Originally defined in module Device::InstanceMethods
Returns true if the device is closed (not enabled).
#enabled? ⇒ Boolean Originally defined in module Device::InstanceMethods
Returns alias for #enabled.
#initialize(device) ⇒ Object Originally defined in module Device::InstanceMethods
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new device wrapper.
#open(*args) {|device| ... } ⇒ Input, Output Originally defined in module Device::InstanceMethods
Opens the device for use.
When a block is given, the device is automatically closed when the block exits. Otherwise, the device is closed at program exit.
#puts(*messages) ⇒ Array<Integer>, Array<String>
Sends a MIDI message to the output.
Accepts multiple message formats for flexibility:
- Numeric bytes:
output.puts(0x90, 0x40, 0x40) - Array of numeric bytes:
output.puts([0x90, 0x40, 0x40]) - Hex string:
output.puts("904040") - Array of strings:
output.puts(["904040", "804040"]) - Objects with
to_bytesmethod:output.puts(midi_event)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/midi-communications/output.rb', line 67 def puts(*) = .first case when Array then .each { |array| puts(*array.flatten) } when Integer then puts_bytes(*) when String then puts_s(*) else if .respond_to?(:to_bytes) puts_bytes(*.to_bytes.flatten) elsif .respond_to?(:to_a) puts_bytes(*.to_a.flatten) end end end |
#puts_bytes(*messages) ⇒ Integer+
Sends a MIDI message as numeric bytes.
This is a lower-level method that does not perform type checking. Use #puts for automatic format detection.
110 111 112 113 |
# File 'lib/midi-communications/output.rb', line 110 def puts_bytes(*) @device.puts_bytes(*) .count < 2 ? [0] : end |
#puts_s(*messages) ⇒ String+ Also known as: puts_bytestr, puts_hex
Sends a MIDI message as a hex string.
This is a lower-level method that does not perform type checking. Use #puts for automatic format detection.
93 94 95 96 |
# File 'lib/midi-communications/output.rb', line 93 def puts_s(*) @device.puts_s(*) .count < 2 ? [0] : end |
#type ⇒ Symbol Originally defined in module Device::InstanceMethods
Returns alias for #direction.