Class: StepSequencer::SoundPlayer
- Inherits:
-
Object
- Object
- StepSequencer::SoundPlayer
- Defined in:
- lib/step_sequencer/sound_player.rb
Instance Attribute Summary collapse
-
#playing ⇒ Object
readonly
Returns the value of attribute playing.
Instance Method Summary collapse
-
#initialize(sources) ⇒ SoundPlayer
constructor
A new instance of SoundPlayer.
- #play(tempo: 120, string: nil, matrix: nil, limit: nil, hit_char: 'x', rest_char: '_') ⇒ Object
- #reset_state ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(sources) ⇒ SoundPlayer
Returns a new instance of SoundPlayer.
7 8 9 10 |
# File 'lib/step_sequencer/sound_player.rb', line 7 def initialize(sources) @sources = sources reset_state end |
Instance Attribute Details
#playing ⇒ Object (readonly)
Returns the value of attribute playing.
5 6 7 |
# File 'lib/step_sequencer/sound_player.rb', line 5 def end |
Instance Method Details
#play(tempo: 120, string: nil, matrix: nil, limit: nil, hit_char: 'x', rest_char: '_') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/step_sequencer/sound_player.rb', line 12 def play(tempo: 120, string: nil, matrix: nil, limit: nil, hit_char: 'x', rest_char: '_') @limit = limit @hit_char, @rest_char = hit_char, rest_char if raise( StandardError, "A sound player received #play when it was not in a stopped state. Use multiple instances instead" ) end if matrix play_from_matrix(tempo: tempo, matrix: matrix) else play_from_string(tempo: tempo, string: string) end = true end |
#reset_state ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/step_sequencer/sound_player.rb', line 34 def reset_state @thread = nil = false # It can't be called multiple times at once. # Use multiple instances instead. # There's a check to precaution against this. @row_lengths = [] @active_steps = [] @steps_played = 0 @limit = nil # an upper limit for steps_played, defaults to no limit end |
#stop ⇒ Object
29 30 31 32 |
# File 'lib/step_sequencer/sound_player.rb', line 29 def stop reset_state @thread&.kill end |