%
% decomanual.abc - MANUAL FOR THE CREATION OF NEW SYMBOLS IN abcm2ps
% Hudson Lacerda (2004)
% 21/08/2004 (04/10/2004) (08/11/2004) (05/01/2005) (18/01/2005) (04/04/2005)
%

% Copyright (C) 2004-2005 Hudson Lacerda
% Copyright (C) 2006 Eduardo Vieira da Silva (English Translation)
% This document is released under the terms of the GNU General Public License, Version 2.
% Este documento  distribudo segundo os termos da Licena Pblica Geral do GNU, Verso 2.

% abcm2ps-4.6.7
% abcm2ps.4.8.0
% abcm2ps.4.8.8

%%setdefl 1
%%footerfont Courier 11
%%footer "$D	$P	$V"

% %lineskipfac 1.5

%%leftmargin 1.5cm
%%rightmargin 1.5cm

%%bstemdown
%%setdefl 1
%%footerfont Courier 9

% %lineskipfac 1.5

%%leftmargin 1.5cm
%%rightmargin 1.5cm

%%scale .8
%%subtitlefont Times-Italic 18

%%textfont  Times-Roman 16   % texto normal
%%setfont-1 Times-Italic 16  % nfase
%%setfont-2 Courier 16       % nome de programa
%%setfont-3 Courier-Bold 14  % cdigo
%%setfont-4 Times-Bold 24   % ttulo

%%topspace -10
%%titlespace 0
%%subtitlespace 0
%%composerspace 0
% %musicspace -5





%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! GENERAL INFORMATION !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%center $4Creating new symbols in abcm2ps
%%center Hudson Lacerda (2004-2005)
%%center English version by Eduardo Vieira da Silva (2006)

%%vskip 24pt

%%text $4(Re)definition of the PostScript operators

%%begintext justify
The score generator $2abcm2ps$0 enables the creation and modification of
$1PostScript$0 operators.  This is a very useful resource for
customizing scores,  as well as introducing
nonexistent symbols in the program.

In order to send a line of $1PostScript$0 to the output,
you can simply use $3\%\%postscript$0 in the file $2ABC$0.

The example below changes the thickness of the staff line by
redefining the operator $3dlw$0 generated by $2abcm2ps$0:

$3\%\%postscript /dlw {2.5 setlinewidth} def
%%endtext

X:1
K:C
%%multicol start
%%multicol new
%%rightmargin 11cm
%%postscript /dlw{.7 setlinewidth}def
T:original dlw (0.7pt)
CDEF FEDC |
%%multicol new
%%leftmargin 11cm
%%postscript /dlw{2.5 setlinewidth}def
T:redefined dlw (2.5pt)
CDEF FEDC |

%%multicol end
%%postscript /dlw{.7 setlinewidth}def

%%begintext justify
The following example redefine the operator $3r4$0 - which draws the
fourth note rest by using the eighth note rest as a base ($3r8$0).
%%endtext
%%begintext
$3\%\%\postscript /r4{gsave translate [-1 0 0 1 0 0] concat 0 0 r8 grestore}def
%%endtext


X:3
M:2/4
L:1/4
K:C
%%multicol start
%%multicol new
%%rightmargin 11cm
%%postscript /r4orig /r4 load def
T:original r4
%%staves (1 2)
[V:1]cd|eg|z/e/d/e/|c2|
[V:2]Cz|Gz|G,z|Cz|
%%multicol new
%%leftmargin 11cm
%%postscript /r4{gsave translate [-1 0 0 1 0 0] concat 0 0 r8 grestore}def
T:redefined r4 (mirrored eighth note)
M:2/4
L:1/4
K:C
%%staves (1 2)
[V:1]cd|eg|z/e/d/e/|c2|
[V:2]Cz|Gz|G,z|Cz|

%%postscript /r4 /r4orig load def
%%multicol end

%%begintext justify
A $1PostScript$0 code can be very useful for inserting drawings
in a very accurate position in relation to the note. The example below
enables the writing of commands in an annotation
($1annotation$0). The annotation text must begin with the character $3`:'$0
so that it may be interpreted as a command
%%endtext

%%begintext
$3\%\%postscript /cp {currentpoint}!
\%\%postscript /anshow { dup 0 get (:) 0 get ne
\%\%postscript     {/gchshow load cshow}
\%\%postscript     {dup length 1 sub 1 exch getinterval cvx exec}ifelse}!
%%endtext

%%begintext justify
By including the above code in the beginning of an$2ABC$0 file, you can
run commands like the following ones:
%%endtext

%%begintext
%%$3X:1
%%T:Commands in annotations
%%K:C
%%"@0,0:cp newpath 10 360 0 arcn stroke"CDEF \\
%%"@0,0:cp newpath 15 360 0 arcn stroke"GFED |\\
%%"@0,0:cp /yy exch def /xx exch def"C2 E2 \\
%%"@0,0:gsave xx yy lineto 2 setlinewidth stroke grestore"G4|

%%endtext

X:1
T:
%%musicspace -20
%%T:Commands in annotations
%%postscript /cp {currentpoint}!
%%postscript /xy {cp xymove cp}!
% %postscript /anshow {dup length exch dup 0 get (:) 0 get ne
% %postscript     {/gchshow load cshow pop}
% %postscript     {exch -1 add 1 exch getinterval cvx exec} ifelse}!
%%postscript	/anshow{dup 0 get (:) 0 get ne
%%postscript		{/gchshow load cshow}
%%postscript		{dup length 1 sub 1 exch getinterval cvx exec}
%%postscript		ifelse}!
K:C
"@0,0:cp newpath 10 360 0 arcn stroke"CDEF \
"@0,0:cp newpath 15 360 0 arcn stroke"GFED |\
"@0,0:cp /yy exch def /xx exch def"C2 E2 \
"@0,0:gsave xx yy lineto 2 setlinewidth stroke grestore"G4|


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! NEW SYMBOLS (DECORATIONS) !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%newpage
%%text $4New symbols (\%\%deco)$0

%%begintext justify
Besides the possibilities that were already shown in the given
examples, $2abcm2ps$0 allows the addition of new decorations (symbols
such as accents, dynamic, articulations, etc.).  This is done through
the command $3\%\%deco$0. The syntax is the following:

$3\%\%deco <name> <type> <ps> <height> <widthL> <widthR> [text]

$0
$3<name>$0 is the symbol identifier;

$3<type>$0 is a number form 0 to 7 which defines the type of symbol;

$3<ps>$0 is the name of the $1PostScript$0 operator to be run;

$3<height>$0 is the vertical space taken by the symbol in points;

$3<widthL>$0 and $3<widthR>$0 indicates the left and right space of the symbol
              (Since $2abcm2ps-4.8.2$0, it has only worked for type 6 decorations);

$3[text]$0 is a (optional) text to be used by the $1PostScript$0 operator
              (used only by type 3, 4 and 6 decorations).
%%endtext


%%begintext
The $3<type>$0 of the symbols defines its positioning

$20:$0 close to the note head, like $3!tenuto!$0 or $3.$0 ($1staccato$0);
$22:$0 on the left of a note head, like $3!slide!$0;
$22:$0 on the left of a chord, like $3!arpeggio!$0;
$23, 4:$0 generic expressions above and below the staff;
$25:$0 long symbol above the staff, like $3!trill(!$0 or $3!trill)!$0;
$26:$0 generic (usually below the staff);
$27:$0 long symbol below the staff, like $3!crescendo(!$0 or $3!crescendo)!$0.

%%endtext

%%begintext justify
Symbols of the 0 through 2 type are associated with the notes, and are placed within the staff.
Types 3 to 5 are placed outside the staff, although they are associated with the notes.
In turn, the types 6 and 7 are associated to the staff.

There is steel another special category of decorations: when its $3<name>$0
begins with $3head-$0, the decoration replaces the note head in which
it is used.

%%endtext


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 0 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%text $4How to create a type 0 decoration
%%begintext justify
Type 0 decorations are placed close to the note head
Two examples are $3!tenuto!$0 and $3!dot!$0.
The $1PostScript$0 operator must use two arguments: the coordinates
$3<x>$0 and $3<y>$0, which determine the position of the symbol The command $3\%\%deco$0
must not make use of the $3[text]$0 argument.

Here is an example (close to the note head):
%%endtext

%%begintext
$3\%\%postscript /example0 {  moveto
\%\%postscript              -3 -2 rmoveto
\%\%postscript               6  2 rlineto
\%\%postscript              -6  2 rlineto
\%\%postscript              stroke
\%\%postscript           } def
%%
\%\%deco ex0 0 example0 5 0 0
%%
%%X:1
%%K:C
%%!ex0!DEFG !ex0!ABcd | GAB!ex0!c def!ex0!g |
%%endtext

% %postscript /example0 {2 0 360 arc fill} def

X:1
%%postscript /example0{moveto -3 -2 rmoveto 6 2 rlineto -6 2 rlineto stroke}def
%%deco ex0 0 example0 6 0 0
%%musicspace -20
K:C
!ex0!DEFG !ex0!ABcd | GAB!ex0!c def!ex0!g |

%%newpage


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 1 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%text $4How to create a type 1 decoration
%%begintext justify
Type 1 decorations are placed on the left of the note head
An example is $3!slide!$0.
Just like the procedure for type 0, $1PostScript$0 operator must use
two arguments: the coordinates a$3<x>$0 and $3<y>$0, which determine the
position of the symbol The command $3\%\%deco$0 must not make use of the
 $3[text]$0 argument. The argument $3<height>$0 is irrelevant,
which can simply be zero.
Notice that the position of the symbol is affected by the
presence of an accidental.

Here is an example (half moon on the left of the note):
%%endtext

%%begintext
$3\%\%postscript /example1 {  newpath
\%\%postscript              exch 1 add exch
\%\%postscript              5 100 260 arc
\%\%postscript              1.2 setlinewidth stroke dlw
\%\%postscript           } def
%%
\%\%deco ex1 1 example1 0 0 0
%%
%%X:1
%%K:C
%%CD!ex1!^D!ex1!E ed!ex1!_d!ex1!c |
%%endtext

X:1
%%postscript /example1 {  newpath
%%postscript              exch 1 add exch
%%postscript              5 100 260 arc
%%postscript              1.2 setlinewidth stroke dlw
%%postscript           } def
%%
%%deco ex1 1 example1 0 0 0
%%
%%continueall
%%musicspace -20
K:C
CD!ex1!^D!ex1!E ed!ex1!_d!ex1!c |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 2 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%vskip 24pt
%%text $4How to create a type 2 decoration
%%begintext justify
Type 2 decorations are placed on the left of chord and their height spans the whole extent of the chord.
An example is $3!arpeggio!$0.

The $1PostScript$0 operator must use three argument: the minimum height
of the symbol and vertical and horizontal coordinates of the
lowest symbol.

The command $3\%\%deco$0 must not make use of the $3[text]$0 argument  The
The $3<height>$0 height is used to define the minimal height of the
symbol (since $2abcm2ps-4.8.8$0).

The positioning of the symbol is affected by the presence of accidentals.

Here is an example (brace):
%%endtext

%%begintext
$3\%\%postscript /exemplo2 {   moveto
\%\%postscript               4 0 rmoveto
\%\%postscript              -4 0 rlineto 0 exch rlineto
\%\%postscript               4 0 rlineto 1.6 setlinewidth stroke dlw
\%\%postscript           } def
%%
\%\%deco ex2 2 exemplo2 6 0 0
%%
%%X:1
%%L:1/4
%%K:C
%%!ex2!C !ex2![CEG] !ex2![C_EG] !ex2![^G,=g] |\\
%%!ex2!c !ex2![ceg] !ex2![c_eg] !ex2![^G=g'] |
%%endtext

X:1
%%postscript /exemplo2 {   moveto
%%postscript               4 0 rmoveto
%%postscript              -4 0 rlineto 0 exch rlineto
%%postscript               4 0 rlineto 1.6 setlinewidth stroke dlw
%%postscript           } def
%%deco ex2 2 exemplo2 6 0 0
%%musicspace 0pt
L:1/4
K:C
!ex2!C !ex2![CEG] !ex2![C_EG] !ex2![^G,=g] |\
!ex2!c !ex2![ceg] !ex2![c_eg] !ex2![^G=g'] |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 3 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%newpage
%%text $4How to create a type 3 decoration
%%begintext justify
Type 3 decorations are usually placed above the staff.  Some
examples are: $3!accent!$0, $3!segno!$0 e $3!mordent!$0.  
The $1PostScript$0 operator must use two or three arguments:
the horizontal and vertical coordinates and, optionally, a text $1string$0 (in case
$3\%\%deco$0 command should use the argument $3[text]$0).

Here is an example (not-accent):
%%endtext

%%begintext
$3\%\%postscript /exemplo3a {  newpath
\%\%postscript               7.5 add
\%\%postscript               5 180 360 arc
\%\%postscript               stroke
\%\%postscript            } def
%%
\%\%deco ex3a 3 exemplo3a 10 0 0
%%
%%X:1
%%K:C
%%!ex3a!CDEF !ex3a!FEDC | !ex3a!cdef !ex3a!fedc | 
%%endtext

X:1
%%postscript /exemplo3a {  newpath
%%postscript               7.5 add
%%postscript               5 180 360 arc
%%postscript               stroke
%%postscript            } def
%%
%%deco ex3a 3 exemplo3a 10 0 0
%%
%%musicspace 0pt
K:C
!ex3a!CDEF !ex3a!FEDC |\ %\
!ex3a!cdef !ex3a!fedc | 


%%text Now an example with text (string indications):

%%begintext
$3\%\%postscript /exemplo3b {  4 add 2 copy
\%\%postscript               newpath 4 add 7 0 360 arc stroke
\%\%postscript               moveto
\%\%postscript               /Helvetica-Bold 12 selectfont
\%\%postscript               showc
\%\%postscript            } def
%%
\%\%deco ex3b_E 3 exemplo3b 16 0 0 E
\%\%deco ex3b_B 3 exemplo3b 16 0 0 B
\%\%deco ex3b_G 3 exemplo3b 16 0 0 G
\%\%deco ex3b_D 3 exemplo3b 16 0 0 D
\%\%deco ex3b_A 3 exemplo3b 16 0 0 A
%%
%%X:1
%%L:1/1
%%K:C treble-8
%%!ex3b_E!e !ex3b_B!B !ex3b_G!G !ex3b_D!D !ex3b_A!A, !ex3b_E!E, |
%%endtext

X:1
%%postscript /exemplo3b { 4 add 2 copy
%%postscript               newpath 4 add 7 0 360 arc stroke
%%postscript               moveto
%%postscript               /Helvetica-Bold 12 selectfont
%%postscript               showc
%%postscript            } def
%%
%%deco ex3b_E 3 exemplo3b 16 0 0 E
%%deco ex3b_B 3 exemplo3b 16 0 0 B
%%deco ex3b_G 3 exemplo3b 16 0 0 G
%%deco ex3b_D 3 exemplo3b 16 0 0 D
%%deco ex3b_A 3 exemplo3b 16 0 0 A
%%
%%musicspace 0pt
L:1/1
K:C treble-8
!ex3b_E!e !ex3b_B!B !ex3b_G!G !ex3b_D!D !ex3b_A!A, !ex3b_E!E, |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 4 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4How to create a type 4 decoration
%%begintext justify
Type 3 decorations are usually placed below the staff.

Just like the procedure for types 3 and 6, the $1PostScript$0 operator must 
use two or three arguments: the horizontal and vertical coordinates
and, optionally, a text $1string$0 (in case,   $3\%\%deco$0 command
should use a the argument $3[text]$0).

An example of its utilization is the creation of symbols for dynamics that are close to the
notes (instead of being horizontally aligned). The $3pf$0operator
from $2abcm2ps$0 (fit for printing dynamics symbols) is
used in the following example. (See also ``How to create a type 6 decoration.)

%%endtext

%%begintext
$3\%\%deco ex4 4 pf 20 0 0 p
%%
%%X:1
%%K:C treble
%%!ex4!E,Gd!ex4!f' |
%%endtext

X:1
%%deco ex4 4 pf 20 0 0 p
%%continueall
%%musicspace 0pt
K:C treble
!ex4!E,Gd!ex4!f' |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 6 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4How to create a type 6 decoration
%%begintext justify
Type 3 decorations are usually placed below the staff.  
Typical examples are the dynamics symbols, such as: $3!p!$0, $3!mf!$0 and 
$3!ff!$0.

Just like the procedure for types 3 and 4, the $1PostScript$0 operator must use two 
or three arguments: the horizontal and vertical coordinates and,
optionally, a text $1string$0 (in case,   $3\%\%deco$0 command
 should use the argument $3[text]$0).

A simple and useful example is the implementation of the dynamics $1mp$0.
The  $3pf$0 operator from $2abcm2ps$0 (fit for printing dynamics symbols)
is used in the following example. Notice that the type 6 decorations,
unlike type 4, are horizontally aligned
%%endtext

%%begintext
$3\%\%deco ex6 6 pf 20 10 8 mp
%%
%%X:1
%%K:C treble
%%!ex6!E,Gd!ex6!f' |
%%endtext

X:1
%%deco ex6 6 pf 20 10 8 mp
%%continueall
%%musicspace 0pt
K:C treble
!ex6!E,Gd!ex6!f' |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 5 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4How to create a type 5 decoration
%%begintext justify
Type 5 decorations are long signs placed above the
staff. An example is the long trill starting with $3!trill(!$0 and
ending with $3!trill)!$0.

In the decoration which starts the symbol, the field  $3<ps>$0 
($1PostScript$0 operator) of the  3\%\%deco$0, must be $3`-'$0. The
$3<name>$0 of the initial decoration typically ends with $3`('$0,
where as the name of the final decoration ends with $3`)'$0.

The $1PostScript$0 operator of the final decoration is the one in charge of the drawing,
and receives three arguments: the span of the symbol and the
horizontal and vertical coordinates of the first part of the symbol.

Here is an example (Ottava brackets):
%%endtext

%%begintext
$3\%\%postscript /exemplo5 {
\%\%postscript              moveto -3 3 rmoveto
\%\%postscript              /Times-BoldItalic 12 selectfont (8) show
\%\%postscript              gsave
\%\%postscript                 2 6 rmoveto
\%\%postscript                 [3] 0 setdash 12 add 0 rlineto
\%\%postscript                 currentpoint stroke
\%\%postscript                 moveto [] 0 setdash 0 -3 rlineto stroke
\%\%postscript              grestore
\%\%postscript           } def
%%endtext
%%begintext
$3\%\%deco ex5( 5 - 10 0 0
\%\%deco ex5) 5 exemplo5 20 0 0
%%
%%X:1
%%K:C
%%cdefgab!ex5(!cdefgab!ex5)!c' |
%%endtext

X:1
%%postscript /exemplo5 {
%%postscript              moveto -3 3 rmoveto
%%postscript              /Times-BoldItalic 12 selectfont (8) show
%%postscript              gsave
%%postscript                 2 6 rmoveto
%%postscript                 [3] 0 setdash 12 add 0 rlineto currentpoint stroke
%%postscript                 moveto [] 0 setdash 0 -3 rlineto stroke
%%postscript              grestore
%%postscript           } def
%%
%%deco ex5( 5 - 10 0 0
%%deco ex5) 5 exemplo5 20 0 0
%%
%%musicspace 0pt
K:C
cdefgab!ex5(!cdefgab!ex5)!c' |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE 7 !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4How to create a type 7 decoration
%%begintext justify
Type 7 decorations are long signs placed below the
staff, such as the dynamics symbols  $3!crescendo(!$0, $3!crescendo)!$0,
$3!diminuendo(!$0 and $3!diminuendo)!$0.

They are created in the same way as the type 5 decorations, except 
that the type 7 decorations are printed below the staff.

Here is an example (Ottava bassa):
%%endtext

%%begintext
$3\%\%postscript /exemplo7 {
\%\%postscript              moveto -6 3 rmoveto
\%\%postscript              /Times-BoldItalic 12 selectfont (8) show
\%\%postscript              gsave
\%\%postscript                 2 2 rmoveto
\%\%postscript                 [3] 0 setdash 12 add 0 rlineto
\%\%postscript                 currentpoint stroke
\%\%postscript                 moveto [] 0 setdash 0 3 rlineto stroke
\%\%postscript              grestore
\%\%postscript           } def
%%endtext
%%begintext
$3\%\%deco ex7( 7 - 10 0 0
\%\%deco ex7) 7 exemplo7 20 0 0
%%
%%X:1
%%K:C
%%cBAGFED!ex7(!cBAGFED!ex7)!C |
%%endtext

X:1
%%postscript /exemplo7 {
%%postscript              moveto -6 -3 rmoveto
%%postscript              /Times-BoldItalic 12 selectfont (8) show
%%postscript              gsave
%%postscript                 2 2 rmoveto
%%postscript                 [3] 0 setdash 12 add 0 rlineto currentpoint stroke
%%postscript                 moveto [] 0 setdash 0 3 rlineto stroke
%%postscript              grestore
%%postscript           } def
%%
%%deco ex7( 7 - 10 0 0
%%deco ex7) 7 exemplo7 20 0 0
%%
%%musicspace 0pt
K:C
cBAGFED!ex7(!cBAGFED!ex7)!C |



%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! TYPE `head-xxx': NOTE HEADS !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4How to create a head-xxx (note head) decoration$0
%%begintext justify
A decoration whose $3<name>$0 begins with $3head-$0 replaces the note
head in which it is used. $3head-xxx$0 decorations are declared as
being of any type (from 0 through 7), using the proper parameters for
the specified type.
%%endtext
%%begintext justify
Two useful examples are the diamond shaped note heads (harmonic) and
in the shape of $3x$0 (percussion). In this example, the $3x$0 is
actually a $1double sharp$0 (drawn by the $1PostScript$0 operator
$3dsh0$0, generated by $2abcm2ps$0). Notice also the effect of a
$3head-xxx$0 decoration in a chord: it is applied to all the notes of
the chord.
%%endtext

%%begintext
$3\%\%postscript /harm{gsave T 40 rotate
\%\%postscript 	           .25 dup setlinewidth
\%\%postscript 	           -3 2.3 3 -1 roll 2 div sub M 6 0 RL
\%\%postscript 	           0 -4.6 RM                   -6 0 RL
\%\%postscript 	           stroke
\%\%postscript             1.4 dup setlinewidth
\%\%postscript 	           3 1 index 2 div sub 2.3 M 0 -4.6 RL
\%\%postscript             -6 add 0 RM               0  4.6 RL
\%\%postscript 	           stroke
\%\%postscript       grestore}!
%%endtext
%%begintext
$3\%\%deco head-h 0 harm 0 0 0
\%\%deco head-x 0 dsh0 0 0 0
%%endtext
%%begintext
%%$3X:1
%%K:C
%%!head-x!B!head-h!G!head-x!D[Ce]-[Ce]2 !head-h![gbe']2 |
%%endtext

X:1
K:C
%%continueall 1
% %postscript /harm{M -3 0 RM 3 3 RL 3 -3 RL -3 -3 RL closepath stroke}!
%%postscript /harm{gsave T 40 rotate
%%postscript 		.25 dup setlinewidth
%%postscript 		-3 2.3 3 -1 roll 2 div sub M 6 0 RL
%%postscript 		0 -4.6 RM                   -6 0 RL
%%postscript 		stroke
%%postscript 		1.4 dup setlinewidth
%%postscript 		3 1 index 2 div sub 2.3 M 0 -4.6 RL
%%postscript 		-6 add 0 RM               0  4.6 RL
%%postscript 		stroke
%%postscript       grestore}!
%%deco head-h 0 harm 0 0 0
%%deco head-x 0 dsh0 0 0 0
!head-x!B!head-h!G!head-x!D[Ce]-[Ce]2 !head-h![gbe']2 |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! DECORATIONS IN SINGLE NOTES IN CHORDS !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4Decorations in single notes in chords
%%begintext justify
A decoration can be applied to a single note of a
chord ($1i.e.$0 a note inside $3`['$0 and $3`]'$0). In this
case, a regular decoration could be misplaced. Therefore
you should resort to a special $1PostScript$0 operator (and a special decoration)
in order to use it in a single note of a chord.

As an example, a mordent (based on the $3lmrd$0 operator of 
$2abcm2ps$0) which is positioned on the left of the note head  The symbol
was declared as a type 1 decoration in order to gain a little bit of 
space on the left.
%%endtext

%%begintext
$3\%\%postscript /morde{exch 11 sub exch 4 sub lmrd}!
%%endtext
%%begintext
$3\%\%deco morde 1 morde 0 0 0
%%endtext
%%begintext
%%$3X:1
%%K:C
%%[CG!morde!ce]2 [G,GBd]2 [A,E!morde!Ac]4 |
%%endtext

X:1
%%postscript /morde{exch 11 sub exch 4 sub lmrd}!
%%deco morde 1 morde 0 0 0
K:C
%%continueall 1
[CG!morde!ce]2 [G,GBd]2 [A,E!morde!Ac]4 |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! MICROTONAL ACCIDENTALS !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4Microtonal accidentals$0
%%begintext justify
With $2abcm2ps$0 it is possible to have special accidentals for microtonalism.
Micro tonal pitches are indicated by a fraction after an
accidental, like $3^3/4c$0. By $1default$0, the numerator is set to
1, and the denominator to 2 ($3^/c$0 is the same as $3^1/2c$0). The
numerator and denominator must be whole numbers from one to 256.
%%endtext
%%begintext justify
1/2 and 3/2 sharps or flats are supported (for quarter-tones). For
other values, new $1PostScript$0 operators must be created (with
$3\%\%postscript$0). The name of a $1PostScript$0 operator for an
accidental must be:

$0
%%endtext
%%begintext obeylines
$3<accidental_type><micro_value>$0
%%endtext
%%begintext justify
where $3<accidental_type>$0 will be: $3sh$0 (sharp), $3ft$0
(flat), $3nt$0 (natural), $3dsh$0 (double sharp) or $3dft$0
(double flat).

$3<micro_value>$0 is a number calculated from the fraction as:

$2(numerator-1)*256 + (denominator-1)$0.
%%endtext
%%begintext justify
In the following example, the first line of music employs the
accidentals which are available in $2abcm2ps$0.  The second line
employs alternative accidentals: a combination of a sharp or a flat
with an arrow In the $2ABC$0 code for this example, an accidental with
$39/$0 (or $39/2$0) uses an up arrow, and an accidental with $36/$0
(or $36/2$0) uses a down arrow.

Notice the value of $3<micro_value>$0 within the name of the
$1PostScript$0 operators, calculated for the fractions $39/2$0 and $36/2$0:

$2($39$2-1)*256 + ($32$2-1) = $32049$2

($36$2-1)*256 + ($32$2-1) = $31281$0

Here is the code:
%%endtext

%%begintext
$3\%\%postscript /seta {M 1.7 -7 RL -3.4 0 RL fill}!
\%\%postscript /sh2049 {2 copy sh0 exch 1.5 add exch 15 add seta}! \% ^9/2
\%\%postscript /sh1281 {2 copy sh0 exch 1.2 sub exch 15 sub        \% ^6/2
\%\%postscript          gsave T 180 rotate 0 0 seta grestore}!
\%\%postscript /ft2049 {2 copy ft0 exch 1.8 sub exch 14 add seta}! \% _9/2
\%\%postscript /ft1281 {2 copy ft0 exch 1.8 sub exch 11 sub        \% _6/2
\%\%postscript          gsave T 180 rotate 0 0 seta grestore}!
%%endtext
%%begintext
%%$3X:1
%%M:none
%%L:1/2
%%K:C
%%=C  ^/C ^C ^3/C =D  _/D _D _3/D =C |
%%=C ^6/C ^C ^9/C =D _9/D _D _6/D =C |
%%endtext

X:1
%%postscript /seta{M 1.7 -7 RL -3.4 0 RL fill}!
%%postscript /sh2049{2 copy sh0 exch 1.5 add exch 15 add seta}! % ^9/2
%%postscript /sh1281{2 copy sh0 exch 1.2 sub exch 15 sub
%%postscript         gsave T 180 rotate 0 0 seta grestore}! % ^6/2
%%postscript /ft2049{2 copy ft0 exch 1.8 sub exch 14 add seta}! % _9/2
%%postscript /ft1281{2 copy ft0 exch 1.8 sub exch 11 sub
%%postscript         gsave T 180 rotate 0 0 seta grestore}! % _6/2
M:none
L:1/2
K:C
=C  ^/C ^C ^3/C =D  _/D _D _3/D =C |
=C ^6/C ^C ^9/C =D _9/D _D _6/D =C |


%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! SOME ESPECIAL OPERATORS !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%text $4Some special operators
%%vskip 24pt
%%text $4defl
%%begintext justify
The operator $3defl$0 (introduced with $2abcm2ps-4.8.0$0) is a
flag, which indicates:

- the state of a type 5 or 7 decoration (beginning or ending);

- the direction of the note tail (up or down).

This operator is generated/refreshed for each note containing the decoration

In order to use it, from $2abcm2ps-4.9.4$0 on, it is necessary to set the
 $3\%\%setdefl command to true$0.
%%endtext
%%begintext justify
The first bit to the right $3defl$0 indicates if a long decoration
is starting ($30$0) or if it is a continuation  ($31$0) (refers to the
left end of the decoration);
%%endtext
%%begintext justify
The second bit, from the right  indicates if the long decoration is
ending ($30$0) or if it will be continued on the next line ($31$0)
(refers to right end of the decoration);
%%endtext
%%begintext justify
The third bit from the right indicates if the tail is up ($30$0) or
down ($31$0). It is useful to create decorations that will change
depending on the direction of the tail (for example, one that will be
drawn right on tail itself).
%%endtext
%%begintext justify
So, in order to check the state of the first bit (on the left end
of a long decoration) you can use a sequence of $1PostScript$0 with the
following structure:
%%endtext
%%begintext obeylines
$3defl 1 and 0 eq {
    \% procedure in case the left end is the beginning of the decoration
}{
    \% \% procedure in case the left end is the continuation of the decoration
} ifelse$0

In order to check if the second bit (right end of a long decoration):

$3defl 2 and 0 eq {
    \% procedure in case the right end is the end of the decoration
}{
    \% procedure in case the right end is the continuation of the decoration
} ifelse$0

And in order to check the third bit (tail direction):

$3defl 4 and 0 eq {
    \% procedure in case the tail is down
}{
    \% procedure in case the tail is up
} ifelse$0
%%endtext

%%vskip 24pt
%%text $2Examples:
%%begintext justify
The example below uses $3defl$0 to determine where the tail is
so that a $3x$0 ($1sprechgesang$0) can be drawn on it.

The decoration is declared is being one of type 1, because its position is always
relative to the note head. As a side effect, $2abcm2ps$0 leaves
an extra space on the left of the note (where it would usually be drawn)
such type of decoration). In case you don't want this extra space, the you can
declare a type 0 (or 3) and always use such decoration (together with the
note) between square bracket, as in a chord.
%%endtext

%%begintext obeylines
$3\%\%setdefl true
\%\%postscript /sprgsg{gsave T
\%\%postscript         defl 4 and 0 eq{1.5 -9}{8.5 9}ifelse T
\%\%postscript         .8 dup scale 0 0 dsh0 grestore}!

\%\%deco sprgsg 1 sprgsg 0 0 0
%%endtext

%%begintext obeylines
%%$3X:1
%%K:C
%%z4 !sprgsg!C !sprgsg!E !sprgsg!G2 | !sprgsg!c4 z4 |]
%%endtext

X:1
%%continueall
%%setdefl true
%%postscript /defl 0 def
%%postscript /sprgsg{gsave T defl 4 and 0 eq{1.5 -9}{8.5 9}ifelse T
%%postscript         .8 dup scale 0 0 dsh0 grestore}!
%%deco sprgsg 1 sprgsg 0 0 0
K:C
z4 !sprgsg!C !sprgsg!E !sprgsg!G2 | !sprgsg!c4 z4 |]

%%begintext justify
In the following example an bracket below the staff is implemented (which
can be used as indication for piano pedal). The beginning and the end
of this long decoration are detected thanks to the $3defl$0 operator.
Notice  (in the score) that the bracket that starts in the last measure of the
of the first line remains `open', as well as the left side of its
continuation on the next line.

The fist line of $1PostScript$0 code defines the $3defl$0 operator 
with zeros. This is totally unnecessary (and has no effect) with
$2abcm2ps-4.8.0$0 or more recent, but makes the code compatible with
earlier versions.  When you use an earlier version of the program, the decoration will always be
be drawn with a beginning and an end.
%%endtext

%%begintext
%%$3\%\%setdefl 1
\%\%postscript /defl 0 def
\%\%postscript /bracket { exch 3 sub exch 1.2 setlinewidth
\%\%postscript             defl 1 and 0 eq{4 add M 0 -4 RL}{M}ifelse
\%\%postscript             7 add 0 RL
\%\%postscript             defl 2 and 0 eq{0 4 RL}if
\%\%postscript             stroke dlw}!
%%endtext
%%begintext
%%$3\%\%deco bracket( 7 - 12 0 0
\%\%deco bracket) 7 bracket 12 0 0
%%endtext
%%begintext
%%$3X:1
%%K:Am clef=treble-8
%%\%
%%!bracket(! A,CEA ceac'  |  e'a'e'c' aecA  |\\
%%!bracket)! !bracket(! FA,CF Acfa  |  c'f'c'a fcAF  !bracket)! |\\
%%!bracket(! DFAd fad'af  |
%%\%
%%dafd AFDA,  !bracket)! !bracket(! |\\
%%E,B,E^G Be^gb  |  !bracket)! !bracket(! e'b'e'b eBEE,  |\\
%%A,EAc eac'e'  |  !bracket)! a'2 z2 z4  |]
%%endtext

X:1
%%setdefl 1
%%postscript /defl 0 def
%%postscript /bracket { exch 3 sub exch 1.2 setlinewidth
%%postscript             defl 1 and 0 eq{4 add M 0 -4 RL}{M}ifelse
%%postscript             7 add 0 RL
%%postscript             defl 2 and 0 eq{0 4 RL}if
%%postscript             stroke dlw}!
%%deco bracket( 7 - 12 0 0
%%deco bracket) 7 bracket 12 0 0
K:Am clef=treble-8
!bracket(!A,CEA ceac' | e'a'e'c' aecA | \
!bracket)!!bracket(!FA,CF Acfa | c'f'c'a fcAF !bracket)!| \
!bracket(!DFAd fad'af |
dafd AFDA, !bracket)!!bracket(!| \
E,B,E^G Be^gb | !bracket)!!bracket(!e'b'e'b eBEE, | \
A,EAc eac'e' | !bracket)!a'2 z2 z4 |]

%%begintext justify

The same principles could be applied to improve the examples
of the type 5 and type 7 decorations given earlier (lines for octave above
and below).
%%endtext






%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% % ! CHANGING THE NOTE HEADS GLOBALLY !
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% %newpage
%%vskip 24pt
%%vskip 24pt
%%text $4Changing the note heads globally
%%begintext justify
In some cases it is desirable to change globally the note heads in
order to `stylize' the score or to create special resources, for
example.  In order to accomplish this, you can just redefine the
$1PostScript$0 operators which are in charge of drawing the note heads.
%%endtext

%%textfont Times-Roman
%%begintext obeylines
The operators in $2abcm2ps$0 that draw note heads are:

$3hd     $0Black head, for fourth notes and shorter notes$3
Hd     $0Half note$3
HD     $0Whole note$3
HDD    $0Breve (rounded)$3
breve  $0Breve (square)$3
longa  $0Longa
%%endtext
%%begintext obeylines
$3pshhd  $0Used in a note with a sharp, when the clef is $3perc $2(abcm2ps-4.4.5)
$3pflhd  $0Used in a note with a flat, when the clef is $3perc $2(abcm2ps-4.4.5)
$3ghd    $0Black head for grace notes (ornaments)
%%endtext

%%begintext justify
$1All$0 of these note heads store their position through the
$3x$0 and $3y$0 operators. They are used to position other
symbols, like tails and augmentation dots

This implies that, in order to write other versions for the note
heads, it is imperative to define $3x$0 e $3y$0. There are at least
two ways of accomplishing this:

(1) Use the operator $3xymove$0, which moves to the ($1x,y$0) point
and saves its coordinates.
%%endtext
%%begintext justify
(2) Define $3x$0 and $3y$0 `manually', in case you don't want to move
the ($1x,y$0) point. This can be accomplished with:
%%endtext
%%begintext justify
$3/y exch def /x exch def$0
%%endtext
%%begintext justify
(which takes the two values on top of the stack and saves them as
$3x$0 as $3y$0);
%%endtext
%%begintext justify
or with:
%%endtext
%%begintext justify
$3/x 2 index def /y 1 index def$0
%%endtext
%%begintext justify
(which takes the two values on top of the stack $1without deleting them$0).
%%endtext

%%begintext justify
Here is an example of redefining the note head in order to draw a
melodic contour:
%%endtext

%%begintext obeylines
$3\%\%postscript /hdo/hd load bind def     \% stores a copy of the original `hd' 
\%\%postscript /xx 10000 def /yy 0 def   \% initialize `previous note'
\%\%postscript /hd { xymove              \% links to the previous note (left)
\%\%postscript 	     x xx gt {xx yy M x y lineto stroke} if
\%\%postscript 	     /xx x def /yy y def}!
%%endtext

%%begintext obeylines
%%$3X:1
%%L:1/8
%%M:none
%%K:C clef=perc stafflines=1  \% (stafflines were introduced in abcm2ps-4.8.6)
%%[M:4/4] AFgG, ad'be' | [M:7/16] c''/a/e/b/ C/B/A/ | [M:3/8] E,3 |
%%\%\%postscript /hd/hdo load bind def     \% restores original `hd' 
%%endtext

X:1
L:1/8
M:none
K:C clef=perc stafflines=1  % (stafflines were introduced in abcm2ps-4.8.6)
%%continueall 0
%%postscript /hdo/hd load bind def % saves a copy of the original `hd'
%%postscript /xx 10000 def /yy 0 def % initializes
%%postscript /hd { xymove % joins this note with the left one
%%postscript 	   x xx gt {xx yy M x y lineto stroke}if
%%postscript 	   /xx x def /yy y def}!
[M:4/4] AFgG, ad'be' | [M:7/16] c''/a/e/b/ C/B/A/ | [M:3/8] E,3 |
%%postscript /hd/hdo load bind def
% [M:4/4] AFgG, ad'be' | [M:7/16] c''/a/e/b/ C/B/A/ | [M:3/8] E,3 |

% %newpage
% %vskip 24pt
% %text $4Some special operators
% %begintext justify
% %endtext

%%vskip 20pt
%%begintext
%%$1Copyright (C) 2004-2005 Hudson Lacerda
%%Copyright (C) 2006 Eduardo Vieira da Silva (English Translation)
%%This document is released under the terms of the GNU General Public License, Version 2.
%%Este documento  distribudo segundo os termos da Licena Pblica Geral do GNU, Verso 2.
%%endtext


% %vskip 20pt
% %center $2- - TO DO: - -$0
% %text $3- dlsym, y0, y1 OPERATORS etc.
% %text $3- defl OPERATORS (LONG DYNAMICS SYMBOLS/HASTES), y0, y1 etc.
% %text $3- DECORAES EM NOTAS INDIVIDUAIS DE ACORDES
% %text $3- COMO MUDAR AS CABEAS DAS NOTAS (!head-x!)
% %text $3- COMO MUDAR AS CABEAS DAS NOTAS MODIFICANDO hd, Hd, HD etc.
% %text $3- COMO CRIAR NOVOS ACIDENTES (MICROTONALISMO)
% %text $3- SOBRE O ARQUIVO syms.c
% %text $3- BREVE INTRODUO A POSTSCRIPT
% %text $3- SOBRE ARQUIVOS DE FORMATO


% %postscript 100 -100 moveto currentpoint 2 copy stc moveto
% %postscript 0 40 40 40 40 0 rcurveto
% %postscript 0 30 -40 30 -40 0 rcurveto fill %stroke
% %postscript /Times-Roman findfont 30 scalefont
% %postscript [-1 -.7 0 1 .7 0 ] makefont setfont (texto) show




