Class: Stretto::Player

Inherits:
Object show all
Defined in:
lib/stretto/renderers/midiator/player.rb

Constant Summary

DEFAULT_BEAT =

TODO: can time signature be set?

4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {:driver => :autodetect}) ⇒ Player

each beat is a quarter note



10
11
12
13
14
15
16
17
18
# File 'lib/stretto/renderers/midiator/player.rb', line 10

def initialize(options = {:driver => :autodetect})
  @midi = ::MIDIator::Interface.new
  if options[:driver] == :autodetect
    @midi.autodetect_driver
  else
    # TODO: exceptions for unhandled drivers
    @midi.use options[:driver]
  end
end

Instance Attribute Details

#bpmObject

Returns the value of attribute bpm



5
6
7
# File 'lib/stretto/renderers/midiator/player.rb', line 5

def bpm
  @bpm
end

#midiObject (readonly)

Returns the value of attribute midi



4
5
6
# File 'lib/stretto/renderers/midiator/player.rb', line 4

def midi
  @midi
end

Instance Method Details

#play(music_string_or_file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stretto/renderers/midiator/player.rb', line 20

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