a python script that prints out the frequencies in a scale and its chords
Note that the script multiplies some of the frequencies by two, in order to present the members of the chords in their canonical position (canonical according to music theory, that is.)
#!/usr/bin/python
import sys
class ScaleStep:
def __init__(self):
self.frequency = 0
class Scale:
def __init__(self, base_frequency):
self.step_one = ScaleStep()
self.step_one.frequency = int(base_frequency)
self.step_two = ScaleStep()
self.step_two.frequency = self.step_one.frequency * 9/8
self.step_three = ScaleStep()
self.step_three.frequency = self.step_one.frequency * 5/4
self.step_four = ScaleStep()
self.step_four.frequency = self.step_one.frequency * 4/3
self.step_five = ScaleStep()
self.step_five.frequency = self.step_one.frequency * 3/2
self.step_six = ScaleStep()
self.step_six.frequency = self.step_one.frequency * 5/3
self.step_seven = ScaleStep()
self.step_seven.frequency = self.step_one.frequency * 15/8
class ChordScale:
def __init__(self, base_frequency):
this_scale = Scale(base_frequency)
self.one_chord = (this_scale.step_one, this_scale.step_three, this_scale.step_five)
self.two_chord = (this_scale.step_two, this_scale.step_four, this_scale.step_six)
self.three_chord = (this_scale.step_three, this_scale.step_five, this_scale.step_seven )
self.four_chord = (this_scale.step_four, this_scale.step_six, this_scale.step_one )
self.five_chord = (this_scale.step_five, this_scale.step_seven, this_scale.step_two )
self.six_chord = (this_scale.step_six, this_scale.step_one, this_scale.step_three )
#------------------- end of classes --------------
def print_scale_frequencies(base_frequency):
this_scale = Scale(base_frequency)
print 'step seven: %d' %this_scale.step_seven.frequency
print 'step six: %d' %this_scale.step_six.frequency
print 'step five: %d' %this_scale.step_five.frequency
print 'step four: %d' %this_scale.step_four.frequency
print 'step three: %d' %this_scale.step_three.frequency
print 'step two: %d' %this_scale.step_two.frequency
print 'step one: %d' %this_scale.step_one.frequency
def print_chord_scale_frequencies(base_frequency):
chords_in_this_scale = ChordScale(base_frequency)
print 'one chord: %d, %d, %d' % (chords_in_this_scale.one_chord[0].frequency, chords_in_this_scale.one_chord[1].frequency, chords_in_this_scale.one_chord[2].frequency)
print 'two chord: %d, %d, %d' % (chords_in_this_scale.two_chord[0].frequency, chords_in_this_scale.two_chord[1].frequency, chords_in_this_scale.two_chord[2].frequency)
print 'three chord: %d, %d, %d' % (chords_in_this_scale.three_chord[0].frequency, chords_in_this_scale.three_chord[1].frequency, chords_in_this_scale.three_chord[2].frequency )
print 'four chord: %d, %d, %d' % (chords_in_this_scale.four_chord[0].frequency, chords_in_this_scale.four_chord[1].frequency, (chords_in_this_scale.four_chord[2].frequency * 2) )
print 'five chord: %d, %d, %d' % (chords_in_this_scale.five_chord[0].frequency, chords_in_this_scale.five_chord[1].frequency, (chords_in_this_scale.five_chord[2].frequency * 2) )
print 'six chord: %d, %d, %d' % (chords_in_this_scale.six_chord[0].frequency, (chords_in_this_scale.six_chord[1].frequency * 2), (chords_in_this_scale.six_chord[2].frequency * 2) )
#-------------------- end of defs ---------------------
base_frequency = int(sys.argv[1])
print 'frequencies of the seven steps in the natural scale, where the frequency of scale step one = %s Hz' %base_frequency
print_scale_frequencies(base_frequency)
print
print 'frequencies of the scale steps in the six chords, where the frequency of scale step one = %s Hz' %base_frequency
print_chord_scale_frequencies(base_frequency)
print
step_one_octave_one = base_frequency/2
print 'two octaves of the natural scale; scale step one in first octave = %s Hz' % step_one_octave_one
for octave in range(1, 3):
print_scale_frequencies(base_frequency)
base_frequency = base_frequency/2
# override user's input to be sure the range is realistic
base_frequency = 800
print
print 'four octaves of the natural scale; scale step one in first octave = 100 Hz'
for octave in range(1, 5):
print_scale_frequencies(base_frequency)
base_frequency = base_frequency/2