Class: MicroMIDI::Instructions::Input
- Inherits:
-
Object
- Object
- MicroMIDI::Instructions::Input
- Includes:
- MIDIMessage
- Defined in:
- lib/micromidi/instructions/input.rb,
lib/micromidi/instructions/shorthand.rb
Instance Method Summary collapse
-
#initialize(state) ⇒ Input
constructor
A new instance of Input.
- #join ⇒ Object (also: #j)
-
#receive(*a, &block) ⇒ Object
(also: #gets, #handle, #listen, #listen_for, #when_receive, #rc)
bind an event that will be called every time a message is received.
- #receive_unless(*a, &block) ⇒ Object (also: #handle_unless, #listen_unless, #listen_for_unless, #unless_receive, #rcu)
-
#thru ⇒ Object
(also: #t)
send input messages thru to the outputs.
-
#thru_except(*a, &block) ⇒ Object
(also: #te)
like thru_unless except a block can be passed that will be called when notes specified as the unless arrive.
-
#thru_if(*a) ⇒ Object
send input messages thru to the outputs if it has a specific class.
-
#thru_unless(*a) ⇒ Object
(also: #tu)
send input messages thru to the outputs unless of a specific class.
-
#wait_for_input(options = {}) ⇒ Object
(also: #w)
wait for input on the last input passed in can pass the option :from => [an input] to specify which one to wait on.
Constructor Details
#initialize(state) ⇒ Input
Returns a new instance of Input.
11 12 13 |
# File 'lib/micromidi/instructions/input.rb', line 11 def initialize(state) @state = state end |
Instance Method Details
#join ⇒ Object Also known as: j
68 69 70 |
# File 'lib/micromidi/instructions/input.rb', line 68 def join loop { wait_for_input } end |
#receive(*a, &block) ⇒ Object Also known as: gets, handle, listen, listen_for, when_receive, rc
bind an event that will be called every time a message is received
16 17 18 19 20 |
# File 'lib/micromidi/instructions/input.rb', line 16 def receive(*a, &block) = a.last.kind_of?(Hash) ? a.pop : {} match = a.empty? ? nil : { :class => msg_classes(a) } listener(match, ) { |event| yield(event[:message], event[:timestamp]) } end |
#receive_unless(*a, &block) ⇒ Object Also known as: handle_unless, listen_unless, listen_for_unless, unless_receive, rcu
27 28 29 30 31 |
# File 'lib/micromidi/instructions/input.rb', line 27 def receive_unless(*a, &block) = a.last.kind_of?(Hash) ? a.pop : {} match = { :class => msg_classes(a) } listener(nil, ) { |event| yield(event[:message], event[:timestamp]) unless match.include?(event[:message].class) } end |
#thru ⇒ Object Also known as: t
send input messages thru to the outputs
38 39 40 |
# File 'lib/micromidi/instructions/input.rb', line 38 def thru thru_if end |
#thru_except(*a, &block) ⇒ Object Also known as: te
like thru_unless except a block can be passed that will be called when notes specified as the unless arrive
56 57 58 59 |
# File 'lib/micromidi/instructions/input.rb', line 56 def thru_except(*a, &block) thru_unless(*a) receive(*a, &block) end |
#thru_if(*a) ⇒ Object
send input messages thru to the outputs if it has a specific class
43 44 45 46 |
# File 'lib/micromidi/instructions/input.rb', line 43 def thru_if(*a) a.last.kind_of?(Hash) ? a.last[:thru] = true : a.push({ :thru => true }) receive(*a) { |, | output() } end |
#thru_unless(*a) ⇒ Object Also known as: tu
send input messages thru to the outputs unless of a specific class
49 50 51 52 |
# File 'lib/micromidi/instructions/input.rb', line 49 def thru_unless(*a) a.last.kind_of?(Hash) ? a.last[:thru] = true : a.push({ :thru => true }) receive_unless(*a) { |, | output() } end |
#wait_for_input(options = {}) ⇒ Object Also known as: w
wait for input on the last input passed in can pass the option :from => [an input] to specify which one to wait on
63 64 65 66 |
# File 'lib/micromidi/instructions/input.rb', line 63 def wait_for_input( = {}) listener = [:from] || @state.listeners.last || @state.thru_listeners.last listener.join end |