From: Mike Solomon Date: Wed, 18 Jan 2012 19:12:13 +0000 (+0100) Subject: Implements rhythmic-music-iterator X-Git-Tag: release/2.15.28-1~23^2~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=868a063d831ce4bf065ce1ec0226f4831bf3c3fc;p=lilypond.git Implements rhythmic-music-iterator --- diff --git a/lily/include/rhythmic-music-iterator.hh b/lily/include/rhythmic-music-iterator.hh new file mode 100644 index 0000000000..6c6b7c6615 --- /dev/null +++ b/lily/include/rhythmic-music-iterator.hh @@ -0,0 +1,44 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2012 Mike Solomon + + 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 . +*/ + +#ifndef RHYTHMIC_MUSIC_ITERATOR_HH +#define RHYTHMIC_MUSIC_ITERATOR_HH + +#include "simple-music-iterator.hh" + +/* + Iterator for atomic music objects: events are generated at the + beginning and at the end of the music. +*/ +class Rhythmic_music_iterator : public Simple_music_iterator +{ +protected: + DECLARE_CLASSNAME (Rhythmic_music_iterator); + //Moment last_processed_mom_; + +public: + DECLARE_SCHEME_CALLBACK (constructor, ()); + Rhythmic_music_iterator (); + virtual void process (Moment); + //virtual bool ok ()const; + //virtual Moment pending_moment ()const; +}; + +#endif /* RHYTHMIC_MUSIC_ITERATOR_HH */ + diff --git a/lily/rhythmic-music-iterator.cc b/lily/rhythmic-music-iterator.cc new file mode 100644 index 0000000000..b547653cd7 --- /dev/null +++ b/lily/rhythmic-music-iterator.cc @@ -0,0 +1,63 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2012 Mike Solomon + + 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 "rhythmic-music-iterator.hh" + +#include "context.hh" +#include "dispatcher.hh" +#include "duration.hh" +#include "input.hh" +#include "international.hh" +#include "music.hh" +#include "warn.hh" + +Rhythmic_music_iterator::Rhythmic_music_iterator () + : Simple_music_iterator () +{ + last_processed_mom_ = -1; +} + +void +Rhythmic_music_iterator::process (Moment m) +{ + if (last_processed_mom_ < Moment (0)) + { + + descend_to_bottom_context (); + + Stream_event *ev = get_music ()->to_event (); + SCM arts = ev->get_property ("articulations"); + Context *c = get_outlet (); + + if (scm_is_pair (arts)) + { + ev->set_property ("articulations", SCM_EOL); + c->event_source ()->broadcast (ev); + for (; scm_is_pair (arts); arts = scm_cdr (arts)) + c->event_source ()->broadcast (unsmob_stream_event (scm_car (arts))); + } + else + c->event_source ()->broadcast (ev); + + ev->unprotect (); + } + Simple_music_iterator::process (m); +} + +IMPLEMENT_CTOR_CALLBACK (Rhythmic_music_iterator); diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index 0dc9c7ee71..fc8c0a857b 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -331,6 +331,7 @@ Note the explicit font switch.") (NoteEvent . ((description . "A note.") + (iterator-ctor . ,ly:rhythmic-music-iterator::constructor) (types . (general-music event note-event rhythmic-event melodic-event)) )) @@ -483,6 +484,7 @@ Syntax: @code{\\unset @var{context}.@var{prop}}") . ((description . "A Rest. Syntax: @code{r4} for a quarter rest.") + (iterator-ctor . ,ly:rhythmic-music-iterator::constructor) (types . (general-music event rhythmic-event rest-event)) ))