2004-08-24 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * input/regression/slur-script-inside.ly: new file.
+
+ * lily/new-slur.cc (outside_slur_callback): new function, to make
+ scripts avoid slurs
+
+ * lily/slur-engraver.cc (finalize):
+
+ * lily/script-interface.cc: add inside-slur property.
+
+ * lily/slur-engraver.cc (finalize): read inside-slur property.
+
* scm/lily.scm (postscript->png): use ~a iso. ~s
* ly/property-init.ly (unHideNotes): hide accidentals at staff
--- /dev/null
+\header {
+
+ texidoc = "Slurs avoid scripts with @code{inside-slur} set
+ true, while scripts avoid slurs if @code{inside-slur} set to
+ false."
+
+}
+
+
+\version "2.3.12"
+
+\paper { raggedright = ##t }
+
+\relative c''{
+ \clef alto
+ \slurUp
+ \override Script #'inside-slur = ##t
+ c4(^\downbow b)
+ \override Script #'inside-slur = ##f
+ c4(^\downbow b)
+ c4^\downbow b
+}
if (ly_c_string_p (script))
{
Item *p = make_item ("Script", ev->self_scm ());
- SCM desc = SCM_EOL;
- make_script_from_event (p, &desc,
+ bool follow;
+ make_script_from_event (p, &follow,
context (), script,
0);
DECLARE_SCHEME_CALLBACK (print, (SCM));
DECLARE_SCHEME_CALLBACK (after_line_breaking, (SCM));
DECLARE_SCHEME_CALLBACK (height, (SCM,SCM));
-
+ DECLARE_SCHEME_CALLBACK (outside_slur_callback, (SCM,SCM));
static bool has_interface (Grob *);
static Bezier get_curve (Grob*me);
};
DECLARE_SCHEME_CALLBACK (before_line_breaking, (SCM));
};
-void make_script_from_event (Grob *p, SCM *descr, Context *tg,
+void make_script_from_event (Grob *p, bool *follow, Context *tg,
SCM type, int index);
#endif /* SCRIPT_INTERFACE_HH */
Grob *script_;
Music *note_event_;
Music *finger_event_;
- SCM description_;
+ bool follow_into_staff_;
int position_;
Finger_tuple ()
position_ = 0;
head_ = script_ = 0;
note_event_ = finger_event_ = 0;
- description_ = SCM_EOL;
+ follow_into_staff_ = false;
}
static int compare (Finger_tuple const & c1, Finger_tuple const & c2)
{
Finger_tuple ft ;
Grob * g= make_item ("Script", event->self_scm () );
- make_script_from_event (g, &ft.description_, context (),
+ make_script_from_event (g, &ft.follow_into_staff_, context (),
event->get_property ("articulation-type"), 0);
if (g)
{
if (stem_ && to_dir (sc->get_property ("side-relative-direction")))
sc->set_property ("direction-source", stem_->self_scm ());
- SCM follow = scm_assoc (ly_symbol2scm ("follow-into-staff"), articulations_[i].description_);
- if (ly_c_pair_p (follow) && to_boolean (ly_cdr (follow)))
+ if (articulations_[i].follow_into_staff_)
{
sc->add_offset_callback (Side_position_interface::quantised_position_proc, Y_AXIS);
sc->set_property ("staff-padding" , SCM_EOL);
ADD_INTERFACE (New_slur, "new-slur-interface",
"A slur",
"encompass-objects control-points dashed details direction height-limit note-columns ratio thickness");
+
+
+
+MAKE_SCHEME_CALLBACK (New_slur, outside_slur_callback, 2);
+SCM
+New_slur::outside_slur_callback (SCM grob, SCM axis)
+{
+ Grob *script = unsmob_grob (grob);
+ Axis a = Axis (ly_scm2int (axis));
+ assert (a == Y_AXIS);
+
+ Grob *slur = unsmob_grob (script->get_property ("slur"));
+
+ if (!slur)
+ return scm_from_int (0);
+
+ Grob *cx = script->common_refpoint (slur, X_AXIS);
+ Grob *cy = script->common_refpoint (slur, Y_AXIS);
+
+ Bezier curve = New_slur::get_curve (slur);
+
+ curve.translate (Offset (slur->relative_coordinate (cx, X_AXIS),
+ slur->relative_coordinate (cy, Y_AXIS)));
+
+ Interval yext = robust_relative_extent (script, cy, Y_AXIS);
+ Interval xext = robust_relative_extent (script, cx, X_AXIS);
+
+
+ Real slur_padding = 0.2; // todo: slur property, script property?
+ yext.widen (slur_padding);
+
+ Interval bezext (curve.control_[0][X_AXIS],
+ curve.control_[3][X_AXIS]);
+
+ Real x = xext.center ();
+ if (!bezext.contains (xext[RIGHT]))
+ x = xext[LEFT];
+ else if (!bezext.contains (xext[LEFT]))
+ x = xext[RIGHT];
+
+
+ if (!bezext.contains (x))
+ return scm_make_real (0);
+
+ Real y = curve.get_other_coordinate (X_AXIS, x);
+ if (yext.contains (y))
+ {
+ Direction dir = get_grob_direction (script);
+ return scm_make_real (y - yext[-dir] + dir * slur_padding);
+ }
+ return scm_make_real (0.0);
+}
{
Music *event_;
Grob *script_;
- SCM description_;
+ bool follow_into_staff_;
Script_tuple ()
{
+ follow_into_staff_ = false;
event_ = 0;
script_ = 0;
- description_ = SCM_EOL;
}
};
}
}
-/* Add the properties, one by one for each Script. A little space
- (memory? --jcn) could be saved by tacking the props onto the Script
- grob (i.e. make ScriptStaccato , ScriptMarcato, etc. ). */
-void make_script_from_event (Grob *p, SCM *descr, Context *tg,
+/* Add the properties, one by one for each Script. A little memory
+ could be saved by tacking the props onto the Script grob (i.e. make
+ ScriptStaccato , ScriptMarcato, etc. ).
+
+*/
+void make_script_from_event (Grob *p, bool * follow, Context *tg,
SCM art_type, int index)
{
SCM alist = tg->get_property ("scriptDefinitions");
}
art = ly_cdr (art);
- *descr = art;
- copy_property (p, ly_symbol2scm ("script-stencil"), art);
- copy_property (p, ly_symbol2scm ("direction"), art);
- copy_property (p, ly_symbol2scm ("side-relative-direction"), art);
+ SCM follow_scm = scm_assoc (ly_symbol2scm ("follow-into-staff"),
+ art);
- int prio = 0;
- SCM sprio = scm_assoc (ly_symbol2scm ("script-priority"), art);
- if (ly_c_pair_p (sprio))
- prio = ly_scm2int (ly_cdr (sprio));
+ *follow = ly_c_pair_p (follow_scm) && to_boolean (ly_cdr (follow_scm));
+ bool priority_found = false ;
+
+ for (SCM s = art ; ly_c_pair_p (s); s = ly_cdr (s))
+ {
+ SCM sym = ly_caar (s);
+ SCM val = ly_cdar (s);
- /* Make sure they're in order of user input by adding index i.
- Don't use the direction in this priority. Smaller means closer
- to the head. */
- prio += index;
+ if (sym == ly_symbol2scm ("script-priority"))
+ {
+ priority_found = true;
+ /* Make sure they're in order of user input by adding index i.
+ Don't use the direction in this priority. Smaller means closer
+ to the head. */
+ int prio = ly_scm2int (val) + index;
+
+
+ val = scm_int2num (prio);
+ }
+ if (p->internal_get_property (sym) == SCM_EOL)
+ p->internal_set_property (sym, val);
+ }
+ if (!priority_found)
+ {
+ p->set_property ("script-priority",
+ scm_int2num (index));
+ }
+
Side_position_interface::set_axis (p, Y_AXIS);
- p->set_property ("script-priority", scm_int2num (prio));
+
}
void
Grob *p = make_item ("Script", m->self_scm ());
- make_script_from_event (p, &scripts_[i].description_, context (),
+ make_script_from_event (p, &scripts_[i].follow_into_staff_, context (),
m->get_property ("articulation-type"),
i);
{
int script_count = scripts_.size ();
for (int i = 0; i < script_count; i++)
- if (Grob *sc = scripts_[i].script_)
+ if (scripts_[i].follow_into_staff_)
{
- SCM follow = scm_assoc (ly_symbol2scm ("follow-into-staff"),
- scripts_[i].description_);
- if (ly_c_pair_p (follow) && to_boolean (ly_cdr (follow)))
- {
- sc->add_offset_callback (Side_position_interface
- ::quantised_position_proc, Y_AXIS);
- sc->set_property ("staff-padding", SCM_EOL);
- }
+ Grob *sc = scripts_[i].script_;
+ sc->add_offset_callback (Side_position_interface
+ ::quantised_position_proc, Y_AXIS);
+ sc->set_property ("staff-padding", SCM_EOL);
}
+
scripts_.clear ();
}
Grob *common = me->common_refpoint (st, Y_AXIS);
Interval staff_size = st->extent (common, Y_AXIS);
- Interval me_ext = me->extent (common, a);
Real diff = d*staff_size[d] + padding - d*(o + iv[-d]);
o += (d* (diff >? 0));
}
me->add_offset_callback (Side_position_interface::aligned_side_proc, a);
}
-
-
// ugh. doesn't catch all variants.
Axis
Side_position_interface::get_axis (Grob*me)
#include "directional-element-interface.hh"
#include "engraver.hh"
#include "spanner.hh"
+#include "tie.hh"
/*
It is possible that a slur starts and ends on the same note. At
}
else
{
+ SCM inside = e->get_property ("inside-slur");
if (Tie::has_interface (e)
- || to_boolean (e->get_property ("inside-slur")))
+ || to_boolean (inside))
{
for (int i = slurs_.size (); i--; )
New_slur::add_extra_encompass (slurs_[i], e);
for (int i = end_slurs_.size (); i--; )
New_slur::add_extra_encompass (end_slurs_[i], e);
}
+ else if (inside == SCM_BOOL_F)
+ {
+ Grob *slur = slurs_.size()?slurs_[0] : 0;
+ slur = (end_slurs_.size () && !slur)
+ ? end_slurs_[0] : slur;
+
+ if (slur)
+ {
+ e->add_offset_callback (New_slur::outside_slur_callback_proc, Y_AXIS);
+ e->set_property ("slur", slur->self_scm());
+ }
+ }
}
}
+
void
Slur_engraver::finalize ()
{
(set! default-script-alist
(append
'(("thumb" .
- (
- (script-stencil . (feta . ("thumb" . "thumb")))
+ ((script-stencil . (feta . ("thumb" . "thumb")))
(direction . 1)))
("accent" .
- (
+ ((inside-slur . #t)
+ (follow-into-staff . #t)
(script-stencil . (feta . ("sforzato" . "sforzato")))
- (side-relative-direction . -1))
- )
+ (side-relative-direction . -1)))
("marcato" .
- (
- (script-stencil . (feta . ("dmarcato" . "umarcato")))
+ ((script-stencil . (feta . ("dmarcato" . "umarcato")))
(follow-into-staff . #t)
(side-relative-direction . -1)))
("staccatissimo" .
- (
+ ((inside-slur . #t)
(script-stencil . (feta . ("dstaccatissimo" . "ustaccatissimo")))
(side-relative-direction . -1)))
((script-stencil . (feta . ("staccato" . "staccato")))
(side-relative-direction . -1)
(follow-into-staff . #t)
+ (inside-slur . #t)
(priority . -100)))
("tenuto" .
((script-stencil . (feta . ("tenuto" . "tenuto")))
(direction . 1)))
("upbow" .
((script-stencil . (feta . ("upbow" . "upbow")))
+ (inside-slur . #f)
(direction . 1) ))
("downbow" .
((script-stencil . (feta . ("downbow" . "downbow")))
- (direction . 1) ))
+ (inside-slur . #f)
+ (direction . 1)))
("lheel" .
((script-stencil . (feta . ("upedalheel" . "upedalheel")))
(direction . -1))