efficient program to spit out SVG for guitar/uke chord frett diagram
SVG: draw dots where your fingers should go
| -rw-r--r-- | ccharter.c | 60 |
1 files changed, 27 insertions, 33 deletions
@@ -1,10 +1,13 @@ #include <stdio.h> #include <string.h> +#include <stdbool.h> +#define WIDTH 50 +#define HEIGHT 60 int main(int argc, char **argv) { - printf("<svg width=\"60px\" height=\"75px\" " + printf("<svg width=\"65px\" height=\"75px\" " "version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" overflow=\"visible\" " "style=\"stroke-width:2; stroke:black;\" " - "viewBox=\"-5 -15 50 75\" " + "viewBox=\"-5 -15 55 75\" " ">" ); int fretsCount = strlen(argv[1]); @@ -15,7 +18,7 @@ int main(int argc, char **argv) { // horizontals int i; for (i = 0; i <= 4; i++) { - printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />", + printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", 0 - 1, (i * 60/4), 0+50+1, (i * 60/4) ); @@ -23,30 +26,30 @@ int main(int argc, char **argv) { // verts for ( i = 0; i < fretsCount; i++ ) { - printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />", + printf("<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n", 0 + (i * 50 / (fretsCount - 1)), 0, 0 + (i * 50 / (fretsCount - 1)), 0 + 60 ); } // label - printf("<text x=\"%d\" y=\"%d\" style=\"stroke-width:0; text-anchor:middle;\">%s</text>", + printf("<text x=\"%d\" y=\"%d\" style=\"stroke-width:0; text-anchor:middle;\">%s</text>\n", 0 + 50/2, 0 - 5, argv[2] ); // If any dots are after 4, adjust the root to be the lowest non-zero fret // If the root is zero , thicken the top fret - /*var baseFret = 0; - var adjBaseFret = false; - var lowestFret = 0; - - for (j=0; j < chord.frets.length; j++) { - if (chord.frets.charAt(j) != 'x' && chord.frets.charAt(j) != 'X' && chord.frets.charAt(j) > 0) { - if (chord.frets.charAt(j) < lowestFret || lowestFret == 0) { - lowestFret = chord.frets.charAt(j); + int baseFret = 0; + bool adjBaseFret = false; + int lowestFret = 0; + int j; + for (j=0; j < strlen(argv[1]); j++) { + if (argv[1][j] > '0' && argv[1][j] <= '9') { + if (argv[1][j] - '0' < lowestFret || lowestFret == 0) { + lowestFret = argv[1][j] - '0'; } - if (chord.frets.charAt(j) > 4) { + if (argv[1][j] > '4') { adjBaseFret = true; } } @@ -58,32 +61,23 @@ int main(int argc, char **argv) { // dots - var dotsize = 3.5; - - var i = 0; - - for (j=0; j < chord.frets.length; j++) { - - ctx.alignText = "left"; - ctx.fillText(chord.frets.charAt(j), origin.x + (i * props.width / (fretsCount - 1)), origin.y + props.height + 12); + for (j=0; j < fretsCount; j++) { - if (chord.frets.charAt(j) == 0) { - - - } else if (chord.frets.charAt(j) == 'x' || chord.frets.charAt(j) == 'X') { - - } else { - ctx.beginPath(); - ctx.arc(origin.x + (i * props.width / (fretsCount -1)), origin.y - 7.5 + (15 * (chord.frets.charAt(j) - baseFret)), dotsize, 0, Math.PI*2,true); - ctx.closePath(); - ctx.fill(); + // TODO: Write the O or X if it is open or muted. + //ctx.alignText = "left"; + //ctx.fillText(chord.frets.charAt(j), origin.x + (i * props.width / (fretsCount - 1)), origin.y + props.height + 12); + + if (argv[1][j] > '0' && argv[1][j] <= '9') { + printf("<circle cx=\"%d\" cy=\"%d\" r=\"3\"/>\n", + (j * WIDTH) / (fretsCount - 1), (HEIGHT/4) * (argv[1][j] - '0') - baseFret - 7 + ); } i++; } // base fret indicator - if (baseFret > 0) { + /*if (baseFret > 0) { ctx.alignText = "left"; ctx.fillText(baseFret + 1, origin.x - 10, origin.y + 11); } else { |