Welcome to %s forums

BrainModular Users Forum

Login Register

Set array : more than 64 elements, huge on cpu ! Any alternative?

I need help on a Patch
Post Reply
moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 28 Feb 2011, 21:30

Is there a way to avoid this : Image ???

I need to set about 64 elements in an array , but my patch have nearly 25% of cpu load ! I really can't use it but I need it ! :/

have you got another solution? Is there a script that might do the job?

Thanks.

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 28 Feb 2011, 21:45

If these values are just part of a larger array, you can use Extract Sub Array to get the part(s) you want to keep unchanged, and then concatenate that with a plain Array module where you use "reset val" and "reset" to enter the new value. Use Concat Array to piece the whole lot together.
Bjørn S

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 28 Feb 2011, 22:08

Thanks you Mr bsork !

I'm not sure to understand your advice ( my english is...not always on top:P ) I'm dealing with sysex values received from my hardware by blocs of 512 values. Then I store them in one big array ( up to 25000 values sometimes ! ). Each of the 512 blocs contains informations in index n°2 that I need to change after the storage process. So , the better way is probably to cut the big bloc to several 512 blocs to re-compose the orginal flow. but I don't know how to start using the extract-sub array. I'd like to avoid using a lot of array module as shown in my pictures.

So if you have an idea where to start to process the big bloc by several 512 ones...you are welcome !

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 28 Feb 2011, 22:43

Extract Sub Array is quite simple to use - just set the start element and the length=number of elements that you want to extract. If you eg want to keep the first 64 elements, skip the next 64, and then keep the rest of of 512, Extrac tSub Array #1 should have start pos=0 and length=64, #2 have start pos=128 and length=384. To set a new value you can use the Fill Array with size=64 (I had forgotten about that one in my post above), and then concatenate the three into one array

But that does only work well if the values you're updating are after another in the array. I'm not sure I understand what you mean by "index n°2" - is it every other index like 0, 2, 4, 6.. or something like that? If so, things can get clumsy with modules, and a script would certainly work better, If you need any help writing a script like this, I can help you.

Off topic, I know, but weren't you the one who reported something wrong with the wiki for one of my scripts some days ago? I tried to search for the topic today, but couldn't find it.
Bjørn S

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 28 Feb 2011, 23:33

Here is the forum link about your excellent scripts (very useful for sysex). http://www.sensomusic.com/forums/viewtopic.php?id=2221

Index n°2 means elements number 2 of each array of 512 elements.
For exemple, for an array of 3 x 512 values stored in one big array of 1536 values, I need to change value number 2 , value number 514 ( 512+2 ), and value number 1026 ( 1024+2). And so on if the array is bigger. So , If i reverse the process ( that's why I want to do ) by cutting the big array in several bloc of array size 512, I could access to index n°2 of each bloc and change the value. don't know if I'm really clear, so if i'm not, nevermind ! ;)

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 01 Mar 2011, 00:59

here is a script solution, bsork might have a cleaner one? wonder if best way to do..
there is a start offset index (in your case '2', then a 'each' sublocsize, here 512, when pressing button it will set each subindex
of the same inputvalue.

Code: Select all

//////////////////////////
// SetEach+IndexStart
/////////////////////////
var ArrayIN, ArrayOUT : tparameter;
var GoSet : tparameter;
var Index, valin : tparameter;
var SubSize: tparameter;
var i, l : integer;
////////////////////////
procedure init;
begin  

ArrayIn:= createParam('Array in', PtArray);           setisOutput(Arrayin,false);
goset  := createParam('set values', Ptbutton);        setisOutput(goset,false);
index  := createParam('index (offset)', Ptdatafader); setisOutput(index,false);
SetFormat(index,'%.0f'); SetMax(index,512);
SubSize:= createParam('each (subsize)', Ptdatafader); setisOutput(subsize,false);
SetFormat(subsize,'%.0f'); SetMax(subsize,512); setMin(subsize,1); setValue(subsize,1);
valin  := createParam('value', Ptdatafader);          setisOutput(valin,false);
SetFormat(valin,'%.0f'); SetMax(valin,255);

ArrayOut:= createParam('Array out', PtArray);         setisINput(ArrayOut,false);
setLength(ArrayOut,0);
end;
/////////////////////////////////////
Procedure Callback(N:integer); 
var NB_OF_SUBS, ID : integer;
begin

if (n=ArrayIn) then IN_TO_OUT;

if (n=GoSet) and (getValue(GoSet)=1) then begin
     IN_TO_OUT;
     NB_OF_SUBS:= L div round(getvalue(subsize));
      for i:= 0 to NB_OF_SUBS  do begin
          ID:= round(getvalue(index)+(i*getvalue(subsize)));
            if ID <= L-1 then begin
     setDataArrayValue&#40;ArrayOut,ID,getValue&#40;valin&#41;&#41;;
     end;
  end;
end;
end;
///////////////
procedure IN_TO_OUT;
begin
    L&#58;= getlength&#40;arrayin&#41;;
    setlength&#40;arrayOut,L&#41;;
    for i&#58;= 0 to L-1 do begin
        setDataArrayValue&#40;ArrayOut,i,getDataArrayValue&#40;ArrayIn,i&#41;&#41;;
     end;
end;
//////////////////////////////

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 01 Mar 2011, 08:29

The script looks good to me. A couple of minor things:
- Max for the index parameter should be 511, not 512.
- The FOR loop should go from 0 to (NO_OF_SUBS-1), then the IF-test can be skipped.

Nice work!
Bjørn S

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 01 Mar 2011, 11:17

It appears to me that I am talking to two script genius ! I have a ton of request for you. Can I make one request a day :lol: ? Or two?

You are so nice to make a script for this problem 23fx23 ! I'm very happy with, it seems to works fine for me in this states.
Thanks you a lot .;)

23fx23
Member
Posts: 2545
Contact:

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

@ bsork, thanks for the check and reminder!

indeed feel should go to nb_of_sub -1 and skip the test, but would need some kind of security cause there is the added startindex, wich if too high could make trying to set a out of range index for output array(superior to it's size, so returning error). mm maybe force max startoffsetindex to sub_size via a temp variable, but then im affraid it could set the last step in some unwanted conditions.. dk if see what i mean.., if so any idea on best solution? would you also do the first 'in_to_out' then do the second specific steps setting procedure or would have done different way?

@moody, you're welcome, as i was far for a long time from usine, i needed for reminder-trainings, your requests were perfect :)

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 01 Mar 2011, 12:03

You're right about the possibility for an out-of-range index, so better keep the IF test. About copying the input to output first before changing the separate values to valIn, the best solution CPU-wise could vary, but your way of doing it makes sure that the output array is filled even when nothing happens with GoSet. I don't think the possible extra overhead should be anything to worry about.
Bjørn S

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 01 Mar 2011, 12:09

cool :) thanks a lot master bsork!

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 01 Mar 2011, 17:22

hey ! Can I ask you for a bit more help ( I'm a bit ashamed) but I was thinking ( and in the need) of the same script you made, with one difference, I'd like to enter the values to set with an array input. Is it possible or need to much work?

And at last, a related script that could give to the user a Get array Element Value each (n) size with offset?

Could be very useful in some situation, and especially in my attempt to build a full sysex editor for my beloved G2.

Thanks you for your precious help cause I actually know absolutely nothing in scripting.

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 01 Mar 2011, 19:08

yup i can have a look for this tonight, so you dlike to set all the indexed sub values, let say of the 8 subparts by a 8 size array for ex? this is doable quite easily normally. then the reversed script should be also doable with a bit of transform, so it would output an array of n size. i will separate the two script for more modularity.

i was looking at your other challenge but, while i could easily make the clocked insert feature, the sort_array code is quite trickier
than i imagined and above my pgming (basic) math or scripting skillz for now, i will make a break and update this one by waiting a new challenging attempt ;)

i have no pb and enjoy helping you as much as i can but beleive me, you should try slowly learn scripting, i did have no clue a few month ago as well ;)

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 01 Mar 2011, 19:28

here is a array input version:

Code: Select all

//////////////////////////
// SetEach+IndexStart_array of values in
/////////////////////////
var ArrayIN, ArrayOUT, ValuesIn &#58; tparameter;
var GoSet &#58; tparameter;
var Index, valin &#58; tparameter;
var SubSize&#58; tparameter;
var i, l &#58; integer;
////////////////////////
procedure init;
begin  

ArrayIn&#58;= createParam&#40;'Array in', PtArray&#41;;           setisOutput&#40;Arrayin,false&#41;;
goset  &#58;= createParam&#40;'set values', Ptbutton&#41;;        setisOutput&#40;goset,false&#41;;
index  &#58;= createParam&#40;'index &#40;offset&#41;', Ptdatafader&#41;; setisOutput&#40;index,false&#41;;
SetFormat&#40;index,'%.0f'&#41;; SetMax&#40;index,511&#41;;
SubSize&#58;= createParam&#40;'each &#40;subsize&#41;', Ptdatafader&#41;; setisOutput&#40;subsize,false&#41;;
SetFormat&#40;subsize,'%.0f'&#41;; SetMax&#40;subsize,511&#41;; setMin&#40;subsize,1&#41;; setValue&#40;subsize,1&#41;;
//valin  &#58;= createParam&#40;'value', Ptdatafader&#41;;          setisOutput&#40;valin,false&#41;;
//SetFormat&#40;valin,'%.0f'&#41;; SetMax&#40;valin,255&#41;;
ValuesIn&#58;= createParam&#40;'Values in', PtArray&#41;;           setisOutput&#40;ValuesIn,false&#41;;

ArrayOut&#58;= createParam&#40;'Array out', PtArray&#41;;         setisINput&#40;ArrayOut,false&#41;;
setLength&#40;ArrayOut,0&#41;;
end;
/////////////////////////////////////
Procedure Callback&#40;N&#58;integer&#41;; 
var NB_OF_SUBS, ID &#58; integer;
begin

if &#40;n=ArrayIn&#41; then IN_TO_OUT;

if &#40;n=GoSet&#41; and &#40;getValue&#40;GoSet&#41;=1&#41; then begin
     IN_TO_OUT;
     NB_OF_SUBS&#58;= L div round&#40;getvalue&#40;subsize&#41;&#41;;
      for i&#58;= 0 to NB_OF_SUBS-1 do begin
          ID&#58;= round&#40;getvalue&#40;index&#41;+&#40;i*getvalue&#40;subsize&#41;&#41;&#41;;
            if ID <= &#40;MinI&#40;L,getLength&#40;ValuesIn&#41;&#41;-1&#41; then begin
     setDataArrayValue&#40;ArrayOut,ID,getdataArrayValue&#40;valuesin,i&#41;&#41;;
     end;
  end;
end;
end;
///////////////
procedure IN_TO_OUT;
begin
    L&#58;= getlength&#40;arrayin&#41;;
    setlength&#40;arrayOut,L&#41;;
    for i&#58;= 0 to L-1 do begin
        setDataArrayValue&#40;ArrayOut,i,getDataArrayValue&#40;ArrayIn,i&#41;&#41;;
     end;
end;
//////////////////////////////

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 01 Mar 2011, 19:38

Yeah !

I'm not sure to understand well, but you seems to correctly understand what I mean. To be more clear => Back to my first example with 3 x 512 values stored in one big array of 1536 values. I want to set a new value for index n°2 (A) , another one for index 512+2 (B) , and another one for index 1024+2(C). Each new value to set are different, so that's why an array input is required. So for A: new value=a ; for B=>b ; for C=> c where a is the first value of an input array, b, the second value , and c the third value to set.

For the second script, in state of setting a new value each subsize+offset , I need to extract values like the GetArrayVal module do. In my example, I would like to extract element value 10, value 512+10, and value 1024+10. all extracting values should be output as an array output.

The challenge was just in case of, and was a bit of joke.However , I'd really like to have a script like this.

Sure, I will take a look in how to make script one day, but it seems to be very hard for me to understand, It's like chinese and far beyond my own logic. ! Although I don't say I will never learn how to. :) I'm often impressed by people like you, bsork and other , going deeply in this kind of programming ! :o

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 01 Mar 2011, 19:38

Oups..posting at the same time..:lol:.I take a look.

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 01 Mar 2011, 20:09

Ok it seems to work. however, If i'm not wrong, it seems to need that the array input (value ) size need to be exactly the same size as the array input. If not, it doesn't seems to going well and we have to fill and concat zeros to perfeclty fit the input size.So, I guess, if it's possible to fill zeros internally to match the good size? However , it seems to work ! :D

waolelaid
Member
Posts: 339
Location: Ecouen 95
Contact:

Unread post by waolelaid » 01 Mar 2011, 21:37

hi sorry but it is to make what ?
Usine begins to be too much difficult for me
it's now made for progammers and as i quit school
at fourteen i can't follow now i know nothing about math
and yet less in programming i had a look on the next new module
working with csound that makes everybody very enthusiastic
but it's still C language
i already don't understand the use of "arrays " so I think
i can't go on
good night and excuse me
Avant l'effet on croit à d'autres causes qu'après
Friedrich Nietzsche

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

Unread post by nay-seven » 01 Mar 2011, 22:03

Hey Wao ! don't worry , you can live without array !
moody is working on a specific project ( an editor for the G2 synthesizer )
but you don't need to follow this to make your own project ;)

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 01 Mar 2011, 22:31

yup wao don't worry that's very specific, you don't need to bother about that, unless you use a G2 synthesizer and wand to do
the exact same weird thingz as moody :)

@moody, i m not sure i fully understood, but this is a new version that may solve the pb:
it's a multimode single script, normally you should be able to set_only, extract_only or booth via the listbox.

Code: Select all

///////////////////////////////////////////////////////////////
// Get/Set Each&#40;n&#41; + IndexStart from/to array of values in/out
/////////////////////////////////////////////////////////////
var ArrayIN, ArrayOUT, ValuesIn, valuesOut, Mode &#58; tparameter;
var GoSet &#58; tparameter;
var Index &#58; tparameter;
var SubSize&#58; tparameter;
var ValTMP&#58; integer;
var i, l &#58; integer;
var NB_OF_SUBS, ID, pass, lvals &#58; integer;
////////////////////////
procedure init;
begin  

ArrayIn&#58;= createParam&#40;'Array in', PtArray&#41;;           setisOutput&#40;Arrayin,false&#41;;
goset  &#58;= createParam&#40;'Process', Ptbutton&#41;;           setisOutput&#40;goset,false&#41;;
index  &#58;= createParam&#40;'index &#40;offset&#41;', Ptdatafader&#41;; setisOutput&#40;index,false&#41;;
SetFormat&#40;index,'%.0f'&#41;; SetMax&#40;index,511&#41;;
SubSize&#58;= createParam&#40;'each &#40;subsize&#41;', Ptdatafader&#41;; setisOutput&#40;subsize,false&#41;;
SetFormat&#40;subsize,'%.0f'&#41;; SetMax&#40;subsize,511&#41;; setMin&#40;subsize,1&#41;; setValue&#40;subsize,1&#41;;
Mode  &#58;= createParam&#40;'mode', PtListBox&#41;;             setisOutput&#40;Mode,false&#41;;
SetListBoxString&#40;Mode, '"Set only", "Set+Extract", "Extract only"'&#41;;
setvalue&#40;mode,0&#41;;
ValuesIn&#58;= createParam&#40;'Values in', PtArray&#41;;           setisOutput&#40;ValuesIn,false&#41;;
ArrayOut&#58;= createParam&#40;'Array out', PtArray&#41;;           setisINput&#40;ArrayOut,false&#41;;
ValuesOut&#58;= createParam&#40;'Values out', PtArray&#41;;         setisINput&#40;ValuesOut,false&#41;;
setLength&#40;ArrayOut,0&#41;;
end;
/////////////////////////////////////
Procedure Callback&#40;N&#58;integer&#41;; 
begin

if &#40;n=ArrayIn&#41; then IN_TO_OUT;

if &#40;n=GoSet&#41; and &#40;getValue&#40;GoSet&#41;=1&#41; then begin
     IN_TO_OUT; 
     if getvalue&#40;mode&#41;<2 then INSERT_VALUES; 
     if getvalue&#40;mode&#41;>0 then EXTRACT_VALUES;
     end;
end;
//////////////////////////////////////////
procedure EXTRACT_VALUES;
begin
     NB_OF_SUBS&#58;= L div round&#40;getvalue&#40;subsize&#41;&#41;;
     setlength&#40;ValuesOut,NB_OF_SUBS&#41;;
      for i&#58;= 0 to NB_OF_SUBS-1 do begin
          ID&#58;= round&#40;getvalue&#40;index&#41;+&#40;i*getvalue&#40;subsize&#41;&#41;&#41;;
            if &#40;ID < L&#41; then begin
            ValTMP&#58;= round&#40;getdataArrayValue&#40;Arrayout,id&#41;&#41;;
            setDataArrayValue&#40;ValuesOut,i,ValTMP&#41;;
            end else begin
            setDataArrayValue&#40;ValuesOut,i,0&#41;;
            end;
       end;
end;
////////////////////////
procedure INSERT_VALUES;
begin
      for i&#58;= 0 to Lvals-1 do begin
          ID&#58;= round&#40;getvalue&#40;index&#41;+&#40;i*getvalue&#40;subsize&#41;&#41;&#41;;
            if ID < L then begin
            ValTMP&#58;= round&#40;getdataArrayValue&#40;valuesin,i&#41;&#41;;
            setDataArrayValue&#40;ArrayOut,ID,VALTMP&#41;;
            end;
       end;
end;
///////////////
procedure IN_TO_OUT;
begin
    L&#58;= getlength&#40;arrayin&#41;;
    Lvals&#58;= getLength&#40;ValuesIn&#41;;
    setlength&#40;arrayOut,L&#41;;
    for i&#58;= 0 to L-1 do begin
        setDataArrayValue&#40;ArrayOut,i,getDataArrayValue&#40;ArrayIn,i&#41;&#41;;
     end;
end;
//////////////////////////////

moody33
Member
Posts: 338
Contact:

Unread post by moody33 » 01 Mar 2011, 23:14

@wao As 23fx23 says, this topic is specific. Usine can be use with simplicity and with complexity, that's why I like it ! And don't worry about math stuff, I'm very very bad too ( as my english). I can pass more than three days to solve a problem where a physicist solve it in a minute ! So, don't take care about topic like these if you are not interested. Plug your vst and make music ! ;)

@23fx23 Impressive script! Exactly what I need for my stuff and it works very well !!! You make my day and I wish to not find other problems within my patch ( and I'm sure there is other sysex problem in view since I'm a bit blind with numbers :cool::cool:
Thanks you so much for your help ! ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests