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