Skip to content

Commit 5b77817

Browse files
committed
monosynth can play with default sustain time and velocity
1 parent 0662bc1 commit 5b77817

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/monosynth.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ define(function (require) {
126126
*/
127127
p5.MonoSynth.prototype.play = function (note, velocity, secondsFromNow, susTime) {
128128
// set range of env (TO DO: allow this to be scheduled in advance)
129-
var susTime = susTime || this.sustain;
130-
this.susTime = susTime;
131-
this.triggerAttack(note, velocity, secondsFromNow);
132-
this.triggerRelease(secondsFromNow + susTime);
129+
if (typeof susTime === 'number') {
130+
this.susTime = susTime;
131+
}
132+
this.triggerAttack(note, velocity, ~~secondsFromNow);
133+
this.triggerRelease(~~secondsFromNow + susTime);
133134
};
134135

135136
/**
@@ -160,11 +161,10 @@ define(function (require) {
160161
*/
161162
p5.MonoSynth.prototype.triggerAttack = function (note, velocity, secondsFromNow) {
162163
var secondsFromNow = secondsFromNow || 0;
163-
164164
//triggerAttack uses ._setNote to convert a midi string to a frequency if necessary
165165
var freq = typeof note === 'string' ? this._setNote(note)
166166
: typeof note === 'number' ? note : 440;
167-
var vel = velocity || 1;
167+
var vel = velocity || 0.1;
168168
this._isOn = true;
169169
this.oscillator.freq(freq, 0, secondsFromNow);
170170
this.env.ramp(this.output, secondsFromNow, vel);

0 commit comments

Comments
 (0)