Skip to content

Commit df1ffef

Browse files
authored
replacement of es5 functions to es6 classes feat Master.js (#537)
1 parent a9531c2 commit df1ffef

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

src/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ import Compressor from './compressor';
7878
p5.Compressor = Compressor;
7979

8080

81+
8182
import peakDetect from './peakDetect';
8283
p5.peakDetect = peakDetect;
8384

85+
8486
import SoundRecorder from './soundRecorder';
8587
p5.SoundRecorder = SoundRecorder;
8688

87-
88-
8989
import Distortion from './distortion';
9090
p5.Distortion = Distortion;
9191

src/master.js

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
import audiocontext from './audiocontext.js';
22
// Master contains the master sound output.
3-
var Master = function () {
4-
this.input = audiocontext.createGain();
5-
this.output = audiocontext.createGain();
3+
class Master {
4+
constructor() {
5+
this.input = audiocontext.createGain();
6+
this.output = audiocontext.createGain();
67

7-
//put a hard limiter on the output
8-
this.limiter = audiocontext.createDynamicsCompressor();
9-
this.limiter.threshold.value = -3;
10-
this.limiter.ratio.value = 20;
11-
this.limiter.knee.value = 1;
8+
//put a hard limiter on the output
9+
this.limiter = audiocontext.createDynamicsCompressor();
10+
this.limiter.threshold.value = -3;
11+
this.limiter.ratio.value = 20;
12+
this.limiter.knee.value = 1;
1213

13-
this.audiocontext = audiocontext;
14+
this.audiocontext = audiocontext;
1415

15-
this.output.disconnect();
16+
this.output.disconnect();
1617

17-
// connect input to limiter
18-
this.input.connect(this.limiter);
18+
// connect input to limiter
19+
this.input.connect(this.limiter);
1920

20-
// connect limiter to output
21-
this.limiter.connect(this.output);
21+
// connect limiter to output
22+
this.limiter.connect(this.output);
2223

23-
// meter is just for global Amplitude / FFT analysis
24-
this.meter = audiocontext.createGain();
25-
this.fftMeter = audiocontext.createGain();
26-
this.output.connect(this.meter);
27-
this.output.connect(this.fftMeter);
24+
// meter is just for global Amplitude / FFT analysis
25+
this.meter = audiocontext.createGain();
26+
this.fftMeter = audiocontext.createGain();
27+
this.output.connect(this.meter);
28+
this.output.connect(this.fftMeter);
2829

29-
// connect output to destination
30-
this.output.connect(this.audiocontext.destination);
30+
// connect output to destination
31+
this.output.connect(this.audiocontext.destination);
3132

32-
// an array of all sounds in the sketch
33-
this.soundArray = [];
34-
// an array of all musical parts in the sketch
35-
this.parts = [];
33+
// an array of all sounds in the sketch
34+
this.soundArray = [];
35+
// an array of all musical parts in the sketch
36+
this.parts = [];
3637

37-
// file extensions to search for
38-
this.extensions = [];
39-
};
38+
// file extensions to search for
39+
this.extensions = [];
40+
}
41+
}
4042

4143
// create a single instance of the p5Sound / master output for use within this sketch
4244
const p5sound = new Master();
43-
// console.log(p5sound.audiocontext)
4445

4546
/**
4647
* Returns a number representing the master amplitude (volume) for sound

0 commit comments

Comments
 (0)