--------------------------------------------------------------------------------
--- Simple Element Class ---------------------------------------------------
--------------------------------------------------------------------------------
local Element = {}
function Element:new(x,y,w,h, r,g,b,a, lbl,fnt,fnt_sz, norm_val)
local elm = {}
elm.def_xywh = {x,y,w,h,fnt_sz} -- its default coord,used for Zoom etc
elm.x, elm.y, elm.w, elm.h = x, y, w, h
elm.r, elm.g, elm.b, elm.a = r, g, b, a
elm.lbl, elm.fnt, elm.fnt_sz = lbl, fnt, fnt_sz
elm.norm_val = norm_val
------
setmetatable(elm, self)
self.__index = self
return elm
end
--------------------------------------------------------------
--- Function for Child Classes(args = Child,Parent Class) ----
--------------------------------------------------------------
function extended(Child, Parent)
setmetatable(Child,{__index = Parent})
end
--------------------------------------------------------------
--- Element Class Methods(Main Methods) ------------------
--------------------------------------------------------------
function Element:update_xywh()
if not Z_w or not Z_h then return end -- return if zoom not defined
if Z_w>0.5 and Z_w<3 then
self.x, self.w = math.ceil(self.def_xywh[1]* Z_w) , math.ceil(self.def_xywh[3]* Z_w) --upd x,w
end
if Z_h>0.5 and Z_h<3 then
self.y, self.h = math.ceil(self.def_xywh[2]* Z_h) , math.ceil(self.def_xywh[4]* Z_h) --upd y,h
end
if Z_w>0.5 or Z_h>0.5 then --fix it!--
self.fnt_sz = math.max(9,self.def_xywh[5]* (Z_w+Z_h)/2)
self.fnt_sz = math.min(22,self.fnt_sz)
end
end
--------
function Element:pointIN(p_x, p_y)
return p_x >= self.x and p_x <= self.x + self.w and p_y >= self.y and p_y <= self.y + self.h
end
--------
function Element:mouseIN()
return gfx.mouse_cap&1==0 and self:pointIN(gfx.mouse_x,gfx.mouse_y)
end
--------
function Element:mouseDown()
return gfx.mouse_cap&1==1 and self:pointIN(mouse_ox,mouse_oy)
end
--------
function Element:mouseClick()
return gfx.mouse_cap&1==0 and last_mouse_cap&1==1 and
self:pointIN(gfx.mouse_x,gfx.mouse_y) and self:pointIN(mouse_ox,mouse_oy)
end
--------
function Element:draw_frame()
local x,y,w,h = self.x,self.y,self.w,self.h
gfx.rect(x, y, w, h, 0)--frame1
gfx.roundrect(x, y, w-1, h-1, 3, true)--frame2
end
--------
--------------------------------------------------------------------------------
--- Create Element Child Classes(Button,Slider,Knob) -----------------------
--------------------------------------------------------------------------------
local Button ={}; local Knob ={}; local Slider ={};
extended(Button, Element)
extended(Knob, Element)
extended(Slider, Element)
---Create Slider Child Classes(V_Slider,H_Slider)----
local H_Slider ={}; local V_Slider ={};
extended(H_Slider, Slider)
extended(V_Slider, Slider)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--- Button Class Methods ---------------------------------------------------
--------------------------------------------------------------------------------
function Button:draw_lbl()
local x,y,w,h = self.x,self.y,self.w,self.h
local fnt,fnt_sz = self.fnt, self.fnt_sz
--Draw btn lbl(text)--
gfx.set(0.7, 1, 0, 1)--set label color
gfx.setfont(1, fnt, fnt_sz);--set label fnt
local lbl_w, lbl_h = gfx.measurestr(self.lbl)
gfx.x = x+(w-lbl_w)/2; gfx.y = y+(h-lbl_h)/2
gfx.drawstr(self.lbl)
end
---------------------
function Button:draw()
self:update_xywh()--Update xywh(if wind changed)
local x,y,w,h = self.x,self.y,self.w,self.h
local r,g,b,a = self.r,self.g,self.b,self.a
---Get L_mouse state--
--in element--
if self:mouseIN() then a=a+0.1 end
--in elm L_down--
if self:mouseDown() then a=a+0.2 end
--in elm L_up(released and was previously pressed)--
if self:mouseClick() then self.onClick() end
--Draw btn(body,frame)--
gfx.set(r,g,b,a)--set btn color
gfx.rect(x,y,w,h,true)--body
self:draw_frame()
------------------------
self:draw_lbl()
end
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
----Objects--------------------------------------
-------------------------------------------------
local btn1 = Button:new(5, 10,30,30, 0.7,0.3,0.3,0.5, "01","Arial",20 )
local btn2 = Button:new(40, 10,30,30, 0.3,0.7,0.3,0.5, "01","Arial",20 )
local btn3 = Button:new(5, 45,30,30, 0.7,0.3,0.3,0.5, "02","Arial",20 )
local btn4 = Button:new(40, 45,30,30, 0.3,0.7,0.3,0.5, "02","Arial",20 )
local btn5 = Button:new(5, 80,30,30, 0.7,0.3,0.3,0.5, "03","Arial",20 )
local btn6 = Button:new(40, 80,30,30, 0.3,0.7,0.3,0.5, "03","Arial",20 )
local btn7 = Button:new(5, 115,30,30, 0.7,0.3,0.3,0.5, "04","Arial",20 )
local btn8 = Button:new(40, 115,30,30, 0.3,0.7,0.3,0.5, "04","Arial",20 )
local btn9 = Button:new(5, 155,30,30, 0.7,0.3,0.3,0.5, "05","Arial",20 )
local btn10 = Button:new(40, 155,30,30, 0.3,0.7,0.3,0.5, "05","Arial",20 )
local btn11 = Button:new(5, 190,30,30, 0.7,0.3,0.3,0.5, "06","Arial",20 )
local btn12 = Button:new(40, 190,30,30, 0.3,0.7,0.3,0.5, "06","Arial",20 )
local btn13 = Button:new(5, 225,30,30, 0.7,0.3,0.3,0.5, "07","Arial",20 )
local btn14 = Button:new(40, 225,30,30, 0.3,0.7,0.3,0.5, "07","Arial",20 )
local btn15 = Button:new(5, 260,30,30, 0.7,0.3,0.3,0.5, "08","Arial",20 )
local btn16 = Button:new(40, 260,30,30, 0.3,0.7,0.3,0.5, "08","Arial",20 )
local btn17 = Button:new(5, 300,30,30, 0.7,0.3,0.3,0.5, "09","Arial",20 )
local btn18 = Button:new(40, 300,30,30, 0.3,0.7,0.3,0.5, "09","Arial",20 )
local btn19 = Button:new(5, 335,30,30, 0.7,0.3,0.3,0.5, "10","Arial",20 )
local btn20 = Button:new(40, 335,30,30, 0.3,0.7,0.3,0.5, "10","Arial",20 )
local btn21 = Button:new(5, 370,30,30, 0.7,0.3,0.3,0.5, "11","Arial",20 )
local btn22 = Button:new(40, 370,30,30, 0.3,0.7,0.3,0.5, "11","Arial",20 )
local btn23 = Button:new(5, 405,30,30, 0.7,0.3,0.3,0.5, "12","Arial",20 )
local btn24 = Button:new(40, 405,30,30, 0.3,0.7,0.3,0.5, "12","Arial",20 )
local btn25 = Button:new(5, 445,30,30, 0.7,0.3,0.3,0.5, "13","Arial",20 )
local btn26 = Button:new(40, 445,30,30, 0.3,0.7,0.3,0.5, "13","Arial",20 )
local btn27 = Button:new(5, 480,30,30, 0.7,0.3,0.3,0.5, "14","Arial",20 )
local btn28 = Button:new(40, 480,30,30, 0.3,0.7,0.3,0.5, "14","Arial",20 )
local btn29 = Button:new(5, 515,30,30, 0.7,0.3,0.3,0.5, "15","Arial",20 )
local btn30 = Button:new(40, 515,30,30, 0.3,0.7,0.3,0.5, "15","Arial",20 )
local btn31 = Button:new(5, 550,30,30, 0.7,0.3,0.3,0.5, "16","Arial",20 )
local btn32 = Button:new(40, 550,30,30, 0.3,0.7,0.3,0.5, "16","Arial",20 )
local btn33 = Button:new(5, 590,30,30, 0.7,0.3,0.3,0.5, "M","Arial",20 )
local btn34 = Button:new(40, 590,30,30, 0.3,0.7,0.3,0.5, "S","Arial",20 )
local btn35 = Button:new(5, 630,65,30, 0.7,0.3,0.3,0.5, "Mute All","Arial",20 )
local Button_TB = {btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12,btn13,btn14,btn15,btn16,
btn17,btn18,btn19,btn19,btn20,btn21,btn22,btn23,btn24,btn25,btn26,btn27,btn28,btn29,btn30,btn31,btn32,
btn33,btn34,btn35}
------------------------------------------------
------------------------------------------------
btn1.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_1"),0) end
btn2.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_1"),0)end
btn3.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_2"),0) end
btn4.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_2"),0) end
btn5.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_3"),0) end
btn6.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_3"),0) end
btn7.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_4"),0) end
btn8.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_4"),0) end
btn9.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_5"),0) end
btn10.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_5"),0) end
btn11.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_6"),0) end
btn12.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_6"),0) end
btn13.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_7"),0) end
btn14.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_7"),0) end
btn15.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_8"),0) end
btn16.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_8"),0) end
btn17.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_9"),0) end
btn18.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_9"),0) end
btn19.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_10"),0) end
btn20.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_10"),0) end
btn21.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_11"),0) end
btn22.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_11"),0) end
btn23.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_12"),0) end
btn24.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_12"),0) end
btn25.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_13"),0) end
btn26.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_13"),0) end
btn27.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_14"),0) end
btn28.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_14"),0) end
btn29.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_15"),0) end
btn30.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_15"),0) end
btn31.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_TRACKS_SLOT_16"),0) end
btn32.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_TRACKS_SLOT_16"),0) end
btn33.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_MUTETOGGLE"),0) end
btn34.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_SOLOTOGGLE"),0) end
btn35.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_RS52ecbce52a3aec233397218ad0b7a75c51eb8074"),0) end
------------------------------------------------
------------------------------------------------
function DRAW()
for key,btn in pairs(Button_TB) do btn:draw() end
end
--------------------------------------------------------------------------------
--Init--------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Init()
--Some gfx Wnd Default Values--------------
local R,G,B = 20,20,20 --0..255 form
Wnd_bgd = R + G*256 + B*65536 --red+green*256+blue*65536
Wnd_Title,Wnd_W,Wnd_H,Wnd_Dock,Wnd_X,Wnd_Y = "Solo_Mute_State", 75,670, 0,1705,100
--Init window------------------------------
gfx.clear = Wnd_bgd
gfx.init( Wnd_Title, Wnd_W,Wnd_H, Wnd_Dock, Wnd_X,Wnd_Y )
--Mouse--
last_mouse_cap = 0
last_x, last_y = 0, 0
end
-------------------------
--Mainloop---------------
function mainloop()
Z_w,Z_h = gfx.w/Wnd_W, gfx.h/Wnd_H
if gfx.mouse_cap&1==1 and last_mouse_cap&1==0 then
mouse_ox, mouse_oy = gfx.mouse_x, gfx.mouse_y
end
Ctrl = gfx.mouse_cap&4==4
Shift = gfx.mouse_cap&8==8
----------------------
--DRAW,MAIN function--
DRAW()--Main()
----------------------
----------------------
last_mouse_cap = gfx.mouse_cap
last_x, last_y = gfx.mouse_x, gfx.mouse_y
char = gfx.getchar()
if char~=-1 then reaper.defer(mainloop) end --defer
-----------
gfx.update()
-----------
end
---------------------------------------
---------------------------------------
Init()
mainloop()