Class: Stretto::Player
- Defined in:
- lib/stretto/renderers/midiator/player.rb
Overview
Stretto default Player uses MIDIator for MIDI output.
Constant Summary collapse
- DEFAULT_BEAT =
TODO: can time signature be set?
4
Instance Attribute Summary collapse
-
#bpm ⇒ Object
Returns the value of attribute bpm.
-
#midi ⇒ Object
readonly
Returns the value of attribute midi.
Instance Method Summary collapse
-
#initialize(options = {:driver => :autodetect}) ⇒ Player
constructor
A new instance of Player.
-
#play(music_string_or_file) ⇒ Object
Plays the passed music string (or a File object containing a music string).
Constructor Details
#initialize(options = {:driver => :autodetect}) ⇒ Player
Returns a new instance of Player.
15 16 17 18 19 20 21 22 23 |
# File 'lib/stretto/renderers/midiator/player.rb', line 15 def initialize( = {:driver => :autodetect}) @midi = ::MIDIator::Interface.new if [:driver] == :autodetect @midi.autodetect_driver else # TODO: exceptions for unhandled drivers @midi.use [:driver] end end |
Instance Attribute Details
#bpm ⇒ Object
Returns the value of attribute bpm.
6 7 8 |
# File 'lib/stretto/renderers/midiator/player.rb', line 6 def bpm @bpm end |
#midi ⇒ Object (readonly)
Returns the value of attribute midi.
5 6 7 |
# File 'lib/stretto/renderers/midiator/player.rb', line 5 def midi @midi end |
Instance Method Details
#play(music_string_or_file) ⇒ Object
Plays the passed music string (or a File object containing a music string)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/stretto/renderers/midiator/player.rb', line 31 def play(music_string_or_file) @pattern = Stretto::Pattern.new(music_string_or_file) set_default_tempo layer_threads = [] @pattern.voices.each_value do |voice| voice.layers.each_value do |layer| layer_threads << Thread.new(layer) do |l| l.each { |e| play_element(e, voice.index) } end end end layer_threads.each { |t| t.join} end |