Welcome to %s forums

BrainModular Users Forum

Login Register

[script] stripping quotes, preferred method?

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

Unread post by woodslanding » 17 Jan 2010, 22:23

I have been working on an alt-combobox script. Basically, it takes the commatext from a combo or textfield and creates labels for a set of buttons. Then you put it in a popup, and use it as a combo. But you can lay out the buttons however you like, and it has paging buttons so you never have to scroll. When I get it working, I'll post it.

It's working great, except for the code that strips off the quotes. This is (with the most recent version) freezing usine. Any ideas about how better to do this (Bsork??)
The code that is trouble (commenting it out makes the script work fine) is:

Code: Select all

 if (item[1] = '"') then begin
                    
                    strings[i] := copy(commatext, pos - charCount + 2, charCount - 3);
                end else begin
                    strings[i] := item;
                end;
This worked fine with earlier versions, but the newest usine complains. I know it's not a great solution, but it used to work! There's just not much doc on characters!!

Thanks,
eric

Code: Select all

/// mondoCombo by emoon//////

/// mondo combo is designed to turn a bank of switches into a combo box.
///  For the moment, we will default to pg 1 each time we start up
///

const buttonCount = 32;  // 32
const itemMax = 256;     // 256

var namesOUT    : array of Tparameter;
var triggersIN  : array of Tparameter;
var cTextIN     : Tparameter;
var nextPg      : Tparameter;
var prevPg      : Tparameter;
var pageOUT     : Tparameter;
var valueOUT    : Tparameter;
var stringOUT   : Tparameter;
var close       : Tparameter;


var strings    : array of String;
var commatext  : String;
var page       : integer;
var selection  : integer;
var itemCount  : integer;
var pageMax    : integer;

// destroy

// initialisation : create parameters
procedure init;

var digit  : string;
var i  : integer; 

begin
    
    cTextIN   := CreateParam('comma text',ptTextField);
    SetIsOutput(cTextIN,false);
    nextPg   := CreateParam('next page',ptButton);
    SetIsOutput(nextPg,false);
    prevPg   := CreateParam('prev page',ptButton);
    SetIsOutput(prevPg,false);

    stringOUT := CreateParam('text out',ptTextField);
    SetIsInput(stringOUT,false); 

    
    valueOUT := CreateParam('value',ptDataField);
    SetIsInput(valueOUT,false); 
    close := CreateParam('close',ptButton);
    SetIsInput(close,false);     

    
    setArrayLength(strings, itemMax);
    setArrayLength(namesOUT, buttonCount);  
    setArrayLength(triggersIN, buttonCount);
  
    for i := 0 to (buttonCount - 1) do begin
        digit := IntToStr(i + 1);
        namesOUT[i] := CreateParam('name' + digit,ptTextField);
        SetIsInput(namesOUT[i],false);        
        triggersIN[i] := CreateParam('button' + digit,ptButton);
        SetIsOutput(triggersIN[i],false);
    end;

    pageOUT := CreateParam('page num',ptDataField);
    SetIsInput(pageOUT,false); 

    page      :=  0;
    selection := -1;
    itemCount :=  0;
    pageMax   :=  0;
end;


procedure updateButtons;
var i : integer;
begin
    setValue(pageOUT, page + 1);
    for i := 0 to (buttonCount - 1) do begin
        if ((page * buttonCount) + i) >= itemCount then begin
            setStringValue(namesOUT[i], '---');   
        end else begin    
            setStringValue(namesOUT[i], strings[(page * buttonCount) + i]);
        end;
    end;
end;

procedure Callback(n:integer);
var charCount : integer;
var i : integer;
var item : string;
var ch: string;
var pos: integer;


begin
    setValue(close, 0);
    // if the user has pressed a button then set the value and close the window
    for i:= 0 to buttonCount - 1 do begin
        if (n = triggersIn[i]) then begin
            if &#40;page * buttonCount&#41; + i < itemCount then begin
                setValue&#40;valueOut, i + &#40;page * buttonCount&#41;&#41;;
                setStringValue&#40;stringOUT, strings&#91;i + &#40;page * buttonCount&#41;&#93;&#41;;
                setValue&#40;close, 1&#41;;
            end;
        end;
    end;
    // if the commaText has changed, reparse the text, and layout the buttons
    if &#40;n = cTextIN&#41; then begin
        page &#58;= 0;  // reset the page number
        // split the commaText
        commatext &#58;= ' ' + getStringValue&#40;cTextIN&#41; + ',';
        i &#58;= 0;
        charCount &#58;= 0;
        for pos &#58;= 1 to length&#40;commatext&#41; do
        begin
            ch &#58;= copy&#40;commatext,pos,1&#41;;    
            if &#40;ch = ','&#41; then 
            begin
                item &#58;= copy&#40;commatext,pos - charCount + 1, charCount - 1&#41;;
                //if &#40;item&#91;1&#93; = '"'&#41; then begin
                    // can't handle quotes inside lines of text!!
                    //strings&#91;i&#93; &#58;= copy&#40;commatext, pos - charCount + 2, charCount - 3&#41;;
               // end else begin
                    strings&#91;i&#93; &#58;= item;
              //  end;
                if &#40;i = length&#40;strings&#41;&#41; then break; 
                i &#58;= i + 1;
                charCount &#58;= 0;           
            end;
            charCount &#58;= charCount + 1;            
        end;
        itemCount &#58;= i;
        pageMax &#58;= trunc&#40;itemCount/buttonCount&#41;;
        updateButtons;        
    end;
    //  if the user has paged, relayout the buttons
    if &#40;n = nextPg&#41; and &#40;page < pageMax&#41; then begin 
        page &#58;= page + 1;
        updateButtons;
    end else if &#40;n = prevPg&#41; and &#40;page > 0&#41; then begin
        page &#58;= page - 1;
        updateButtons;
    end;
        
end;

// no process bloc
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 » 17 Jan 2010, 22:45

okay, I've figured out that the problem actually comes from an extra return at the end of the textfield I use as input. Then the code works fine.

I tried using trim(getStringValue(commatextIN)) but that does not help. Any clues how to strip a linefeed from the end of a comma text input???

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

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 17 Jan 2010, 23:03

hi woodlanding,

did you try with that ?

Code: Select all

AdjustLineBreaks&#40;const S&#58; string&#41;;
For the doc, if you speak about the new fast script engine, did you see this page ?

and as usine script is nearly direct delphi transcription, a google search with delphi + yourkeyword does a good job.


Hope it help
Martin FLEURENT - Usine Developer - SDK maintainer

martignasse
Site Admin
Posts: 611
Location: Lyon, FRANCE
Contact:

Unread post by martignasse » 18 Jan 2010, 00:48

ok,

i did some research and found the TStringList is what you need


here we go with a simple example

Code: Select all

//////////////////////////
// TStringList example
/////////////////////////
// parameters declaration
var cTextIN     &#58; Tparameter;

var stringlist&#58; TStringList;

// initialisation &#58; create parameters
procedure init;
begin  
    cTextIN   &#58;= CreateParam&#40;'comma text',ptTextField&#41;;
    SetIsOutput&#40;cTextIN,false&#41;;

    stringlist &#58;= TStringList.create;
end;

// Global variables


// Callback
procedure Callback&#40;n&#58;integer&#41;;
var commastring &#58; string;
var item &#58; string;
var i &#58; integer;
begin
    if &#40;n = cTextIN&#41; then begin
        commastring &#58;= getStringValue&#40;cTextIN&#41;; 
        strace&#40; commastring &#41;;

        stringlist.CommaText &#58;= commastring ;

        for i &#58;= 0 to stringlist.Count-1 do begin
            item &#58;= stringlist.Strings&#91;i&#93;;
            strace&#40; item &#41;;
        end;
    end;
end;
as you see, it will make your life easier :)
Martin FLEURENT - Usine Developer - SDK maintainer

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

Unread post by bsork » 18 Jan 2010, 08:33

Thanks for reminding me of TStringList, Martin! I think I can improve some old scripts of mine with that one. :)
Bjørn S

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 18 Jan 2010, 09:50

Wow, great, thanks guys!

on to my next problem!
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 » 18 Jan 2010, 10:19

okay, I redid this with stringlist. WOW< EASY!!!!

I am still having a problem with this script. The automatic closing works fine the first time you use it, but doesn't work after that. So I put a manual close in, but even that has to be clicked twice to work.

It's actually almost a feature. In fact, instead of a close button, I'd like a 'keep open' switch. That makes it easy to browse a number of different selections, and still get quick combobox functionality when you need it.

But I need to figure out how to get data ins and outs working right!

Thanks as always for your AWESOME HELP!!!

I will post this in addons when I get it working right. It's a really nice alternative combobox setup for the touchscreen....

Code: Select all

/// mondoCombo by emoon//////

/// mondo combo is designed to turn a bank of switches into a combo box.
/// it breaks the elements into banks of buttons, and allows paging thru them
///
///

const buttonCount = 32;  // 32
const itemMax = 256;     // 256

var namesOUT    &#58; array of Tparameter;
var triggersIN  &#58; array of Tparameter;
var cTextIN     &#58; Tparameter;
var nextPg      &#58; Tparameter;
var prevPg      &#58; Tparameter;
var pageOUT     &#58; Tparameter;
var valueOUT    &#58; Tparameter;
var stringOUT   &#58; Tparameter;
var close       &#58; Tparameter;

var stringlist&#58; TStringList;
var commatext  &#58; String;
var page       &#58; integer;
var selection  &#58; integer;
var itemCount  &#58; integer;
var pageMax    &#58; integer;

// destroy  --do we need to worry about destroying the stringlist??  It lasts the life of the prog, so maybe not??

// initialisation &#58; create parameters
procedure init;

var digit  &#58; string;
var i  &#58; integer; 

begin
    
    cTextIN   &#58;= CreateParam&#40;'comma text',ptTextField&#41;;
    SetIsOutput&#40;cTextIN,false&#41;;
    nextPg   &#58;= CreateParam&#40;'next page',ptButton&#41;;
    SetIsOutput&#40;nextPg,false&#41;;
    prevPg   &#58;= CreateParam&#40;'prev page',ptButton&#41;;
    SetIsOutput&#40;prevPg,false&#41;;

    stringOUT &#58;= CreateParam&#40;'text out',ptTextField&#41;;
    SetIsInput&#40;stringOUT,false&#41;; 

    
    valueOUT &#58;= CreateParam&#40;'value',ptDataField&#41;;
    SetIsInput&#40;valueOUT,false&#41;; 
    close &#58;= CreateParam&#40;'close',ptButton&#41;;
    SetIsInput&#40;close,false&#41;;     

    setArrayLength&#40;namesOUT, buttonCount&#41;;  
    setArrayLength&#40;triggersIN, buttonCount&#41;;
  
    for i &#58;= 0 to &#40;buttonCount - 1&#41; do begin
        digit &#58;= IntToStr&#40;i + 1&#41;;
        namesOUT&#91;i&#93; &#58;= CreateParam&#40;'name' + digit,ptTextField&#41;;
        SetIsInput&#40;namesOUT&#91;i&#93;,false&#41;;        
        triggersIN&#91;i&#93; &#58;= CreateParam&#40;'button' + digit,ptButton&#41;;
        SetIsOutput&#40;triggersIN&#91;i&#93;,false&#41;;
    end;

    pageOUT &#58;= CreateParam&#40;'page num',ptDataField&#41;;
    SetIsInput&#40;pageOUT,false&#41;; 
   
    stringlist &#58;= TStringList.create;
    page      &#58;=  0;
    selection &#58;= -1;
    itemCount &#58;=  0;
    pageMax   &#58;=  0;
end;


procedure updateButtons;
var i &#58; integer;
begin
    setValue&#40;pageOUT, page + 1&#41;;
    for i &#58;= 0 to &#40;buttonCount - 1&#41; do begin
        if &#40;&#40;page * buttonCount&#41; + i&#41; >= itemCount then begin
            setStringValue&#40;namesOUT&#91;i&#93;, '---'&#41;;   
        end else begin    
            setStringValue&#40;namesOUT&#91;i&#93;, stringlist.strings&#91;&#40;page * buttonCount&#41; + i&#93;&#41;;
        end;
    end;
end;

procedure Callback&#40;n&#58;integer&#41;;
var charCount &#58; integer;
var i &#58; integer;
var item &#58; string;
var commastring&#58; string;
var pos&#58; integer;


begin
    setValue&#40;close, 0&#41;;
    // if the user has pressed a button then set the value and close the window
    for i&#58;= 0 to buttonCount - 1 do begin
        if &#40;n = triggersIn&#91;i&#93;&#41; then begin
            if &#40;page * buttonCount&#41; + i < itemCount then begin
                setValue&#40;valueOut, i + &#40;page * buttonCount&#41;&#41;;
                setStringValue&#40;stringOUT, stringlist.strings&#91;i + &#40;page * buttonCount&#41;&#93;&#41;;
                setValue&#40;close, 1&#41;;
            end;
        end;
    end;
    // if the commaText has changed, reparse the text, and layout the buttons
    if &#40;n = cTextIN&#41; then begin
        page &#58;= 0;  // reset the page number
        // split the commaText
        commastring &#58;= getStringValue&#40;cTextIN&#41;; 
//strace&#40; commastring &#41;;

        stringlist.CommaText &#58;= commastring ;
        itemCount &#58;= stringlist.Count - 1;
        
        for i &#58;= 0 to itemCount do begin
            item &#58;= stringlist.Strings&#91;i&#93;;
//strace&#40; item &#41;;
        end;

        pageMax &#58;= trunc&#40;itemCount/buttonCount&#41;;
        updateButtons;        
    end;
    //  if the user has paged, relayout the buttons
    if &#40;n = nextPg&#41; and &#40;page < pageMax&#41; then begin 
        page &#58;= page + 1;
        updateButtons;
    end else if &#40;n = prevPg&#41; and &#40;page > 0&#41; then begin
        page &#58;= page - 1;
        updateButtons;
    end;       
end;

// no process bloc
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 » 20 Jan 2010, 08:58

well, I kludged a workaround. Still not sure how you send a switch output from the callback loop.... you need to send a 1 and then a 0 sometime later. What is a working method for this??

Well, I ended up putting in an 'open' input that resets the value of close whenever the combo is open. Not so elegant, but it works.

I will post this to addons once V5 is out....
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests