Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed May 2, 2022
1 parent bd5a654 commit e9c98f3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
26 changes: 22 additions & 4 deletions javascript/JZZ.synth.OSC.js
@@ -1,4 +1,5 @@
(function(global, factory) {
/* istanbul ignore next */
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = factory;
}
Expand All @@ -10,13 +11,20 @@
}
})(this, function(JZZ) {

/* istanbul ignore next */
if (!JZZ) return;
/* istanbul ignore next */
if (!JZZ.synth) JZZ.synth = {};
/* istanbul ignore next */
if (JZZ.synth.OSC) return;

var _version = '1.1.9';
var _version = '1.2.0';

var _ac = JZZ.lib.getAudioContext();
var _ac;
function initAC() {
if (!_ac) _ac = JZZ.lib.getAudioContext();
return !!_ac;
}

function Synth() {
this.ac = _ac;
Expand All @@ -36,6 +44,7 @@
var b = arr[0];
var n = arr[1];
var v = arr[2];
/* istanbul ignore next */
if (b < 0 || b > 255) return;
var c = b & 15;
var s = b >> 4;
Expand Down Expand Up @@ -108,7 +117,9 @@
this.oscillator = this.channel.synth.ac.createOscillator();
this.oscillator.type = 'sawtooth';
this.oscillator.frequency.setTargetAtTime(this.freq, this.channel.synth.ac.currentTime, 0.005);
/* istanbul ignore next */
if (!this.oscillator.start) this.oscillator.start = this.oscillator.noteOn;
/* istanbul ignore next */
if (!this.oscillator.stop) this.oscillator.stop = this.oscillator.noteOff;

this.gain = this.channel.synth.ac.createGain();
Expand Down Expand Up @@ -136,7 +147,9 @@
this.oscillator = this.channel.synth.ac.createOscillator();
this.oscillator.type = 'sine';
this.oscillator.frequency.setTargetAtTime(this.freq, this.channel.synth.ac.currentTime, 0.005);
/* istanbul ignore next */
if (!this.oscillator.start) this.oscillator.start = this.oscillator.noteOn;
/* istanbul ignore next */
if (!this.oscillator.stop) this.oscillator.stop = this.oscillator.noteOff;

this.gain = this.channel.synth.ac.createGain();
Expand Down Expand Up @@ -166,7 +179,12 @@
};

_engine._openOut = function(port, name) {
if (!_ac) { port._crash('AudioContext not supported'); return; }
initAC();
/* istanbul ignore next */
if (!_ac) {
port._crash('AudioContext not supported');
return;
}
var synth;
if (typeof name !== 'undefined') {
name = '' + name;
Expand All @@ -188,7 +206,7 @@
};

JZZ.synth.OSC.register = function(name) {
return _ac ? JZZ.lib.registerMidiOut(name, _engine) : false;
return initAC() ? JZZ.lib.registerMidiOut(name, _engine) : false;
};

JZZ.synth.OSC.version = function() { return _version; };
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.synth.OSC.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "jzz-synth-osc",
"version": "1.1.9",
"version": "1.2.0",
"description": "Fallback MIDI-Out implementation",
"main": "javascript/JZZ.synth.OSC.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
"grunt": "^1.5.2",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-uglify": "^5.2.1",
"mocha": "^9.2.2",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"web-audio-test": "^0.0.1"
},
Expand Down
15 changes: 15 additions & 0 deletions test/mocha.js
Expand Up @@ -17,6 +17,21 @@ describe('register', function() {
describe('web-audio', function() {
it('create', function() {
synth = JZZ.synth.OSC();
synth.program(0, 1);
synth.noteOn(0, 'C5', 127);
synth.noteOff(0, 'C5');
synth.damper(0);
synth.noteOn(9, 'C5', 127);
synth.noteOff(9, 'C5', 127);
synth.damper(0, false);
synth.allSoundOff(0);
synth.portamento(0, 'C5');
});
it('plug', function() {
JZZ.synth.OSC.register('synth');
synth = JZZ().openMidiOut('synth');
synth = JZZ().openMidiOut('synth');
synth.plug();
synth.plug({ context: JZZ.lib.getAudioContext() });
});
});

0 comments on commit e9c98f3

Please sign in to comment.