module UniMIDI::Device::InstanceMethods
Public Class Methods
included(base)
click to toggle source
Add attributes for the device instance :direction, :id, :name
# 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
new(device)
click to toggle source
@param [AlsaRawMIDI::Input, AlsaRawMIDI::Output, CoreMIDI::Destination, CoreMIDI::Source, MIDIJRuby::Input, MIDIJRuby::Output, MIDIWinMM::Input, MIDIWinMM::Output] device
# File lib/unimidi/device.rb, line 112 def initialize(device) @device = device @enabled = false populate_from_device end
Public Instance Methods
close(*args)
click to toggle source
Close the device Params are passed to the underlying device object @param [*Object] args @return [Boolean]
# File lib/unimidi/device.rb, line 153 def close(*args) if @enabled @device.close(*args) @enabled = false true else false end end
closed?()
click to toggle source
Returns true if the device is not enabled @return [Boolean]
# File lib/unimidi/device.rb, line 165 def closed? !@enabled end
open(*args) { |self| ... }
click to toggle source
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 @param [*Object] args @return [Input, Output] self
# 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_name()
click to toggle source
A human readable display name for this device @return [String]
# File lib/unimidi/device.rb, line 145 def pretty_name "#{id}) #{name}" end
Private Instance Methods
populate_direction()
click to toggle source
Populate the direction attribute
# File lib/unimidi/device.rb, line 183 def populate_direction @direction = case @device.type when :source, :input then :input when :destination, :output then :output end end
populate_from_device()
click to toggle source
Populate attributes from the underlying device object
# File lib/unimidi/device.rb, line 191 def populate_from_device @id = @device.id @name = @device.name populate_direction end