Class: Portmidi::Device
- Inherits:
-
Object
- Object
- Portmidi::Device
- Defined in:
- lib/portmidi/device.rb
Instance Attribute Summary collapse
-
#device_id ⇒ Object
readonly
Returns the value of attribute device_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(device_id, input, output, name) ⇒ Device
constructor
A new instance of Device.
- #inspect ⇒ Object
- #open(buffer_size = nil, latency = nil) ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(device_id, input, output, name) ⇒ Device
Returns a new instance of Device.
4 5 6 7 8 9 |
# File 'lib/portmidi/device.rb', line 4 def initialize(device_id, input, output, name) @device_id = device_id @type = (input == 1 ? :input : (output == 1 ? :output : :none)) @type = :bidirectional if @type == :input && output == 1 @name = name end |
Instance Attribute Details
#device_id ⇒ Object (readonly)
Returns the value of attribute device_id.
3 4 5 |
# File 'lib/portmidi/device.rb', line 3 def device_id @device_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/portmidi/device.rb', line 3 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/portmidi/device.rb', line 3 def type @type end |
Instance Method Details
#inspect ⇒ Object
32 33 34 |
# File 'lib/portmidi/device.rb', line 32 def inspect "#<Portmidi::Device:#{@device_id} @name=\"#{@name}\", @type=:#{@type}>" end |
#open(buffer_size = nil, latency = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/portmidi/device.rb', line 11 def open(buffer_size = nil, latency = nil) case(@type) when :input Input.new(@device_id, buffer_size) when :output Output.new(@device_id, buffer_size, latency) when :bidirectional [Input.new(@device_id, buffer_size), Output.new(@device_id, buffer_size, latency)] else raise "this device has no inputs or outputs to open" end end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/portmidi/device.rb', line 24 def to_s to_str end |
#to_str ⇒ Object
28 29 30 |
# File 'lib/portmidi/device.rb', line 28 def to_str "#{@device_id}> #{@name} (#{@type})" end |