]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #ifndef MUSIC_ITERATOR_HH
10 #define MUSIC_ITERATOR_HH
11
12 #include "array.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, dummy);
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   Music_iterator *try_music (Music *) const;
65   Context *get_outlet () const;
66   void set_context (Context *);
67   static SCM get_static_get_iterator (Music *mus);
68   void init_translator (Music *, Context *);
69   void quit ();
70   void substitute_outlet (Context *from, Context *to);
71   virtual void derived_substitute (Context *, Context *);
72   virtual Moment pending_moment () const;
73   virtual bool ok () const;
74   virtual bool run_always () const;
75   virtual void process (Moment until);
76   virtual void derived_mark () const;
77   virtual void construct_children ();
78   DECLARE_SCHEME_CALLBACK (constructor, ());
79   SCM get_iterator (Music *) const;
80
81   virtual Music_iterator *try_music_in_children (Music *) const;
82
83   Music *get_music () const;
84 protected:
85   virtual void do_quit ();
86   void descend_to_child (Context *);
87
88 private:
89   Context_handle handle_;
90   Music *music_;
91 };
92
93 bool is_child_context (Context *me, Context *child);
94
95 #define IMPLEMENT_CTOR_CALLBACK(Class)                                  \
96   LY_DEFINE_MEMBER_FUNCTION (Class, constructor, #Class "::constructor", \
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