Class: MMPlayer::MIDI::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/mmplayer/midi/wrapper.rb

Overview

Wrapper for MIDI functionality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options = {}) ⇒ Wrapper

Returns a new instance of Wrapper.

Parameters:

  • input (UniMIDI::Input, Array<UniMIDI::Input>)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :buffer_length (Integer)

    Length of MIDI message buffer in seconds

  • :receive_channel (Integer)

    A MIDI channel to subscribe to. By default, responds to all



14
15
16
17
18
19
20
# File 'lib/mmplayer/midi/wrapper.rb', line 14

def initialize(input, options = {})
  @buffer_length = options[:buffer_length]
  @channel = options[:receive_channel]

  @message_handler = MessageHandler.new
  @listener = MIDIEye::Listener.new(input)
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



8
9
10
# File 'lib/mmplayer/midi/wrapper.rb', line 8

def channel
  @channel
end

#listenerObject (readonly)

Returns the value of attribute listener.



8
9
10
# File 'lib/mmplayer/midi/wrapper.rb', line 8

def listener
  @listener
end

#message_handlerObject (readonly)

Returns the value of attribute message_handler.



8
9
10
# File 'lib/mmplayer/midi/wrapper.rb', line 8

def message_handler
  @message_handler
end

Instance Method Details

#add_cc_callback(index, &callback) ⇒ Hash

Add a callback for a given MIDI control change

Parameters:

  • index (Integer, nil)

    The MIDI control change index to add a callback for eg 10

  • callback (Proc)

    The callback to execute when the given MIDI control change is received

Returns:

  • (Hash)


42
43
44
# File 'lib/mmplayer/midi/wrapper.rb', line 42

def add_cc_callback(index, &callback)
  @message_handler.add_callback(:cc, index, &callback)
end

#add_note_callback(note, &callback) ⇒ Hash

Add a callback for a given MIDI note

Parameters:

  • note (Integer, String, nil)

    The MIDI note to add a callback for eg 64 “E4”

  • callback (Proc)

    The callback to execute when the given MIDI note is received

Returns:

  • (Hash)


34
35
36
# File 'lib/mmplayer/midi/wrapper.rb', line 34

def add_note_callback(note, &callback)
  @message_handler.add_note_callback(note, &callback)
end

#add_system_callback(command, &callback) ⇒ Hash

Add a callback for a given MIDI system message

Parameters:

  • command (String, Symbol)

    The MIDI system command eg :start, :stop

  • callback (Proc)

    The callback to execute when the given MIDI command is received

Returns:

  • (Hash)


26
27
28
# File 'lib/mmplayer/midi/wrapper.rb', line 26

def add_system_callback(command, &callback)
  @message_handler.add_callback(:system, command, &callback)
end

#omni?Boolean

Whether the player is subscribed to all channels

Returns:

  • (Boolean)


73
74
75
# File 'lib/mmplayer/midi/wrapper.rb', line 73

def omni?
  @channel.nil?
end

#startBoolean

Start the MIDI listener

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'lib/mmplayer/midi/wrapper.rb', line 64

def start
  initialize_listener
  @start_time = Time.now.to_i
  @listener.start(:background => true)
  true
end

#stopBoolean

Stop the MIDI listener

Returns:

  • (Boolean)


48
49
50
# File 'lib/mmplayer/midi/wrapper.rb', line 48

def stop
  @listener.stop
end