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