Improve handling of nested overrides using list syntax.
[lilypond/mpolesky.git] / lily / script-interface.cc
blobc3735343a5408a1cfdbee9ba87890e53ec5df50f
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "script-interface.hh"
22 #include "directional-element-interface.hh"
23 #include "item.hh"
24 #include "warn.hh"
25 #include "font-interface.hh"
26 #include "side-position-interface.hh"
27 #include "output-def.hh"
28 #include "lookup.hh"
29 #include "stem.hh"
30 #include "note-column.hh"
32 Stencil
33 Script_interface::get_stencil (Grob *me, Direction d)
35 SCM s = me->get_property ("script-stencil");
36 assert (scm_is_pair (s));
38 SCM key = scm_car (s);
39 if (key == ly_symbol2scm ("feta"))
41 SCM name_entry = scm_cdr (s);
42 SCM str = ((scm_is_pair (name_entry)) ? index_get_cell (name_entry, d)
43 : name_entry);
44 return Font_interface::get_default_font (me)
45 ->find_by_name ("scripts." + ly_scm2string (str));
47 else
48 assert (false);
50 return Stencil ();
53 MAKE_SCHEME_CALLBACK (Script_interface, calc_positioning_done, 1);
54 SCM
55 Script_interface::calc_positioning_done (SCM smob)
57 Grob *me = unsmob_grob (smob);
58 if (Grob *par = me->get_parent (X_AXIS))
60 Grob *stem = Note_column::get_stem (par);
61 if (stem && Stem::first_head (stem))
62 me->set_parent (Stem::first_head (stem), X_AXIS);
64 return SCM_BOOL_T;
67 Direction
68 Script_interface::get_direction (Grob *me)
70 Direction relative_dir = Direction (1);
71 SCM reldir = me->get_property ("side-relative-direction");
72 if (is_direction (reldir))
73 relative_dir = to_dir (reldir);
75 SCM other_elt = me->get_object ("direction-source");
76 Grob *e = unsmob_grob (other_elt);
77 if (e)
78 return (Direction) (relative_dir * get_grob_direction (e));
80 return CENTER;
83 MAKE_SCHEME_CALLBACK (Script_interface, calc_direction, 1);
84 SCM
85 Script_interface::calc_direction (SCM smob)
87 Grob *me = unsmob_grob (smob);
88 Direction d = Script_interface::get_direction (me);
90 if (!d)
92 me->programming_error ("script direction not yet known");
93 d = DOWN;
96 (void) me->get_property ("positioning-done");
97 return scm_from_int (d);
100 MAKE_SCHEME_CALLBACK (Script_interface, calc_cross_staff, 1);
102 Script_interface::calc_cross_staff (SCM smob)
104 Grob *me = unsmob_grob (smob);
105 Grob *stem = Note_column::get_stem (me->get_parent (X_AXIS));
107 if (stem && to_boolean (stem->get_property ("cross-staff")))
108 return SCM_BOOL_T;
110 Grob *slur = unsmob_grob (me->get_object ("slur"));
111 SCM avoid_slur = me->get_property ("avoid-slur");
112 if (slur && to_boolean (slur->get_property ("cross-staff"))
113 && (avoid_slur == ly_symbol2scm ("outside")
114 || avoid_slur == ly_symbol2scm ("around")))
115 return SCM_BOOL_T;
117 return SCM_BOOL_F;
120 MAKE_SCHEME_CALLBACK (Script_interface, print, 1);
123 Script_interface::print (SCM smob)
125 Grob *me = unsmob_grob (smob);
127 Direction dir = get_grob_direction (me);
129 return get_stencil (me, dir).smobbed_copy ();
132 struct Text_script
134 DECLARE_GROB_INTERFACE ();
137 ADD_INTERFACE (Text_script,
138 "An object that is put above or below a note.",
140 /* properties */
141 "add-stem-support "
142 "avoid-slur "
143 "script-priority "
144 "slur "
148 Hmm. Where should we put add-stem-support ?
150 ADD_INTERFACE (Script_interface,
151 "An object that is put above or below a note.",
153 /* properties */
154 "add-stem-support "
155 "avoid-slur "
156 "direction-source "
157 "positioning-done "
158 "script-priority "
159 "script-stencil "
160 "side-relative-direction "
161 "slur "
162 "slur-padding "
163 "toward-stem-shift "