From: Neil Puttock Date: Wed, 17 Feb 2010 22:30:47 +0000 (+0000) Subject: Rename Time_scaled_music_iterator -> Tuplet_iterator. X-Git-Tag: release/2.13.14-1~61 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=131fa6b31beae464e4e6730dc11a3e406e4893a4;p=lilypond.git Rename Time_scaled_music_iterator -> Tuplet_iterator. --- diff --git a/lily/time-scaled-music-iterator.cc b/lily/time-scaled-music-iterator.cc deleted file mode 100644 index f82bbbfb46..0000000000 --- a/lily/time-scaled-music-iterator.cc +++ /dev/null @@ -1,153 +0,0 @@ -/* - This file is part of LilyPond, the GNU music typesetter. - - Copyright (C) 1998--2010 Han-Wen Nienhuys , - Erik Sandberg - - 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 "context.hh" -#include "input.hh" -#include "international.hh" -#include "music.hh" -#include "music-wrapper-iterator.hh" -#include "stream-event.hh" - -/* - Iterates \times, by sending TupletSpanEvents at the start/end of each - tuplet bracket. Extra stop/start events are sent at regular - intervals if tupletSpannerDuration is set. -*/ -class Time_scaled_music_iterator : public Music_wrapper_iterator -{ -public: - DECLARE_SCHEME_CALLBACK (constructor, ()); - /* construction */ - DECLARE_CLASSNAME (Time_scaled_music_iterator); - Time_scaled_music_iterator (); -protected: - virtual void process (Moment m); - virtual void construct_children (); - virtual void derived_mark () const; - virtual Moment pending_moment () const; - - Music *create_event (Direction d); - -private: - - /* tupletSpannerDuration */ - Moment spanner_duration_; - - /* next time to add a stop/start pair */ - Moment next_split_mom_; - - /* Recycle start/stop events if tupletSpannerDuration is set. */ - SCM synthesized_events_; - - Context_handle tuplet_handler_; -}; - -Music* -Time_scaled_music_iterator::create_event (Direction d) -{ - SCM ev_scm = scm_call_2 (ly_lily_module_constant ("make-span-event"), - ly_symbol2scm ("TupletSpanEvent"), - scm_from_int (d)); - - Music *mus = get_music (); - - Music *ev = unsmob_music (ev_scm); - ev->set_spot (*mus->origin ()); - if (d == START) - { - ev->set_property ("numerator", mus->get_property ("numerator")); - ev->set_property ("denominator", mus->get_property ("denominator")); - ev->set_property ("tweaks", mus->get_property ("tweaks")); - ev->set_property ("length", spanner_duration_.smobbed_copy ()); - } - - synthesized_events_ = scm_cons (ev_scm, synthesized_events_); - return ev; -} - - -Time_scaled_music_iterator::Time_scaled_music_iterator () -{ - spanner_duration_ = next_split_mom_ = 0; - synthesized_events_ = SCM_EOL; -} - - -Moment -Time_scaled_music_iterator::pending_moment () const -{ - Moment next_mom = Music_wrapper_iterator::pending_moment (); - next_mom = min (next_mom, next_split_mom_); - - return next_mom; -} - - -void -Time_scaled_music_iterator::process (Moment m) -{ - if (spanner_duration_.to_bool () && - m.main_part_ == next_split_mom_) - { - descend_to_bottom_context (); - if (tuplet_handler_.get_outlet ()) - create_event (STOP)->send_to_context (tuplet_handler_.get_outlet ()); - - if (m.main_part_ < music_get_length ().main_part_) - { - tuplet_handler_.set_context (get_outlet ()); - report_event (create_event (START)); - - next_split_mom_ += spanner_duration_; - } - else - { - tuplet_handler_.set_context (0); - } - } - Music_wrapper_iterator::process (m); - if (child_iter_ && child_iter_->ok ()) - descend_to_child (child_iter_->get_outlet ()); - -} - -void -Time_scaled_music_iterator::construct_children () -{ - spanner_duration_ = music_get_length (); - - Moment *mp = unsmob_moment (get_outlet ()->get_property ("tupletSpannerDuration")); - if (mp) - spanner_duration_ = min (mp->main_part_, spanner_duration_); - - Music_wrapper_iterator::construct_children (); - - if (child_iter_ && child_iter_->ok ()) - descend_to_child (child_iter_->get_outlet ()); -} - -void -Time_scaled_music_iterator::derived_mark () const -{ - scm_gc_mark (synthesized_events_); - Music_wrapper_iterator::derived_mark (); -} - -IMPLEMENT_CTOR_CALLBACK (Time_scaled_music_iterator); diff --git a/lily/tuplet-iterator.cc b/lily/tuplet-iterator.cc new file mode 100644 index 0000000000..cfe4ce083d --- /dev/null +++ b/lily/tuplet-iterator.cc @@ -0,0 +1,149 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 1998--2010 Han-Wen Nienhuys , + Erik Sandberg + + 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 "context.hh" +#include "input.hh" +#include "international.hh" +#include "music.hh" +#include "music-wrapper-iterator.hh" +#include "stream-event.hh" + +/* + Iterates \times, by sending TupletSpanEvents at the start/end of each + tuplet bracket. Extra stop/start events are sent at regular + intervals if tupletSpannerDuration is set. +*/ +class Tuplet_iterator : public Music_wrapper_iterator +{ +public: + DECLARE_SCHEME_CALLBACK (constructor, ()); + /* construction */ + DECLARE_CLASSNAME (Tuplet_iterator); + Tuplet_iterator (); +protected: + virtual void process (Moment m); + virtual void construct_children (); + virtual void derived_mark () const; + virtual Moment pending_moment () const; + + Music *create_event (Direction d); + +private: + + /* tupletSpannerDuration */ + Moment spanner_duration_; + + /* next time to add a stop/start pair */ + Moment next_split_mom_; + + /* Recycle start/stop events if tupletSpannerDuration is set. */ + SCM synthesized_events_; + + Context_handle tuplet_handler_; +}; + +Music * +Tuplet_iterator::create_event (Direction d) +{ + SCM ev_scm = scm_call_2 (ly_lily_module_constant ("make-span-event"), + ly_symbol2scm ("TupletSpanEvent"), + scm_from_int (d)); + + Music *mus = get_music (); + + Music *ev = unsmob_music (ev_scm); + ev->set_spot (*mus->origin ()); + if (d == START) + { + ev->set_property ("numerator", mus->get_property ("numerator")); + ev->set_property ("denominator", mus->get_property ("denominator")); + ev->set_property ("tweaks", mus->get_property ("tweaks")); + ev->set_property ("length", spanner_duration_.smobbed_copy ()); + } + + synthesized_events_ = scm_cons (ev_scm, synthesized_events_); + return ev; +} + +Tuplet_iterator::Tuplet_iterator () +{ + spanner_duration_ = next_split_mom_ = 0; + synthesized_events_ = SCM_EOL; +} + +Moment +Tuplet_iterator::pending_moment () const +{ + Moment next_mom = Music_wrapper_iterator::pending_moment (); + next_mom = min (next_mom, next_split_mom_); + + return next_mom; +} + +void +Tuplet_iterator::process (Moment m) +{ + if (spanner_duration_.to_bool () + && m.main_part_ == next_split_mom_) + { + descend_to_bottom_context (); + if (tuplet_handler_.get_outlet ()) + create_event (STOP)->send_to_context (tuplet_handler_.get_outlet ()); + + if (m.main_part_ < music_get_length ().main_part_) + { + tuplet_handler_.set_context (get_outlet ()); + report_event (create_event (START)); + + next_split_mom_ += spanner_duration_; + } + else + tuplet_handler_.set_context (0); + } + Music_wrapper_iterator::process (m); + if (child_iter_ && child_iter_->ok ()) + descend_to_child (child_iter_->get_outlet ()); + +} + +void +Tuplet_iterator::construct_children () +{ + spanner_duration_ = music_get_length (); + + Moment *mp + = unsmob_moment (get_outlet ()->get_property ("tupletSpannerDuration")); + if (mp) + spanner_duration_ = min (mp->main_part_, spanner_duration_); + + Music_wrapper_iterator::construct_children (); + + if (child_iter_ && child_iter_->ok ()) + descend_to_child (child_iter_->get_outlet ()); +} + +void +Tuplet_iterator::derived_mark () const +{ + scm_gc_mark (synthesized_events_); + Music_wrapper_iterator::derived_mark (); +} + +IMPLEMENT_CTOR_CALLBACK (Tuplet_iterator); diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index f01dd2ca7e..973e59a403 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -578,7 +578,7 @@ Syntax: @code{\\times @var{fraction} @var{music}}, e.g., @code{\\times 2/3 @{ @dots{} @}} for triplets.") (length-callback . ,ly:music-wrapper::length-callback) (start-callback . ,ly:music-wrapper::start-callback) - (iterator-ctor . ,ly:time-scaled-music-iterator::constructor) + (iterator-ctor . ,ly:tuplet-iterator::constructor) (types . (time-scaled-music music-wrapper-music general-music)) ))