Sha256: aa3d1a160338711d0baa3c4e7fd8bc3804176e8bb8ec73311a6a2becb91b8f15
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
module Music module Transcription # Describes a pitch (for one note) that can be linked to a pitch in another note. # # @author James Tunnell # # @!attribute [rw] pitch # @return [Pitch] The pitch of the note. # # @!attribute [rw] link # @return [Link] Shows how the current note is related to a following note. # class Interval include Hashmake::HashMakeable attr_reader :pitch, :link # hashed-arg specs (for hash-makeable idiom) ARG_SPECS = { :pitch => arg_spec(:type => Pitch, :reqd => true), :link => arg_spec(:type => Link, :reqd => false, :default => ->(){ Link.new } ), } def initialize args hash_make args end # Return true if the @link relationship is not NONE. def linked? @link.relationship != Link::RELATIONSHIP_NONE end # Compare the equality of another Interval object. def == other return (@pitch == other.pitch) && (@link == other.link) end # Set the note pitch. # @param [Pitch] pitch The pitch to use. # @raise [ArgumentError] if pitch is not a Pitch. def pitch= pitch ARG_SPECS[:pitch].validate_value pitch @pitch = pitch end # Setup the relationship to a following note. # @param [Link] link The Link object to assign. def link= link ARG_SPECS[:link].validate_value link @link = link end # Produce an identical Note object. def clone Interval.new(:pitch => @pitch, :link => @link.clone) end end module_function def interval pitch, link = Link.new Interval.new(:pitch => pitch, :link => link) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
music-transcription-0.3.0 | lib/music-transcription/interval.rb |