@@ -5,25 +5,40 @@ define(function (require) {
55 var AudioVoice = require ( 'audioVoice' ) ;
66
77 /**
8- * An MonoSynth is used as a single voice for sound synthesis.
9- * This is a class to be used in conjonction with the PolySynth
8+ * A MonoSynth is used as a single voice for sound synthesis.
9+ * This is a class to be used in conjunction with the PolySynth
1010 * class. Custom synthetisers should be built inheriting from
1111 * this class.
1212 *
1313 * @class p5.MonoSynth
1414 * @constructor
1515 * @example
1616 * <div><code>
17- * var monosynth;
18- * var x;
17+ * var monoSynth;
1918 *
2019 * function setup() {
21- * monosynth = new p5.MonoSynth();
22- * monosynth.play(45,1,x=0,1);
23- * monosynth.play(49,1,x+=1,0.25);
24- * monosynth.play(50,1,x+=0.25,0.25);
25- * monosynth.play(49,1,x+=0.5,0.25);
26- * monosynth.play(50,1,x+=0.25,0.25);
20+ * var cnv = createCanvas(100, 100);
21+ * cnv.mousePressed(playSynth);
22+ *
23+ * monoSynth = new p5.MonoSynth();
24+ *
25+ * textAlign(CENTER);
26+ * text('click to play', width/2, height/2);
27+ * }
28+ *
29+ * function playSynth() {
30+ * // time from now (in seconds)
31+ * var time = 0;
32+ * // note duration (in seconds)
33+ * var dur = 0.25;
34+ * // velocity (volume, from 0 to 1)
35+ * var v = 0.2;
36+ *
37+ * monoSynth.play("G3", v, time, dur);
38+ * monoSynth.play("C4", v, time += dur, dur);
39+ *
40+ * background(random(255), random(255), 255);
41+ * text('click to play', width/2, height/2);
2742 * }
2843 * </code></div>
2944 **/
@@ -66,20 +81,49 @@ define(function (require) {
6681 p5 . MonoSynth . prototype = Object . create ( p5 . AudioVoice . prototype ) ;
6782
6883 /**
69- * Play tells the MonoSynth to start playing a note. This method schedules
70- * the calling of .triggerAttack and .triggerRelease.
71- *
72- * @method play
73- * @param {String | Number } note the note you want to play, specified as a
74- * frequency in Hertz (Number) or as a midi
75- * value in Note/Octave format ("C4", "Eb3"...etc")
76- * See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">
77- * Tone</a>. Defaults to 440 hz.
78- * @param {Number } [velocity] velocity of the note to play (ranging from 0 to 1)
79- * @param {Number } [secondsFromNow] time from now (in seconds) at which to play
80- * @param {Number } [sustainTime] time to sustain before releasing the envelope
81- *
82- */
84+ * Play tells the MonoSynth to start playing a note. This method schedules
85+ * the calling of .triggerAttack and .triggerRelease.
86+ *
87+ * @method play
88+ * @param {String | Number } note the note you want to play, specified as a
89+ * frequency in Hertz (Number) or as a midi
90+ * value in Note/Octave format ("C4", "Eb3"...etc")
91+ * See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">
92+ * Tone</a>. Defaults to 440 hz.
93+ * @param {Number } [velocity] velocity of the note to play (ranging from 0 to 1)
94+ * @param {Number } [secondsFromNow] time from now (in seconds) at which to play
95+ * @param {Number } [sustainTime] time to sustain before releasing the envelope
96+ * @example
97+ * <div><code>
98+ * var monoSynth;
99+ *
100+ * function setup() {
101+ * var cnv = createCanvas(100, 100);
102+ * cnv.mousePressed(playSynth);
103+ *
104+ * monoSynth = new p5.MonoSynth();
105+ *
106+ * textAlign(CENTER);
107+ * text('click to play', width/2, height/2);
108+ * }
109+ *
110+ * function playSynth() {
111+ * // time from now (in seconds)
112+ * var time = 0;
113+ * // note duration (in seconds)
114+ * var dur = 1/6;
115+ * // note velocity (volume, from 0 to 1)
116+ * var v = random();
117+ *
118+ * monoSynth.play("Fb3", v, 0, dur);
119+ * monoSynth.play("Gb3", v, time += dur, dur);
120+ *
121+ * background(random(255), random(255), 255);
122+ * text('click to play', width/2, height/2);
123+ * }
124+ * </code></div>
125+ *
126+ */
83127 p5 . MonoSynth . prototype . play = function ( note , velocity , secondsFromNow , susTime ) {
84128 // set range of env (TO DO: allow this to be scheduled in advance)
85129 var susTime = susTime || this . sustain ;
@@ -93,14 +137,26 @@ define(function (require) {
93137 * Similar to holding down a key on a piano, but it will
94138 * hold the sustain level until you let go.
95139 *
96- * @param {String | Number } note the note you want to play, specified as a
97- * frequency in Hertz (Number) or as a midi
140+ * @param {String | Number } note the note you want to play, specified as a
141+ * frequency in Hertz (Number) or as a midi
98142 * value in Note/Octave format ("C4", "Eb3"...etc")
99143 * See <a href = "https://github.com/Tonejs/Tone.js/wiki/Instruments">
100144 * Tone</a>. Defaults to 440 hz
101145 * @param {Number } [velocity] velocity of the note to play (ranging from 0 to 1)
102146 * @param {Number } [secondsFromNow] time from now (in seconds) at which to play
103147 * @method triggerAttack
148+ * @example
149+ * <div><code>
150+ * var monoSynth = new p5.MonoSynth();
151+ *
152+ * function mousePressed() {
153+ * monoSynth.triggerAttack("E3");
154+ * }
155+ *
156+ * function mouseReleased() {
157+ * monoSynth.triggerRelease();
158+ * }
159+ * </code></div>
104160 */
105161 p5 . MonoSynth . prototype . triggerAttack = function ( note , velocity , secondsFromNow ) {
106162 var secondsFromNow = secondsFromNow || 0 ;
@@ -121,6 +177,18 @@ define(function (require) {
121177 *
122178 * @param {Number } secondsFromNow time to trigger the release
123179 * @method triggerRelease
180+ * @example
181+ * <div><code>
182+ * var monoSynth = new p5.MonoSynth();
183+ *
184+ * function mousePressed() {
185+ * monoSynth.triggerAttack("E3");
186+ * }
187+ *
188+ * function mouseReleased() {
189+ * monoSynth.triggerRelease();
190+ * }
191+ * </code></div>
124192 */
125193 p5 . MonoSynth . prototype . triggerRelease = function ( secondsFromNow ) {
126194 var secondsFromNow = secondsFromNow || 0 ;
0 commit comments