]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
*** empty log message ***
[lilypond.git] / lily / repeat-acknowledge-engraver.cc
1 /*   
2   repeat-acknowledge-engraver.cc --  implement Repeat_acknowledge_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "context.hh"
13 #include "repeated-music.hh"
14
15
16 /*
17   Objective:
18
19   -- set and reset repeatCommands, so Unfolded_repeat_iterator knows
20     where to set variables.
21
22   -- collect information passed by Unfolded_repeat_iterator for
23    Bar_engraver: writes whichBar property. (TODO: check for
24    interactions with timing engraver.)
25   
26  */
27 class Repeat_acknowledge_engraver : public Engraver
28 {
29 public:
30   
31   TRANSLATOR_DECLARATIONS (Repeat_acknowledge_engraver);
32 protected:
33   virtual void start_translation_timestep ();
34   virtual void process_music ();
35   virtual void initialize ();
36
37 };
38
39 void
40 Repeat_acknowledge_engraver::initialize ()
41 {
42   context ()->set_property ("repeatCommands", SCM_EOL);
43 }
44
45
46 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
47 {
48 }
49
50 void
51 Repeat_acknowledge_engraver::start_translation_timestep ()
52 {
53   Context * tr = context ()->where_defined (ly_symbol2scm ("repeatCommands"));
54   if (!tr)
55     tr = context ();
56
57   tr->set_property ("repeatCommands", SCM_EOL);
58 }
59
60 void
61 Repeat_acknowledge_engraver::process_music ()
62 {
63   /*
64     At the start of a piece, we don't print any repeat bars.
65    */
66   if (!now_mom ().main_part_)
67     return ; 
68   
69   SCM cs = get_property ("repeatCommands");
70   
71   String s = "";
72   bool start = false;
73   bool end = false;
74   bool volta_found = false;
75   while (scm_is_pair (cs))
76     {
77       SCM command = scm_car (cs);
78       if (command == ly_symbol2scm ("start-repeat"))
79         start = true;
80       else if (command == ly_symbol2scm ("end-repeat"))
81         end = true;
82       else if (scm_is_pair (command) && scm_car (command) == ly_symbol2scm ("volta"))
83         volta_found = true;
84       cs = scm_cdr (cs);      
85     }
86
87   if (start && end)
88     s = ":|:";
89   else if (start)
90     s = "|:";
91   else if (end)
92     s = ":|";
93
94   /*
95     TODO: line breaks might be allowed if we set whichBar to "".
96    */
97
98   /*
99     We only set the barline if we wouldn't overwrite a previously set
100     barline.
101    */
102   SCM wb = get_property ("whichBar");
103   SCM db  = get_property ("defaultBarType");
104   if (!scm_is_string (wb) || ly_c_equal_p (db, wb))
105     {
106       if (s != "" || (volta_found && !scm_is_string (wb)))
107         {
108           context ()->set_property ("whichBar", scm_makfrom0str (s.to_str0 ()));
109         }
110     }
111 }
112
113 ENTER_DESCRIPTION (Repeat_acknowledge_engraver,
114 /* descr */       "Acknowledge repeated music, and convert the contents of "
115 "repeatCommands ainto an appropriate setting for whichBar.",
116 /* creats*/       "",
117 /* accepts */     "",
118 /* acks  */      "",
119 /* reads */       "repeatCommands whichBar",
120 /* write */       "");