Class: Stretto::Player

Inherits:
Object show all
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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Player.

Examples:

Stretto::Player.new(:driver => :dls_synth)

Parameters:

  • options (Hash) (defaults to: {:driver => :autodetect})

    An array of options to initialize the MIDI driver Pass ‘:driver => :autodetect` to let MIDIator select the most appropiate driver based on the OS



15
16
17
18
19
20
21
22
23
# File 'lib/stretto/renderers/midiator/player.rb', line 15

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.



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

def bpm
  @bpm
end

#midiObject (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)

Examples:

Stretto::Player.new.play("C D E F G A B C6")

Parameters:

  • music_string_or_file (String, File)

    The stretto 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