[Tutor] Musical Pitch

Gregor Lingl glingl at aon.at
Wed Feb 25 16:47:27 EST 2004


Hi Kevin!

kevin parks schrieb:

> ... So far i have just been sort of making things up as i go along, 
> making huge silly lists or dictionaries. In order to spare the list 
> some bandwidth i'll just post a URL showing the type of monstrous 
> kludgy constructs i have been using:
>
> http://www.people.virginia.edu/~kpp9c/pitchname.py.html
>
> But i am wondering if maybe it is time for me to take another 
> (possibly OO ? gasp!) oriented approach or just build a pitch module 
> that i can import and reuse.
>
> Here are some possible representations just to give you a taste of 
> what i am up against (here i am talking 12 tone equal temperament, i 
> have other tools i use for dealing with tuning ratios)
>
> 1. Old fashioned letter names : A4 (C#3, and  the like)
> 2. Frequencies in Hz : 440.00
> 3. MIDI note numbers: 69
> 4. Octave point pitch-class: 8.09 (middle c = 8.00, there are 12 pitch 
> classes in an octave, 8.12 would = 9.00)
> 5. Octave point decimal : 8.75 (middle c = 8.00, but now the 
> pitch-class continuum is 100/12 (8.333..) * number of half steps. An 
> octave run of which would look something like this: 

...

>
>
> So in all, 5 different representations of pitch....
>
> Then there would be a slew of modulo 12 operations that maybe could be 
> functions or methods if i decide to get fancy such as transposition, 
> inversion, reducing to 1 oct range, compliment, pitch mapping.... etc.
>
> All of which i hope to build up over time....
>
> so... I am wondering:
>
> 1. anyone already have something like this hacked together?

No

> 2. anyone bored and want to take a whack helping me get started?

Bored? Not at all. Nevertheless, here is a couple of functions, which
might get you started:

def pitchname(midi, name={0:"C",1:"C#",2:"D",3:"D#",
                          4:"E",5:"F",6:"F#",7:"G",
                          8:"G#",9:"A",10:"A#",11:"H"} ):
    return "%s%d" % (name[midi%12],midi//12-1)

def frequency(midi, f = 2**(1.0/12)):
    return round(440 * f**(midi-69),3)

def octpoint_pc(midi):
    return "%d.%02d" % (3+midi//12,midi%12)

def octpoint_dc(midi):
    return round( 3+midi/12.0 ,6)


for i in range(128):
    print pitchname(i), frequency(i), octpoint_pc(i), octpoint_dc(i), i

#you can get your table:

pitch = [ (pitchname(i), frequency(i), octpoint_pc(i), octpoint_dc(i), 
i) for i in range(128)]

for p in pitch:
    print p

Perhaps you have to convert some of the numbers into strings, if needed ...

BTW, do you know midi-software with Python-interfaces (for Windows)
Any hint/link would be appreciated...   (A friend of mine asked me for this
some weeks ago.)

Regards, Gregor
 



More information about the Tutor mailing list