X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmusic-sequence.cc;h=42bfd8719f718ef86be08cc1cfbf269ed7bf6132;hb=1bc26969fe372d9e257d91f0ef6e1ca0f9999ed6;hp=30ca686e79d1071f092f88673acc8978ec2dc4e1;hpb=d8082113a0df616e7beabc0417c3590a3fac7320;p=lilypond.git diff --git a/lily/music-sequence.cc b/lily/music-sequence.cc index 30ca686e79..42bfd8719f 100644 --- a/lily/music-sequence.cc +++ b/lily/music-sequence.cc @@ -1,9 +1,20 @@ /* - music-sequence.cc -- implement Music_sequence + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 1998--2011 Han-Wen Nienhuys - (c) 1998--2006 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "music-sequence.hh" @@ -137,10 +148,10 @@ Music_sequence::first_start (SCM l) for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) { Music *mus = unsmob_music (scm_car (s)); - Moment l = mus->get_length (); - Moment s = mus->start_mom (); - if (l.to_bool () || s.to_bool ()) - return s; + Moment lt = mus->get_length (); + Moment st = mus->start_mom (); + if (lt.to_bool () || st.to_bool ()) + return st; } return m; } @@ -182,3 +193,58 @@ Music_sequence::event_chord_relative_callback (SCM music, SCM pitch) p, true).smobbed_copy (); } +MAKE_SCHEME_CALLBACK (Music_sequence, repeated_chord_relative_callback, 2); +SCM +Music_sequence::repeated_chord_relative_callback (SCM music, SCM pitch) +{ + Music *me = unsmob_music (music); + Music *repeated_chord = unsmob_music (me->get_property ("element")); + Music *original_chord = unsmob_music (me->get_property ("original-chord")); + + /* A repeated chord octave is not computed from the previous pitch, + * (this function `pitch' argument), but from the original chord, so + * that repeated chords have the same octave have the original chord, + * even though other simple notes have been entered meanwhile. + */ + assert (repeated_chord); + Pitch *p = 0; + /* Get the original chord first pitch */ + if (original_chord) + { + for (SCM s = original_chord->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s)) + { + if (Music *m = unsmob_music (scm_car (s))) + { + p = unsmob_pitch (m->get_property ("pitch")); + if (p) + break; + } + } + } + /* Use the `pitch' argument if no pitch found in original chord. */ + if (! p) + p = unsmob_pitch (pitch); + + /* Change the first note pitch to -1, to avoid octaviation. Indeed, + * the first pitch should be the same as the original chord first + * pitch. */ + for (SCM s = repeated_chord->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s)) + { + if (Music *m = unsmob_music (scm_car (s))) + { + Pitch *first_pitch = unsmob_pitch (m->get_property ("pitch")); + if (first_pitch) + { + Pitch new_pitch = Pitch (-1, + first_pitch->get_notename (), + first_pitch->get_alteration ()); + m->set_property ("pitch", new_pitch.smobbed_copy ()); + break; + } + } + } + music_list_to_relative (repeated_chord->get_property ("elements"), *p, true).smobbed_copy (); + /* Return `pitch' instead of the repeated chord first pitch, + * because `pitch' is the last explicitly entered pitch */ + return pitch; +}