Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Delta Between Two Patch Sets: lily/music.cc

Issue 573670043: Refactor get/set_property to take the item as first argument
Left Patch Set: Created 4 years, 11 months ago
Right Patch Set: Manual completion of patch set Created 4 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lily/multi-measure-rest-engraver.cc ('k') | lily/music-iterator.cc » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* 1 /*
2 This file is part of LilyPond, the GNU music typesetter. 2 This file is part of LilyPond, the GNU music typesetter.
3 3
4 Copyright (C) 1997--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> 4 Copyright (C) 1997--2020 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 5
6 LilyPond is free software: you can redistribute it and/or modify 6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or 8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
(...skipping 22 matching lines...) Expand all
33 /* 33 /*
34 Music is anything that has (possibly zero) duration and supports 34 Music is anything that has (possibly zero) duration and supports
35 both time compression and transposition. 35 both time compression and transposition.
36 36
37 In Lily, everything that can be thought to have a length and a pitch 37 In Lily, everything that can be thought to have a length and a pitch
38 (which has a duration which can be transposed) is considered "music". 38 (which has a duration which can be transposed) is considered "music".
39 */ 39 */
40 bool 40 bool
41 Music::internal_is_music_type (SCM k) const 41 Music::internal_is_music_type (SCM k) const
42 { 42 {
43 SCM ifs = get_property ("types"); 43 SCM ifs = get_property (this, "types");
44 44
45 return scm_is_true (scm_c_memq (k, ifs)); 45 return scm_is_true (scm_c_memq (k, ifs));
46 } 46 }
47 47
48 Preinit_Music::Preinit_Music () 48 Preinit_Music::Preinit_Music ()
49 { 49 {
50 length_callback_ = SCM_EOL; 50 length_callback_ = SCM_EOL;
51 start_callback_ = SCM_EOL; 51 start_callback_ = SCM_EOL;
52 } 52 }
53 53
54 Music::Music (SCM init) 54 Music::Music (SCM init)
55 : Prob (ly_symbol2scm ("Music"), init) 55 : Prob (ly_symbol2scm ("Music"), init)
56 { 56 {
57 length_callback_ = get_property ("length-callback"); 57 length_callback_ = get_property (this, "length-callback");
58 if (!ly_is_procedure (length_callback_)) 58 if (!ly_is_procedure (length_callback_))
59 length_callback_ = duration_length_callback_proc; 59 length_callback_ = duration_length_callback_proc;
60 60
61 start_callback_ = get_property ("start-callback"); 61 start_callback_ = get_property (this, "start-callback");
62 } 62 }
63 63
64 void 64 void
65 Music::derived_mark () const 65 Music::derived_mark () const
66 { 66 {
67 scm_gc_mark (length_callback_); 67 scm_gc_mark (length_callback_);
68 scm_gc_mark (start_callback_); 68 scm_gc_mark (start_callback_);
69 } 69 }
70 70
71 SCM 71 SCM
(...skipping 11 matching lines...) Expand all
83 Music::Music (Music const &m) 83 Music::Music (Music const &m)
84 : Prob (m) 84 : Prob (m)
85 { 85 {
86 length_callback_ = m.length_callback_; 86 length_callback_ = m.length_callback_;
87 start_callback_ = m.start_callback_; 87 start_callback_ = m.start_callback_;
88 } 88 }
89 89
90 Moment 90 Moment
91 Music::get_length () const 91 Music::get_length () const
92 { 92 {
93 SCM lst = get_property ("length"); 93 SCM lst = get_property (this, "length");
94 if (unsmob<Moment> (lst)) 94 if (unsmob<Moment> (lst))
95 return *unsmob<Moment> (lst); 95 return *unsmob<Moment> (lst);
96 96
97 if (ly_is_procedure (length_callback_)) 97 if (ly_is_procedure (length_callback_))
98 { 98 {
99 SCM res = scm_call_1 (length_callback_, self_scm ()); 99 SCM res = scm_call_1 (length_callback_, self_scm ());
100 return *unsmob<Moment> (res); 100 return *unsmob<Moment> (res);
101 } 101 }
102 102
103 return Moment (0); 103 return Moment (0);
(...skipping 22 matching lines...) Expand all
126 scm_display (scm_caar (s), port); 126 scm_display (scm_caar (s), port);
127 scm_puts (" = ", port); 127 scm_puts (" = ", port);
128 scm_write (scm_cdar (s), port); 128 scm_write (scm_cdar (s), port);
129 scm_puts ("\n", port); 129 scm_puts ("\n", port);
130 } 130 }
131 } 131 }
132 132
133 Pitch 133 Pitch
134 Music::generic_to_relative_octave (Pitch last) 134 Music::generic_to_relative_octave (Pitch last)
135 { 135 {
136 SCM elt = get_property ("element"); 136 SCM elt = get_property (this, "element");
137 Pitch *old_pit = unsmob<Pitch> (get_property ("pitch")); 137 Pitch *old_pit = unsmob<Pitch> (get_property (this, "pitch"));
138 if (old_pit) 138 if (old_pit)
139 { 139 {
140 Pitch new_pit = *old_pit; 140 Pitch new_pit = *old_pit;
141 new_pit = new_pit.to_relative_octave (last); 141 new_pit = new_pit.to_relative_octave (last);
142 142
143 SCM check = get_property ("absolute-octave"); 143 SCM check = get_property (this, "absolute-octave");
144 if (scm_is_number (check) 144 if (scm_is_number (check)
145 && new_pit.get_octave () != scm_to_int (check)) 145 && new_pit.get_octave () != scm_to_int (check))
146 { 146 {
147 Pitch expected_pit (scm_to_int (check), 147 Pitch expected_pit (scm_to_int (check),
148 new_pit.get_notename (), 148 new_pit.get_notename (),
149 new_pit.get_alteration ()); 149 new_pit.get_alteration ());
150 origin ()->warning (_f ("octave check failed; expected \"%s\", found: \"%s\"", 150 origin ()->warning (_f ("octave check failed; expected \"%s\", found: \"%s\"",
151 expected_pit.to_string (), 151 expected_pit.to_string (),
152 new_pit.to_string ())); 152 new_pit.to_string ()));
153 new_pit = expected_pit; 153 new_pit = expected_pit;
154 } 154 }
155 155
156 set_property ("pitch", new_pit.smobbed_copy ()); 156 set_property (this, "pitch", new_pit.smobbed_copy ());
157 157
158 last = new_pit; 158 last = new_pit;
159 } 159 }
160 160
161 if (Music *m = unsmob<Music> (elt)) 161 if (Music *m = unsmob<Music> (elt))
162 last = m->to_relative_octave (last); 162 last = m->to_relative_octave (last);
163 163
164 (void) music_list_to_relative (get_property ("articulations"), last, true); 164 (void) music_list_to_relative (get_property (this, "articulations"), last, tru e);
165 last = music_list_to_relative (get_property ("elements"), last, false); 165 last = music_list_to_relative (get_property (this, "elements"), last, false);
166 return last; 166 return last;
167 } 167 }
168 168
169 Pitch 169 Pitch
170 Music::to_relative_octave (Pitch last) 170 Music::to_relative_octave (Pitch last)
171 { 171 {
172 SCM callback = get_property ("to-relative-callback"); 172 SCM callback = get_property (this, "to-relative-callback");
173 if (ly_is_procedure (callback)) 173 if (ly_is_procedure (callback))
174 { 174 {
175 Pitch *p = unsmob<Pitch> (scm_call_2 (callback, self_scm (), 175 Pitch *p = unsmob<Pitch> (scm_call_2 (callback, self_scm (),
176 last.smobbed_copy ())); 176 last.smobbed_copy ()));
177 return *p; 177 return *p;
178 } 178 }
179 179
180 return generic_to_relative_octave (last); 180 return generic_to_relative_octave (last);
181 } 181 }
182 182
183 void 183 void
184 Music::compress (Rational factor) 184 Music::compress (Rational factor)
185 { 185 {
186 SCM elt = get_property ("element"); 186 SCM elt = get_property (this, "element");
187 187
188 if (Music *m = unsmob<Music> (elt)) 188 if (Music *m = unsmob<Music> (elt))
189 m->compress (factor); 189 m->compress (factor);
190 190
191 compress_music_list (get_property ("elements"), factor); 191 compress_music_list (get_property (this, "elements"), factor);
192 Duration *d = unsmob<Duration> (get_property ("duration")); 192 Duration *d = unsmob<Duration> (get_property (this, "duration"));
193 if (d) 193 if (d)
194 set_property ("duration", 194 set_property (this, "duration",
195 d->compressed (factor).smobbed_copy ()); 195 d->compressed (factor).smobbed_copy ());
196 } 196 }
197 197
198 /* 198 /*
199 This mutates alist. Hence, make sure that it is not shared 199 This mutates alist. Hence, make sure that it is not shared
200 */ 200 */
201 201
202 void 202 void
203 Prob::transpose (Pitch delta) 203 Prob::transpose (Pitch delta)
204 { 204 {
205 if (to_boolean (get_property ("untransposable"))) 205 if (to_boolean (get_property (this, "untransposable")))
206 return; 206 return;
207 207
208 for (SCM s = mutable_property_alist_; scm_is_pair (s); s = scm_cdr (s)) 208 for (SCM s = mutable_property_alist_; scm_is_pair (s); s = scm_cdr (s))
209 { 209 {
210 SCM entry = scm_car (s); 210 SCM entry = scm_car (s);
211 SCM prop = scm_car (entry); 211 SCM prop = scm_car (entry);
212 SCM val = scm_cdr (entry); 212 SCM val = scm_cdr (entry);
213 SCM new_val = val; 213 SCM new_val = val;
214 214
215 if (Pitch *p = unsmob<Pitch> (val)) 215 if (Pitch *p = unsmob<Pitch> (val))
(...skipping 19 matching lines...) Expand all
235 new_val = ly_transpose_key_alist (val, delta.smobbed_copy ()); 235 new_val = ly_transpose_key_alist (val, delta.smobbed_copy ());
236 236
237 if (!scm_is_eq (val, new_val)) 237 if (!scm_is_eq (val, new_val))
238 scm_set_cdr_x (entry, new_val); 238 scm_set_cdr_x (entry, new_val);
239 } 239 }
240 } 240 }
241 241
242 void 242 void
243 Music::set_spot (Input ip) 243 Music::set_spot (Input ip)
244 { 244 {
245 set_property ("origin", ip.smobbed_copy ()); 245 set_property (this, "origin", ip.smobbed_copy ());
246 } 246 }
247 247
248 Input * 248 Input *
249 Music::origin () const 249 Music::origin () const
250 { 250 {
251 Input *ip = unsmob<Input> (get_property ("origin")); 251 Input *ip = unsmob<Input> (get_property (this, "origin"));
252 return ip ? ip : &dummy_input_global; 252 return ip ? ip : &dummy_input_global;
253 } 253 }
254 254
255 /* 255 /*
256 ES TODO: This method should probably be reworked or junked. 256 ES TODO: This method should probably be reworked or junked.
257 */ 257 */
258 Stream_event * 258 Stream_event *
259 Music::to_event () const 259 Music::to_event () const
260 { 260 {
261 SCM class_name = ly_camel_case_2_lisp_identifier (get_property ("name")); 261 SCM class_name = ly_camel_case_2_lisp_identifier (get_property (this, "name")) ;
262 262
263 // catch programming mistakes. 263 // catch programming mistakes.
264 if (!internal_is_music_type (class_name)) 264 if (!internal_is_music_type (class_name))
265 programming_error ("Not a music type"); 265 programming_error ("Not a music type");
266 266
267 Stream_event *e = new Stream_event 267 Stream_event *e = new Stream_event
268 (Lily::ly_make_event_class (class_name), 268 (Lily::ly_make_event_class (class_name),
269 mutable_property_alist_); 269 mutable_property_alist_);
270 Moment length = get_length (); 270 Moment length = get_length ();
271 if (length.to_bool ()) 271 if (length.to_bool ())
272 e->set_property ("length", length.smobbed_copy ()); 272 set_property (e, "length", length.smobbed_copy ());
273 273
274 // articulations as events. 274 // articulations as events.
275 SCM art_mus = e->get_property ("articulations"); 275 SCM art_mus = get_property (e, "articulations");
276 if (scm_is_pair (art_mus)) 276 if (scm_is_pair (art_mus))
277 { 277 {
278 SCM art_ev = SCM_EOL; 278 SCM art_ev = SCM_EOL;
279 for (; scm_is_pair (art_mus); art_mus = scm_cdr (art_mus)) 279 for (; scm_is_pair (art_mus); art_mus = scm_cdr (art_mus))
280 { 280 {
281 Music *m = unsmob<Music> (scm_car (art_mus)); 281 Music *m = unsmob<Music> (scm_car (art_mus));
282 art_ev = scm_cons (m->to_event ()->unprotect (), art_ev); 282 art_ev = scm_cons (m->to_event ()->unprotect (), art_ev);
283 } 283 }
284 e->set_property ("articulations", scm_reverse_x (art_ev, SCM_EOL)); 284 set_property (e, "articulations", scm_reverse_x (art_ev, SCM_EOL));
285 } 285 }
286 286
287 /* 287 /*
288 ES TODO: This is a temporary fix. Stream_events should not be 288 ES TODO: This is a temporary fix. Stream_events should not be
289 aware of music. 289 aware of music.
290 */ 290 */
291 e->set_property ("music-cause", self_scm ()); 291 set_property (e, "music-cause", self_scm ());
292 292
293 return e; 293 return e;
294 } 294 }
295 295
296 void 296 void
297 Music::send_to_context (Context *c) 297 Music::send_to_context (Context *c)
298 { 298 {
299 Stream_event *ev = to_event (); 299 Stream_event *ev = to_event ();
300 c->event_source ()->broadcast (ev); 300 c->event_source ()->broadcast (ev);
301 ev->unprotect (); 301 ev->unprotect ();
302 } 302 }
303 303
304 Music * 304 Music *
305 make_music_by_name (SCM sym) 305 make_music_by_name (SCM sym)
306 { 306 {
307 SCM rv = Lily::make_music (sym); 307 SCM rv = Lily::make_music (sym);
308 308
309 /* UGH. */ 309 /* UGH. */
310 Music *m = unsmob<Music> (rv); 310 Music *m = unsmob<Music> (rv);
311 m->protect (); 311 m->protect ();
312 return m; 312 return m;
313 } 313 }
314 314
315 MAKE_SCHEME_CALLBACK (Music, duration_length_callback, 1); 315 MAKE_SCHEME_CALLBACK (Music, duration_length_callback, 1);
316 SCM 316 SCM
317 Music::duration_length_callback (SCM m) 317 Music::duration_length_callback (SCM m)
318 { 318 {
319 Music *me = unsmob<Music> (m); 319 Music *me = unsmob<Music> (m);
320 Duration *d = unsmob<Duration> (me->get_property ("duration")); 320 Duration *d = unsmob<Duration> (get_property (me, "duration"));
321 321
322 Moment mom; 322 Moment mom;
323 if (d) 323 if (d)
324 mom = d->get_length (); 324 mom = d->get_length ();
325 return mom.smobbed_copy (); 325 return mom.smobbed_copy ();
326 } 326 }
327 327
328 SCM 328 SCM
329 music_deep_copy (SCM m) 329 music_deep_copy (SCM m)
330 { 330 {
(...skipping 21 matching lines...) Expand all
352 352
353 void 353 void
354 set_origin (SCM m, SCM origin) 354 set_origin (SCM m, SCM origin)
355 { 355 {
356 while (scm_is_pair (m)) 356 while (scm_is_pair (m))
357 { 357 {
358 set_origin (scm_car (m), origin); 358 set_origin (scm_car (m), origin);
359 m = scm_cdr (m); 359 m = scm_cdr (m);
360 } 360 }
361 if (Music *mus = unsmob<Music> (m)) 361 if (Music *mus = unsmob<Music> (m))
362 mus->set_property ("origin", origin); 362 set_property (mus, "origin", origin);
363 } 363 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b