}
// create one note instance for the pad instrument
private Event createPadNote(String note, double ts, double durationGate, double durationTotal,
double volume) {
Event event=new Event();
event.setAbstractName("pad");
event.setInstanceName("pad"+nameCount++);
event.setStarttime(ts);
event.setDuration(durationGate);
event.setLivetime(durationTotal);
event.setFrequency(scale.getValueFor(note));
event.setPitch(scale.getPitch(note));
PWM pwm=new PWM();
pwm.setAbstractName("pad-pw");
pwm.setInstanceName("pad-pw"+nameCount++);
Envelope filterEnv=new Envelope();
Sine lfo=new Sine();
Envelope volumeEnv=new Envelope();
StateVariableFilter svf=new StateVariableFilter();
StateVariableFilter hp=new StateVariableFilter();
mul mfilfreq=new mul(), mfilfreq2=new mul();
plus pfilfreq=new plus();
mul mout=new mul();
mul lfof=new mul();
mul mvol=new mul();
mul dmul=new mul();
mul dmul2=new mul();
plus dpl=new plus();
plus dpl2=new plus();
try{
lfof.setSource(IN_IMAG.i, event, FREQUENCY.i);
lfof.setSource(IN.i, ConstStream.c(0.005), OUT.i);
lfo.setSource(FREQUENCY.i, lfof, OUT.i);
hp.setSource(FREQUENCY.i, ConstStream.c(20), OUT.i);
hp.setSource(IN.i, pwm, OUT.i);
filterEnv.setSource(SYNC.i, event, GATE.i);
filterEnv.setSource(A.i, ConstStream.c(0.4), OUT.i);
filterEnv.setSource(D.i, ConstStream.c(0.7), OUT.i);
filterEnv.setSource(R.i, ConstStream.c(0.7), OUT.i);
filterEnv.setSource(S.i, ConstStream.c(0), OUT.i);
volumeEnv.setSource(SYNC.i, event, GATE.i);
volumeEnv.setSource(A.i, ConstStream.c(0.4), OUT.i);
volumeEnv.setSource(D.i, ConstStream.c(1.1), OUT.i);
volumeEnv.setSource(R.i, ConstStream.c(1.1), OUT.i);
volumeEnv.setSource(S.i, ConstStream.c(0.8), OUT.i);
pwm.setSource(FREQUENCY.i, event, FREQUENCY.i);
dmul.setSource(IN_IMAG.i, filterEnv, OUT.i);
dmul.setSource(IN.i, ConstStream.c(0.4), OUT.i);
dpl.setSource(IN_IMAG.i, dmul, OUT.i);
dpl.setSource(IN.i, ConstStream.c(0.5), OUT.i);
pwm.setSource(DUTYCYCLE.i, dpl2, OUT.i);
dpl2.setSource(IN.i, dpl, OUT.i);
dpl2.setSource(IN_IMAG.i, dmul2, OUT.i);
dmul2.setSource(IN_IMAG.i, lfo, OUT.i);
dmul2.setSource(IN.i, ConstStream.c(0.2), OUT.i);
svf.setSource(IN.i, hp, HP.i);
mfilfreq.setSource(IN.i, filterEnv, OUT.i);
mfilfreq.setSource(IN_IMAG.i, ConstStream.c(4), OUT.i);
mfilfreq2.setSource(IN.i, mfilfreq, OUT.i);
mfilfreq2.setSource(IN_IMAG.i, event, FREQUENCY.i);
pfilfreq.setSource(IN_IMAG.i, mfilfreq2, OUT.i);
pfilfreq.setSource(IN.i, event, FREQUENCY.i);
svf.setSource(FREQUENCY.i, pfilfreq, OUT.i);
svf.setSource(Q.i, ConstStream.c(0.9), OUT.i);
mout.setSource(IN_IMAG.i, volumeEnv, OUT.i);
mout.setSource(IN.i, mvol, OUT.i);
mvol.setSource(IN_IMAG.i, svf, LP.i);
mvol.setSource(IN.i, ConstStream.c(volume*totalVolume), OUT.i);
}catch(UnknownConnectionException e){
e.printStackTrace();
}catch(TypeMismatchException e){
e.printStackTrace();
}
event.addElement(pwm);
event.addElement(filterEnv);
event.addElement(volumeEnv);
event.addElement(mout);
event.addElement(mvol);
event.addElement(svf);
event.addElement(hp);
event.addElement(pfilfreq);
event.addElement(mfilfreq);
event.addElement(mfilfreq2);
event.addElement(dmul);
event.addElement(dmul2);
event.addElement(dpl);
event.addElement(lfo);
event.addElement(lfof);
event.addElement(dpl2);
NoteGateOffEvent nge=new NoteGateOffEvent(event, ts+event.getDuration(), advancerRegistry);
NoteBirthEvent nbe=new NoteBirthEvent(event, ts, advancerRegistry);
NoteGateOnEvent ng1e=new NoteGateOnEvent(event, ts+1.01/globalParameters.getSampleRate(),
advancerRegistry);
NoteDeathEvent nde=new NoteDeathEvent(event, ts+event.getLivetime(), advancerRegistry);
event.addMixerConnection(pad_L, mout, OUT.i);
event.addMixerConnection(pad_R, mout, OUT.i);
advancerRegistry.addEvent(nbe.getTimestamp(), nbe, event);
advancerRegistry.addEvent(nge.getTimestamp(), nge, event);
advancerRegistry.addEvent(ng1e.getTimestamp(), ng1e, event);
advancerRegistry.addEvent(nde.getTimestamp(), nde, event);
return event;