]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeat-acknowledge-engraver.cc
* lily/include/grob-info.hh: origin_contexts() now does not
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "translator-group.hh"
12 #include "context.hh"
13 #include "repeated-music.hh"
14
15
16 /*
17   Objective:
18
19   -- set and reset repeatCommands, so Unfolded_repeat_iterator knows
20     where to set variables.
21
22   -- collect information passed by Unfolded_repeat_iterator for
23    Bar_engraver: writes whichBar property. (TODO: check for
24    interactions with timing engraver.)
25   
26  */
27 class Repeat_acknowledge_engraver : public Engraver
28 {
29 public:
30   TRANSLATOR_DECLARATIONS(Repeat_acknowledge_engraver);
31
32   virtual void start_translation_timestep ();
33   virtual void process_music ();
34   virtual void initialize ();
35
36 };
37
38 void
39 Repeat_acknowledge_engraver::initialize ()
40 {
41   daddy_context_->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   Context * tr = daddy_context_->where_defined (ly_symbol2scm ("repeatCommands"));
53   if (!tr)
54     tr = daddy_context_;
55
56   tr->set_property ("repeatCommands", SCM_EOL);
57 }
58
59 void
60 Repeat_acknowledge_engraver::process_music ()
61 {
62   /*
63     At the start of a piece, we don't print any repeat bars.
64    */
65   if (now_mom () == Moment (0))
66     return ; 
67   
68   SCM cs = get_property ("repeatCommands");
69   
70   String s = "";
71   bool start = false;
72   bool end = false;
73   bool volta_found = false;
74   while (gh_pair_p (cs))
75     {
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 (gh_pair_p (command) && ly_car (command) == ly_symbol2scm ("volta"))
82         volta_found = true;
83       cs = ly_cdr (cs);      
84     }
85
86   if (start && end)
87     s = ":|:";
88   else if (start)
89     s = "|:";
90   else if (end)
91     s = ":|";
92
93   /*
94     TODO: line breaks might be allowed if we set whichBar to "".
95    */
96
97   /*
98     We only set the barline if we wouldn't overwrite a previously set
99     barline.
100    */
101   SCM wb = get_property ("whichBar");
102   SCM db  = get_property ("defaultBarType");
103   if (!gh_string_p (wb) || gh_equal_p (db, wb))
104     {
105       if (s != "" || (volta_found && !gh_string_p (wb)))
106         {
107           daddy_context_->set_property ("whichBar", scm_makfrom0str (s.to_str0 ()));
108         }
109     }
110 }
111
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 */       "");