[Solved] return color of a button using vb.views["x"].color

The button that I intend to manipulate may be this way:

vb:button {

id = “x”,

color ={ 0xFF, 0x00, 0x00 }

}

I have a small problem with the color of a button.I need to return the color of a button usingvb.views[“x”].color

What is my problem?To paint an ‘X’ button, it is easy like this:

  • vb.views[“x”].color = { 0xFF, 0x00, 0x00 }

or

  • vb.views[“x”].color = { 255, 000, 000 }

The problem is that when I need to take the already pre-set button color.I do not know how to recover it. If I use:

  • print ( vb.views[“x”].color )

or

  • color =vb.views[“x”].color

print (color)

return a table with this format: table: 0000000013EBD770

And I need to get --> { 0xFF, 0x00, 0x00 }

How do I obtain { 0xFF, 0x00, 0x00 } ???

There! Ignore the previous question…

The real problem I’m having is that I start with a color A of a button X.With a function I modify the color A and change it by the color B using pressed property of the button X.But then, I do not know how to recover the original color A using released property of the button X. :wacko:

Well reading this Raul I’m like: :wacko:

Also rprint? So:

rprint(vb.views["x"].color)

would probably be better than just standard ‘print’ to give the contents of a table? Each individual RGB component of the color table can probably be accessed with:

vb.views["x"].color[1] -- Red component
vb.views["x"].color[2] -- Green component
vb.views["x"].color[3] -- Blue component

Also:
local mycolor = vb.views["x"].color -- Store vb.views["x"].color table into 'mycolor' table
vb.views["x"].color = mycolor -- Put mycolor back into vb.views["x"].color
vb.views["x"].color = {0,0,0} -- 'Transparent' (themes) color

Just some random thoughts Raul :slight_smile:

Well reading this Raul I’m like: :wacko:

Also rprint? So:

rprint(vb.views["x"].color)

would probably be better than just standard ‘print’ to give the contents of a table? Each individual RGB component of the color table can probably be accessed with:

vb.views["x"].color[1] -- Red component
vb.views["x"].color[2] -- Green component
vb.views["x"].color[3] -- Blue component

Also:
local mycolor = vb.views["x"].color -- Store vb.views["x"].color table into 'mycolor' table
vb.views["x"].color = mycolor -- Put mycolor back into vb.views["x"].color
vb.views["x"].color = {0,0,0} -- 'Transparent' (themes) color

Just some random thoughts Raul :slight_smile:

Thanks! Finally, I have solved this problem by creating a specific function (return_key_note_released() ). I wanted to make it simpler, because it affects 120 buttons. But it works:

function return_key_note_pressed( k )
  k = vb.views['WMP_CTRL_NOT'].value
  vb.views["WMP_KEY_"..k..""].color = { 0xFF,0x00,0x00 }
end
---
function return_key_note_released( k, tb_cl )
  k = vb.views['WMP_CTRL_NOT'].value
  tb_cl = {}
  tb_cl.yl_1 = { 0,2,4,5,7,9,11, 12,14,16,17,19,21,23 }
  tb_cl.yl_2 = { 1,3,6,8,10, 13,15,18,20,22 }
  
  tb_cl.bl_1 = { 24,26,28,29,31,33,35, 36,38,40,41,43,45,47, 48,50,52,53,55,57,59 }
  tb_cl.bl_2 = { 25,27,30,32,34, 37,39,42,44,46, 49,51,54,56,58 }
  
  tb_cl.rd_1 = { 60,62,64,65,67,69,71, 72,74,76,77,79,81,83, 84,86,88,89,91,93,95 }
  tb_cl.rd_2 = { 61,63,66,68,70, 73,75,78,80,82, 85,87,90,92,94 }
  
  tb_cl.gy_1 = { 96,98,100,101,103,105,107, 108,110,112,113,115,117,119 }
  tb_cl.gy_2 = { 97,99,102,104,106, 109,111,114,116,118 }

  local function restore_color_piano()
    for i = 0, 119 do
      if tb_cl.yl_1[i] == k then return { 0xFF,0xFF,0xBF } end
      if tb_cl.yl_2[i] == k then return { 0x60,0x60,0x15 } end
      if tb_cl.bl_1[i] == k then return { 0xCF,0xCF,0xFF } end
      if tb_cl.bl_2[i] == k then return { 0x26,0x26,0x76 } end
      if tb_cl.rd_1[i] == k then return { 0xFF,0xCF,0xCF } end
      if tb_cl.rd_2[i] == k then return { 0x56,0x26,0x26 } end
      if tb_cl.gy_1[i] == k then return { 0xCF,0xFF,0xCF } end
      if tb_cl.gy_2[i] == k then return { 0x26,0x46,0x26 } end
    end
  end
  vb.views["WMP_KEY_"..k..""].color = restore_color_piano()
end

--- --- ---

WMP_KEY_NOTE = vb:button {
  active = false,
  id = 'WMP_KEY_NOTE',
  width = 50,
  height = 22,
  --color = { 0x40, 0x00, 0x00 },
  text = '---',
  tooltip = "'Last Note Monitor': show last pressed key. Press to locate!\n[Range: C-0 to B-9 (120 notes)]\nINS = Number of Instrument\nEMP = Note Empty\nOFF = Note-Off",
  pressed = function() return_key_note_pressed() repeat_key() wmp_fn_bt_pres() end,
  released = function() return_key_note_released() repeat_key(true) wmp_fn_bt_rel() end,
  
}

WMP_KEY_NOTE is a button that can modify up to 120 buttons.

Sometimes a small problem affects much bigger things :smiley: