Welcome to %s forums

BrainModular Users Forum

Login Register

[scripting] Sending a button message to a ptbutton outlet

I need help on a Patch
Post Reply
oxyredox
Member
Posts: 44
Location: Paris
Contact:

Unread post by oxyredox » 10 Jul 2011, 20:05

Hi everyone,
I need my script to send a button message ( 1 then 0) to one of its outlet. I have this parameter set to ptbutton and its name is, say, ButtonOut.
It seems that setvalue(ButtonOut,1) does'nt work... No big surprise indeed !

Is there a simple way to do this or do I have to send '1' and then after one cycle send a '0' ? I would like to avoid this chronological approach since my script, so far, is just immediate...

Thank you all

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

Unread post by nay-seven » 10 Jul 2011, 20:54

hello,
I'm really a newbie in script world but maybe (and waiting for a script guru in this Sunday evening)
you can find some inspiration in this Bsork script :


Code: Select all

/////////////////////////////////////////////////////////////
//Bloc counter with Max Value and refresh speed
///////////////////////////////////////////////////////////
// If start pulse will count incremental till max value is reached
// increment is timespaced of nb_blocs input.
////////////////////////////////////////////////////////
VAR start, counter, maxVal,counting,NB_blocs : tParameter;
VAR count : Integer;
///////////////////////////////////////////////////
PROCEDURE Init;
BEGIN

   start := CreateParam('start', ptButton);
   SetIsOutput(start, FALSE);

   maxVal := CreateParam('max', ptDataField);
   SetIsOutput(maxVal, FALSE);setValue(maxVal,16);

   NB_blocs := CreateParam('nb_blocs', ptDataField);
   SetIsOutput(NB_blocs, FALSE); setValue(Nb_Blocs,100);

   counter := CreateParam('counter', ptDataField);
   SetIsInput(counter, FALSE);

   counting := CreateParam('counting', ptDataField);
   SetIsInput(counting, FALSE);
END;

//PROCEDURE Callback(n : Integer);
var maxvaltmp : integer;
PROCEDURE Process;
BEGIN

   IF (GetValue(start) = 1) THEN BEGIN                          //if start pulse of button we start the process
      setvalue(start,0);
      maxValtmp:= round(getValue(maxVal)*getValue(NB_blocs));   // we get the maxvalue to count to. we muliply by nb_blocs for the speed.                                                            //we reset count to 0 
      count := 0;
      SetValue(counting,1);                                     //we start counting so set the parameter to 1.
      END
      ELSE BEGIN                                                //as soon as the button went back to 0 will count.
          count := count + 1;
      END;


    while count > maxValtmp                                // if count reached maxvalue, it keeps that value
          do begin                                         // and set counting parameter to 0.
          count := maxValtmp;
          SetValue(counting,0);
      END;

   SetValue(counter, count div round(getValue(NB_blocs)));        //we set the value to counter output. (we divide by nb_blocs as previously multiplied the max
                                                                  // to get a control over refresh speed. At 1 bloc, it's the fastest possible clock in usine
                                                                  // that will increment each bloc (3ms at 128samples) and ensure a strong jiter free 
                                                                  // sync over time counters.
                                                                  // it can be used to set some arrayvalue, dispatchers, ask osc datas ect...
END;

oxyredox
Member
Posts: 44
Location: Paris
Contact:

Unread post by oxyredox » 11 Jul 2011, 19:38

unfortunately in this script the button is an inlet, mine is an outlet
what I need to do is to send a button message out the script

thanks anyway !

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 12 Jul 2011, 00:50

I think you should use a normal ptdatafield type output, and indeed you must send 1 then 0. For this the usyal solution is to trig a counter in process when an input in callback has hanged if you really need 1 then next bloc 0. But if ie you trig by a mouse down input, you can make it simpler by staying in callback and set output to 1 when mouse is dwn and 0 wen it release, or trig the 0 by another input chg.

oxyredox
Member
Posts: 44
Location: Paris
Contact:

Unread post by oxyredox » 12 Nov 2011, 12:08

Yes, that's logical... So I can't escape using the main procedure, there's no way doing it with just the callback proc. ?

Ken29
Member
Posts: 116
Contact:

Unread post by Ken29 » 14 Nov 2011, 09:59

Hi,

It can work that way with the callback procedure,

Cheers


// parameters declaration

Var InA :tParameter;
Var OutA : tParameter;


// initialisation : create parameters
procedure init;

begin
InA := Createparam('Go', ptdatafield);
SetIsOutput(InA, False);
OutA := Createparam('Resultat', PtButton);
SetIsInput(OutA, False);
end;

// Callback procedure

Procedure Callback(N:integer);

begin
If getvalue(InA)=1 then SetValue (OutA,1) else SetValue (OutA,0);
End;

oxyredox
Member
Posts: 44
Location: Paris
Contact:

Unread post by oxyredox » 03 Mar 2012, 12:26

interesting!

I'll try this,
the callback procedure must be called twice (first to send 1, and next block to send 0) so I might connect the "button" output of the script to an input of the script that would inevitably cause the callback procedure to be called next block..

I'll report soon !

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 66 guests