Page 1 of 1

Posted: 01 Nov 2015, 23:01
by ahonoe
Apologies if this seems too idiotic...

I've done some scripting before so you can imagine my surprise when I can't get a basic counter to work. If I connect a trace module to the 'out' of the following script, I expect to see 0 through 31 in the trace window. Instead I only see 31. What am I missing??

//////////////////////////
//
/////////////////////////
// parameters declaration
var inp : Tparameter;
var outp : tparameter;

// initialisation : create parameters
procedure init;
begin
inp :=CreateParam('in',ptButton);
outp:= CreateParam('out',ptDataFader);
setmax(outp,32);
end;

// Callback procedure
Procedure Callback(N:integer);
var i: integer;
begin
for i :=0 to 31 do begin
setvalue(outp,i);
end;
end;

// no process block

Posted: 01 Nov 2015, 23:57
by shawnb
I believe the whole thing is executing within one block of processing time. Thus, the only output is the final result.

With HH (and PureData, and Max, and similar) you must think about processing as blocks of work, intended to fit within the time it takes to work on one (blocksize) of audio.

Read up on the blocksize parameter, that may help tie it all together.

Posted: 02 Nov 2015, 00:00
by sephult
Hello ahonoe!

So the processing in that for loop happens faster than the output. That's why you always just end up with 31.
You need to have some sort of tick or timer to divide up the incremental numbers.

I took and made a test using the processing loop and a switch, by incrementing each processing block (which the process procedure does).
Now you can see it zooming through and actually changing, but at the speed of the processing block.

//////////////////////////
//
/////////////////////////
// parameters declaration
var inp : Tparameter;
var outp : tparameter;
var reset : TParameter;
// initialisation : create parameters
procedure init;
begin
inp :=CreateParam('in',ptButton);
outp:= CreateParam('out',ptDataFader);
setmax(outp,32);

reset:=CreateParam('reset',ptButton);

end;

var CountOn :single;
var i :integer;
procedure process;
begin

//get value of the switch
CountOn:=round(getvalue(inp));

if countON = 1 then begin
if i < 32 then begin
inc(i);
setvalue(outp,i)
end
else begin
i:=0;
setvalue(outp,i);
end;
end;

end;

Posted: 02 Nov 2015, 00:03
by sephult
The Midi Arpeggiator has an example of a Tick controlled timer, although sometimes quite complicated to read...but it does show a little more how you could use an external clock to drive, or you will need to implement in scripting to processing only soo many n blocks....etc...

I guess long story short there are many ways you could code it up:)

If you need help let me know and I'll try to come up with some ideas to help get you going.

-s

Posted: 02 Nov 2015, 00:15
by ahonoe
Brilliant! Thanks for getting back to me shawnb and sephult.

I was wondering if everything was executing within a single bloc. I assumed that the setvalue() would regulate the speed of the script. So sephult, you are suggesting I use the process block, rather than the fast callback section and add the if statement to slow things down?

Posted: 02 Nov 2015, 02:17
by sephult
You could use either one, like I said if you want to use an external clock to adjust the counting you could similar to how the arpeggiator uses the callback and Tick procedure. Quick and dirty I just gave you a process block example. With a little thought you could probably implement a way to only count every so many process blocks with a scripted counter internal.

You could do something like this pseudo code

i:=i+1
if i=5 then
inc(c)
setvalue(outp,c)
i:=0
end


Just a rough explanation, so that your output doesn't get modified the first 4 iterations of the process block, but will output on the 5th iteration and reset the internal counter.

Hope makes sense....getting a little too dopey tonight to script... lol :)

-s