Welcome to %s forums

BrainModular Users Forum

Login Register

the simplest patch and a question

I need help on a Patch
Post Reply
Floego
Member
Posts: 319
Location: Venezuela
Contact:

Unread post by Floego » 16 Aug 2010, 20:43

I created this two patches: Hook and Wirebox please see below:

Image

They are the simplest patches (only wires) but it may be very useful, surely many of Usine users have already created them into their patches. They consume very little resources.

Wirebox makes easy to connect/disconnect wires on an heavy populated single inlet/outlet.

The hook patch helps to keep right angle wires and avoid long diagonal lines (for people like me with heavy astigmatism it could help).


Maybe they could be fusioned into just one or two?. Or should they ask at loading about the number of inlet/outlet?.

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 16 Aug 2010, 21:40

for my side, i use essentially the hook ones, but i name them pass through...

about wirebox, i prefer to connect many wire one one output.

anyway...
they could be good candidates for some user modules (with the query system, ask for how many how many inlet/outlet)
or just be part of everyone patch library for convenience.

but for sure, those are very useful, for wiring or visual reason.
Martin FLEURENT - Usine Developer - SDK maintainer

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

Unread post by nay-seven » 16 Aug 2010, 21:53

have you also check the script examples part..?
there's an example named 1 In 1 Out Example.script
you could easily adapt them i think
for example for a 1 input , 2 output :

Code: Select all

//////////////////////////////////////////////////////
// Script example 
// one Input, 2 output
// set the input value to the 2 output value
// (data thru)
//////////////////////////////////////////////////////

//////////////////////////////////////////////////////
// Paramters declaration
//////////////////////////////////////////////////////
var input : Tparameter;
var output: Tparameter;
var output2: Tparameter;

//////////////////////////////////////////////////////
// initialisation procedure
//////////////////////////////////////////////////////
procedure init;
begin  
 input := CreateParam('input',ptDatafader);
 SetIsOutput(input,false);
 SetMin(input,0);
 SetMax(input,100);
 SetSymbol(input,'%');
 SetDefaultValue(input,10);
 SetValue(input,10);

 output := CreateParam('output',ptDataFader );
 SetIsInput(output,false);
 SetMin(output,0);
 SetMax(output,100);
 SetSymbol(output,'%');
 SetDefaultValue(output,10);

 output2 := CreateParam('output2',ptDataFader );
 SetIsInput(output2,false);
 SetMin(output2,0);
 SetMax(output2,100);
 SetSymbol(output2,'%');
 SetDefaultValue(output2,10);

end;

// Global Variables
var inval : single;

//////////////////////////////////////////////////////
// Main Loop procedure
//////////////////////////////////////////////////////
Procedure Process;
begin

 inval := getValue(input);
 setvalue(output,inval);
 setvalue(output2,inval);

end;
or for a 2 inputs to a 1 output :

Code: Select all

//////////////////////////////////////////////////////
// Script example 
// 2 Inputs, one output
// set the input value to the output value
// (data thru)
//////////////////////////////////////////////////////

//////////////////////////////////////////////////////
// Paramters declaration
//////////////////////////////////////////////////////
var input : Tparameter;
var input2 : Tparameter;
var output: Tparameter;

//////////////////////////////////////////////////////
// initialisation procedure
//////////////////////////////////////////////////////
procedure init;
begin  
 input := CreateParam('input',ptDatafader);
 SetIsOutput(input,false);
 SetMin(input,0);
 SetMax(input,100);
 SetSymbol(input,'%');
 SetDefaultValue(input,10);
 SetValue(input,10);

 input2 := CreateParam('input2',ptDatafader);
 SetIsOutput(input2,false);
 SetMin(input2,0);
 SetMax(input2,100);
 SetSymbol(input2,'%');
 SetDefaultValue(input2,10);
 SetValue(input2,10);

 output := CreateParam('output',ptDataFader );
 SetIsInput(output,false);
 SetMin(output,0);
 SetMax(output,100);
 SetSymbol(output,'%');
 SetDefaultValue(output,10);

end;

// Global Variables
var inval : single;

//////////////////////////////////////////////////////
// Main Loop procedure
//////////////////////////////////////////////////////
Procedure Process;
begin

 inval := getValue(input);
 setvalue(output,inval);

 inval := getValue(input2);
 setvalue(output,inval);


end;

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 17 Aug 2010, 00:04

mmm nay on code2, you made the extra In but, you didn't modified the process that only pick input one.
if i well understood booth input should be added to output.?

also the code with is based ond an old one use process, mean it process constantly,
in this case better use callback that will process only on changes.

here is a code example for N inputs to one output using callback can edit the constant.

Code: Select all

const nb_ins = 8;  //define number of inputs all going to output.(summed).
////////////////////////////////////////////////////////////////////////////
var INPUTS : array of Tparameter;
var output : tparameter;
var i      : integer;
var valtmp : single;
//////////////////////////////////
Procedure Init;
begin

setArrayLength(INPUTS,nb_ins);
for i:= 0 to nb_ins-1 do begin
INPUTS[i]:=  CreateParam('input'+IntToStr(i),PtDataField);  SetIsOutput(INPUTS[i],false);

end;
////////////////////////////////////////////////////////////
output:= createParam('output',Ptdatafield); setisInput(output,false);

valtmp:=0;
end;// init
//////////////////////////////////////////////
Procedure Callback (n:integer);
Begin

if n>=0 then begin
valtmp:= getValue(inputs[0]);
for i:= 1 to nb_ins-1 do begin
valtmp:= valtmp + getValue(Inputs[i]);
end;
setValue(output,valtmp);
end;

end;// callback
////////////////////////////////////////

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 17 Aug 2010, 00:13

..and if interested, code for one input to N outputs:

Code: Select all

const nb_outs = 8;  //define number of outputs all picking input.
////////////////////////////////////////////////////////////////////////////
var OUTPUTS : array of Tparameter;
var input : tparameter;
var i      : integer;
var valtmp : single;
//////////////////////////////////
Procedure Init;
begin
////////////////////////////////////////////////////////////
input:= createParam('input',Ptdatafield); setisOutput(input,false);
/////////////////////////////////////////////////////////////////
setArrayLength(OUTPUTS,nb_outs);
for i:= 0 to nb_outs-1 do begin
OUTPUTS[i]:=  CreateParam('output'+IntToStr(i),PtDataField);  SetIsInput(OUTPUTS[i],false);

end;

valtmp:=0;
end;// init
//////////////////////////////////////////////
Procedure Callback (n:integer);
Begin

if n>=0 then begin
valtmp:= getValue(input);
for i:= 0 to nb_outs-1 do begin
setValue(outputs[i],valtmp);
end;
end;

end;// callback
////////////////////////////////////////

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 17 Aug 2010, 00:27

..and as we are, a third one for N in to N outs, coresponding:

Code: Select all

const nb_inouts = 8;  //define number of in-outputs all picking correponding.
////////////////////////////////////////////////////////////////////////////
var INPUTS, OUTPUTS : array of Tparameter;
var i      : integer;
//var valtmp : single;
//////////////////////////////////
Procedure Init;
begin
////////////////////////////////////////////////////////////
setArrayLength(INPUTS,nb_inouts);
for i:= 0 to nb_inouts-1 do begin
INPUTS[i]:=  CreateParam('Input'+IntToStr(i),PtDataField);  SetIsOutput(INPUTS[i],false);
end;
/////////////////////////////////////////////////////////////////
setArrayLength(OUTPUTS,nb_inouts);
for i:= 0 to nb_inouts-1 do begin
OUTPUTS[i]:=  CreateParam('output'+IntToStr(i),PtDataField);  SetIsInput(OUTPUTS[i],false);
end;
end;// init
//////////////////////////////////////////////
Procedure Callback (n:integer);
Begin

if n>=0 then begin
setValue(outputs[n],getValue(inputs[n]));
end;

end;// callback
////////////////////////////////////////

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

Unread post by nay-seven » 17 Aug 2010, 01:12

great , and yep , you're right about he second one ( I've correct it )

the good question now is : did the script has a low cpu use than a sub-patch...?
( but for n series script is quickest to adapt anyway )

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 17 Aug 2010, 01:30

that's exactly what i wondered, wich one take more/less CPU.

between they won't react exactly the same: if using wires and some have stop envent flow, they ll be ignored, that won't work
i suppose here,( but a different code could). the advantage here is easy change nb, but ideally a query would be even better,
(also that's quick done to edit constant and reload script). the other difference is naming, but a commatext variable is possible...

now the most interessant question to check still is, wich use more cpu, indeed, ;)

Floego
Member
Posts: 319
Location: Venezuela
Contact:

Unread post by Floego » 17 Aug 2010, 04:00

Thank you very much for your smart analysis and advices ! !

I compiled the scripts, then used the scripts in the midipadayan patch (only for testing purposes), used the hook patched version too, and compared to the original midipadayan patch. The results are similar between the hook patch version and the script one. See below:

original midipadayan:

Image

now hook patch with midipadayan:

Image


finally hook script with midipadayan:

Image

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

Unread post by bsork » 17 Aug 2010, 08:16

Just a tip if all you want to is to put in an extra "node" to make the wiring more tidy: Instead of sub-patches, just use one of the simples modules you can find. I use an A+B for this once in a while.
Bjørn S

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

Unread post by nay-seven » 17 Aug 2010, 09:57

great , thanks for this interesting test , would be curious to test this too on my different computer
can you upload them somewhere..?

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

Unread post by nay-seven » 17 Aug 2010, 11:17

btw , i realize I've to update this add-on with the new matrix , and i must admit it's handy to have not all wires from the matrix .

but...i also remember that we have said before that the more wires and connections we use , the more cpu we eat..
and as said Bsork , a simple module like the a+b one can do the job with less cpu
an example here ( and if you use this 2 method in 2 different empty patch you can check the cpu difference )

Image

btw , if we use direct link , this fall to 4 wires , 4 connections....

Floego
Member
Posts: 319
Location: Venezuela
Contact:

Unread post by Floego » 17 Aug 2010, 14:36

yes, I know it takes more wires and connections and eat more cpu, but I found it useful for a visual tracing of a process etc. So eventually, once the patch is working and the modules are better distributed, I just could remove it.

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests