172 lines
4.6 KiB
Python
Executable file
172 lines
4.6 KiB
Python
Executable file
#!/usr/bin/python
|
|
|
|
from data import *
|
|
|
|
stock = []
|
|
stock += daddario_plain_steel
|
|
stock += daddario_nickle_wound
|
|
#stock += circle_k_plain
|
|
#stock += circle_k_hybrid_wound
|
|
|
|
mm_to_in = 0.03937
|
|
scale_length = 648*mm_to_in
|
|
|
|
string_sets = {
|
|
'regular light': (
|
|
# (desired note, tension, and type)
|
|
('E4' , 16, 'P'),
|
|
('B3' , 16, 'P'),
|
|
('G3' , 16, 'P'),
|
|
('D3' , 16, 'W'),
|
|
('A2' , 16, 'W'),
|
|
('E2' , 16, 'W'),
|
|
),
|
|
'jazz light': (
|
|
('E4' , 24, 'P'),
|
|
('B3' , 24, 'P'),
|
|
('G3' , 24, 'W'),
|
|
('D3' , 24, 'W'),
|
|
('A2' , 24, 'W'),
|
|
('E2' , 24, 'W'),
|
|
),
|
|
'regular light (DADGAD)': (
|
|
('D4' , 16, 'P'),
|
|
('A3' , 16, 'P'),
|
|
('G3' , 16, 'P'),
|
|
('D3' , 16, 'W'),
|
|
('A2' , 16, 'W'),
|
|
('D2' , 16, 'W'),
|
|
),
|
|
'regular light (open G, 6)': (
|
|
('D4' , 16, 'P'),
|
|
('B3' , 16, 'P'),
|
|
('G3' , 16, 'P'),
|
|
('D3' , 16, 'W'),
|
|
('B2' , 16, 'W'),
|
|
('D2' , 16, 'W'),
|
|
),
|
|
'regular light (open G, 7)': (
|
|
('D4' , 16, 'P'),
|
|
('B3' , 16, 'P'),
|
|
('G3' , 16, 'P'),
|
|
('D3' , 16, 'W'),
|
|
('B2' , 16, 'W'),
|
|
('G2' , 16, 'W'),
|
|
('D2' , 16, 'W'),
|
|
),
|
|
}
|
|
|
|
A = 440
|
|
notes = {
|
|
'C' : 0,
|
|
'D' : 2,
|
|
'E' : 4,
|
|
'F' : 5,
|
|
'G' : 7,
|
|
'A' : 9,
|
|
'B' : 11,
|
|
}
|
|
rel = (2**(1/12.))
|
|
def note2freq(name):
|
|
sharp = name[1] == '#'
|
|
flat = name[1] == 'b'
|
|
if sharp or flat:
|
|
note = name[0:1]
|
|
octave = int(name[2])
|
|
else:
|
|
note = name[0]
|
|
octave = int(name[1])
|
|
num = notes[note]
|
|
if sharp:
|
|
num += 1
|
|
if flat:
|
|
num -= 1
|
|
fullnum = num + 12*(octave - 5)
|
|
return A*rel**(fullnum + 3)
|
|
|
|
def test(name, expected):
|
|
print('{:3} gave {: 9.2f} Hz\nexpected {: 9.2f} Hz'.format(name, note2freq(name), expected))
|
|
if False:
|
|
test('C2' , 65.41)
|
|
test('Ab4', 415.30)
|
|
test('A4' , 440.00)
|
|
test('B4' , 493.88)
|
|
test('B#4', 523.25)
|
|
test('Cb5', 493.88)
|
|
test('C5' , 523.25)
|
|
print()
|
|
test('E4' , 329.63)
|
|
test('B3' , 246.94)
|
|
test('G3' , 196.00)
|
|
test('D3' , 146.83)
|
|
test('A2' , 110.00)
|
|
test('E2' , 82.41)
|
|
import sys
|
|
sys.exit(0)
|
|
|
|
uw_const = 386.4
|
|
def uw2tension(uw, freq):
|
|
return (uw*(2*scale_length*freq)**2)/uw_const
|
|
|
|
def tension2uw(t, freq):
|
|
return (t*uw_const)/(2*scale_length*freq)**2
|
|
|
|
if False:
|
|
# DAd's data is all screwy so we use change scale lengths for a best-fit
|
|
scale_length = 25.4825
|
|
D3 = note2freq('D3')
|
|
A2 = note2freq('A2')
|
|
E2 = note2freq('E2')
|
|
print('NW024 {:10.8f} == 0.00010857'.format(tension2uw(15.73, D3)))
|
|
print('NW025* {:10.8f} == ? '.format(tension2uw(17.21, D3)))
|
|
print('NW026 {:10.8f} == 0.00012671'.format(tension2uw(18.38, D3)))
|
|
print()
|
|
print('NW036 {:10.8f} == 0.00023964'.format(tension2uw(19.04, A2)))
|
|
print('NW037* {:10.8f} == ? '.format(tension2uw(20.23, A2)))
|
|
print('NW038 {:10.8f} == 0.00026471'.format(tension2uw(20.96, A2)))
|
|
print()
|
|
scale_length = 25.18
|
|
print('NW039 {:10.8f} == 0.00027932'.format(tension2uw(12.46, E2)))
|
|
print('NW040* {:10.8f} == ? '.format(tension2uw(13.18, E2)))
|
|
print('NW042 {:10.8f} == 0.00032279'.format(tension2uw(14.37, E2)))
|
|
print()
|
|
scale_length = 25.02
|
|
print('NW049 {:10.8f} == 0.00043014'.format(tension2uw(18.97, E2)))
|
|
print('NW050* {:10.8f} == ? '.format(tension2uw(19.68, E2)))
|
|
print('NW052 {:10.8f} == 0.00048109'.format(tension2uw(21.15, E2)))
|
|
import sys
|
|
sys.exit(0)
|
|
|
|
outfmt = '{:<8} at {:> 5.2f} lbs ({:>+4.2f})'
|
|
finalfmt = 'total: {:>7.2f} lbs ({:>+5.2f})'
|
|
def print_ideal_stock(strings):
|
|
total_tension = 0
|
|
total_desired_tension = 0
|
|
for note, tension, kind in strings:
|
|
freq = note2freq(note)
|
|
uw = tension2uw(tension, freq)
|
|
|
|
closest = ('n/a', 0)
|
|
for name, stock_uw in stock:
|
|
if kind == 'P' and name[2] != 'P':
|
|
continue
|
|
if kind == 'W' and name[3] != 'W':
|
|
continue
|
|
if abs(stock_uw - uw) < abs(closest[1] - uw):
|
|
closest = (name, stock_uw)
|
|
|
|
closest_tension = uw2tension(closest[1], freq)
|
|
diff = closest_tension - tension
|
|
print(outfmt.format(closest[0], closest_tension, diff))
|
|
|
|
total_tension += closest_tension
|
|
total_desired_tension += tension
|
|
|
|
error = total_tension - total_desired_tension
|
|
print(finalfmt.format(total_tension, error))
|
|
|
|
print('for a scale length of {:>5.2f} inches'.format(scale_length))
|
|
for name, strings in string_sets.items():
|
|
print()
|
|
print('"{}"'.format(name))
|
|
print_ideal_stock(strings)
|