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) ⇒ 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) ⇒ Input
9 10 11 |
# File 'lib/micromidi/instructions/input.rb', line 9 def initialize(state) @state = state end |
Instance Method Details
#join ⇒ Boolean Also known as: j
Join the listener thread
95 96 97 98 |
# File 'lib/micromidi/instructions/input.rb', line 95 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
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/micromidi/instructions/input.rb', line 17 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
38 39 40 41 42 43 44 45 |
# File 'lib/micromidi/instructions/input.rb', line 38 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
52 53 54 |
# File 'lib/micromidi/instructions/input.rb', line 52 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
77 78 79 80 |
# File 'lib/micromidi/instructions/input.rb', line 77 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
59 60 61 62 63 |
# File 'lib/micromidi/instructions/input.rb', line 59 def thru_if(*args) = thru_arguments(args) receive(*) { |, | output() } true end |
#thru_unless(*args) ⇒ Boolean Also known as: tu
Send input messages thru to the outputs unless they’re of the specified class
68 69 70 71 |
# File 'lib/micromidi/instructions/input.rb', line 68 def thru_unless(*args) = thru_arguments(args) receive_unless(*) { |, | output() } 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
87 88 89 90 91 |
# File 'lib/micromidi/instructions/input.rb', line 87 def wait_for_input( = {}) listener = [:from] || @state.listeners.last || @state.thru_listeners.last listener.join true end |