]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
* lily/include/music-iterator.hh (class Music_iterator): add
[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--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #ifndef MUSIC_ITERATOR_HH
11 #define MUSIC_ITERATOR_HH
12
13 #include "lily-proto.hh"
14 #include "array.hh"
15 #include "moment.hh"
16 #include "virtual-methods.hh"
17 #include "interpretation-context-handle.hh"
18 #include "smobs.hh"
19
20 /**
21    ---
22
23    Music_iterator is an object type that traverses the Music structure and
24    reports the events it finds to interpretation contexts. It is not yet
25    user-serviceable.
26
27
28    ---
29         
30   Conceptually a music-iterator operates on a queue of musical events
31   that are pending. This queue does not actually exist, but it is a
32   way of viewing and traversing music-expressions.
33
34   
35   ok () -- events left ?
36
37   pending_mom () -- time tag of the next event to be processed.
38     PRECONDITION: this->ok () holds.
39   
40   process (M) -- process all at M (Precondition: no events exist
41     before M, this->ok () holds).  Side-effects:
42     
43     * This removes all events at M from the pending queue.
44
45     * Typically this reports the music to an interpretation context,
46     thus changing the state of the interpretation context.
47
48   get_pending_events (M) -- return all events starting at M (pre: no events
49     before M). No side-effects
50
51   skip (M) -- remove all events starting before M (leave the ones that
52     start M).  no side-effects on interpretation context
53
54
55   TODO:
56
57   merge pending_moment and process?
58   
59 */
60 class Music_iterator
61 {
62 protected:
63   Moment music_length_;
64   Moment start_mom_;
65
66   DECLARE_SMOBS (Music_iterator,dummy);
67 public:
68   VIRTUAL_COPY_CONS (Music_iterator);
69   
70   Moment music_get_length () const;
71   Moment music_start_mom () const;
72   Music_iterator ();
73   Music_iterator (Music_iterator const&);
74
75   /**
76      Do the reporting.  Will try MUSIC_L_ in its own translator first,
77      then its children. Returns the iterator that succeeded
78   */
79   Music_iterator *  try_music (Music  *) const;
80   
81   /**
82     The translation unit that we this iterator is reporting  to now.
83    */
84   Translator_group* report_to () const;
85
86   void set_translator (Translator_group*);
87   
88   /** Get an iterator matching the type of MUS, and use TRANS to find
89     an accompanying translation unit
90    */
91   static SCM get_static_get_iterator (Music * mus);
92   void init_translator (Music  *, Translator_group *); 
93   void quit ();
94   void substitute_outlet (Translator_group* from, Translator_group *to);
95   virtual void derived_substitute (Translator_group*, Translator_group*);
96   virtual Moment pending_moment () const;
97   virtual bool ok () const;
98
99   virtual bool run_always () const; 
100   virtual SCM get_pending_events (Moment until)const;
101   virtual void process (Moment until);
102   virtual void skip (Moment until);
103
104   virtual void derived_mark ()const;
105   virtual void construct_children ();
106   
107   /**
108     Construct sub-iterators, and set the translator to 
109     report to.
110    */
111
112   DECLARE_SCHEME_CALLBACK(constructor, ());
113   
114   /**
115     Get an iterator for MUS, inheriting the translation unit from THIS.
116    */
117   SCM get_iterator (Music *) const;
118
119   virtual Music_iterator* try_music_in_children (Music *) const;
120
121   Music * get_music () const;
122 protected:
123   virtual void do_quit();
124 private:
125   Interpretation_context_handle handle_;
126   Music  * music_;
127 };
128
129
130 #define IMPLEMENT_CTOR_CALLBACK(Class)          \
131 LY_DEFINE_MEMBER_FUNCTION(Class,constructor, #Class "::constructor",\
132           0,0,0,\
133           (),\
134           "Construct a @code{" #Class "} music iterator")\
135 {                                               \
136   SCM val = (new Class)->self_scm();   \
137   scm_gc_unprotect_object (val);\
138   return val ;                          \
139 }                                               \
140
141 DECLARE_UNSMOB(Music_iterator, iterator);
142
143 #endif // MUSIC_ITERATOR_HH