@@ -20,7 +20,7 @@ define(function (require) {
20
20
* <div><code>
21
21
* var monosynth;
22
22
* var x;
23
- *
23
+ *
24
24
* function setup() {
25
25
* monosynth = new p5.MonoSynth();
26
26
* monosynth.loadPreset('simpleBass');
@@ -54,7 +54,6 @@ define(function (require) {
54
54
55
55
// this.oscillator.connect(this.filter);
56
56
this . env . setInput ( this . oscillator ) ;
57
- this . env . connect ( this . filter ) ;
58
57
this . filter . connect ( this . output ) ;
59
58
60
59
this . oscillator . start ( ) ;
@@ -67,6 +66,7 @@ define(function (require) {
67
66
p5sound . soundArray . push ( this ) ;
68
67
} ;
69
68
69
+ p5 . MonoSynth . prototype = Object . create ( p5 . AudioVoice . prototype ) ;
70
70
71
71
/**
72
72
* Used internally by play() and triggerAttack()
@@ -75,8 +75,8 @@ define(function (require) {
75
75
* Synth creators with more complex setups may have overridden
76
76
* the oscillator chain with more than one oscillator,
77
77
* and should override this method accordingly.
78
- *
79
- * @param {Number } note midi value of a note, where
78
+ *
79
+ * @param {Number } note midi value of a note, where
80
80
* middle c is 60
81
81
* @param {Number } [secondsFromNow] (optional) a time (in seconds
82
82
* from now) at which
@@ -90,53 +90,53 @@ define(function (require) {
90
90
91
91
/**
92
92
* Play tells the MonoSynth to start playing a note
93
- *
94
- * @method playNote
93
+ *
94
+ * @method play
95
95
* @param {Number } [note] midi note to play (ranging from 0 to 127 - 60 being a middle C)
96
96
* @param {Number } [velocity] velocity of the note to play (ranging from 0 to 1)
97
97
* @param {Number } [secondsFromNow] time from now (in seconds) at which to play
98
98
* @param {Number } [sustainTime] time to sustain before releasing the envelope
99
- *
100
- */
99
+ *
100
+ */
101
101
102
102
p5 . MonoSynth . prototype . play = function ( note , velocity , secondsFromNow , susTime ) {
103
103
// set range of env (TO DO: allow this to be scheduled in advance)
104
- var vel = velocity || 1 ;
105
-
106
- this . triggerAttack ( note , vel , secondsFromNow ) ;
104
+ var susTime = susTime || this . sustain ;
105
+ this . triggerAttack ( note , veocity , secondsFromNow ) ;
107
106
this . triggerRelease ( secondsFromNow + susTime ) ;
108
107
} ;
109
108
110
109
/**
111
110
* Trigger the Attack, and Decay portion of the Envelope.
112
111
* Similar to holding down a key on a piano, but it will
113
- * hold the sustain level until you let go.
112
+ * hold the sustain level until you let go.
114
113
*
115
114
* @param {Number } secondsFromNow time from now (in seconds)
116
115
* @param {Number } [velocity] velocity of the note to play (ranging from 0 to 1)
117
116
* @param {Number } [secondsFromNow] time from now (in seconds) at which to play
118
117
* @method triggerAttack
119
- */
118
+ */
120
119
p5 . MonoSynth . prototype . triggerAttack = function ( note , velocity , secondsFromNow ) {
121
- //scheduling in relation to audioContext.currentTime will be handeled by oscillator.frew() and env.ramp()
122
- var tFromNow = secondsFromNow || 0 ;
123
- var n = p5 . prototype . midiToFreq ( note ) ;
124
- this . _isOn = true ;
120
+ var secondsFromNow = secondsFromNow || 0 ;
121
+ var freq = p5 . prototype . midiToFreq ( note ) ;
122
+ var vel = velocity || 1 ;
125
123
126
- this . oscillator . freq ( n , 0 , tFromNow ) ;
127
- this . env . ramp ( this . output , tFromNow , velocity ) ;
124
+ this . _isOn = true ;
125
+ this . oscillator . freq ( freq , 0 , secondsFromNow ) ;
126
+ this . env . ramp ( this . output , secondsFromNow , vel ) ;
128
127
} ;
129
128
130
129
/**
131
130
* Trigger the Release of the Envelope. This is similar to releasing
132
131
* the key on a piano and letting the sound fade according to the
133
132
* release level and release time.
134
- *
133
+ *
135
134
* @param {Number } secondsFromNow time to trigger the release
136
135
* @method triggerRelease
137
- */
136
+ */
138
137
139
138
p5 . MonoSynth . prototype . triggerRelease = function ( secondsFromNow ) {
139
+ var secondsFromNow = secondsFromNow || 0 ;
140
140
this . env . ramp ( this . output , secondsFromNow , 0 ) ;
141
141
this . _isOn = false ;
142
142
} ;
@@ -149,11 +149,11 @@ define(function (require) {
149
149
* For instance if you want to build a complex synthesizer
150
150
* with one or more filters, effects etc. this is where you
151
151
* will want to set their values.
152
- *
152
+ *
153
153
* @method setParams
154
- * @param
155
- *
156
- */
154
+ * @param
155
+ *
156
+ */
157
157
158
158
p5 . MonoSynth . prototype . setParams = function ( params ) {
159
159
} ;
@@ -232,7 +232,7 @@ define(function (require) {
232
232
* <a href="https://en.wikipedia.org/wiki/Synthesizer#/media/File:ADSR_parameter.svg">
233
233
* ADSR envelope
234
234
* </a>.
235
- *
235
+ *
236
236
* @method setADSR
237
237
* @param {Number } attackTime Time (in seconds before envelope
238
238
* reaches Attack Level
@@ -261,7 +261,7 @@ define(function (require) {
261
261
* @param {Number } sustain
262
262
* @param {Number } release
263
263
*/
264
- Object . defineProperties ( p5 . MonoSynth , {
264
+ Object . defineProperties ( p5 . MonoSynth . prototype , {
265
265
'attack' : {
266
266
get : function ( ) {
267
267
return this . env . aTime ;
@@ -339,7 +339,7 @@ define(function (require) {
339
339
340
340
/**
341
341
* Get rid of the MonoSynth and free up its resources / memory.
342
- *
342
+ *
343
343
* @method dispose
344
344
*/
345
345
p5 . MonoSynth . prototype . dispose = function ( ) {
0 commit comments