lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

zig-zag patch


From: Rune Zedeler
Subject: zig-zag patch
Date: Tue, 15 Oct 2002 02:21:00 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529

Inspired by the recent discussion on user.
Todo:
- Better calculation of boundingbox
- pdf-output (HELP!)

-Rune
Index: ChangeLog
===================================================================
RCS file: /cvsroot/lilypond/lilypond/ChangeLog,v
retrieving revision 1.557
diff -p -u -r1.557 ChangeLog
--- ChangeLog   14 Oct 2002 14:32:45 -0000      1.557
+++ ChangeLog   15 Oct 2002 00:17:00 -0000
@@ -1,3 +1,18 @@
+2002-10-15  Rune Zedeler  <address@hidden>
+
+       * scm/tex.scm (zigzig-line): added.
+
+       * scm/ps.scm (zigzag-line): added.
+
+       * ps/music-drawing-routines.ps (subvec): added.
+                                      (draw_zigzag_line): added.
+       
+       * lily/line-spanner.cc: Add support for #'type = #'zigzag. reading
+       grob properties zigzag-width and zigzag-length.
+
+       * input/regression/glissando.ly: Add some zig-zagged glissandi.
+
+       
 2002-10-14  Rune Zedeler  <address@hidden>
 
        * lily/rest.cc (after_line_breaking): bugfix: dots after half
Index: input/regression/glissando.ly
===================================================================
RCS file: /cvsroot/lilypond/lilypond/input/regression/glissando.ly,v
retrieving revision 1.4
diff -p -u -r1.4 glissando.ly
--- input/regression/glissando.ly       16 Jul 2002 23:57:06 -0000      1.4
+++ input/regression/glissando.ly       15 Oct 2002 00:17:01 -0000
@@ -16,13 +16,14 @@ The engraver does no time-keeping, so it
                     % gliss non gliss and 
             c4 \glissando d e \glissando f \glissando \break
             % consecutive 
-            c \glissando d \glissando e
+            c \glissando d, \glissando e'
              < { \stemUp e8 \glissando g8 }
                \context Voice = VB {\stemDown \repeat unfold 4 d16 } >
-            
+               \property Voice.Glissando \override #'type = #'zigzag
+               c4 \glissando c,, \glissando c' \glissando d
     }
     \paper{
-        linewidth = 70.\mm
+        linewidth = 50.\mm indent = 0
        \translator{
               \StaffContext
               % makes for handier debugging
Index: lily/line-spanner.cc
===================================================================
RCS file: /cvsroot/lilypond/lilypond/lily/line-spanner.cc,v
retrieving revision 1.13
diff -p -u -r1.13 line-spanner.cc
--- lily/line-spanner.cc        26 Jul 2002 00:23:28 -0000      1.13
+++ lily/line-spanner.cc        15 Oct 2002 00:17:01 -0000
@@ -61,6 +61,30 @@ line_atom (Grob* me, Real thick, Real dx
   return list;
 }
 
+static SCM
+zigzag_atom (Grob* me, Real thick, Real dx, Real dy)
+{
+  Real staff_space = Staff_symbol_referencer::staff_space (me);
+  SCM ws = me->get_grob_property ("zigzag-width");
+  SCM ls = me->get_grob_property ("zigzag-length");
+  double w = (gh_number_p(ws) ? gh_scm2double(ws) : 1)*staff_space;
+  double l = (gh_number_p(ls) ? gh_scm2double(ls) : 1);
+  double h = l>w/2 ? sqrt(l*l-w*w/4) : 0;
+  
+  SCM list = scm_list_n (ly_symbol2scm ("zigzag-line"),
+                     gh_bool2scm (true),
+                     gh_double2scm (w),
+                     gh_double2scm (h),
+                     gh_double2scm (thick),
+                     gh_double2scm (dx),
+                     gh_double2scm (dy),
+                     SCM_UNDEFINED);
+
+  return list;
+}
+
+
+
 Molecule
 Line_spanner::line_molecule (Grob* me, Real thick, Real dx, Real dy)
 {
@@ -77,6 +101,15 @@ Line_spanner::line_molecule (Grob* me, R
       mol = Molecule (b, line_atom (me, thick, dx, dy));
     }
   else if (gh_symbol_p (type)
+          && type == ly_symbol2scm ("zigzag"))
+    {
+      // TODO:
+      Box b (Interval (-0.5* thick +  (0 <? dx) ,0.5* thick+ (0 >? dx)),
+            Interval (- 0.5* thick + (0<? dy), 0.5*thick + (0 >? dy)));
+      mol = Molecule (b, zigzag_atom (me, thick, dx, dy));
+
+    }
+  else if (gh_symbol_p (type)
           && type == ly_symbol2scm ("trill"))
     {
       SCM alist_chain = Font_interface::font_alist_chain (me);
@@ -263,6 +296,6 @@ Line_spanner::brew_molecule (SCM smob) 
 ADD_INTERFACE (Line_spanner, "line-spanner-interface",
   "Generic line drawn between two objects, eg. for use with glissandi.
 gap is measured in staff-spaces.   ",
-  "gap dash-period dash-length thickness type");
+  "gap dash-period dash-length zigzag-width zigzag-length thickness type");
 
 
Index: ps/music-drawing-routines.ps
===================================================================
RCS file: /cvsroot/lilypond/lilypond/ps/music-drawing-routines.ps,v
retrieving revision 1.10
diff -p -u -r1.10 music-drawing-routines.ps
--- ps/music-drawing-routines.ps        21 Jul 2002 02:30:19 -0000      1.10
+++ ps/music-drawing-routines.ps        15 Oct 2002 00:17:01 -0000
@@ -224,6 +224,50 @@
 } bind def 
 
 
+% a b c d subvec  ==  a-c b-d
+/subvec {
+  3 2 roll exch sub
+  3 1 roll
+  sub exch
+} bind def
+
+
+% centre? zzwidth zzheight thickness x0 y0 x1 y1
+/draw_zigzag_line {
+  newpath
+  6 dict begin
+ 
+  4 2 roll % zzuw zzh th x1 y1 x0 y0
+  2 copy
+  moveto
+  subvec % zzuw zzh th dx dy
+
+  2 copy euclidean_length /l exch def
+  l div /uy exch def
+  l div /ux exch def
+  setlinewidth
+  /zzh exch def
+  l exch div round /n exch def
+  n 0 gt { %if
+      /zzw l n 2 mul div def
+      {
+         uy zzh mul 2 div ux zzh mul -2 div rmoveto
+      } if
+      1 1 n {
+         ux zzw mul uy zzh mul sub
+         uy zzw mul ux zzh mul add
+         rlineto
+         ux zzw mul uy zzh mul add
+         uy zzw mul ux zzh mul sub
+         rlineto
+      } bind for
+  }{ %else
+      pop
+      ux l mul uy l mul rlineto
+  } ifelse
+  stroke
+ end
+} bind def
 
 /bracket_traject 
 { 
Index: scm/grob-description.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/grob-description.scm,v
retrieving revision 1.141
diff -p -u -r1.141 grob-description.scm
--- scm/grob-description.scm    13 Oct 2002 21:58:05 -0000      1.141
+++ scm/grob-description.scm    15 Oct 2002 00:17:01 -0000
@@ -581,6 +581,7 @@
      . (
        (type . line)
        (gap . 0.5)
+       (zigzag-width . 0.75)
        (breakable . #t)
        (X-extent-callback . #f)
        (Y-extent-callback . #f)                         
Index: scm/grob-property-description.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/grob-property-description.scm,v
retrieving revision 1.122
diff -p -u -r1.122 grob-property-description.scm
--- scm/grob-property-description.scm   13 Oct 2002 21:58:05 -0000      1.122
+++ scm/grob-property-description.scm   15 Oct 2002 00:17:01 -0000
@@ -510,9 +510,9 @@ Like @code{bracket-visibility}, but for 
 (grob-property-description 'tie ly:grob? "") 
 (grob-property-description 'type symbol? " 
 
-one of: line, dashed-line, trill or dotted-line.
+one of: line, dashed-line, trill, dotted-line or zigzag.
 
-[FIXME: type is too generic for this doc, move doco to intefrace] 
+[FIXME: type is too generic for this doc, move doco to interface] 
 ")
 
 (grob-property-description 'break-visibility procedure? "a function that takes 
the break direction and returns a  cons of booleans containing (TRANSPARENT . 
EMPTY).
@@ -543,7 +543,14 @@ no extent.
 (grob-property-description 'width-correct number? "width correction for 
(de)cresc. text spanners.")
 (grob-property-description 'x-gap number? "horizontal gap between notehead and 
tie.")
 (grob-property-description 'y-free number? "minimal vertical gap between slur 
and noteheads or stems.")
-(grob-property-description 'y-offset number? "extra vertical offset for ties 
away from the center line.")
+(grob-property-description 'y-offset number? "extra vertical offset
+for ties away from the center line.")
+(grob-property-description 'zigzag-length number? "The length of the
+lines of a zigzag - relative to zigzag-width. a value of 1
+gives 60-degree zigzags.")
+(grob-property-description 'zigzag-width number? "the width of one
+zigzag-squiggle, measured in staff space. The width will be adjusted
+so that the line can be constructed from a whole number of squiggles.")
 
 
 ;;; INTERNAL
Index: scm/ps.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/ps.scm,v
retrieving revision 1.37
diff -p -u -r1.37 ps.scm
--- scm/ps.scm  13 Oct 2002 21:58:05 -0000      1.37
+++ scm/ps.scm  15 Oct 2002 00:17:01 -0000
@@ -147,6 +147,21 @@
    (ly:number->string off)
    " ] 0 draw_dashed_line"))
 
+(define (zigzag-line centre? zzw zzh thick dx dy)
+  (string-append
+    (if centre? "true" "false")
+    " "
+    (ly:number->string zzw)
+    " "
+    (ly:number->string zzh)
+    " "
+    (ly:number->string thick)
+    " 0 0 "
+    (ly:number->string dx)
+    " "
+    (ly:number->string dy)
+    " draw_zigzag_line "))
+
 (define (draw-line thick x1 y1 x2 y2)
 
   (string-append 
Index: scm/tex.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/tex.scm,v
retrieving revision 1.34
diff -p -u -r1.34 tex.scm
--- scm/tex.scm 13 Oct 2002 21:58:05 -0000      1.34
+++ scm/tex.scm 15 Oct 2002 00:17:01 -0000
@@ -96,6 +96,9 @@
 (define (dashed-line thick on off dx dy)
   (embedded-ps (list 'dashed-line  thick on off dx dy)))
 
+(define (zigzag-line centre? zzw zzh thick dx dy)
+  (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
+
 (define (font-load-command name-mag command)
   (string-append
    "\\font\\" command "="

reply via email to

[Prev in Thread] Current Thread [Next in Thread]