]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
Merge master into nested-bookparts
[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--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "engraver.hh"
10 #include "translator-group.hh"
11 #include "context.hh"
12 #include "repeated-music.hh"
13
14 #include "translator.icc"
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 class Repeat_acknowledge_engraver : public Engraver
27 {
28 public:
29
30   TRANSLATOR_DECLARATIONS (Repeat_acknowledge_engraver);
31 protected:
32   void start_translation_timestep ();
33   void process_music ();
34   virtual void initialize ();
35 };
36
37 void
38 Repeat_acknowledge_engraver::initialize ()
39 {
40   context ()->set_property ("repeatCommands", SCM_EOL);
41 }
42
43 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
44 {
45 }
46
47 void
48 Repeat_acknowledge_engraver::start_translation_timestep ()
49 {
50   SCM rc;
51   Context *tr = context ()->where_defined (ly_symbol2scm ("repeatCommands"), &rc);
52   if (!tr)
53     tr = context ();
54
55   tr->set_property ("repeatCommands", SCM_EOL);
56 }
57
58 void
59 Repeat_acknowledge_engraver::process_music ()
60 {
61   /*
62     At the start of a piece, we don't print any repeat bars.
63   */
64   if (!now_mom ().main_part_)
65     return;
66
67   SCM cs = get_property ("repeatCommands");
68
69   string s = "";
70   bool start = false;
71   bool end = false;
72   bool volta_found = false;
73   while (scm_is_pair (cs))
74     {
75       SCM command = scm_car (cs);
76       if (command == ly_symbol2scm ("start-repeat"))
77         start = true;
78       else if (command == ly_symbol2scm ("end-repeat"))
79         end = true;
80       else if (scm_is_pair (command) && scm_car (command) == ly_symbol2scm ("volta"))
81         volta_found = true;
82       cs = scm_cdr (cs);
83     }
84
85   if (start && end)
86     s = robust_scm2string (get_property ("doubleRepeatType"), ":|:");
87   else if (start)
88     s = "|:";
89   else if (end)
90     s = ":|";
91
92   /*
93     TODO: line breaks might be allowed if we set whichBar to "".
94   */
95
96   /*
97     We only set the barline if we wouldn't overwrite a previously set
98     barline.
99   */
100   SCM wb = get_property ("whichBar");
101   SCM db = get_property ("defaultBarType");
102   if (!scm_is_string (wb) || ly_is_equal (db, wb))
103     {
104       if (s != "" || (volta_found && !scm_is_string (wb)))
105         context ()->set_property ("whichBar", ly_string2scm (s));
106     }
107 }
108
109 ADD_TRANSLATOR (Repeat_acknowledge_engraver,
110                 /* doc */
111                 "Acknowledge repeated music, and convert the contents of"
112                 " @code{repeatCommands} into an appropriate setting for"
113                 " @code{whichBar}.",
114
115                 /* create */
116                 "",
117
118                 /* read */
119                 "doubleRepeatType "
120                 "repeatCommands "
121                 "whichBar ",
122
123                 /* write */
124                 ""
125                 );