class Music::Transcription::Note
Constants
- CONVERSION_METHOD
- DEFAULT_ARTICULATION
- PARSER
Attributes
accented[RW]
articulation[RW]
duration[RW]
links[R]
pitches[R]
Public Class Methods
add_note_method(name, dur)
click to toggle source
# File lib/music-transcription/model/note.rb, line 100 def self.add_note_method(name, dur) self.class.send(:define_method,name.to_sym) do |pitches = [], articulation: DEFAULT_ARTICULATION, links: {}, accented: false| Note.new(dur, pitches, articulation: articulation, links: links, accented: accented) end end
new(duration, pitches = [], articulation: DEFAULT_ARTICULATION, accented: false, links: {})
click to toggle source
# File lib/music-transcription/model/note.rb, line 14 def initialize duration, pitches = [], articulation: DEFAULT_ARTICULATION, accented: false, links: {} @duration = duration if !pitches.is_a? Enumerable pitches = [ pitches ] end @pitches = Set.new(pitches).sort @articulation = articulation @accented = accented @links = links end
Public Instance Methods
==(other)
click to toggle source
# File lib/music-transcription/model/note.rb, line 35 def == other return (@duration == other.duration) && (self.pitches == other.pitches) && (@links.to_a.sort == other.links.to_a.sort) && (@articulation == other.articulation) && (@accented == other.accented) end
check_methods()
click to toggle source
# File lib/music-transcription/model/note.rb, line 25 def check_methods [ :ensure_positive_duration ] end
clone()
click to toggle source
# File lib/music-transcription/model/note.rb, line 43 def clone Marshal.load(Marshal.dump(self)) end
ensure_positive_duration()
click to toggle source
# File lib/music-transcription/model/note.rb, line 29 def ensure_positive_duration unless @duration > 0 raise NonPositiveError, "duration #{@duration} is not positive" end end
stretch(ratio)
click to toggle source
# File lib/music-transcription/model/note.rb, line 59 def stretch ratio self.clone.stretch! ratio end
stretch!(ratio)
click to toggle source
# File lib/music-transcription/model/note.rb, line 63 def stretch! ratio @duration *= ratio return self end
to_s()
click to toggle source
# File lib/music-transcription/model/note.rb, line 68 def to_s d = @duration.to_r if d.denominator == 1 dur_str = "#{d.numerator}" elsif d.numerator == 1 dur_str = "/#{d.denominator}" else dur_str = d.to_s end art_str = case @articulation when Articulations::SLUR then "=" when Articulations::LEGATO then "|" when Articulations::TENUTO then "_" when Articulations::PORTATO then "%" when Articulations::STACCATO then "." when Articulations::STACCATISSIMO then "'" else "" end pitch_links_str = @pitches.map do |p| if @links.has_key?(p) p.to_s + @links[p].to_s else p.to_s end end.join(",") acc_str = @accented ? "!" : "" return dur_str + art_str + pitch_links_str + acc_str end
transpose(diff)
click to toggle source
# File lib/music-transcription/model/note.rb, line 47 def transpose diff self.clone.transpose! diff end
transpose!(diff)
click to toggle source
# File lib/music-transcription/model/note.rb, line 51 def transpose! diff @pitches = @pitches.map {|pitch| pitch.transpose(diff) } @links = Hash[ @links.map do |k,v| [ k.transpose(diff), v.transpose(diff) ] end ] return self end