]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
261ccf128d704fd53b73150147238fa3a439cef5
[lilypond.git] / lily / include / music-iterator.hh
1 /*
2   music-iterator.hh -- declare Music_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef MUSIC_ITERATOR_HH
10 #define MUSIC_ITERATOR_HH
11
12 #include "std-vector.hh"
13 #include "moment.hh"
14 #include "virtual-methods.hh"
15 #include "context-handle.hh"
16
17 /**
18    ---
19
20    Music_iterator is an object type that traverses the Music structure and
21    reports the events it finds to interpretation contexts. It is not yet
22    user-serviceable.
23
24
25    ---
26
27    Conceptually a music-iterator operates on a queue of musical events
28    that are pending. This queue does not actually exist, but it is a
29    way of viewing and traversing music-expressions.
30
31
32    ok () -- events left ?
33
34    pending_mom () -- time tag of the next event to be processed.
35    PRECONDITION: this->ok () holds.
36
37    process (M) -- process all at M (Precondition: no events exist
38    before M, this->ok () holds).  Side-effects:
39
40    * This removes all events at M from the pending queue.
41
42    * Typically this reports the music to an interpretation context,
43    thus changing the state of the interpretation context.
44
45
46    TODO:
47
48    merge pending_moment and process?
49 */
50 class Music_iterator
51 {
52 protected:
53   Moment music_length_;
54   Moment start_mom_;
55
56   DECLARE_CLASSNAME(Music_iterator);
57   DECLARE_SMOBS (Music_iterator);
58   Music_iterator (Music_iterator const &);
59
60 public:
61   Moment music_get_length () const;
62   Moment music_start_mom () const;
63   Music_iterator ();
64   void report_event (Music *);
65   Context *get_outlet () const;
66   void set_context (Context *);
67   static SCM get_static_get_iterator (Music *mus);
68   void init_context (Music *, Context *);
69   void quit ();
70   void substitute_outlet (Context *from, Context *to);
71   void descend_to_bottom_context ();
72   virtual void derived_substitute (Context *, Context *);
73   virtual Moment pending_moment () const;
74   virtual bool ok () const;
75   virtual bool run_always () const;
76   virtual void process (Moment until);
77   virtual void derived_mark () const;
78   virtual void construct_children ();
79   DECLARE_SCHEME_CALLBACK (constructor, ());
80   SCM get_iterator (Music *) const;
81
82   Music *get_music () const;
83 protected:
84   virtual void do_quit ();
85   void descend_to_child (Context *);
86
87 private:
88   Context_handle handle_;
89   Music *music_;
90 };
91
92 bool is_child_context (Context *me, Context *child);
93
94 #define IMPLEMENT_CTOR_CALLBACK(Class)                                  \
95   LY_DEFINE_MEMBER_FUNCTION (Class, constructor, \
96                              mangle_cxx_identifier (string (#Class) + "::constructor").c_str(), \
97                              0, 0, 0,                                   \
98                              (),                                        \
99                              "")                                        \
100   {                                                                     \
101     Class *c = (new Class);                                             \
102     return c->unprotect ();                                             \
103   }
104
105 DECLARE_UNSMOB (Music_iterator, iterator);
106
107 #endif // MUSIC_ITERATOR_HH