Class: SurfaceMaster::Device
- Inherits:
-
Object
- Object
- SurfaceMaster::Device
show all
- Includes:
- Logging
- Defined in:
- lib/surface_master/device.rb
Overview
Base class for MIDI controller drivers.
Sub-classes should extend the constructor, extend sysex_prefix, implement reset!, and add whatever methods are appropriate for them.
Instance Method Summary
collapse
Methods included from Logging
#logger, #logger=
Constructor Details
#initialize(opts = nil) ⇒ Device
9
10
11
12
13
14
|
# File 'lib/surface_master/device.rb', line 9
def initialize(opts = nil)
opts = { input: true, output: true }.merge(opts || {})
self.logger = opts[:logger]
@input = create_input_device(opts)
@output = create_output_device(opts)
end
|
Instance Method Details
#close ⇒ Object
Closes the device - nothing can be done with the device afterwards.
17
18
19
20
21
22
23
|
# File 'lib/surface_master/device.rb', line 17
def close
logger.debug "Closing #{self.class}##{object_id}"
@input.close unless @input.nil?
@input = nil
@output.close unless @output.nil?
@output = nil
end
|
#closed? ⇒ Boolean
25
|
# File 'lib/surface_master/device.rb', line 25
def closed?; !(input_enabled? || output_enabled?); end
|
26
|
# File 'lib/surface_master/device.rb', line 26
def input_enabled?; !@input.nil?; end
|
#output_enabled? ⇒ Boolean
27
|
# File 'lib/surface_master/device.rb', line 27
def output_enabled?; !@output.nil?; end
|
#read ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/surface_master/device.rb', line 31
def read
fail SurfaceMaster::NoInputAllowedError unless input_enabled?
Array(@input.read(16)).collect do |midi_message|
(code, note, velocity) = midi_message[:message]
{ timestamp: midi_message[:timestamp],
state: (velocity == 127) ? :down : :up,
velocity: velocity,
code: code,
note: note }
end
end
|
#reset! ⇒ Object
29
|
# File 'lib/surface_master/device.rb', line 29
def reset!; end
|