Sha256: 8f75888e2408a9698b2b79eefd6be107a83ed6c1fe62c6e6c40b4f2c5bbdfbfc

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

require 'yaml'

module Music
module Transcription

# Abstraction of a musical part. Contains notes and loudness_profile settings.
#
# @author James Tunnell
#
# @!attribute [r] notes
#   @return [Array] The notes to be played.
#
# @!attribute [r] dynamic_profile
#   @return [Profile] Dynamic values profile
#
class Part
  attr_reader :notes, :dynamic_profile
  
  def initialize notes: [], dynamic_profile: Profile.new(Dynamics::MF)
    @notes = notes
    @dynamic_profile = dynamic_profile
  end
  
  # Produce an exact copy of the current object
  def clone
    Marshal.load(Marshal.dump(self))
  end
  
  # Compare the equality of another Part object.
  def ==(other)
    return (@notes == other.notes) &&
    (@dynamic_profile == other.dynamic_profile)
  end

  # Duration of part notes.
  def duration
    return @notes.inject(0) { |sum, note| sum + note.duration }
  end
  
  def transpose pitch_diff
    self.clone.transpose! pitch_diff
  end

  def transpose! pitch_diff
    @notes[0...-1].each do |note|
      note.transpose_pitches_and_links! pitch_diff
    end
    @notes[-1].transpose_pitches_only! pitch_diff
    return self
  end  
end

end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
music-transcription-0.5.2 lib/music-transcription/part.rb