From 56ad9c71638c9b3e23f75a85a9ba96f19566d400 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 24 Aug 2004 21:34:36 +0000 Subject: [PATCH] * 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 level. Fixes: hideNotes-accidental.ly --- ChangeLog | 11 ++++ input/regression/slur-script-inside.ly | 22 ++++++++ lily/drum-note-engraver.cc | 4 +- lily/include/new-slur.hh | 2 +- lily/include/script-interface.hh | 2 +- lily/new-fingering-engraver.cc | 9 ++-- lily/new-slur.cc | 52 ++++++++++++++++++ lily/script-engraver.cc | 74 ++++++++++++++++---------- lily/side-position-interface.cc | 3 -- lily/slur-engraver.cc | 17 +++++- scm/script.scm | 19 +++---- 11 files changed, 164 insertions(+), 51 deletions(-) create mode 100644 input/regression/slur-script-inside.ly diff --git a/ChangeLog b/ChangeLog index e46d4cd189..c69eaf0847 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2004-08-24 Han-Wen Nienhuys + * 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 diff --git a/input/regression/slur-script-inside.ly b/input/regression/slur-script-inside.ly new file mode 100644 index 0000000000..93ac982fbd --- /dev/null +++ b/input/regression/slur-script-inside.ly @@ -0,0 +1,22 @@ +\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 +} diff --git a/lily/drum-note-engraver.cc b/lily/drum-note-engraver.cc index 3143bcf78c..e26cdceebf 100644 --- a/lily/drum-note-engraver.cc +++ b/lily/drum-note-engraver.cc @@ -104,8 +104,8 @@ Drum_notes_engraver::process_music () 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); diff --git a/lily/include/new-slur.hh b/lily/include/new-slur.hh index 51c837c8c4..25caa9528c 100644 --- a/lily/include/new-slur.hh +++ b/lily/include/new-slur.hh @@ -23,7 +23,7 @@ public: 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); }; diff --git a/lily/include/script-interface.hh b/lily/include/script-interface.hh index fbef77562a..c5ed329130 100644 --- a/lily/include/script-interface.hh +++ b/lily/include/script-interface.hh @@ -26,7 +26,7 @@ public: 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 */ diff --git a/lily/new-fingering-engraver.cc b/lily/new-fingering-engraver.cc index 3dbb171395..e40c970a37 100644 --- a/lily/new-fingering-engraver.cc +++ b/lily/new-fingering-engraver.cc @@ -24,7 +24,7 @@ struct Finger_tuple Grob *script_; Music *note_event_; Music *finger_event_; - SCM description_; + bool follow_into_staff_; int position_; Finger_tuple () @@ -32,7 +32,7 @@ struct 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) { @@ -114,7 +114,7 @@ New_fingering_engraver::add_script (Grob * head, 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) { @@ -300,8 +300,7 @@ New_fingering_engraver::stop_translation_timestep () 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); diff --git a/lily/new-slur.cc b/lily/new-slur.cc index 5da6a302ee..78b569053e 100644 --- a/lily/new-slur.cc +++ b/lily/new-slur.cc @@ -129,3 +129,55 @@ New_slur::add_extra_encompass (Grob*me, Grob*n) 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); +} diff --git a/lily/script-engraver.cc b/lily/script-engraver.cc index 21072b1132..0cf404e7b1 100644 --- a/lily/script-engraver.cc +++ b/lily/script-engraver.cc @@ -24,12 +24,12 @@ struct Script_tuple { Music *event_; Grob *script_; - SCM description_; + bool follow_into_staff_; Script_tuple () { + follow_into_staff_ = false; event_ = 0; script_ = 0; - description_ = SCM_EOL; } }; @@ -85,10 +85,12 @@ copy_property (Grob *g, SCM sym, SCM alist) } } -/* 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"); @@ -104,24 +106,41 @@ void make_script_from_event (Grob *p, SCM *descr, Context *tg, } 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 @@ -134,7 +153,7 @@ Script_engraver::process_music () 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); @@ -206,17 +225,14 @@ Script_engraver::stop_translation_timestep () { 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 (); } diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index 896bbb2b33..6220a609f0 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -231,7 +231,6 @@ Side_position_interface::aligned_side (SCM element_smob, SCM axis) 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)); } @@ -246,8 +245,6 @@ Side_position_interface::set_axis (Grob*me, Axis a) 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) diff --git a/lily/slur-engraver.cc b/lily/slur-engraver.cc index 2f1cc065e8..bad108894a 100644 --- a/lily/slur-engraver.cc +++ b/lily/slur-engraver.cc @@ -12,6 +12,7 @@ #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 @@ -89,16 +90,30 @@ Slur_engraver::acknowledge_grob (Grob_info info) } 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 () { diff --git a/scm/script.scm b/scm/script.scm index 0c57f21b5a..2da8149027 100644 --- a/scm/script.scm +++ b/scm/script.scm @@ -7,21 +7,19 @@ (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))) @@ -76,6 +74,7 @@ ((script-stencil . (feta . ("staccato" . "staccato"))) (side-relative-direction . -1) (follow-into-staff . #t) + (inside-slur . #t) (priority . -100))) ("tenuto" . ((script-stencil . (feta . ("tenuto" . "tenuto"))) @@ -91,10 +90,12 @@ (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)) -- 2.39.5