release commit
[lilypond.git] / lily / repeat-acknowledge-engraver.cc
blob53265a70e520c15880e7ac2b3222c85c21166248
1 /*
2 repeat-acknowledge-engraver.cc -- implement Repeat_acknowledge_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "engraver.hh"
10 #include "translator-group.hh"
11 #include "repeated-music.hh"
15 Objective:
17 -- set and reset repeatCommands, so Unfolded_repeat_iterator knows
18 where to set variables.
20 -- collect information passed by Unfolded_repeat_iterator for
21 Bar_engraver: writes whichBar property. (TODO: check for
22 interactions with timing engraver.)
25 class Repeat_acknowledge_engraver : public Engraver
27 public:
28 TRANSLATOR_DECLARATIONS(Repeat_acknowledge_engraver);
30 virtual void start_translation_timestep ();
31 virtual void process_music ();
32 virtual void initialize ();
34 bool first_b_;
37 void
38 Repeat_acknowledge_engraver::initialize ()
40 first_b_ = true;
41 daddy_trans_->set_property ("repeatCommands", SCM_EOL);
45 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
49 void
50 Repeat_acknowledge_engraver::start_translation_timestep ()
52 first_b_ = true;
53 Translator_group * tr = daddy_trans_->where_defined (ly_symbol2scm ("repeatCommands"));
54 if (!tr)
55 tr = daddy_trans_;
57 tr->set_property ("repeatCommands", SCM_EOL);
60 void
61 Repeat_acknowledge_engraver::process_music ()
64 At the start of a piece, we don't print any repeat bars.
66 if (now_mom () == Moment (0))
67 return ;
69 SCM cs = get_property ("repeatCommands");
71 String s = "";
72 bool start = false;
73 bool end = false;
74 bool volta_found = false;
75 while (gh_pair_p (cs))
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);
87 if (start && end)
88 s = ":|:";
89 else if (start)
90 s = "|:";
91 else if (end)
92 s = ":|";
95 TODO: line breaks might be allowed if we set whichBar to "".
99 We only set the barline if we wouldn't overwrite a previously set
100 barline.
102 SCM wb = get_property ("whichBar");
103 SCM db = get_property ("defaultBarType");
104 if (!gh_string_p (wb) || gh_equal_p (db, wb))
106 if (s != "" || (volta_found && !gh_string_p (wb)))
108 daddy_trans_->set_property ("whichBar", scm_makfrom0str (s.to_str0 ()));
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 /* accepts */ "",
118 /* acks */ "",
119 /* reads */ "repeatCommands whichBar",
120 /* write */ "");