2 repeat-engraver.cc -- implement Repeat_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "repeat-engraver.hh"
11 #include "bar-engraver.hh"
12 #include "musical-request.hh"
13 #include "multi-measure-rest.hh"
14 #include "command-request.hh"
15 #include "time-description.hh"
16 #include "engraver-group.hh"
17 #include "new-repeated-music.hh"
18 #include "time-description.hh"
19 #include "volta-spanner.hh"
20 #include "note-column.hh"
21 #include "paper-def.hh"
22 #include "music-list.hh"
24 ADD_THIS_TRANSLATOR (Repeat_engraver
);
27 Urg. Hairy. Needs redesign?
30 Repeat_engraver::do_try_music (Music
* m
)
32 if (New_repeated_music
* r
= dynamic_cast<New_repeated_music
*> (m
))
37 Music_sequence
* alt
= r
->alternatives_p_
;
38 Moment repeat_length_mom
= r
->repeat_body_p_
->length_mom ();
39 Moment stop_mom
= now_mom () + repeat_length_mom
;
40 Moment alt_mom
= now_mom () + repeat_length_mom
;
43 if there's a repeat block, we'll need a stop-repeat :|
45 if (repeat_length_mom
)
48 if there are alternatives, the :| comes before last alternative
49 (only for semi-unfolded, but otherwise we're not here anyway?)
53 for (Cons
<Music
> *i (alt
->music_p_list_p_
->head_
); i
&& i
->next_
; i
= i
->next_
)
55 stop_mom
+= i
->car_
->length_mom ();
60 repeated_music_arr_
.push (r
);
61 stop_mom_arr_
.push (stop_mom
);
65 Counting nested repeats, it seems safest to forbid
66 two pieces of alternative music to start at the same time.
68 for (int i
= 0; i
< alternative_start_mom_arr_
.size (); i
++)
69 if (alternative_start_mom_arr_
[i
] == alt_mom
)
73 Coda kludge: see input/test/coda-kludge.ly
76 Scalar prop
= get_property ("voltaSpannerDuration", 0);
78 span_mom
= prop
.to_rat ();
83 int alt_i
= r
->repeats_i_
+ 1 - cons_list_size_i (alt
->music_p_list_p_
->head_
) >? 1;
84 for (Cons
<Music
> *i
= alt
->music_p_list_p_
->head_
; i
; i
= i
->next_
)
86 alternative_music_arr_
.push (i
->car_
);
87 alternative_start_mom_arr_
.push (alt_mom
);
89 alternative_stop_mom_arr_
.push (alt_mom
+ span_mom
);
91 alternative_stop_mom_arr_
.push (alt_mom
+ i
->car_
->length_mom ());
93 if ((alt_i
!= 1) && (alt_i
!= r
->repeats_i_
) && (i
== alt
->music_p_list_p_
->head_
))
95 str
+= to_str (alt_i
) + ".";
97 alternative_str_arr_
.push (str
);
98 if (!dynamic_cast<Simultaneous_music
*> (alt
))
99 alt_mom
+= i
->car_
->length_mom ();
107 Repeat_engraver::acknowledge_element (Score_element_info i
)
109 Moment now
= now_mom ();
110 if (Note_column
*c
= dynamic_cast<Note_column
*> (i
.elem_l_
))
112 for (int i
= 0; i
< volta_p_arr_
.size (); i
++)
113 if (volta_p_arr_
[i
] && (now
>= alternative_start_mom_arr_
[i
]))
114 volta_p_arr_
[i
]->add_column (c
);
116 if (Bar
*c
= dynamic_cast<Bar
*> (i
.elem_l_
))
118 for (int i
= 0; i
< volta_p_arr_
.size (); i
++)
119 if (volta_p_arr_
[i
] && (now
>= alternative_start_mom_arr_
[i
]))
120 volta_p_arr_
[i
]->add_column (c
);
125 Repeat_engraver::do_removal_processing ()
127 for (int i
= 0; i
< volta_p_arr_
.size (); i
++)
129 typeset_element (volta_p_arr_
[i
]);
133 Repeat_engraver::do_process_requests ()
135 Moment now
= now_mom ();
136 Bar_engraver
* bar_engraver_l
= dynamic_cast <Bar_engraver
*>
137 (daddy_grav_l ()->get_simple_translator ("Bar_engraver"));
138 for (int i
= bar_b_arr_
.size (); i
< repeated_music_arr_
.size (); i
++)
141 bar_engraver_l
->request_bar ("|:");
142 bar_b_arr_
.push (true);
144 for (int i
= 0; i
< bar_b_arr_
.size (); i
++)
146 if (!bar_b_arr_
[i
] && (now
>= stop_mom_arr_
[i
]))
149 bar_engraver_l
->request_bar (":|");
152 for (int i
= volta_p_arr_
.size (); i
< alternative_music_arr_
.size (); i
++)
154 Volta_spanner
* v
= new Volta_spanner
;
155 Scalar prop
= get_property ("voltaVisibility", 0);
156 if (!prop
.to_bool ())
157 v
->set_elt_property (transparent_scm_sym
, SCM_BOOL_T
);
158 prop
= get_property ("voltaSpannerDuration", 0);
159 if ((i
== alternative_music_arr_
.size () - 1) || prop
.length_i ())
162 v
->number_str_
= alternative_str_arr_
[i
];
163 volta_p_arr_
.push (v
);
164 announce_element (Score_element_info (v
, alternative_music_arr_
[i
]));
169 Repeat_engraver::do_pre_move_processing ()
171 Moment now
= now_mom ();
172 for (int i
= bar_b_arr_
.size (); i
--; )
175 bar_b_arr_
[i
] = false;
176 if (now
>= stop_mom_arr_
[i
])
179 stop_mom_arr_
.del (i
);
180 repeated_music_arr_
.del (i
);
183 for (int i
= volta_p_arr_
.size (); i
--; )
185 if (volta_p_arr_
[i
] && (now
>= alternative_stop_mom_arr_
[i
])
186 && (volta_p_arr_
[i
]->column_arr_
.size () >= 1))
188 typeset_element (volta_p_arr_
[i
]);
190 volta_p_arr_
.del (i
);
191 alternative_music_arr_
[i
] = 0;
192 alternative_music_arr_
.del (i
);
193 alternative_start_mom_arr_
.del (i
);
194 alternative_stop_mom_arr_
.del (i
);
195 alternative_str_arr_
.del (i
);