|
|
|
03-18-2021, 03:12 PM
|
#841
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
Maybe add a variable to the pos and size ?
Code:
GUI.New("key_chord1", "Button", 3, 16+a, 55+b, 70+c, 20+d, chord[1], btn_click_chord1)
and leave the elements starting on the left at there current horizontal pos ???
you would need to use ondelete & init and put all your elements in a function
Code:
function resize_gui(a,b,c,d)
GUI.elms.countin_btn:ondelete()
GUI.New("countin_btn", "Button", 1, 10+a, 162+b, 64+c, 34+d, "Count-in", countin_btn_click)
GUI.elms.countin_btn.col_txt = "red"
GUI.elms.countin_btn.col_fill = "blue"
GUI.elms.countin_btn:init()
...
...
end
or maybe just use one var "a" that adds or subtracts 1 from it's value if it's zooming both horizontally and vertically ?
|
|
|
03-18-2021, 06:01 PM
|
#842
|
Human being with feelings
Join Date: May 2020
Posts: 190
|
I managed to get something that *kind of* scales the elements. I'm having some buffer issues that crash the window if you adjust it for too long though, and it doesn't seem to be scaling everything exactly how I would like it to (mainly a frame on my window that doesn't seem to be scaling as much as everything else).
Apologies for some of the messy code, though, since it is still a work in progress and I haven't simplified everything yet.
Code:
--scales all of the GUI elements to the new width and height of the window
function GUI.AutoResize()
for key, value in pairs(GUI.elms) do
if value.type == "Tabs" then
if not value.w_scale then GUI.elms[key].w_scale = value.tab_w/GUI.w end
if not value.h_scale then GUI.elms[key].h_scale = value.tab_h/GUI.h end
if not value.w_lock then GUI.elms[key].tab_w = GUI.round(GUI.cur_w*GUI.elms[key].w_scale, 0) end
if not value.h_lock then GUI.elms[key].tab_h = GUI.round(GUI.cur_h*GUI.elms[key].h_scale, 0) end
else
if not value.w_scale then GUI.elms[key].w_scale = value.w/GUI.w end
if not value.h_scale then GUI.elms[key].h_scale = value.h/GUI.h end
if not value.w_lock then GUI.elms[key].w = GUI.round(GUI.cur_w*GUI.elms[key].w_scale, 0) end
if not value.h_lock then GUI.elms[key].h = GUI.round(GUI.cur_h*GUI.elms[key].h_scale, 0) end
end
if not value.x_scale then GUI.elms[key].x_scale = value.x/GUI.w end
if not value.y_scale then GUI.elms[key].y_scale = value.y/GUI.h end
if not value.x_lock then GUI.elms[key].x = GUI.round(GUI.cur_w*GUI.elms[key].x_scale, 0) end
if not value.y_lock then GUI.elms[key].y = GUI.round(GUI.cur_h*GUI.elms[key].y_scale, 0) end
if value.char_w and value.char_h then
if not value.char_w_scale then GUI.elms[key].char_w_scale = value.char_w/value.w end
if not value.char_h_scale then GUI.elms[key].char_h_scale = value.char_h/value.h end
if not value.w_lock and value.char_w then GUI.elms[key].char_w = GUI.round(GUI.elms[key].w*GUI.elms[key].char_w_scale, 0) end
if not value.h_lock and value.char_h then GUI.elms[key].char_h = GUI.round(GUI.elms[key].h*GUI.elms[key].char_h_scale, 0) end
end
GUI.elms[key]:init()
end
GUI.redraw_z[0] = true
end
And I implemented some of this into the Core.lua GUI.Main_Update_State function in order to call it:
Code:
if GUI.cur_w ~= gfx.w or GUI.cur_h ~= gfx.h then
GUI.cur_w, GUI.cur_h = gfx.w, gfx.h
if GUI.is_auto_resize and (GUI.cur_w >= GUI.w and GUI.cur_h >= GUI.h) then
local new_time = reaper.time_precise()
if new_time - GUI.last_resize >= 0.05 then
GUI.AutoResize()
GUI.last_resize = new_time
end
end
GUI.resized = true
-- Hook for user code
if GUI.onresize then GUI.onresize() end
else
GUI.resized = false
end
|
|
|
03-18-2021, 08:58 PM
|
#843
|
Human being with feelings
Join Date: Sep 2014
Posts: 2,643
|
I had a go at it.
It could maybe change the text size if a > x
Or to resize the GUI also:
|
|
|
03-22-2021, 09:52 AM
|
#844
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
Using Scythe v3
I am trying to get the label in the example code to be updated in realtime when the slider is changed and display the value. I am not quite sure why this isn't working as I am able to set default value and display that. Is there a redrawing function I am missing ?
Many thanks.
Code:
local libPath = reaper.GetExtState("Scythe v3", "libPath")
if not libPath or libPath == "" then
reaper.MB("Couldn't load the Scythe library. Please install 'Scythe library v3' from ReaPack, then run 'Script: Scythe_Set v3 library path.lua' in your Action List.", "Whoops!", 0)
return
end
loadfile(libPath .. "scythe.lua")()
local GUI = require("gui.core")
local Color = require("public.color")
local Slider = require("gui.elements.Slider")
local Label = require("gui.elements.Label")
------------------------------------
-------- Window settings -----------
------------------------------------
local window = GUI.createWindow({
name = "Default Parameters",
w = 400,
h = 220,
})
------------------------------------
-------- GUI Elements --------------
------------------------------------
local layer = GUI.createLayer({name = "Layer1"})
layer:addElements( GUI.createElements(
{
name = "MySlider",
type = "Slider",
x = 20,
y = 30,
w = 150,
min = -90,
max = 12,
inc = 0.01,
defaults = -60,
fillColor = Color.fromRgba({0,255,255}),
showValues = false,
horizontal = false,
},
{
name = "MyLabel",
type = "Label",
x = 200,
y = 150,
w = 96,
h = 20,
output = function(val)
val = GUI.Val("MySlider")
val = tonumber(val)
return (val)
end
}
))
window:addLayers(layer)
window:open()
GUI.Main()
|
|
|
03-22-2021, 10:25 AM
|
#845
|
Human being with feelings
Join Date: May 2020
Posts: 190
|
Quote:
Originally Posted by MusoBob
It could maybe change the text size if a > x
|
I thought about that as well, but I haven't done anything with it since I am not sure how much to increase the font by each resize.
|
|
|
03-22-2021, 10:40 AM
|
#846
|
Human being with feelings
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
|
Quote:
Originally Posted by J Reverb
Using Scythe v3
I am trying to get the label in the example code to be updated in realtime when the slider is changed and display the value. I am not quite sure why this isn't working as I am able to set default value and display that. Is there a redrawing function I am missing ?
Many thanks.
Code:
local libPath = reaper.GetExtState("Scythe v3", "libPath")
if not libPath or libPath == "" then
reaper.MB("Couldn't load the Scythe library. Please install 'Scythe library v3' from ReaPack, then run 'Script: Scythe_Set v3 library path.lua' in your Action List.", "Whoops!", 0)
return
end
loadfile(libPath .. "scythe.lua")()
local GUI = require("gui.core")
local Color = require("public.color")
local Slider = require("gui.elements.Slider")
local Label = require("gui.elements.Label")
------------------------------------
-------- Window settings -----------
------------------------------------
local window = GUI.createWindow({
name = "Default Parameters",
w = 400,
h = 220,
})
------------------------------------
-------- GUI Elements --------------
------------------------------------
local layer = GUI.createLayer({name = "Layer1"})
layer:addElements( GUI.createElements(
{
name = "MySlider",
type = "Slider",
x = 20,
y = 30,
w = 150,
min = -90,
max = 12,
inc = 0.01,
defaults = -60,
fillColor = Color.fromRgba({0,255,255}),
showValues = false,
horizontal = false,
func = function(self)
label = getElementByName('MyLabel')
label:val(self:val()) --or label:setCaption(self:val())
end,
},
{
name = "MyLabel",
type = "Label",
x = 200,
y = 150,
w = 96,
h = 20,
output = function(val)
val = GUI.Val("MySlider")
val = tonumber(val)
return (val)
end
}
))
window:addLayers(layer)
window:open()
GUI.Main()
|
I think you need to put a line of code setting a value for 'func' in the constructor for the slider. You want something to happen when the SLIDER value changes. See edit above:
func = function(self)
label = getElementByName('MyLabel') --something like this, anyway....
label:val(self:val()) --or label:setCaption(self:val())
end,
I always set my elements to a variable when I create them, but there is a get element by name function, I believe--it's in one of the example scripts. (I've created all my own elements, so I'm not positive how the basic ones work....)
Hope this helps.
-e
Last edited by woodslanding; 03-22-2021 at 10:45 AM.
Reason: need colons on the method calls. Always forget this if I don't have syntax coloring!!
|
|
|
03-22-2021, 10:56 AM
|
#847
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Is there a specific reason why you want to use a dedicated label. Or is using the built-in value display of the Slider class also an option?
Code:
local libPath = reaper.GetExtState("Scythe v3", "libPath")
if not libPath or libPath == "" then
reaper.MB("Couldn't load the Scythe library. Please install 'Scythe library v3' from ReaPack, then run 'Script: Scythe_Set v3 library path.lua' in your Action List.", "Whoops!", 0)
return
end
loadfile(libPath .. "scythe.lua")()
local GUI = require("gui.core")
local Color = require("public.color")
local Slider = require("gui.elements.Slider")
local Label = require("gui.elements.Label")
local window = GUI.createWindow({
name = "Default Parameters",
w = 400,
h = 220,
})
local layer = GUI.createLayer({name = "Layer1"})
layer:addElements( GUI.createElements(
{
name = "MySlider",
type = "Slider",
x = 20,
y = 30,
w = 150,
min = -90,
max = 12,
inc = 0.01,
defaults = -60,
fillColor = Color.fromRgba({0,255,255}),
showValues = true,
horizontal = false,
output = "%val%"
}
))
window:addLayers(layer)
window:open()
GUI.Main()
|
|
|
03-22-2021, 11:30 AM
|
#848
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@woodslanding
Thanks for the help with getElementByName I had sort of tried this.
I still can't get it to change in realtime. Is there some sort of updating that needs to be done with label ?
@solger
Yes I want to be able to display the value elsewhere other than the default location so any pointers would be great.
Thanks.
|
|
|
03-22-2021, 11:37 AM
|
#849
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
OK, I think I found it
There are afterDrag, afterWheel and afterMouseDown user function hooks for mouse drag, mouse wheel and left click on a Slider:
Code:
local libPath = reaper.GetExtState("Scythe v3", "libPath")
if not libPath or libPath == "" then
reaper.MB("Couldn't load the Scythe library. Please install 'Scythe library v3' from ReaPack, then run 'Script: Scythe_Set v3 library path.lua' in your Action List.", "Whoops!", 0)
return
end
loadfile(libPath .. "scythe.lua")()
local GUI = require("gui.core")
local Color = require("public.color")
local Slider = require("gui.elements.Slider")
local Label = require("gui.elements.Label")
local window = GUI.createWindow({
name = "Default Parameters",
w = 400,
h = 220,
})
local layer = GUI.createLayer({name = "Layer1"})
layer:addElements( GUI.createElements(
{
name = "MySlider",
type = "Slider",
x = 20,
y = 30,
w = 150,
min = -90,
max = 12,
inc = 0.01,
defaults = -60,
fillColor = Color.fromRgba({0,255,255}),
showValues = false,
horizontal = false,
afterDrag = function(self)
GUI.Val("MyLabel", self:val())
end,
afterWheel = function(self)
GUI.Val("MyLabel", self:val())
end,
afterMouseDown = function(self)
GUI.Val("MyLabel", self:val())
end
},
{
name = "MyLabel",
type = "Label",
x = 200,
y = 150,
w = 96,
h = 20
}
))
window:addLayers(layer)
window:open()
GUI.Main()
Last edited by solger; 03-22-2021 at 11:56 AM.
Reason: code update
|
|
|
03-22-2021, 12:05 PM
|
#850
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@solger
Ah.... awesome ! I would have never have found those
Where did you find them ?
That's nailed it ! Thanks very much.
|
|
|
03-22-2021, 12:11 PM
|
#851
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Quote:
Originally Posted by J Reverb
@solger
Ah.... awesome ! I would have never have found those
Where did you find them ?
|
Mainly from looking at the code files of the core library (..\Scythe library v3\library) and of the developer tools (..\Scythe library v3\development).
As example, in the user-event-hooks.lua file in the 'development/gui-testing' subfolder, there's a general listing of user events that can be used as before or after hooks.
And, as far as I know, available user hooks can vary depending on the element class (Slider, Button, etc).
Here's another example for the Menubox (which I couldn't find earlier): https://forum.cockos.com/showpost.ph...&postcount=732
Quote:
That's nailed it ! Thanks very much.
|
You're welcome!
Last edited by solger; 03-22-2021 at 12:40 PM.
|
|
|
03-22-2021, 01:17 PM
|
#852
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@solger
Quote:
As example, in the user-event-hooks.lua file in the 'development/gui-testing' subfolder, there's a general listing of user events that can be used as before or after hooks.
And, as far as I know, available user hooks can vary depending on the element class (Slider, Button, etc).
|
Thanks for pointing this out, very helpful
I am getting some un truncated and non rounded numbers being produced when using ctrl+wheel on the slider ( 0.9999999 ) instead of 0.1 is this hard coded in the library ? Maybe a forsight not sure if it's fixable this side ?
This doesn't happen with ctrl+drag.
Ah maybe something to do with internal values ?
Thanks.
Last edited by J Reverb; 03-22-2021 at 01:23 PM.
|
|
|
03-22-2021, 02:44 PM
|
#853
|
Human being with feelings
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
|
If you look in lokasenna's utilities, you'll find methods for rounding.
It may well be a bug. The only real bug I've found so far was color values not being truncated to integers....
|
|
|
03-23-2021, 01:57 PM
|
#854
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@woodslanding
Thanks will look into that nice one
|
|
|
03-26-2021, 11:02 AM
|
#855
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
Hi All,
I am trying to get the value of MySlider to update the volume on first track.
What am I doing wrong ?
Thanks v much.
Code..
Code:
function test()
newval = GUI.Val("MySlider")
tr = reaper.GetTrack(0, 0)
reaper.SetMediaTrackInfo_Value(tr, "D_VOL" , newval)
end
|
|
|
03-26-2021, 11:12 AM
|
#856
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Quote:
Originally Posted by J Reverb
Hi All,
I am trying to get the value of MySlider to update the volume on first track.
What am I doing wrong ?
Thanks v much.
Code..
Code:
function test()
newval = GUI.Val("MySlider")
tr = reaper.GetTrack(0, 0)
reaper.SetMediaTrackInfo_Value(tr, "D_VOL" , newval)
end
|
Seems to work here.
Where are you calling the test function?
Or in other words: how does the rest of the code look like currently?
|
|
|
03-26-2021, 11:28 AM
|
#857
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@solger
Thanks for your help.
Ah I must be putting it in the wrong place.. er.. or not calling it properly
Code:
local libPath = reaper.GetExtState("Scythe v3", "libPath")
if not libPath or libPath == "" then
reaper.MB("Couldn't load the Scythe library. Please install 'Scythe library v3' from ReaPack, then run 'Script: Scythe_Set v3 library path.lua' in your Action List.", "Whoops!", 0)
return
end
loadfile(libPath .. "scythe.lua")()
local GUI = require("gui.core")
local Color = require("public.color")
local Slider = require("gui.elements.Slider")
local Label = require("gui.elements.Label")
function test()
newval = GUI.Val("MySlider")
tr = reaper.GetTrack( 0, 0)
reaper.SetMediaTrackInfo_Value( tr, "D_VOL" ,newval)
end
local window = GUI.createWindow({
name = "Default Parameters",
w = 400,
h = 220,
})
local layer = GUI.createLayer({name = "Layer1"})
layer:addElements( GUI.createElements(
{
name = "MySlider",
type = "Slider",
x = 20,
y = 30,
w = 150,
min = -90,
max = 12,
inc = 0.1,
defaults = -20,
fillColor = Color.fromRgba({0,255,255}),
showValues = false,
horizontal = false,
afterDrag = function(self)
GUI.Val("MyLabel", (self:val()))
end,
afterWheel = function(self)
GUI.Val("MyLabel",(self:val()))
end,
afterMouseDown = function(self)
GUI.Val("MyLabel", (self:val()))
end,
func = test,
},
{
name = "MyLabel",
type = "Label",
x = 200,
y = 180,
w = 1,
h = 10,
}
))
window:addLayers(layer)
window:open()
test()
GUI.Main()
|
|
|
03-26-2021, 11:39 AM
|
#858
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Quote:
Originally Posted by J Reverb
@solger
Thanks for your help.
Ah I must be putting it in the wrong place.. er.. or not calling it properly
|
Yeah, you'll need to call it in the event hooks:
Code:
...
afterDrag = function(self)
GUI.Val("MyLabel", (self:val()))
test()
end,
afterWheel = function(self)
GUI.Val("MyLabel",(self:val()))
test()
end,
afterMouseDown = function(self)
GUI.Val("MyLabel", (self:val()))
test()
end
...
Side note: in case I haven't overlooked something: the func and rightFunc event hooks for left and right click are mainly available in the Button class.
Last edited by solger; 03-26-2021 at 11:44 AM.
|
|
|
03-26-2021, 11:44 AM
|
#859
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@solger
Yes what a donut !
Thanks for that
Also from your side note that's correct I have stray code in there, splendid TA !
|
|
|
04-12-2021, 08:54 AM
|
#860
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
Hi all,
Couple of questions
Is there a best practice for creating a row of buttons ?
I would like to have a different function on each button which I have but at the moment I have to create each one individually like so .. and the code gets long and I'm looking at creating quite a few of them.
Code:
local layer = GUI.createLayer({name = "Layer1"})
layer:addElements( GUI.createElements(
{
name = "1",
type = "Button",
x = 8,
y = 10,
w = 60,
h = 30,
caption = "b1",
func = func1,
},
{
name = "2",
type = "Button",
x = 8,
y = 90,
w = 60,
h = 30,
caption = "b2",
func = func2,
},
etc. etc.
Also second question,
Is there a way to change the color of the last clicked button ? So I know that is the current function ?
Thanks v much
|
|
|
04-12-2021, 11:32 AM
|
#861
|
Human being with feelings
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
|
There are a lot of ways to do that. I created a grid layout method for a bunch of identically sized elements:
Code:
function GetLayoutXandY(i,x,y,w,h,rows)
----MSG("layout: x = "..x)
local xadj = math.floor((i - 1)/rows)
local yadj = (i-1) % rows
local xpos = x + (xadj * w)
local ypos = y + (yadj * h)
return xpos,ypos
end
then I have a method like this:
Code:
mybuttons = {
x = 0, y = 0, w = 96, h = 36
}
for i,s in ipairs(mybuttons) do
local xpos, ypos = GetLayoutXandY(i,mybuttons.x,mybuttons.y, mybuttons.w,mybuttons.h, 1)
local button = GUI.createElement({
name = 'button'..i,
x = xpos,
y = ypos,
--etc.
})
myLayer:addElements(button)
end
Hope this helps.
|
|
|
04-12-2021, 02:45 PM
|
#862
|
Human being with feelings
Join Date: Jul 2009
Posts: 1,071
|
@woodslanding
Yeah that looks like the sort of thing I might need I was sure there had to be a way of drawing stuff automatically, I am using scythe v3 and can't seem to get your code working though. How would this integrate into the basic framework ?
Cheers for your help.
|
|
|
04-13-2021, 07:16 AM
|
#863
|
Human being with feelings
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
|
that's kind of pseudo-code, yeah. I'm sure it won't work as is... it's just to give you the idea.
Read up on lua tables, and study the methods he uses to create the various widgets himself, you'll see how the constructors are just tables. Once you learn to create and alter tables various ways, it will all fall into place.
|
|
|
04-23-2021, 07:16 PM
|
#864
|
Human being with feelings
Join Date: Aug 2016
Posts: 232
|
I am having a little bit of difficulty with a radio box in Scythe 3. I have everything laid out perfectly. All of the form elements appear to function.Text boxes transmit the changed values in my submit function. But when I submit the form, the radio box value always shows as "1" rather than the index. Is there a function i need to call when the user changes the radio box value? Currently I am trying to pull the value in this way:
Code:
GUI.findElementByName("myRadioOptionChoice"):val()
Thanks in advance!
UPDATE: I figured it out. You have to loop through the options by using a statement such as:
Code:
if self:isOptionSelected(i) == true then
More specifically, you can place this in the radio element:
Code:
afterMouseDown = function(self)
for i=1, 50 do
if self:isOptionSelected(i) == true then
reaper.ShowConsoleMsg("Is Selected: "..i.."\n")
else
reaper.ShowConsoleMsg("Not Selected: "..i.."\n")
end
end
end
Last edited by storyteller; 04-23-2021 at 08:51 PM.
|
|
|
05-02-2021, 10:16 PM
|
#865
|
Human being with feelings
Join Date: Aug 2016
Posts: 232
|
I’ve been trying to troubleshoot another bug I have in Scythe 3... hoping someone might have some insight. I have a 3 tab layout. I have a case statement in the main() that determines which tab to default to at the start. This is where it gets a little nutty, I have one main button on tab 2 in the middle of the page. Sometimes it works, sometimes it doesn’t. Closing the window and reopening it will generally resolve the issue within 2-3 reloads. Sometimes it loads properly from the start. I’ve changed the main() refresh time, replaced functions to only run once rather than looped. It’s always the same. Any thoughts? SOS.
Also... another issue I’ve discovered is that updating the textinputs with values causes the cursor to not function correctly in the focus. The values are shoved off screen as well rather than left aligned in he textinput box. Is there a fix for this? Or a best practice for setting textinput values. I’ve had to resort to running the function before the GUI build to set the default valances in the text boxes.
Thanks in advance!
UPDATE: I just rebuilt the thing in a completely different manner. I couldn't get around the bug. Basically I have to rebuild the entire UI via script depending on the circumstance.
Last edited by storyteller; 05-11-2021 at 11:10 PM.
|
|
|
05-11-2021, 11:08 PM
|
#866
|
Human being with feelings
Join Date: Aug 2016
Posts: 232
|
So I am just going to keep posting here in this thread I guess in hopes that someone... anyone... will contribute some guidance with Scythe 3. Ha. Lokasenna......? Are you around these days?
Current question: I have run out of available buffer slots. (yes, this is a VERY HEAVY GUI). I can see that in buffer.lua that the max buffers are 1023. When I double it, this opens up enough buffers... but the graphics futz out. Is the buffer hard-limited somewhere else, or was it set at 1023 to prevent the potential issues I am seeing? Is there somewhere else in the library that needs updated to allow for more buffers?
Thanks.
UPDATE: Seems like there is no way around the 1023 buffer limit.. and getting any responses in this thread is just listening to crickets... so the unfortunate workaround I decided to do was as follows: I decided to TAB the elements, then dynamically remove and rebuild the elements each time a user clicks a tab. This keeps the GUI beneath the buffer limit. But since everything is now dynamically being rebuilt, it did require a lot of new scripting, creating and saving states of the GUI, etc. Hope this helps someone in the future who might be dealing with a similar circumstance.
Last edited by storyteller; 05-13-2021 at 02:47 PM.
|
|
|
10-16-2021, 09:13 AM
|
#867
|
Human being with feelings
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
|
Scythe v3
Hi!
I can't get my buttons to give parameters with their func call... the value {1} is stored in the button.params (confirmed by my first Message Box), but then the second Message Box in the selectButton-function displays "Parameter that comes OUT (should be 1 but turns out to be nil): nil".
Anyone know why?
Micha
Code:
Buttons = {}
function makeButtons()
for i=1,15 do
Buttons[i] = {}
Buttons[i].col = ((i-1)%5)+1
Buttons[i].row = math.floor((i-1)/5)+1
Buttons[i].button = GUI.createElements({
name = "Button " .. i,
type = "Button",
x = 4 + (100 * (Buttons[i].col-1)),
y = 4 + (100 * (Buttons[i].row-1)),
w = 96, h = 96,
func = selectButton,
params = {1}
})
if i<2 then
reaper.ShowMessageBox("Parameter that goes IN (should be 1): " .. tostring(Buttons[i].button.params[1]), "Debug", 0)
end
end
end
function selectButton(stuff)
reaper.ShowMessageBox("Parameter that comes OUT (should be 1 but turns out to be nil): " .. tostring(stuff[1]), "Debug", 0)
end
Last edited by GameAudioRvlzzr; 10-16-2021 at 10:00 AM.
Reason: Clarity
|
|
|
10-16-2021, 10:10 AM
|
#868
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Quote:
Originally Posted by GameAudioRvlzzr
Scythe v3
Hi!
I can't get my buttons to give parameters with their func call... the value {1} is stored in the button.params (confirmed by my first Message Box), but then the second Message Box in the selectButton-function displays "Parameter that comes OUT (should be 1 but turns out to be nil): nil".
Anyone know why?
Micha
Code:
Buttons = {}
function makeButtons()
for i=1,15 do
Buttons[i] = {}
Buttons[i].col = ((i-1)%5)+1
Buttons[i].row = math.floor((i-1)/5)+1
Buttons[i].button = GUI.createElements({
name = "Button " .. i,
type = "Button",
x = 4 + (100 * (Buttons[i].col-1)),
y = 4 + (100 * (Buttons[i].row-1)),
w = 96, h = 96,
func = selectButton,
params = {1}
})
if i<2 then
reaper.ShowMessageBox("Parameter that goes IN (should be 1): " .. tostring(Buttons[i].button.params[1]), "Debug", 0)
end
end
end
function selectButton(stuff)
reaper.ShowMessageBox("Parameter that comes OUT (should be 1 but turns out to be nil): " .. tostring(stuff[1]), "Debug", 0)
end
|
In the first MessageBox, 'Buttons[i].button.params[1]' is accessed directly inside the for loop (after the value has been set):
Code:
if i<2 then
reaper.ShowMessageBox("Parameter that goes IN (should be 1): " .. tostring(Buttons[i].button.params[1]), "Debug", 0)
end
But there are currently no parameters passed to the selectButton function. Hence you get a 'nil' value when trying to access the 'stuff' parameter variable in the second MessageBox:
Code:
func = selectButton
One option to try is to pass the parameter directly to the function:
Code:
...
Buttons[i].button = GUI.createElements({
name = "Button " .. i,
type = "Button",
x = 4 + (100 * (Buttons[i].col-1)),
y = 4 + (100 * (Buttons[i].row-1)),
w = 96, h = 96,
func = selectButton({1})
})
...
Another example that might be helpful can be found in the Script: Scythe_Example - Working with Images.lua (that is part of the Scythe library v3 (developer tools) package in ReaPack):
Code:
local w, h = 31, 17
buttons = buttons:map(function(imagePath, idx)
return GUI.createElement({
name = "IBtn"..idx,
type = "IButton",
w = w,
h = h,
x = ((idx - 1) % 6) * w,
y = math.floor((idx - 1) / 6) * h,
image = imagePath,
func = function(self, a, b, c) Msg(self.name, a, b, c) end,
params = {"a", "b", "c"}
})
end)
Last edited by solger; 10-16-2021 at 10:39 AM.
|
|
|
10-17-2021, 05:13 AM
|
#869
|
Human being with feelings
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
|
Hi Solger :-) thank you for your reply!
Quote:
Originally Posted by solger
In the first MessageBox, 'Buttons[i].button.params[1]' is accessed directly inside the for loop (after the value has been set):
Code:
if i<2 then
reaper.ShowMessageBox("Parameter that goes IN (should be 1): " .. tostring(Buttons[i].button.params[1]), "Debug", 0)
end
But there are currently no parameters passed to the selectButton function. Hence you get a 'nil' value when trying to access the 'stuff' parameter variable in the second MessageBox:
Code:
func = selectButton
One option to try is to pass the parameter directly to the function:
Code:
...
Buttons[i].button = GUI.createElements({
name = "Button " .. i,
type = "Button",
x = 4 + (100 * (Buttons[i].col-1)),
y = 4 + (100 * (Buttons[i].row-1)),
w = 96, h = 96,
func = selectButton({1})
})
...
|
I think you are mistaken here. If i put the parameters in brackets behind the function name, weird stuff happens. From what i understand, in Scythe, you're supposed to just write the name of the function without brackets or parameters, and define the parameters in the seperate line "params = {}".
Not sure why it has to be that way.
But i found the solution, deducting from your second code example. I didn't realise that self was autmatically being added to my parameters. Where i thought i was calling the number 1, i instead accessed the self. In other words: I thought if i define {1,2,3} as the params then the function gets an array of length 3 with the values 1,2,3 in it. BUT it actually gets no array but 4(!) variables: self, 1,2, and 3! If i access the second variable instead of the first, i've got what i wanted.
So my selectButton-function has to look like this for it to work:
Code:
function selectButton(self, number)
reaper.ShowMessageBox("Parameter that comes out (should be 1): " .. number, "Debug", 0)
end
Thank you Solger :-)
Last edited by GameAudioRvlzzr; 01-04-2022 at 07:24 AM.
Reason: Misunderstood something, learned about it later, corrected my falsehood
|
|
|
10-18-2021, 08:37 AM
|
#870
|
Human being with feelings
Join Date: Jan 2021
Posts: 22
|
Help with element deletion
Hi Everyone, I'm trying to have a button that removes itself after a certain amount of time. It seems to remove its self property when it is clicked, but when triggered by the timer function it doesn't seem to update the UI. I believe I somehow need to trigger a UI redraw but am not sure of how ( I also might be looking in the wrong place). Any help would be greatly appreciated.
Code:
Code:
function remove_popup()
GUI.elms.popup:delete()
end
GUI.New("popup", "Button", {
z = 1,
x = 5.0,
y = 260.0,
w = 330,
h = 40,
caption = msg,
font = 3,
col_txt = "white",
col_fill = "blue",
func = remove_popup
})
time_start = reaper.time_precise()
reaper.ShowConsoleMsg("Starting a timer for 2 seconds...")
local function Main()
local elapsed = reaper.time_precise() - time_start
if elapsed >= 3 then
remove_popup()
reaper.ShowConsoleMsg("2 seconds have elapsed")
return
else
reaper.defer(Main)
end
end
Main()
|
|
|
10-18-2021, 10:31 AM
|
#871
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Adding this line should do the trick:
Code:
function remove_popup()
GUI.elms.popup:delete()
GUI.redraw_z[0] = true
end
Using redraw_z[0] (with value 'zero') redraws everything. It's also possible to redraw only specific z layers. More info here: https://github.com/jalovatt/Lokasenn.../4.02-Z-layers
EDIT:
Since the button in your example is on z layer 1 (z = 1), redrawing only z layer 1 should also work:
Code:
function remove_popup()
GUI.elms.popup:delete()
GUI.redraw_z[1] = true
end
Last edited by solger; 10-18-2021 at 10:38 AM.
|
|
|
10-18-2021, 05:22 PM
|
#872
|
Human being with feelings
Join Date: Jan 2021
Posts: 22
|
That's the ticket, thanks so much Solger. Very helpful as always.
Quote:
Originally Posted by solger
Adding this line should do the trick:
Code:
function remove_popup()
GUI.elms.popup:delete()
GUI.redraw_z[0] = true
end
Using redraw_z[0] (with value 'zero') redraws everything. It's also possible to redraw only specific z layers. More info here: https://github.com/jalovatt/Lokasenn.../4.02-Z-layers
EDIT:
Since the button in your example is on z layer 1 (z = 1), redrawing only z layer 1 should also work:
Code:
function remove_popup()
GUI.elms.popup:delete()
GUI.redraw_z[1] = true
end
|
|
|
|
11-28-2021, 11:59 AM
|
#873
|
Human being with feelings
Join Date: Jan 2011
Location: Ottawa, Canada
Posts: 293
|
Easy Q: How do I close the main window?
Hey Folks, just getting started with this cool GUI script and Lua scripting in general.
I've written my script and hooked it into a couple sliders and buttons. But for some reason I'm stuck on what I figured would be the easiest things:
1. I would like the Ok button to Close the GUI main window (as changes have already been applied)
2. I would like the main window "X" button to call a 'restore()' function and close the window
I have my various functions working. I can modify the Midi, and restore it. But I can't figure out how to interact with the main window.
I've tried setting 'GUI.quit = true' and it doesn't appear to do anything to the window.
I've been looking at the wiki and I see guidance on how to start the Gui, but not how to shut it down: https://github.com/jalovatt/Lokasenn...a-basic-script
Any help here would be much appreciated...
|
|
|
11-28-2021, 12:21 PM
|
#874
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Quote:
Originally Posted by DrFrankencopter
1. I would like the Ok button to Close the GUI main window (as changes have already been applied)
...
I've tried setting 'GUI.quit = true' and it doesn't appear to do anything to the window.
|
Calling 'gfx.quit' afterwards should do the trick:
Code:
GUI.quit = true
gfx.quit()
Quote:
Originally Posted by DrFrankencopter
2. I would like the main window "X" button to call a 'restore()' function and close the window
|
Try using the reaper.atexit function ( https://www.extremraym.com/cloud/rea...oc/#lua_atexit):
Code:
reaper.atexit(function ()
-- call your code or function(s) here
end)
|
|
|
11-28-2021, 12:53 PM
|
#875
|
Human being with feelings
Join Date: Jan 2011
Location: Ottawa, Canada
Posts: 293
|
Quote:
Originally Posted by solger
|
Will give that a shot. Many many thanks for your help!
Update: gfx.quit works like a charm...but reaper.atexit() seems to be called right at the start of my script, and not when the X button on the gui is pressed.
I can live with this not quite working. Now I need to sort out my undo data....
Update 2: Turns out you can access the trigger on the window 'X' button by pointing GUI.exit to your exit function. But please note that the exit function needs to be set before you call GUI.Init()
Last edited by DrFrankencopter; 11-28-2021 at 01:22 PM.
|
|
|
12-19-2021, 04:26 PM
|
#876
|
Human being with feelings
Join Date: Apr 2016
Location: Stuttgart, Germany
Posts: 217
|
EDIT: With fresh eyes, i found a workaround. Still, if i could have done this more elegantely, please let me know.
My workaround is changing files in the Scythe lib folder. In the Button-file, I copied the "func" elements from the "local Button = Element:new()"-section and "self:func(table.unpack(self.params))" from the onMouseUp-section, and pasted it into the corresponding sections in the Listbox-file.
Now i can define an action to be called (where i will check for change in listbox selection) when there's a mouseUp on my Listbox. Yeah :-)
_______________________________
Hi everyone, again me being stuck with v3 / Scythe :-/
I wonder how i get informed when the user makes a selection in a Listbox.
I mean, when the user selects one of the options the Listboxoffers him, i want to do something with that selection. But how would i know he did? Is there a function that gets called when a selection is made?
Let's say, in above Listbox, the user selects "E-Piano" (changing from the formerly selected "Bells"). I want to sort a dataset by "Piano", as soon as the user made that selection. How?
Do i need an extra button that executes reading the values from the Listbox? Would really prefer doing it without that.
Thanks for your help
Micha
Last edited by GameAudioRvlzzr; 12-20-2021 at 05:50 AM.
Reason: Found a workaround myself
|
|
|
12-21-2021, 09:51 AM
|
#877
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,856
|
Quote:
Originally Posted by GameAudioRvlzzr
EDIT: With fresh eyes, i found a workaround. Still, if i could have done this more elegantely, please let me know.
My workaround is changing files in the Scythe lib folder. In the Button-file, I copied the "func" elements from the "local Button = Element:new()"-section and "self:func(table.unpack(self.params))" from the onMouseUp-section, and pasted it into the corresponding sections in the Listbox-file.
Now i can define an action to be called (where i will check for change in listbox selection) when there's a mouseUp on my Listbox. Yeah :-)
_______________________________
Hi everyone, again me being stuck with v3 / Scythe :-/
I wonder how i get informed when the user makes a selection in a Listbox.
I mean, when the user selects one of the options the Listboxoffers him, i want to do something with that selection. But how would i know he did? Is there a function that gets called when a selection is made?
Let's say, in above Listbox, the user selects "E-Piano" (changing from the formerly selected "Bells"). I want to sort a dataset by "Piano", as soon as the user made that selection. How?
Do i need an extra button that executes reading the values from the Listbox? Would really prefer doing it without that.
Thanks for your help
Micha
|
Hi Micha,
there are user event hooks available (such as afterDoubleClick or afterMouseUp) to call a function on a specific event:
Code:
GUI.createElement({
name = "lst_titles",
type = "Listbox",
x = 16,
y = 40,
w = 300,
h = 208,
caption = "",
multi = true,
list = titles,
afterDoubleClick = function(self) yourFunction() end,
afterMouseUp = function(self) yourFunction() end
})
For an example, have a look at the code in the Script: Scythe_Example - Menubar, Listbox, and TextEditor.lua file (which uses the afterDoubleClick hook function).
EDIT: General info about available user event hooks can be found in the user-event-hooks.lua file (see post #851: https://forum.cockos.com/showpost.ph...&postcount=851).
Last edited by solger; 12-21-2021 at 10:45 AM.
|
|
|
12-23-2021, 12:50 PM
|
#878
|
Human being with feelings
Join Date: Jul 2018
Posts: 52
|
Rea effects
Hello,
Sorry if it's a dumb question,
Is it possible to alter the Rea effects look with Scythe?
Thanks.
__________________
Windows 10 pro v22H2, I7 10700@ 2.90Ghz, 32GB,
RME Babyface pro, NI KK S49 MK2, Nektar Panorama P1,
Softube Console 1.
|
|
|
12-23-2021, 03:49 PM
|
#879
|
Human being with feelings
Join Date: Dec 2017
Location: Brazil
Posts: 2,011
|
You can't.
This are for reascript.
The maximum in that path you will be able to do is make a script with your GUI to change the rea effects parameters.
|
|
|
12-23-2021, 07:06 PM
|
#880
|
Human being with feelings
Join Date: Jul 2018
Posts: 52
|
Quote:
Originally Posted by daniellumertz
You can't.
This are for reascript.
The maximum in that path you will be able to do is make a script with your GUI to change the rea effects parameters.
|
Thanks Daniel,
That's way beyond my skills
__________________
Windows 10 pro v22H2, I7 10700@ 2.90Ghz, 32GB,
RME Babyface pro, NI KK S49 MK2, Nektar Panorama P1,
Softube Console 1.
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:10 AM.
|