Method: Beats::Track#initialize
- Defined in:
- lib/beats/track.rb
#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 |