button inputs to scripts
-
woodslanding
- Member
- Posts: 1327
I am trying to check a button from a script, and I think I'm making it harder than it should be, and it doesn't work anyway.
Can anyone explain how to do this, or point me to a script that does it. I just want to have the script do something when the user pushes a button connected to an input.
Thanks!
-eric
Can anyone explain how to do this, or point me to a script that does it. I just want to have the script do something when the user pushes a button connected to an input.
Thanks!
-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
-
woodslanding
- Member
- Posts: 1327
I wasn't using a button input. But now I am, and it's still not working.....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
-
woodslanding
- Member
- Posts: 1327
Okay, I see my problem now.
I'd like to run my main methods in a slower event loop, but then I seem to miss the button presses. I tried to keep track of whether the button had been pressed since the last iteration of my slow loop, but I haven't figured out how to track that reliably.....
For now, I'm running at full control rate, but I worry a little about the processor overhead.....
I'd like to run my main methods in a slower event loop, but then I seem to miss the button presses. I tried to keep track of whether the button had been pressed since the last iteration of my slow loop, but I haven't figured out how to track that reliably.....
For now, I'm running at full control rate, but I worry a little about the processor overhead.....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
-
bmoussay
- Member
- Posts: 130
Hello,
Wouldn't something like this do the trick?
var ButtonPressed: boolean;
If getvalue(pButton)=1 then
begin
Setvalue(pButton, 0);
ButtonPressed:=true;
end;
You put this before your slow loop, then you can check the value of ButtonPressed inside the slow loop, without forgetting to do
ButtonPressed:=false;
before exiting your slow loop.
Hope it can help.
Rgds,
B.
Wouldn't something like this do the trick?
var ButtonPressed: boolean;
If getvalue(pButton)=1 then
begin
Setvalue(pButton, 0);
ButtonPressed:=true;
end;
You put this before your slow loop, then you can check the value of ButtonPressed inside the slow loop, without forgetting to do
ButtonPressed:=false;
before exiting your slow loop.
Hope it can help.
Rgds,
B.
-
woodslanding
- Member
- Posts: 1327
I see. Cool, I'll try that--the key is to set the buttonpressed back to false.....
thanks!
-e
thanks!
-e
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify
-
pansoul
- Member
- Posts: 39
Hello
i dont really unsderstand the use of button in script.
bsork, when you write
IF (GetValue(pButton) = 1) THEN BEGIN
...
// To be on the safe side, add:
SetValue(pButton, 0);
END;
i suppose the pButton you refer in GetValue(pButton) is an input button and the pButton of SetValue(pButton, 0) an outuput button.
an i wrong ? if i am not, it means the output pButton have never be in the 1 position before come back in 0 position.
if i write
inval := getvalue(inputbutton);
setvalue(outputbutton,inval);
there is no problem, the output button follow the input one behaviour
but between this two moments i want to make a lot of things.
I want to trig a button behaviour (1..0) on an output at the end of my script
i tried to put at the end of my script that i suppose to be the last performed code (?)
setvalue(outputbutton,1);
setvalue(outputbutton,0);
but i can only see the 0 in the output.
anyone can help me or to point me out a script without input/output correlation ?
thanks
i dont really unsderstand the use of button in script.
bsork, when you write
IF (GetValue(pButton) = 1) THEN BEGIN
...
// To be on the safe side, add:
SetValue(pButton, 0);
END;
i suppose the pButton you refer in GetValue(pButton) is an input button and the pButton of SetValue(pButton, 0) an outuput button.
an i wrong ? if i am not, it means the output pButton have never be in the 1 position before come back in 0 position.
if i write
inval := getvalue(inputbutton);
setvalue(outputbutton,inval);
there is no problem, the output button follow the input one behaviour
but between this two moments i want to make a lot of things.
I want to trig a button behaviour (1..0) on an output at the end of my script
i tried to put at the end of my script that i suppose to be the last performed code (?)
setvalue(outputbutton,1);
setvalue(outputbutton,0);
but i can only see the 0 in the output.
anyone can help me or to point me out a script without input/output correlation ?
thanks
-
bsork
- Site Admin
- Posts: 1334
- Location: Asker, Norway
The pButton I'm referring to is the same parameter/variable both for input and output. What I didn't make clear, is that sometimes (may be bad programming, I don't know), the pButton is still 1 in the next execution block.
If I have understood things correctly, Usine won't update an input parameter unless something is passed along the "wire", so if you return it to 0 within the script somewhere after checking for 1, you can be sure that the code isn't executed repeatedly. (The p in pButton is jus my habit when naming the in/out parameters.)
Just for the record, a "proper" button message in Usine is a 1 followed by a 0 in the next block. What you're doing with
setvalue(outputbutton,1);
setvalue(outputbutton,0);
is assigning two values to the same variable, so he last one overrides the first. What you should do is set the value to 1 at the bottom of the script (assuming that you do this within a IF-test or something like that), and then at the top set the value to 0 - maybe with a check whether the value is 1 and needs to be updated.
A very general tip: If you can avoid reading parameters, do that, even if it means you have to create another variable of three. In most case you can save some CPU, while also getting a more readable script.
Hope this helps.
If I have understood things correctly, Usine won't update an input parameter unless something is passed along the "wire", so if you return it to 0 within the script somewhere after checking for 1, you can be sure that the code isn't executed repeatedly. (The p in pButton is jus my habit when naming the in/out parameters.)
Just for the record, a "proper" button message in Usine is a 1 followed by a 0 in the next block. What you're doing with
setvalue(outputbutton,1);
setvalue(outputbutton,0);
is assigning two values to the same variable, so he last one overrides the first. What you should do is set the value to 1 at the bottom of the script (assuming that you do this within a IF-test or something like that), and then at the top set the value to 0 - maybe with a check whether the value is 1 and needs to be updated.
A very general tip: If you can avoid reading parameters, do that, even if it means you have to create another variable of three. In most case you can save some CPU, while also getting a more readable script.
Hope this helps.
Bjørn S
-
pansoul
- Member
- Posts: 39
you mean reduce the input number ? i think about several technic to create variable of three but i am surebsork wrote:If you can avoid reading parameters, do that, even if it means you have to create another variable of three.
-use of multiple variable module
-multiply 2 button input value by 1 and 2 in order to distinguish their value at the script input
...
-
bsork
- Site Admin
- Posts: 1334
- Location: Asker, Norway
Hi Pansoul, sorry I was a bit unclear.
What I meant was: Avoid getting (and setting) parameter values more than once like in:
What I would have done, could look something like this:
Reducing the number of parameters isn't necessarily the best way of reducing CPU load - it's getting and setting the values (and of course the internal computations in the script) that eats the cycles. You can use different strategies; some are discussed in this topic: http://www.sensomusic.com/forums/viewtopic.php?id=1050, and there are also quite a few other threads where scripts and CPU are being discussed.
---
PS: Just noticed that once again I've made a bad typo. It should have been "...another variable or three". I guess a "variable of three" could be mistaken with the Multiple Variable module(?).
What I meant was: Avoid getting (and setting) parameter values more than once like in:
Code: Select all
IF ((GetValue(p1) = 1) OR (GetVaue(p2) = 1)) THEN BEGIN
...
IF (GetValue(p1) = 1) THEN BEGIN
...
IF (GetVaue(p2) = 1) THEN BEGIN
...Code: Select all
VAR b1, b2 : BOOLEAN;
...
b1 := (GetValue(p1) = 1);
b2 := (GetValue(p2) = 1);
IF (b1 OR b2) THEN BEGIN
...
IF (b1) THEN BEGIN
...
IF (b2) THEN BEGIN
...---
PS: Just noticed that once again I've made a bad typo. It should have been "...another variable or three". I guess a "variable of three" could be mistaken with the Multiple Variable module(?).
Bjørn S
