]> git.donarmstrong.com Git - lilypond.git/blob - lily/include/music-iterator.hh
release: 1.3.105
[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     PRECONDITION: this->ok() holds.
29   
30   process (M) -- process all at M (Precondition: no events exist
31     before M, this->ok() holds).  Side-effects:
32     
33     * This removes all events at M from the pending queue.
34
35     * Typically this reports the music to an interpretation context,
36     thus changing the state of the interpretation context.
37
38   get_music (M) -- return all events starting at M (pre: no events
39     before M). No side-effects
40
41   skip (M) -- remove all events starting before M (leave the ones that
42     start M).  no side-effects on interpretation context
43
44
45   TODO:
46
47   merge pending_moment and process?
48   
49 */
50 class Music_iterator
51 {
52 protected:
53   Moment music_length_;
54
55 public:
56   VIRTUAL_COPY_CONS (Music_iterator);
57
58   Moment music_length_mom () const;
59   Music_iterator ();
60   Music_iterator (Music_iterator const&);
61   virtual ~Music_iterator ();
62
63   /**
64      Do the reporting.  Will try MUSIC_L_ in its own translator first,
65      then its children. Returns the iterator that succeeded
66   */
67   Music_iterator *  try_music (Music  *) const;
68   
69   /**
70     The translation unit that we this iterator is reporting  to now.
71    */
72   Translator_group* report_to_l () const;
73
74   void set_translator (Translator_group*);
75   
76   /** Get an iterator matching the type of MUS, and use TRANS to find
77     an accompanying translation unit
78    */
79   static Music_iterator* static_get_iterator_p (Music * mus);
80   void init_translator (Music  *, Translator_group *); 
81
82   virtual Moment pending_moment () const;
83   virtual bool ok () const;
84   virtual SCM get_music (Moment until)const;
85   virtual void process (Moment until);
86   virtual void skip (Moment until);
87
88   /**
89     Construct sub-iterators, and set the translator to 
90     report to.
91    */
92   virtual void construct_children ();
93
94 protected:
95   Music  * music_l_;
96
97   /**
98     Get an iterator for MUS, inheriting the translation unit from THIS.
99    */
100   Music_iterator* get_iterator_p (Music *) const;
101
102   virtual Music_iterator* try_music_in_children (Music *) const;
103
104 private:
105   Interpretation_context_handle handle_;
106 };
107
108
109  
110   
111
112
113
114 #endif // MUSIC_ITERATOR_HH