Saving a Preset Sequence of SynthDefs

This is yet another issue. If you want to automagically rename the controls used in Ndef role slots to have them suffixed with the slot number, you can use my #2 solution from here. Pasting it here for convenience. You probably want to comment out the debugging postlns, but they are informative on a first run to see what it does.

(~massPostmaglerInstaller = { arg newRolesSuffix = "M"; // so \mixM etc.
	var targetRoles = #[\mix, \filter, \filterIn];
	var defaultSkipNames = #["out", "i_out", "gate", "fadeTime"];
	var specificSkipNames = (mix: ["mix"], filter: ["wet"], filterIn: ["wet"]);
	var postmangler = { arg name, index, role;
		var skipNames = defaultSkipNames ++ (specificSkipNames[role] +++ index);
		name = name.asString;
		//skipNames.postln;
		if(skipNames.indexOfEqual(name).isNil) {
			name = name.asString ++ index;
			("Renamed::" + name).postln;
		} {
			("Skipped::" + name).postln;
		};
		name.asSymbol
	};
	var wrapperGen = { arg roleName, roleBuildFunc;  // curried targets
		{ arg func, proxy, channelOffset = 0, index;
			var psd = roleBuildFunc.value(func, proxy, channelOffset, index);
			psd.allControlNames.do { arg cno;
				cno.name = postmangler.value(cno.name, index, roleName) };
			psd.allControlNames.do(_.postln);
			psd
		}
	};
	targetRoles.collect { arg roleName;
		var origBuildFunc = AbstractPlayControl.buildMethods[roleName];
		var newBuildFunc = wrapperGen.value(roleName, origBuildFunc);
		var newRoleName = (roleName.asString ++ newRolesSuffix).asSymbol;
		AbstractPlayControl.buildMethods.put(newRoleName, newBuildFunc);
		(newRoleName.asString + "installed").postln;
		[newRoleName, newBuildFunc]  // ret val somewhat irrelevant
	}
})
// actually call it
~massPostmaglerInstaller.()

The default Ndef(\x)[num] = {/* blah */} is basically almost the same as Ndef(\x)[num] = \mix -> {/* blah */}, except the later add a control for the mix value, but it defaults to one. So there’s not much need to have a role that enhances the mere = “direct” slot assignment; just use \mixM produced by the above wrapper gen. Which you can of course adapt for your needs to maybe number things differently e.g. based on a global Bag count for each name per Ndef rather than slot index suffix.

1 Like