Class: Webmidi::Access
- Inherits:
-
Object
- Object
- Webmidi::Access
- Includes:
- Enumerable
- Defined in:
- lib/webmidi/access.rb
Instance Attribute Summary collapse
-
#sysex_enabled ⇒ Object
(also: #sysex_enabled?)
readonly
Returns the value of attribute sysex_enabled.
Instance Method Summary collapse
- #close ⇒ Object
- #create_input(name) ⇒ Object
- #create_output(name) ⇒ Object
- #each(&block) ⇒ Object
- #fetch_input!(name_or_id) ⇒ Object
- #fetch_output!(name_or_id) ⇒ Object
-
#initialize(sysex: false, transport: nil) ⇒ Access
constructor
A new instance of Access.
- #input(name_or_id) ⇒ Object
- #inputs ⇒ Object
- #on_state_change(&block) ⇒ Object
- #output(name_or_id) ⇒ Object
- #outputs ⇒ Object
- #refresh_ports ⇒ Object
Constructor Details
#initialize(sysex: false, transport: nil) ⇒ Access
Returns a new instance of Access.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/webmidi/access.rb', line 13 def initialize(sysex: false, transport: nil) @sysex_enabled = sysex @transport = transport ? Transport.send(:resolve_transport!, transport) : Transport.auto_detect @inputs = Port::Map.new @outputs = Port::Map.new @state_change_callbacks = [] @port_state_subscriptions = [] @mutex = Mutex.new refresh_ports end |
Instance Attribute Details
#sysex_enabled ⇒ Object (readonly) Also known as: sysex_enabled?
Returns the value of attribute sysex_enabled.
9 10 11 |
# File 'lib/webmidi/access.rb', line 9 def sysex_enabled @sysex_enabled end |
Instance Method Details
#close ⇒ Object
57 58 59 60 |
# File 'lib/webmidi/access.rb', line 57 def close each(&:disconnect) self end |
#create_input(name) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/webmidi/access.rb', line 67 def create_input(name) handle = @transport.create_virtual_input(name) port = Port::Input.new( id: handle.device_info.id, name: handle.device_info.name, manufacturer: handle.device_info.manufacturer, version: handle.device_info.version, transport_handle: handle, sysex_enabled: @sysex_enabled ) register_port(port, @inputs) port end |
#create_output(name) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/webmidi/access.rb', line 81 def create_output(name) handle = @transport.create_virtual_output(name) port = Port::Output.new( id: handle.device_info.id, name: handle.device_info.name, manufacturer: handle.device_info.manufacturer, version: handle.device_info.version, transport_handle: handle, sysex_enabled: @sysex_enabled ) register_port(port, @outputs) port end |
#each(&block) ⇒ Object
62 63 64 65 |
# File 'lib/webmidi/access.rb', line 62 def each(&block) ports = @mutex.synchronize { @inputs.to_a + @outputs.to_a } ports.each(&block) end |
#fetch_input!(name_or_id) ⇒ Object
40 41 42 |
# File 'lib/webmidi/access.rb', line 40 def fetch_input!(name_or_id) input(name_or_id) || raise(PortNotFoundError, "Input port not found: #{name_or_id}") end |
#fetch_output!(name_or_id) ⇒ Object
44 45 46 |
# File 'lib/webmidi/access.rb', line 44 def fetch_output!(name_or_id) output(name_or_id) || raise(PortNotFoundError, "Output port not found: #{name_or_id}") end |
#input(name_or_id) ⇒ Object
32 33 34 |
# File 'lib/webmidi/access.rb', line 32 def input(name_or_id) @mutex.synchronize { @inputs[name_or_id] } end |
#inputs ⇒ Object
24 25 26 |
# File 'lib/webmidi/access.rb', line 24 def inputs @mutex.synchronize { @inputs.snapshot } end |
#on_state_change(&block) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/webmidi/access.rb', line 48 def on_state_change(&block) raise ArgumentError, "on_state_change requires a block" unless block @mutex.synchronize { @state_change_callbacks << block } CallbackSubscription.new do @mutex.synchronize { @state_change_callbacks.delete(block) } end end |
#output(name_or_id) ⇒ Object
36 37 38 |
# File 'lib/webmidi/access.rb', line 36 def output(name_or_id) @mutex.synchronize { @outputs[name_or_id] } end |
#outputs ⇒ Object
28 29 30 |
# File 'lib/webmidi/access.rb', line 28 def outputs @mutex.synchronize { @outputs.snapshot } end |