Sha256: 28ff85639a26e9a2aa7c6990e563de65363b6a387b502f9e4452d64ae73f3411

Contents?: true

Size: 786 Bytes

Versions: 2

Compression:

Stored size: 786 Bytes

Contents

require 'yaml'

module Music
module Transcription

class Part
  attr_reader :start_dynamic, :dynamic_changes, :notes
  
  def initialize start_dynamic, notes: [], dynamic_changes: {}
    @notes = notes
    @start_dynamic = start_dynamic
    @dynamic_changes = dynamic_changes
    
    d = self.duration
    badkeys = dynamic_changes.keys.select {|k| k < 0 || k > d }
    if badkeys.any?
      raise ArgumentError, "dynamic profile has changes outside 0..d"
    end
  end
  
  def clone
    Marshal.load(Marshal.dump(self))
  end
  
  def ==(other)
    return (@notes == other.notes) &&
    (@start_dynamic == other.start_dynamic) &&
    (@dynamic_changes == other.dynamic_changes)
  end

  def duration
    return @notes.inject(0) { |sum, note| sum + note.duration }
  end
end

end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
music-transcription-0.7.1 lib/music-transcription/part.rb
music-transcription-0.7.0 lib/music-transcription/part.rb