saebekassebil / teoria

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

Use coords internally to represent notes and intervals #37

Closed saebekassebil closed 11 years ago

saebekassebil commented 11 years ago

This took a lot of work, but I've finally got around to finishing this up.

This pull request breaks a lot of the old API, by replacing many properties (such as TeoriaNote.octave) with functions (now TeoriaNote#octave()). This is due to the internal representation of a TeoriaNote and a TeoriaInterval. Both of these objects now have only one property: this.coord.

The coord property is an array with two elements: coord[octaves, fifths]. Using octaves and fifths, it is possible to represent all notes (at least in the 12TET), with an arbitrary number of accidentals. All TeoriaNotes are now relative to the concert pitch, A4, which is the origo of the coordinate space:

teoria.note('A4').coord -> [0, 0]

This API change has made it possible to remove a lot of tables from the code, which is great, because it leads to less redundancy.

I'd like to thank @gregjopa for his music.js, which I've borrowed the idea of representing notes with coords, from.

If there's no objections to these changes, I'll probably pull this, later this week.

/cc @gregjopa and @quickredfox whom I believe I've discussed this issue of abstracting out the note names with.

gregjopa commented 11 years ago

@saebekassebil great work! I have no objection to these changes. This opens up the door for adding support for different temperaments/microtones.

I'd like the unit tests you have. I think it would be fun to add some audio tests as well using the web audio api and also add some audio to http://saebekassebil.github.io/teoria/.