Skip to content

Commit

Permalink
Merge branch 'alexanderwallin-utility-effects'
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodeus committed Sep 19, 2016
2 parents f415c82 + 736801c commit eb460e0
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -21,6 +21,8 @@ Effect list:
<li>Bitcrusher</li>
<li>Moog Filter</li>
<li>Ping Pong Delay</li>
<li>Panner</li>
<li>Gain</li>
</ul>

Usage
Expand Down
58 changes: 58 additions & 0 deletions tests/tests.js
Expand Up @@ -554,6 +554,64 @@ describe("In Tuna", function() {
wahwah.bypass = false;
expect(wahwah.activateCallback).toHaveBeenCalled();
});
});

describe("a Gain node", function() {
var gain;

beforeEach(function() {
gain = new tuna.Gain();
});

it("will have default values set", function() {
expect(gain.gain.value).toEqual(1);
expect(gain.bypass).toBeFalsy();
});

it("will have passed values set", function() {
gain = new tuna.Gain({
gain: 3,
bypass: true
});
expect(gain.gain.value).toEqual(3);
expect(gain.bypass).toBeTruthy();
});

it("will be activated", function() {
gain.activateCallback = jasmine.createSpy();
gain.bypass = true;
gain.bypass = false;
expect(gain.activateCallback).toHaveBeenCalled();
});
});

describe("a Panner node", function() {
var panner;

beforeEach(function() {
panner = new tuna.Panner();
});

it("will have default values set", function() {
expect(panner.pan.value).toEqual(0);
expect(panner.bypass).toBeFalsy();
});

it("will have passed values set", function() {
panner = new tuna.Panner({
pan: 0.75,
bypass: true
});
expect(panner.pan.value).toEqual(0.75);
expect(panner.bypass).toBeTruthy();
});

it("will be activated", function() {
panner.activateCallback = jasmine.createSpy();
panner.bypass = true;
panner.bypass = false;
expect(panner.activateCallback).toHaveBeenCalled();
});

});
});
4 changes: 2 additions & 2 deletions tuna-min.js

Large diffs are not rendered by default.

94 changes: 94 additions & 0 deletions tuna.js
Expand Up @@ -1023,6 +1023,52 @@
}
});

Tuna.prototype.Gain = function(properties) {
if (!properties) {
properties = this.getDefaults();
}

this.input = userContext.createGain();
this.activateNode = userContext.createGain();
this.gainNode = userContext.createGain();
this.output = userContext.createGain();

this.activateNode.connect(this.gainNode);
this.gainNode.connect(this.output);

this.gain = initValue(properties.gain, this.defaults.gain.value);
this.bypass = properties.bypass || false;
};
Tuna.prototype.Gain.prototype = Object.create(Super, {
name: {
value: "Gain"
},
defaults: {
writable: true,
value: {
bypass: {
value: false,
automatable: false,
type: BOOLEAN
},
gain: {
value: 1.0,
automatable: true,
type: FLOAT
}
}
},
gain: {
enumerable: true,
get: function() {
return this.gainNode.gain;
},
set: function(value) {
this.gainNode.gain.value = value;
}
}
});

Tuna.prototype.MoogFilter = function(properties) {
if (!properties) {
properties = this.getDefaults();
Expand Down Expand Up @@ -1290,6 +1336,54 @@
}
});

Tuna.prototype.Panner = function(properties) {
if (!properties) {
properties = this.getDefaults();
}

this.input = userContext.createGain();
this.activateNode = userContext.createGain();
this.panner = userContext.createStereoPanner();
this.output = userContext.createGain();

this.activateNode.connect(this.panner);
this.panner.connect(this.output);

this.pan = initValue(properties.pan, this.defaults.pan.value);
this.bypass = properties.bypass || false;
};
Tuna.prototype.Panner.prototype = Object.create(Super, {
name: {
value: "Panner"
},
defaults: {
writable: true,
value: {
bypass: {
value: false,
automatable: false,
type: BOOLEAN
},
pan: {
value: 0.0,
min: -1.0,
max: 1.0,
automatable: true,
type: FLOAT
}
}
},
pan: {
enumerable: true,
get: function() {
return this.panner.pan;
},
set: function(value) {
this.panner.pan.value = value;
}
}
});

Tuna.prototype.Phaser = function(properties) {
if (!properties) {
properties = this.getDefaults();
Expand Down

0 comments on commit eb460e0

Please sign in to comment.