Welcome to %s forums

BrainModular Users Forum

Login Register

Any way to know when Enter key is pressed on text fader?

I need help on a Patch
Post Reply
woodslanding
Member
Posts: 1327
Contact:

Any way to know when Enter key is pressed on text fader?

Unread post by woodslanding » 25 Nov 2022, 06:33

Sometimes PIC module isn't perfect. For regular faders, I can check mousedown. But the mouse is not down when I'm typing into a text fader. The important thing is when I press Enter, and I'd like to use that as a trigger....

Thoughts?

Thanks!!!!
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 25 Nov 2022, 06:52

Okay, this seems to work pretty well...
enterKey.png
(for some reason, the 'key' output on the keyboard module is always zero.)

The problem here, which I never know how to solve, is that if I put a PIC module before the text 2 fader, then change the text 2 fader value, and want to update it back to the old text 1 value, the PIC module doesn't see a change, and nothing happens. If I don't add a PIC, then I can't change the value of text2 at all.

I encounter this kind of issue a lot, and I am trying to figure out a way around it.....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 25 Nov 2022, 07:03

I thought I had the solution. It seemed like the problem was that the key out never changed...
enterKey2.png
But this still has the problem that I cannot change the value of text 2, even when 'pass' is off. The pass output shows [-1], but the value still won't change.
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 25 Nov 2022, 10:18

this solution seems to work as expected:
ss key.png

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 08 Dec 2024, 07:04

Coming back to this years later.

This patch makes me unreasonably happy. A text fader that triggers on enter, even if the text is unchanged. So great!

Mouse in makes sure enter key doesn't have an effect unless the text is open for editing...

cheers!
EnterText.usine-subpatch
(16.35 KiB) Downloaded 711 times
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 08 Dec 2024, 17:38

Well, there is a problem with this. If I escape from the textfield, because I changed my mind, that leaves the mouse value hot, and if I press enter from some other textfield, or for any other reason, it fires, and sends the data.

Trying to figure this out...

Would sure be nice to have an 'is editing' output on the textfield....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 09 Dec 2024, 02:48

I am working on a script that would turn a switch into a text fader, because the entry popup in a text fader is so small. I am running into a problem trying to convert keycodes to text. Is there a usine method for turning keycodes into strings or chars? I am not having luck tracking that down. I know usine just does it internally, by mis-cabling, and I will use that feature for now, but I'd like to include it in the script. I'm not sure how to use char's in usine, I can't find any documentation on it. And I'm not sure what text encoding usine uses, and I'm not very encoding-savvy to begin with.

Also, Is there somewhere in the documentation where it is noted what actual version of pascal Usine uses? That would be nice information to know. I am always trying commands I find on the web, but they don't work in usine....

thanks!!!
-eric
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 09 Dec 2024, 06:43

Went searching through the forums, and tracked down Chr(keynum) command. Working great! I'll post my patch when I get it a little more debugged.... would be nice to put that in the string part of the scripts page of the manual.
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 09 Dec 2024, 07:39

Here's the script, in case it's useful to someone. It only does capital letters so far. I'm not sure what to do about that--I am not checking the shift key, so I would expect all lower case letters. I will look into it more, but this will work okay for now.

Code: Select all

////////////////////////////////////////////   
//  SWITCH AS TEXT FADER  
//  if you are tired of those tiny windows 95 text entry popups, try this.  It uses the text of
//  the button, so you can make it as large as you like.  If the text will end up as the
//  title of the button, you can also know whether it will fit...
//
//  off text is typically the title.  when the user presses the switch
//  the text shown is either what was last entered, or an empty string, depending 
//  on the state of 'clear existing'.
//  'text to switch' is typically wired to the switch on caption, but could be wired
//  to the switch off caption as well, to show the value even when it's off.

//  since we don't have a cursor, a backspace will clear all the text.  Actually more convenient
//  for short text, I think.
//                     
////////////////////////////////////////////
const ENTER = 13;
const BACKSPACE = 8;
const ESCAPE = 27;
                          
// Globally enable/disable logging 
const DTAG = 'TextButton: ';
const DBUG_ON = TRUE;
procedure debug(s: string); begin if DBUG_ON then strace(DTAG + s); end;
procedure iDebug(s: string; num : integer); begin debug(s + '= ' + intToStr(num)); end;

// parameters declaration                                            
var switchIN, switchTextIN, keyNumIN, keyDownIN, offEntersIN, clearTextIN: tParameter;
var textOUT, switchOffOUT, switchTextOUT: tParameter;
var gText, gRevertText, gKeyin: string;
var gKeynum: integer;
var gLive,gSwitchedOff: boolean;
 // initialisation : create parameters
procedure init;
var i : integer;                   
begin                           
    SetModuleColor($804080+600000); 
 
    switchIN := CreateParam('switch in', ptSwitch, pioInput);
    //if we start with existing text
    switchTextIN := CreateParam('switch text', ptTextfield, pioInput);
    keyNumIN := CreateParam('key num', ptDatafield, pioInput);     
    clearTextIN := CreateParam('clear existing', ptSwitch, pioInput);
    switchOffOUT := CreateParam('set switch off', ptButton, pioOutput);
    switchTextOUT := CreateParam('text to switch', ptTextfield, pioOutput);
    //text to send on
    textOUT := CreateParam('text out', ptTextfield, pioOutput);

    gLive := FALSE;
    gSwitchedOff := TRUE;
    
end;

procedure processSwitch(state: integer);
begin
    if state = 0 then
    //switch turned off
    begin
        gLive := FALSE;
    end
    else if (state = 1) then
    //switch turned on
    begin
        if clearTextIN.asInteger = 0 then
            gText := switchTextIN.asString
            else gText := '';
        switchTextOUT.asString(gText);
        gRevertText := switchTextIN.asString;; //save this in case the user cancels.
        gLive := TRUE;
    end
end;

procedure processKey(keynum: integer);
begin
    //if the key is backspace, clear everything. We have no cursor, so this is how we do it
    if keynum = BACKSPACE then
    begin
        gText := '';
        switchTextOUT.asString(gText);
    end
    //if the key is enter, send the text to the output and turn off the button
    else if keynum = ENTER then
    begin
        //button text will not need to be changed.... oh I guess it does.
        textOUT.asString(gText);
        switchTextOUT.asString(gText);
        switchOffOUT.asInteger(1);
        gSwitchedOff := TRUE;
    end
    //if the key is esc, clear the text and turn off the button
    else if keynum = ESCAPE then
    begin
        //gText := '';
        switchOffOUT.asInteger(1);
        switchTextOUT.asString(gRevertText);
        gSwitchedOff := TRUE;
    end
    //otherwise, add the key to buttonText and send it out.
    else
    begin  
        Debug('key ' + Chr(keynum));
        gText := gText + Chr(keynum);
        switchTextOUT.asString(gText);
        gSwitchedOff := TRUE;
    end;
    //
end;

procedure Callback(n:integer);    
begin
    if n = switchIN then processSwitch(switchIN.asInteger)   
    else if (n =  keyNumIN) and (keyNumIN.asInteger > 0) and gLive then
    begin
       //we could store, and wait for zero (key up)
       idebug('process key num',keyNumIN.asInteger);
       processKey(keyNumIN.asInteger);

    end
end;

// no process bloc
procedure processIdle();
begin
    if gSwitchedOff then
    begin
        gSwitchedOff := FALSE;
        switchOffOUT.asInteger(0);
        textOUT.length(-1);
        switchTextOUT.length(-1);
    end;
end;


Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

User avatar
senso
Site Admin
Posts: 4424
Location: France
Contact:

Unread post by senso » 24 Dec 2024, 10:44

thanks+++

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 100 guests