Skip to content

Commit

Permalink
Merge pull request #1 from Zly-u/ItemsEditing/ExtendStretchToNextItem
Browse files Browse the repository at this point in the history
Refactoring of the `Items Editing` scripts
  • Loading branch information
Zly-u authored Feb 11, 2024
2 parents dc11d18 + 4cae84b commit c38f513
Show file tree
Hide file tree
Showing 6 changed files with 418 additions and 28 deletions.
15 changes: 3 additions & 12 deletions Items Editing/ExtendToNextItem/Zly_ExtendToNextItem.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
--[[
@description Extend To Next Item
@author Zly
@version 1.0
@provides
[main] .
@about
# Extend To Next Item
- Extends selected Items to next adjacent item.
@changelog
- Init
--]]
@noindex
]]--


function main()
local item_count = reaper.CountSelectedMediaItems()
Expand Down
15 changes: 3 additions & 12 deletions Items Editing/StretchToNextItem/Zly_StretchToNextItem.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
--[[
@description Stretch To Next Item
@author Zly
@version 1.0
@provides
[main] .
@about
# Stretch To Next Item
- Stretches selected Items to next adjacent item.
@changelog
- Init
--]]
@noindex
]]--


_G._print = print
_G.print = function(...)
Expand Down
14 changes: 14 additions & 0 deletions Items Editing/meta_ExtendToNextItem.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--[[
@metapackage
@description Extend To Next Item
@author Zly
@version 1.0
@provides
[main] .\ExtendToNextItem\Zly_ExtendToNextItem.lua
@about
# Extend To Next Item
- Extends selected Items to next adjacent item.
@changelog
- Init
--]]
14 changes: 14 additions & 0 deletions Items Editing/meta_StretchToNextItem.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--[[
@metapackage
@description Stretch To Next Item
@author Zly
@version 1.0
@provides
[main] .\StretchToNextItem\Zly_StretchToNextItem.lua
@about
# Stretch To Next Item
- Stretches selected Items to next adjacent item.
@changelog
- Init
--]]
300 changes: 300 additions & 0 deletions Video/VideoAutoFlipper/VAF_GUI.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,308 @@
-- @noindex

-- Loading Lokasenna_GUI

local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not reaper.file_exists(lib_path .. "Core.lua") or not lib_path or lib_path == "" then
local description =
[[
Couldn't load Lokasenna_GUI library.
1) Please install 'Lokasenna's GUI library v2 for Lua' via ReaPack
2) Then run the 'Set Lokasenna_GUI v2 library path.lua' script in the Action List
]]
reaper.MB(description, "Error", 0)
local gui = {
error = "NoLib"
}
return gui
end
loadfile(lib_path .. "Core.lua")() do
GUI.req("Classes/Class - Label.lua")()
GUI.req("Classes/Class - Knob.lua")()
GUI.req("Classes/Class - Tabs.lua")()
GUI.req("Classes/Class - Slider.lua")()
GUI.req("Classes/Class - Button.lua")()
GUI.req("Classes/Class - Menubox.lua")()
GUI.req("Classes/Class - Textbox.lua")()
GUI.req("Classes/Class - Frame.lua")()
GUI.req("Classes/Class - Options.lua")()
GUI.req("Classes/Class - Window.lua")()
end
if missing_lib then return nil end


--[[===================================]]--
--[[===================================]]--
--[[===================================]]--


------------------------------------
-------- Functions -----------------
------------------------------------


local function fade_lbl()
-- Fade out the label
if GUI.elms.my_lbl.z == 3 then
GUI.elms.my_lbl:fade(1, 3, 6)
-- Bring it back
else
GUI.elms.my_lbl:fade(1, 3, 6, -3)
end
end


local function btn_click()
-- Open the Window element
GUI.elms.wnd_test:open()
end


local function wnd_OK()
-- Close the Window element
GUI.elms.wnd_test:close()
end


-- Returns a list of every element on the specified z-layer and
-- a second list of each element's values
local function get_values_for_tab(tab_num)

-- The '+ 2' here is just to translate from a tab number to its'
-- associated z layer. More complicated scripts would have to
-- actually access GUI.elms.tabs.z_sets[tab_num] and iterate over
-- the table's contents (see the call to GUI.elms.tabs:update_sets
-- below)
local strs_v, strs_val = {}, {}
for _, tab in pairs(GUI.elms_list[tab_num + 2]) do

strs_v[#strs_v + 1] = tab
local val = GUI.Val(tab)
if type(val) == "table" then
local strs = {}
for _, value in pairs(val) do
local str = tostring(value)

-- For conciseness, reduce boolean values to T/F
str = str and "T" or "F"
strs[#strs + 1] = str
end
val = table.concat(strs, ", ")
end

-- Limit the length of the returned string so it doesn't
-- spill out past the edge of the window
strs_val[#strs_val + 1] = string.len(tostring(val)) <= 35
and tostring(val)
or string.sub(val, 1, 32) .. "..."

end

return strs_v, strs_val
end


--[[===================================]]--
--[[===================================]]--
--[[===================================]]--

--local core = require("VAF_CORE")
local gui = {}

function gui:Init()
GUI.name = "Video Auto-Flipper"

GUI.x = 0
GUI.y = 0
GUI.w = 432
GUI.h = 500
GUI.anchor = "mouse"
GUI.corner = "C"


--[[
Button z, x, y, w, h, caption, func[, ...]
Checklist z, x, y, w, h, caption, opts[, dir, pad]
Frame z, x, y, w, h[, shadow, fill, color, round]
Knob z, x, y, w, caption, min, max, default[, inc, vals]
Label z, x, y, caption[, shadow, font, color, bg]
Menubox z, x, y, w, h, caption, opts
Radio z, x, y, w, h, caption, opts[, dir, pad]
Slider z, x, y, w, caption, min, max, defaults[, inc, dir]
Tabs z, x, y, tab_w, tab_h, opts[, pad]
Textbox z, x, y, w, h[, caption, pad]
Window z, x, y, w, h, caption, z_set[, center]
]]--


-- Elements can be created in any order you want. I find it easiest to organize them
-- by tab, or by what part of the script they're involved in.
end

function gui:Main()
-- Prevent the user from resizing the window
if GUI.resized then

-- If the window's size has been changed, reopen it
-- at the current position with the size we specified
local _, x, y, w, h = gfx.dock(-1,0,0,0,0)
gfx.quit()
gfx.init(GUI.name, GUI.w, GUI.h, 0, x, y)

GUI.redraw_z[0] = true
end
end

function gui:Setup()
------------------------------------
-------- General elements ----------
------------------------------------
do
GUI.New("tabs", "Tabs", 1, 0, 0, 64, 20, "Stuff, Sliders, Options", 16)
GUI.New("tab_bg", "Frame", 2, 0, 0, 448, 20, false, true, "elm_bg", 0)
GUI.New("my_btn", "Button", 1, 168, 28, 96, 20, "Go!", btn_click)
GUI.New("btn_frm", "Frame", 1, 0, 56, GUI.w, 4, true, true)

-- Telling the tabs which z layers to display
-- See Classes/Tabs.lua for more detail
GUI.elms.tabs:update_sets(
-- Tab
-- Layers
{ [1] = {3},
[2] = {4},
[3] = {5},
}
)

-- Notice that layers 1 and 2 aren't assigned to a tab; this leaves them visible
-- all the time.
end
------------------------------------
-------- Tab 1 Elements ------------
------------------------------------
do
GUI.New("my_lbl", "Label", 3, 256, 96, "Label!", true, 1)
GUI.New("my_knob", "Knob", 3, 64, 112, 48, "Volume", 0, 11, 44, 0.25)
GUI.New("my_mnu", "Menubox", 3, 256, 176, 64, 20, "Options:", "1,2,3,4,5,6.12435213613")
GUI.New("my_btn2", "Button", 3, 256, 256, 64, 20, "Click me!", fade_lbl)
GUI.New("my_txt", "Textbox", 3, 96, 224, 96, 20, "Text:", 4)
GUI.New("my_frm", "Frame", 3, 16, 288, 192, 128, true, false, "elm_frame", 4)


-- We have too many values to be legible if we draw them all; we'll disable them, and
-- have the knob's caption update itself to show the value instead.
GUI.elms.my_knob.vals = false
function GUI.elms.my_knob:redraw()
GUI.Knob.redraw(self)
self.caption = self.retval .. "dB"
end

-- Make sure it shows the value right away
GUI.elms.my_knob:redraw()


GUI.Val(
"my_frm",
"this is a really long string of text with no carriage returns so hopefully "..
"it will be wrapped correctly to fit inside this frame"
)
GUI.elms.my_frm.bg = "elm_bg"
end
------------------------------------
-------- Tab 2 Elements ------------
------------------------------------
do
GUI.New("my_rng", "Slider", 4, 32, 128, 256, "Sliders", 0, 30, {5, 10, 15, 20, 25})
GUI.New("my_pan", "Slider", 4, 32, 192, 256, "Pan", -100, 100, 100)
GUI.New("my_sldr", "Slider", 4, 128, 256, 128, "Slider", 0, 10, 20, 0.25, "v")
GUI.New("my_rng2", "Slider", 4, 352, 96, 256, "Vertical?", 0, 30, {5, 10, 15, 20, 25}, nil, "v")

-- Using a function to change the value label depending on the value
GUI.elms.my_pan.output = function(val)
val = tonumber(val)
return val == 0
and "0"
or string.format("%d%s", math.abs(val), (val < 0 and "L" or "R"))
end
end
------------------------------------
-------- Tab 3 Elements ------------
------------------------------------
do
GUI.New("my_chk", "Checklist", 5, 32, 96, 160, 160, "Checklist:", "Alice,Bob,Charlie,Denise,Edward,Francine", "v", 4)
GUI.New("my_opt", "Radio", 5, 200, 96, 160, 160, "Options:", "Apples,Bananas,_,Donuts,Eggplant", "v", 4)
GUI.New("my_chk2", "Checklist", 5, 32, 280, 384, 64, "Whoa, another Checklist", "A,B,C,_,D,E,F,_,G,H,I", "h", 4)
GUI.New("my_opt2", "Radio", 5, 32, 364, 384, 64, "Horizontal options", "A,A#,B,C,C#,D,D#,E,F,F#,G,G#", "h", 4)

GUI.elms.my_opt.swap = true
GUI.elms.my_chk2.swap = true
end
------------------------------------
-------- Subwindow and -------------
-------- its elements -------------
------------------------------------
do
GUI.New("wnd_test", "Window", 10, 0, 0, 312, 244, "Dialog Box", {9, 10})
GUI.New("lbl_elms", "Label", 9, 16, 16, "", false, 4)
GUI.New("lbl_vals", "Label", 9, 96, 16, "", false, 4, nil, elm_bg)
GUI.New("btn_close", "Button", 9, 0, 184, 48, 24, "OK", wnd_OK)

-- We want these elements out of the way until the window is opened
GUI.elms_hide[9] = true
GUI.elms_hide[10] = true

-- :onopen is a hook provided by the Window class. This function will be run
-- every time the window opens.
function GUI.elms.wnd_test:onopen()

-- :adjustelm places the element's specified x,y coordinates relative to
-- the Window. i.e. creating an element at 0,0 and adjusting it will put
-- the element in the Window's top-left corner.
self:adjustelm(GUI.elms.btn_close)

-- Buttons look nice when they're centered.
GUI.elms.btn_close.x, _ = GUI.center(GUI.elms.btn_close, self)

self:adjustelm(GUI.elms.lbl_elms)
self:adjustelm(GUI.elms.lbl_vals)

-- Set the Window's title
local tab_num = GUI.Val("tabs")
self.caption = "Element values for Tab " .. tab_num

-- This Window provides a readout of the values for every element
-- on the current tab.
local strs_v, strs_val = get_values_for_tab(tab_num)

GUI.Val("lbl_elms", table.concat(strs_v, "\n"))
GUI.Val("lbl_vals", table.concat(strs_val, "\n"))

end
end

--[[==================================================]]--
--[[==================================================]]--
--[[==================================================]]--

-- Open the script window and initialize a few things
GUI.Init()

-- Tell the GUI library to run Main on each update loop
-- Individual elements are updated first, then GUI.func is run, then the GUI is redrawn
GUI.func = self.Main

-- How often (in seconds) to run GUI.func. 0 = every loop.
GUI.freq = 0.016

-- Start the main loop
GUI.Main()
end

function gui:StartGUI()
gui:Init()
gui:Setup()
end

return gui
Loading

0 comments on commit c38f513

Please sign in to comment.