Closed chtenb closed 9 years ago
Hi Chiel92 -- welcome. There is a mailing list at music21list@googlegroups.com; in the future this would be a good place to start, but you've also discovered some bugs in the system worth using GitHub for.
I thought at first that the small bugs would be from using C0 = 16.35 and not the closer approximation 16.351597831287375, and this explains the differences between 653 and 652.936; but this turns out to be insufficient for the rest. (Note: this example is in Python 3; substitute 12.0 and 1200.0 for Python 2 division) The difference between f and f1 are floating point rounding errors (we convert frequency to a pitch and microtone and then convert back to get the frequency, so 261 and 260.9999994 are as close as we can get).
One thing that could've caused some problems in the system is in conflating octave which is a fact of DIATONIC space (note names, etc.) and pitchClass which, like .ps, comes from CHROMATIC space. For instance, this is NOT a bug:
p = pitch.Pitch("C4")
p2 = pitch.Pitch("B#3")
p.ps == p2.ps # True
p.pitchClass == p2.pitchClass # True
p.octave == p2.octave # FALSE!!!!!!
This is not a bug, because octave designations are often used in layout decisions, staff splitting etc., and the presence of an accidental (even a triple sharp, etc.) is defined never to change the octave of the note. So two notes could have the same frequency and have different octaves.
What you've found is that .pitchClass and .microtone seem to interact in strange ways. The bug is that your 216, 130, and 64 examples all have pitchClass 12. That should never be allowed to exist. They should be pitchClass 0. This is the bug that will be fixed.
The problem that arises is that pitchClass for non-12ET pitches is undefined in the literature. What should C-half-sharp's pitch class be? 0 [a type of C], 0.5 [halfway between 0 and 1], or 1 [0.5 rounds to 1]? What we have been doing is rounding to the nearest pitch, so that pitchClass is always an integer, as it is in most situation it is expected. (A C half sharp can be created with the symbol "C~"; half-flat with "C`")
The microtone, however, is an adjustment off of the displayed accidental. So for instance, C + 90c is a possible designation. Its pitchClass is 1 because it is much closer to C# than to C. However, its microtonal adjustment is 90 cents up, not 10 cents down. So by adjusting upwards from the rounded number, the difference between pitchClass and actual frequency becomes compounded, not alleviated.
Thus, it's really complicated to compute frequency manually from pitches. There are pitches defined as "7th harmonic of X" that are even more complex and "neutral" accidentals [not fully implemented or documented] which take their accidental from the prevailing key signature or context. The plan is also for .frequency to take into account transposition context (An "A4" played by a Bb clarinet is not 440 hertz if the score is defined as a transposing score). In these cases, .freq440
(currently just a synonym for .frequency) will return the naive (and fast) frequency of a note.
The bug fix will fix the pitchClass == 12 bugs, but will leave the (expected) behavior of the other calculations alone.
Thanks! I'll post this exchange to the music21list so that others can benefit from it.
Fixed! Feel free to reopen or comment w/ more suggestions.
Thanks a lot for your fast and clear reply!
Thank you for bringing attention to the bug and giving me the chance to write some better documentation (to go with the next release)!
My apologies if this question is inappropriate here, but I couldn't find a mailing list or the like.
Consider the following testing code.
The output of this is
There is often a difference between my manual computation of the frequency resp. the pitch space and the
music21
value. Note that sometimes this difference can be about an octave (like the first two C note frequencies), but mostly it is about one tone. Another weird thing is that for the third testing frequency the pitchspace values are the same while the frequencies are not.Are my manual formulas wrong, or is
music21
using the attributes in an unexpected way?