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