omde.pitch
index
/usr/local/lib/python2.1/site-packages/omde/pitch.py

This modules contains functions, classes and data
useful to perform pitch to frequency conversions
in several ways.
 
Csound-like pitch converters by Erasmus Zipfel.

 
Modules
            
UserDict
cPickle
math
os
re
sys
types

 
Classes
            
omde.converter.Converter(omde.functional.Generator)
PchOct
PitchConverter
FreePitchConverter
GenericPitchConverter
Ptolemy
Pythagorean
TET12
omde.functional.Generator
PitchGenerator
Pitch
Scale
_convert
_pch_convert
Cpsmidi
PchClass
_pch_convert2
cpsnote
midinote
pchnote
cpsoct
cpspch
midicps
octcps
octmidi
octpch
pchmidi

 
class Cpsmidi(_pch_convert)
      Cpsmidi( [input, reference] )
 
converts from midi to cps: 69 => 440. If you
are using the slower converter (by setting
reference), so float >midi< values are permitted.
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class FreePitchConverter(PitchConverter)
       
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, input=None, pseudoctaveratio=2.0, nsteps=25, origin_frequency=0)
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
_normalize(self, modulo, pitch) from PitchConverter
convert(self, value) from PitchConverter
pitch2freq(self, pitch)

 
class GenericPitchConverter(PitchConverter)
       
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, central_A_freq=32.851846551950104, klass=0, name=None, ratios=None, input=None)
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
_normalize(self, modulo, pitch) from PitchConverter
convert(self, value) from PitchConverter
pitch2freq(self, pitch)

 
class PchClass(_pch_convert)
      Converts pitch Class values to pch ( la Csound).
 
Integers represent pitch Classes, whenever
a float value is given, so the fractional
parts represent the pitch Class and the integer part
represents the octave.
 
The last given octave resets the attribute octpc.
 
The initial octave may be given as octpc keyword
(as number, not as string!).
 
Example:
 
FIXME: Is this example useful and correct??
I'm not sure what the original intent was.
 
>>> input = List(7,4,15,18,13,5,2,-1,10,12,9,20)
>>> pc = PchClass(input)
>>> for i in range(len(pc.input.list)):
...     print pc(),
...
8.07 8.04 9.03 9.06 9.01 8.05 8.02 7.11 8.1 9.0 8.09 9.08
 
  
__call__(self, a=None)
__init__(self, input=0, octpc=8)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class PchOct(omde.converter.Converter)
      PchOct(input, reference)
 
converts from octave point decimal to pch
in Csound-usage: 8.75 => 8.09
 
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, input=None, reference=None)
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
convert(self, value)

 
class Pitch
      This class represents a pitch as a pair:
pitch class and octave.
 
Note that pitch class is spelled 'klass' in
OMDE/pmask because 'class' is a Python keyword.
 
Usually a PitchConverter performs a normalization step before
converting a Pitch object to a frequency value: the pitch class
number is wrapped at octave boundaries in order to get the real
pitch class and octave number. So a pitch class of 13 will become
a pitch class of 1, and increase the octave by 1.
 
Pitch class values start with 0.
 
Note also that octave doesn't always mean a 2:1 ratio.
 
>>>
>>>
 
  
__init__(self, klass, octave=0)
freq(self, converter)

 
class PitchConverter(omde.converter.Converter)
      Base class for all Pitch to frequency converters.
This is a Generator.
 
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, input=None)
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
_normalize(self, modulo, pitch)
convert(self, value)
pitch2freq(self, pitch)

 
class PitchGenerator(omde.functional.Generator)
       
  
__add__(self, object) from omde.functional.Generator
__call__(self)
__div__(self, object) from omde.functional.Generator
__init__(self, klass, octave=None)
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator

 
class Ptolemy(GenericPitchConverter)
      >>> for i in range(13): print "%.2f" % ptolemy(i),
...
4.11 4.38 4.62 4.93 5.13 5.48 5.77 6.16 6.57 6.84 7.39 7.70 8.21
 
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, central_A_freq=32.851846551950104, klass=0, name=None, ratios=None, input=None) from GenericPitchConverter
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
_normalize(self, modulo, pitch) from PitchConverter
convert(self, value) from PitchConverter
pitch2freq(self, pitch) from GenericPitchConverter

 
class Pythagorean(GenericPitchConverter)
      >>> for i in range(13): print "%.2f" % pythagorean(i),
...
4.11 4.16 4.62 4.87 5.20 5.48 5.85 6.16 6.49 6.93 7.30 7.80 8.21
 
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, central_A_freq=32.851846551950104, klass=0, name=None, ratios=None, input=None) from GenericPitchConverter
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
_normalize(self, modulo, pitch) from PitchConverter
convert(self, value) from PitchConverter
pitch2freq(self, pitch) from GenericPitchConverter

 
class Scale
      Represent a scale from the SCALA database.
This object has 3 attributes:
 
name: a short name derived from the name of
the file in the original SCALA archive by
stripping pathname and extension.
 
info: a description of the scale as contained
in the original SCALA .scm file.
 
ratios: a list of the intervals contained in
this scale as ratios.
 
  
__init__(self, name, info, ratios)

 
class TET12(PitchConverter)
       A PitchConverter which converts from
pitch Class to frequency. The pitch Class 0 is taken to mean C
four octaves below the central A frequency.
By default, the central A frequency is 442 Hz.
 
So middle C can be found like so:
 
>>> print '%.4f' % TET12(0 + 12 * 4)()
525.6295
 
>>> for c in range(13):
...    print "%.2f" % tet12(Pitch(c, 3)),
262.81 278.44 295.00 312.54 331.13 350.82 371.68 393.78 417.19 442.00 468.28 496.13 525.63
>>> for i in range(13): print "%.2f" % tet12(i),
...
 32.85 34.81 36.87 39.07 41.39 43.85 46.46 49.22 52.15 55.25 58.54 62.02 65.70
>>> print tet12(9)
 55.25
 
  
__add__(self, object) from omde.functional.Generator
__call__(self) from omde.functional.Generator
__div__(self, object) from omde.functional.Generator
__init__(self, input=None, central_A_freq=442.0)
__mul__(self, object) from omde.functional.Generator
__radd__(self, object) from omde.functional.Generator
__rdiv__(self, object) from omde.functional.Generator
__rmul__(self, object) from omde.functional.Generator
__rsub__(self, object) from omde.functional.Generator
__sub__(self, object) from omde.functional.Generator
_call1(self, object) from omde.converter.Converter
_call2(self, *args) from omde.converter.Converter
_normalize(self, modulo, pitch) from PitchConverter
convert(self, value) from PitchConverter
pitch2freq(self, pitch)
steps2ratio(self, n)

 
class _convert
       
  
__len__(self)
_li(self, a)
_t_(self, a)
_ti_(self, a)
display(self, n=None)
getList(self, n=None)

 
class _pch_convert(_convert)
       
  
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class _pch_convert2(_pch_convert)
       
  
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
_tn_(self, a)
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class cpsnote(_pch_convert2)
      cpsnote( [input, reference, octRef] )
 
converts strings with 'notename' to cps:
 
'8a'   => 440 Hz
'8ab'  is 'a-flat'
'8abb' is 'a-double-flat'
'8h'   is 'b' - german notation
'8as'  is 'a-sharp'
'8ass' is 'a-double-sharp'
 
the last given octave resets attribute 'octRef',
so: '7c','7g','8e' is the same as: '7c','g','8e',
or 'c','g','8e' if you set 'octRef' to '7'
(as a string!).
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0, octRef='8')
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
_tn_(self, a) from _pch_convert2
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class cpsoct(_pch_convert)
      Cpsoct( [input, reference] )
 
converts from octave point decimal to cps:
8.75 => 440
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class cpspch(_pch_convert)
      cpspch( [input, reference] )
 
converts from pch (in Csound usage) to cps:
8.09 => 440
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class midicps(_pch_convert)
      midicps( [input , reference] )
 
converts from cps to midi 440 => 69
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class midinote(_pch_convert2)
      midinote( [input , reference, octRef] )
 
converts a string with "notename" to midi:
"8a" => 69
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0, octRef='8')
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
_tn_(self, a) from _pch_convert2
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class octcps(_pch_convert)
      octcps( [input, reference] )
 
converts from cps to octave point decimal:
440 => 8.75
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class octmidi(_pch_convert)
      octmidi( [input, reference] )
 
converts from midi to octave point decimal:
69 => 8.75, with 'reference' setting also in 
float >midi<.
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class octpch(_pch_convert)
      octpch( [input, reference] )
 
converts from pch (in Csound usage) to octave
point decimal: 8.09 => 8.75
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class pchmidi(_pch_convert)
      pchmidi( [input, reference] )
 
converts from pch (in Csound usage) to midi:
8.09 => 69, with "reference" also in floats.
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0)
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
class pchnote(_pch_convert2)
      pchnote( [input , reference, octRef] )
 
converts a string with "notename" to pch in
Csound-usage: "8a" => 8.09
 
  
__call__(self, a=None)
__init__(self, input=0, reference=0, octRef='8')
__len__(self) from _convert
_li(self, a) from _convert
_t_(self, a) from _convert
_ti_(self, a) from _convert
_tn_(self, a) from _pch_convert2
display(self, n=None) from _convert
getList(self, n=None) from _convert

 
Functions
            
_test()
converter_by_name(name, central_A_freq=32.851846551950104, klass=0)
Build a PitchConverter from the SCALA database list by name.
 
Raise a ValueError exception if there is no scale with the
specified name.
cps2oct(value, reference=8.0)
Convert from cps to oct ( la Csound)
 
>>> print cps2oct(440, 8.0)
8.0
>>> print '%.4f' % cps2oct(440 * 1.5, 8.0)
8.5850
>>> print cps2oct(880, 8.0)
9.0
>>>
midi2cps(value, reference)
note2cps_lookup(value)
note2midi_lookup(value)
oct2cps(value, reference=440)
Converts from octave-point-decimal to cps ( la Csound)
 
>>> print oct2cps(8.00, 440)
261.625565301
>>> print oct2cps(8.00, 441)
262.220168858
>>>
oct2pch(value, reference=0.0)
Convert from octave-point-decimal to pch ( la Csound)
 
>>> print oct2pch(8.75, 0)
8.09
>>>
pch(value, octave=0)

 
Data
             __file__ = '/usr/local/lib/python2.1/site-packages/omde/pitch.pyc'
__name__ = 'omde.pitch'
_cps_midi = [8.1760000000000002, 8.6620000000000008, 9.1769999999999996, 9.7230000000000008, 10.301, 10.913, 11.561999999999999, 12.25, 12.978, 13.75, 14.568, 15.433999999999999, 16.352, 17.324000000000002, 18.353999999999999, 19.445, 20.602, 21.827000000000002, 23.125, 24.5, ...]
_ln_2 = 0.69314718055994529
_ln_440 = 6.0867747269123065
_notename_cps = {'10a': 1760, '10ab': 1661.2190000000001, '10abb': 1567.982, '10as': 1864.655, '10ass': 1975.5329999999999, '10c': 1046.502, '10cb': 987.76700000000005, '10cbb': 932.32799999999997, '10cs': 1108.731, '10css': 1174.6590000000001, ...}
_notename_midi = {'10a': 93, '10ab': 92, '10abb': 91, '10as': 94, '10ass': 95, '10c': 84, '10cb': 83, '10cbb': 82, '10cs': 85, '10css': 86, ...}
_notename_pch = {'10a': 10.09, '10ab': 10.08, '10abb': 10.07, '10as': 10.1, '10ass': 10.109999999999999, '10c': 10.0, '10cb': 9.1099999999999994, '10cbb': 9.0999999999999996, '10cs': 10.01, '10css': 10.02, ...}
_pch_midi = [3.0, 3.0099999999999998, 3.02, 3.0299999999999998, 3.04, 3.0499999999999998, 3.0600000000000001, 3.0699999999999998, 3.0800000000000001, 3.0899999999999999, 3.1000000000000001, 3.1099999999999999, 4.0, 4.0099999999999998, 4.0199999999999996, 4.0300000000000002, 4.04, 4.0499999999999998, 4.0599999999999996, 4.0700000000000003, ...]
file = <closed file '/usr/local/share/omde/scales', mode 'rb'>
name = '/usr/local/share/omde/scales'
ptolemy = <omde.pitch.Ptolemy instance>
pythagorean = <omde.pitch.Pythagorean instance>
scales = [<omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, <omde.pitch.Scale instance>, ...]
tet12 = <omde.pitch.TET12 instance>
u = <Unpickler object>