Scheduling and turning off fractional instruments

Here’s the solution that works. It’s very close to the first code I posted. The main difference is that I’m setting the event duration to 3600 instead of -1. There was something about using negative duration values that wasn’t playing well with turnoff/turnoff2 and the linsegr/expsegr amplitude envelopes.

I’m surprised this works because I thought I read somewhere that turnoff won’t allow the linsegr/expsegr envelopes to play out, but that’s not the case. Overall, compared to the solution I came up with a few days ago, this crossfade is much more elegant from a coding perspective and sounds smoother.

Thanks Rory for your pivotal input on this!

Jason

; read ktimescale, kloop_end, and kcrossfade_duration from GUI
; kloop_end and kcrossfade_duration are expressed in numbers of samples

kcrossfade init 0
kndx = 0
while (kndx < ksmps) do
	aphs[kndx] = kphs/sr
	kphs = kphs + ktimescale 
	kndx += 1 
od

if kphs > kloop_end then
	if kcrossfade == 0 then
		event "i", p1, 0, 3600, p4, kreset_count
		kcrossfade = 1
        turnoff
	endif
endif

irelease = chnget:i(SCrossfadeDurationChannel)
kamp_env linsegr 0.00, 0.01, 1, irelease/44100, 0.00
asigl mincer aphs, kamp*kamp_env, kpitch, kfunction, ilock, 2048, 10
1 Like