I’m pretty new to SC and am struggling with how to access Buffer information (such as bufnum, numChannels, numFrames, sampleRate) within a Pbind, using either Pkey or Pswitch.
I’d like to be able to set the key \bufnum and then be able to refer to it in other key pairs to access numChannels, numFrames etc.
As a simple example, if I want to change \rate depending on the number of channels of a particular Buffer in the Array ~stuff, this does not work:
~test = Pbind( \instrument, \bufsynth, \bufnum, 107, \rate, ~stuff[Pkey(\bufnum)].numChannels ).asStream; x= ~test.next(());
It gives me an “Index not an Integer” error. I’ve tried numerous variations (too many to list here), including Pkey(\bufnum).asInteger, but I always get the “Index not an Integer” error.
I’ve also tried to use Pswitch, as in the following:
~test = Pbind( \instrument, \bufsynth, \bufnum, 107, \rate, Pswitch(~stuff, Pkey(\bufnum)).numChannels ).asStream; x= ~test.next(());
This does not give an error, but it does not give the right result. It always gives a value of 1, even for stereo buffers. Also, if I use .numFrames instead, then I do get an error ("‘numFrames’ not understood").
Can anyone help me understand what is going on? And how I can access Buffer information by referring back to a key like \bufnum in the examples above?