lilypond-devel
[Top][All Lists]

## Representation of pitches and scales

 From: Rune Zedeler Subject: Representation of pitches and scales Date: Mon, 04 Jun 2007 10:59:34 +0200 User-agent: Thunderbird 1.5.0.10 (X11/20070306)

Wondering how to solve the absolute pitch-compare-problem I mentioned in the ambitus bug report, I took a look into how pitches and scales are represented in lily.
```I see that the diatonic scale is represented as

(ly:make-scale #(0 1 2 5/2 7/2 9/2 11/2)

```
thereby effectively hardcoding a semitone to be exactly half a whole tone - which is rather inadequate because it makes it impossible to distinguish e.g. cis from des. I didn't look deeply into the code - it seems like it could use some cleanup - in scale.cc The comment to ly:make-scale says that the function takes an int-vector as argument even though it takes a rational vector. The vector is also named "semitones" even though it counts whole tones (?!?!). In tone_pitch it seems like it is hardcoded that an octave consists of exactly 6 whole notes.
```
Another question:
Pitch::rounded_semitone_pitch () const
{
return int (double (tone_pitch () * Rational (2)));
}
```
Converting a double to an int always rounds down. Isn't it wrong not to call round() on the double before casting it to int?
```
```
Well, having tone_pitch returning the pitch in 1/6-octaves is pure messy. I have never heard of that scale before.
```
```
I would propose using the cents-scale, that is sortof a standard. A cent is 1/1200 of an octave. Having tone_pitch returning a number of cents - and having the scale defined as a list of cents relative to base-tone- would IMO be the right thing to do. This would also make it easier to type in alternative scales, because scales are always reported in cents.
```
```
I also think that the Scale object should contain information about the size of an alteration (that is, how many cents a quartertone takes).
```
```
We could add some nifty scheme functions to calculate a scale given a fifth-size in cents, or a whole-tone-size in cents.
```