Welcome to %s forums

BrainModular Users Forum

Login Register

CallBack procedure [script]

I need help on a Patch
Post Reply
ethnix73
Member
Posts: 604
Location: France, Caen
Contact:

Unread post by ethnix73 » 04 Feb 2011, 12:06

I've done a little script to adapt the speed of the grain sampler sampler according to the global tempo, the lenght of the sample and his number of beats. I use it to slice the sample and re-order them.

I'm wondering if my script is buggy or not.

Do i really need to put everything in the callback procedure?
As the callback procedure is calculated each time the in parameters change, Is it to cpu intensive?
Is it buggy?

I'm still confused about this

Code: Select all

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


var BarDur : Tparameter;
var result1 : single;
var d : single;

var a,b,c : single;
var length : Tparameter;
var NbBeats : Tparameter;
var tempo : single;
var tempoOut : Tparameter;

var i,j : single;
var x : single;
var speed : Tparameter;



// initialisation : create parameters
procedure init;
begin  

BarDur :=Createparam('BarDur', ptDataFader);
SetIsOutput(barDur,FALSE);
SetMax(Bardur,50000);

Length :=CreateParam('Length', ptDataFader);
SetIsOutput(Length,FALSE);
SetMax(Length,50000);

NbBeats :=CreateParam('NbBeats', ptDataFader);
SetIsOutput(NbBeats,FALSE);

TempoOut :=CreateParam('TempoOut', ptDataFader);
SetIsInput(Tempoout,FALSE);
SetMax(TempoOut,1000);

speed :=Createparam('speed',ptDataFader);
SetisInput(speed,FALSE);
SetMax(speed,50000);


end;

// Callback procedure
Procedure Callback(N:integer); 
begin

If (n=BarDur) OR (n=Length) OR (n=NbBeats) then begin

d := GetValue(BarDur);
result1 := 480000/d;

a := GetValue(length);
b := GetValue(NbBeats);
c := (a/b)/1000;
tempo :=60/c;
SetValue (TempoOut, tempo);


i :=result1;
j :=tempo;
x := (i/j)*100;
SetValue(speed,x);
end;
end;

// Global variables

//////////////////////////////
// main proc
//////////////////////////////
Procedure Process;
begin
end;
Seb.Dub

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

Unread post by bsork » 05 Feb 2011, 10:52

Hi, I haven't tested your script, but you don't have to get all the values in the callback. If for instance you have one parameter that you want to trigger a recalculation of other input values, put it in the callback (IF (n=?) THEN...) and just read the the other values when they're needed.

Another approach is to have a Boolean variable set to TRUE in the callback, and then check that variable in Process, do the calculations, and set the Boolean to FALSE.

BTW, for a little script like this I don't see much point in sweating over optimizations, and I don't think you'd notice much difference in CPU anyway. The one thing you could o, hoiwever, is remove the Process procedure as it isn't needed. You only need to use Process whenever there is something you want to be done within a block without any callbacks; eg zeroing an MIDI output array or checking some timing vaiables.
Bjørn S

ethnix73
Member
Posts: 604
Location: France, Caen
Contact:

Unread post by ethnix73 » 05 Feb 2011, 12:41

Hi bsork,

"You only need to use Process whenever there is something you want to be done within a block without any callbacks",

Thanks for this precision!

Digging so slowly in script :)....
Seb.Dub

Post Reply

Who is online

Users browsing this forum: No registered users and 165 guests