Welcome to %s forums

BrainModular Users Forum

Login Register

Storing and recalling preset according to list text

I need help on a Patch
Post Reply
gthibert
Member
Posts: 46
Location: Chicoutimi, Québec
Contact:

Unread post by gthibert » 05 Mar 2011, 09:47

Hi all,

I've got a problem with a patch and I need help. I can't figure out where's the problem.

I built a patch that allows me to store and recall presets according to a selected item in a list. This is not simply based on the list index, but on the text itself. The idea is to be able to change the order of items in the list and keep the preset associated. My goal is to store in a preset all the parameters linked to a sample in the sampler file list.

My patch is based on a script. I tryed several things, but the easiest and most effective way I've found is by using comma separated text and TStringList. If someone have a better idea...

In facts, my patch works A1... as long as I don't save and reload the workspace. Then, the script only recalls the first 8-10 elements saved in the comma text list. And I can't figure out why...maybe it's simply a Usine bug. Maybe the comma text I try to save is too long for a ptTextfield.

So, I've prepared an exemple patch :

preset_manager.pat

And here is the script :

Code: Select all

//////////////////////////
// 
/////////////////////////
// parameters declaration

var inPresetName	: Tparameter;
var inStore		: Tparameter;
var inRecall		: Tparameter;
var inCleanup		: Tparameter;
var inClear		: Tparameter;
var inCommaList	: Tparameter;
var presetsComma : Tparameter;

var filesList	: TStringList;
var presetsList 	: TStringList;

// initialisation : create parameters
procedure init;
begin  
	inPresetName := CreateParam('preset name',ptTextfield); 
	SetIsOutPut(inPresetName,false);
	
	inCommaList := CreateParam('comma text',ptTextfield); 
	SetIsOutPut(inCommaList,false);
	
	presetsComma := CreateParam('preset comma',ptTextfield); 
	SetIsOutPut(presetsComma,false);
	SetIsInput(presetsComma,false);
	SetDontSave(presetsComma, false);
	
	inStore := CreateParam('store',ptButton); 
	SetIsOutPut(inStore,false);
	
	inRecall := CreateParam('recall',ptButton); 
	SetIsOutPut(inRecall,false);
	
	inCleanup := CreateParam('cleanup',ptButton); 
	SetIsOutPut(inCleanup,false);
	
	inClear := CreateParam('clear',ptButton); 
	SetIsOutPut(inClear,false);
	
	filesList := tStringList.create;
	presetsList := tStringList.create;
	presetsList.capacity := 64;
end;


Procedure savePresets();
begin
	setStringValue(presetsComma, presetsList.commatext);
end;

Procedure clearPresets();
var x:Integer;
begin
	strace('Clearing presetsList');
	presetsList.clear;
	for x := 0 to 63 do begin
		presetsList.add('free');
	end;
	savePresets();
end;

Procedure loadPresets;
var x:Integer;
begin
	strace('Loading presetsList.');
	presetsList.commatext := getStringValue(presetsComma);
	if presetsList.count = 0 then clearPresets();
end;


Procedure cleanupPresets();
var x:Integer;
begin
	strace('Clean up');
	filesList.commatext := getStringValue(inCommaList);
	for x := 0 to presetsList.count do begin
		if filesList.indexOf(presetsList[x]) = -1 then begin
			presetsList[x] := 'free';
		end;
	end;
end;


Procedure recallPreset(presetIndex:Integer);
var pmName:String;
var pmNum:String;
begin
	pmName:= 'Preset' + intToStr(presetIndex div 16 + 1);
	pmNum := intToStr(presetIndex mod 16);
	SendInternalMsg('SET_TARGET_PATCH','SENDER_PATCH');
	SendInternalMsg('SET_VALUE', pmName, 'num', pmNum);	
end;

Procedure storePreset(presetIndex:Integer);
var pmName:String;
var pmNum:String;
begin
	pmName:= 'Preset' + intToStr(presetIndex div 16 + 1);
	pmNum := intToStr(presetIndex mod 16);		
	SendInternalMsg('SET_TARGET_PATCH','SENDER_PATCH');
	SendInternalMsg('SET_VALUE', pmName, 'store', '1');
	SendInternalMsg('SET_VALUE', pmName, 'num', pmNum);
end;


Procedure Callback(N:integer); 
var x:integer;
var pmName:String;
var pmNum:String;
var presetIndex:integer;
begin
	// Store
	if (n=inStore) and (getValue(inStore)=1) then begin
		if presetsList.count = 0 then loadPresets();
		presetIndex := presetsList.indexOf(getStringValue(inPresetName));
		if presetIndex = -1 then begin 
			presetIndex := presetsList.indexOf('free');
			if presetIndex = -1 then begin
				cleanupPresets();
				presetIndex := presetsList.indexOf('free');
			end;
			presetsList[presetIndex] := getStringValue(inPresetName);
		end;
		storePreset(presetIndex);
		savePresets();
	end;

	// Recall
	if (n=inRecall) and (getValue(inRecall) = 1) then begin
		if presetsList.count = 0 then loadPresets();
		presetIndex := presetsList.indexOf(getStringValue(inPresetName));
		if presetIndex <> -1 then begin 
			strace&#40;'Recalling'&#41;;
			recallPreset&#40;presetIndex&#41;;
		end;
	end;
	
	// Clear
	if &#40;n=inClear&#41; and &#40;getValue&#40;inClear&#41;=1&#41; then begin
		strace&#40;'Clear'&#41;;
		clearPresets&#40;&#41;;
	end;

	// Cleanup
	if &#40;&#40;n=inCleanUp&#41; and &#40;getValue&#40;inCleanUp&#41;=1&#41;&#41; then begin
		cleanupPresets&#40;&#41;;
	end;
	
end;

//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin

end;
Guillaume Thibert
www.cemproduction.com

gthibert
Member
Posts: 46
Location: Chicoutimi, Québec
Contact:

Unread post by gthibert » 06 Mar 2011, 01:36

Or maybe someone have a better solution than mine to achieve what I want do...?
Guillaume Thibert
www.cemproduction.com

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 06 Mar 2011, 01:46

gonna have a look

don't find something wrong. maybe try to display the pttexfield as output used to store and look if the commatext is full and correct..

gthibert
Member
Posts: 46
Location: Chicoutimi, Québec
Contact:

Unread post by gthibert » 06 Mar 2011, 02:01

I think I've already tryed, but I'll check.

But do you think the script in efficient ? Is there a better solution ?
Guillaume Thibert
www.cemproduction.com

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 06 Mar 2011, 02:11

it looks quite cool. btween i didn't fully tested with comma and pm, but the code look nice. and cool idea.

i just don't understand why there is 2 times the check, couldn't it be only once?

if presetIndex = -1 then begin
presetIndex := presetsList.indexOf('free');
if presetIndex = -1 then begin

edit: oh, i had just copied the script, didn't saw the patch link. will check with the comma text

gthibert
Member
Posts: 46
Location: Chicoutimi, Québec
Contact:

Unread post by gthibert » 06 Mar 2011, 03:16

It's just to check if all 64 presets are taken. If it's the case, cleanUp() procedure will try to free some presets, according to the comma text of the list box (if some items associated with presets were deleted).
Guillaume Thibert
www.cemproduction.com

gthibert
Member
Posts: 46
Location: Chicoutimi, Québec
Contact:

Unread post by gthibert » 06 Mar 2011, 20:54

I tryed to set the ptTexfield as output, but it still does'nt work.

Maybe it's a bug...
Guillaume Thibert
www.cemproduction.com

gthibert
Member
Posts: 46
Location: Chicoutimi, Québec
Contact:

Unread post by gthibert » 12 Mar 2011, 02:56

I still have the problem. Can anyone take a look ?
Guillaume Thibert
www.cemproduction.com

Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests