From: larryh@cabezon.uucp (Larry Huntley)
Newsgroups: alt.guitar,rec.music.makers.guitar
Subject: Fret position calculator
Date: 12 Nov 92 21:54:44 GMT
Article-I.D.: cabezon.1992Nov12.215444.25558
Organization: Logic Modeling Corporation of Beaverton Oregon


	Yes, I know this is getting repetitive, but I worked on this over
	lunch, and made it more useful.

	An example: a 34" scale for bass guitar, 24 frets, expressed in
	millimeters:

src 70> frets -m 863.6 24
Scale Length: 863.60 mm; Number of Frets: 24
Fret  1: 48.470 mm from previous fret; 48.470 mm from nut.
Fret  2: 45.750 mm from previous fret; 94.220 mm from nut.
Fret  3: 43.182 mm from previous fret; 137.402 mm from nut.
Fret  4: 40.758 mm from previous fret; 178.160 mm from nut.
Fret  5: 38.471 mm from previous fret; 216.631 mm from nut.
Fret  6: 36.312 mm from previous fret; 252.943 mm from nut.
Fret  7: 34.274 mm from previous fret; 287.216 mm from nut.
Fret  8: 32.350 mm from previous fret; 319.566 mm from nut.
Fret  9: 30.534 mm from previous fret; 350.101 mm from nut.
Fret 10: 28.821 mm from previous fret; 378.921 mm from nut.
Fret 11: 27.203 mm from previous fret; 406.124 mm from nut.
Fret 12: 25.676 mm from previous fret; 431.800 mm from nut.
Fret 13: 24.235 mm from previous fret; 456.035 mm from nut.
Fret 14: 22.875 mm from previous fret; 478.910 mm from nut.
Fret 15: 21.591 mm from previous fret; 500.501 mm from nut.
Fret 16: 20.379 mm from previous fret; 520.880 mm from nut.
Fret 17: 19.235 mm from previous fret; 540.116 mm from nut.
Fret 18: 18.156 mm from previous fret; 558.272 mm from nut.
Fret 19: 17.137 mm from previous fret; 575.408 mm from nut.
Fret 20: 16.175 mm from previous fret; 591.583 mm from nut.
Fret 21: 15.267 mm from previous fret; 606.850 mm from nut.
Fret 22: 14.410 mm from previous fret; 621.261 mm from nut.
Fret 23: 13.601 mm from previous fret; 634.862 mm from nut.
Fret 24: 12.838 mm from previous fret; 647.700 mm from nut.
src 71> 

	There's some holes in the code, but anyone who wants to is welcome
	to rework it as they see fit.  I hope someone finds it helpful.

	To compile:

		cc frets.c -o frets

	to use:

		frets -i 25.5 24

	for a 25.5 inch scale (strat) with 24 frets measured in inches

		frets -m 629 22

	for a 24.75 inch (629 mm) scale (Gibson) with 22 frets in millimeters

	etc.
/* --------------------------- Cut Here ------------------------------------ */

/*  Frets.c - Fretboard layout calculator.  Utilizes the following relation:

    d = L - L/ 2**1/12

    where:
          d is the distance between slots cut for two frets
            (or from the edge of the fingerboard to the slot for the
             first fret),

          L is the remaining scale length.  This starts out as the overall
             scale length (nut-to-bridge distance) and is decreased by the
             current fret distance each iteration,

          and "2**1/12" is the twelfth root of two, the frequency difference
	     between two adjacent notes in the chromatic scale - a half-step.


   ***********************************************************************
   * Originally Coded by: Larry J. Huntley (larryh@lmc.com)              *
   * Date: 12 November, 1992.                                            *
   * Released into the public domain for unlimited use and modification. *
   * Flames will be gleefully ignored; constructive criticism welcomed.  *
   * Modify it and make it useful.  When you do, send me a copy so I can *
   * enjoy it, too.                                                      *
   ***********************************************************************


   Customization: change the FRETS and SCALE definitions to serve your own
   purposes;
   Make these command-line arguments for true usefulness.  Use millimeters
   for somewhat better accuracy and ease of cutting.
*/

#include <stdio.h>
#include <math.h>

#define FRETS 24
#define SCALE 25.5  /*  Inches  */
#define TWELFTH_ROOT_OF_TWO 1.059463094

main(argc, argv)
int	argc;
char   *argv[];
{

    float   length = SCALE;
    float   distance_from_nut = 0;
    float   distance_from_prev_fret = 0;
    int     fret_no;
    int	    frets = (int) FRETS;
    char    unit_string[4];
    void    usage();

    if (argc < 2)
	usage();

    if (*argv[1] == '-')
    {
	switch (*++argv[1])
	{
		case 'm' : strcpy (unit_string, "mm"); break;
		case 'c' : strcpy (unit_string, "cm"); break;
		case 'i' : strcpy (unit_string, "in"); break;
		default  : strcpy (unit_string, "in");
	}
	length = atof (argv[2]);
	frets  = atoi (argv[3]);
    }
    else
    {
	strcpy (unit_string, "in");
	length = atof (argv[1]);
	frets  = atoi (argv[2]);
    }

    printf ("Scale Length: %5.2f %s; ", length, unit_string);
    printf ("Number of Frets: %d\n", frets);

    for (fret_no = 1; fret_no <= frets; fret_no++) 
    {
        distance_from_prev_fret = (length - (length / TWELFTH_ROOT_OF_TWO));

        printf ("Fret %2d: ", fret_no);
        printf ("%5.3f", distance_from_prev_fret);
	printf (" %s from previous fret; ", unit_string);

        distance_from_nut += distance_from_prev_fret;

        printf ("%5.3f", distance_from_nut);
        printf (" %s from nut.\n", unit_string);

        length = length - distance_from_prev_fret;
    }
    exit(0);
}
        

void usage()
{
    printf("usage: frets -[i|c|m] scale_length fret_count\n\n");
    printf("\t-i: lengths are expressed in inches (default)\n");
    printf("\t-c: lengths are expressed in centimeters\n");
    printf("\t-m: lengths are expressed in millimeters\n");
    printf("\tscale_length is the nut-to-bridge distance expressed\n");
    printf("\t             the units chosen.\n");
    printf("\tfret count is the number of fret positions to calculate.\n");
    exit(0);
}


/* ------------------------------ Cut Here --------------------------------- */


	So, use/modify at will and build some great necks, y'all.

	- Larry Huntley
-- 
         (larryh@lmc.com)         |         --TALK.BIZARRE-- 
     Logic Modeling Corporation   |      The Suppurating Abcess
          Beaverton,  OR          | of the INTERNET - Dr. Donald Wildmon
Newsgroups: alt.guitar,aus.music