From 17b4f74490ec818dc1ad31ede775fb3d4bfd3c1b Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer Date: Tue, 17 Jun 2008 23:25:37 +0200 Subject: [PATCH 1/1] Feature: Implement straight flags, add grace slash for straight flags -) Added glyphs flags.straight[ud][3456], so that a simple \override Stem #'flag-style = #'straight switches lilypond to use straight (uncurved) flags in Stockhausen or Boulez style (angle ~18-22 degrees) -) Added glyphs flags.straight[ud]grace, because the default grace slash looks terrible with straight flags -) Modified the Stem grob to use flag-style-dependent graces. In particular, the slash glyph will be flags.(flag-style)[ud](slash-style), e.g. flags.straightugrace. If no such flag-style-dependent grace glyph exists, I fall back to the usual flag.[ud](slash-style), e.g. flag.ugrace. -) Added regtest for these features Thanks to Werner Lemberg, who fixed my unsuccessful attempts to create the glyphs using metafont! --- input/regression/straight-flags.ly | 31 ++++++ lily/stem.cc | 7 +- mf/feta-banier.mf | 209 ++++++++++++++++++++++++++++++++++++ mf/feta-macros.mf | 21 ++++ mf/parmesan-macros.mf | 21 ---- 5 files changed, 267 insertions(+), 22 deletions(-) create mode 100644 input/regression/straight-flags.ly diff --git a/input/regression/straight-flags.ly b/input/regression/straight-flags.ly new file mode 100644 index 0000000..eb6366e --- /dev/null +++ b/input/regression/straight-flags.ly @@ -0,0 +1,31 @@ +\version "2.11.53" + +% test notes, which will be shown in different style: +testnotes = { + \autoBeamOff + \stemUp + c'8 d'8 e'8 f'8 + c'16 d'16 e'16 f'16 + c'32 d'32 e'32 f'32 + c'64 d'64 e'64 f'64 + \acciaccatura {c'8 c'16 c'32 } f'16 | + + \stemDown + c''8 d''8 e''8 f''8 + c''16 d''16 e''16 f''16 + c''32 d''32 e''32 f''32 + c''64 d''64 e''64 f''64 + \acciaccatura {\stemDown c''8 c''16 c''32 } b'16\bar"|." +} + + +{ + \override Stem #'flag-style = #'straight + \testnotes + + \revert Stem #'flag-style + \testnotes + + \override Stem #'flag-style = #'mensural + \testnotes +} \ No newline at end of file diff --git a/lily/stem.cc b/lily/stem.cc index b517b6e..a9d9521 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -632,8 +632,13 @@ Stem::flag (Grob *me) string stroke_style = ly_scm2string (stroke_style_scm); if (!stroke_style.empty ()) { - string font_char = to_string (dir) + stroke_style; + string font_char = flag_style + to_string (dir) + stroke_style; Stencil stroke = fm->find_by_name ("flags." + font_char); + if (stroke.is_empty ()) + { + font_char = to_string (dir) + stroke_style; + stroke = fm->find_by_name ("flags." + font_char); + } if (stroke.is_empty ()) me->warning (_f ("flag stroke `%s' not found", font_char)); else diff --git a/mf/feta-banier.mf b/mf/feta-banier.mf index e3d5637..59e868f 100644 --- a/mf/feta-banier.mf +++ b/mf/feta-banier.mf @@ -468,4 +468,213 @@ fet_beginchar ("64th (down)", "d6"); y_mirror_char; fet_endchar; + + + + + + +%%%%%%%% +% +% Straight flags (old, but not ancient, style) +% + +save straight_flag_angle, straight_upflag_length; +save straight_downflag_length, straight_flag_thickness; + +straight_upflag_angle = -18; +straight_downflag_angle = 22; +straight_upflag_length# = .95 black_notehead_width# + stemthickness# / 2; +straight_downflag_length# = 1.0 black_notehead_width# + stemthickness# / 2; +straight_flag_thickness# = 0.55 staff_space#; + +define_pixels (straight_upflag_length, straight_downflag_length); +define_pixels (straight_flag_thickness); + +save straight_flag_path; +path straight_flag_path; + +def draw_straight_flag (expr center, len, angle, thickness) = + clearxy; + + save ellipse, T; + path ellipse; + transform T; + + T := identity xscaled blot_diameter + yscaled thickness; + pickup pencircle transformed T; + ellipse := reverse fullcircle transformed T; + + z1 = center; + z2 = z1 + len * dir (angle); + + fill top z1 + -- get_subpath (ellipse, z2 - z1, z1 - z2, z2) + -- bot z1 + -- cycle; +enddef; + + +def create_straight_flag_char (expr flag_count, len, lenhash, angle) = +begingroup + save flagspace, depth, width; + flagspace# = 0.9 staff_space#; + define_pixels (flagspace); + + (width#, depth#) = lenhash * dir (-angle) + + (blot_diameter# / 2, straight_flag_thickness#) + + (0, flagspace# * (flag_count - 1)); + + set_char_box (0, width#, depth#, stemthickness# / 2); +% set_char_box (0, width#, depth#, stemthickness# / 2); +% set_char_box (0, width#, depth#, 0); + + for n = 1 upto flag_count: + draw_straight_flag ((0, -flagspace * (n - 1) + - straight_flag_thickness / 2), + len, + angle, + straight_flag_thickness); + endfor + +% draw_square_block ((-0.5 stemthickness_rounded, +% -flag_count * flagspace), (0, 0)); +endgroup +enddef; + + +fet_beginchar ("straight 8th Flag (up)", "straightu3"); + create_straight_flag_char (1, straight_upflag_length, + straight_upflag_length#, straight_upflag_angle); +fet_endchar; + + +fet_beginchar ("straight 16th Flag (up)", "straightu4"); + create_straight_flag_char (2, straight_upflag_length, + straight_upflag_length#, straight_upflag_angle); +fet_endchar; + + +fet_beginchar ("straight 32nd Flag (up)", "straightu5"); + create_straight_flag_char (3, straight_upflag_length, + straight_upflag_length#, straight_upflag_angle); +fet_endchar; + + +fet_beginchar ("straight 64th Flag (up)", "straightu6"); + create_straight_flag_char (4, straight_upflag_length, + straight_upflag_length#, straight_upflag_angle); +fet_endchar; + + +fet_beginchar ("straight 8th (down)", "straightd3"); + create_straight_flag_char (1, straight_downflag_length, + straight_downflag_length#, -straight_downflag_angle); + y_mirror_char; +fet_endchar; + + +fet_beginchar ("straight 16th (down)", "straightd4"); + create_straight_flag_char (2, straight_downflag_length, + straight_downflag_length#, -straight_downflag_angle); + y_mirror_char; +fet_endchar; + + +fet_beginchar ("straight 32nd (down)", "straightd5"); + create_straight_flag_char (3, straight_downflag_length, + straight_downflag_length#, -straight_downflag_angle); + y_mirror_char; +fet_endchar; + + +fet_beginchar ("straight 64th (down)", "straightd6"); + create_straight_flag_char (4, straight_downflag_length, + straight_downflag_length#, -straight_downflag_angle); + y_mirror_char; +fet_endchar; + +%%%%%%%% +% +% Single Stroke for Short Appogiatura +% + +fet_beginchar ("straight grace dash (up)", "straightugrace"); + save width_ratio, pre_depth_ratio, width, depth, tmpd; + + pre_depth_ratio = .4 ; + width_ratio = 0.85 ; + + (width#, tmpd#) = straight_downflag_length# * dir (straight_downflag_angle) + + (blot_diameter# / 2, straight_flag_thickness#); + + + depth# = 2 staff_space#; + + define_pixels (width, depth); + + set_char_box (width# * pre_depth_ratio + blot_diameter# / 2, width# * width_ratio + blot_diameter# / 2, + depth# + blot_diameter# / 2, blot_diameter# / 2) + + pickup pencircle scaled 1.5 stemthickness; + + z1 = (-b, -d); + z2 = (w, h); + + penpos1 (1.5 stemthickness, angle (z2 - z1) - 90); + penpos2 (1.5 stemthickness, angle (z2 - z1) - 90); + + fill z1l + -- z2l + .. top z2 + .. rt z2 + .. z2r + -- z1r + .. bot z1 + .. lft z1 + .. cycle; + + penlabels (1, 2); +fet_endchar; + + +fet_beginchar ("straight grace dash (down)", "straightdgrace"); + save width_ratio, pre_depth_ratio, width, depth, tmpd; + + pre_depth_ratio = .4 ; + width_ratio = 0.85 ; + + (width#, tmpd#) = straight_downflag_length# * dir (straight_downflag_angle) + + (blot_diameter# / 2, straight_flag_thickness#); + + + depth# = 2 staff_space#; + + define_pixels (width, depth); + + set_char_box (width# * pre_depth_ratio + blot_diameter# / 2, width# * width_ratio + blot_diameter# / 2, + depth# + blot_diameter# / 2, blot_diameter# / 2) + + pickup pencircle scaled 1.5 stemthickness; + + z1 = (-b, -d); + z2 = (w, h); + + penpos1 (1.5 stemthickness, angle (z2 - z1) - 90); + penpos2 (1.5 stemthickness, angle (z2 - z1) - 90); + + fill z1l + -- z2l + .. top z2 + .. rt z2 + .. z2r + -- z1r + .. bot z1 + .. lft z1 + .. cycle; + + y_mirror_char; +fet_endchar; + fet_endgroup ("flags"); diff --git a/mf/feta-macros.mf b/mf/feta-macros.mf index 944c8cd..2323871 100644 --- a/mf/feta-macros.mf +++ b/mf/feta-macros.mf @@ -476,6 +476,27 @@ endgroup enddef; +% +% Get subpath specified by `dir_in' and `dir_out' of `curve' +% which is then shifted by `offset'. Assure that result has +% the same orientation as `curve'. +% +def get_subpath (expr curve, dir_in, dir_out, offset) = + begingroup; + save t_in, t_out; + + t_in := directiontime dir_in of curve; + t_out := directiontime dir_out of curve; + + if t_in > t_out: + t_out := t_out + length curve; + fi; + + (subpath (t_in, t_out) of curve) shifted offset + endgroup +enddef; + + pi := 3.14159; diff --git a/mf/parmesan-macros.mf b/mf/parmesan-macros.mf index 1f0b4ad..984377b 100644 --- a/mf/parmesan-macros.mf +++ b/mf/parmesan-macros.mf @@ -70,27 +70,6 @@ enddef; % -% Get subpath specified by `dir_in' and `dir_out' of `curve' -% which is then shifted by `offset'. Assure that result has -% the same orientation as `curve'. -% -def get_subpath (expr curve, dir_in, dir_out, offset) = - begingroup; - save t_in, t_out; - - t_in := directiontime dir_in of curve; - t_out := directiontime dir_out of curve; - - if t_in > t_out: - t_out := t_out + length curve; - fi; - - (subpath (t_in, t_out) of curve) shifted offset - endgroup -enddef; - - -% % Get point specified by `dir_' of `curve' which is then % shifted by `offset'. % -- 1.5.6.3