2016-11-29 18:33:09 -05:00
|
|
|
/*
|
|
|
|
|
|
|
|
A Pitch effect
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Tone = require('tone');
|
|
|
|
|
|
|
|
function PitchEffect () {
|
2016-11-30 11:29:00 -05:00
|
|
|
this.value = 0;
|
2017-01-30 11:09:45 -05:00
|
|
|
this.ratio = 1;
|
2016-11-29 18:33:09 -05:00
|
|
|
|
2016-11-30 11:29:00 -05:00
|
|
|
this.tone = new Tone();
|
2016-11-29 18:33:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PitchEffect.prototype.set = function (val, players) {
|
|
|
|
this.value = val;
|
2017-01-30 11:09:45 -05:00
|
|
|
this.ratio = this.getRatio(this.value);
|
2016-11-29 18:33:09 -05:00
|
|
|
this.updatePlayers(players);
|
|
|
|
};
|
|
|
|
|
|
|
|
PitchEffect.prototype.changeBy = function (val, players) {
|
|
|
|
this.set(this.value + val, players);
|
|
|
|
};
|
|
|
|
|
2017-01-30 11:09:45 -05:00
|
|
|
PitchEffect.prototype.getRatio = function (val) {
|
|
|
|
return this.tone.intervalToFrequencyRatio(val / 10);
|
|
|
|
};
|
|
|
|
|
|
|
|
PitchEffect.prototype.updatePlayer = function (player) {
|
|
|
|
player.setPlaybackRate(this.ratio);
|
2016-11-29 18:33:09 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
PitchEffect.prototype.updatePlayers = function (players) {
|
|
|
|
if (!players) return;
|
|
|
|
|
2017-01-30 11:09:45 -05:00
|
|
|
for (var md5 in players) {
|
|
|
|
this.updatePlayer(players[md5]);
|
2016-11-29 18:33:09 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-30 11:09:45 -05:00
|
|
|
|
|
|
|
|
2016-11-29 18:33:09 -05:00
|
|
|
module.exports = PitchEffect;
|
|
|
|
|