Welcome to %s forums

BrainModular Users Forum

Login Register

trouble with callback on matrix input

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

trouble with callback on matrix input

Unread post by woodslanding » 02 Nov 2024, 19:39

I have a script that aims to display matrix data in columns. It works fine for the text of the cells, but I recently tried to use it to reorder the cells values, and I'm having trouble with the array ins and outs.

Basically the output array only changes if the first item in the input array changes. I don't know why.. It sets the output array correctly for all items, but only when the first value in the input array has changed.

Thanks

Code: Select all

//////////////////////////////////////////////////////
// read matrix data newspaper style in columns
//e moon Nov 2022
////////////////////////////////////////////////////

const FAVTAG = '-';
var rowsIN, colsIN,ctIN,valsIN : Tparameter;
var ctOUT,dispCtOUT,valsOUT: Tparameter;

var gTextin, gTextOut, gDisplayText : TstringList;  
var row, col : integer;

// Globally enable/disable logging/////////////////////////////////////// 
const DTAG = 'matrix Sw> ';
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;
procedure fDebug(s: string; num : single); begin debug(s + '= ' + floatToStr(num)); end;
// Always log, whether debug is on or not.
procedure Error(s: string); begin strace('ERROR-' + DTAG + s); end;
procedure fError(s: string; num : single); begin strace('ERROR-' + DTAG + s + '= ' + floatToStr(num)); end;
//////////////////////////////////////////////////////////////////////////


procedure init;
begin   
    colsIN := CreateParam('col ct',ptDatafield,pioInput); 
    rowsIN := CreateParam('row ct',ptDatafield,pioInput);
    ctIN := CreateParam('ctext',ptTextField,pioInput);
    valsIN := CreateParam('values',ptArray,pioInput);

    ctOUT := CreateParam('ct out',ptTextField,pioOutput);
    dispCtOUT := CreateParam('display ct',ptTextField,pioOutput);
    valsOUT := CreateParam('values out',ptArray, pioOutput);

    ModuleColor($FF8E44AD); 
    gTextin.create; gTextOut.create; gDisplayText.create;
end;

// destroy
procedure Destroy; begin gTextIn.free; gTextOut.free; gDisplayText.free; end; 

procedure Callback(n:integer);
var i,j,len: integer;
var val: float;
var text,displayT: string;
var options: TReplaceFlags;
VAR values : ARRAY OF float;
begin
    
    //setArrayLength(values, 0); 
    //if n = valsIN then
    //begin
        len := valsIN.Length;
        valsOUT.Length(len);
        debug('vals in changed');
        j := 0;
        for col := 0 to (colsIN.asInteger - 1) do 
        begin
            for row := 0 to (rowsIN.asInteger - 1) do 
            begin 
                i := (colsIN.asInteger * row) + col;                                     
                valsOUT.asArray(j,valsIN.asArray(i));
                //values[j] := valsIN.asArray(i));
                //iDebug('setting output array position',j);
                //iDebug('to value',i);
                j := j + 1;
            end;
        end;
        gTextIn.clear; gTextOut.clear; gDisplayText.clear;
        gTextIn.setCommaText(ctIN.asString);

        options := [];
        
        for row := 0 to (rowsIN.asInteger - 1) do 
        begin
            for col := 0 to (colsIN.asInteger - 1) do 
            begin                                      
                i := (rowsIN.asInteger * col) + row;
                if i >= gTextIn.count then text := '' else text := gTextIn.getStrings(i);            
                gTextOut.add(text);
                //trim leading '-' from names for display
                if text.startsWith(FAVTAG) then displayT := StringReplace(text, FAVTAG,'', options) else displayT := text;
                gDisplayText.add(displayT);
                j := j + 1;
            end;
        end;
        ctOUT.asString(gTextOut.GetCommatext); 
        dispCtOUT.asString(gDisplayText.GetCommatext);
    //end;     
end;
Thanks,
-eric
Last edited by woodslanding on 02 Nov 2024, 20:30, edited 2 times in total.
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 » 02 Nov 2024, 19:54

here's my test patch:
MatrixSwitchTestAgain.pat
(23.63 KiB) Downloaded 738 times
Again, if I change the value of the first cell, all arrayOUT values update correctly. But even though the callback method always gets called, it only works when the first arrayIN value changes.

Thanks
Attachments
MatrixSwitchTest.pat
(18.29 KiB) Downloaded 450 times
Custom Ryzen 5900x MATX build, Win10, Fireface UFX, touchscreen
Custom 2 manual midi keyboard
Usine, Kontakt, Reaktor, Synthmaster, Byome, Arturia, Soundtoys, Unify

SylvainT
Site Admin
Posts: 494
Contact:

Unread post by SylvainT » 06 Nov 2024, 22:36

Hi,
On my end, text doesn't react, but matrix input works as expected. 😉
Sorry, i haven't found time to dive into your script too much.
Sylvain

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 07 Nov 2024, 00:09

Hi !
I tried to understand your patch, and I re-did it with modules from HH6
Hope it helps

Olivar
combine string and data.pat
(41.84 KiB) Downloaded 953 times
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

woodslanding
Member
Posts: 1327
Contact:

Unread post by woodslanding » 07 Nov 2024, 16:46

Well, I re-wrote the script so it doesn't need to send an Array out. I still don't understand why it's not working, but I guess I don't need to know, for now.
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 10 guests