lib/music-transcription/model/note.rb in music-transcription-0.11.0 vs lib/music-transcription/model/note.rb in music-transcription-0.13.0
- old
+ new
@@ -63,9 +63,41 @@
def stretch! ratio
@duration *= ratio
return self
end
+
+ 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
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