2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 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: ok () holds.
48 process (M) -- process all at M (Precondition: no events exist
49 before M, 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 int print_smob (SCM, scm_print_state *) const;
65 SCM mark_smob () const;
66 static const char * const type_p_name_;
67 virtual ~Music_iterator ();
72 DECLARE_CLASSNAME (Music_iterator);
74 Music_iterator (Music_iterator const &); // Do not define! Not copyable!
77 Moment music_get_length () const;
78 // music_start_mom () is calculated relative to the time where the
79 // iterator occurs in the music stream, so it will usually be
80 // non-zero only for expressions starting with grace notes.
81 Moment music_start_mom () const;
83 void report_event (Music *);
84 virtual Context *get_outlet () const;
85 virtual void set_context (Context *);
86 static SCM get_static_get_iterator (Music *mus);
87 void init_context (Music *, Context *);
89 void substitute_outlet (Context *from, Context *to);
90 void descend_to_bottom_context ();
91 virtual void derived_substitute (Context *, Context *);
92 virtual Moment pending_moment () const;
93 virtual bool ok () const;
94 virtual bool run_always () const;
95 // process is called with a time relative to the iterator start, so
96 // usually the last processed moment is the same as music_get_length.
97 virtual void process (Moment until);
98 virtual void derived_mark () const;
99 virtual void construct_children ();
100 DECLARE_SCHEME_CALLBACK (constructor, ());
101 SCM get_iterator (Music *) const;
103 Music *get_music () const;
105 virtual void do_quit ();
106 void descend_to_child (Context *);
109 Context_handle handle_;
113 bool is_child_context (Context *me, Context *child);
115 #define IMPLEMENT_CTOR_CALLBACK(Class) \
116 LY_DEFINE_MEMBER_FUNCTION (Class, constructor, \
117 mangle_cxx_identifier (string (#Class) + "::constructor").c_str(), \
122 Class *c = (new Class); \
123 return c->unprotect (); \
127 #endif // MUSIC_ITERATOR_HH