JavaScript library for microtonal tuning systems.
Try the live demo.
- calculate cents based on various temperaments
- calculate nth harmonic of a given frequency
- ftom (frequency to MIDI function)
- mtof (MIDI to frequency function)
- get note name for a given MIDI note
import tune.js library
<script src="tune.js"></script>now you can use the library to create a tuner
// create a tuner
myTuner = new Tuner();// use custom options
var options = {
temperament: 'equal',
fundamental: 440
};
// create a new tuner
var myTuner = new Tuner(options);set the current temperament
myTuner.setTemperament("meantone");get the current temperament
myTuner.getTemperament();
// meantonecalculate the cents given a specific frequency
myTuner.tune(448);
// -7.887184708183386get nth harmonic of a given frequency
harmonic(frequency, partial)
get the 3rd harmonic of 440
Tuner.harmonic(440, 3);
// 1320calculate the frequency given a specific MIDI note
Tuner.mtof(60);
// 261.6255653005986calculate the MIDI note given a specific frequency
Tuner.ftom(440);
// 69get note name from MIDI note number
you can use a negative number to get the flat
Tuner.getNoteName(63);
// D#
// use negative number for flat
Tuner.getNoteName(-63);
// Ebor use a second argument sharp or flat to get enharmonic note name
Tuner.getNoteName(63, 'sharp');
// D#
Tuner.getNoteName(63, 'flat');
// Eb| attribute | type | options | default |
|---|---|---|---|
temperament |
string | equal, just, pythagorean, meantone, werckmeister |
equal |
fundamental |
number | any integer or float |
440 |
Set the temperament for a given tuner.
Type:
stringDefault:equalAvailable values:equaljustpythagoreanmeantonewerckmeisterIwerckmeisterIIwerckmeisterIII
Examples
// create a new tuner with meantone temperament
var myTuner = new Tuner({
temperament: "meantone"
});
// set temperament to pythagorean
myTuner.setTemperament('pythagorean');
// get current temperament
myTuner.getTemperament();
// pythagoreanSet the target frequency for a given tuner.
Type:
number
Default:440Available values:integerorfloat
Examples
// create a new tuner with fundamental 440
var myTuner = new Tuner({
fundamental: 440
});
// update fundamental to 442
myTuner.setFundamental(442);
// get current fundamental
myTuner.getFundamental();
// 442Calculte cents
Examples
// create a new tuner
var myTuner = new Tuner({
temperament: 'meantone',
fundamental: 440
});
// calculate cents
myTuner.tune(439);
// -3.939100787161778Any contributions you make are greatly appreciated. Any bugs and change requests are to be reported on the issues tab. If you don't like coding, you can contribute by becoming a sponsor.
Please write to [email protected] or visit instrument.bible.