saebekassebil / teoria

Javascript taught Music Theory
http://saebekassebil.github.io/teoria
MIT License
1.32k stars 114 forks source link

Key signatures #89

Open dy opened 9 years ago

dy commented 9 years ago

Sorry for asking maybe an obvious question, but I can’t think up, what is the best way to get key signature notes for a scale? I could imagine some method like scale.signature(), which returns key signature notes in proper order, but seems it is already possible to do via other means, but it’s not quite clear how. Any ideas? I can go the default way like building it from scratch, as it described here though. Thank you.

Trying to use teoria in piano-game to engage scales, accents, chords etc.

dy commented 9 years ago

@saebekassebil if you want I can implement this method in a separate PR?

saebekassebil commented 9 years ago

Hey Deema!

Well, that's a good question. My first thought is something like summing up the accidentals, and then mapping to a signature? It's a bit fragile, but should work with all the diatonic scales:

var scale = teoria.note('D').scale('major');
var notes = scale.notes();

var signatureSum = notes.reduce(function(sum, note) {
  return sum + note.accidentalValue();
}, 0);

Let me just think about this for a little while - it's a bit early in the morning here :) Looking forward to try out your piano game!

dy commented 9 years ago

Interesting approach, but I can’t think up the continuation. First I thought to simply show the notes with accidentals while traversing degrees in a scale, but the order of notes in signature is important (famous "Father Christmas Gave Dad An Electric Blanket"). That is why I thought it may be possible to calculate signatures via circle of fifts and note coordinates in a scale. But I didn’t manage to understand the meaning of note coordinates