From b309fbcdc2532a6247fbca34c7d2870c27eb7c02 Mon Sep 17 00:00:00 2001 From: Vilson Vieira Date: Tue, 5 Sep 2017 13:59:23 -0300 Subject: [PATCH 1/3] Make it possible to create interval from semitones --- lib/interval.js | 8 ++++++++ lib/knowledge.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) 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'], From 927c5510d416f67eddbfa12d98885dd7bf527554 Mon Sep 17 00:00:00 2001 From: Vilson Vieira Date: Tue, 5 Sep 2017 14:02:48 -0300 Subject: [PATCH 2/3] Transpose a note without mutating it --- lib/note.js | 5 +++++ 1 file changed, 5 insertions(+) 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#'') */ From 14724fd7a22b94fa826d430482c7c9ff8c1a96d7 Mon Sep 17 00:00:00 2001 From: Vilson Vieira Date: Tue, 5 Sep 2017 14:03:59 -0300 Subject: [PATCH 3/3] Update bundle --- teoria.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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#'') */