2 script-engraver.cc -- engrave Scripts: Articulations.
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "directional-element-interface.hh"
11 #include "engraver.hh"
13 #include "note-column.hh"
14 #include "paper-column.hh"
15 #include "rhythmic-head.hh"
16 #include "script-interface.hh"
17 #include "side-position-interface.hh"
18 #include "staff-symbol-referencer.hh"
33 class Script_engraver : public Engraver
35 Array<Script_tuple> scripts_;
39 virtual bool try_music (Music *);
40 void stop_translation_timestep ();
41 void process_music ();
43 DECLARE_ACKNOWLEDGER (slur);
44 DECLARE_ACKNOWLEDGER (rhythmic_head);
45 DECLARE_ACKNOWLEDGER (stem);
46 DECLARE_ACKNOWLEDGER (note_column);
49 TRANSLATOR_DECLARATIONS (Script_engraver);
52 Script_engraver::Script_engraver ()
58 Script_engraver::try_music (Music *m)
60 if (m->is_mus_type ("articulation-event"))
62 /* Discard double articulations for part-combining. */
63 int script_count = scripts_.size ();
64 for (int i = 0; i < script_count; i++)
65 if (ly_is_equal (scripts_[i].event_
66 ->get_property ("articulation-type"),
67 m->get_property ("articulation-type")))
79 copy_property (Grob *g, SCM sym, SCM alist)
81 if (g->internal_get_property (sym) == SCM_EOL)
83 SCM entry = scm_assoc (sym, alist);
84 if (scm_is_pair (entry))
85 g->internal_set_property (sym, scm_cdr (entry));
89 /* Add the properties, one by one for each Script. A little memory
90 could be saved by tacking the props onto the Script grob (i.e. make
91 ScriptStaccato , ScriptMarcato, etc. ).
93 void make_script_from_event (Grob *p, Context *tg,
94 SCM art_type, int index)
96 SCM alist = tg->get_property ("scriptDefinitions");
97 SCM art = scm_assoc (art_type, alist);
99 if (art == SCM_BOOL_F)
102 warning (_ ("don't know how to interpret articulation: "));
103 warning (_ ("scheme encoding: "));
104 scm_write (art_type, scm_current_error_port ());
111 bool priority_found = false;
113 for (SCM s = art; scm_is_pair (s); s = scm_cdr (s))
115 SCM sym = scm_caar (s);
116 SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
117 if (!ly_is_procedure (type))
120 SCM val = scm_cdar (s);
122 if (sym == ly_symbol2scm ("script-priority"))
124 priority_found = true;
125 /* Make sure they're in order of user input by adding index i.
126 Don't use the direction in this priority. Smaller means closer
128 int prio = scm_to_int (val) + index;
130 val = scm_from_int (prio);
133 SCM preset = p->get_property_data (sym);
134 if (scm_call_1 (type, preset) == SCM_BOOL_F)
135 p->internal_set_property (sym, val);
140 p->set_property ("script-priority",
141 scm_from_int (index));
144 Side_position_interface::set_axis (p, Y_AXIS);
148 Script_engraver::process_music ()
150 for (int i = 0; i < scripts_.size (); i++)
152 Music *music = scripts_[i].event_;
154 Grob *p = make_item ("Script", music->self_scm ());
156 make_script_from_event (p, context (),
157 music->get_property ("articulation-type"),
160 scripts_[i].script_ = p;
162 SCM force_dir = music->get_property ("direction");
163 if (is_direction (force_dir) && to_dir (force_dir))
164 p->set_property ("direction", force_dir);
169 Script_engraver::acknowledge_stem (Grob_info info)
171 int script_count = scripts_.size ();
172 for (int i = 0; i < script_count; i++)
174 Grob *e = scripts_[i].script_;
176 if (to_dir (e->get_property ("side-relative-direction")))
177 e->set_object ("direction-source", info.grob ()->self_scm ());
179 Side_position_interface::add_support (e, info.grob ());
184 Script_engraver::acknowledge_rhythmic_head (Grob_info info)
186 if (info.music_cause ())
188 for (int i = 0; i < scripts_.size (); i++)
190 Grob *e = scripts_[i].script_;
192 if (Side_position_interface::get_axis (e) == X_AXIS
193 && !e->get_parent (Y_AXIS))
195 e->set_parent (info.grob (), Y_AXIS);
197 Side_position_interface::add_support (e, info.grob ());
203 Script_engraver::acknowledge_note_column (Grob_info info)
205 /* Make note column the parent of the script. That is not
206 correct, but due to seconds in a chord, noteheads may be
207 swapped around horizontally.
209 As the note head to put it on is not known now, postpone this
210 decision to Script_interface::calc_direction (). */
211 for (int i = 0; i < scripts_.size (); i++)
213 Grob *e = scripts_[i].script_;
215 if (!e->get_parent (X_AXIS)
216 && Side_position_interface::get_axis (e) == Y_AXIS)
217 e->set_parent (info.grob (), X_AXIS);
222 Script_engraver::acknowledge_slur (Grob_info info)
224 slur_ = info.spanner ();
228 Script_engraver::stop_translation_timestep ()
233 #include "translator.icc"
235 ADD_ACKNOWLEDGER (Script_engraver, slur);
236 ADD_ACKNOWLEDGER (Script_engraver, rhythmic_head);
237 ADD_ACKNOWLEDGER (Script_engraver, stem);
238 ADD_ACKNOWLEDGER (Script_engraver, note_column);
240 ADD_TRANSLATOR (Script_engraver,
241 /* doc */ "Handles note scripted articulations.",
242 /* create */ "Script",
243 /* accept */ "script-event articulation-event",
244 /* read */ "scriptDefinitions",