Mail Archives: geda-user/2019/03/18/11:25:38
Aw, just google up a copy of PLRM.pdf (Postscript Language Reference
Manual), it's not that bad. I do a little sometimes when I want to
print something exactly the size I plan it to be without any scaling.
Usually I write C that writes the Postscript. I can send the
Postscript directly to my HP laser printer with lpr and I've checked
some with dial calipers for accuracy.
This makes a guitar note chart (on letter size paper) but the frets
are spaced right:
/*
Guitar note chart in C and Postscript
Alan Corey 1/2018
*/
#define LEFTSTRING 15.42857142857142857148
#define PERSTRING 30.85714285714285714296
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
FILE *opf;
// for 25 inch nut to bridge, 22 frets
https://www.stewmac.com/FretCalculator.html
double frets[23] = {0,1.403,2.728,3.978,5.157,6.271,7.322,8.315,9.251,10.135,
10.969,11.757,12.500,13.202,13.864,14.489,15.079,15.636,16.161,16.657,
17.125,17.567,17.985};
double newfretloc[23]; // after scaling/translating
double stringx[6]; // horizontal positions of strings
int markerloc[] = {3,5,7,9,12,15,17,19,21}; // markers at fret numbers
// This is for standard tuning, you can replace just this part
char notes[22][6][3] = {{"E","A","D","G","B","E"}, // open
{"F","A#","D#","G#","C","F"}, // fret 1
{"F#","B","E","A","C#","F#"}, // fret 2
{"G","C","F","A#","D","G"}, // fret 3
{"G#","C#","F#","B","D#","G#"}, // fret 4
{"A","D","G","C","E","A"}, // fret 5
{"A#","D#","G#","C#","F","A#"}, // fret 6
{"B","E","A","D","F#","B"}, // fret 7
{"C","F","A#","D#","G","C"}, // fret 8
{"C#","F#","B","E","G#","C#"}, // fret 9
{"D","G","C","F","A","D"}, // fret 10
{"D#","G#","C#","F#","A#","D#"}, // fret 11
{"E","A","D","G","B","E"}, // fret 12
{"F","A#","D#","G#","C","F"}, // fret 13
{"F#","B","E","A","C#","F#"}, // fret 14
{"G","C","F","A#","D","G"}, // fret 15
{"G#","C#","F#","B","D#","G#"}, // fret 16
{"A","D","G","C","E","A"}, // fret 18
{"A#","D#","G#","C#","F","A#"}, // fret 19
{"B","E","A","D","F#","B"}, // fret 20
{"C","F","A#","D#","G","C"}, // fret 21
{"C#","F#","B","E","G#","C#"}}; // fret 22
void numfrets(void) { // number frets
int i;
double x,y;
fprintf(opf,"\n/Helvetica findfont\n");
fprintf(opf,"13.0 scalefont setfont\n");
x = stringx[5] + 50;
for (i=1; i<22; i++) {
y = newfretloc[i];
fprintf(opf,"%f %f moveto\n",x,y);
fprintf(opf,"(%i) show\n",i);
}
}
void drawnotes(void) { // write the note letters
int i,j;
double x,y;
double xofs, yofs;
fprintf(opf,"/notenames { newpath\n");
fprintf(opf,"0.5 0.0 1.0 setrgbcolor\n"); // plumish
fprintf(opf,"\n/Helvetica findfont\n");
fprintf(opf,"13.0 scalefont setfont\n");
xofs = -5;
yofs = 1;
for (i=0; i<22; i++) { // frets/notes
y = newfretloc[i];
for (j=0; j<6; j++) { // strings
x = stringx[j];
fprintf(opf,"%f %f moveto\n",(x+xofs),(y+yofs));
fprintf(opf,"(%s) show\n",notes[i][j]);
}
}
fprintf(opf,"0.0 0.0 0.0 setrgbcolor\n"); // reset to black
fprintf(opf,"} def\nnotenames stroke\n");
}
void markers(void) { // like on the side of the neck, and fretboard
int i;
double y;
double mofs = -6.0; // marker offset (font size matters)
for (i=0; i<9; i++) {
fprintf(opf,"\n/Helvetica findfont\n");
fprintf(opf,"12.5 scalefont setfont\n");
y = newfretloc[markerloc[i]] + mofs;
fprintf(opf,"100 %f moveto\n",y);
if (i == 4)
fprintf(opf,"(**) show\n"); // 12th fret double marker
else
fprintf(opf,"(*) show\n");
printf("Marker at %f\n",y);
}
}
void strings(void) { // draw strings
int i;
double n;
// markers go left of neck edge
fprintf(opf,"[1 5] 0 setdash\n");
fprintf(opf,"0 setlinewidth\n");
fprintf(opf,"/edges {\n newpath\n");
// using fixed numbers is a kludge, width change won't work
fprintf(opf," 144 54 moveto\n"); // up 1/4"
fprintf(opf," 144 756 lineto\n");
fprintf(opf," 329.142857428571 54 moveto\n");
fprintf(opf," 329.142857428571 756 lineto");
fprintf(opf,"} def\nedges stroke\n");
fprintf(opf,"/strings { newpath\n");
fprintf(opf,"0.5 setlinewidth\n"); // for actual strings
fprintf(opf,"[] 0 setdash\n");
for (i=0; i<6; i++) { // draw strings
n = LEFTSTRING + (i * PERSTRING) + 144;
fprintf(opf,"%f %f moveto\n",n,54.0);
fprintf(opf,"%f %f lineto\n",n,756.0);
stringx[i] = n;
}
fprintf(opf,"} def\n strings stroke\n");
}
void drawfrets(void) {
int i;
double y;
fprintf(opf,"/frets { newpath\n");
fprintf(opf,"3 setlinewidth\n");
fprintf(opf,"%f %f moveto\n",stringx[0],newfretloc[0]);
fprintf(opf,"%f %f lineto\n",stringx[5],newfretloc[0]);
for (i=0; i<22; i++) {
y = newfretloc[i];
fprintf(opf,"%f %f moveto\n",stringx[0],y);
fprintf(opf,"%f %f lineto\n",stringx[5],y);
}
fprintf(opf,"}\n def\n frets stroke\n");
}
void init(void) {
int i;
opf = fopen("guitar.ps","w");
if (opf == NULL) {
printf("Creating postscript file failed.\n");
exit(1);
}
fprintf(opf,"%%!PS-Adobe-\n"); // starts Postscript interpreter
// calc adjusted fret locations
for (i=0; i<22; i++) {
newfretloc[i] = 756 - ((frets[i]/17.895) * 702);
printf("%i Old loc %f new loc %f\n",i,frets[i],newfretloc[i]);
}
}
int main(void) {
init();
fprintf(opf,"0.83 0.83 0.83 setrgbcolor\n"); /// light gray
strings();
drawfrets();
fprintf(opf,"0.0 0.0 0.0 setrgbcolor\n"); // default black
markers();
drawnotes();
numfrets();
fclose(opf);
return 0;
}
On 3/17/19, Svenn Are Bjerkem (svenn DOT bjerkem AT gmail DOT com) [via
geda-user AT delorie DOT com] <geda-user AT delorie DOT com> wrote:
> On Sat, 16 Mar 2019 at 23:27, Girvin Herr (gherrl AT fastmail DOT com) [via
> geda-user AT delorie DOT com] <geda-user AT delorie DOT com> wrote:
>
>>
>> I am not into pain enough to create PostScript code directly. No thanks.
>> The tools can do that much better than I.
>>
>> Girvin
>>
>>
> You could use xcircuit to short-cut the hand typing of postscript as
> xcircuit uses postscript as its storage format :)
>
> --
> Svenn
>
--
-------------
No, I won't call it "climate change", do you have a "reality problem"? - AB1JX
Cities are cages built to contain excess people and keep them from
cluttering up nature.
Impeach Impeach Impeach Impeach Impeach Impeach Impeach Impeach
- Raw text -