Closed benmurrell closed 10 years ago
Modifying the add function as follows fixes my immediate use case:
function add(note, interval) {
var ret = [note[0] + interval[0], note[1] + interval[1]];
while( ret[1] <= -9 ) {
ret[1] += 12;
ret[0] -= 7;
}
return ret;
}
Similar changes are probably needed for sub and mul, and checking for out of bounds on the other side would probably be good too. Or modify the various functions that use coords to do some sort of normalization before using the data - for instance, TeoriaNote.accidental() only looks at coord[1] and expects it to be in a certain range.
Cheers Ben,
So what you are trying to do (I assume) is to generate a chromatic collection of note. In this case a chromatic scale from the note C.
The thing is, that theoretically this cannot be generated by continuously moving a minor second up (or down). Although it seems (on a piano/guitar) to have the same effect, you're actually generating more and more "far out" notes. This is because a minor second only "moves" a semitone, but at the same time "moves" a whole note in the scale.
As you can see teoria is trying its best in the beginning. C -> Db -> Ebb -> Fbb
(notice how the note name changes every time you apply a second). But from here stuff gets difficult. This is because the next note would be called Gbbb
and this is (in almost every case) completely useless.
If you want to generate a chromatic scale of notes you can do several things:
var chromatic = teoria.scale('C2', 'chromatic');
chromatic.notes(); // returns an array of twelve chromatic notes.
or if you want to be able to generate chromatic scales of arbitrary length (with no control of the theoretical intervals but just the semitone distance of 1), try something like:
function chromaticSequence(note, length) {
var startkey = note.key(), sequence = [note];
for (var i = 0; i < length; i++) {
sequence.push(teoria.note.fromKey(startkey + i + 1);
}
return sequence;
}
chromaticSequence(teoria.note('C3'), 12).map(function(n) { return n.toString(); })
// -> ["c3", "db3", "d3", "eb3", "e3", "f3", "f#3", "g3", "g#3", "a3", "a#3", "b3", "c4"]
chromaticSequence(teoria.note('C3', 24).map(function(n) { return n.toString(); })
["c3", "db3", "d3", "eb3", "e3", "f3", "f#3", "g3", "g#3", "a3", "a#3", "b3", "c4", "db4", "d4", "eb4", "e4", "f4", "f#4", "g4", "g#4", "a4", "a#4", "b4", "c5"]
The internal .coord
is the representation of the note, relative to the note A4
. It's represented in the format [octaves, fifths]
. This means that "to get to the note from A4" you would move octaves
number of octaves and fifths
number of fifths. I should probably document this better!
I'm closing this, as it's not an issue with the library (as far as I can tell), but feel free to reopen or question!
That makes sense - thanks!
Here's a snippet that brings the problem to light:
Output:
As you can see, the interval is the correct number of semitones, but the coord of the resulting note differs significantly from what we would get if we just asked for it via teoria.note(). The out of bound coords breaks the calculation of accidentals, octaves, and note names - the last note logged should be b2.
I'm not sure what the coord represents exactly, so this is difficult for me to fix.