Class: MMPlayer::Context
- Inherits:
-
Object
- Object
- MMPlayer::Context
- Includes:
- Helper::Numbers, Instructions::MIDI, Instructions::Player
- Defined in:
- lib/mmplayer/context.rb
Overview
DSL context for interfacing an instance of MPlayer with MIDI
Instance Attribute Summary collapse
-
#midi ⇒ Object
readonly
Returns the value of attribute midi.
-
#player ⇒ Object
readonly
Returns the value of attribute player.
Instance Method Summary collapse
-
#initialize(midi_input, options = {}) { ... } ⇒ Context
constructor
A new instance of Context.
-
#start(options = {}) ⇒ Boolean
Start listening for MIDI Note that MPlayer will start when Context#play (aka Instructions::Player#play) is called.
-
#stop ⇒ Boolean
Stop the player.
Methods included from Instructions::Player
Methods included from Instructions::MIDI
#on_cc, #on_note, #on_system, #receive_channel
Methods included from Helper::Numbers
Constructor Details
#initialize(midi_input, options = {}) { ... } ⇒ Context
Returns a new instance of Context.
18 19 20 21 22 23 24 25 26 |
# File 'lib/mmplayer/context.rb', line 18 def initialize(midi_input, = {}, &block) = { :buffer_length => [:midi_buffer_length], :receive_channel => [:receive_channel] || [:rx_channel] } @midi = MIDI.new(midi_input, ) @player = Player.new(:flags => [:mplayer_flags]) instance_eval(&block) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MMPlayer::Instructions::Player
Instance Attribute Details
#midi ⇒ Object (readonly)
Returns the value of attribute midi.
10 11 12 |
# File 'lib/mmplayer/context.rb', line 10 def midi @midi end |
#player ⇒ Object (readonly)
Returns the value of attribute player.
10 11 12 |
# File 'lib/mmplayer/context.rb', line 10 def player @player end |
Instance Method Details
#start(options = {}) ⇒ Boolean
Start listening for MIDI Note that MPlayer will start when Context#play (aka Instructions::Player#play) is called
33 34 35 36 37 38 |
# File 'lib/mmplayer/context.rb', line 33 def start( = {}) @midi.start @playback_thread = playback_loop @playback_thread.join unless !![:background] true end |
#stop ⇒ Boolean
Stop the player
42 43 44 45 46 47 |
# File 'lib/mmplayer/context.rb', line 42 def stop @midi.stop @player.quit @playback_thread.kill true end |