Skip to content

Commit 5bad8cb

Browse files
authored
Merge pull request #697 from KevinGrajeda/typesToMonosynth
Added setType and getType to MonoSynth
2 parents ef20da3 + 6e919b6 commit 5bad8cb

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/monosynth.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,29 @@ class MonoSynth extends AudioVoice {
298298
this.env.setADSR(attack, decay, sustain, release);
299299
}
300300

301+
/**
302+
* Set type to 'sine', 'triangle', 'sawtooth' or 'square'.
303+
*
304+
* @method setType
305+
* @for p5.MonoSynth
306+
* @param {String} type 'sine', 'triangle', 'sawtooth' or 'square'.
307+
*/
308+
setType(type) {
309+
this.oscillator.setType(type);
310+
}
311+
312+
/**
313+
* Returns current type of internal oscillator eg. 'sine', 'triangle', 'sawtooth' or 'square'.
314+
*
315+
* @method getType
316+
* @for p5.MonoSynth
317+
* @returns {String} type of internal oscillator eg. 'sine', 'triangle', 'sawtooth' or 'square'.
318+
*/
319+
320+
getType() {
321+
return this.oscillator.getType();
322+
}
323+
301324
/**
302325
* MonoSynth amp
303326
* @method amp

test/tests/p5.MonoSynth.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ describe('p5.MonoSynth', function () {
162162
expect(monosynth.env.dLevel).to.equal(0.565);
163163
});
164164

165+
it('can setType and getType of oscillator', function () {
166+
let monosynth = new p5.MonoSynth();
167+
//defaults to sine
168+
expect(monosynth.getType()).to.equal('sine');
169+
monosynth.setType('square');
170+
expect(monosynth.getType()).to.equal('square');
171+
});
172+
165173
it("can use amp to get and set osc's amp value", function (done) {
166174
let monosynth = new p5.MonoSynth();
167175

0 commit comments

Comments
 (0)