Class: MicroMIDI::Instructions::Input
- Inherits:
-
Object
- Object
- MicroMIDI::Instructions::Input
- Defined in:
- lib/micromidi/instructions/input.rb,
lib/micromidi/instructions/shorthand.rb
Overview
Commands dealing with MIDI input
Instance Method Summary collapse
-
#initialize(state, &thru_action) ⇒ Input
constructor
A new instance of Input.
-
#join ⇒ Boolean
(also: #j)
Join the listener thread.
-
#receive(*args, &callback) ⇒ Boolean
(also: #gets, #handle, #listen, #listen_for, #when_receive, #rc)
Bind an event that will be fired when a message is received.
-
#receive_unless(*args, &callback) ⇒ Boolean
(also: #handle_unless, #listen_unless, #listen_for_unless, #unless_receive, #rcu)
Bind an event that will be fired when a message is received.
-
#thru ⇒ Object
(also: #t)
Send input messages thru to the outputs.
-
#thru_except(*args, &callback) ⇒ Boolean
(also: #te)
Similar to Input#thru_unless except a callback can be passed that will be fired when notes specified arrive.
-
#thru_if(*args) ⇒ Boolean
Send input messages thru to the outputs if they have a specified class.
-
#thru_unless(*args) ⇒ Boolean
(also: #tu)
Send input messages thru to the outputs unless they’re of the specified class.
-
#wait_for_input(options = {}) ⇒ Boolean
(also: #w)
Wait for input on the last input passed in (blocking) Can pass the option :from => [an input] to specify which one to wait on.
Constructor Details
#initialize(state, &thru_action) ⇒ Input
Returns a new instance of Input.
10 11 12 13 |
# File 'lib/micromidi/instructions/input.rb', line 10 def initialize(state, &thru_action) @state = state @thru_action = thru_action end |
Instance Method Details
#join ⇒ Boolean Also known as: j
Join the listener thread
97 98 99 100 |
# File 'lib/micromidi/instructions/input.rb', line 97 def join loop { wait_for_input } true end |
#receive(*args, &callback) ⇒ Boolean Also known as: gets, handle, listen, listen_for, when_receive, rc
Bind an event that will be fired when a message is received
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/micromidi/instructions/input.rb', line 19 def receive(*args, &callback) args = args.dup = args.last.kind_of?(Hash) ? args.pop : {} unless args.empty? match = { :class => (args) } end listener(match, ) do |event| yield(event[:message], event[:timestamp]) end true end |
#receive_unless(*args, &callback) ⇒ Boolean Also known as: handle_unless, listen_unless, listen_for_unless, unless_receive, rcu
Bind an event that will be fired when a message is received
40 41 42 43 44 45 46 47 |
# File 'lib/micromidi/instructions/input.rb', line 40 def receive_unless(*args, &callback) args = args.dup = args.last.kind_of?(Hash) ? args.pop : {} match = (args) listener(nil, ) do |event| yield(event[:message], event[:timestamp]) unless match.include?(event[:message].class) end end |
#thru ⇒ Object Also known as: t
Send input messages thru to the outputs
54 55 56 |
# File 'lib/micromidi/instructions/input.rb', line 54 def thru thru_if end |
#thru_except(*args, &callback) ⇒ Boolean Also known as: te
Similar to Input#thru_unless except a callback can be passed that will be fired when notes specified arrive
79 80 81 82 |
# File 'lib/micromidi/instructions/input.rb', line 79 def thru_except(*args, &callback) thru_unless(*args) receive(*args, &callback) end |
#thru_if(*args) ⇒ Boolean
Send input messages thru to the outputs if they have a specified class
61 62 63 64 65 |
# File 'lib/micromidi/instructions/input.rb', line 61 def thru_if(*args) = thru_arguments(args) receive(*) { |, | @thru_action.call() } true end |
#thru_unless(*args) ⇒ Boolean Also known as: tu
Send input messages thru to the outputs unless they’re of the specified class
70 71 72 73 |
# File 'lib/micromidi/instructions/input.rb', line 70 def thru_unless(*args) = thru_arguments(args) receive_unless(*) { |, | @thru_action.call() } end |
#wait_for_input(options = {}) ⇒ Boolean Also known as: w
Wait for input on the last input passed in (blocking) Can pass the option :from => [an input] to specify which one to wait on
89 90 91 92 93 |
# File 'lib/micromidi/instructions/input.rb', line 89 def wait_for_input( = {}) listener = [:from] || @state.listeners.last || @state.thru_listeners.last listener.join true end |