Class: JSound::Midi::Device

Inherits:
Object
  • Object
show all
Includes:
TypeFromClassName
Defined in:
lib/jsound/midi/device.rb

Overview

A device that can transmit and/or receive messages (typically MIDI messages). This default implementation simply passes through all messages.

Instance Method Summary collapse

Methods included from TypeFromClassName

included

Instance Method Details

#<=(message) ⇒ Object

send a message to this device. shortcut for #message

See Also:



66
67
68
# File 'lib/jsound/midi/device.rb', line 66

def <=(message)
  message(message)
end

#>>(device) ⇒ Object

Connect a device as the output for this device. shortcut for #output=

Parameters:

  • the (Device)

    device to connect, or nil to disconnect the currently connected device

See Also:

  • JSound::Midi::Device.{{#output=}


47
48
49
# File 'lib/jsound/midi/device.rb', line 47

def >> device
  self.output= device
end

#closeObject

Note:

this operation is typically only relevant for Java-based devices such as JSound::Midi::Devices::InputDevice and JSound::Midi::Devices::OutputDevice

Close the device and free up any resources used by this device.



23
24
# File 'lib/jsound/midi/device.rb', line 23

def close
end

#message(message) ⇒ Object

Send a message to this device and pass it through to any output(s)

Parameters:

See Also:



54
55
56
57
58
59
60
61
62
# File 'lib/jsound/midi/device.rb', line 54

def message(message)
  if @output.respond_to? :each
    for device in @output
      device.message(message)
    end
  elsif @output
    @output.message(message)
  end
end

#openObject

Note:

this operation is typically only relevant for Java-based devices such as JSound::Midi::Devices::InputDevice and JSound::Midi::Devices::OutputDevice

Open the device and allocate the needed resources so that it can send and receive messages



12
13
# File 'lib/jsound/midi/device.rb', line 12

def open
end

#open?Boolean

return true if this device is currently open

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/jsound/midi/device.rb', line 16

def open?
  # typically, ruby devices are always open, subclasses might not be
  true
end

#outputDevice

the device connected to this device’s output

Returns:

  • (Device)

    the connected device, or nil if nothing is connected



33
34
35
# File 'lib/jsound/midi/device.rb', line 33

def output
  @output
end

#output=(device) ⇒ Object

connect a device as the output for this device

Parameters:

  • the (Device)

    device to connect, or nil to disconnect the currently connected device

See Also:

  • JSound::Midi::Device.{{#>>}


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

def output= device
  @output = device
end

#to_sObject



70
71
72
# File 'lib/jsound/midi/device.rb', line 70

def to_s
  "MIDI #{type} device"
end

#typeObject



26
27
28
29
# File 'lib/jsound/midi/device.rb', line 26

def type
  # The base Device behaves like a 'pass through'
  @type ||= (self.class == Device ? :pass_through : self.class.type)
end