X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmusic-sequence.cc;h=644ba9beb727e5982603ba69485a1c4dfdda15b2;hb=926115ff42def8bc1ce767029e4f03c8072994ba;hp=e8493b8ada14ce36e54e593de9e2c30bff9e7fc5;hpb=4bb29573149a0ffa1f881c5e38a0fe68e9e76b67;p=lilypond.git diff --git a/lily/music-sequence.cc b/lily/music-sequence.cc index e8493b8ada..644ba9beb7 100644 --- a/lily/music-sequence.cc +++ b/lily/music-sequence.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1998--2011 Han-Wen Nienhuys + Copyright (C) 1998--2015 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 @@ -21,6 +21,8 @@ #include "warn.hh" #include "program-option.hh" +#include "duration.hh" +#include "moment.hh" #include "music.hh" #include "input.hh" @@ -28,7 +30,8 @@ void transpose_music_list (SCM lst, Pitch rq) { for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s)) - unsmob_music (scm_car (s))->transpose (rq); + if (Prob *p = unsmob (scm_car (s))) + p->transpose (rq); } Moment @@ -39,7 +42,7 @@ Music_sequence::cumulative_length (SCM l) for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) { - Moment l = unsmob_music (scm_car (s))->get_length (); + Moment l = unsmob (scm_car (s))->get_length (); if (last_len.grace_part_ && l.main_part_) last_len.grace_part_ = Rational (0); cumulative += last_len; @@ -58,7 +61,7 @@ Music_sequence::maximum_length (SCM l) Moment dur = 0; for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) { - Music *m = unsmob_music (scm_car (s)); + Music *m = unsmob (scm_car (s)); if (!m) programming_error ("Music sequence should have music elements"); else @@ -75,7 +78,22 @@ MAKE_SCHEME_CALLBACK (Music_sequence, maximum_length_callback, 1); SCM Music_sequence::maximum_length_callback (SCM m) { - Music *me = unsmob_music (m); + Music *me = unsmob (m); + return maximum_length (me->get_property ("elements")).smobbed_copy (); +} + +MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_length_callback, 1); +SCM +Music_sequence::event_chord_length_callback (SCM m) +{ + Music *me = unsmob (m); + Duration *d = unsmob (me->get_property ("duration")); + // Preset duration is used in chord repetitions. + if (d) + { + Moment mom = d->get_length (); + return mom.smobbed_copy (); + } return maximum_length (me->get_property ("elements")).smobbed_copy (); } @@ -83,7 +101,7 @@ MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1); SCM Music_sequence::cumulative_length_callback (SCM m) { - Music *me = unsmob_music (m); + Music *me = unsmob (m); return cumulative_length (me->get_property ("elements")).smobbed_copy (); } @@ -91,7 +109,7 @@ MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1); SCM Music_sequence::minimum_start_callback (SCM m) { - Music *me = unsmob_music (m); + Music *me = unsmob (m); return minimum_start (me->get_property ("elements")).smobbed_copy (); } @@ -99,7 +117,7 @@ MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1); SCM Music_sequence::first_start_callback (SCM m) { - Music *me = unsmob_music (m); + Music *me = unsmob (m); return first_start (me->get_property ("elements")).smobbed_copy (); } @@ -112,7 +130,7 @@ music_list_to_relative (SCM l, Pitch p, bool ret_first) Pitch last = p; for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) { - if (Music *m = unsmob_music (scm_car (s))) + if (Music *m = unsmob (scm_car (s))) { last = m->to_relative_octave (last); if (!count++) @@ -127,7 +145,7 @@ void compress_music_list (SCM l, Moment m) { for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) - unsmob_music (scm_car (s))->compress (m); + unsmob (scm_car (s))->compress (m); } Moment @@ -136,115 +154,40 @@ Music_sequence::minimum_start (SCM l) Moment m; for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) - m = min (m, unsmob_music (scm_car (s))->start_mom ()); + m = min (m, unsmob (scm_car (s))->start_mom ()); return m; } Moment Music_sequence::first_start (SCM l) { - Moment m; 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; + Music *mus = unsmob (scm_car (s)); + Moment start = mus->start_mom (); + if (mus->get_length ().to_bool () || start.to_bool ()) + return start; } - return m; + return Moment (); } MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2); SCM Music_sequence::simultaneous_relative_callback (SCM music, SCM pitch) { - Music *me = unsmob_music (music); - Pitch p = *unsmob_pitch (pitch); - - SCM elts = me->get_property ("elements"); - SCM copied = SCM_EOL; - if (lily_1_8_relative) - copied = ly_music_deep_copy (elts); - - Pitch retval = music_list_to_relative (elts, p, false); - - if (lily_1_8_relative) - { - - Pitch retval_1_8 = music_list_to_relative (copied, p, true); - if (retval_1_8 != retval) - lily_1_8_compatibility_used = true; - - retval = retval_1_8; - } - - return retval.smobbed_copy (); + Music *me = unsmob (music); + Pitch p = *unsmob (pitch); + return music_list_to_relative (me->get_property ("elements"), + p, false).smobbed_copy (); } MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2); SCM Music_sequence::event_chord_relative_callback (SCM music, SCM pitch) { - Music *me = unsmob_music (music); - Pitch p = *unsmob_pitch (pitch); + Music *me = unsmob (music); + Pitch p = *unsmob (pitch); return music_list_to_relative (me->get_property ("elements"), 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; -}