]> git.donarmstrong.com Git - lilypond.git/blob - lily/grob.cc
release: 1.5.17
[lilypond.git] / lily / grob.cc
1 /*
2   score-elem.cc -- implement Grob
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include <string.h>
11 #include <math.h>
12
13 #include "input-smob.hh"
14 #include "libc-extension.hh"
15 #include "group-interface.hh"
16 #include "misc.hh"
17 #include "paper-score.hh"
18 #include "paper-def.hh"
19 #include "molecule.hh"
20 #include "grob.hh"
21 #include "debug.hh"
22 #include "spanner.hh"
23 #include "line-of-score.hh"
24 #include "item.hh"
25 #include "paper-column.hh"
26 #include "molecule.hh"
27 #include "misc.hh"
28 #include "paper-outputter.hh"
29 #include "dimension-cache.hh"
30 #include "side-position-interface.hh"
31 #include "item.hh"
32
33 #include "ly-smobs.icc"
34
35 /*
36 TODO:
37
38 remove dynamic_cast<Spanner,Item> and put this code into respective
39   subclass.
40 */
41
42
43 #define INFINITY_MSG "Infinity or NaN encountered"
44
45 Grob::Grob (SCM basicprops)
46 {
47   /*
48     fixme: default should be no callback.
49    */
50
51   pscore_l_=0;
52   status_c_ = 0;
53   original_l_ = 0;
54   immutable_property_alist_ =  basicprops;
55   mutable_property_alist_ = SCM_EOL;
56
57   smobify_self ();
58
59   /*
60     TODO:
61
62     destill this into a function, so we can re-init the immutable
63     properties with a new BASICPROPS value after creation. Convenient
64     eg. when using \override with StaffSymbol.  */
65   
66   char const*onames[] = {"X-offset-callbacks", "Y-offset-callbacks"};
67   char const*enames[] = {"X-extent-callback", "Y-extent-callback"};
68   
69   for (int a = X_AXIS; a <= Y_AXIS; a++)
70     {
71       SCM l = get_grob_property (onames[a]);
72
73       if (scm_ilength (l) >=0)
74         {
75           dim_cache_[a].offset_callbacks_ = l;
76           dim_cache_[a].offsets_left_ = scm_ilength (l);
77         }
78       else
79         {
80           programming_error ("[XY]-offset-callbacks must be a list");
81         }
82
83       SCM cb = get_grob_property (enames[a]);
84
85       /*
86         Should change default to be empty? 
87       */
88       if (cb != SCM_BOOL_F && !gh_procedure_p (cb) && !gh_pair_p (cb))
89         cb = molecule_extent_proc;
90     
91       dim_cache_[a].dimension_ = cb;
92     }
93
94   SCM meta = get_grob_property ("meta");
95   if (gh_pair_p (meta))
96     {
97       SCM ifs = scm_assoc (ly_symbol2scm ("interfaces"), meta);
98   
99       set_grob_property ("interfaces",ly_cdr (ifs));
100     }
101 }
102
103 Grob::Grob (Grob const&s)
104    : dim_cache_ (s.dim_cache_)
105 {
106   original_l_ = (Grob*) &s;
107   immutable_property_alist_ = s.immutable_property_alist_;
108   mutable_property_alist_ = SCM_EOL;
109   
110   status_c_ = s.status_c_;
111   pscore_l_ = s.pscore_l_;
112
113   smobify_self ();
114 }
115
116 Grob::~Grob ()
117 {
118   /*
119     do nothing scm-ish and no unprotecting here.
120    */
121 }
122
123
124 SCM
125 Grob::get_grob_property (const char *nm) const
126 {
127   SCM sym = ly_symbol2scm (nm);
128   return get_grob_property (sym);
129 }
130
131 SCM
132 Grob::get_grob_property (SCM sym) const
133 {
134   SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
135   if (s != SCM_BOOL_F)
136     return ly_cdr (s);
137
138   s = scm_sloppy_assq (sym, immutable_property_alist_);
139   return (s == SCM_BOOL_F) ? SCM_EOL : ly_cdr (s); 
140 }
141
142 /*
143   Remove the value associated with KEY, and return it. The result is
144   that a next call will yield SCM_EOL (and not the underlying
145   `basic' property.
146 */
147 SCM
148 Grob::remove_grob_property (const char* key)
149 {
150   SCM val = get_grob_property (key);
151   if (val != SCM_EOL)
152     set_grob_property (key, SCM_EOL);
153   return val;
154 }
155
156 void
157 Grob::set_grob_property (const char* k, SCM v)
158 {
159   SCM s = ly_symbol2scm (k);
160   set_grob_property (s, v);
161 }
162
163 /*
164   Puts the k, v in the immutable_property_alist_, which is convenient for
165   storing variables that are needed during the breaking process. (eg.
166   Line_of_score::rank : int)
167  */
168 void
169 Grob::set_immutable_grob_property (const char*k, SCM v)
170 {
171   SCM s = ly_symbol2scm (k);
172   set_immutable_grob_property (s, v);
173 }
174
175 void
176 Grob::set_immutable_grob_property (SCM s, SCM v)
177 {
178   immutable_property_alist_ = gh_cons (gh_cons (s,v), mutable_property_alist_);
179   mutable_property_alist_ = scm_assq_remove_x (mutable_property_alist_, s);
180 }
181 void
182 Grob::set_grob_property (SCM s, SCM v)
183 {
184   mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
185 }
186
187
188 MAKE_SCHEME_CALLBACK (Grob,molecule_extent,2);
189 SCM
190 Grob::molecule_extent (SCM element_smob, SCM scm_axis)
191 {
192   Grob *s = unsmob_grob (element_smob);
193   Axis a = (Axis) gh_scm2int (scm_axis);
194
195   Molecule *m = s->get_molecule ();
196   Interval e ;
197   if (m)
198     e = m->extent (a);
199   return ly_interval2scm (e);
200 }
201
202 MAKE_SCHEME_CALLBACK (Grob,preset_extent,2);
203
204 SCM
205 Grob::preset_extent (SCM element_smob, SCM scm_axis)
206 {
207   Grob *s = unsmob_grob (element_smob);
208   Axis a = (Axis) gh_scm2int (scm_axis);
209
210   SCM ext = s->get_grob_property ((a == X_AXIS)
211                                  ? "extent-X"
212                                  : "extent-Y");
213   
214   if (gh_pair_p (ext))
215     {
216       Real l = gh_scm2double (ly_car (ext));
217       Real r = gh_scm2double (ly_cdr (ext));
218       return ly_interval2scm (Interval (l, r));
219     }
220   
221   return ly_interval2scm (Interval ());
222 }
223
224
225
226 Paper_def*
227 Grob::paper_l ()  const
228 {
229  return pscore_l_ ? pscore_l_->paper_l_ : 0;
230 }
231
232 void
233 Grob::calculate_dependencies (int final, int busy, SCM funcname)
234 {
235   if (status_c_ >= final)
236     return;
237
238   if (status_c_== busy)
239     {
240       programming_error ("Element is busy, come back later");
241       return;
242     }
243   
244   status_c_= busy;
245
246   for (SCM d=  get_grob_property ("dependencies"); gh_pair_p (d); d = ly_cdr (d))
247     {
248       unsmob_grob (ly_car (d))
249         ->calculate_dependencies (final, busy, funcname);
250     }
251
252   // ughugh.
253   String s = ly_symbol2string (funcname);
254   SCM proc = get_grob_property (s.ch_C ());
255   if (gh_procedure_p (proc))
256     gh_call1 (proc, this->self_scm ());
257   
258   status_c_= final;
259
260 }
261
262 Molecule *
263 Grob::get_molecule ()  const
264 {
265   SCM mol = get_grob_property ("molecule");
266   if (unsmob_molecule (mol))
267     return unsmob_molecule (mol);
268
269   mol =  get_uncached_molecule ();
270   
271   Grob *me = (Grob*)this;
272   me->set_grob_property ("molecule", mol);
273   
274   return unsmob_molecule (mol);  
275 }
276 SCM
277 Grob::get_uncached_molecule ()const
278 {
279   SCM proc = get_grob_property ("molecule-callback");
280
281   SCM  mol = SCM_EOL;
282   if (gh_procedure_p (proc)) 
283     mol = gh_apply (proc, scm_list_n (this->self_scm (), SCM_UNDEFINED));
284
285   
286   Molecule *m = unsmob_molecule (mol);
287   
288   if (unsmob_molecule (mol))
289     {
290       /*
291         TODO: add option for not copying origin info. 
292       */
293       SCM origin =get_grob_property ("origin");
294       if (!unsmob_input (origin))
295         origin =ly_symbol2scm ("no-origin");
296       
297       
298       // ugr.
299       
300       mol = Molecule (m->extent_box (),
301                       scm_list_n (origin, m->get_expr (), SCM_UNDEFINED)
302                       ). smobbed_copy ();
303
304       m = unsmob_molecule (mol);
305     }
306   
307   /*
308     transparent retains dimensions of element.
309    */
310   if (m && to_boolean (get_grob_property ("transparent")))
311     mol = Molecule (m->extent_box (), SCM_EOL).smobbed_copy ();
312
313   return mol;
314 }
315
316 /*
317   
318   VIRTUAL STUBS
319
320  */
321 void
322 Grob::do_break_processing ()
323 {
324 }
325
326
327
328
329
330
331 Line_of_score *
332 Grob::line_l () const
333 {
334   return 0;
335 }
336
337 void
338 Grob::add_dependency (Grob*e)
339 {
340   if (e)
341     {
342       Pointer_group_interface ::add_element (this, "dependencies",e);
343
344     }
345   else
346     programming_error ("Null dependency added");
347 }
348
349
350
351
352 /**
353       Do break substitution in S, using CRITERION. Return new value.
354       CRITERION is either a SMOB pointer to the desired line, or a number
355       representing the break direction. Do not modify SRC.
356
357       It is rather tightly coded, since it takes a lot of time.
358 */
359 SCM
360 Grob::handle_broken_grobs (SCM src, SCM criterion)
361 {
362  again:
363   Grob *sc = unsmob_grob (src);
364   if (sc)
365     {
366       if (gh_number_p (criterion))
367         {
368           Item * i = dynamic_cast<Item*> (sc);
369           Direction d = to_dir (criterion);
370           if (i && i->break_status_dir () != d)
371             {
372               Item *br = i->find_prebroken_piece (d);
373               return (br) ? br->self_scm () : SCM_UNDEFINED;
374             }
375         }
376       else
377         {
378           Line_of_score * line
379             = dynamic_cast<Line_of_score*> (unsmob_grob (criterion));
380           if (sc->line_l () != line)
381             {
382               sc = sc->find_broken_piece (line);
383
384             }
385
386           /* now: !sc || (sc && sc->line_l () == line) */
387           if (!sc)
388             return SCM_UNDEFINED;
389
390           /* now: sc && sc->line_l () == line */
391           if (!line
392               /*
393                 This was introduced in 1.3.49 as a measure to prevent
394                 programming errors. It looks expensive (?). TODO:
395                 benchmark , document when (what kind of programming
396                 errors) this happens.
397                */
398               || (sc->common_refpoint (line, X_AXIS)
399                   && sc->common_refpoint (line, Y_AXIS)))
400             {
401               return sc->self_scm ();
402             }
403           return SCM_UNDEFINED;
404         }
405     }
406   else if (gh_pair_p (src))
407     {
408       SCM oldcar =ly_car (src);
409       /*
410         UGH! breaks on circular lists.
411       */
412       SCM newcar = handle_broken_grobs (oldcar, criterion);
413       SCM oldcdr = ly_cdr (src);
414       
415       if (newcar == SCM_UNDEFINED
416           && (gh_pair_p (oldcdr) || oldcdr == SCM_EOL))
417         {
418           /*
419             This is tail-recursion, ie. 
420             
421             return handle_broken_grobs (cdr, criterion);
422
423             We don't want to rely on the compiler to do this.  Without
424             tail-recursion, this easily crashes with a stack overflow.  */
425           src =  oldcdr;
426           goto again;
427         }
428
429       SCM newcdr = handle_broken_grobs (oldcdr, criterion);
430       return gh_cons (newcar, newcdr);
431     }
432   else
433     return src;
434
435   return src;
436 }
437
438 void
439 Grob::handle_broken_dependencies ()
440 {
441   Spanner * s= dynamic_cast<Spanner*> (this);
442   if (original_l_ && s)
443     return;
444
445   if (s)
446     {
447       for (int i = 0;  i< s->broken_into_l_arr_ .size (); i++)
448         {
449           Grob * sc = s->broken_into_l_arr_[i];
450           Line_of_score * l = sc->line_l ();
451           sc->mutable_property_alist_ =
452             handle_broken_grobs (mutable_property_alist_,
453                                  l ? l->self_scm () : SCM_UNDEFINED);
454         }
455     }
456
457
458   Line_of_score *line = line_l ();
459
460   if (line && common_refpoint (line, X_AXIS) && common_refpoint (line, Y_AXIS))
461     {
462       mutable_property_alist_
463         = handle_broken_grobs (mutable_property_alist_,
464                                line ? line->self_scm () : SCM_UNDEFINED);
465     }
466   else if (dynamic_cast <Line_of_score*> (this))
467     {
468       mutable_property_alist_ = handle_broken_grobs (mutable_property_alist_,
469                                             SCM_UNDEFINED);
470     }
471   else
472     {
473       /*
474         This element is `invalid'; it has been removed from all
475         dependencies, so let's junk the element itself.
476
477         do not do this for Line_of_score, since that would remove
478         references to the originals of score-elts, which get then GC'd
479  (a bad thing.)
480       */
481       suicide ();
482     }
483 }
484
485 /*
486  Note that we still want references to this element to be
487  rearranged, and not silently thrown away, so we keep pointers
488  like {broken_into_{drul,array}, original}
489 */
490 void
491 Grob::suicide ()
492 {
493   mutable_property_alist_ = SCM_EOL;
494   immutable_property_alist_ = SCM_EOL;
495
496   set_extent_callback (SCM_EOL, Y_AXIS);
497   set_extent_callback (SCM_EOL, X_AXIS);
498
499   for (int a= X_AXIS; a <= Y_AXIS; a++)
500     {
501       dim_cache_[a].offset_callbacks_ = SCM_EOL;
502       dim_cache_[a].offsets_left_ = 0;
503     }
504 }
505
506 void
507 Grob::handle_prebroken_dependencies ()
508 {
509 }
510
511 Grob*
512 Grob::find_broken_piece (Line_of_score*) const
513 {
514   return 0;
515 }
516
517 void
518 Grob::translate_axis (Real y, Axis a)
519 {
520   if (isinf (y) || isnan (y))
521     programming_error (_ (INFINITY_MSG));
522   else
523     {
524       dim_cache_[a].offset_ += y;
525     }
526 }  
527
528 Real
529 Grob::relative_coordinate (Grob const*refp, Axis a) const
530 {
531   if (refp == this)
532     return 0.0;
533
534   /*
535     We catch PARENT_L_ == nil case with this, but we crash if we did
536     not ask for the absolute coordinate (ie. REFP == nil.)
537     
538    */
539   if (refp == dim_cache_[a].parent_l_)
540     return get_offset (a);
541   else
542     return get_offset (a) + dim_cache_[a].parent_l_->relative_coordinate (refp, a);
543 }
544
545 Real
546 Grob::get_offset (Axis a) const
547 {
548   Grob *me = (Grob*) this;
549   while (dim_cache_[a].offsets_left_)
550     {
551       int l = --me->dim_cache_[a].offsets_left_;
552       SCM cb = scm_list_ref (dim_cache_[a].offset_callbacks_,  gh_int2scm (l));
553       SCM retval = gh_call2 (cb, self_scm (), gh_int2scm (a));
554
555       Real r =  gh_scm2double (retval);
556       if (isinf (r) || isnan (r))
557         {
558           programming_error (INFINITY_MSG);
559           r = 0.0;
560         }
561       me->dim_cache_[a].offset_ +=r;
562     }
563   return dim_cache_[a].offset_;
564 }
565
566
567 MAKE_SCHEME_CALLBACK (Grob,point_dimension_callback,2);
568 SCM
569 Grob::point_dimension_callback (SCM , SCM)
570 {
571   return ly_interval2scm (Interval (0,0));
572 }
573
574 bool
575 Grob::empty_b (Axis a)const
576 {
577   return ! (gh_pair_p (dim_cache_[a].dimension_) ||
578             gh_procedure_p (dim_cache_[a].dimension_));
579 }
580
581 /*
582   TODO: add
583
584     Grob *refpoint
585
586   to arguments?
587  */
588 Interval
589 Grob::extent (Grob * refp, Axis a) const
590 {
591   Real x = relative_coordinate (refp, a);
592
593   
594   Dimension_cache * d = (Dimension_cache *)&dim_cache_[a];
595   Interval ext ;   
596   if (gh_pair_p (d->dimension_))
597     ;
598   else if (gh_procedure_p (d->dimension_))
599     {
600       /*
601         FIXME: add doco on types, and should typecheck maybe? 
602        */
603       d->dimension_= gh_call2 (d->dimension_, self_scm (), gh_int2scm (a));
604     }
605   else
606     return ext;
607
608   if (!gh_pair_p (d->dimension_))
609     return ext;
610   
611   ext = ly_scm2interval (d->dimension_);
612
613   SCM extra = get_grob_property (a == X_AXIS
614                                 ? "extra-extent-X"
615                                 : "extra-extent-Y");
616
617   /*
618     signs ?
619    */
620   if (gh_pair_p (extra))
621     {
622       ext[BIGGER] +=  gh_scm2double (ly_cdr (extra));
623       ext[SMALLER] +=   gh_scm2double (ly_car (extra));
624     }
625   
626   extra = get_grob_property (a == X_AXIS
627                                 ? "minimum-extent-X"
628                                 : "minimum-extent-Y");
629   if (gh_pair_p (extra))
630     {
631       ext.unite (Interval (gh_scm2double (ly_car (extra)),
632                            gh_scm2double (ly_cdr (extra))));
633     }
634
635   ext.translate (x);
636   
637   return ext;
638 }
639
640
641 Grob*
642 Grob::parent_l (Axis a) const
643 {
644   return  dim_cache_[a].parent_l_;
645 }
646
647 Grob * 
648 Grob::common_refpoint (Grob const* s, Axis a) const
649 {
650   /*
651     I don't like the quadratic aspect of this code, but I see no other
652     way. The largest chain of parents might be 10 high or so, so
653     it shouldn't be a real issue. */
654   for (Grob const *c = this; c; c = c->dim_cache_[a].parent_l_)
655     for (Grob const * d = s; d; d = d->dim_cache_[a].parent_l_)
656       if (d == c)
657         return (Grob*)d;
658
659   return 0;
660 }
661
662
663 Grob *
664 Grob::common_refpoint (SCM elist, Axis a) const
665 {
666   Grob * common = (Grob*) this;
667   for (; gh_pair_p (elist); elist = ly_cdr (elist))
668     {
669       Grob * s = unsmob_grob (ly_car (elist));
670       if (s)
671         common = common->common_refpoint (s, a);
672     }
673
674   return common;
675 }
676
677 String
678 Grob::name () const
679 {
680   SCM meta = get_grob_property ("meta");
681   SCM nm = scm_assoc (ly_symbol2scm ("name"), meta);
682   nm = (gh_pair_p (nm)) ? ly_cdr (nm) : SCM_EOL;
683   return  gh_symbol_p (nm) ? ly_symbol2string (nm) :  classname (this);  
684 }
685
686 void
687 Grob::add_offset_callback (SCM cb, Axis a)
688 {
689   if (!has_offset_callback_b (cb, a))
690   {
691     dim_cache_[a].offset_callbacks_ = gh_cons (cb, dim_cache_[a].offset_callbacks_);
692     dim_cache_[a].offsets_left_ ++;
693   }
694 }
695
696 bool
697 Grob::has_extent_callback_b (SCM cb, Axis a)const
698 {
699   return scm_equal_p (cb, dim_cache_[a].dimension_) == SCM_BOOL_T;
700 }
701
702
703 bool
704 Grob::has_extent_callback_b (Axis a) const
705 {
706   return gh_procedure_p (dim_cache_[a].dimension_);
707 }
708
709 bool
710 Grob::has_offset_callback_b (SCM cb, Axis a)const
711 {
712   return scm_memq (cb, dim_cache_[a].offset_callbacks_) != SCM_BOOL_F;
713 }
714
715 void
716 Grob::set_extent_callback (SCM dc, Axis a)
717 {
718   dim_cache_[a].dimension_ =dc;
719 }
720
721 void
722 Grob::set_parent (Grob *g, Axis a)
723 {
724   dim_cache_[a].parent_l_ = g;
725 }
726
727 MAKE_SCHEME_CALLBACK (Grob,fixup_refpoint,1);
728 SCM
729 Grob::fixup_refpoint (SCM smob)
730 {
731   Grob *me = unsmob_grob (smob);
732   for (int a = X_AXIS; a < NO_AXES; a ++)
733     {
734       Axis ax = (Axis)a;
735       Grob * parent = me->parent_l (ax);
736
737       if (!parent)
738         continue;
739       
740       if (parent->line_l () != me->line_l () && me->line_l ())
741         {
742           Grob * newparent = parent->find_broken_piece (me->line_l ());
743           me->set_parent (newparent, ax);
744         }
745
746       if (Item * i  = dynamic_cast<Item*> (me))
747         {
748           Item *parenti = dynamic_cast<Item*> (parent);
749
750           if (parenti && i)
751             {
752               Direction  my_dir = i->break_status_dir () ;
753               if (my_dir!= parenti->break_status_dir ())
754                 {
755                   Item *newparent =  parenti->find_prebroken_piece (my_dir);
756                   me->set_parent (newparent, ax);
757                 }
758             }
759         }
760     }
761   return smob;
762 }
763
764
765
766 /****************************************************
767   SMOB funcs
768  ****************************************************/
769
770
771
772 IMPLEMENT_SMOBS (Grob);
773 IMPLEMENT_DEFAULT_EQUAL_P (Grob);
774
775 SCM
776 Grob::mark_smob (SCM ses)
777 {
778   Grob * s = (Grob*) SCM_CELL_WORD_1 (ses);
779   scm_gc_mark (s->immutable_property_alist_);
780   scm_gc_mark (s->mutable_property_alist_);
781
782   for (int a =0 ; a < 2; a++)
783     {
784       scm_gc_mark (s->dim_cache_[a].offset_callbacks_);
785       scm_gc_mark (s->dim_cache_[a].dimension_);
786     }
787   
788   if (s->parent_l (Y_AXIS))
789     scm_gc_mark (s->parent_l (Y_AXIS)->self_scm ());
790   if (s->parent_l (X_AXIS))
791     scm_gc_mark (s->parent_l (X_AXIS)->self_scm ());
792
793   if (s->original_l_)
794     scm_gc_mark (s->original_l_->self_scm ());
795   return s->do_derived_mark ();
796 }
797
798 int
799 Grob::print_smob (SCM s, SCM port, scm_print_state *)
800 {
801   Grob *sc = (Grob *) ly_cdr (s);
802      
803   scm_puts ("#<Grob ", port);
804   scm_puts ((char *)sc->name ().ch_C (), port);
805
806   /*
807     don't try to print properties, that is too much hassle.
808    */
809   scm_puts (" >", port);
810   return 1;
811 }
812
813 SCM
814 Grob::do_derived_mark ()
815 {
816   return SCM_EOL;
817 }
818
819
820 SCM
821 ly_set_grob_property (SCM elt, SCM sym, SCM val)
822 {
823   Grob * sc = unsmob_grob (elt);
824
825   if (!gh_symbol_p (sym))
826     {
827       error ("Not a symbol");
828       ly_display_scm (sym);
829       return SCM_UNSPECIFIED;
830     }
831
832   if (sc)
833     {
834       sc->set_grob_property (sym, val);
835     }
836   else
837     {
838       error ("Not a score element");
839       ly_display_scm (elt);
840     }
841
842   return SCM_UNSPECIFIED;
843 }
844
845
846 SCM
847 ly_get_grob_property (SCM elt, SCM sym)
848 {
849   Grob * sc = unsmob_grob (elt);
850   
851   if (sc)
852     {
853       return sc->get_grob_property (sym);
854     }
855   else
856     {
857       error ("Not a score element");
858       ly_display_scm (elt);
859     }
860   return SCM_UNSPECIFIED;
861 }
862
863
864 void
865 Grob::discretionary_processing ()
866 {
867 }
868
869
870
871 SCM
872 spanner_get_bound (SCM slur, SCM dir)
873 {
874   return dynamic_cast<Spanner*> (unsmob_grob (slur))->get_bound (to_dir (dir))->self_scm ();
875 }
876
877
878
879 static SCM interfaces_sym;
880 static void
881 init_functions ()
882 {
883   interfaces_sym = scm_permanent_object (ly_symbol2scm ("interfaces"));
884
885   scm_c_define_gsubr ("ly-get-grob-property", 2, 0, 0,
886                       (Scheme_function_unknown)ly_get_grob_property);
887   scm_c_define_gsubr ("ly-set-grob-property", 3, 0, 0,
888                       (Scheme_function_unknown)ly_set_grob_property);
889   scm_c_define_gsubr ("ly-get-spanner-bound", 2 , 0, 0,
890                       (Scheme_function_unknown) spanner_get_bound);
891 }
892
893 bool
894 Grob::has_interface (SCM k)
895 {
896   SCM ifs = get_grob_property (interfaces_sym);
897
898   return scm_memq (k, ifs) != SCM_BOOL_F;
899 }
900
901 void
902 Grob::set_interface (SCM k)
903 {
904   if (has_interface (k))
905     return ;
906   else
907     {
908       set_grob_property (interfaces_sym,
909                         gh_cons (k, get_grob_property (interfaces_sym)));
910     }
911 }
912
913
914 ADD_SCM_INIT_FUNC (scoreelt, init_functions);
915 IMPLEMENT_TYPE_P (Grob, "ly-grob?");