saebekassebil / teoria

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

Adding two intervals #49

Closed amitgur closed 10 years ago

amitgur commented 10 years ago

I'm looking for the best way to add two intervals.

m3 + M2 = P4 P5 + m-6 = M-2

Any ideas for the right way to do it ?

amitgur commented 10 years ago

At the moment I'm doing it this way

var newInterval = teoria.note("c4").interval(interval1).interval(interval2).interval(teoria.note('c4'));

amitgur commented 10 years ago

Well my implimentation is not working for all cases ..

amitgur commented 10 years ago

This one is doing the job:

newNote = teoria.note("c4").interval(interval1).interval(interval2);

newInterval = teoria.note("c4").interval(newNote);

saebekassebil commented 10 years ago

I think it should be possible to just add the interval coords together:

teoria.TeoriaInterval.prototype.add = function(interval) {
  return new teoria.TeoriaInterval([this.coord[0] + interval.coord[0], this.coord[1] + interval.coord[1]]);
}

teoria.interval('m3').add(teoria.interval('M2')).toString(); // -> P4

I'll test this out and implement it if it works out.

saebekassebil commented 10 years ago

Fixed in b4d7ae552d499d82d52ad70287e23e9716f48505

Example:

teoria.interval('P5').add(teoria.interval('m-6')).toString(); // -> 'm-2'
amitgur commented 10 years ago

Thanks