@Aleksandr Oleynik, я делал себе панельку, очень удобную на мой взгляд, там запоминается статус мьютированный и немьютированных айтемов. На основе Жениного скрипта, который он как основу для творчества предложил, хочу его немного развить. Вот код:
Код:
--------------------------------------------------------------------------------
--- 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(250/256, 250/256, 250/256, 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
-------------------------------------------------
-------------------------------------------------
R = 228/256;
G = 81/256;
B = 18/256;
R1 = 82/256;
G1 = 150/256;
B1 = 70/256;
R2 = 210/256;
G2 = 120/256;
B2 = 49/256;
R3 = 69/256;
G3 = 150/256;
B3 = 140/256;
-------------------------------------------------
----Objects--------------------------------------
-------------------------------------------------
local btn1 = Button:new(5, 10,30,30, R,G,B,1, "01","Arial",20 )
local btn2 = Button:new(40, 10,30,30, R1,G1,B1,1, "01","Arial",20 )
local btn3 = Button:new(5, 45,30,30, R,G,B,1, "02","Arial",20 )
local btn4 = Button:new(40, 45,30,30, R1,G1,B1,1, "02","Arial",20 )
local btn5 = Button:new(5, 80,30,30, R,G,B,1, "03","Arial",20 )
local btn6 = Button:new(40, 80,30,30, R1,G1,B1,1, "03","Arial",20 )
local btn7 = Button:new(5, 115,30,30, R,G,B,1, "04","Arial",20 )
local btn8 = Button:new(40, 115,30,30, R1,G1,B1,1, "04","Arial",20 )
local btn9 = Button:new(5, 155,30,30, R2,G2,B2,1, "05","Arial",20 )
local btn10 = Button:new(40, 155,30,30, R3,G3,B3,1, "05","Arial",20 )
local btn11 = Button:new(5, 190,30,30, R2,G2,B2,1, "06","Arial",20 )
local btn12 = Button:new(40, 190,30,30, R3,G3,B3,1, "06","Arial",20 )
local btn13 = Button:new(5, 225,30,30, R2,G2,B2,1, "07","Arial",20 )
local btn14 = Button:new(40, 225,30,30, R3,G3,B3,1, "07","Arial",20 )
local btn15 = Button:new(5, 260,30,30, R2,G2,B2,1, "08","Arial",20 )
local btn16 = Button:new(40, 260,30,30, R3,G3,B3,1, "08","Arial",20 )
local btn17 = Button:new(5, 300,30,30, R,G,B,1, "09","Arial",20 )
local btn18 = Button:new(40, 300,30,30, R1,G1,B1,1, "09","Arial",20 )
local btn19 = Button:new(5, 335,30,30, R,G,B,1, "10","Arial",20 )
local btn20 = Button:new(40, 335,30,30, R1,G1,B1,1, "10","Arial",20 )
local btn21 = Button:new(5, 370,30,30, R,G,B,1, "11","Arial",20 )
local btn22 = Button:new(40, 370,30,30, R1,G1,B1,1, "11","Arial",20 )
local btn23 = Button:new(5, 405,30,30, R,G,B,1, "12","Arial",20 )
local btn24 = Button:new(40, 405,30,30, R1,G1,B1,1, "12","Arial",20 )
local btn25 = Button:new(5, 445,30,30, R2,G2,B2,1, "13","Arial",20 )
local btn26 = Button:new(40, 445,30,30, R3,G3,B3,1, "13","Arial",20 )
local btn27 = Button:new(5, 480,30,30, R2,G2,B2,1, "14","Arial",20 )
local btn28 = Button:new(40, 480,30,30, R3,G3,B3,1, "14","Arial",20 )
local btn29 = Button:new(5, 515,30,30, R2,G2,B2,1, "15","Arial",20 )
local btn30 = Button:new(40, 515,30,30, R3,G3,B3,1, "15","Arial",20 )
local btn31 = Button:new(5, 550,30,30, R2,G2,B2,1, "16","Arial",20 )
local btn32 = Button:new(40, 550,30,30, R3,G3,B3,1, "16","Arial",20 )
local btn33 = Button:new(5, 590,30,30, R3,G3,B3,1, "Time","Arial",14 )
local btn34 = Button:new(40, 590,30,30, R3,G3,B3,1, "Track","Arial",14 )
local btn35 = Button:new(5, 625,30,30, R3,G3,B3,1, "T+T","Arial",14 )
local btn36 = Button:new(40, 625,30,30, R1,G1,B1,1, "Unsel","Arial",14 )
local btn37 = Button:new(5, 660,30,30, R,G,B,1, "M","Arial",20 )
local btn38 = Button:new(40, 660,30,30, R1,G1,B1,1, "Un","Arial",20 )
local btn39 = Button:new(5, 700,65,30, R,G,B,1, "Remove","Arial",20 )
local btn40 = Button:new(5, 735,65,30, R1,G1,B1,1, "Paste","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,btn36,btn37,btn38,btn39,btn40}
------------------------------------------------
------------------------------------------------
btn1.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_1"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn2.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_1"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn3.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_2"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn4.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_2"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn5.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_3"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn6.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_3"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn7.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_4"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn8.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_4"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn9.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_5"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn10.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_5"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn11.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_6"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn12.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_6"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn13.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_7"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn14.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_7"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn15.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_8"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn16.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_8"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn17.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_9"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn18.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_9"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn19.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_10"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn20.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_10"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn21.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_11"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn22.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_11"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn23.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_12"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn24.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_12"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn25.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_13"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn26.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_13"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn27.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_14"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn28.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_14"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn29.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_15"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn30.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_15"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn31.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_SAVE_SOLO_MUTE_ALL_ITEMS_SLOT_16"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn32.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_RESTORE_SOLO_MUTE_ALL_ITEMS_SLOT_16"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn33.onClick = function()reaper.Main_OnCommand(40717,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn34.onClick = function()reaper.Main_OnCommand(40421,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn35.onClick = function()reaper.Main_OnCommand(40718,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn36.onClick = function()reaper.Main_OnCommand(40289,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn37.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_RS1bd2b238e9d479aa5810c8e7acfc9a16a9c83f75"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn38.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_RS268441f85b4a49000f857fd18eeb91fa337bea59"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn39.onClick = function()reaper.Main_OnCommand(40006,0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),0)end
btn40.onClick = function()reaper.Main_OnCommand(reaper.NamedCommandLookup("_RSce98886369682a42fdce6be0b98f4ebf69a97b0f"),0)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_ARRANGE_WND"),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 = "mute_state_items", 75,770, 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()