Page 1 of 1
Posted: 28 Feb 2011, 21:30
by moody33
Is there a way to avoid this :

???
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.
Posted: 28 Feb 2011, 21:45
by bsork
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.
Posted: 28 Feb 2011, 22:08
by moody33
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 !
Posted: 28 Feb 2011, 22:43
by bsork
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.
Posted: 28 Feb 2011, 23:33
by moody33
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 !

Posted: 01 Mar 2011, 00:59
by 23fx23
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(ArrayOut,ID,getValue(valin));
end;
end;
end;
end;
///////////////
procedure IN_TO_OUT;
begin
L:= getlength(arrayin);
setlength(arrayOut,L);
for i:= 0 to L-1 do begin
setDataArrayValue(ArrayOut,i,getDataArrayValue(ArrayIn,i));
end;
end;
//////////////////////////////
Posted: 01 Mar 2011, 08:29
by bsork
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!
Posted: 01 Mar 2011, 11:17
by moody33
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

? 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 .

Posted: 01 Mar 2011, 11:46
by 23fx23
@ 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

Posted: 01 Mar 2011, 12:03
by bsork
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.
Posted: 01 Mar 2011, 12:09
by 23fx23
cool

thanks a lot master bsork!
Posted: 01 Mar 2011, 17:22
by moody33
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.
Posted: 01 Mar 2011, 19:08
by 23fx23
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

Posted: 01 Mar 2011, 19:28
by 23fx23
here is a array input version:
Code: Select all
//////////////////////////
// SetEach+IndexStart_array of values in
/////////////////////////
var ArrayIN, ArrayOUT, ValuesIn : 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,511);
SubSize:= createParam('each (subsize)', Ptdatafader); setisOutput(subsize,false);
SetFormat(subsize,'%.0f'); SetMax(subsize,511); setMin(subsize,1); setValue(subsize,1);
//valin := createParam('value', Ptdatafader); setisOutput(valin,false);
//SetFormat(valin,'%.0f'); SetMax(valin,255);
ValuesIn:= createParam('Values in', PtArray); setisOutput(ValuesIn,false);
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-1 do begin
ID:= round(getvalue(index)+(i*getvalue(subsize)));
if ID <= (MinI(L,getLength(ValuesIn))-1) then begin
setDataArrayValue(ArrayOut,ID,getdataArrayValue(valuesin,i));
end;
end;
end;
end;
///////////////
procedure IN_TO_OUT;
begin
L:= getlength(arrayin);
setlength(arrayOut,L);
for i:= 0 to L-1 do begin
setDataArrayValue(ArrayOut,i,getDataArrayValue(ArrayIn,i));
end;
end;
//////////////////////////////
Posted: 01 Mar 2011, 19:38
by moody33
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 !

Posted: 01 Mar 2011, 19:38
by moody33
Oups..posting at the same time..

.I take a look.
Posted: 01 Mar 2011, 20:09
by moody33
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 !

Posted: 01 Mar 2011, 21:37
by waolelaid
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
Posted: 01 Mar 2011, 22:03
by nay-seven
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

Posted: 01 Mar 2011, 22:31
by 23fx23
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(n) + IndexStart from/to array of values in/out
/////////////////////////////////////////////////////////////
var ArrayIN, ArrayOUT, ValuesIn, valuesOut, Mode : tparameter;
var GoSet : tparameter;
var Index : tparameter;
var SubSize: tparameter;
var ValTMP: integer;
var i, l : integer;
var NB_OF_SUBS, ID, pass, lvals : integer;
////////////////////////
procedure init;
begin
ArrayIn:= createParam('Array in', PtArray); setisOutput(Arrayin,false);
goset := createParam('Process', Ptbutton); setisOutput(goset,false);
index := createParam('index (offset)', Ptdatafader); setisOutput(index,false);
SetFormat(index,'%.0f'); SetMax(index,511);
SubSize:= createParam('each (subsize)', Ptdatafader); setisOutput(subsize,false);
SetFormat(subsize,'%.0f'); SetMax(subsize,511); setMin(subsize,1); setValue(subsize,1);
Mode := createParam('mode', PtListBox); setisOutput(Mode,false);
SetListBoxString(Mode, '"Set only", "Set+Extract", "Extract only"');
setvalue(mode,0);
ValuesIn:= createParam('Values in', PtArray); setisOutput(ValuesIn,false);
ArrayOut:= createParam('Array out', PtArray); setisINput(ArrayOut,false);
ValuesOut:= createParam('Values out', PtArray); setisINput(ValuesOut,false);
setLength(ArrayOut,0);
end;
/////////////////////////////////////
Procedure Callback(N:integer);
begin
if (n=ArrayIn) then IN_TO_OUT;
if (n=GoSet) and (getValue(GoSet)=1) then begin
IN_TO_OUT;
if getvalue(mode)<2 then INSERT_VALUES;
if getvalue(mode)>0 then EXTRACT_VALUES;
end;
end;
//////////////////////////////////////////
procedure EXTRACT_VALUES;
begin
NB_OF_SUBS:= L div round(getvalue(subsize));
setlength(ValuesOut,NB_OF_SUBS);
for i:= 0 to NB_OF_SUBS-1 do begin
ID:= round(getvalue(index)+(i*getvalue(subsize)));
if (ID < L) then begin
ValTMP:= round(getdataArrayValue(Arrayout,id));
setDataArrayValue(ValuesOut,i,ValTMP);
end else begin
setDataArrayValue(ValuesOut,i,0);
end;
end;
end;
////////////////////////
procedure INSERT_VALUES;
begin
for i:= 0 to Lvals-1 do begin
ID:= round(getvalue(index)+(i*getvalue(subsize)));
if ID < L then begin
ValTMP:= round(getdataArrayValue(valuesin,i));
setDataArrayValue(ArrayOut,ID,VALTMP);
end;
end;
end;
///////////////
procedure IN_TO_OUT;
begin
L:= getlength(arrayin);
Lvals:= getLength(ValuesIn);
setlength(arrayOut,L);
for i:= 0 to L-1 do begin
setDataArrayValue(ArrayOut,i,getDataArrayValue(ArrayIn,i));
end;
end;
//////////////////////////////
Posted: 01 Mar 2011, 23:14
by moody33
@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

Thanks you so much for your help !
