]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
(start_translation_timestep): remove first_b_
[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--2003 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 };
35
36 void
37 Repeat_acknowledge_engraver::initialize ()
38 {
39   daddy_trans_->set_property ("repeatCommands", SCM_EOL);
40 }
41
42
43 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
44 {
45 }
46
47 void
48 Repeat_acknowledge_engraver::start_translation_timestep ()
49 {
50   Translator_group * tr = daddy_trans_->where_defined (ly_symbol2scm ("repeatCommands"));
51   if (!tr)
52     tr = daddy_trans_;
53
54   tr->set_property ("repeatCommands", SCM_EOL);
55 }
56
57 void
58 Repeat_acknowledge_engraver::process_music ()
59 {
60   /*
61     At the start of a piece, we don't print any repeat bars.
62    */
63   if (now_mom () == Moment (0))
64     return ; 
65   
66   SCM cs = get_property ("repeatCommands");
67   
68   String s = "";
69   bool start = false;
70   bool end = false;
71   bool volta_found = false;
72   while (gh_pair_p (cs))
73     {
74       SCM command = ly_car (cs);
75       if (command == ly_symbol2scm ("start-repeat"))
76         start = true;
77       else if (command == ly_symbol2scm ("end-repeat"))
78         end = true;
79       else if (gh_pair_p (command) && ly_car (command) == ly_symbol2scm ("volta"))
80         volta_found = true;
81       cs = ly_cdr (cs);      
82     }
83
84   if (start && end)
85     s = ":|:";
86   else if (start)
87     s = "|:";
88   else if (end)
89     s = ":|";
90
91   /*
92     TODO: line breaks might be allowed if we set whichBar to "".
93    */
94
95   /*
96     We only set the barline if we wouldn't overwrite a previously set
97     barline.
98    */
99   SCM wb = get_property ("whichBar");
100   SCM db  = get_property ("defaultBarType");
101   if (!gh_string_p (wb) || gh_equal_p (db, wb))
102     {
103       if (s != "" || (volta_found && !gh_string_p (wb)))
104         {
105           daddy_trans_->set_property ("whichBar", scm_makfrom0str (s.to_str0 ()));
106         }
107     }
108 }
109
110 ENTER_DESCRIPTION(Repeat_acknowledge_engraver,
111 /* descr */       "Acknowledge repeated music, and convert the contents of "
112 "repeatCommands ainto an appropriate setting for whichBar.",
113 /* creats*/       "",
114 /* accepts */     "",
115 /* acks  */      "",
116 /* reads */       "repeatCommands whichBar",
117 /* write */       "");