* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / repeat-acknowledge-engraver.cc
blob134017428bddc4627a6241f18bab27d612263daf
1 /*
2 repeat-acknowledge-engraver.cc -- implement Repeat_acknowledge_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "context.hh"
13 #include "repeated-music.hh"
17 Objective:
19 -- set and reset repeatCommands, so Unfolded_repeat_iterator knows
20 where to set variables.
22 -- collect information passed by Unfolded_repeat_iterator for
23 Bar_engraver: writes whichBar property. (TODO: check for
24 interactions with timing engraver.)
27 class Repeat_acknowledge_engraver : public Engraver
29 public:
30 TRANSLATOR_DECLARATIONS (Repeat_acknowledge_engraver);
32 virtual void start_translation_timestep ();
33 virtual void process_music ();
34 virtual void initialize ();
38 void
39 Repeat_acknowledge_engraver::initialize ()
41 daddy_context_->set_property ("repeatCommands", SCM_EOL);
45 Repeat_acknowledge_engraver::Repeat_acknowledge_engraver ()
49 void
50 Repeat_acknowledge_engraver::start_translation_timestep ()
52 Context * tr = daddy_context_->where_defined (ly_symbol2scm ("repeatCommands"));
53 if (!tr)
54 tr = daddy_context_;
56 tr->set_property ("repeatCommands", SCM_EOL);
59 void
60 Repeat_acknowledge_engraver::process_music ()
63 At the start of a piece, we don't print any repeat bars.
65 if (now_mom () == Moment (0))
66 return ;
68 SCM cs = get_property ("repeatCommands");
70 String s = "";
71 bool start = false;
72 bool end = false;
73 bool volta_found = false;
74 while (ly_pair_p (cs))
76 SCM command = ly_car (cs);
77 if (command == ly_symbol2scm ("start-repeat"))
78 start = true;
79 else if (command == ly_symbol2scm ("end-repeat"))
80 end = true;
81 else if (ly_pair_p (command) && ly_car (command) == ly_symbol2scm ("volta"))
82 volta_found = true;
83 cs = ly_cdr (cs);
86 if (start && end)
87 s = ":|:";
88 else if (start)
89 s = "|:";
90 else if (end)
91 s = ":|";
94 TODO: line breaks might be allowed if we set whichBar to "".
98 We only set the barline if we wouldn't overwrite a previously set
99 barline.
101 SCM wb = get_property ("whichBar");
102 SCM db = get_property ("defaultBarType");
103 if (!ly_string_p (wb) || ly_equal_p (db, wb))
105 if (s != "" || (volta_found && !ly_string_p (wb)))
107 daddy_context_->set_property ("whichBar", scm_makfrom0str (s.to_str0 ()));
112 ENTER_DESCRIPTION (Repeat_acknowledge_engraver,
113 /* descr */ "Acknowledge repeated music, and convert the contents of "
114 "repeatCommands ainto an appropriate setting for whichBar.",
115 /* creats*/ "",
116 /* accepts */ "",
117 /* acks */ "",
118 /* reads */ "repeatCommands whichBar",
119 /* write */ "");