class MVLC::Context
DSL context for interfacing an video player instance with MIDI
Attributes
midi[R]
playback_thread[R]
player[R]
Public Class Methods
new(midi_input, options = {}, &block)
click to toggle source
@param [UniMIDI::Input, Array<UniMIDI::Input>] midi_input @param [Hash] options @option options [Integer] :midi_buffer_length Length of MIDI
message buffer in seconds @option options [Integer] :receive_channel (also: :rx_channel) A MIDI
channel to subscribe to. By default, responds to all @yield
# File lib/mvlc/context.rb, line 17 def initialize(midi_input, options = {}, &block) midi_options = { :buffer_length => options[:midi_buffer_length], :receive_channel => options[:receive_channel] || options[:rx_channel] } @midi = MIDI.new(midi_input, midi_options) @player = Player.new instance_eval(&block) if block_given? end
Public Instance Methods
start(options = {})
click to toggle source
Start listening for MIDI
, start video player @param [Hash] options @option options [Boolean] :background Whether to run in a background thread @return [Boolean]
# File lib/mvlc/context.rb, line 31 def start(options = {}) @midi.start begin @playback_thread = ::MVLC::Thread.new(:timeout => false) do playback_loop end @playback_thread.join unless !!options[:background] rescue SystemExit, Interrupt => e stop raise(e) end true end
stop()
click to toggle source
Stop the player @return [Boolean]
# File lib/mvlc/context.rb, line 47 def stop @midi.stop @player.quit @playback_thread.kill true end
Private Instance Methods
playback_loop()
click to toggle source
Main playback loop
# File lib/mvlc/context.rb, line 57 def playback_loop until @player.active? sleep(0.1) end @player.playback_loop true end