2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef MUSIC_ITERATOR_HH
21 #define MUSIC_ITERATOR_HH
23 #include "std-vector.hh"
25 #include "virtual-methods.hh"
26 #include "context-handle.hh"
31 Music_iterator is an object type that traverses the Music structure and
32 reports the events it finds to interpretation contexts. It is not yet
38 Conceptually a music-iterator operates on a queue of musical events
39 that are pending. This queue does not actually exist, but it is a
40 way of viewing and traversing music-expressions.
43 ok () -- events left ?
45 pending_mom () -- time tag of the next event to be processed.
46 PRECONDITION: this->ok () holds.
48 process (M) -- process all at M (Precondition: no events exist
49 before M, this->ok () holds). Side-effects:
51 * This removes all events at M from the pending queue.
53 * Typically this reports the music to an interpretation context,
54 thus changing the state of the interpretation context.
59 merge pending_moment and process?
61 class Music_iterator : public Smob<Music_iterator>
64 static int print_smob (SCM, SCM, scm_print_state *);
65 static SCM mark_smob (SCM);
66 static const char type_p_name_[];
67 virtual ~Music_iterator ();
72 DECLARE_CLASSNAME (Music_iterator);
73 Music_iterator (Music_iterator const &);
76 Moment music_get_length () const;
77 Moment music_start_mom () const;
79 void report_event (Music *);
80 virtual Context *get_outlet () const;
81 virtual void set_context (Context *);
82 static SCM get_static_get_iterator (Music *mus);
83 void init_context (Music *, Context *);
85 void substitute_outlet (Context *from, Context *to);
86 void descend_to_bottom_context ();
87 virtual void derived_substitute (Context *, Context *);
88 virtual Moment pending_moment () const;
89 virtual bool ok () const;
90 virtual bool run_always () const;
91 virtual void process (Moment until);
92 virtual void derived_mark () const;
93 virtual void construct_children ();
94 DECLARE_SCHEME_CALLBACK (constructor, ());
95 SCM get_iterator (Music *) const;
97 Music *get_music () const;
99 virtual void do_quit ();
100 void descend_to_child (Context *);
103 Context_handle handle_;
107 bool is_child_context (Context *me, Context *child);
109 #define IMPLEMENT_CTOR_CALLBACK(Class) \
110 LY_DEFINE_MEMBER_FUNCTION (Class, constructor, \
111 mangle_cxx_identifier (string (#Class) + "::constructor").c_str(), \
116 Class *c = (new Class); \
117 return c->unprotect (); \
121 #endif // MUSIC_ITERATOR_HH