// create one note instance for the solo instrument
private Event createSoloNote(note n, double volume) {
double effvol=volume;
if(n.beats<1.0/8)
effvol*=0.7;
Event event=new Event();
SawTooth st=new SawTooth();
WhiteNoise pn=new WhiteNoise();
mul noisevol=new mul();
mul sawvol=new mul();
Envelope noiseenv=new Envelope();
Envelope sawenv=new Envelope();
Sine dclfo1=new Sine();
Sine dclfo2=new Sine();
mul lfomul1=new mul(), lfomul2=new mul();
mul lfomul1a=new mul(), lfomul2a=new mul();
plus lfopl1=new plus(), lfopl2=new plus();
Mixer out=new Mixer();
try{
lfomul1.setSource(IN_IMAG.i, ConstStream.c(n.frequency), OUT.i);
lfomul1.setSource(IN.i, ConstStream.c(0.00033), OUT.i);
dclfo1.setSource(FREQUENCY.i, lfomul1, OUT.i);
lfomul1a.setSource(IN_IMAG.i, dclfo1, OUT.i);
lfomul1a.setSource(IN.i, ConstStream.c(0.333), OUT.i);
lfopl1.setSource(IN_IMAG.i, lfomul1a, OUT.i);
lfopl1.setSource(IN.i, ConstStream.c(0.5), OUT.i);
lfomul2.setSource(IN_IMAG.i, ConstStream.c(n.frequency), OUT.i);
lfomul2.setSource(IN.i, ConstStream.c(0.00013), OUT.i);
dclfo2.setSource(FREQUENCY.i, lfomul2, OUT.i);
lfomul2a.setSource(IN_IMAG.i, dclfo2, OUT.i);
lfomul2a.setSource(IN.i, ConstStream.c(0.133), OUT.i);
lfopl2.setSource(IN_IMAG.i, lfomul2a, OUT.i);
lfopl2.setSource(IN.i, lfopl1, OUT.i);
st.setSource(FREQUENCY.i, ConstStream.c(n.frequency), OUT.i);
st.setSource(DUTYCYCLE.i, lfopl2, OUT.i);
out.setSource(-1, sawvol, OUT.i);
out.setSource(-1, ConstStream.c(0.5*effvol), OUT.i);
out.setSource(-2, noisevol, OUT.i);
out.setSource(-2, ConstStream.c(0.4*effvol), OUT.i);
sawvol.setSource(IN_IMAG.i, st, OUT.i);
noisevol.setSource(IN_IMAG.i, pn, OUT.i);
sawvol.setSource(IN.i, sawenv, OUT.i);
noisevol.setSource(IN.i, noiseenv, OUT.i);
noiseenv.setSource(SYNC.i, event, GATE.i);
sawenv.setSource(SYNC.i, event, GATE.i);
noiseenv.setSource(A.i, ConstStream.c(0.02), OUT.i);
noiseenv.setSource(D.i, ConstStream.c(0.23), OUT.i);
noiseenv.setSource(S.i, ConstStream.c(0.05), OUT.i);
sawenv.setSource(A.i, ConstStream.c(0.02), OUT.i);
sawenv.setSource(D.i, ConstStream.c(1), OUT.i);
if(n.legato){
sawenv.setSource(S.i, ConstStream.c(0.3), OUT.i);
sawenv.setSource(R.i, ConstStream.c(1), OUT.i);
noiseenv.setSource(R.i, ConstStream.c(1), OUT.i);
}else{
sawenv.setSource(S.i, ConstStream.c(0.2), OUT.i);
sawenv.setSource(R.i, ConstStream.c(0.01), OUT.i);
noiseenv.setSource(R.i, ConstStream.c(0.01), OUT.i);
}
}catch(UnknownConnectionException e){
e.printStackTrace();
}catch(TypeMismatchException e){
e.printStackTrace();
}
double ts=getTimestamp(n.startbeat);
event.setStarttime(ts);
if(n.legato){
event.setDuration(n.beats/16/tempo);
}else{
event.setDuration(Math.min(n.beats, 0.5)/16/tempo*0.6);
}
event.setLivetime(event.getDuration()+1);
event.setFrequency(n.frequency);
// System.out.println("solo note "+n.frequency+"Hz at "+ts+" for "+event.getDuration()+"/"+event.getLivetime()+"(beats:"+n.beats+","+tempo+")");
event.setPitch(n.pitch);
event.addElement(st);
event.addElement(pn);
event.addElement(noisevol);
event.addElement(noiseenv);
event.addElement(sawvol);
event.addElement(sawenv);
event.addElement(out);
event.addElement(dclfo1);
event.addElement(dclfo2);
event.addElement(lfomul1);
event.addElement(lfomul2);
event.addElement(lfomul1a);
event.addElement(lfomul2a);
event.addElement(lfopl1);
event.addElement(lfopl2);
NoteGateOffEvent ng0e=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(solo_L, out, OUT.i);
event.addMixerConnection(solo_R, out, OUT.i);
advancerRegistry.addEvent(nbe.getTimestamp(), nbe, event);
advancerRegistry.addEvent(ng0e.getTimestamp(), ng0e, event);
advancerRegistry.addEvent(ng1e.getTimestamp(), ng1e, event);
advancerRegistry.addEvent(nde.getTimestamp(), nde, event);
return event;