-- Script by Stepan Hlavsa -- hlavsa@seznam.cz -- Window starting position, width and height x = 100 y = 100 w = 1500 h = 550 -- Font size of text fsize=200 -- Size of play triangle and stop rectangle psize=100 -- Size of rectangle showing progress in the middle of the window rsize=200 -- IDs and titles of actions for 6 regions actionArr = {} aTitleArr = {} actionArr[1]=40862 aTitleArr[1]="Previous tab" actionArr[2]=40044 aTitleArr[2]="Play / stop" actionArr[3]=40861 aTitleArr[3]="Next tab" actionArr[4]="_RS0937555a0d9c32d360a48bacacebf92543d3f25b" aTitleArr[4]="Close window" actionArr[5]=40044 aTitleArr[5]="---" actionArr[6]=40042 aTitleArr[6]="Home" -- Should the window give the focus back to track view after start? -- If "true", the window will lost focus after start so you can continue -- using track view hot keys for example. If "false" the window will -- keep focus after start. focusOff=true ------------------------------------------------------------------------------------- local function rgb2num(red, green, blue) green = green * 256 blue = blue * 256 * 256 return red + green + blue end local function num2rgb(RGB) local R = RGB & 255 local G = (RGB >> 8) & 255 local B = (RGB >> 16) & 255 R = R/255 G = G/255 B = B/255 return R,G,B end local function TextOut(txt,color,alpha,idx,size) local __,x,y,w,h = gfx.dock(-1,0,0,0,0) gfx.setfont(1, "Arial", fsize*size) local str_w, str_h = gfx.measurestr(txt) local r,g,b = num2rgb(color) gfx.set(r,g,b,alpha) gfx.x = ((gfx.w - str_w) / 2) gfx.y = ((gfx.h - (str_h*3)) / 2)+(str_h*idx) gfx.drawstr(txt) end local function RectOut(Recpos,Reccolor) local Ry = gfx.h/2-(rsize/2) local r,g,b = num2rgb(Reccolor) gfx.set(r,g,b) gfx.rect(0,Ry,gfx.w*Recpos,rsize,1) end local function GetRgnName(regionidx) local retval, isrgn, pos, rgnend, name, markrgnindexnumber, color = reaper.EnumProjectMarkers3(nil, regionidx) return name,color,pos,rgnend end local function GetCurRegion(position) local markeridx, regionidx = reaper.GetLastMarkerAndCurRegion(nil,position) return regionidx end local function GetNextRegion(position) local markeridx, regionidx = reaper.GetLastMarkerAndCurRegion(nil,position) local retval, isrgn, pos, rgnend, name, markrgnindexnumber, color = reaper.EnumProjectMarkers3(nil, regionidx) local markeridx, nregionidx = reaper.GetLastMarkerAndCurRegion(nil,rgnend) return nregionidx end local function WriteText() local Apos if reaper.GetPlayState() == 2 then Apos = reaper.GetCursorPosition() else Apos = reaper.GetPlayPosition() end local RgnIdx1 = GetCurRegion(Apos) local name1, color1,pos1,rgnend1 = GetRgnName(RgnIdx1) local RgnIdx2 = GetNextRegion(Apos) local name2, color2,pos2,rgnend2 = GetRgnName(RgnIdx2) if name1=="" then local ret,filename=reaper.EnumProjects(-1, "") name1=string.match(filename, "([^\\]-)$") end -- Background gfx.clear = color1 -- 3 lines to divide 6 regions gfx.set(1,1,1,0.8) gfx.line(gfx.w/3,0,gfx.w/3,gfx.h) gfx.line(gfx.w/3*2,0,gfx.w/3*2,gfx.h) gfx.line(0,gfx.h/2,gfx.w,gfx.h/2) gfx.setfont(1, "Arial", 20) local i local j -- 6 titles for 6 regions for j=1,2 do for i=1,3 do gfx.x=gfx.w/3*i-gfx.w/6 gfx.y=gfx.h/2+j*20-40 gfx.drawstr(aTitleArr[(j-1)*3+i]) end end -- Progress barr local rpos = (Apos-pos1)/(rgnend1-pos1) if color2==color1 then RectOut(rpos,(256*256*256)-1-color2) else RectOut(rpos,color2) end -- Region names TextOut(name1,(256*256*256)-1-color1,1,0,1) TextOut(">>"..name2,(256*256*256)-1-color1,rpos,2,0.8) -- Play stop sign gfx.set(255,0,0) if reaper.GetPlayState() == 1 then gfx.triangle(10,10,10+psize,10+(psize/2),10,10+psize) elseif reaper.GetPlayState() == 0 then gfx.rect(10,10,psize,psize) elseif reaper.GetPlayState() == 2 then gfx.rect(10,10,psize/4,psize) gfx.rect(10+psize/4*2,10,psize/4,psize) elseif reaper.GetPlayState() == 5 then gfx.circle(30,30,20,1) end end -- Are these coordinates inside the given area? local function IsInside(ix, iy, iw, ih) local mouse_x, mouse_y = gfx.mouse_x, gfx.mouse_y local inside = mouse_x >= ix and mouse_x < (ix + iw) and mouse_y >= iy and mouse_y < (iy + ih) return inside end local function CallAction(aID) if type(aID)=='number' then reaper.Main_OnCommand(aID,0) else reaper.Main_OnCommand(reaper.NamedCommandLookup(aID),0) end end local function Main() local char = gfx.getchar() if char ~= 27 and char ~= -1 and char ~= 48 then reaper.defer(Main) end gfx.update() WriteText() -- If the left button is down if gfx.mouse_cap & 1 == 1 then -- If the cursor is inside the rectangle AND the button wasn't down before if not mouse_btn_down then if IsInside(0, 0,gfx.w/3, gfx.h/2) then CallAction(actionArr[1]) elseif IsInside(gfx.w/3, 0, gfx.w/3, gfx.h/2) then CallAction(actionArr[2]) elseif IsInside(gfx.w/3*2, 0, gfx.w/3, gfx.h/2) then CallAction(actionArr[3]) elseif IsInside(0, gfx.h/2, gfx.w/3, gfx.h) then CallAction(actionArr[4]) elseif IsInside(gfx.w/3, gfx.h/2, gfx.w/3, gfx.h) then CallAction(actionArr[5]) elseif IsInside(gfx.w/3*2, gfx.h/2, gfx.w/3, gfx.h) then CallAction(actionArr[6]) end mouse_btn_down = true end -- If the left button is up else mouse_btn_down = false end end mouse_btn_down=false gfx.init("Region names", w, h, 0, x, y) if focusOff then reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_TRACKS"),0) end Main()