Module: UniMIDI::Device::InstanceMethods

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

Overview

Methods that are shared by both Input and Output instances

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Add attributes for the device instance :direction, :id, :name


171
172
173
174
175
176
177
178
# File 'lib/unimidi/device.rb', line 171

def self.included(base)
  base.send(:attr_reader, :direction)
  base.send(:attr_reader, :enabled)
  base.send(:attr_reader, :id)
  base.send(:attr_reader, :name)
  base.send(:alias_method, :enabled?, :enabled)
  base.send(:alias_method, :type, :direction)
end

Instance Method Details

#close(*args) ⇒ Boolean

Close the device Params are passed to the underlying device object

Parameters:

  • args (*Object)

Returns:

  • (Boolean)

153
154
155
156
157
158
159
160
161
# File 'lib/unimidi/device.rb', line 153

def close(*args)
  if @enabled
    @device.close(*args)
    @enabled = false
    true
  else
    false
  end
end

#closed?Boolean

Returns true if the device is not enabled

Returns:

  • (Boolean)

165
166
167
# File 'lib/unimidi/device.rb', line 165

def closed?
  !@enabled
end

#initialize(device) ⇒ Object

Parameters:

  • device (AlsaRawMIDI::Input, AlsaRawMIDI::Output, CoreMIDI::Destination, CoreMIDI::Source, MIDIJRuby::Input, MIDIJRuby::Output, MIDIWinMM::Input, MIDIWinMM::Output)

112
113
114
115
116
117
# File 'lib/unimidi/device.rb', line 112

def initialize(device)
  @device = device
  @enabled = false

  populate_from_device
end

#open(*args, &block) ⇒ Input, Output

Enable the device for use Params are passed to the underlying device object Can be passed a block to which the device will be passed in as the yieldparam

Parameters:

  • args (*Object)

Returns:


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/unimidi/device.rb', line 124

def open(*args, &block)
  unless @enabled
    @device.open(*args)
    @enabled = true
  end
  if block_given?
    begin
      yield(self)
    ensure
      close
    end
  else
    at_exit do
      close
    end
  end
  self
end

#pretty_nameString

A human readable display name for this device

Returns:

  • (String)

145
146
147
# File 'lib/unimidi/device.rb', line 145

def pretty_name
  "#{id}) #{name}"
end