qambi
Version:
MIDI sequencer, loads MIDI files, can record and playback MIDI, uses WebMIDI and WebAudio
64 lines (49 loc) • 2.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SampleOscillator = undefined;
var _sample = require('./sample');
var _init_audio = require('./init_audio');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var instanceIndex = 0;
var SampleOscillator = exports.SampleOscillator = function (_Sample) {
_inherits(SampleOscillator, _Sample);
function SampleOscillator(sampleData, event) {
_classCallCheck(this, SampleOscillator);
var _this = _possibleConstructorReturn(this, (SampleOscillator.__proto__ || Object.getPrototypeOf(SampleOscillator)).call(this, sampleData, event));
_this.id = _this.constructor.name + '_' + instanceIndex++ + '_' + new Date().getTime();
if (_this.sampleData === -1) {
// create dummy source
_this.source = {
start: function start() {},
stop: function stop() {},
connect: function connect() {}
};
} else {
// @TODO add type 'custom' => PeriodicWave
var type = _this.sampleData.type;
_this.source = _init_audio.context.createOscillator();
switch (type) {
case 'sine':
case 'square':
case 'sawtooth':
case 'triangle':
_this.source.type = type;
break;
default:
_this.source.type = 'square';
}
_this.source.frequency.value = event.frequency;
}
_this.output = _init_audio.context.createGain();
_this.volume = event.data2 / 127;
_this.output.gain.value = _this.volume;
_this.source.connect(_this.output);
//this.output.connect(context.destination)
return _this;
}
return SampleOscillator;
}(_sample.Sample);