Changing The Colour Of A Gui Button When Note Present On Row00?

Hi, how would I go about changing the colour of a gui button when note present on row00?.

I’ve got a button which samples to a specific track. It’s a destructive affair altogether, every time the button is pressed, a record starts overwriting a specific sample in a specific slot.
a note is put into the pattern editor upon clicking on the button.

Now, I’m really content on this, especially in mixer view. But how would I go about altering it so that once there’s a note on the button’s track, the button changes colour? I know pretty much nothing about the viewBuilder and it’s really daunting for me to even just get regular buttons in. I was eventually able to hack together some code that enabled midi-binding buttons… :)

  
for i=1,7 do   
if renoise.song().instruments[i].samples[1].sample_buffer.has_sample_data then   
color1 = {0x22, 0xaa, 0xff}  
  

well, obviously, color1 is button1, so this is useless as it ends up with sampleslot 7’s content changing the button1’s color1. I’m not quite sure how to define a table in a for-loop :)

That would require some refresh option. The way you can do it is simply hide the element, change the colourproperty and then make it visible again. The button should now show itself with the new properties.
I could ofcourse advise you to inspect the Duplex code how to do it, but Duplex may be a tad bit too complex in this to be capable of easily locate this.
However Drumprocessor ( 2.6, so you need to change the API level from 1.0 to 2.0 in order to enable it) also does colorchanging of the buttons and might be a lot easier to analyze the code how it is being done there:
http://tools.renoise.com/tools/drum-processor

So would it basically be a notifier which notices there’s a sample in a slot, hides the element and changes the colourproperty and makes it visible again?

I noticed you can change the color instantly (saves you from the hassle of hiding and displaying stuff again)…
simply attach an id to your button and then change the colour by :
vb.views.yourbuttonid.color = {0xff,0x00,0x00}

Here is a small changed snippet of the ExampleToolGui.lua (default available in Renoise), ignore the bitmap snippet in the middle, it is just for your orientation where to find it:

  
 vb:button {  
 text = "Hit me",  
 width = 60,  
 notifier = function()  
 if vb.views.mybutton.color[1] == 0xff then  
 vb.views.mybutton.color = {0x00, 0x00, 0xff}  
 else  
 vb.views.mybutton.color = {0xff, 0x00, 0x00}  
 end  
  
 show_status("button was hit")  
 end,  
 },  
 vb:button {  
 -- buttons can also use bitmaps as icons:  
 bitmap = "Bitmaps/MiniPiano.bmp",  
 width = 20,  
 notifier = function()  
 show_status("button with bitmap was hit")  
 end,  
 },  
  
 vb:button {  
 -- buttons can also have custom text/back colors  
 text = "Color",  
 id='mybutton',  
 width = 30,  
 color = {0x22, 0xaa, 0xff},  
 -- and we also can handle presses, releases separately  
 pressed = function()  
 show_status("button with custom colors was pressed")  
 end,  
 released = function()  
 show_status("button with custom colors was released")  
 end,  
 }  
 }  
  
  

Okay, I understand this example. Up to a point.
I tried

 vb:button{id='syncOn1', color=synccolor1, height=30, width=50, text='SYNC', notifier=function()  
if s.instruments[1].samples[1].beat_sync_enabled==true  
then s.instruments[1].samples[1].beat_sync_enabled=false  
a:show_status("Sample 1 set to sync: OFF")  
synccolor1={0x44,0x00,0x00}  
else  
  

but it seems that the notifier for changing the synccolor1 will have to be called elsewhere, before the vb?

Ok… This worked. One button click will change the colour, and another button click will change it back. Thanks! Now I just need to use this so that it’s set via a notifier. It was very nice of you to spell it out with the button_id.color thing, as that will help me in further projects :) thx