/*  
 *  This file is part of abc2ps, Copyright (C) 1996,1997 Michael Methfessel
 *  See file abc2ps.c for details.
 */

#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include "abc2ps.h"

/*  subroutines to define postscript macros which draw symbols	*/

/******************************************************/
/*                                                    */	
/* This font is required as it is used to form some   */
/* of the music symbols (segno).                      */
/* J. Atchley -- 05/00  [JSA]                         */
/*                                                    */	
/******************************************************/
static char def_segno_font[] = "\n/Times-BoldItalic findfont\n"
	"dup length dict begin\n"
	"	{1 index /FID ne {def} {pop pop} ifelse} forall\n"
	"   /Encoding ISOLatin1Encoding def\n"
	"   currentdict\n"
	"end\n"
	"/Times-BoldItalic-ISO exch definefont pop\n";

/******************************************************/
/*                                                    */	
/* String tablature symbols.                          */
/* J. Atchley -- 12/10/1999  [JSA]                    */
/*                                                    */	
/******************************************************/

/* This draws the full bend up.                 [JSA] */
static char def_stringtab[] = "\n/tw_fullbend { %% usage: y1 y2 tw_fullbend\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	/* draw the curve */
	"       x jsast_delta25 sub jsast_y1 jsast_delta25 sub moveto\n"
	"		x jsast_delta75 add jsast_y1 jsast_delta25 sub "
	"       x jsast_delta75 add jsast_y1 "
	"       x jsast_delta add jsast_y1 jsast_delta75 add curveto stroke\n"
	"       grestore\n" 
	"   } bind def\n"
/* This draws the full release  .               [JSA] */
	"\n/tw_fullrelease { %% usage: y1 y2 tw_fullrelease\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	/* draw the curve */
	"       x jsast_delta25 add jsast_y1 jsast_delta25 sub moveto\n"
	"		x jsast_delta75 sub jsast_y1 jsast_delta25 sub "
	"       x jsast_delta75 sub jsast_y1 "
	"       x jsast_delta sub jsast_y1 jsast_delta75 add curveto stroke\n"
	"       grestore\n" 
	"   } bind def\n"
/* This draws the half bend.                    [JSA] */
	"\n/tw_halfbend { %% usage: y1 y2 tw_halfbend\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
	/* draw the curve */
	"       x jsast_delta25 sub jsast_y1 jsast_delta25 sub moveto\n"
	"		x jsast_delta75 add jsast_y1 jsast_delta25 sub "
	"       x jsast_delta75 add jsast_y1 "
	"       x jsast_delta add jsast_y1 jsast_delta75 add curveto stroke\n"
	/* draw the "1" numerator */
	"       x jsast_delta50 add jsast_y2 jsast_delta75 sub moveto (1) cshow\n"
	/* draw the "2" denominator */
	"       x jsast_delta add jsast_delta25 add jsast_y1 jsast_delta50 sub moveto (2) cshow\n"
	"       grestore\n" 
	"   } bind def\n"
/* This draws the half release  .               [JSA] */
	"\n/tw_halfrelease { %% usage: y1 y2 tw_halfrelease\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
	/* draw the curve */
	"       x jsast_delta25 add jsast_y1 jsast_delta25 sub moveto\n"
	"		x jsast_delta75 sub jsast_y1 jsast_delta25 sub "
	"       x jsast_delta75 sub jsast_y1 "
	"       x jsast_delta sub jsast_y1 jsast_delta75 add curveto stroke\n"
	/* draw the "2" denominator */
	"       x jsast_delta25 sub jsast_y1 moveto (2) cshow\n"
	/* draw the "1" numerator */
	"       x jsast_delta sub jsast_delta25 sub jsast_y1 moveto (1) cshow\n"
	"       grestore\n" 
	"   } bind def\n"
/* This draws the slide up to.               [JSA] */
	"\n/tw_slideupto { %% usage: y1 y2 fret tw_slideupto\n"
	"       /jsast_txt exch def\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
	/* draw the line */
	"       x jsast_delta50 sub jsast_y1 jsast_delta25 sub moveto\n"
	"       jsast_delta75 jsast_delta50 rlineto stroke\n"
	/* draw fret number */
	"       x jsast_delta25 add jsast_y2 jsast_delta75 sub moveto jsast_txt show\n"
	"       grestore\n"
	"   } bind def\n"
/* This draws the slide down to.             [JSA] */
	"\n/tw_slidedownto { %% usage: y1 y2 fret tw_slidedownto\n"
	"       /jsast_txt exch def\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       jsast_delta 0.35 mul /jsast_delta35 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
	/* draw the line */
	"       x jsast_delta50 sub jsast_y2 jsast_delta75 sub moveto\n"
	"       jsast_delta75 0 jsast_delta50 sub rlineto stroke\n"
	/* draw fret number */
	"       x jsast_delta35 add jsast_y1 jsast_delta75 sub moveto jsast_txt show\n"
	"       grestore\n"
	"   } bind def\n"
/* This draws the slide up from.             [JSA] */
	"\n/tw_slideupfrom { %% usage: y1 y2 fret tw_slideupfrom\n"
	"       /jsast_txt exch def\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.65 mul /jsast_delta65 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
	/* draw the line */
	"       x jsast_delta65 sub jsast_y1 jsast_delta50 sub moveto\n"
	"       jsast_delta75 jsast_delta50 rlineto stroke\n"
	/* draw fret number */
	"       x jsast_delta75 sub jsast_y1 jsast_delta75 sub moveto jsast_txt lshow\n"
	"       grestore\n"
	"   } bind def\n"
/* This draws the slide down from.           [JSA] */
	"\n/tw_slidedownfrom { %% usage: y1 y2 fret tw_slidedownfrom\n"
	"       /jsast_txt exch def\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.75 mul /jsast_delta75 exch def\n"
	"       jsast_delta 0.5 mul /jsast_delta50 exch def\n"
	"       jsast_delta 0.65 mul /jsast_delta65 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta25 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
	/* draw the line */
	"       x jsast_delta65 sub jsast_y2 jsast_delta75 sub moveto\n"
	"       jsast_delta75 0 jsast_delta50 sub rlineto stroke\n"
	/* draw fret number */
	"       x jsast_delta75 sub jsast_y2 jsast_delta sub moveto jsast_txt lshow\n"
	"       grestore\n"
	"   } bind def\n"
/* This draws the hammer on.                    [JSA] */
	"\n/tw_hammer { %% usage: y1 y2 tw_hammer\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
    "       x jsast_y1 moveto (H) cshow\n"
	"       grestore\n"
	"   } bind def\n"
/* This draws the pull off.                     [JSA] */
	"\n/tw_pull { %% usage: y1 y2 tw_pull\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       gsave .5 setlinewidth\n"
	"       /Helvetica jsast_delta selectfont\n"
    "       x jsast_y1 moveto (P) cshow\n"
	"       grestore\n"
	"   } bind def\n"
/* This draws the vibrato.                      [JSA] */
	"\n/tw_trill { %% usage: y1 y2 tw_trill\n"
	"       /jsast_y2 exch def\n"
	"       /jsast_y1 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.9 mul jsast_y1 add /jsast_y2 exch def\n"
	"       jsast_y2 jsast_y1 sub /jsast_delta exch def\n"
	"       jsast_delta 0.15 mul /jsast_delta10 exch def\n"
	"       jsast_delta 0.25 mul /jsast_delta20 exch def\n"
	"       gsave .5 setlinewidth\n"
	"       jsast_delta10 5 mul /jsast_t exch def x jsast_t sub jsast_y1 jsast_delta20 sub moveto\n"
	"       jsast_delta10 4 mul /jsast_t exch def x jsast_t sub jsast_y1 jsast_delta20 sub jsast_delta10 180 0 arc\n"
	"       x jsast_delta10 sub jsast_y1 jsast_delta20 sub moveto\n"
	"       jsast_delta10 2 mul /jsast_t exch def x jsast_t sub jsast_y1 jsast_delta20 sub jsast_delta10 0 180 arc\n"
	"       x jsast_delta10 sub jsast_y1 jsast_delta20 sub moveto\n"
	"       x jsast_y1 jsast_delta20 sub jsast_delta10 180 0 arc\n"
	"       jsast_delta10 3 mul x add jsast_y1 jsast_delta20 sub moveto\n"
	"       jsast_delta10 2 mul x add jsast_y1 jsast_delta20 sub jsast_delta10 0 180 arc\n"
	"       jsast_delta10 3 mul x add jsast_y1 jsast_delta20 sub moveto\n"
	"       jsast_delta10 4 mul x add jsast_y1 jsast_delta20 sub jsast_delta10 180 0 arc\n"
	"       stroke\n"
	"       grestore\n"
	"   } bind def\n";

/******************************************************/
/*                                                    */	
/* Whistle or Irish flute tablature symbols.          */
/* J. Atchley -- 10/06/1999  [JSA]                    */
/*                                                    */	
/******************************************************/

/* Each of the three means of drawing a hole (open, half, or filled) */
/* first does a relative move up from the current position.   [JSA]  */
static char def_tw_o[] = "\n/tw_o { %% usage: tw_o - draws open hole\n"
	"		jsatw_y 7 add /jsatw_y exch def\n"
	"		x 3 add jsatw_y moveto x jsatw_y 3 0 360 arc stroke\n"
	"	} bind def\n";

static char def_tw_h[] = "\n/tw_h { %% usage: tw_h - draws half-open hole\n"
	"		jsatw_y 7 add /jsatw_y exch def\n"
	"		x jsatw_y 3 add moveto x jsatw_y 3 90 270 arc fill\n"
	"		x jsatw_y -3 add moveto x jsatw_y 3 270 90 arc stroke\n"
	"	} bind def\n";

static char def_tw_f[] = "\n/tw_f { %% usage: tw_f - draws closed hole\n"
	"		jsatw_y 7 add /jsatw_y exch def\n"
	"		x 3 add jsatw_y moveto x jsatw_y 3 0 360 arc fill\n"
	"	} bind def\n";

/* This draws the "+" for the overblown second octave.[JSA]  */
static char def_tw_2[] = "\n/tw_2 { %% usage: tw_2 - draws + for second octave\n"
	"		gsave\n"
	"		x jsatw_y -3 add moveto 0 6 rlineto -3 -3 rmoveto 6 0 rlineto stroke"
	"		grestore\n"
	"	} bind def\n"
/* This draws the "++" for the overblown third octave.[JSA]  */
	"\n/tw_3 { %% usage: tw_3 - draws ++ for third octave\n"
	"		gsave\n"
	"		x -1.5 add jsatw_y -1.5 add moveto 0 3 rlineto\n"
	"		x 1.5 add jsatw_y -1.5 add moveto 0 3 rlineto\n"
	"		x -3 add jsatw_y moveto 6 0 rlineto stroke\n"
	"		grestore\n"
	"	} bind def\n"
/* This draws the down arrow for octaves too low.     [JSA]  */
	"\n/tw_under { %% usage: y tw_under - draws down arrow for octave too low\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		x jsatw_y 49 add moveto 0 -3 rmoveto\n"
	"		-2.5 2.5 rlineto 2.5 -2.5 rmoveto\n"
	"		2.5 2.5 rlineto -2.5 -2.5 rmoveto\n"
	"		0 6 rlineto stroke\n"
	"		grestore\n"
	"	} bind def\n"
/* This draws the up arrow for octaves too high.     [JSA]  */
	"\n/tw_over { %% usage: y tw_over - draws up arrow for octave too high\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		x jsatw_y 49 add moveto 0 3 rmoveto\n"
	"		-2.5 -2.5 rlineto 2.5 2.5 rmoveto\n"
	"		2.5 -2.5 rlineto -2.5 2.5 rmoveto\n"
	"		0 -6 rlineto stroke\n"
	"		grestore\n"
	"	} bind def\n";

/* Each of these draws a set of six fingerholes [JSA] */
static char def_tw_sixholes[] = "\n/tw_00 { %% usage: y tw_00\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_o tw_o tw_o\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_05 { %% usage: y tw_05\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_f tw_f tw_o\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_10 { %% usage: y tw_10\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_o tw_o tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_15 { %% usage: y tw_15\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_o tw_h tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_20 { %% usage: y tw_20\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_o tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_25 { %% usage: y tw_25\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_h tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_30 { %% usage: y tw_30\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_o tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_35 { %% usage: y tw_35\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_h tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_40 { %% usage: y tw_40\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_o tw_f tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_45 { %% usage: y tw_45\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_h tw_f tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_50 { %% usage: y tw_50\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_o tw_f tw_f tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_55 { %% usage: y tw_55\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_h tw_f tw_f tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_60 { %% usage: y tw_60\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_f tw_f tw_f tw_f tw_f tw_f\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_002 { %% usage: y tw_002\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_00\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_052 { %% usage: y tw_052\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_05\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_102 { %% usage: y tw_102\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_10\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_152 { %% usage: y tw_152\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_15\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_202 { %% usage: y tw_202\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_20\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_252 { %% usage: y tw_252\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_25\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_302 { %% usage: y tw_302\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_30\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_352 { %% usage: y tw_352\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_35\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_402 { %% usage: y tw_402\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_40\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_452 { %% usage: y tw_452\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_45\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_502 { %% usage: y tw_502\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_50\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_552 { %% usage: y tw_552\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 jsatw_y tw_55\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_602 { %% usage: y tw_602\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_2 tw_f tw_f tw_f tw_f tw_f tw_o\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_003 { %% usage: y tw_003\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_00\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_053 { %% usage: y tw_053\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_05\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_103 { %% usage: y tw_103\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_10\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_153 { %% usage: y tw_153\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_15\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_203 { %% usage: y tw_203\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_20\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_253 { %% usage: y tw_253\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_25\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_303 { %% usage: y tw_303\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_30\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_353 { %% usage: y tw_353\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_35\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_403 { %% usage: y tw_403\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_40\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_453 { %% usage: y tw_453\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_45\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_503 { %% usage: y tw_503\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_50\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_553 { %% usage: y tw_553\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_55\n"
	"		grestore\n"
	"	} bind def\n"
	"\n/tw_603 { %% usage: y tw_603\n"
	"		/jsatw_y exch def\n"
	"		gsave .5 setlinewidth\n"
	"		tw_3 jsatw_y tw_60\n"
	"		grestore\n"
	"	} bind def\n";

/******************************************************/
/*                                                    */	
/* Additional Standard Symbols [JSA] 05/00            */
/*                                                    */	
/******************************************************/
static char def_jsa_std_sym[] = "\n/segno { %% usage: x y segno\n"
	"	/jsay exch def /jsax exch def\n" 
	"	/Times-BoldItalic 9 selectfont\n"
	"	jsax jsay moveto 45 rotate 0 4 rmoveto (S) cshow -45 rotate\n"
	"	jsax jsay moveto 45 rotate 0 -4 rmoveto(S) cshow -45 rotate\n"
	"	jsax jsay moveto 45 rotate -6 3 rmoveto 12 0 rlineto stroke -45 rotate\n"
	"} bind def\n"
	"\n/coda { %%usage: x y coda\n"
	"	/jsay exch def /jsax exch def\n"
	"	jsax 6 add jsay moveto jsax jsay 6 0 360 arc stroke\n"
	"	jsax jsay moveto 0 8 rmoveto 0 -16 rlineto stroke\n"
	"	jsax jsay moveto -8 0 rmoveto 16 0 rlineto stroke\n"
	"} bind def\n"
	"\n/crescendo { %% usage x1 x2 y crescendo\n"
	"	/jsay exch def /jsax2 exch def /jsax exch def\n"
	"	gsave\n"
	"		0.5 setlinewidth\n"
	"		jsax jsay moveto jsax2 jsay 4 add lineto stroke\n"
	"		jsax jsay moveto jsax2 jsay -4 add lineto stroke\n"
	"	grestore\n"
	"} bind def\n"
	"\n/diminuendo { %% usage x1 x2 y diminuendo\n"
	"	/jsay exch def /jsax2 exch def /jsax exch def\n"
	"	gsave\n"
	"		0.5 setlinewidth\n"
	"		jsax2 jsay moveto jsax jsay 4 add lineto stroke\n"
	"		jsax2 jsay moveto jsax jsay -4 add lineto stroke\n"
	"	grestore\n"
	"} bind def\n"
	"\n/accent { %% usage:  x y accent - accent (loud) mark\n"
	"	/jsay exch def /jsax exch def\n"
	"	gsave\n"
	"		0.9 setlinewidth\n"
	"		jsax -5 add jsay moveto jsax 10 add jsay 3 add lineto stroke\n"
	"		jsax -5 add jsay moveto jsax 10 add jsay -3 add lineto stroke\n"
	"	grestore\n"
	"} bind def\n";

/******************************************************/
/*                                                    */	
/* Original symbols from abcm2ps, v. 0.9.5, 8/31/1998 */
/*                                                    */	
/******************************************************/

static char def_misc[] = "\n/cshow { %% usage: string cshow  - center at current pt\n"
	"   dup stringwidth pop 2 div neg 0 rmoveto\n"
	"   currentpoint pop dup 0 lt {neg 0 rmoveto} {pop} ifelse\n"
	"   show\n"
	"} bind def\n"
	"\n/lshow { %% usage: string lshow - show left-aligned\n"
	"   dup stringwidth pop neg 0 rmoveto show\n"
	"} bind def\n"

	"\n/wd { moveto show } bind def\n"
	"/wln {\n"
	"dup 3 1 roll moveto gsave 0.6 setlinewidth lineto stroke grestore\n"
	"} bind def\n"

	"/whf {moveto gsave 0.5 1.2 scale (-) show grestore} bind def\n";

static char def_typeset[] = "\n/WS {   %%usage:	w nspaces str WS\n"
	"   dup stringwidth pop 4 -1 roll\n"
	"   sub neg 3 -1 roll div 0 8#040 4 -1 roll\n"
	"   widthshow\n"
	"} bind def\n"

	"\n/W1 { show pop pop } bind def\n"

	"\n/str 50 string def\n"
	"/W0 {\n"
	"   dup stringwidth pop str cvs exch show (	) show show pop pop\n"
	"} bind def\n"

	"\n/WC { counttomark 1 sub dup 0 eq { 0 }\n"
	"  {  ( ) stringwidth pop neg 0 3 -1 roll\n"
	"  {  dup 3 add index stringwidth pop ( ) stringwidth pop add\n"
	"  dup 3 index add 4 index lt 2 index 1 lt or\n"
	"  {3 -1 roll add exch 1 add} {pop exit} ifelse\n"
	"  } repeat } ifelse\n"
	"} bind def\n"

	"\n/P1 {\n"
	"  {  WC dup 0 le {exit} if\n"
	"	  exch pop gsave { exch show ( ) show } repeat grestore LF\n"
	"   } loop pop pop pop pop\n"
	"} bind def\n"

	"\n/P2 {\n"
	"   {  WC dup 0 le {exit} if\n"
	"	  dup 1 sub dup 0 eq\n"
	"	  { pop exch pop 0.0 }\n"
	"	  { 3 2 roll 3 index exch sub exch div } ifelse\n"
	"	  counttomark 3 sub 2 index eq { pop 0 } if exch gsave\n"
	"	  {  3 2 roll show ( ) show dup 0 rmoveto } repeat\n"
	"	  grestore LF pop\n"
	"   } loop pop pop pop pop\n"
	"} bind def\n";

static char def_tsig[] = "\n/tsig { %% usage: x y (top) (bot) tsig -- draw time signature\n"
	"   4 2 roll moveto\n"
	"   gsave /Times-Bold 16 selectfont 1.2 1 scale\n"
	"   0 1.0 rmoveto currentpoint 3 -1 roll cshow\n"
	"   moveto 0 12 rmoveto cshow grestore\n"
	"} bind def\n";

static char def_dot[] = "\n/dt {  %% usage: dx dy dt  - dot shifted by dx,dy\n"
	"  y add exch x add exch 1.2 0 360 arc fill\n"
	"} bind def\n";

static char def_hl[] = "\n/hl {  %% usage: y hl  - helper line at height y\n"
	"   gsave 1 setlinewidth x exch moveto \n"
	"   -5.5 0 rmoveto 11 0 rlineto stroke grestore\n"
	"} bind def\n"

	"\n/hl1 {  %% usage: y hl1  - longer helper line\n"
	"   gsave 1 setlinewidth x exch moveto \n"
	"   -7 0 rmoveto 14 0 rlineto stroke grestore\n"
	"} bind def\n";

static char def_beam[] = "\n/bm {  %% usage: x1 y1 x2 y2 t bm  - beam, depth t\n"
	"  3 1 roll moveto dup 0 exch neg rlineto\n"
	"  dup 4 1 roll sub lineto 0 exch rlineto fill\n"
	"} bind def\n"

	"\n/bnum {  %% usage: x y (str) bnum	- number on beam\n"
	"  3 1 roll moveto gsave /Times-Italic 12 selectfont\n"
	"  cshow grestore\n"
	"} bind def\n"
  
	"\n/hbr {  %% usage: x1 y1 x2 y2 hbr	- half bracket\n"
	"  moveto lineto 0 -3 rlineto stroke\n"
	"} bind def\n";

static char def_bars[] = "\n/bar {  %% usage: h x y bar  - single bar\n"
	"  moveto 0 exch rlineto stroke\n"
	"} bind def\n"
	  
	"\n/dbar {  %% usage: h x y dbar  - thin double bar\n"
	"   moveto dup 0 exch rlineto dup -3 exch neg rmoveto\n"
	"   0 exch rlineto stroke\n"
	"} bind def\n"

	"\n/fbar1 {  %% usage: h x y fbar1  - fat double bar at start\n"
	"  moveto dup 0 exch rlineto 3 0 rlineto dup 0 exch neg rlineto \n"
	"  currentpoint fill moveto\n"
	"  3 0 rmoveto 0 exch rlineto stroke\n"
	"} bind def\n"

	"\n/fbar2 {  %% usage: h x y fbar2  - fat double bar at end\n"
	"  moveto dup 0 exch rlineto -3 0 rlineto dup 0 exch neg rlineto \n"
	"  currentpoint fill moveto\n"
	"  -3 0 rmoveto 0 exch rlineto stroke\n"
	"} bind def\n"

	"\n/rdots {  %% usage: x y rdots  - repeat dots \n"
	"  moveto 0 9 rmoveto currentpoint 2 copy 1.2 0 360 arc \n"
	"  moveto 0 6 rmoveto  currentpoint 1.2 0 360 arc fill\n"
	"} bind def\n";

static char def_gchord[] = "\n/gc { %% usage: x y (str) gc  -- draw guitar chord string\n"
	"  3 1 roll moveto show\n"
	"} bind def\n";

static char def_staff[] = "\n/staff {	%% usage: l staff  - draw staff\n"
	"  gsave 0.5 setlinewidth\n"
	"  dup 0 rlineto dup neg 6 rmoveto\n"
	"  dup 0 rlineto dup neg 6 rmoveto\n"
	"  dup 0 rlineto dup neg 6 rmoveto\n"
	"  dup 0 rlineto dup neg 6 rmoveto\n"
	"  dup 0 rlineto dup neg 6 rmoveto\n"
	"  pop stroke grestore\n"
	"} bind def\n"

	"\n/hbrce {\n"
	"  -3 -2 rmoveto\n"
	"  -3.65 -3.3 -4.97 -7.44 -4.97 -12.39 rcurveto\n"
	"  0.0 -4.95 0.48 -10.56 1.44 -16.84 rcurveto\n"
	"  0.96 -6.28 1.44 -10.4 1.44 -12.38 rcurveto\n"
	"  0.0 -1.98 -0.6 -3.63 -1.8 -4.96 rcurveto\n"
	"  -1.2 -1.32 -0.96 -0.99 0.72 1.0 rcurveto\n"
	"  1.69 1.98 2.65 5.44 2.89 10.4 rcurveto\n"
	"  0.24 4.95 -0.24 9.74 -1.45 14.36 rcurveto\n"
	"  -1.2 4.63 -1.8 8.59 -1.8 11.89 rcurveto\n"
	"  0.0 3.3 1.08 6.44 3.25 9.41 rcurveto\n"
	"  2.17 2.97 1.92 2.81 -0.72 -0.49 rcurveto\n"
	"  fill\n"
	"} bind def\n"

	"\n/brace {  %%usage h x y brace\n"
	"  gsave translate 0 0 moveto 98 div 1.05 exch scale hbrce\n"
	"  0 -98 moveto 1 -1 scale hbrce grestore\n"
	"} bind def\n"

	"\n/bracket {  %%usage h x y braket\n"
	"  3 copy 3 -1 roll sub moveto -4 0 rlineto stroke\n"
	"  2 copy moveto -4 0 rlineto stroke exch 4 sub exch moveto\n"
	"  dup 0 exch neg rlineto -3 0 rlineto 0 exch rlineto\n"
	"  fill\n"
	"} bind def\n";

static char def_sep[] = "\n/sep0 { %% usage: x1 x2 sep0  - hline separator \n"
	"   0 moveto 0 lineto stroke\n"
	"} bind def\n";

/* ----- define_font ------- */
void define_font(FILE *fp,
		 char name[],
		 int  num)
{
	if (!strcmp(name,"Symbol")) {
		fprintf(fp, "/F%d { /%s exch selectfont } bind def\n",
			num, name);
		return;
	}
	fprintf(fp, "\n/%s findfont\n"
		"dup length dict begin\n"
		"   {1 index /FID ne {def} {pop pop} ifelse} forall\n"
		"   /Encoding ISOLatin1Encoding def\n"
		"   currentdict\n"
		"end\n"
		"/%s-ISO exch definefont pop\n",
		name, name);

	fprintf(fp,
		"/F%d { /%s-ISO exch selectfont } bind def\n",
		num, name);
}

/* ----- add_cv ------- */
static void add_cv(FILE *fp,
		   float f1,
		   float f2,
		   float p[][2],
		   int i0,
		   int ncv)
{
	int i,i1,m;

	i1=i0;
	for (m=0; m<ncv; m++) {
		fprintf(fp, " ");
		for (i=0; i<3; i++)
			fprintf(fp, " %.2f %.2f",
				f1*(p[i1+i][0]-p[i1-1][0]),
				f2*(p[i1+i][1]-p[i1-1][1]));
		fprintf(fp, " rcurveto\n");
		i1 += 3;
	}
}

/* ----- add_sg ------- */
static
void add_sg(FILE *fp,
	    float f1,
	    float f2,
	    float p[][2],
	    int i0,
	    int nseg)
{
	int i;

	for (i=0; i<nseg; i++)
		fprintf(fp, "  %.2f %.2f rlineto\n",
			f1*(p[i0+i][0]-p[i0+i-1][0]),
			f2*(p[i0+i][1]-p[i0+i-1][1]));
}

/* ----- add_mv ------- */
static void add_mv(FILE *fp,
		   float f1,
		   float f2,
		   float p[][2],
		   int i0)
{
	if (i0==0)
		fprintf(fp, "  %.2f %.2f rmoveto\n",
			f1*p[i0][0], f2*p[i0][1]);
	else	fprintf(fp, "  %.2f %.2f rmoveto\n",
			f1*(p[i0][0]-p[i0-1][0]),
			f2*(p[i0][1]-p[i0-1][1]));
}

/* ----- def_stems ------- */
static void def_stems(FILE *fp)
{
	fprintf(fp, "\n/su {  %% usage: len su	- up stem\n"
		"  x y moveto %.1f %.1f rmoveto %.1f sub 0 exch rlineto stroke\n"
		"} bind def\n",
		STEM_XOFF, STEM_YOFF, STEM_YOFF );

	fprintf(fp, "\n/sd {  %% usage: len td  - down stem\n"
		"  x y moveto %.1f %.1f rmoveto neg %.1f add 0 exch rlineto stroke\n"
		"} bind def\n",
		-STEM_XOFF, -STEM_YOFF, STEM_YOFF);
}


/* ----- def_deco ------- */
static void def_deco(FILE *fp)
{
static float p[7][2] = {
	{-10,-2},{0,15},{1,-11},{10,2},{0,-15},{-1,11},{-10,-2} };

/*  float q[7][2] = {
    {-13,0},{-2,9},{2,9},{13,0},{3,5},{-3,5},{-13,-0} }; */

/*  float q[7][2] = {
    {-11,0},{-9,10},{9,10},{11,0},{5,7},{-5,7},{-11,-0} }; */

  /* Walsh suggestion, scale 1.8 in y */ 
static float q[7][2] = {
	{-13,0},{-12,9},{12,9},{13,0},{10,(float)7.4},{-10,(float)7.4},{-13,-0} };

static float s[7][2] = {
	{-8,(float)-4.8},{-6,(float)-5.5},{-3,(float)-4.6},{0,0},{(float)-2.3,-5},{-6,(float)-6.8},{(float)-8.5,-6} };

	float f1,f2;
	int i;

	f1=(float)0.5;
	f2=(float)0.5;

	fprintf(fp, "\n/grm {  %% usage:  y grm  - gracing mark\n"
		"  x exch moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "   fill\n} bind def\n"
		"\n/stc {  %% usage:  y stc  - staccato mark\n"
		"  x exch 1.2 0 360 arc fill } bind def\n");

	f2 *= (float)1.8;

#if 0
	if (temp_switch==3) {
		f1 *= (float)0.8; f2 *= (float)0.8;
	} else {
#endif
		f1 *= (float)0.9; f2 *= (float)0.9;
  
	fprintf(fp, "\n/cpu {  %% usage:  y cpu  - roll sign above head\n"
		"  x exch moveto\n");
	add_mv(fp,f1,f2,q,0);
	add_cv(fp,f1,f2,q,1,2);
	fprintf(fp, "   fill\n} bind def\n");

	for (i=0;i<7;i++)
		q[i][1]=-q[i][1];

	fprintf(fp, "\n/cpd {  %% usage:  y cpd  - roll sign below head\n"
		"  x exch moveto\n");
	add_mv(fp,f1,f2,q,0);
	add_cv(fp,f1,f2,q,1,2);
	fprintf(fp, "   fill\n} bind def\n");

	f1=(float)0.9;
	f2=(float)1.0;
	fprintf(fp, "\n/sld {  %% usage:  y dx sld  - slide\n"
		"  x exch sub exch moveto\n");
	add_mv(fp,f1,f2,s,0);
	add_cv(fp,f1,f2,s,1,2);
	fprintf(fp, "   fill\n} bind def\n"
  
		"\n/emb {  %% usage:  y emb  - empahsis bar\n"
		"  gsave 1.2 setlinewidth 1 setlinecap x exch moveto \n"
		" -2.5 0 rmoveto 5 0 rlineto stroke grestore\n"
		"} bind def\n"

		"\n/trl {  %% usage:  y trl  - trill sign\n"
		"  gsave /Times-BoldItalic 14 selectfont\n"
		"  x 4 sub exch moveto (tr) show grestore\n"
		"} bind def\n");
}

/* ----- def_deco1 ------- */
static void def_deco1(FILE *fp)
{
static float p[8][2] = {	/* for hold sign */
	{-15,0},{-15,23},{15,23},{15,0},
	{14.5,0},{12,18},{-12,18},{-14.5,0} };

static float q[8][2] = {    /* for down bow sign */
	{-4,0},{-4,9},{4,9},{4,0},
	{-4,6},{-4,9},{4,9},{4,6} };

static float r[3][2] = {    /* for up bow sign */
	{(float)-3.2,11},{0,0},{(float)3.2,11} };

	float f1,f2;

	f1=f2=(float)0.5;
	fprintf(fp, "\n/hld {  %% usage:  y hld  - hold sign\n"
		"  x exch 2 copy 1.5 add 1.3 0 360 arc moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,1);
	add_sg(fp,f1,f2,p,4,1);
	add_cv(fp,f1,f2,p,5,1);
	fprintf(fp, "   fill\n} bind def\n");

	f1=f2=(float)0.8;
	fprintf(fp, "\n/dnb {  %% usage:  y dnb  - down bow\n"
		"  x exch moveto\n");
	add_mv(fp,f1,f2,q,0);
	add_sg(fp,f1,f2,q,1,3);
	fprintf(fp, "   currentpoint stroke moveto\n");
	add_mv(fp,f1,f2,q,4);
	add_sg(fp,f1,f2,q,5,3);
	fprintf(fp, "   fill\n} bind def\n"

		"\n/upb {  %% usage:  y upb  - up bow\n"
		"  x exch moveto\n");
	add_mv(fp,f1,f2,r,0);
	add_sg(fp,f1,f2,r,1,2);
	fprintf(fp, "   stroke\n} bind def\n");
}

/* ----- def_flags1 ------- */
static void def_flags1(FILE *fp)
{
static float p[13][2] = {
	{0.0, 0.0},  {1.5, -3.0},  {1.0, -2.5},  {4.0, -6.0}, {9.0, -10.0},
	{9.0, -16.0}, {8.0, -20.0}, {7.0, -24.0}, {4.0, -26.0},
	{6.5, -21.5}, {9.0, -15.0}, {4.0, -9.0}, {0.0, -8.0} };

	float f1,f2;
	int i;

	f1=f2=(float)(6.0/9.0);
	fprintf(fp, "\n/f1u {  %% usage:  len f1u  - single flag up\n"
		"  y add x %.1f add exch moveto\n", STEM_XOFF);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,4);
	fprintf(fp, "   fill\n} bind def\n");

	f1=(float)1.2*f1;
	for (i=0;i<13;i++) p[i][1]=-p[i][1];
	fprintf(fp, "\n/f1d {  %% usage:  len f1d  - single flag down\n"
		"  neg y add x %.1f sub exch moveto\n", STEM_XOFF);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,4);
	fprintf(fp, "   fill\n} bind def\n");
}

/* ----- def_flags2 ------- */
static void def_flags2(FILE *fp)
{
static float p[13][2] = {
	{0.0, 0.0},
	{2.0, -5.0},  {9.0, -6.0}, {7.5, -18.0},
	{7.5, -9.0},  {1.5, -6.5}, {0.0, -6.5},
	{2.0, -14.0}, {9.0, -14.0}, {7.5, -26.0},
	{7.5, -17.0}, {1.5, -14.5}, {0.0, -14.0},
};

	float f1,f2;
	int i;

	f1=f2=(float)(6.0/9.0);			/* up flags */
	fprintf(fp, "\n/f2u {  %% usage:  len f2u  - double flag up\n"
		"  y add x %.1f add exch moveto\n", STEM_XOFF);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,4);
	fprintf(fp, "   fill\n} bind def\n");

	f1 *= (float)1.2;			/* down flags */
	for (i=0;i<13;i++) p[i][1]=-p[i][1];
	fprintf(fp, "\n/f2d {  %% usage:  len f2d  - double flag down\n"
		"  neg y add x %.1f sub exch moveto\n", STEM_XOFF);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,4);
	fprintf(fp, "   fill\n} bind def\n");
}

/* ----- def_xflags ------- */
static void def_xflags(FILE *fp)
{
static float p[7][2] = {
	{0.0, 0.0},
	{2.0, -7.5},  {9.0, -7.5}, {7.5, -19.5},
	{7.5, -10.5}, {1.5, -8.0}, {0.0, -7.5}
};

	float f1,f2;
	int i;

	f1=f2=(float)(6.0/9.0);			/* extra up flag */
	fprintf(fp, "\n/xfu {  %% usage:  len xfu  - extra flag up\n"
		"  y add x %.1f add exch moveto\n", STEM_XOFF);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "   fill\n} bind def\n");

	f1 *= (float)1.2;			/* extra down flag */
	for (i=0;i<7;i++)
		p[i][1]=-p[i][1];
	fprintf(fp, "\n/xfd {  %% usage:  len xfd  - extra flag down\n"
		"  neg y add x %.1f sub exch moveto\n", STEM_XOFF);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "   fill\n} bind def\n"

		"\n/f3d {dup f2d 9.5 sub xfd} bind def\n"

		"\n/f4d {dup dup f2d 9.5 sub xfd 14.7 sub xfd} bind def\n"

		"\n/f3u {dup f2u 9.5 sub xfu} bind def\n"

		"\n/f4u {dup dup f2u 9.5 sub xfu 14.7 sub xfu} bind def\n");
}

/* ----- def_acc ------- */
static void def_acc(FILE *fp)
{
static float p[12][2]={
	{-2,3},{6,6.5},{6,-1},{-2,-4.5},{4,0},{4,4},{-2,2},{-2,10},{-2,-4}};
static float q[14][2]={
	{4,4},{4,7},{-4,5},{-4,2},{4,4},{4,-5},{4,-2},{-4,-4},{-4,-7},{4,-5},
	{2,-10},{2,11.5},{-2,-11.5},{-2,10} };
static float r[14][2]={
	{-2.5,-6}, {2.5,-5}, {2.5,-2}, {-2.5,-3}, {-2.5,6},
	{-2.5,2}, {2.5,3}, {2.5,6}, {-2.5,5}, {-2.5,2},
	{-2.5,11}, {-2.5,-5.5},
	{2.5,5.5}, {2.5,-11} };
static float s[25][2]={
	{(float)0.7,0},{(float)3.9,3},{6,3},{(float)6.2,(float)6.2},{3,6},{3,(float)3.9},
	{0,(float)0.7},{-3,(float)3.9},{-3,6},{(float)-6.2,(float)6.2},{-6,3},{(float)-3.9,3},
	{(float)-0.7,0},{(float)-3.9,-3},{-6,-3},{(float)-6.2,(float)-6.2},{-3,-6},{-3,(float)-3.9},
	{0,(float)-0.7},{3,(float)-3.9},{3,-6},{(float)6.2,(float)-6.2},{6,-3},{(float)3.9,-3},
	{(float)0.7,0} };

	float f1,f2;

	f2=(float)(8.0/9.0);
	f1=f2*(float)0.9;
	fprintf(fp, "\n/ft0 { %% usage:  x y ft0  - flat sign\n"
		"  moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "  currentpoint fill moveto\n");
	add_mv(fp,f1,f2,p,7);
	add_sg(fp,f1,f2,p,8,1);
	fprintf(fp, "  stroke\n } bind def\n"
		"/ft { %% usage: dx ft  - flat relative to head\n"
		" neg x add y ft0 } bind def\n");

	f2=(float)(8.0/9.0);	/* more narrow flat sign for double flat */
	f1=f2*(float)0.8;
	fprintf(fp, "\n/ftx { %% usage:  x y ftx  - narrow flat sign\n"
		"  moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "  currentpoint fill moveto\n");
	add_mv(fp,f1,f2,p,7);
	add_sg(fp,f1,f2,p,8,1);
	fprintf(fp, "  stroke\n } bind def\n"
		"/dft0 { %% usage: x y dft0 ft  - double flat sign\n"
		"  2 copy exch 2.5 sub exch ftx exch 1.5 add exch ftx } bind def\n"
		"/dft { %% usage: dx dft  - double flat relative to head\n"
		"  neg x add y dft0 } bind def\n");

	f2=(float)(6.5/9.0);
	f1=f2*(float)0.9;
	fprintf(fp, "\n/sh0 {  %% usage:  x y sh0  - sharp sign\n"
		"  moveto\n");
	add_mv(fp,f1,f2,q,0);
	add_sg(fp,f1,f2,q,1,4);
	add_mv(fp,f1,f2,q,5);
	add_sg(fp,f1,f2,q,6,4);
	fprintf(fp, "  currentpoint fill moveto\n");
	add_mv(fp,f1,f2,q,10);
	add_sg(fp,f1,f2,q,11,1);
	fprintf(fp, "  currentpoint stroke moveto\n");
	add_mv(fp,f1,f2,q,12);
	add_sg(fp,f1,f2,q,13,1);
	fprintf(fp, "  stroke\n } bind def\n");
	fprintf(fp, "/sh { %% usage: dx sh  - sharp relative to head\n"
		" neg x add y sh0 } bind def\n");

	f2=(float)(6.5/9.0);
	f1=f2*(float)0.9;
	fprintf(fp, "\n/nt0 {  %% usage:  x y nt0  - neutral sign\n"
		"  moveto\n");
	add_mv(fp,f1,f2,r,0);
	add_sg(fp,f1,f2,r,1,4);
	add_mv(fp,f1,f2,r,5);
	add_sg(fp,f1,f2,r,6,4);
	fprintf(fp, "  currentpoint fill moveto\n");
	add_mv(fp,f1,f2,r,10);
	add_sg(fp,f1,f2,r,11,1);
	fprintf(fp, "  currentpoint stroke moveto\n");
	add_mv(fp,f1,f2,r,12);
	add_sg(fp,f1,f2,r,13,1);
	fprintf(fp, "  stroke\n } bind def\n"
		"/nt { %% usage: dx nt  - neutral relative to head\n"
		" neg x add y nt0 } bind def\n");

	f1=(float)(5.0/9.0);
	f2=f1;
	fprintf(fp, "\n/dsh0 {  %% usage:  x y dsh0  - double sharp\n"
		"  moveto\n");
	add_mv(fp,f1,f2,s,0);
	add_sg(fp,f1,f2,s,1,24);
	fprintf(fp, "  fill\n } bind def\n"
		"/dsh { %% usage: dx dsh  - double sharp relative to head\n"
		" neg x add y dsh0 } bind def\n");
}

/* ----- def_rests ------- */
static void def_rests(FILE *fp)
{
static float p[14][2]={
	{-1,17}, {15,4}, {-6,8}, {6.5,-5}, {-2,-2}, {-5,-11}, {1,-15},
	{-9,-11}, {-6,0}, {1,-1}, {-9,7}, {7,5}, {-1,17} };
static float q[16][2]={
	{8,14}, {5,9}, {3,5}, {-1.5,4},
	{4,11}, {-9,14}, {-9,7},
	{-9,4}, {-6,2}, {-3,2},
	{4,2}, {5,7}, {7,11},
	{(float)-1.8,-20},  {(float)-0.5,-20}, {(float)8.5,14}};
static float r[29][2]={  
	{8,14}, {5,9}, {3,5}, {(float)-1.5,4},
	{4,11}, {-9,14}, {-9,7},
	{-9,4}, {-6,2}, {-3,2},
	{4,2}, {5,7}, {7,11},
	{8,14}, {5,9}, {3,5}, {-1.5,4},
	{4,11}, {-9,14}, {-9,7},
	{-9,4}, {-6,2}, {-3,2},
	{4,2}, {5,7}, {(float)7.3,11},
	{(float)-1.8,-21},  {(float)-0.5,-21}, {(float)8.5,14} };
	float f1,f2;
	int i;

	fprintf(fp, "\n/r4 {  %% usage:  x y r4  -  quarter rest\n"
		"   dup /y exch def exch dup /x exch def exch moveto\n");
	f1=f2=(float)(6.0/11.5);
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,4);
	fprintf(fp, "  fill\n } bind def\n");

	fprintf(fp, "\n/r8 {  %% usage:  x y r8  -  eighth rest\n"
		"   dup /y exch def exch dup /x exch def exch moveto\n");
	f1=f2=(float)(7/18.0);
	add_mv(fp,f1,f2,q,0);
	add_cv(fp,f1,f2,q,1,4);
	add_sg(fp,f1,f2,q,13,3);
	fprintf(fp, "  fill\n } bind def\n");

	for (i=13;i<26;i++) {
		r[i][0]-=(float)4.2; r[i][1]-=14;
	}
	fprintf(fp, "\n/r16 {  %% usage:  x y r16  -  16th rest\n"
		"   dup /y exch def exch dup /x exch def exch moveto\n");
	f1=f2=(float)(7/18.0);
	add_mv(fp,f1,f2,r,0);
	add_cv(fp,f1,f2,r,1,4);
	add_sg(fp,f1,f2,r,13,1);
	add_cv(fp,f1,f2,r,14,4);
	add_sg(fp,f1,f2,r,26,3);
	fprintf(fp, "  fill\n } bind def\n");

	fprintf(fp,
		"\n/r1 {  %% usage:	x y r1	-  rest\n"
		"  6 add dup /y exch def exch dup /x exch def exch moveto\n"
		"  -3 0 rmoveto 0 -3 rlineto 6 0 rlineto 0 3 rlineto fill\n"
		"} bind def\n"
		"\n/r2 {  %% usage:	x y r2	-  half rest\n"
		"  dup /y exch def exch dup /x exch def exch moveto\n"
		"  -3 0 rmoveto 0 3 rlineto 6 0 rlineto 0 -3 rlineto fill\n"
		"} bind def\n");

	/* get 32nd, 64th rest by overwriting 8th and 16th rests */
	fprintf(fp,
		"\n/r32 {\n"
		"2 copy r16 5.5 add exch 1.6 add exch r8\n"
		"} bind def\n"

		"\n/r64 {\n"
		"2 copy 5.5 add exch 1.6 add exch r16\n"
		"5.5 sub exch 1.5 sub exch r16\n"
		"} bind def\n");
}

/* ----- def_ends ------ */
static void def_ends(FILE *fp)
{
	/* old style had dy=20 */
	int y=50,dy=20;

	fprintf(fp, "\n/end1 {  %% usage: x1 x2 (str) y end1  - mark first ending\n"
		"  gsave 0 exch translate\n"
		"  3 1 roll %d moveto 0 %d rlineto dup %d lineto 0 %d rlineto stroke\n"
		"  4 add %d moveto /Times-Roman 13 selectfont 1.2 0.95 scale\n"
		"  show grestore\n"
		"} bind def\n",
		y-dy,  dy, y, -dy,  y-10);

	fprintf(fp, "\n/end2 {  %% usage: x1 x2 (str) y end2  - mark second ending\n"
		"  gsave 0 exch translate\n"
		"  3 1 roll %d moveto dup %d lineto 0 %d rlineto stroke\n"
		"  4 add %d moveto /Times-Roman 13 selectfont 1.2 0.95 scale\n"
		"  show grestore\n"
		"} bind def\n",
		y, y, -dy,  y-10);
}  

/* ----- def_sl ------ */
static void def_sl(FILE *fp)
{
/*	fprintf(fp, "\n/sl {  %% usage: x1 y2 x2 y2 x3 y3 x0 y0 sl\n"
		"  gsave %.1f setlinewidth moveto curveto stroke grestore\n"
		"} bind def\n", SLURWIDTH); */

	fprintf(fp, "\n/SL {	%% usage: pp2x pp1x p1 pp1 pp2 p2 p1 sl\n"
		"  moveto curveto rlineto curveto fill\n"
		"} bind def\n");
}

/* ----- def_hd1 ------- */
static void def_hd1(FILE *fp)
{
static float p[7][2] = {
	{8.0, 0.0},  {8.0, 8.0}, {-8.0, 8.0}, {-8.0, 0.0}, {-8.0, -8.0},
	{8.0, -8.0}, {8.0, 0.0} };

	float c,s,xx,yy,f1,f2;
	int i;
/*float phi; */

/*phi=0.6;
  c=cos(phi);
  s=sin(phi); */

	c=(float)0.825; s=(float)0.565;

	for (i=0;i<7;i++) {
		xx = c*p[i][0] - s*p[i][1];
		yy = s*p[i][0] + c*p[i][1];
		p[i][0]=xx;
		p[i][1]=yy;
	}

	f1=f2=6.0/12.0;
	fprintf(fp, "\n/hd {  %% usage: x y hd  - full head\n"
		"  dup /y exch def exch dup /x exch def exch moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "   fill\n} bind def\n");
}

/* ----- def_hd2 ------- */
static void def_hd2(FILE *fp)
{
static float p[14][2] = {
	{8.0, 0.0},  {8.0, 8.5},  {-8.0, 8.5}, {-8.0, 0.0}, {-8.0, -8.5},
	{8.0, -8.5}, {8.0, 0.0},  {7.0, 0.0},  {7.0, -4.0}, {-7.0, -4.0},
	{-7.0, 0.0}, {-7.0, 4.0}, {7.0, 4.0},  {7.0, 0.0} };

/*  float phi; */
	float c,s,xx,yy,f1,f2;
	int i;

/*phi=0.5;
  c=cos(phi);
  s=sin(phi); */

	c=(float)0.878; s=(float)0.479;

	for (i=0;i<14;i++) {
		xx = c*p[i][0] - s*p[i][1];
		yy = s*p[i][0] + c*p[i][1];
		p[i][0]=xx;
		p[i][1]=yy;
	}

	f1=f2=6.0/12.0;
	fprintf(fp, "\n/Hd {  %% usage: x y Hd  - open head for half\n"
		"  dup /y exch def exch dup /x exch def exch moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	add_mv(fp,f1,f2,p,7);
	add_cv(fp,f1,f2,p,8,2);
	fprintf(fp, "   fill\n} bind def\n");
}

/* ----- def_hd3 ------- */
static void def_hd3(FILE *fp)
{
static float p[13][2] = {
	{11.0, 0.0}, {11.0, 2.0},  {6.0, 6.5},  {0.0, 6.5}, {-6.0, 6.5},
	{-11.0, 2.0}, {-11.0, 0.0}, {-11.0, -2.0}, {-6.0, -6.5},
	{0.0, -6.5},  {6.0, -6.5}, {11.0, -2.0},  {11.0, 0.0} };

static float q[8][2] = {
	 {11.0, 0.0}, {5.0, 0.0}, {5.0, -5.0}, {-5.0, -5.0}, {-5.0, 0.0},
	 {-5.0, 5.0}, {5.0, 5.0}, {5.0, 0.0}};

/*  float phi; */
	float c,s,xx,yy,f1,f2;
	int i;

/*phi=2.5;
  c=cos(phi);
  s=sin(phi); */

	c=(float)-0.801; s=(float)0.598;

	for (i=1;i<8;i++) {
		xx = c*q[i][0] - s*q[i][1];
		yy = s*q[i][0] + c*q[i][1];
		q[i][0]=xx;
		q[i][1]=yy;
	}

	f1=f2=(float)(6.5/12.0);
	fprintf(fp, "\n/HD { %% usage: x y HD  - open head for whole\n"
		"  dup /y exch def exch dup /x exch def exch moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,4);
	add_mv(fp,f1,f2,q,1);
	add_cv(fp,f1,f2,q,2,2);
	fprintf(fp, "   fill\n} bind def\n");
}

/* ----- def_gnote ------- */
static void def_gnote(FILE *fp)
{
static float p[7][2] = {
	{0,10}, {16,10}, {16,-10}, {0,-10}, {-16,-10}, {-16,10}, {0,10} };
/*  float phi; */
	float c,s,xx,yy,f1,f2;
	int i;

/*phi=0.7;
  c=cos(phi);
  s=sin(phi); */

	c=(float)0.765; s=(float)0.644;

	for (i=0;i<7;i++) {
		xx = c*p[i][0] - s*p[i][1];
		yy = s*p[i][0] + c*p[i][1];
		p[i][0]=xx;
		p[i][1]=yy;
	}

	f1=f2=(float)(2./10.0);

	fprintf(fp, "\n/gn1 {  %% usage: x y l gnt  - grace note w. tail\n"
		"  3 1 roll 2 copy moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "  fill moveto %.2f 0 rmoveto 0 exch rlineto\n"
		"3 -4 4 -5 2 -8 rcurveto -5 2 rmoveto 7 4 rlineto   \n"
		"stroke\n",
		GSTEM_XOFF);
	fprintf(fp, "} bind def\n"

		"\n/gnt {  %% usage: x y l gnt  - grace note\n"
		"  3 1 roll 2 copy moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,2);
	fprintf(fp, "  fill moveto %.2f 0 rmoveto 0 exch rlineto stroke\n",
		GSTEM_XOFF);
	fprintf(fp, "} bind def\n"

		"\n/gbm2 {  %% usage: x1 y1 x2 y2 gbm2  - double note beam\n"
		"  gsave 1.4 setlinewidth\n"
		"  4 copy 0.5 sub moveto 0.5 sub lineto stroke\n"
		"  3.4 sub moveto 3.4 sub lineto stroke grestore\n"
		"} bind def\n"

		"\n/gbm3 {  %% usage: x1 y1 x2 y2 gbm3  - triple gnote beam\n"
		"  gsave 1.2 setlinewidth\n"
		"  4 copy 0.3 sub moveto 0.3 sub lineto stroke\n"
		"  4 copy 2.5 sub moveto 2.5 sub lineto stroke\n"
		"  4.7 sub moveto 4.7 sub lineto stroke grestore\n"
		"} bind def\n"

		"\n/ghl {  %% usage: x y ghl  - grace note helper line\n"
		"   gsave 0.7 setlinewidth moveto \n"
		"   -3 0 rmoveto 6 0 rlineto stroke grestore\n"
		"} bind def\n"

		"\n/gsl {  %% usage: x1 y2 x2 y2 x3 y3 x0 y0 gsl\n"
		"  moveto curveto stroke\n"
		"} bind def\n"

		"\n/gsh0 {  %% usage: x y gsh0\n"
		"gsave translate 0.7 0.7 scale 0 0 sh0 grestore\n"
		"} bind def\n"

		"\n/gft0 {  %% usage: x y gft0\n"
		"gsave translate 0.7 0.7 scale 0 0 ft0 grestore\n"
		"} bind def\n"

		"\n/gnt0 {  %% usage: x y gnt0\n"
		"gsave translate 0.7 0.7 scale 0 0 nt0 grestore\n"
		"} bind def\n");
}

/* ----- def_csig ------- */
static void def_csg(FILE *fp)
{
static float p[25][2]={
	{0,26},
	{4,26}, {11,23}, {11,14},
	{11,20}, {5,19}, {5,14},
	{5,9}, {12,9}, {12,15},
	{12,25}, {6,28}, {0,28},
	{-15,28}, {-25,17}, {-25,2},
	{-25,-10}, {-10,-28}, {11,-8},
	{-6,-20}, {-18,-11}, {-18,2},
	{-18,14}, {-14,26}, {0,26} };
	float f1,f2;
	int i;

	for (i=0;i<25;i++) {
		p[i][0]=p[i][0]+4;
		p[i][1]=p[i][1]+43;
	}
	f1 = f2 = 0.25;
	fprintf(fp, "\n/csig {  %% usage:  x y csig	- C timesig\n"
		" moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,8);
	fprintf(fp, "   fill\n} bind def\n"

		"\n/ctsig {  %% usage:  x y ctsig  - C| timesig\n"
		"  exch 4 add exch 2 copy csig 4 add moveto 0 16 rlineto stroke\n"
		"} bind def\n");
}

/* ----- def_tclef ------- */
static void def_tclef(FILE *fp)
{
static float p[71][2]={
	{-6, 16}, {-8, 13}, {-14, 19}, {-10, 35}, {2, 35}, {8, 37},
	{21, 30}, {21, 17}, {21, 5}, {10, -1}, {0, -1}, {-12, -1},
	{-23, 5}, {-23, 22}, {-23, 29}, {-22, 37}, {-7, 49}, {10, 61},
	{10, 68}, {10, 73}, {10, 78}, {9, 82}, {7, 82}, {2, 78},
	{-2, 68}, {-2, 62}, {-2, 25}, {10, 18}, {11, -8}, {11, -18},
	{5, -23}, {-4, -23}, {-10, -23}, {-15, -18}, {-15, -13},
	{-15, -8}, {-12, -4}, {-7, -4}, {3, -4}, {3, -20}, {-6, -17},
	{-5, -23}, {9, -20}, {9, -9}, {7, 24}, {-5, 30}, {-5, 67},
	{-5, 78}, {-2, 87}, {7, 91}, {13, 87}, {18, 80}, {17, 73},
	{17, 62}, {10, 54}, {1, 45}, {-5, 38}, {-15, 33}, {-15, 19},
	{-15, 7}, {-8, 1}, {0, 1}, {8, 1}, {15, 6}, {15, 14}, {15, 23},
	{7, 26},  {2, 26}, {-5, 26}, {-9, 21}, {-6, 16} };
	float f1,f2;

	f1 = f2 = (float)(24.0/65.0);
	fprintf(fp, "\n/tclef {  %% usage:  x y tclef  - treble clef \n"
		" moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_sg(fp,f1,f2,p,1,1);
	add_cv(fp,f1,f2,p,2,23);
	fprintf(fp, "   fill\n} bind def\n"

		"\n/stclef {\n"
		"  exch 0.85 div exch 0.85 div gsave 0.85 0.85 scale tclef grestore\n"
		"} bind def\n");
}

/* ----- def_bclef ------- */
static void def_bclef(FILE *fp)
{
static float p[42][2]={
	{(float)-2.3,3}, {6,7}, {(float)10.5,12}, {(float)10.5,16},
	{(float)10.5,(float)20.5}, {(float)8.5,(float)23.5}, {(float)6.2,(float)23.3},
	{(float)5.2,(float)23.5}, {2,(float)23.5}, {(float)0.5,(float)19.5},
	{2,20}, {4,(float)19.5}, {4,18},
	{4,17}, {(float)3.5,16}, {2,16},
	{1,16}, {0,(float)16.9}, {0,(float)18.5},
	{0,21}, {(float)2.1,24}, {6,24},
	{10,24}, {(float)13.5,(float)21.5}, {(float)13.5,(float)16.5},
	{(float)13.5,11}, {7,(float)5.5}, {(float)-2.0,(float)2.8},
	{(float)14.9,21},
	{(float)14.9,(float)22.5}, {(float)16.9,(float)22.5}, {(float)16.9,21},
	{(float)16.9,(float)19.5}, {(float)14.9,(float)19.5}, {(float)14.9,21},
	{(float)14.9,15},
	{(float)14.9,(float)16.5}, {(float)16.9,(float)16.5}, {(float)16.9,15},
	{(float)16.9,(float)13.5}, {(float)14.9,(float)13.5}, {(float)14.9,15} };
	int i;
	float f1,f2;

	for (i=0;i<42;i++) {
		p[i][0]-=7.5; p[i][1]-=0.5;
	}
	f1 = f2 = (float)1.0;
	fprintf(fp, "\n/bclef {  %% usage:  x y bclef  - bass clef \n"
		" moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_cv(fp,f1,f2,p,1,9);
	add_cv(fp,f1,f2,p,1,9);

	add_mv(fp,f1,f2,p,28);
	add_cv(fp,f1,f2,p,29,2);

	add_mv(fp,f1,f2,p,25);
	add_cv(fp,f1,f2,p,36,2);

	fprintf(fp, "fill\n} bind def\n"

		"\n/sbclef {\n"
		"  exch 0.85 div exch 0.85 div gsave 0.85 0.85 scale 0 4 translate bclef grestore\n"
		"} bind def\n");
}

/* ----- def_cclef ------- */
static void def_cclef(FILE *fp)
{
static float p[30][2]={
	{0,0}, {2,(float)5.5}, 
	{9,(float)4.5}, {12,10}, {12,(float)15.5},
	{12,(float)19.5}, {11,(float)23.3}, {(float)6.5,(float)23.5},
	{(float)5.2,(float)23.5}, {2,(float)23.5}, {(float)0.5,(float)19.5},
	{2,20}, {4,(float)19.5}, {4,18},
	{4,17}, {(float)3.5,16}, {2,16},
	{1,16}, {0,(float)16.9}, {0,(float)18.5},
	{0,21}, {(float)2.1,24}, {6,24},
	{12,24}, {15,(float)21.5}, {15,(float)16.5},
	{15,10}, {10,(float)4.5}, {4,5},
	{3,0} };
	int i;
	float f1,f2;

	for (i=0;i<30;i++)
		p[i][1]+=24;

	f1 = (float)0.6;
	f2 = (float)0.5;
	fprintf(fp, "\n/cchalf {\n"
		"  0 0 moveto\n");
	add_mv(fp,f1,f2,p,0);
	add_sg(fp,f1,f2,p,1,1);
	add_cv(fp,f1,f2,p,2,9);
	add_sg (fp,f1,f2,p,29,1);
	fprintf(fp, "fill\n} bind def\n"

		"\n/cclef {	 %% usage: x y cclef\n"
		"   gsave translate\n"
		"   cchalf 0 24 translate 1 -1 scale cchalf\n"
		"   -6.5 0 moveto 0 24 rlineto 3 0 rlineto 0 -24 rlineto fill\n"
		"   -1.8 0 moveto 0 24 rlineto 0.8 setlinewidth stroke grestore \n"
		"} bind def\n"

		"\n/scclef { cclef } bind def\n");
}

void DefWatermark(FILE *fp, char * Watermark, float Gray) {
	char	b1[256], *p, *p2, *p3;

	fprintf(fp, "<< 	/PatternType 1\n");
	fprintf(fp, "	/PaintType 1\n");
	fprintf(fp, "	/TilingType 1\n");
	fprintf(fp, "	/BBox [0 0 100 100]\n");
	fprintf(fp, "	/XStep 100\n");
	fprintf(fp, "	/YStep 100\n");
	fprintf(fp, "	/PaintProc {\n");
	fprintf(fp, "		begin\n");
	fprintf(fp, "		/Helvetica 10.0 selectfont\n");
	fprintf(fp, "		%.2f setgray\n", Gray);
	strncpy(b1, Watermark, 255);
	p = strchr(b1, '/');
	if (p) {
		*p = '\0';
		p++;
		p2 = strchr(p, '/');
		if (p2) {
			*p2 = '\0';
			p2++;
			p3 = strchr(p2, '/');
			if (p3) {
				*p3 = '\0';
				p3++;
				fprintf(fp, "		39 61 moveto 45 rotate (%s) cshow -45 rotate\n", b1);
				fprintf(fp, "		46 54 moveto 45 rotate (%s) cshow -45 rotate\n", p);
				fprintf(fp, "       54 46 moveto 45 rotate (%s) cshow -45 rotate\n", p2);
				fprintf(fp, "		61 39 moveto 45 rotate (%s) cshow\n", p3);
			} else {
				fprintf(fp, "		42 58 moveto 45 rotate (%s) cshow -45 rotate\n", b1);
				fprintf(fp, "       50 50 moveto 45 rotate (%s) cshow -45 rotate\n", p);
				fprintf(fp, "		58 42 moveto 45 rotate (%s) cshow\n", p2);
			}
		} else {
			fprintf(fp, "		46 54 moveto 45 rotate (%s) cshow -45 rotate\n", b1);
			fprintf(fp, "		54 46 moveto 45 rotate (%s) cshow\n", p);
		}
	} else {
		fprintf(fp, "       50 50 moveto 45 rotate (%s) cshow\n", b1);
	}
	fprintf(fp, "		end\n");
	fprintf(fp, "	} bind\n");
	fprintf(fp, ">>\n");
	fprintf(fp, "matrix\n");
	fprintf(fp, "makepattern\n");
	fprintf(fp, "/JsaWatermark exch def\n");
}

/* ----- define_symbols: write postscript macros to file ------ */
void define_symbols(FILE *fp, char *Watermark, float Gray) {
	fprintf(fp, def_segno_font);
	fprintf(fp, def_tw_o);
	fprintf(fp, def_tw_h);
	fprintf(fp, def_tw_f);
	fprintf(fp, def_tw_2);
	fprintf(fp, def_tw_sixholes);
	fprintf(fp, def_misc);
	fprintf(fp, def_stringtab);
	fprintf(fp, def_jsa_std_sym);
	def_tclef(fp);
	def_bclef(fp);
	def_cclef(fp);
	def_hd1(fp);
	def_hd2(fp); 
	def_hd3(fp); 
	def_stems(fp);
	fprintf(fp, def_beam);
	def_sl(fp);
	fprintf(fp, def_dot);
	def_deco(fp);
	def_deco1(fp);
	fprintf(fp, def_hl);
	def_flags1(fp);
	def_flags2(fp);
	def_xflags(fp);
	def_acc(fp);
	fprintf(fp, def_gchord);
	def_rests(fp);
	fprintf(fp, def_bars);
	def_ends(fp);
	def_gnote(fp);
	def_csg(fp);
	fprintf(fp, def_sep);
	fprintf(fp, def_tsig);
	fprintf(fp, def_staff);
	fprintf(fp, def_typeset);
	DefWatermark(fp, Watermark, Gray);
}
