Cabbage Logo
Back to Cabbage Site

A-rate arrays as a buffer questions?

Question 1:
I’m trying to add a “mixer bus” style functionality to a cabbage instrument and running into some issues… not sure if what I’m trying to do should be possible, or if I’m trying something silly.

I have two global a-rate arrays, one for L and one for R, with 4 elements each. I’m not bothering to try with 2d arrays yet just to keep it simple until I get it working.

I would like each element to acts as a bus channel. the “bus” channel being read is a combobox with items(“1”, “2”, “3”, “4”)

And what I’d like to do is this:

  gaLeft[chnget("bus")-1] += aL
  gaRight[chnget("bus")-1] += aR

But this doesn’t appear to work.

I can’t use this workaround either, because channels will get overwritten by p1 and/or note priority:

  gaLeft[chnget("bus")-1] = gaLeft[chnget("bus")-1]+aL
  gaRight[chnget("bus")-1] = gaRight[chnget("bus")-1]+aR

Question 2:
What’s the proper way to clear the array buffers? clear doesn’t seem to work with arrays, nor can I set it to 0 with a simple = statement. Right now I’m using *= on the entire array which seems to do the trick, but feels very hack-ish. Plus I found it ironically strange that I can perform that operation on the full array, but not an individual element? :wink:

I’m not sure I can help here, I think I would rather use channels that global a-rate arrays. In that case you would have access to clear and chnmix :thinking:

I got it working using chnmix and chnclear. I was trying to be able to work on them as a single variable in an array, for instance clearing out an entire array at once… or applying a global volume gain to all channels, things like that. I was probably just overcomplicating it tho, especially for my specific use case.

Now the discussion I guess becomes more of the hypothetical one: Should arrays be able to be operated on in this way? It seems like they should and is currently very inconsistent in it’s behaviors between elements and the array as an entity.

I might need to find someone who regularly uses arrays more tho. Or perhaps I need to try similar concepts at k-rate so see if it’s just a-rate missing out?

Either way, it looks like my current goal was reached… thanks for prodding me in a different direction! :partying_face:

Glad you got it sorted. I think the channel bus is one of the most useful things ever added to Csound!