Class: Webmidi::Port::Output
- Inherits:
-
Base
- Object
- Base
- Webmidi::Port::Output
show all
- Defined in:
- lib/webmidi/port/output.rb
Instance Attribute Summary
Attributes inherited from Base
#id, #manufacturer, #name, #type, #version
Instance Method Summary
collapse
-
#<<(message) ⇒ Object
-
#all_notes_off(channel: nil) ⇒ Object
-
#clear ⇒ Object
-
#close ⇒ Object
-
#control_change(cc, value, channel: 0) ⇒ Object
-
#disconnect ⇒ Object
-
#initialize(**kwargs) ⇒ Output
constructor
A new instance of Output.
-
#note_off(note, velocity: 0, channel: 0) ⇒ Object
-
#note_on(note, velocity: 100, channel: 0) ⇒ Object
-
#pitch_bend(value, channel: 0) ⇒ Object
-
#program_change(program, channel: 0) ⇒ Object
-
#reset ⇒ Object
-
#send(message, timestamp: nil) ⇒ Object
-
#send_all(*messages) ⇒ Object
-
#use(middleware = nil, **options, &block) ⇒ Object
Methods inherited from Base
#connected?, #connection, #on_state_change, #open, #open?, #state, #sysex_enabled?
Constructor Details
#initialize(**kwargs) ⇒ Output
Returns a new instance of Output.
6
7
8
9
10
11
12
13
14
|
# File 'lib/webmidi/port/output.rb', line 6
def initialize(**kwargs)
super(**kwargs, type: :output)
@middleware_stack = nil
@scheduled_messages = []
@scheduler_mutex = Mutex.new
@scheduler_cv = ConditionVariable.new
@scheduler_thread = nil
@scheduler_shutdown = false
end
|
Instance Method Details
#<<(message) ⇒ Object
74
75
76
|
# File 'lib/webmidi/port/output.rb', line 74
def <<(message)
send(message)
end
|
#all_notes_off(channel: nil) ⇒ Object
#clear ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/webmidi/port/output.rb', line 32
def clear
@scheduler_mutex.synchronize do
@scheduled_messages.clear
@scheduler_cv.broadcast
end
self
end
|
#close ⇒ Object
101
102
103
104
|
# File 'lib/webmidi/port/output.rb', line 101
def close
shutdown_scheduler
super
end
|
#control_change(cc, value, channel: 0) ⇒ Object
48
49
50
|
# File 'lib/webmidi/port/output.rb', line 48
def control_change(cc, value, channel: 0)
send(Message.control_change(cc, value, channel: channel))
end
|
#disconnect ⇒ Object
106
107
108
109
|
# File 'lib/webmidi/port/output.rb', line 106
def disconnect
shutdown_scheduler
super
end
|
#note_off(note, velocity: 0, channel: 0) ⇒ Object
44
45
46
|
# File 'lib/webmidi/port/output.rb', line 44
def note_off(note, velocity: 0, channel: 0)
send(Message.note_off(note, velocity: velocity, channel: channel))
end
|
#note_on(note, velocity: 100, channel: 0) ⇒ Object
40
41
42
|
# File 'lib/webmidi/port/output.rb', line 40
def note_on(note, velocity: 100, channel: 0)
send(Message.note_on(note, velocity: velocity, channel: channel))
end
|
#pitch_bend(value, channel: 0) ⇒ Object
56
57
58
|
# File 'lib/webmidi/port/output.rb', line 56
def pitch_bend(value, channel: 0)
send(Message.pitch_bend(value, channel: channel))
end
|
#program_change(program, channel: 0) ⇒ Object
52
53
54
|
# File 'lib/webmidi/port/output.rb', line 52
def program_change(program, channel: 0)
send(Message.program_change(program, channel: channel))
end
|
#reset ⇒ Object
69
70
71
72
|
# File 'lib/webmidi/port/output.rb', line 69
def reset
send(Message.system_reset)
self
end
|
#send(message, timestamp: nil) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/webmidi/port/output.rb', line 16
def send(message, timestamp: nil)
open unless open?
message = apply_middleware(message)
return self unless message
byte_messages = outbound_byte_messages(message)
byte_messages.each { |bytes| ensure_sysex_permitted!(bytes) }
if timestamp && timestamp > current_timestamp
schedule(byte_messages, timestamp)
else
byte_messages.each { |bytes| write_bytes(bytes) }
end
self
end
|
#send_all(*messages) ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/webmidi/port/output.rb', line 90
def send_all(*messages)
items = if messages.size == 1 && messages.first.is_a?(Array) &&
messages.first.all? { |message| message.is_a?(Message::Base) }
messages.first
else
messages
end
items.each { |msg| send(msg) }
self
end
|
#use(middleware = nil, **options, &block) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/webmidi/port/output.rb', line 78
def use(middleware = nil, **options, &block)
require_relative "../middleware"
@middleware_stack ||= Middleware::Stack.new
if middleware.is_a?(Middleware::Stack) && options.empty? && !block
@middleware_stack = middleware
else
@middleware_stack.use(middleware || block, **options)
end
self
end
|