Skip to content

Commit

Permalink
replacement of es5 functions to es6 class def feat P5.AudioVoice , P5…
Browse files Browse the repository at this point in the history
….monosynth , p5.Envelope (#509)


* replacement of es5 functions to es6 class def feat P5.AudioVoice , P5.monosynth , p5.Envelope
  • Loading branch information
endurance21 authored Aug 10, 2020
1 parent f2804b9 commit 5299fea
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 350 deletions.
11 changes: 7 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,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;
2 changes: 1 addition & 1 deletion src/audioin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ p5sound.inputSources = [];
*
* function setup(){
* let cnv = createCanvas(100, 100);
* cnv.mousePressed(userStartAudio);
* cnv.mousePressed(useraudiocontextStartAudio);
* textAlign(CENTER);
* mic = new p5.AudioIn();
* mic.start();
Expand Down
3 changes: 2 additions & 1 deletion src/envelope.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,4 +897,5 @@ p5.Env = function (t1, l1, t2, l2, t3, l3) {
};
p5.Env.prototype = Object.create(p5.Envelope.prototype);

export default p5.Envelope;
const Envelope = p5.Envelope;
export default Envelope;
Loading

0 comments on commit 5299fea

Please sign in to comment.