Class: JSound::Midi::Devices::JDevice
- Inherits:
-
JSound::Midi::Device
- Object
- JSound::Midi::Device
- JSound::Midi::Devices::JDevice
- Defined in:
- lib/jsound/midi/devices/jdevice.rb
Overview
A Java-provided MIDI device (wraps javax.sound.midi.MidiDevice objects)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
the description of this device.
-
#info ⇒ Object
readonly
the javax.sound.midi.MidiDevice.Info object for this java device.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .from_java(java_device) ⇒ Object
-
.open_devices ⇒ Object
All open JDevices.
Instance Method Summary collapse
- #[](field) ⇒ Object
- #close ⇒ Object
-
#initialize(java_device, type) ⇒ JDevice
constructor
A new instance of JDevice.
- #inspect ⇒ Object
- #method_missing(sym, *args, &block) ⇒ Object
- #open ⇒ Object
- #respond_to?(sym) ⇒ Boolean
- #to_s ⇒ Object
Methods inherited from JSound::Midi::Device
#<=, #>>, #message, #open?, #output, #output=
Methods included from TypeFromClassName
Constructor Details
#initialize(java_device, type) ⇒ JDevice
Returns a new instance of JDevice.
29 30 31 32 33 34 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 29 def initialize(java_device, type) @java_device = java_device @info = @java_device.deviceInfo @description = @info.description @type = type end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 72 def method_missing(sym, *args, &block) if @java_device.respond_to? sym @java_device.send(sym, *args, &block) else @info.send(sym, *args, &block) end end |
Instance Attribute Details
#description ⇒ String (readonly)
the description of this device
13 14 15 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 13 def description @description end |
#info ⇒ Object (readonly)
the javax.sound.midi.MidiDevice.Info object for this java device
9 10 11 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 9 def info @info end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 15 def type @type end |
Class Method Details
.from_java(java_device) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 36 def self.from_java(java_device) case java_device when javax.sound.midi.Sequencer then type = :sequencer when javax.sound.midi.Synthesizer then type = :synthesizer else # This assumes a single device cannot be both an input and an output: if java_device.maxTransmitters != 0 return InputDevice.new(java_device) elsif java_device.maxReceivers != 0 return OutputDevice.new(java_device) else type = :unknown end end new java_device, type end |
.open_devices ⇒ Object
Note:
All open devices will be automatically closed at_exit
All open JDevices
19 20 21 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 19 def self.open_devices @@open_devices ||= [] end |
Instance Method Details
#[](field) ⇒ Object
84 85 86 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 84 def [](field) send field end |
#close ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 64 def close if @java_device.open? puts "Closing #{to_s}" @java_device.close self.class.open_devices.delete(self) end end |
#inspect ⇒ Object
92 93 94 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 92 def inspect to_s end |
#open ⇒ Object
Note:
All open devices will be automatically closed at_exit
55 56 57 58 59 60 61 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 55 def open unless @java_device.open? puts "Opening #{to_s}" @java_device.open self.class.open_devices << self end end |
#respond_to?(sym) ⇒ Boolean
80 81 82 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 80 def respond_to?(sym) super or @java_device.respond_to? sym or info.respond_to? sym end |
#to_s ⇒ Object
88 89 90 |
# File 'lib/jsound/midi/devices/jdevice.rb', line 88 def to_s "#{super}: #{info.description}" end |