Cabbage Logo
Back to Cabbage Site

Confused about kBPM chnget "HOST_BPM"

I exported HostInfo as an effect plugin. When first loaded in Logic all of the fields (BPM, Playing, etc.) are blank. Press “play” and they remain blank. Press “record” and they populate. Play a track that has no audio, then a snippet of audio … fields are blank until the audio region is reached.

Logic has a unique way to running plugins. It won’t actually call the main processing method unless there is some audio to process. If the main processing method is not called, Csound is not called. So whatever way you work things, you will have to keep this in mind. But on the plus side, it doesn’t crash, so it looks like it might be something with your code? If you want to send me on the full csd you’re seeing the crash with I can test.

That is interesting. I’m planning to use the effect on a bus, not a track. I wonder how that will impact the chnget functions.

And — more importantly — I’m planning to use it with live audio, recording the output to a an audio track. Requiring audio (which I assume means recorded audio?) might make relying on the host bpm impossible.

The issue is a division by zero. So first of all, you should be using a k-rate var for the BPM. i-rate is fine for the plugin test as it can only ever be a plugin or not a plugin. Then whereever you did something like this:

kdel_length1 = kDelay1 * sr * (60/kBPM)

do this instead:

kdel_length1 = kDelay1 * sr * divz:k(60, kBPM, 60)

The problem is that the host BPM might not be known immediately, and will return a 0, which causes the div by zero issue. This should fix it. :slight_smile:

Hmm … it passes Logic’s scanning test now. But when I actually load it on a track I get the following error message:

“An Audio Unit plug-in reported a problem which might cause the system to become unstable. Please quit and restart Logic Pro.”

Maybe it makes more sense to check if HOST_BPM is undefined and set it to a friendly value outside of the loop instead of this divide by zero check?

That’s strange, I’m not getting any issues here. you can check if host bmp is 0 and then another value accordingly. Worth a try.

Here’s what ended up working:

kBPM init 60
kPlug chnget "IS_A_PLUGIN"
if kPlug == 1 then
   kBPM chnget "HOST_BPM"
   if kBPM == -1 || kBPM == 0 then
        kBPM = 60
   endif
endif

The plugin now responds to BPM changes!

Thank you!

1 Like