This one uses the first column to select pages, and the rest of the cells update accordingly. It can take a number in, and send a number out via a click on the matrix. I swapped the x and y axes, because I like to read down more than across....
It's basically working fine, but two small problems:
1. If I put any spaces in my pages commatext, it is mis-parsed into two elements. It looks at it as 'spaceText'.....
2. Although I'm only setting values of 1 or 0 for 'cells out', I'm seeing a lot of very small values, and the matrix buttons are changing shades (randomly?) when the first button in column 2 is pressed.
Here's the patch:
http://www.sensomusic.com/forums/upload ... omboHH.pat
and here's the code:
Code: Select all
////////////////////////////////////////////////////////////////////////////////////////////////
CONST BUTTON_COUNT = 32; //should be a multiple of page count
CONST PAGE_COUNT = 8;
VAR cellsOUT, namesOUT, presetOUT, presetsIN, pagesIN, clickedIN, presetIN: tParameter;
VAR pages, presets,buttonNames : TStringList;
var page, preset, presetCount, pageMax, ROW_COUNT, COL_COUNT, MATRIX_SIZE : integer;
// destroy
procedure Destroy;
begin
pages.free;
presets.free;
buttonNames.free;
end;
PROCEDURE Init;
BEGIN
pagesIN := CreateParam('pages', ptTextfield); SetIsOutput(pagesIN, FALSE);
presetsIN := CreateParam('presets', ptTextfield); SetIsOutput(presetsIN, FALSE);
clickedIN := CreateParam('last clicked', ptDatafield); SetIsOutput(clickedIN, FALSE);
presetIN := CreateParam('preset num', ptDatafield); SetIsOutput(presetIN, FALSE);
cellsOut := CreateParam('cells out', ptArray); SetIsInput(cellsOut, FALSE);
namesOut := CreateParam('captions out', ptTextfield); SetIsInput(namesOut, FALSE);
presetOut := CreateParam('preset out', ptDatafield); SetIsInput(presetOut, FALSE);
MATRIX_SIZE := PAGE_COUNT + BUTTON_COUNT;
COL_COUNT := BUTTON_COUNT div PAGE_COUNT;
ROW_COUNT := PAGE_COUNT;
setLength(cellsOUT, MATRIX_SIZE );
pages.Create;
presets.Create;
buttonNames.Create;
END; // Init
///////////////////////////////////////////////////////////////////////////////////////
// to switch rows and columns. x = row, y = col. For x = 0, add the page name. then
// for x = 1 to 4, get items 0, 8, 16, and 24. that's page_count * (x-1) + y
//
procedure UpdateButtons;
var col,row,index : integer;
begin
buttonNames.Clear;
for row := 0 to (ROW_COUNT - 1) do begin // for each row
for col := 0 to COL_COUNT do begin // for each column--incl page column
if col = 0 then buttonNames.add(pages.getStrings(row)) // add page row item
else begin
index := (PAGE_COUNT * (col - 1)) + row; // get the row/col adjusted index....
if ((page * BUTTON_COUNT) + index) >= presetCount then begin
buttonNames.add('---');
end else begin
buttonNames.add(presets.getStrings((page * BUTTON_COUNT) + index));
end;
end;
end;
end;
setStringValue(namesOUT, buttonNames.getCommatext);
end;
PROCEDURE clearMatrix(); //////////////////CLEAR MATRIX////////////////////
var i : integer;
BEGIN
for i := 0 to (MATRIX_SIZE - 1) DO BEGIN
setDataArrayValue(cellsOUT,i,0);
strace('cell zeroed: ' + intToStr(i));
END;
END;
PROCEDURE enable(index : integer); /////////////////ENABLE////////////////////////
BEGIN
setDataArrayValue(cellsOUT, index, 1.0);
END;
PROCEDURE PageChanged(); /////////////////////PAGE CHANGED////////////////
var index, cellNum: integer;
BEGIN
UpdateButtons();
ClearMatrix();
enable(page * (COL_COUNT + 1));
if (preset div BUTTON_COUNT) = page then // if the preset is on the current page....
BEGIN
index:= preset mod BUTTON_COUNT; // raw preset index
cellNum:= ((index mod ROW_COUNT) * (COL_COUNT + 1)) + 1 + (index div ROW_COUNT);// actual cell num
enable(cellNum);
END;
END;
PROCEDURE PresetChanged(); /////////////////////PRESET CHANGED////////////////
var index, cellNum: integer;
BEGIN
page:= preset div BUTTON_COUNT; // figure out which page the preset is on
// strace('page = ' + intToStr(page));
PageChanged();
setValue(presetOUT, preset);
END;
PROCEDURE Callback(n : Integer); ///////////////////////CALLBACK////////////////
VAR i, x, y, index, clicked, cellNum, column : Integer;
BEGIN
CASE n of
presetsIN:
BEGIN
presets.setCommaText(GetStringValue(presetsIN));
presetCount:= presets.count;
END;
pagesIN:
BEGIN
pages.setCommaText(GetStringValue(pagesIN));
END;
presetIN:
BEGIN
preset:= trunc(getValue(presetIN));
PresetChanged();
END;
clickedIN:
BEGIN
cellNum:= trunc(getValue(clickedIN));
column := cellNum mod (COL_COUNT + 1);
if (column = 0) then BEGIN // it's a page number
page := cellNum div (COL_COUNT + 1);
PageChanged();
END
ELSE BEGIN
index:= (column * ROW_COUNT) + (cellNum div (COL_COUNT + 1)) - ROW_COUNT;// + ROW_COUNT;
preset:= (BUTTON_COUNT * page) + index; // compute preset number
PresetChanged();
END;
END;
END; //case
END; // Callback
///////////////////////////////////////////////////////////////////////////////////////
PROCEDURE Process;
BEGIN
END;cheers,
-e
