Created
August 8, 2012 04:50
-
-
Save gregjopa/3292167 to your computer and use it in GitHub Desktop.
Teoria.js - tuning interface design
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var teoria = {}; | |
teoria.note = function(name, tuning) { | |
return (new TeoriaNote(name, tuning)); | |
}; | |
// how should we handle multiple optional parameters like duration and tuning? | |
// should be pass in a { param } object instead of individual parameters? | |
function TeoriaNote(name, tuning) { | |
this.name = name; | |
var tuning = tuning || '12tet'; | |
this.tuning = namedTuning(tuning); | |
} | |
TeoriaNote.prototype = { | |
// would key need to be moved to each tuning class? | |
// it looks like the key function assumes 12 notes per octave | |
key: function(whitenotes) { | |
//... | |
}, | |
fq: function(concertPitch) { | |
concertPitch = concertPitch || 440; | |
return this.tuning.frequency(this.key(), concertPitch); | |
} | |
}; | |
// case statement to create instance of tuning class based on string | |
// is there a better way to do this? | |
function namedTuning(name) { | |
switch (name) { | |
case '12tet': | |
return new Tuning12tet(); | |
break; | |
} | |
} | |
// what parameter(s) would be passed to the tuning constructors? | |
function Tuning12tet() { | |
} | |
Tuning12tet.prototype = { | |
frequency: function(key, concertPitch) { | |
return concertPitch * Math.pow(2, (key - 49) / 12); | |
} | |
}; | |
// usage | |
var a4 = teoria.note('a4', '12tet'); | |
a4.fq(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment