music-suite / music-pitch

This repo has been merged into: https://github.com/music-suite/music-suite
http://music-suite.github.io
BSD 3-Clause "New" or "Revised" License
9 stars 9 forks source link

Pitch.name: bad value #32

Closed hanshoglund closed 10 years ago

hanshoglund commented 10 years ago
>>> iterate sharpen c :: [Pitch]
[c,cs,css,csss,cssss,csssss,cssssss,csssssss,cssssssss,csssssssss,cssssssssss,csssssssssss,cssssssssssss,*** Exception: Pitch.name: Bad value -9
>>> iterate flatten c :: [Pitch]
[c,cb,cbb,cbbb,cbbbb,cbbbbb,cbbbbbb,cbbbbbbb,cbbbbbbbb,cbbbbbbbbb,cbbbbbbbbbb,cbbbbbbbbbbb,cbbbbbbbbbbbb,*** Exception: Pitch.name: Bad value -9
>>> 
ejlilley commented 10 years ago

The fix for this (pull-request incoming) is to make the Ord instance of Interval compare only on the second element of the Interval-tuple. Whether this affects other code that relies on the Ord instance of Interval, I can't say.

hanshoglund commented 10 years ago

A propos the comment in your last commit. Vectors can actually be ordered in infinitely many ways by providing a flattening function R^2 -> R, i.e. a mapping from the VS to a number line.

I think in this case we are restricted by the Eq instance: we don't want compare a b == EQ without also having (==) a b, so the Ord instance can not ignore one of the elements.

hanshoglund commented 10 years ago

Intuitively, I think this is only possible using http://en.wikipedia.org/wiki/Lexicographical_order, which is what derive generates. O.t.o.h one might argue that the instance should compare Number before comparing the chromatic component, which is what the old instance did.

ejlilley commented 10 years ago

Well, the projection to the real line is basically the tuning function. The problem is evident for say, Pythagorean and quarter-comma meantone: in Pythagorean, the interval d2 ~= 0.987, whereas in QC meantone, d2 ~= 1.024. Clearly we can't say definitively how to order intervals until we know how they're going to be tuned. My compromise is to basically order them according to how they appear vertically on a page of music.