]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
9ca076c6255c1bc0e2566b69ce8dcef7db59c6e2
[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   static int print_smob (SCM, 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   Music_iterator (Music_iterator const &);
74
75 public:
76   Moment music_get_length () const;
77   Moment music_start_mom () const;
78   Music_iterator ();
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 *);
84   void quit ();
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;
96
97   Music *get_music () const;
98 protected:
99   virtual void do_quit ();
100   void descend_to_child (Context *);
101
102 private:
103   Context_handle handle_;
104   Music *music_;
105 };
106
107 bool is_child_context (Context *me, Context *child);
108
109 #define IMPLEMENT_CTOR_CALLBACK(Class)                                  \
110   LY_DEFINE_MEMBER_FUNCTION (Class, constructor, \
111                              mangle_cxx_identifier (string (#Class) + "::constructor").c_str(), \
112                              0, 0, 0,                                   \
113                              (),                                        \
114                              "")                                        \
115   {                                                                     \
116     Class *c = (new Class);                                             \
117     return c->unprotect ();                                             \
118   }
119
120
121 #endif // MUSIC_ITERATOR_HH