qambi
Version:
MIDI sequencer, loads MIDI files, can record and playback MIDI, uses WebMIDI and WebAudio
81 lines (63 loc) • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SampleBuffer = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
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 SampleBuffer = exports.SampleBuffer = function (_Sample) {
_inherits(SampleBuffer, _Sample);
function SampleBuffer(sampleData, event) {
_classCallCheck(this, SampleBuffer);
var _this = _possibleConstructorReturn(this, (SampleBuffer.__proto__ || Object.getPrototypeOf(SampleBuffer)).call(this, sampleData, event));
_this.id = _this.constructor.name + '_' + instanceIndex++ + '_' + new Date().getTime();
if (_this.sampleData === -1 || typeof _this.sampleData.buffer === 'undefined') {
// create dummy source
_this.source = {
start: function start() {},
stop: function stop() {},
connect: function connect() {}
};
} else {
_this.source = _init_audio.context.createBufferSource();
//console.log(sampleData)
_this.source.buffer = sampleData.buffer;
//console.log(this.source.buffer)
}
_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;
}
//@override
_createClass(SampleBuffer, [{
key: 'start',
value: function start(time) {
var _sampleData = this.sampleData,
sustainStart = _sampleData.sustainStart,
sustainEnd = _sampleData.sustainEnd,
segmentStart = _sampleData.segmentStart,
segmentDuration = _sampleData.segmentDuration;
//console.log(sustainStart, sustainEnd, segmentStart, segmentDuration)
if (sustainStart && sustainEnd) {
this.source.loop = true;
this.source.loopStart = sustainStart;
this.source.loopEnd = sustainEnd;
}
if (segmentStart && segmentDuration) {
console.log(segmentStart, segmentDuration);
this.source.start(time, segmentStart / 1000, segmentDuration / 1000);
} else {
this.source.start(time);
}
}
}]);
return SampleBuffer;
}(_sample.Sample);