Class: Beats::Track
- Inherits:
-
Object
- Object
- Beats::Track
- Defined in:
- lib/beats/track.rb
Overview
Domain object which models a kit sound playing a rhythm. For example, a bass drum playing every quarter note for two measures.
This object is like sheet music; the AudioEngine is responsible creating actual audio data for a Track (with the help of a Kit).
Defined Under Namespace
Classes: InvalidRhythmError
Constant Summary collapse
- REST =
"."- BEAT =
"X"- BARLINE =
"|"- SPACE =
" "- DISALLOWED_CHARACTERS =
I.e., anything not an ‘X’, ‘.’, ‘|’, or ‘ ’
/[^X\.| ]/
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rhythm ⇒ Object
readonly
Returns the value of attribute rhythm.
-
#step_count ⇒ Object
readonly
Returns the value of attribute step_count.
-
#trigger_step_lengths ⇒ Object
readonly
Returns the value of attribute trigger_step_lengths.
Instance Method Summary collapse
-
#initialize(name, rhythm) ⇒ Track
constructor
A new instance of Track.
Constructor Details
#initialize(name, rhythm) ⇒ Track
Returns a new instance of Track.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/beats/track.rb', line 16 def initialize(name, rhythm) unless name.is_a?(String) raise ArgumentError, "Track name '#{name.inspect}' is invalid, must be a String" end unless rhythm.is_a?(String) && rhythm.match(DISALLOWED_CHARACTERS) == nil raise InvalidRhythmError, "Track '#{name}' has an invalid rhythm: '#{rhythm.inspect}'. Can only contain '#{BEAT}', '#{REST}', '#{BARLINE}', or ' '" end @name = name.dup.freeze @rhythm = rhythm.delete(BARLINE + SPACE).freeze @step_count = @rhythm.length @trigger_step_lengths = calculate_trigger_step_lengths.freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
32 33 34 |
# File 'lib/beats/track.rb', line 32 def name @name end |
#rhythm ⇒ Object (readonly)
Returns the value of attribute rhythm.
32 33 34 |
# File 'lib/beats/track.rb', line 32 def rhythm @rhythm end |
#step_count ⇒ Object (readonly)
Returns the value of attribute step_count.
32 33 34 |
# File 'lib/beats/track.rb', line 32 def step_count @step_count end |
#trigger_step_lengths ⇒ Object (readonly)
Returns the value of attribute trigger_step_lengths.
32 33 34 |
# File 'lib/beats/track.rb', line 32 def trigger_step_lengths @trigger_step_lengths end |