diff --git a/Tone/source/OmniOscillator.js b/Tone/source/OmniOscillator.js index d99e5b83..0203c332 100644 --- a/Tone/source/OmniOscillator.js +++ b/Tone/source/OmniOscillator.js @@ -72,7 +72,7 @@ define(["../core/Tone", "../source/Source", "../source/Oscillator", "../source/P "frequency" : 440, "detune" : 0, "type" : "sine", - "phase" : 0, + "phase" : 0 }; /** @@ -186,6 +186,24 @@ define(["../core/Tone", "../source/Source", "../source/Oscillator", "../source/P } }); + /** + * The partial count of the oscillator. This is not available on "pwm" and "pulse" oscillator types. + * @memberOf Tone.OmniOscillator# + * @type {Number} + * @name partialCount + * @example + * //set the maximum number of partials + * osc.partialCount = 0; + */ + Object.defineProperty(Tone.OmniOscillator.prototype, "partialCount", { + get : function(){ + return this._oscillator.partialCount; + }, + set : function(partialCount){ + this._oscillator.partialCount = partialCount; + } + }); + /** * Set a member/attribute of the oscillator. * @param {Object|String} params @@ -205,6 +223,22 @@ define(["../core/Tone", "../source/Source", "../source/Oscillator", "../source/P return this; }; + /** + * Get the object's attributes. Given no arguments get + * will return all available object properties and their corresponding + * values. Pass in a single attribute to retrieve or an array + * of attributes. The attribute strings can also include a "." + * to access deeper properties. + * @param {Array=|string|undefined} params the parameters to get, otherwise will return + * all available. + * @returns {Object} + */ + Tone.OmniOscillator.prototype.get = function(params){ + var options = this._oscillator.get(params); + options.type = this.type; + return options; + }; + /** * connect the oscillator to the frequency and detune signals * @private @@ -249,6 +283,58 @@ define(["../core/Tone", "../source/Source", "../source/Oscillator", "../source/P } }); + /** + * The source type names + * @private + * @type {Object} + */ + var SourceTypeNames = { + PulseOscillator : "pulse", + PWMOscillator : "pwm", + Oscillator : "oscillator", + FMOscillator : "fm", + AMOscillator : "am", + FatOscillator : "fat" + }; + + /** + * The source type of the oscillator. + * @memberOf Tone.OmniOscillator# + * @type {String} + * @signal + * @name sourceType + * @example + * var omniOsc = new Tone.OmniOscillator(440, "fmsquare"); + * omniOsc.sourceType // 'fm' + */ + Object.defineProperty(Tone.OmniOscillator.prototype, "sourceType", { + get : function(){ + return SourceTypeNames[this._sourceType]; + }, + set : function(sType){ + //the basetype defaults to sine + var baseType = "sine"; + if (this._oscillator.type !== "pwm" && this._oscillator.type !== "pulse"){ + baseType = this._oscillator.type; + } + + //set the type + if (sType === SourceTypeNames.FMOscillator){ + this.type = "fm" + baseType; + } else if (sType === SourceTypeNames.AMOscillator){ + this.type = "am" + baseType; + } else if (sType === SourceTypeNames.FatOscillator){ + this.type = "fat" + baseType; + } else if (sType === SourceTypeNames.Oscillator){ + this.type = baseType; + } else if (sType === SourceTypeNames.PulseOscillator){ + this.type = "pulse"; + } else if (sType === SourceTypeNames.PWMOscillator){ + this.type = "pwm"; + } + } + }); + /** * The width of the oscillator (only if the oscillator is set to "pulse") * @memberOf Tone.OmniOscillator# diff --git a/test/source/OmniOscillator.js b/test/source/OmniOscillator.js index 67939c54..f22e168c 100644 --- a/test/source/OmniOscillator.js +++ b/test/source/OmniOscillator.js @@ -180,6 +180,41 @@ function(BasicTests, OmniOscillator, Offline, SourceTests, OscillatorTests, Outp omni.dispose(); }); + it("can get/set the partialCount", function(){ + var omni = new OmniOscillator({ + "type" : "square2", + }); + expect(omni.partialCount).to.equal(2); + omni.partialCount = 3; + expect(omni.partialCount).to.equal(3); + expect(omni.type).to.equal("square3"); + omni.dispose(); + }); + + it("can set the sourceType", function(){ + var omni = new OmniOscillator({ + type : "fatsquare3" + }); + expect(omni.type).to.equal("fatsquare3"); + expect(omni.sourceType).to.equal("fat"); + omni.sourceType = "oscillator"; + expect(omni.sourceType).to.equal("oscillator"); + expect(omni.type).to.equal("square3"); + omni.sourceType = "pulse"; + expect(omni.sourceType).to.equal("pulse"); + expect(omni.type).to.equal("pulse"); + omni.sourceType = "fm"; + expect(omni.sourceType).to.equal("fm"); + expect(omni.type).to.equal("fmsine"); + omni.sourceType = "pwm"; + expect(omni.sourceType).to.equal("pwm"); + expect(omni.type).to.equal("pwm"); + omni.sourceType = "am"; + expect(omni.sourceType).to.equal("am"); + expect(omni.type).to.equal("amsine"); + omni.dispose(); + }); + it("can set a FM oscillator with partials", function(){ var omni = new OmniOscillator({ "detune" : 4,