X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmusic-scheme.cc;h=de5442e9664d0fa71d3d387d8a42e70b49ebc373;hb=90e4d7057f3857da049dfda3d130017d4719bd6b;hp=ffd7c5cdd837487d7fee158ce0a5712f93cb8ed2;hpb=f5e923a6ce8cebb7ef893c03ce56aa5e598002c9;p=lilypond.git diff --git a/lily/music-scheme.cc b/lily/music-scheme.cc index ffd7c5cdd8..de5442e966 100644 --- a/lily/music-scheme.cc +++ b/lily/music-scheme.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2005--2014 Han-Wen Nienhuys + Copyright (C) 2005--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 @@ -20,6 +20,8 @@ #include "music.hh" #include "duration.hh" +#include "input.hh" +#include "lily-imports.hh" #include "program-option.hh" #include "warn.hh" @@ -29,7 +31,7 @@ LY_DEFINE (ly_music_length, "ly:music-length", " it as a @code{Moment} object.") { LY_ASSERT_SMOB (Music, mus, 1); - Music *sc = Music::unsmob (mus); + Music *sc = unsmob (mus); return sc->get_length ().smobbed_copy (); } @@ -71,14 +73,14 @@ LY_DEFINE (ly_music_p, "ly:music?", 1, 0, 0, (SCM obj), "Is @var{obj} a music object?") { - return ly_bool2scm (Music::is_smob (obj)); + return ly_bool2scm (unsmob (obj)); } LY_DEFINE (ly_event_p, "ly:event?", 1, 0, 0, (SCM obj), "Is @var{obj} a proper (non-rhythmic) event object?") { - if (Music *m = Music::unsmob (obj)) + if (Music *m = unsmob (obj)) { return scm_from_bool (m->is_mus_type ("post-event")); } @@ -93,7 +95,7 @@ LY_DEFINE (ly_music_mutable_properties, "ly:music-mutable-properties", " constant and initialized by the @code{make-music} function.") { LY_ASSERT_SMOB (Music, mus, 1); - Music *m = Music::unsmob (mus); + Music *m = unsmob (mus); return m->get_property_alist (true); } @@ -106,7 +108,7 @@ LY_DEFINE (ly_music_list_p, "ly:music-list?", while (scm_is_pair (lst)) { - if (!Music::is_smob (scm_car (lst))) + if (!unsmob (scm_car (lst))) return SCM_BOOL_F; lst = scm_cdr (lst); } @@ -115,30 +117,55 @@ LY_DEFINE (ly_music_list_p, "ly:music-list?", } LY_DEFINE (ly_music_deep_copy, "ly:music-deep-copy", - 1, 0, 0, (SCM m), + 1, 1, 0, (SCM m, SCM origin), "Copy @var{m} and all sub expressions of@tie{}@var{m}." " @var{m} may be an arbitrary type; cons cells and music" - " are copied recursively.") + " are copied recursively. If @var{origin} is given," + " it is used as the origin for one level of music by calling" + " @code{ly:set-origin!} on the copy.") { - if (Music::is_smob (m)) - return Music::unsmob (m)->clone ()->unprotect (); - if (scm_is_pair (m)) - { - SCM copy = SCM_EOL; - do - { - copy = scm_cons (ly_music_deep_copy (scm_car (m)), copy); - m = scm_cdr (m); - } - while (scm_is_pair (m)); - // Oh, come on, GUILE. Why do you require the second argument - // of scm_reverse_x to be a proper list? That makes no sense. - // return scm_reverse_x (copy, ly_music_deep_copy (m)); - SCM last_cons = copy; - copy = scm_reverse_x (copy, SCM_EOL); - scm_set_cdr_x (last_cons, ly_music_deep_copy (m)); - return copy; - } + m = music_deep_copy (m); + + if (SCM_UNBNDP (origin)) + return m; + + if (Music *mus = unsmob (origin)) + origin = mus->get_property ("origin"); + + if (scm_is_false (origin) || scm_is_null (origin)) + return m; + + LY_ASSERT_SMOB (Input, origin, 2); + + set_origin (m, origin); + return m; +} + +LY_DEFINE (ly_set_origin_x, "ly:set-origin!", + 1, 1, 0, (SCM m, SCM origin), + "This sets the origin given in @var{origin} to @var{m}. " + " @var{m} will typically be a music expression or a list" + " of music. List structures are searched recursively," + " but recursion stops at the changed music expressions" + " themselves. " + " @var{origin} is generally of type @code{ly:input-location?}," + " defaulting to @code{(*location*)}. Other valid values for" + " @code{origin} are a music expression which is then used as" + " the source of location information, or @code{#f}" + " or @code{'()} in which case no action is performed. " + " The return value is @var{m} itself.") +{ + if (SCM_UNBNDP (origin)) + origin = scm_fluid_ref (Lily::f_location); + else if (Music *mus = unsmob (origin)) + origin = mus->get_property ("origin"); + + if (scm_is_false (origin) || scm_is_null (origin)) + return m; + + LY_ASSERT_SMOB (Input, origin, 2); + + set_origin (m, origin); return m; } @@ -150,8 +177,8 @@ LY_DEFINE (ly_music_transpose, "ly:music-transpose", LY_ASSERT_SMOB (Music, m, 1); LY_ASSERT_SMOB (Pitch, p, 2); - Music *sc = Music::unsmob (m); - Pitch *sp = Pitch::unsmob (p); + Music *sc = unsmob (m); + Pitch *sp = unsmob (p); sc->transpose (*sp); // SCM_UNDEFINED ? @@ -168,8 +195,8 @@ LY_DEFINE (ly_music_compress, "ly:music-compress", LY_ASSERT_SMOB (Music, m, 1); LY_ASSERT_SMOB (Moment, factor, 2); - Music *sc = Music::unsmob (m); - sc->compress (*Moment::unsmob (factor)); + Music *sc = unsmob (m); + sc->compress (*unsmob (factor)); return sc->self_scm (); } @@ -181,8 +208,8 @@ LY_DEFINE (ly_make_music_relative_x, "ly:make-music-relative!", LY_ASSERT_SMOB (Music, music, 1); LY_ASSERT_SMOB (Pitch, pitch, 2); - Pitch start = *Pitch::unsmob (pitch); - Music *m = Music::unsmob (music); + Pitch start = *unsmob (pitch); + Music *m = unsmob (music); Pitch last = m->to_relative_octave (start); return last.smobbed_copy (); @@ -194,9 +221,9 @@ LY_DEFINE (ly_music_duration_length, "ly:music-duration-length", 1, 0, 0, " length.") { LY_ASSERT_SMOB (Music, mus, 1); - Music *m = Music::unsmob (mus); + Music *m = unsmob (mus); - Duration *d = Duration::unsmob (m->get_property ("duration")); + Duration *d = unsmob (m->get_property ("duration")); Moment len; if (d) @@ -214,10 +241,10 @@ LY_DEFINE (ly_music_duration_compress, "ly:music-duration-compress", 2, 0, 0, LY_ASSERT_SMOB (Music, mus, 1); LY_ASSERT_SMOB (Moment, fact, 2); - Music *m = Music::unsmob (mus); - Moment *f = Moment::unsmob (fact); + Music *m = unsmob (mus); + Moment *f = unsmob (fact); - Duration *d = Duration::unsmob (m->get_property ("duration")); + Duration *d = unsmob (m->get_property ("duration")); if (d) m->set_property ("duration", d->compressed (f->main_part_).smobbed_copy ()); return SCM_UNSPECIFIED; @@ -236,7 +263,7 @@ LY_DEFINE (ly_transpose_key_alist, "ly:transpose-key-alist", " pitch @var{pit}.") { SCM newlist = SCM_EOL; - Pitch *p = Pitch::unsmob (pit); + Pitch *p = unsmob (pit); for (SCM s = l; scm_is_pair (s); s = scm_cdr (s)) { @@ -268,4 +295,3 @@ LY_DEFINE (ly_transpose_key_alist, "ly:transpose-key-alist", } return scm_reverse_x (newlist, SCM_EOL); } -