Welcome to %s forums

BrainModular Users Forum

Login Register

un-concal list...

I need help on a Patch
Post Reply
multiphone
Member
Posts: 303
Contact:

Unread post by multiphone » 11 Nov 2010, 18:06

Hello,

I have one question for the community of patcher or scripter. I try to do the opposite of the script "ConCal list". Rather than adding lists, I try to separate the elements one by one. For example, a list of 16 élements in 16 separate lists of one elements. If you have any ideas I'm interested.

Thanks in advance
HB

Lines / Points / Squares

http://www.hervebirolini.com/

User avatar
nay-seven
Site Admin
Posts: 5684
Location: rennes France
Contact:

Unread post by nay-seven » 11 Nov 2010, 18:40

woodslanding has done this script , maybe can suit you:
open it to change out number

Code: Select all

/// commastring splitter by emoon//////

const stringCount = 6;  // if this is too small, it doesn't like it.....

var outputs    : array of Tparameter;
var input      : Tparameter;
var strings    : array of String;
var commatext  : String;

// destroy

// initialisation : create parameters
procedure init;

var digit  : string;
var i  : integer; 

begin
    input := CreateParam('commaText',ptTextField);
    SetIsOutput(input,false);
    
    setArrayLength(strings, stringCount);
    setArrayLength(outputs, stringCount); 
    
    for i := 0 to (stringCount - 1) do begin
        digit := IntToStr(i + 1);
        outputs[i] := CreateParam('String ' + digit,ptTextField);
        SetIsInPut(Outputs[i],false);
    end;
end;



procedure Callback(n:integer);
var charCount : integer;
var i : integer;
var ch: string;
var pos: integer;


begin
     commatext := ' ' + getStringValue(Input) + ',';

     i := 0;
     charCount := 0;
     for pos := 1 to length(commatext) do
     begin
        ch := copy(commatext,pos,1);       
        if (ch = ',') then 
        begin
            strings[i] := copy(commatext,pos - charCount + 1, charCount - 1);
            SetStringValue(Outputs[i],strings[i]);
            strace('in loop ' + strings[i]);
            // a little bounds checking
            if (i = length(strings)) then break; 
            i := i + 1;
            charCount := 0;           
        end;
        charCount := charCount + 1; 
          
     end;       
end;

// no process bloc

multiphone
Member
Posts: 303
Contact:

Unread post by multiphone » 11 Nov 2010, 18:59

Thanks Nay !

I had not seen this post !

All is ok, thanks woodslanding.
HB

Lines / Points / Squares

http://www.hervebirolini.com/

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 11 Nov 2010, 19:26

cool if working ok,

but i think at the time it was done woodslanding was new to script and searched a too complex way of doing this.
scanning all characters one by one, when the tstringlist allow a direct access to separate elements.
a much simpler code can be done for that, using TstringList that pick input as it's commatext.
think it will be also lighter on cpu.

looks like

Code: Select all

for i:=0 to SL.count -1 do begin   
    outputs[i] := SL.strings[i]
   end;
i ll try to post the full script later.

multiphone
Member
Posts: 303
Contact:

Unread post by multiphone » 11 Nov 2010, 19:35

Hello 23fx,

indeed, this script is not free CPU, but it works.

I would love to improve it, but I am still unable at this time.

To be continued ...
HB

Lines / Points / Squares

http://www.hervebirolini.com/

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 13 Nov 2010, 20:14

yeah, I didn't know about the stringList, or I couldn't get it to work....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 13 Nov 2010, 20:56

that's what i though ;)

here is the equivalent with tstringlist.

Code: Select all

 
 /////////////////////////////////////////////
// Spread CommaText Elmts to individual outs
////////////////////////////////////////////
Const NB_ELMTS = 8;   // adjust for nb of output wanted
////////////////////////////
// parameters declaration
var CommaIN   : Tparameter;
var outputs   : Array of Tparameter;
var sl1       : TStringList;
var i         : integer;
/////////////////////////
procedure Destroy;
begin  
 sl1.free;
end;
////////////////////////////
procedure init;
begin 
 
 CommaIN := CreateParam('Comma_In',ptTextField);
 SetIsOutPut(CommaIN,false);

setArrayLength(OUTPUTS,NB_ELMTS);

  for i:=0 to NB_ELMTS -1 do begin
      outputs[i] := CreateParam('out'+ intToStr(i),ptTextField);
      SetIsInPut(Outputs[i],false);
   end;

 Sl1 := TStringList.Create; 

end;
//////////////////////////////////////////
procedure Callback(n:integer);
begin

 if (n=commaIn) then begin
  SL1.commatext:= getStringValue(CommaIN);
       for i:= 0 to NB_ELMTS -1 do begin
         if i < SL1.count then begin
           setStringValue&#40;outputs&#91;i&#93;,Sl1.strings&#91;i&#93;&#41;;
         end else begin
           setStringValue&#40;outputs&#91;i&#93;,''&#41;;
          end;
       end;
   end;

end;
//////////////////////////////////////////////

multiphone
Member
Posts: 303
Contact:

Unread post by multiphone » 14 Nov 2010, 11:16

Hello 23FX,

Very nice !

Thanks for efficiency.

I look your code deeper.
HB

Lines / Points / Squares

http://www.hervebirolini.com/

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 14 Nov 2010, 18:51

you re welcome multiphone ;)

once you catched the in/out creation, more explained in the 'basics scripts' section in wiki,
the only thing to catch is Tstringlist, it's kind of delphi object that can pick a commatext, and let acces the individual
elements via indexes in it's internal memory. the script just reassingn elements to same output nb.
it just need a protection to assign only if an element exists,, via checking if index (i) is within the total number of elements
given by the SL1.count , otherwise it sets a blank name ''.

hope it helps.

multiphone
Member
Posts: 303
Contact:

Unread post by multiphone » 14 Nov 2010, 22:58

OK, i understand...

Thank for explication.

I try to unproved the script with an supplementary inlet for choose the number active of out (maybe can i patch that more easily) and a random determination of N elements in one list.
HB

Lines / Points / Squares

http://www.hervebirolini.com/

Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests