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