Buffer:storeOn?

Any reason Buffer doesn’t have this:

storeOn { arg stream;
	stream << this.class.name << "(" <<*
		[server.asCompileString, numFrames, numChannels, bufnum, sampleRate] <<")"
}

Would make things work with Pdef source generation etc.

Right, the lack of it is inconsistent with Bus, which does implement storeOn.

Both Buffer and Bus, however, have the same problem, in that the existence of a compileString doesn’t ensure that Server allocators are in sync (or, for Buffer, that the server has allocated memory). Pdef source generation would be valid only within a single session, though that won’t be immediately evident from the generated code.

Buffer management was one of the sticky problems I had to deal with in JITModular. I ended up attaching a JMBufferSet object to a JITModPatch, where the JMBufferSet “has-a” dictionary associating names to buffers. When the buffer set changes, the owner patch gets notified and creates, for each buffer, a control-rate nodeproxy holding the buffer number. So, audio proxies can access the buffer number by ~bufname.kr(1), and, because the source of the kr proxy contains a reference to the buffer, you can get to the buffer object by ~bufname.source.bufferand, because there’s no hard reference in code generation to Buffer.new with a bufnum that would be invalid when reloading, save/restore works too.

I.e., Buffer:storeOn might be helpful, but it’s not a magic bullet for every case.

hjh

Sure. But I think expecting storeOn to account for server state is a different and rather more complex problem. We can’t even be 100% sure that the original Buffer object is in sync.

But for something like a Pdef which is swapping in and out buffer objects this is very handy to reconstruct a past state in the same session. Otherwise the src capture is broken if a Buffer is involved.

I would suggest this be dealt with in doc?

TBH I think it would be OK to implement storeOn for Buffer, based on Bus as precedent. In that case, both would be “at your own risk, if you shoot yourself in the foot, that’s on you.”

hjh