piano-mp3
Version:
This is a repo for holding MP3 files for an acoustic piano, sampled directly from this [repo](https://github.com/gleitz/midi-js-soundfonts). These are exposed for use in another repo. The `/example` is a good show of what this repo can/will be used for.
34 lines (27 loc) • 733 B
JavaScript
var path = require('path');
var Tone = require('tone');
var Notes = require('./notes');
function Player() {
this.buffers = {};
this.player = null;
};
Player.prototype.make = function() {
this.makeBuffers();
this.makePlayer();
};
Player.prototype.makeBuffers = function() {
for (var i = 0, len = Notes.notes.length; i < len; i++) {
var n = Notes.notes[i];
this.buffers[n] = new Tone.Buffer(path.resolve(__dirname, '../piano-mp3/' + n + '.mp3'));
}
};
Player.prototype.makePlayer = function() {
this.player = new Tone.Player({
retrigger: true,
}).toMaster();
};
Player.prototype.playNote = function(note) {
this.player.buffer = this.buffers[note];
this.player.start();
};
module.exports = Player;