visual response to midi controller action

hey guys,

i am scripting my first gui for a midi controller to have a visual view of the controler values on the screen.
the midi mapping from the options menu works verry well when i create a button like this:

local mybutton = vb:button {  
 -- buttons can also have custom text/back colors  
 id = "my_button",  
 text = "Color",  
 width = 50,  
 height = 50,  
 color = {0x22, 0xaa, 0xff},  
 midi_mapping = "Transport:Playback:Start Playing [Trigger]",  
 -- and we also can handle presses, releases separately  
 pressed = function(mybutton)  
 show_status("button with custom colors was pressed")  
 local my_button_view = vb.views.my_button  
 my_button_view.color = {0x00, 0x00, 0x00}  
 released = function()  
 show_status("button with custom colors was released")  

my problem now is that the button doesn’t switch the color when i use it with midi controller. only when i click it with the mouse it is changing its color.
the function gets triggered in the right way but the button doesn’t respond.

any ideas how to solve this issue?

What you are doing seems to be the right approach. But something that might not be obvious is, that when setting a button to “fully black” the color is in fact removed from the button
A workaround would be to set the color to almost black, something like {0x01,0x01,0x01}

(yes, that the current Renoise API works in this way is a bit hackish really, and might change. But even then, this workaround would still work just fine…)

thanks for the answer. the coloring is not the problem. it is working like it should work. but only when using it via mouse.
the visual response seems not to be triggered by midi events. even in the midi_mapping() example from the docu. triggering a button doesnt cause any visual feedback.
do i have to map the response in aspecial way to the states and values of a button or slider?

Oh, now I understand.

Yes, there is no built-in visual reponse with MIDI input, as is the case with mouse actions.
You would have to store a reference to the button (vb.views.my_button), and then update it’s color property in the function receiving the midi message (the handler)

Would the handler then have to be defined somewhere else in the code?

i think for example in the midi callback function. or better in the function which is assigned to the button, like:

midi_mapping = "com.renoise.ExampleToolGui:Example MIDI Mapping"  

thanks danoise!

whtt i still dont understand is how to use the context of the view in the function which gets triggered from the midi event. i tried it like following:

 name = "com.minzky.div:mymidifun",  
 invoke = function(vb)  
 vb.views.my_button.color = {0x00, 0x00, 0x00}  

but the context of the vb is not passable to the function. any ideas?

The midi handler method does not get passed a reference to the viewbuilder - it receives a “MidiMessage”.
What exactly this message contains is explained in the scriptingtool API docs, basically you can examine the message properties based on how it was originally mapped to the parameter, when using MIDI mapping dialog.

But otherwise, the approach is good. You want a reference the the button, and using the vb.views makes sense, because you could reference basically any viewbuilder component that was tagged with an id.

All you need to do in order to keep a valid reference to the viewbuilder instance, is to make it a “global” variable. In other words, define your variable outside any function, and it should be accessible from within any function in your tool:

local vb = nil -- this is globally accessible  
function create_ui()  
 vb = renoise.ViewBuilder() -- store a reference to the viewbuilder   
 id = "my_button",  
 midi_mapping = "Transport:Playback:Start Playing [Trigger]",  
 name = "Transport:Playback:Start Playing [Trigger]",  
 invoke = function(msg)  
 print(vb.views.my_button) -- access our global variable  

ok i did it now like this. works well. thanks danoise!