Module: MIDICommunicationsWindows::Device::InstanceMethods

Included in:
Input, Output
Defined in:
lib/midi-communications-windows/device.rb

Overview

Methods on an individual port.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabled ⇒ Object (readonly) Also known as: enabled?



98
# File 'lib/midi-communications-windows/device.rb', line 98

attr_reader :id, :name, :enabled

#id ⇒ Integer (readonly)

Returns the port's WinMM index within its direction; see the note on identity in MIDICommunicationsWindows::Device.

Returns:



98
99
100
# File 'lib/midi-communications-windows/device.rb', line 98

def id
  @id
end

#name ⇒ String (readonly)

Returns the port's name, as WinMM reports it, truncated to 31 characters. Not unique: see the note on names in MIDICommunicationsWindows::Device.

Returns:



98
# File 'lib/midi-communications-windows/device.rb', line 98

attr_reader :id, :name, :enabled

Instance Method Details

#close ⇒ Boolean

Closes the port.

Returns:

  • (Boolean) —

    true if it was open, false if it already was not



181
182
183
184
185
186
187
188
# File 'lib/midi-communications-windows/device.rb', line 181

def close
  return false unless @enabled

  disconnect
  @enabled = false

  true
end

#display_name ⇒ String

The name to show a person choosing a port.

This is the port name unchanged. On macOS the display name is built as "manufacturer model (name)", which here would render as a name wrapped in the punctuation of two absent fields.

Returns:

  • (String)


146
147
148
# File 'lib/midi-communications-windows/device.rb', line 146

def display_name
  @name
end

#initialize(id, name) ⇒ Object

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.

Parameters:

  • id (Integer) —

    the port's WinMM index within its direction

  • name (String) —

    the port's name as reported by WinMM



107
108
109
110
111
# File 'lib/midi-communications-windows/device.rb', line 107

def initialize(id, name)
  @id = id
  @name = name
  @enabled = false
end

#manufacturer ⇒ nil

Who made the device.

Always nil on Windows. See the note in MIDICommunicationsWindows::Device for why this is not derived from wMid.

Returns:

  • (nil)


126
127
128
# File 'lib/midi-communications-windows/device.rb', line 126

def manufacturer
  nil
end

#model ⇒ nil

The device model.

Always nil on Windows, for the same reason as #manufacturer.

Returns:

  • (nil)


135
136
137
# File 'lib/midi-communications-windows/device.rb', line 135

def model
  nil
end

#open {|self| ... } ⇒ self Also known as: enable, start

Opens the port.

Opening twice is not an error and does nothing the second time, which is what midi-communications relies on when it opens a port a caller may already hold.

Yields:

  • (self) —

    if a block is given, the port is closed when it returns

Returns:

  • (self)

Raises:

  • (Error) —

    if WinMM refuses to open the port



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/midi-communications-windows/device.rb', line 159

def open
  unless @enabled
    connect
    @enabled = true
  end

  if block_given?
    begin
      yield self
    ensure
      close
    end
  end

  self
end

#to_s ⇒ String

Returns:

  • (String)


191
192
193
# File 'lib/midi-communications-windows/device.rb', line 191

def to_s
  "#{self.class.name.split('::').last} #{@id}: #{@name}"
end

#type ⇒ Symbol

The port's direction.

Returns:

  • (Symbol) —

    :input or :output



116
117
118
# File 'lib/midi-communications-windows/device.rb', line 116

def type
  self.class.direction
end