Module: RawMIDI::Device

Included in:
Input, Output
Defined in:
lib/rawmidi/device.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cardObject (readonly)

Returns the value of attribute card.



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

def card
  @card
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#closeObject



29
30
31
32
33
34
# File 'lib/rawmidi/device.rb', line 29

def close
  return if closed?
  API::Device.close(@midi_p)
  @midi_p = nil
  true
end

#closed?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/rawmidi/device.rb', line 40

def closed?
  !open?
end

#handle_nameObject



15
16
17
# File 'lib/rawmidi/device.rb', line 15

def handle_name
  "#{@card.handle_name},#{@id},0"
end

#initialize(card_or_id, id, **info) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/rawmidi/device.rb', line 5

def initialize(card_or_id, id, **info)
  @card = card_or_id.is_a?(Card) ? card_or_id : Card.new(card_or_id)
  @id = id

  info = get_subdevice_info if info.empty?
  @name = info[:name]
  @input = info[:input]
  @output = info[:output]
end

#inspectObject



19
20
21
# File 'lib/rawmidi/device.rb', line 19

def inspect
  "#<#{self.class.name}:#{"0x%014x" % object_id} #{handle_name} #{@name.inspect} #{open? ? 'open' : 'closed'}>"
end

#openObject



23
24
25
26
27
# File 'lib/rawmidi/device.rb', line 23

def open
  fail 'already open' if @midi_p
  @midi_p = API::Device.open(handle_name, direction, :sync)
  true
end

#open?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/rawmidi/device.rb', line 36

def open?
  !!@midi_p
end