]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
release: 1.5.29
[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--2002 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   TRANSLATOR_DECLARATIONS(Repeat_acknowledge_engraver);
29
30   virtual void start_translation_timestep ();
31   virtual void process_music ();
32   virtual void initialize ();
33
34   bool first_b_;
35 };
36
37 void
38 Repeat_acknowledge_engraver::initialize ()
39 {
40   first_b_ = true;
41   daddy_trans_l_->set_property ("repeatCommands", SCM_EOL);
42 }
43
44
45 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
46 {
47 }
48
49 void
50 Repeat_acknowledge_engraver::start_translation_timestep ()
51 {
52   first_b_ = true;
53   Translator_group * tr = daddy_trans_l_->where_defined (ly_symbol2scm ("repeatCommands"));
54   if (!tr)
55     tr = daddy_trans_l_;
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 () == Moment (0))
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 (gh_pair_p (cs))
76     {
77       SCM command = ly_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 (gh_pair_p (command) && ly_car (command) == ly_symbol2scm ("volta"))
83         volta_found = true;
84       cs = ly_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 (!gh_string_p (wb) || gh_equal_p (db, wb))
105     {
106       if (s != "" || (volta_found && !gh_string_p (wb)))
107         {
108           daddy_trans_l_->set_property ("whichBar", ly_str02scm (s.ch_C ()));
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 /* acks  */       "",
118 /* reads */       "repeatCommands whichBar",
119 /* write */       "");