]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
release: 1.3.87
[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--2000 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
19 /** 
20   Conceptually a music-iterator operates on a queue of musical events
21   that are pending. This queue does not actually exist, but it is a
22   way of viewing and traversing music-expressions.
23
24   
25   ok () -- events left ?
26
27   pending_mom () -- time tag of the next event to be processed.
28   
29   process (M) -- process all at M (Precondition: no events exist before
30     M).  Side-effects:
31     
32     * This removes all events at M from the pending queue.
33
34     * Typically this reports the music to an interpretation context,
35     thus changing the state of the interpretation context.
36
37   get_music (M) -- return all events starting at M (pre: no events
38     before M).  Side effects:
39
40     * This removes all events at M from the pending queue.
41
42   Because next (M) is rolled into process () as a side effect,
43   we need to roll next (M) into get_music too.  Urg.
44     
45 */
46 class Music_iterator
47 {
48 public:
49   VIRTUAL_COPY_CONS (Music_iterator);
50
51   Music_iterator ();
52   Music_iterator (Music_iterator const&);
53   virtual ~Music_iterator ();
54
55   /**
56      Do the reporting.  Will try MUSIC_L_ in its own translator first,
57      then its children. Returns the iterator that succeeded
58   */
59   Music_iterator *  try_music (Music  *) const;
60
61   /**
62     The translation unit that we this iterator is reporting  to now.
63    */
64   Translator_group* report_to_l () const;
65
66   void set_translator (Translator_group*);
67   
68   /** Get an iterator matching the type of MUS, and use TRANS to find
69     an accompanying translation unit
70    */
71   static Music_iterator* static_get_iterator_p (Music * mus);
72   void init_translator (Music  *, Translator_group *); 
73
74   virtual Moment pending_moment () const;
75   virtual bool ok () const;
76   virtual SCM get_music (Moment until)const;
77   virtual void process (Moment until);
78
79   /**
80     Construct sub-iterators, and set the translator to 
81     report to.
82    */
83   virtual void construct_children ();
84
85 protected:
86   Music  * music_l_;
87
88   /**
89     Get an iterator for MUS, inheriting the translation unit from THIS.
90    */
91   Music_iterator* get_iterator_p (Music *) const;
92
93   virtual Music_iterator* try_music_in_children (Music *) const;
94
95 private:
96   Interpretation_context_handle handle_;
97 };
98
99 #endif // MUSIC_ITERATOR_HH