]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
Run grand-replace (issue 3765)
[lilypond.git] / lily / include / music-iterator.hh
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #ifndef MUSIC_ITERATOR_HH
21 #define MUSIC_ITERATOR_HH
22
23 #include "std-vector.hh"
24 #include "moment.hh"
25 #include "virtual-methods.hh"
26 #include "context-handle.hh"
27
28 /**
29    ---
30
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
33    user-serviceable.
34
35
36    ---
37
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.
41
42
43    ok () -- events left ?
44
45    pending_mom () -- time tag of the next event to be processed.
46    PRECONDITION: this->ok () holds.
47
48    process (M) -- process all at M (Precondition: no events exist
49    before M, this->ok () holds).  Side-effects:
50
51    * This removes all events at M from the pending queue.
52
53    * Typically this reports the music to an interpretation context,
54    thus changing the state of the interpretation context.
55
56
57    TODO:
58
59    merge pending_moment and process?
60 */
61 class Music_iterator
62 {
63 protected:
64   Moment music_length_;
65   Moment start_mom_;
66
67   DECLARE_CLASSNAME (Music_iterator);
68   DECLARE_SMOBS (Music_iterator);
69   Music_iterator (Music_iterator const &);
70
71 public:
72   Moment music_get_length () const;
73   Moment music_start_mom () const;
74   Music_iterator ();
75   void report_event (Music *);
76   Context *get_outlet () const;
77   void set_context (Context *);
78   static SCM get_static_get_iterator (Music *mus);
79   void init_context (Music *, Context *);
80   void quit ();
81   void substitute_outlet (Context *from, Context *to);
82   void descend_to_bottom_context ();
83   virtual void derived_substitute (Context *, Context *);
84   virtual Moment pending_moment () const;
85   virtual bool ok () const;
86   virtual bool run_always () const;
87   virtual void process (Moment until);
88   virtual void derived_mark () const;
89   virtual void construct_children ();
90   DECLARE_SCHEME_CALLBACK (constructor, ());
91   SCM get_iterator (Music *) const;
92
93   Music *get_music () const;
94 protected:
95   virtual void do_quit ();
96   void descend_to_child (Context *);
97
98 private:
99   Context_handle handle_;
100   Music *music_;
101 };
102
103 bool is_child_context (Context *me, Context *child);
104
105 #define IMPLEMENT_CTOR_CALLBACK(Class)                                  \
106   LY_DEFINE_MEMBER_FUNCTION (Class, constructor, \
107                              mangle_cxx_identifier (string (#Class) + "::constructor").c_str(), \
108                              0, 0, 0,                                   \
109                              (),                                        \
110                              "")                                        \
111   {                                                                     \
112     Class *c = (new Class);                                             \
113     return c->unprotect ();                                             \
114   }
115
116 DECLARE_UNSMOB (Music_iterator, iterator);
117
118 #endif // MUSIC_ITERATOR_HH