diff --git a/lib/interval.js b/lib/interval.js index 3ef3a1f..9f66c85 100644 --- a/lib/interval.js +++ b/lib/interval.js @@ -136,6 +136,14 @@ Interval.prototype = { return !this.equal(interval) && !this.greater(interval); }, + fromSemitones: function(index) { + var coord = knowledge.intervalsSemitones[index]; + if (!coord) + throw new Error('Invalid index'); + + return new Interval(coord); + }, + add: function(interval) { return new Interval(vector.add(this.coord, interval.coord)); }, diff --git a/lib/knowledge.js b/lib/knowledge.js index b1888cc..1d9d130 100644 --- a/lib/knowledge.js +++ b/lib/knowledge.js @@ -22,6 +22,22 @@ module.exports = { octave: [1, 0] }, + intervalsSemitones: { + 0: [0, 0], + 1: [3, -5], + 2: [-1, 2], + 3: [2, -3], + 4: [-2, 4], + 5: [1, -1], + 6: [-3, 6], + 7: [0, 1], + 8: [3, -4], + 9: [-1, 3], + 10: [2, -2], + 11: [-2, 5], + 12: [1, 0] + }, + intervalFromFifth: ['second', 'sixth', 'third', 'seventh', 'fourth', 'unison', 'fifth'], diff --git a/lib/note.js b/lib/note.js index f7f9582..038976a 100644 --- a/lib/note.js +++ b/lib/note.js @@ -90,6 +90,11 @@ Note.prototype = { return this; }, + transposeNew: function(interval) { + var coord = vector.add(this.coord, interval.coord); + return new Note(coord); + }, + /** * Returns the Helmholtz notation form of the note (fx C,, d' F# g#'') */ diff --git a/teoria.js b/teoria.js index 439d7ed..4d88e20 100644 --- a/teoria.js +++ b/teoria.js @@ -446,6 +446,14 @@ Interval.prototype = { return !this.equal(interval) && !this.greater(interval); }, + fromSemitones: function(index) { + var coord = knowledge.intervalsSemitones[index]; + if (!coord) + throw new Error('Invalid index'); + + return new Interval(coord); + }, + add: function(interval) { return new Interval(vector.add(this.coord, interval.coord)); }, @@ -505,6 +513,22 @@ module.exports = { octave: [1, 0] }, + intervalsSemitones: { + 0: [0, 0], + 1: [3, -5], + 2: [-1, 2], + 3: [2, -3], + 4: [-2, 4], + 5: [1, -1], + 6: [-3, 6], + 7: [0, 1], + 8: [3, -4], + 9: [-1, 3], + 10: [2, -2], + 11: [-2, 5], + 12: [1, 0] + }, + intervalFromFifth: ['second', 'sixth', 'third', 'seventh', 'fourth', 'unison', 'fifth'], @@ -737,6 +761,11 @@ Note.prototype = { return this; }, + transposeNew: function(interval) { + var coord = vector.add(this.coord, interval.coord); + return new Note(coord); + }, + /** * Returns the Helmholtz notation form of the note (fx C,, d' F# g#'') */