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