]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
patch::: 1.3.136.jcn3
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include "engraver.hh"
10 #include "translator-group.hh"
11 #include "repeated-music.hh"
12
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  */
25 class Repeat_acknowledge_engraver : public Engraver
26 {
27 public:
28   VIRTUAL_COPY_CONS (Translator);
29   Repeat_acknowledge_engraver ();
30
31   virtual void start_translation_timestep ();
32   virtual void process_music ();
33   virtual void initialize ();
34
35   bool first_b_;
36 };
37
38 void
39 Repeat_acknowledge_engraver::initialize ()
40 {
41   first_b_ = true;
42   daddy_trans_l_->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   first_b_ = true;
54   Translator_group * tr = daddy_trans_l_->where_defined (ly_symbol2scm ("repeatCommands"));
55   if (!tr)
56     tr = daddy_trans_l_;
57
58   tr->set_property ("repeatCommands", SCM_EOL);
59 }
60
61 void
62 Repeat_acknowledge_engraver::process_music ()
63 {
64   /*
65     At the start of a piece, we don't print any repeat bars.
66    */
67   if (now_mom () == Moment (0))
68     return ; 
69   
70   SCM cs = get_property ("repeatCommands");
71   
72   String s = "";
73   bool start = false;
74   bool end = false;
75   bool volta_found = false;
76   while (gh_pair_p (cs))
77     {
78       SCM command = gh_car (cs);
79       if (command == ly_symbol2scm ("start-repeat"))
80         start = true;
81       else if (command == ly_symbol2scm ("end-repeat"))
82         end = true;
83       else if (gh_pair_p (command) && gh_car (command) == ly_symbol2scm ("volta"))
84         volta_found = true;
85       cs = gh_cdr (cs);      
86     }
87
88   if (start && end)
89     s = ":|:";
90   else if (start)
91     s = "|:";
92   else if (end)
93     s = ":|";
94
95   /*
96     TODO: line breaks might be allowed if we set whichBar to "". 
97    */
98   if (s != "" || (volta_found && !gh_string_p (get_property ("whichBar"))))
99     {
100       daddy_trans_l_->set_property ("whichBar", ly_str02scm (s.ch_C ()));
101     }
102 }
103
104 ADD_THIS_TRANSLATOR (Repeat_acknowledge_engraver);