]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
4abf1d270afd9042c50b963509091cba80a63afd
[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 : public Smob<Music_iterator>
62 {
63 public:
64   int print_smob (SCM, scm_print_state *);
65   SCM mark_smob ();
66   static const char type_p_name_[];
67   virtual ~Music_iterator ();
68 protected:
69   Moment music_length_;
70   Moment start_mom_;
71
72   DECLARE_CLASSNAME (Music_iterator);
73 private:
74   Music_iterator (Music_iterator const &); // Do not define!  Not copyable!
75
76 public:
77   Moment music_get_length () const;
78   Moment music_start_mom () const;
79   Music_iterator ();
80   void report_event (Music *);
81   virtual Context *get_outlet () const;
82   virtual void set_context (Context *);
83   static SCM get_static_get_iterator (Music *mus);
84   void init_context (Music *, Context *);
85   void quit ();
86   void substitute_outlet (Context *from, Context *to);
87   void descend_to_bottom_context ();
88   virtual void derived_substitute (Context *, Context *);
89   virtual Moment pending_moment () const;
90   virtual bool ok () const;
91   virtual bool run_always () const;
92   virtual void process (Moment until);
93   virtual void derived_mark () const;
94   virtual void construct_children ();
95   DECLARE_SCHEME_CALLBACK (constructor, ());
96   SCM get_iterator (Music *) const;
97
98   Music *get_music () const;
99 protected:
100   virtual void do_quit ();
101   void descend_to_child (Context *);
102
103 private:
104   Context_handle handle_;
105   Music *music_;
106 };
107
108 bool is_child_context (Context *me, Context *child);
109
110 #define IMPLEMENT_CTOR_CALLBACK(Class)                                  \
111   LY_DEFINE_MEMBER_FUNCTION (Class, constructor, \
112                              mangle_cxx_identifier (string (#Class) + "::constructor").c_str(), \
113                              0, 0, 0,                                   \
114                              (),                                        \
115                              "")                                        \
116   {                                                                     \
117     Class *c = (new Class);                                             \
118     return c->unprotect ();                                             \
119   }
120
121
122 #endif // MUSIC_ITERATOR_HH