Class: Portmidi::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/portmidi/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject (readonly)

Returns the value of attribute device_id.



3
4
5
# File 'lib/portmidi/device.rb', line 3

def device_id
  @device_id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/portmidi/device.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/portmidi/device.rb', line 3

def type
  @type
end

Instance Method Details

#inspectObject



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_sObject



24
25
26
# File 'lib/portmidi/device.rb', line 24

def to_s
  to_str
end

#to_strObject



28
29
30
# File 'lib/portmidi/device.rb', line 28

def to_str
  "#{@device_id}> #{@name} (#{@type})"
end