Class: Patch::IO::MIDI::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/patch/io/midi/input.rb

Overview

MIDI Input functions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, device, options = {}) ⇒ Input

Returns a new instance of Input.

Parameters:

  • id (Fixnum)
  • device (String, UniMIDI::Input)
  • options (Hash) (defaults to: {})

Options Hash (options):



16
17
18
19
20
21
# File 'lib/patch/io/midi/input.rb', line 16

def initialize(id, device, options = {})
  @log = options[:log]
  @id = id
  @device = get_input(device)
  @listener = MIDIEye::Listener.new(@device) unless @device.nil?
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



10
11
12
# File 'lib/patch/io/midi/input.rb', line 10

def device
  @device
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/patch/io/midi/input.rb', line 10

def id
  @id
end

#listenerObject (readonly)

Returns the value of attribute listener.



10
11
12
# File 'lib/patch/io/midi/input.rb', line 10

def listener
  @listener
end

Instance Method Details

#active?Boolean

Is the input active?

Returns:

  • (Boolean)


36
37
38
# File 'lib/patch/io/midi/input.rb', line 36

def active?
  @listener.running?
end

#disable(patch) ⇒ Boolean

Clear message handlers

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/patch/io/midi/input.rb', line 53

def disable(patch)
  @listener.event.clear
  true
end

#listen(patch, &callback) ⇒ Boolean

Specify a mpatch context and handler callback to use when messages are received

Parameters:

Returns:

  • (Boolean)

    Whether adding the callback was successful



62
63
64
65
66
67
68
69
70
71
# File 'lib/patch/io/midi/input.rb', line 62

def listen(patch, &callback)
  if !@listener.nil?
    @listener.listen_for(:class => [MIDIMessage::ControlChange]) do |event|
      handle_event_received(patch, event, &callback)
    end
    true
  else
    false
  end
end

#startBoolean

Start listening for MIDI messages

Returns:

  • (Boolean)

    Whether the listener was started



25
26
27
28
29
30
31
32
# File 'lib/patch/io/midi/input.rb', line 25

def start
  if !@listener.nil?
    @listener.run(:background => true)
    true
  else
    false
  end
end

#stopBoolean

Stop the MIDI listener

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
# File 'lib/patch/io/midi/input.rb', line 42

def stop
  if !@listener.nil?
    @listener.stop
    true
  else
    false
  end
end