[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Free a collection of buffers for reuse?



You’re wiping out your ~bufs variable on each call to ~changesamples…  So the easiest fix would be to not set it, or else only initialize it to something if it’s already not set…

// The following will assign the value of the function { [] } if ~bufs is currently nil, otherwise it will just leave it as-is.
~bufs = ~bufs ?? { [] };

Probably better to just eliminate that “initialise ~bufs to something” line entirely.  Your ~bufs.collect (lower down) to free existing Buffers won’t do any harm if it’s called with nil or an empty array.  (Also, it won’t affect anything, but your “collect” could be changed to “do”, because you’re not really wanting to return something, just do a free action for each Buffer!)

Hope that helps,
Glen.

> On 30 Dec 2016, at 13:34, tedthetrumpet <tedthetrumpet@xxxxxxxxx> wrote:
> 
> I have a function called ~changesamples, below. This reads through one of a
> number of subfolders of a folder called 'bfsamples', and then loads the
> samples found in the named subfolder into an array called ~bufs. Problem is:
> say I evaluate ~changesamples.("hitz01") to load buffers 0-9 with ten
> samples. If I now evaluate ~changesamples.("soh"), the new files are loaded
> into buffers 10-19, and buffers 0-9 are not freed.
> 
> In a previous version of the function, I had Buffer.freeAll in before the
> new files were loaded, which seemed to work. However, now have other
> collections of buffers elsewhere in my project that I do not want to be
> freed when ~changesamples executes.
> 
> I'm guessing that this is some sort of race condition betwen the old buffers
> being freed and the new ones filled, as it works if I run these lines one at
> a time. Any ideas how to do this? Thanks!
> 
> (
> ~changesamples = {
> 	|x="hitz01"|
> 	~bufs = [Buffer.new]; // initialise ~bufs to something
> 	if ( "hitz01 soh hamburg iowaphil emf nl".find(x) != nil, // checking the
> subfolder is correct
> 		{	var path = "../bfsamples/".resolveRelative ++ x ++ "/";
> 			var files = (path ++ "*.aiff").pathMatch ++ (path ++ "*.aif").pathMatch;
> 			// first, free all the buffers in ~bufs
> 			~bufs.collect({|i| i.free});
> 			// now, read the new files into ~bufs
> 			~bufs = files.collect({ |i|  Buffer.read(s, i)});
> 		},
> 		{"that's not a sample folder".error; nil});
> };
> )
> 
> 
> 
> -----
> -- 
> J. Simon van der Walt
> jsimonvanderwalt.com
> twitter.com/tedthetrumpet
> --
> View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Free-a-collection-of-buffers-for-reuse-tp7629824.html
> Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.
> 
> _______________________________________________
> sc-users mailing list
> 
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: https://listarc.bham.ac.uk/marchives/sc-users/
> search: https://listarc.bham.ac.uk/lists/sc-users/search/


_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/