]> git.donarmstrong.com Git - lilypond.git/blob - lily/context.cc
Issue 4512: Remove redundant occurences of this->
[lilypond.git] / lily / context.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "context.hh"
21
22 #include "context-def.hh"
23 #include "dispatcher.hh"
24 #include "global-context.hh"
25 #include "international.hh"
26 #include "main.hh"
27 #include "output-def.hh"
28 #include "profile.hh"
29 #include "program-option.hh"
30 #include "scm-hash.hh"
31 #include "translator-group.hh"
32 #include "warn.hh"
33 #include "lily-imports.hh"
34
35 bool
36 Context::is_removable () const
37 {
38   return scm_is_null (context_list_) && ! client_count_
39          && !dynamic_cast<Global_context const *> (daddy_context_);
40 }
41
42 void
43 Context::check_removal ()
44 {
45   for (SCM p = context_list_; scm_is_pair (p); p = scm_cdr (p))
46     {
47       Context *ctx = unsmob<Context> (scm_car (p));
48
49       ctx->check_removal ();
50       if (ctx->is_removable ())
51         {
52           recurse_over_translators (ctx, &Translator::finalize,
53                                     &Translator_group::finalize,
54                                     UP);
55           send_stream_event (ctx, "RemoveContext", 0, 0);
56         }
57     }
58 }
59
60 Scheme_hash_table *
61 Context::properties_dict () const
62 {
63   return unsmob<Scheme_hash_table> (properties_scm_);
64 }
65
66 void
67 Context::add_context (Context *child)
68 {
69   context_list_ = ly_append2 (context_list_,
70                               scm_cons (child->self_scm (), SCM_EOL));
71
72   child->daddy_context_ = this;
73   events_below_->register_as_listener (child->events_below_);
74 }
75
76 Context::Context ()
77 {
78   daddy_context_ = 0;
79   aliases_ = SCM_EOL;
80   client_count_ = 0;
81   implementation_ = 0;
82   properties_scm_ = SCM_EOL;
83   accepts_list_ = SCM_EOL;
84   default_child_ = SCM_EOL;
85   context_list_ = SCM_EOL;
86   definition_ = SCM_EOL;
87   definition_mods_ = SCM_EOL;
88   event_source_ = 0;
89   events_below_ = 0;
90
91   smobify_self ();
92
93   Scheme_hash_table *tab = new Scheme_hash_table;
94   properties_scm_ = tab->unprotect ();
95   event_source_ = new Dispatcher ();
96   event_source_->unprotect ();
97   events_below_ = new Dispatcher ();
98   events_below_->unprotect ();
99 }
100
101 /* TODO:  this shares code with find_create_context ().  */
102 Context *
103 Context::create_unique_context (SCM name, const string &id, SCM operations)
104 {
105   /*
106     Don't create multiple score contexts.
107   */
108   Global_context *gthis = dynamic_cast<Global_context *> (this);
109   if (gthis && gthis->get_score_context ())
110     return gthis->get_score_context ()->create_unique_context (name, id, operations);
111
112   vector<Context_def *> path = path_to_acceptable_context (name);
113   if (path.size ())
114     {
115       Context *current = this;
116
117       // Iterate through the path and create all of the implicit contexts.
118       for (vsize i = 0; i < path.size (); i++)
119         {
120           SCM ops = SCM_EOL;
121           string id_str = "\\new";
122           if (i == path.size () - 1)
123             {
124               ops = operations;
125               id_str = id;
126             }
127           current = current->create_context (path[i],
128                                              id_str,
129                                              ops);
130         }
131
132       return current;
133     }
134
135   /*
136     Don't go up to Global_context, because global goes down to the
137     Score context
138   */
139   Context *ret = 0;
140   if (daddy_context_ && !dynamic_cast<Global_context *> (daddy_context_))
141     ret = daddy_context_->create_unique_context (name, id, operations);
142   else
143     {
144       warning (_f ("cannot find or create new `%s'",
145                    ly_symbol2string (name).c_str ()));
146       ret = 0;
147     }
148   return ret;
149 }
150
151 Context *
152 Context::find_create_context (SCM n, const string &id, SCM operations)
153 {
154   /*
155     Don't create multiple score contexts.
156   */
157   Global_context *gthis = dynamic_cast<Global_context *> (this);
158   if (gthis)
159     {
160       if (gthis->get_score_context ())
161         return gthis->get_score_context ()->find_create_context (n, id, operations);
162
163       // Special case: If we use \set Timing.xxx = whatever before
164       // Score is established, the alias of Score to Timing will not
165       // be taken into account.  We check for this particular case
166       // here.  Aliases apart from Score-level ones don't warrant
167       // context creation as they could create unwanted contexts, like
168       // RhythmicVoice instead of Voice.  Creating a Score context,
169       // however, can't really do anything wrong.
170
171       SCM score_name = default_child_context_name ();
172       SCM score_def = find_context_def (get_output_def (), score_name);
173
174       if (Context_def *cd = unsmob<Context_def> (score_def))
175         {
176           if (cd->is_alias (n))
177             return create_context (cd, id, operations);
178         }
179     }
180
181
182   if (Context *existing = find_context_below (this, n, id))
183     return existing;
184
185   if (scm_is_eq (n, ly_symbol2scm ("Bottom")))
186     {
187       Context *tg = get_default_interpreter (id);
188       return tg;
189     }
190
191   vector<Context_def *> path = path_to_acceptable_context (n);
192
193   if (path.size ())
194     {
195       Context *current = this;
196
197       // start at 1.  The first one (index 0) will be us.
198       for (vsize i = 0; i < path.size (); i++)
199         {
200           SCM ops = (i == path.size () - 1) ? operations : SCM_EOL;
201
202           string this_id = "";
203           if (i == path.size () - 1)
204             this_id = id;
205
206           current = current->create_context (path[i],
207                                              this_id,
208                                              ops);
209         }
210
211       return current;
212     }
213
214   /*
215     Don't go up to Global_context, because global goes down to the
216     Score context
217   */
218   Context *ret = 0;
219   if (daddy_context_ && !dynamic_cast<Global_context *> (daddy_context_))
220     ret = daddy_context_->find_create_context (n, id, operations);
221   else
222     {
223       warning (_f ("cannot find or create `%s' called `%s'",
224                    ly_symbol2string (n).c_str (), id));
225       ret = 0;
226     }
227   return ret;
228 }
229
230 void
231 Context::acknowledge_infant (SCM sev)
232 {
233   infant_event_ = unsmob<Stream_event> (sev);
234 }
235
236 void
237 Context::set_property_from_event (SCM sev)
238 {
239   Stream_event *ev = unsmob<Stream_event> (sev);
240
241   SCM sym = ev->get_property ("symbol");
242   if (scm_is_symbol (sym))
243     {
244       SCM val = ev->get_property ("value");
245
246       if (SCM_UNBNDP (val)) {
247         unset_property (sym);
248         return;
249       }
250
251       bool ok = true;
252       ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
253
254       if (ok)
255         set_property (sym, val);
256     }
257 }
258
259 void
260 Context::unset_property_from_event (SCM sev)
261 {
262   Stream_event *ev = unsmob<Stream_event> (sev);
263
264   SCM sym = ev->get_property ("symbol");
265   type_check_assignment (sym, SCM_EOL, ly_symbol2scm ("translation-type?"));
266   unset_property (sym);
267 }
268
269 /*
270   Creates a new context from a CreateContext event, and sends an
271   AnnounceNewContext event to this context.
272 */
273 void
274 Context::create_context_from_event (SCM sev)
275 {
276   Stream_event *ev = unsmob<Stream_event> (sev);
277
278   string id = ly_scm2string (ev->get_property ("id"));
279   SCM ops = ev->get_property ("ops");
280   SCM type_scm = ev->get_property ("type");
281   string type = ly_symbol2string (type_scm);
282
283   vector<Context_def *> path = path_to_acceptable_context (type_scm);
284
285   if (path.size () != 1)
286     {
287       programming_error (to_string ("Invalid CreateContext event: Cannot create %s context", type.c_str ()));
288       return;
289     }
290   Context_def *cdef = path[0];
291
292   Context *new_context = cdef->instantiate (ops);
293
294   new_context->id_string_ = id;
295
296   /* Register various listeners:
297       - Make the new context hear events that universally affect contexts
298       - connect events_below etc. properly */
299   /* We want to be the first ones to hear our own events. Therefore, wait
300      before registering events_below_ */
301   new_context->event_source ()->
302   add_listener (new_context->GET_LISTENER (Context, create_context_from_event),
303                 ly_symbol2scm ("CreateContext"));
304   new_context->event_source ()->
305   add_listener (new_context->GET_LISTENER (Context, remove_context),
306                 ly_symbol2scm ("RemoveContext"));
307   new_context->event_source ()->
308   add_listener (new_context->GET_LISTENER (Context, change_parent),
309                 ly_symbol2scm ("ChangeParent"));
310   new_context->event_source ()->
311   add_listener (new_context->GET_LISTENER (Context, set_property_from_event),
312                 ly_symbol2scm ("SetProperty"));
313   new_context->event_source ()->
314   add_listener (new_context->GET_LISTENER (Context, unset_property_from_event),
315                 ly_symbol2scm ("UnsetProperty"));
316
317   new_context->events_below_->register_as_listener (new_context->event_source_);
318   add_context (new_context);
319
320   new_context->unprotect ();
321
322   Context_def *td = unsmob<Context_def> (new_context->definition_);
323
324   /* This cannot move before add_context (), because \override
325      operations require that we are in the hierarchy.  */
326   td->apply_default_property_operations (new_context);
327   apply_property_operations (new_context, ops);
328
329   send_stream_event (this, "AnnounceNewContext", 0,
330                      ly_symbol2scm ("context"), new_context->self_scm (),
331                      ly_symbol2scm ("creator"), sev);
332 }
333
334 vector<Context_def *>
335 Context::path_to_acceptable_context (SCM name) const
336 {
337   // The 'accepts elements in definition_mods_ is a list of ('accepts string),
338   // but the Context_def expects to see elements of the form ('accepts symbol).
339   SCM accepts = SCM_EOL;
340   for (SCM s = definition_mods_; scm_is_pair (s); s = scm_cdr (s))
341     if (scm_is_eq (scm_caar (s), ly_symbol2scm ("accepts")))
342       {
343         SCM elt = scm_list_2 (scm_caar (s), scm_string_to_symbol (scm_cadar (s)));
344         accepts = scm_cons (elt, accepts);
345       }
346
347   return unsmob<Context_def> (definition_)->path_to_acceptable_context (name,
348          get_output_def (),
349          scm_reverse_x (accepts, SCM_EOL));
350
351 }
352
353 Context *
354 Context::create_context (Context_def *cdef,
355                          const string &id,
356                          SCM ops)
357 {
358   infant_event_ = 0;
359   /* TODO: This is fairly misplaced. We can fix this when we have taken out all
360      iterator specific stuff from the Context class */
361   event_source_->
362   add_listener (GET_LISTENER (Context, acknowledge_infant),
363                 ly_symbol2scm ("AnnounceNewContext"));
364   /* The CreateContext creates a new context, and sends an announcement of the
365      new context through another event. That event will be stored in
366      infant_event_ to create a return value. */
367   send_stream_event (this, "CreateContext", 0,
368                      ly_symbol2scm ("ops"), ops,
369                      ly_symbol2scm ("type"), cdef->get_context_name (),
370                      ly_symbol2scm ("id"), ly_string2scm (id));
371   event_source_->
372   remove_listener (GET_LISTENER (Context, acknowledge_infant),
373                    ly_symbol2scm ("AnnounceNewContext"));
374
375   assert (infant_event_);
376   SCM infant_scm = infant_event_->get_property ("context");
377   Context *infant = unsmob<Context> (infant_scm);
378
379   if (!infant || infant->get_parent_context () != this)
380     {
381       programming_error ("create_context: can't locate newly created context");
382       return 0;
383     }
384
385   return infant;
386 }
387
388 /*
389   Default child context as a SCM string, or something else if there is
390   none.
391 */
392 SCM
393 Context::default_child_context_name () const
394 {
395   return default_child_;
396 }
397
398 bool
399 Context::is_bottom_context () const
400 {
401   return !scm_is_symbol (default_child_context_name ());
402 }
403
404 Context *
405 Context::get_default_interpreter (const string &context_id)
406 {
407   if (!is_bottom_context ())
408     {
409       SCM nm = default_child_context_name ();
410       SCM st = find_context_def (get_output_def (), nm);
411
412       string name = ly_symbol2string (nm);
413       Context_def *t = unsmob<Context_def> (st);
414       if (!t)
415         {
416           warning (_f ("cannot find or create: `%s'", name.c_str ()));
417           t = unsmob<Context_def> (definition_);
418         }
419       if (scm_is_symbol (t->get_default_child (SCM_EOL)))
420         {
421           Context *tg = create_context (t, "\\new", SCM_EOL);
422           return tg->get_default_interpreter (context_id);
423         }
424       return create_context (t, context_id, SCM_EOL);
425     }
426   else if (!context_id.empty () && context_id != id_string ())
427     {
428       if (daddy_context_ && !dynamic_cast<Global_context *> (daddy_context_))
429         return daddy_context_->get_default_interpreter (context_id);
430       warning (_f ("cannot find or create new Bottom = \"%s\"",
431                    context_id.c_str ()));
432     }
433   return this;
434 }
435
436 /*
437   PROPERTIES
438 */
439 Context *
440 Context::where_defined (SCM sym, SCM *value) const
441 {
442 #ifdef DEBUG
443   if (profile_property_accesses)
444     note_property_access (&context_property_lookup_table, sym);
445 #endif
446
447   if (properties_dict ()->try_retrieve (sym, value))
448     return (Context *)this;
449
450   return (daddy_context_) ? daddy_context_->where_defined (sym, value) : 0;
451 }
452
453 /* Quick variant of where_defined.  Checks only the context itself. */
454
455 bool
456 Context::here_defined (SCM sym, SCM *value) const
457 {
458 #ifdef DEBUG
459   if (profile_property_accesses)
460     note_property_access (&context_property_lookup_table, sym);
461 #endif
462
463   return properties_dict ()->try_retrieve (sym, value);
464 }
465
466 /*
467   return SCM_EOL when not found.
468 */
469 SCM
470 Context::internal_get_property (SCM sym) const
471 {
472 #ifdef DEBUG
473   if (profile_property_accesses)
474     note_property_access (&context_property_lookup_table, sym);
475 #endif
476
477   SCM val = SCM_EOL;
478   if (properties_dict ()->try_retrieve (sym, &val))
479     return val;
480
481   if (daddy_context_)
482     return daddy_context_->internal_get_property (sym);
483
484   return val;
485 }
486
487 /*
488 Called by the send_stream_event macro. props is a 0-terminated array of
489 properties and corresponding values, interleaved. This method should not
490 be called from any other place than the send_stream_event macro.
491 */
492 void
493 Context::internal_send_stream_event (SCM type, Input *origin, SCM props[])
494 {
495   Stream_event *e = new Stream_event (Lily::ly_make_event_class (type), origin);
496   for (int i = 0; props[i]; i += 2)
497     {
498       e->set_property (props[i], props[i + 1]);
499     }
500   event_source_->broadcast (e);
501   e->unprotect ();
502 }
503
504 bool
505 Context::is_alias (SCM sym) const
506 {
507   if (scm_is_eq (sym, ly_symbol2scm ("Bottom")))
508     return is_bottom_context ();
509   if (scm_is_eq (sym, context_name_symbol ()))
510     return true;
511
512   return scm_is_true (scm_c_memq (sym, aliases_));
513 }
514
515 void
516 Context::add_alias (SCM sym)
517 {
518   aliases_ = scm_cons (sym, aliases_);
519 }
520
521 /* we don't (yet) instrument context properties */
522 void
523 Context::instrumented_set_property (SCM sym, SCM val, const char *, int, const char *)
524 {
525   internal_set_property (sym, val);
526 }
527
528 void
529 Context::internal_set_property (SCM sym, SCM val)
530 {
531   bool type_check_ok = type_check_assignment (sym, val, ly_symbol2scm ("translation-type?"));
532
533   if (do_internal_type_checking_global)
534     assert (type_check_ok);
535
536   if (type_check_ok)
537     properties_dict ()->set (sym, val);
538 }
539
540 /*
541   TODO: look up to check whether we have inherited var?
542 */
543 void
544 Context::unset_property (SCM sym)
545 {
546   properties_dict ()->remove (sym);
547 }
548
549 void
550 Context::change_parent (SCM sev)
551 {
552   Stream_event *ev = unsmob<Stream_event> (sev);
553   Context *to = unsmob<Context> (ev->get_property ("context"));
554
555   disconnect_from_parent ();
556   to->add_context (this);
557 }
558
559 /*
560   Die. The next GC sweep should take care of the actual death.
561  */
562 void
563 Context::remove_context (SCM)
564 {
565   /* ugh, the translator group should listen to RemoveContext events by itself */
566   Translator_group *impl = implementation ();
567   if (impl)
568     impl->disconnect_from_context ();
569   disconnect_from_parent ();
570 }
571
572 void
573 Context::disconnect_from_parent ()
574 {
575   daddy_context_->events_below_->unregister_as_listener (events_below_);
576   daddy_context_->context_list_ = scm_delq_x (self_scm (), daddy_context_->context_list_);
577   daddy_context_ = 0;
578 }
579
580 Context *
581 find_context_above (Context *where, SCM type)
582 {
583   while (where && !where->is_alias (type))
584     where = where->get_parent_context ();
585
586   return where;
587 }
588
589 Context *
590 find_context_above_by_parent_type (Context *where, SCM parent_type)
591 {
592   for (Context *child = 0; where;
593        child = where, where = where->get_parent_context ())
594     if (where->is_alias (parent_type))
595       return child;
596
597   return 0;
598 }
599
600 Context *
601 find_context_below (Context *where,
602                     SCM type, const string &id)
603 {
604   if (where->is_alias (type))
605     {
606       if (id == "" || where->id_string () == id)
607         return where;
608     }
609
610   Context *found = 0;
611   for (SCM s = where->children_contexts ();
612        !found && scm_is_pair (s); s = scm_cdr (s))
613     {
614       Context *tr = unsmob<Context> (scm_car (s));
615
616       found = find_context_below (tr, type, id);
617     }
618
619   return found;
620 }
621
622 Context *
623 find_context_near (Context *where,
624                    SCM type, const string &id)
625 {
626   for ( ; where; where = where->get_parent_context ())
627     {
628       Context *found = find_context_below (where, type, id);
629       if (found)
630         return found;
631     }
632
633   return 0;
634 }
635
636 Context *
637 find_top_context (Context *where)
638 {
639   Context *top = where;
640   for ( ; where; where = where->get_parent_context())
641     top = where;
642   return top;
643 }
644
645 SCM
646 Context::properties_as_alist () const
647 {
648   return properties_dict ()->to_alist ();
649 }
650
651 SCM
652 Context::context_name_symbol () const
653 {
654   Context_def *td = unsmob<Context_def> (definition_);
655   return td->get_context_name ();
656 }
657
658 string
659 Context::context_name () const
660 {
661   return ly_symbol2string (context_name_symbol ());
662 }
663
664 Context *
665 Context::get_score_context () const
666 {
667   if (daddy_context_)
668     return daddy_context_->get_score_context ();
669   else
670     return 0;
671 }
672
673 Output_def *
674 Context::get_output_def () const
675 {
676   return daddy_context_ ? daddy_context_->get_output_def () : 0;
677 }
678
679 Context::~Context ()
680 {
681 }
682
683 Moment
684 Context::now_mom () const
685 {
686   Context const *p = this;
687   while (p->daddy_context_)
688     p = p->daddy_context_;
689
690   return p->now_mom ();
691 }
692
693 int
694 Context::print_smob (SCM port, scm_print_state *) const
695 {
696   scm_puts ("#<", port);
697   scm_puts (class_name (), port);
698   if (Context_def *d = unsmob<Context_def> (definition_))
699     {
700       scm_puts (" ", port);
701       scm_display (d->get_context_name (), port);
702     }
703
704   if (!id_string_.empty ())
705     {
706       scm_puts ("=", port);
707       scm_puts (id_string_.c_str (), port);
708     }
709
710   scm_puts (" ", port);
711
712   scm_display (context_list_, port);
713   scm_puts (" >", port);
714
715   return 1;
716 }
717
718 SCM
719 Context::mark_smob () const
720 {
721   scm_gc_mark (context_list_);
722   scm_gc_mark (aliases_);
723   scm_gc_mark (definition_);
724   scm_gc_mark (definition_mods_);
725   scm_gc_mark (properties_scm_);
726   scm_gc_mark (accepts_list_);
727   scm_gc_mark (default_child_);
728
729   if (implementation_)
730     scm_gc_mark (implementation_->self_scm ());
731
732   if (event_source_)
733     scm_gc_mark (event_source_->self_scm ());
734
735   if (events_below_)
736     scm_gc_mark (events_below_->self_scm ());
737
738   return properties_scm_;
739 }
740
741 const char Context::type_p_name_[] = "ly:context?";
742
743 Global_context *
744 Context::get_global_context () const
745 {
746   if (dynamic_cast<Global_context *> ((Context *) this))
747     return dynamic_cast<Global_context *> ((Context *) this);
748
749   if (daddy_context_)
750     return daddy_context_->get_global_context ();
751
752   programming_error ("no Global context");
753   return 0;
754 }
755
756 Context *
757 Context::get_parent_context () const
758 {
759   return daddy_context_;
760 }
761
762 /*
763   Ugh. Where to put this?
764 */
765 Rational
766 measure_length (Context const *context)
767 {
768   SCM l = context->get_property ("measureLength");
769   Rational length (1);
770   if (unsmob<Moment> (l))
771     length = unsmob<Moment> (l)->main_part_;
772   return length;
773 }
774
775 Moment
776 measure_position (Context const *context)
777 {
778   SCM sm = context->get_property ("measurePosition");
779
780   Moment m = 0;
781   if (unsmob<Moment> (sm))
782     {
783       m = *unsmob<Moment> (sm);
784
785       if (m.main_part_ < Rational (0))
786         {
787           Rational length (measure_length (context));
788           while (m.main_part_ < Rational (0))
789             m.main_part_ += length;
790         }
791     }
792
793   return m;
794 }
795
796 /* Finds the measure position after a note of length DUR that
797    begins at the current measure position. */
798 Moment
799 measure_position (Context const *context, Duration const *dur)
800 {
801   Moment pos = measure_position (context);
802   Rational dur_length = dur ? dur->get_length () : Rational (0);
803
804   Moment end_pos = pos.grace_part_ < Rational (0)
805                    ? Moment (pos.main_part_, pos.grace_part_ + dur_length)
806                    : Moment (pos.main_part_ + dur_length, 0);
807
808   return end_pos;
809 }
810
811 int
812 measure_number (Context const *context)
813 {
814   SCM barnum = context->get_property ("internalBarNumber");
815   SCM smp = context->get_property ("measurePosition");
816
817   int bn = robust_scm2int (barnum, 0);
818   Moment mp = robust_scm2moment (smp, Moment (0));
819   if (mp.main_part_ < Rational (0))
820     bn--;
821
822   return bn;
823 }
824
825 void
826 set_context_property_on_children (Context *trans, SCM sym, SCM val)
827 {
828   trans->set_property (sym, ly_deep_copy (val));
829   for (SCM p = trans->children_contexts (); scm_is_pair (p); p = scm_cdr (p))
830     {
831       Context *trg = unsmob<Context> (scm_car (p));
832       set_context_property_on_children (trg, sym, ly_deep_copy (val));
833     }
834 }
835
836 bool
837 melisma_busy (Context *tr)
838 {
839   // When there are subcontexts, they are responsible for maintaining
840   // melismata.
841   SCM ch = tr->children_contexts ();
842   if (scm_is_pair (ch))
843     {
844       // all contexts need to have a busy melisma for this to evaluate
845       // to true.
846
847       do {
848         if (!melisma_busy (unsmob<Context> (scm_car (ch))))
849           return false;
850         ch = scm_cdr (ch);
851       } while (scm_is_pair (ch));
852       return true;
853     }
854
855   for (SCM melisma_properties = tr->get_property ("melismaBusyProperties");
856        scm_is_pair (melisma_properties);
857        melisma_properties = scm_cdr (melisma_properties))
858     if (to_boolean (tr->get_property (scm_car (melisma_properties))))
859       return true;
860
861   return false;
862 }
863
864 bool
865 check_repeat_count_visibility (Context const *context, SCM count)
866 {
867   SCM proc = context->get_property ("repeatCountVisibility");
868   return (ly_is_procedure (proc)
869           && to_boolean (scm_call_2 (proc,
870                                      count,
871                                      context->self_scm ())));
872 }