hi, a very tricky question,
and if you put some more effort in it
to give us something ready to play with, to understand,
would have been appreciated
so i start from minim ADSR example ( possibly like you )
but work it over and check documentation
and replaced the bunch of numbers with readable variables.
/* MINIM ADSRExample */
// http://code.compartmental.net/minim/adsr_class_adsr.html
// http://code.compartmental.net/minim-beta/documentation/audiooutput_method_playnote.htm
// https://discourse.processing.org/t/adsr-and-playnote-with-minim/16057
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
class ToneInstrument implements Instrument {
Oscil sineOsc;
ADSR adsr;
float maxAmp= 0.5, attTime=0.01, decTime=0.05, susLvl = 0.01/*0.5*/, relTime = 0.5;
ToneInstrument( float frequency, float amplitude ) {
sineOsc = new Oscil( frequency, amplitude, Waves.SINE );
adsr = new ADSR( maxAmp, attTime, decTime, susLvl, relTime );
sineOsc.patch( adsr );
}
void noteOn( float dur ) {
adsr.noteOn();
adsr.patch( out );
}
void noteOff() {
adsr.unpatchAfterRelease( out );
adsr.noteOff();
}
}
void setup() {
size( 512, 200, P2D );
minim = new Minim( this );
out = minim.getLineOut( Minim.MONO, 2048 );
out.pauseNotes();
println("use key [ ]");
}
void draw() {
background( 0 );
plot();
}
void keyPressed() {
if ( key == ' ' ) play4( 440 );
}
void play4(float hz) {
println("play 4 notes "+hz+" hz");
float amp = 0.5;
float startTime=1, beat=2, duration=1; //sec
for( int i = 0; i < 4; i++ )
out.playNote( startTime + i*beat, duration, new ToneInstrument( hz, amp ) );
out.resumeNotes();
}
void plot() {
stroke( 255 );
for( int i = 0; i < out.bufferSize() - 1; i++ ) {
float x1 = map( i, 0, out.bufferSize(), 0, width );
float x2 = map( i+1, 0, out.bufferSize(), 0, width );
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
}
}
yes, you are right, it is not possible to use the
playNote(startTime, duration, instrument);
without duration, so it is not meant to play ADSR as is.
so you find a other way to play the instrument and make your own timing.
still i was able to betray that whole construct,
when, like in my above code, use
susLvl = 0.01/*0.5*/
make the Sustain tone low its
overwritten duration does not matter, works like a pause.
just a hack…