Fix InstrumentSwitch grob definition.
[lilypond.git] / lily / script-interface.cc
bloba8fbc49fcdb51d3b446e12eca0848b1541ea9f19
1 /*
2 script-interface.cc -- implement Script_interface
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "script-interface.hh"
11 #include "directional-element-interface.hh"
12 #include "item.hh"
13 #include "warn.hh"
14 #include "font-interface.hh"
15 #include "side-position-interface.hh"
16 #include "output-def.hh"
17 #include "lookup.hh"
18 #include "stem.hh"
19 #include "note-column.hh"
21 Stencil
22 Script_interface::get_stencil (Grob *me, Direction d)
24 SCM s = me->get_property ("script-stencil");
25 assert (scm_is_pair (s));
27 SCM key = scm_car (s);
28 if (key == ly_symbol2scm ("feta"))
30 SCM name_entry = scm_cdr (s);
31 SCM str = ((scm_is_pair (name_entry)) ? index_get_cell (name_entry, d)
32 : name_entry);
33 return Font_interface::get_default_font (me)
34 ->find_by_name ("scripts." + ly_scm2string (str));
36 else
37 assert (false);
39 return Stencil ();
42 MAKE_SCHEME_CALLBACK (Script_interface, calc_positioning_done, 1);
43 SCM
44 Script_interface::calc_positioning_done (SCM smob)
46 Grob *me = unsmob_grob (smob);
47 if (Grob *par = me->get_parent (X_AXIS))
49 Grob *stem = Note_column::get_stem (par);
50 if (stem && Stem::first_head (stem))
51 me->set_parent (Stem::first_head (stem), X_AXIS);
53 return SCM_BOOL_T;
56 MAKE_SCHEME_CALLBACK (Script_interface, calc_direction, 1);
57 SCM
58 Script_interface::calc_direction (SCM smob)
60 Grob *me = unsmob_grob (smob);
61 Direction d = Side_position_interface::get_direction (me);
63 if (!d)
65 me->programming_error ("script direction not yet known");
66 d = DOWN;
69 (void) me->get_property ("positioning-done");
70 return scm_from_int (d);
73 MAKE_SCHEME_CALLBACK (Script_interface, calc_cross_staff, 1);
74 SCM
75 Script_interface::calc_cross_staff (SCM smob)
77 Grob *me = unsmob_grob (smob);
78 Grob *stem = Note_column::get_stem (me->get_parent (X_AXIS));
80 if (stem && to_boolean (stem->get_property ("cross-staff")))
81 return SCM_BOOL_T;
83 Grob *slur = unsmob_grob (me->get_object ("slur"));
84 SCM avoid_slur = me->get_property ("avoid-slur");
85 if (slur && to_boolean (slur->get_property ("cross-staff"))
86 && (avoid_slur == ly_symbol2scm ("outside")
87 || avoid_slur == ly_symbol2scm ("around")))
88 return SCM_BOOL_T;
90 return SCM_BOOL_F;
93 MAKE_SCHEME_CALLBACK (Script_interface, print, 1);
95 SCM
96 Script_interface::print (SCM smob)
98 Grob *me = unsmob_grob (smob);
100 Direction dir = get_grob_direction (me);
102 return get_stencil (me, dir).smobbed_copy ();
105 struct Text_script
107 DECLARE_GROB_INTERFACE ();
110 ADD_INTERFACE (Text_script,
111 "An object that is put above or below a note.",
113 /* properties */
114 "add-stem-support "
115 "avoid-slur "
116 "script-priority "
117 "slur "
121 Hmm. Where should we put add-stem-support ?
123 ADD_INTERFACE (Script_interface,
124 "An object that is put above or below a note.",
126 /* properties */
127 "add-stem-support "
128 "avoid-slur "
129 "positioning-done "
130 "script-priority "
131 "script-stencil "
132 "slur "
133 "slur-padding "