Cabbage Logo
Back to Cabbage Site

FLButton label does not update

Dear All,
Am facing another problem, this time it’s about renaming button labels.
The loop works fine and outputs the values
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
as stings on the console as expected.
However, on the FLbuttons the numbers are not present. Instead, all buttons are labeld with “15” although.

Thanks in advance for your time !
Dominik

FLpanel “Control”, 660, 550, 100, 100, 5, 1 ; start of container
iCount = 0
iButSize = 40
gkSeqArray[] init 16
giHaButArray[] init 16
gSeqStr[] init 16
until iCount == 16 do; draw a column of buttons
gkSeqArray[iCount], giHaButArray[iCount] FLbutton “”, 1, 0, 1,; “label”, ion, ioff, itype
iButSize, iButSize, (iButSize*iCount), iButSize, 0; iwidth, iheight, ix, iy, iopcode
; init widgets…
gSeqStr[iCount] sprintf "1:%d ", iCount
prints gSeqStr[iCount]
FLsetText gSeqStr[iCount], giHaButArray[iCount]
iCount += 1
od
gkVol,giHaVol FLslider “Vol”, -1, 0, 0, 6, -1,; “label”, imin, imax, iexp, itype, idisp
20, 300, 10, 100; iwidth, iheight, ix, iy
gkQ,giHaQ FLslider “Q”, -1, 0, 0, 6, -1,; “label”, imin, imax, iexp, itype, idisp
20, 300, 40, 100; iwidth, iheight, ix, iy
FLpanelEnd; end of container
FLrun; runs the widget thread
; Set the widget’s initial value
FLsetVal_i -0.9, giHaVol
FLsetVal_i -0.9, giHaQ

I think this has to do with memory allocation for the FLsetText opcode being continually overwritten within the loop. The way around the problem is to use a recursive UDO:

opcode	SetText, 0, io
 iNumber, iCount	xin
 gSeqStr[iCount] sprintf "1:%d ", iCount
 FLsetText gSeqStr[iCount], giHaButArray[iCount]
 if iCount < iNumber then
  SetText	iNumber, iCount+1
 endif
endop

SetText	15

But I’ll say this before anyone else does… why don’t you use Cabbage widgets instead of the FLTK ones? For achieving this sort of thing they are much more flexible and they look more modern. Maybe you have a good reason for using FLTK but I had to ask really as this is the Cabbage forum :wink:

Many thanks for our quick response Ian,

Yes, i was considering an iterative approach as well, but thought that FLsetText could not be overwritten since each handle is stored in a different location in the array.

I get your point re Cabbage which looks fantastic. Saying this, it crashed several times and the link to the latest version doesn’t work.So i downloaded a version without the studio.

However, since still a fresher with Csound, i’d like to get the basics right first.

Cheers
Dominik