Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacement of es5 functions to es6 class def feat P5.AudioVoice , P5.monosynth , p5.Envelope #509

Merged
merged 9 commits into from
Aug 10, 2020
22 changes: 16 additions & 6 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'audioworklet-polyfill';
import './shims';
import './audiocontext';

import { getAudioContext, userStartAudio } from './audiocontext';
p5.prototype.getAudioContext = getAudioContext;
p5.prototype.userStartAudio = userStartAudio;
endurance21 marked this conversation as resolved.
Show resolved Hide resolved

import './master';
import './helpers';
import './errorHandler';
Expand All @@ -19,7 +23,10 @@ import './oscillator';
import './envelope';
import './pulse';
import './noise';
import './audioin';

import AudioIn from './audioin';
p5.AudioIn = AudioIn;

import './filter';
import './eq';
import './panner3d';
Expand All @@ -33,9 +40,12 @@ import './compressor';
import './soundRecorder';
import './peakDetect';
import './gain';
import './monosynth';
import './polysynth';
import './distortion';
import './audioVoice';
import './monosynth';

import AudioVoice from './audioVoice';
p5.AudioVoice = AudioVoice;

import MonoSynth from './monosynth';
p5.MonoSynth = MonoSynth;

import './polysynth';
84 changes: 38 additions & 46 deletions src/audioVoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,47 @@ import p5sound from './master';
* @class p5.AudioVoice
* @constructor
*/
p5.AudioVoice = function () {
this.ac = p5sound.audiocontext;
this.output = this.ac.createGain();
this.connect();
p5sound.soundArray.push(this);
};

p5.AudioVoice.prototype.play = function (
note,
velocity,
secondsFromNow,
sustime
) {};

p5.AudioVoice.prototype.triggerAttack = function (
note,
velocity,
secondsFromNow
) {};

p5.AudioVoice.prototype.triggerRelease = function (secondsFromNow) {};

p5.AudioVoice.prototype.amp = function (vol, rampTime) {};
class AudioVoice {
constructor() {
this.ac = p5sound.audiocontext;
this.output = this.ac.createGain();
this.connect();
p5sound.soundArray.push(this);
}
play(note, velocity, secondsFromNow, sustime) {}

/**
* Connect to p5 objects or Web Audio Nodes
* @method connect
* @for p5.AudioVoice
* @param {Object} unit
*/
p5.AudioVoice.prototype.connect = function (unit) {
var u = unit || p5sound.input;
this.output.connect(u.input ? u.input : u);
};
triggerAttack(note, velocity, secondsFromNow) {}

/**
* Disconnect from soundOut
* @method disconnect
* @for p5.AudioVoice
*/
p5.AudioVoice.prototype.disconnect = function () {
this.output.disconnect();
};
triggerRelease(secondsFromNow) {}

p5.AudioVoice.prototype.dispose = function () {
if (this.output) {
amp(vol, rampTime) {}

/**
* Connect to p5 objects or Web Audio Nodes
* @method connect
* @for p5.AudioVoice
* @param {Object} unit
*/
connect(unit) {
var u = unit || p5sound.input;
this.output.connect(u.input ? u.input : u);
}

/**
* Disconnect from soundOut
* @method disconnect
* @for p5.AudioVoice
*/
disconnect() {
this.output.disconnect();
delete this.output;
}
};

export default p5.AudioVoice;
dispose() {
if (this.output) {
this.output.disconnect();
delete this.output;
}
}
}

export default AudioVoice;
8 changes: 4 additions & 4 deletions src/audiocontext.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Tone.setContext(audiocontext);
*
* </div></code>
*/
p5.prototype.getAudioContext = function () {
export function getAudioContext() {
return audiocontext;
};
}

/**
* <p>It is not only a good practice to give users control over starting
Expand Down Expand Up @@ -102,7 +102,7 @@ p5.prototype.getAudioContext = function () {
* }
* </code></div>
*/
p5.prototype.userStartAudio = function (elements, callback) {
export function userStartAudio(elements, callback) {
var elt = elements;
if (elements instanceof p5.Element) {
elt = elements.elt;
Expand All @@ -112,6 +112,6 @@ p5.prototype.userStartAudio = function (elements, callback) {
});
}
return StartAudioContext(audiocontext, elt, callback);
};
}

export default audiocontext;
Loading