X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmusic.cc;h=ae75ff795273da024d404a76d144f10da52613bd;hb=b872748c6aa8bb721ced458691b38ac2fac5dfc8;hp=02dbe41499e644d184c356254933e4c1397fddfa;hpb=e8f544af29c93145d122efa8dcfc0548d9b84f0b;p=lilypond.git diff --git a/lily/music.cc b/lily/music.cc index 02dbe41499..ae75ff7952 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1997--2012 Han-Wen Nienhuys + Copyright (C) 1997--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 @@ -24,11 +24,11 @@ #include "duration.hh" #include "input.hh" #include "international.hh" -#include "ly-smobs.icc" #include "main.hh" #include "music-sequence.hh" #include "score.hh" #include "warn.hh" +#include "lily-imports.hh" /* Music is anything that has (possibly zero) duration and supports @@ -42,15 +42,18 @@ Music::internal_is_music_type (SCM k) const { SCM ifs = get_property ("types"); - return scm_c_memq (k, ifs) != SCM_BOOL_F; + return scm_is_true (scm_c_memq (k, ifs)); } -Music::Music (SCM init) - : Prob (ly_symbol2scm ("Music"), init) +Preinit_Music::Preinit_Music () { length_callback_ = SCM_EOL; start_callback_ = SCM_EOL; +} +Music::Music (SCM init) + : Prob (ly_symbol2scm ("Music"), init) +{ length_callback_ = get_property ("length-callback"); if (!ly_is_procedure (length_callback_)) length_callback_ = duration_length_callback_proc; @@ -68,7 +71,7 @@ Music::derived_mark () const SCM Music::copy_mutable_properties () const { - return ly_music_deep_copy (mutable_property_alist_); + return music_deep_copy (mutable_property_alist_); } void @@ -91,13 +94,13 @@ Moment Music::get_length () const { SCM lst = get_property ("length"); - if (unsmob_moment (lst)) - return *unsmob_moment (lst); + if (unsmob (lst)) + return *unsmob (lst); if (ly_is_procedure (length_callback_)) { SCM res = scm_call_1 (length_callback_, self_scm ()); - return *unsmob_moment (res); + return *unsmob (res); } return Moment (0); @@ -110,7 +113,7 @@ Music::start_mom () const if (ly_is_procedure (lst)) { SCM res = scm_call_1 (lst, self_scm ()); - return *unsmob_moment (res); + return *unsmob (res); } Moment m; @@ -134,7 +137,7 @@ Pitch Music::generic_to_relative_octave (Pitch last) { SCM elt = get_property ("element"); - Pitch *old_pit = unsmob_pitch (get_property ("pitch")); + Pitch *old_pit = unsmob (get_property ("pitch")); if (old_pit) { Pitch new_pit = *old_pit; @@ -158,9 +161,10 @@ Music::generic_to_relative_octave (Pitch last) last = new_pit; } - if (Music *m = unsmob_music (elt)) + if (Music *m = unsmob (elt)) last = m->to_relative_octave (last); + (void) music_list_to_relative (get_property ("articulations"), last, true); last = music_list_to_relative (get_property ("elements"), last, false); return last; } @@ -171,7 +175,7 @@ Music::to_relative_octave (Pitch last) SCM callback = get_property ("to-relative-callback"); if (ly_is_procedure (callback)) { - Pitch *p = unsmob_pitch (scm_call_2 (callback, self_scm (), + Pitch *p = unsmob (scm_call_2 (callback, self_scm (), last.smobbed_copy ())); return *p; } @@ -184,11 +188,11 @@ Music::compress (Moment factor) { SCM elt = get_property ("element"); - if (Music *m = unsmob_music (elt)) + if (Music *m = unsmob (elt)) m->compress (factor); compress_music_list (get_property ("elements"), factor); - Duration *d = unsmob_duration (get_property ("duration")); + Duration *d = unsmob (get_property ("duration")); if (d) set_property ("duration", d->compressed (factor.main_part_).smobbed_copy ()); @@ -197,71 +201,57 @@ Music::compress (Moment factor) /* This mutates alist. Hence, make sure that it is not shared */ + void -transpose_mutable (SCM alist, Pitch delta) +Prob::transpose (Pitch delta) { - for (SCM s = alist; scm_is_pair (s); s = scm_cdr (s)) + if (to_boolean (get_property ("untransposable"))) + return; + + for (SCM s = mutable_property_alist_; scm_is_pair (s); s = scm_cdr (s)) { SCM entry = scm_car (s); SCM prop = scm_car (entry); SCM val = scm_cdr (entry); SCM new_val = val; - if (Pitch *p = unsmob_pitch (val)) + if (Pitch *p = unsmob (val)) { Pitch transposed = p->transposed (delta); - if (transposed.get_alteration ().abs () > Rational (1, 1)) - { - string delta_str; - if (delta.get_alteration ().abs () > Rational (1, 1)) - delta_str = (delta.normalized ().to_string () - + " " + _ ("(normalized pitch)")); - else - delta_str = delta.to_string (); - - warning (_f ("Transposing %s by %s makes alteration larger than double", - p->to_string (), - delta_str)); - transposed = transposed.normalized (); - } + + if (scm_is_eq (prop, ly_symbol2scm ("tonic"))) + transposed = Pitch (-1, transposed.get_notename (), + transposed.get_alteration ()); new_val = transposed.smobbed_copy (); } - else if (prop == ly_symbol2scm ("element")) + else if (scm_is_eq (prop, ly_symbol2scm ("element"))) { - if (Music *m = unsmob_music (val)) + if (Prob *m = unsmob (val)) m->transpose (delta); } - else if (prop == ly_symbol2scm ("elements")) + else if (scm_is_eq (prop, ly_symbol2scm ("elements")) + || scm_is_eq (prop, ly_symbol2scm ("articulations"))) transpose_music_list (val, delta); - else if (prop == ly_symbol2scm ("pitch-alist") + else if (scm_is_eq (prop, ly_symbol2scm ("pitch-alist")) && scm_is_pair (val)) new_val = ly_transpose_key_alist (val, delta.smobbed_copy ()); - if (val != new_val) + if (!scm_is_eq (val, new_val)) scm_set_cdr_x (entry, new_val); } } -void -Music::transpose (Pitch delta) -{ - if (to_boolean (get_property ("untransposable"))) - return; - - transpose_mutable (mutable_property_alist_, delta); -} - void Music::set_spot (Input ip) { - set_property ("origin", make_input (ip)); + set_property ("origin", ip.smobbed_copy ()); } Input * Music::origin () const { - Input *ip = unsmob_input (get_property ("origin")); + Input *ip = unsmob (get_property ("origin")); return ip ? ip : &dummy_input_global; } @@ -277,7 +267,9 @@ Music::to_event () const if (!internal_is_music_type (class_name)) programming_error ("Not a music type"); - Stream_event *e = new Stream_event (class_name, mutable_property_alist_); + Stream_event *e = new Stream_event + (Lily::ly_make_event_class (class_name), + mutable_property_alist_); Moment length = get_length (); if (length.to_bool ()) e->set_property ("length", length.smobbed_copy ()); @@ -289,7 +281,7 @@ Music::to_event () const SCM art_ev = SCM_EOL; for (; scm_is_pair (art_mus); art_mus = scm_cdr (art_mus)) { - Music *m = unsmob_music (scm_car (art_mus)); + Music *m = unsmob (scm_car (art_mus)); art_ev = scm_cons (m->to_event ()->unprotect (), art_ev); } e->set_property ("articulations", scm_reverse_x (art_ev, SCM_EOL)); @@ -315,11 +307,10 @@ Music::send_to_context (Context *c) Music * make_music_by_name (SCM sym) { - SCM make_music_proc = ly_lily_module_constant ("make-music"); - SCM rv = scm_call_1 (make_music_proc, sym); + SCM rv = Lily::make_music (sym); /* UGH. */ - Music *m = unsmob_music (rv); + Music *m = unsmob (rv); m->protect (); return m; } @@ -328,8 +319,8 @@ MAKE_SCHEME_CALLBACK (Music, duration_length_callback, 1); SCM Music::duration_length_callback (SCM m) { - Music *me = unsmob_music (m); - Duration *d = unsmob_duration (me->get_property ("duration")); + Music *me = unsmob (m); + Duration *d = unsmob (me->get_property ("duration")); Moment mom; if (d) @@ -337,8 +328,39 @@ Music::duration_length_callback (SCM m) return mom.smobbed_copy (); } -Music * -unsmob_music (SCM m) +SCM +music_deep_copy (SCM m) { - return dynamic_cast (unsmob_prob (m)); + if (Music *mus = unsmob (m)) + return mus->clone ()->unprotect (); + if (scm_is_pair (m)) + { + SCM copy = SCM_EOL; + do + { + copy = scm_cons (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, music_deep_copy (m)); + SCM last_cons = copy; + copy = scm_reverse_x (copy, SCM_EOL); + scm_set_cdr_x (last_cons, music_deep_copy (m)); + return copy; + } + return m; +} + +void +set_origin (SCM m, SCM origin) +{ + while (scm_is_pair (m)) + { + set_origin (scm_car (m), origin); + m = scm_cdr (m); + } + if (Music *mus = unsmob (m)) + mus->set_property ("origin", origin); }