Class: MicroMIDI::Instructions::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/micromidi/instructions/input.rb,
lib/micromidi/instructions/shorthand.rb

Overview

Commands dealing with MIDI input

Instance Method Summary collapse

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

#joinBoolean 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
  options = args.last.kind_of?(Hash) ? args.pop : {}
  unless args.empty?
    match = { :class => message_classes(args) }
  end
  listener(match, options) 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
  options = args.last.kind_of?(Hash) ? args.pop : {}
  match = message_classes(args)
  listener(nil, options) do |event|
    yield(event[:message], event[:timestamp]) unless match.include?(event[:message].class)
  end
end

#thruObject 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)
  receive_options = thru_arguments(args)
  receive(*receive_options) { |message, timestamp| output(message) }
  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)
  receive_options = thru_arguments(args)
  receive_unless(*receive_options) { |message, timestamp| output(message) }
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

Options Hash (options):

  • :from (UniMIDI::Input)


87
88
89
90
91
# File 'lib/micromidi/instructions/input.rb', line 87

def wait_for_input(options = {})
  listener = options[:from] || @state.listeners.last || @state.thru_listeners.last
  listener.join
  true
end