Old 09-24-2019, 04:43 PM   #521
parrssee
Human being with feelings
 
Join Date: Sep 2019
Posts: 2
Default Reinitialize window

Hello, Lokasenna! Hello, guys. I'm try to realize function to delete buttons from window, but my window already drawn and i need to restart whole script. So can i just reinitialize window or maybe there is another solution?
parrssee is offline   Reply With Quote
Old 09-24-2019, 07:25 PM   #522
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

When you delete elements, you have to tell it to redraw whatever z they were on.

Code:
GUI.elms.my_button:delete()
GUI.redraw_z[4] = true -- or whatever the z was
Lokasenna is online now   Reply With Quote
Old 09-26-2019, 05:58 PM   #523
parrssee
Human being with feelings
 
Join Date: Sep 2019
Posts: 2
Default

Thanks!
parrssee is offline   Reply With Quote
Old 10-19-2019, 01:18 AM   #524
Supremo
Human being with feelings
 
Join Date: Mar 2019
Posts: 17
Default

Hi Lokasenna!

Sorry for putting this question in the wrong thread probably, but I couldn't find a dedicated topic about your scripts, particularly regarding the "Show only specified tracks" one.

My issue with that script is the following:

- I export a preset with certain settings and give a name to that preset.
- A separate script appears in my action list with that particular preset.

However, when I try to run that new script, it won't activate. It just does nothing although the original script works as usual.

Would you please help me figure that out?

Many thanks!
Supremo is offline   Reply With Quote
Old 10-19-2019, 06:31 AM   #525
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Weird. Can you post the exported script on Dropbox or something and I'll have a look?

Assuming you're using Reapack:
- In the Action List, run Show REAPER resource path in explorer
- Navigate to Reaper/Scripts/ReaTeam Scripts/Tracks Properties
- Look for Lokasenna_Show only specified tracks - Whatever you named the exported script.lua
Lokasenna is online now   Reply With Quote
Old 10-19-2019, 10:33 AM   #526
Supremo
Human being with feelings
 
Join Date: Mar 2019
Posts: 17
Default

Nevermind, Lokasenna. I have figured that out. First I thought that I could export my specific settings as a default preset (e.g. having some check-boxes enabled by default on every run) but then I realized that this 'Export Preset' function works only for names being typed in the search box and not for the settings.

That would be cool to have an option for memorizing default settings though.
Supremo is offline   Reply With Quote
Old 10-19-2019, 11:46 AM   #527
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by Supremo View Post
Nevermind, Lokasenna. I have figured that out. First I thought that I could export my specific settings as a default preset (e.g. having some check-boxes enabled by default on every run) but then I realized that this 'Export Preset' function works only for names being typed in the search box and not for the settings.

That would be cool to have an option for memorizing default settings though.
The exported action uses both the search text and the settings.

You're right that the main script doesn't remember your previous settings... I'll add that to my to-do list if I ever get around to updating that script.
Lokasenna is online now   Reply With Quote
Old 10-20-2019, 02:58 AM   #528
Supremo
Human being with feelings
 
Join Date: Mar 2019
Posts: 17
Default

Quote:
Originally Posted by Lokasenna View Post
The exported action uses both the search text and the settings.

You're right that the main script doesn't remember your previous settings... I'll add that to my to-do list if I ever get around to updating that script.
That would be really handy indeed!
One small request: could you please let me know, what line I should add in the lua file in order to run the "Show only specified tracks" script always in a docked position?

I try to integrate this script into my orchestral template and have already added it to my _startup.lua file but it runs undocked every time I call this action. Would be really helpful if the script could remember its last docked position.


BTW, just sent you a donation for your awesome work.
Supremo is offline   Reply With Quote
Old 10-21-2019, 11:25 AM   #529
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

just looking at the gui library as a possible way of improving reaper toolbars. been having trouble with them resizing themselves in uncontrollable ways. this seems maybe more controllable. one thing i'm wondering, though, is whether it's possible to have two lines of text on a button. i literally JUST tried the library for the first time so i very likely missed something. how would one do this? here's a screenshot of a toolbar i just had an issue with (as you can see, all of the buttons have two lines of text):




the second question would be about editing a toolbar once it's been made. would that be possible? or, would it have to be rebuilt from the ground up? didn't see an import option.

thanks for the really exciting possibilities,
babag

Last edited by babag; 10-21-2019 at 11:42 AM.
babag is offline   Reply With Quote
Old 10-21-2019, 11:46 AM   #530
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
is whether it's possible to have two lines of text on a button. i literally JUST tried the library for the first time so i very likely missed something. how would one do this?
It's been a while, but I think you just have to type \n in the label to get a line break.

Quote:
the second question would be about editing a toolbar once it's been made. would that be possible? or, would it have to be rebuilt from the ground up? didn't see an import option.
You can have it create the toolbar dynamically from a list when the script starts. Something like:
Code:
local toolbar_buttons = {
  { label: "thing", command: 12345 },
  { label: "stuff", command: 67890 },
}

local button_width = 48

for k, v in ipairs(toolbar_buttons) do
  GUI.New("btn_"..k, "Button", (k - 1) * button_width, 0, button_width, 24, caption = v.label, func = function() reaper.Main_OnCommand(v.command, 0) end)
end
(This example might be a bit rough... I don't have Reaper on this machine and I haven't used v2 of the library in a while)

The list could also be a separate text file if that's easier, you just have to get Lua to read it in. Regardless, editing your toolbar would just be a matter of editing the list.
Lokasenna is online now   Reply With Quote
Old 10-21-2019, 11:53 AM   #531
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by Supremo View Post
could you please let me know, what line I should add in the lua file in order to run the "Show only specified tracks" script always in a docked position?
It would be a bit of work to make the script docker-friendly - it needs to be able to save the docker state, load it again, and then apply that when it opens the window. Doable, but not something I can easily post here. :/

I will add that to the to-do list for v3 of the GUI library, so future scripts should be able to do it more easily.
Lokasenna is online now   Reply With Quote
Old 10-21-2019, 12:23 PM   #532
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

the '\n' worked.

i'm not much of a scripter so it might take me a while to get up the gumption to try something like the second suggestion.

thanks!
babag
babag is offline   Reply With Quote
Old 10-21-2019, 02:02 PM   #533
Supremo
Human being with feelings
 
Join Date: Mar 2019
Posts: 17
Default

Quote:
Originally Posted by Lokasenna View Post
It would be a bit of work to make the script docker-friendly - it needs to be able to save the docker state, load it again, and then apply that when it opens the window. Doable, but not something I can easily post here. :/

I will add that to the to-do list for v3 of the GUI library, so future scripts should be able to do it more easily.
Thanks anyway, Lokasenna!
Supremo is offline   Reply With Quote
Old 10-21-2019, 03:14 PM   #534
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

started playing a little with the suggested code and have gotten my first error:
Quote:
toolbartest-01_GUI.lua:27: <name> expected near '"XF ON"'
i decided to try making two buttons, one to enable, the other to disable 'crossfade on split.' started by taking a test script generated by the gui builder and editing the code into it. here's what threw the error:
Code:
-- Script generated by Lokasenna's GUI Builder

local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Set Lokasenna_GUI v2 library path.lua' in the Lokasenna_GUI folder.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()


GUI.req("Classes/Class - Button.lua")()
-- If any of the requested libraries weren't found, abort the script.
if missing_lib then return 0 end


GUI.name = "New script GUI"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 1024, 240
GUI.anchor, GUI.corner = "mouse", "C"


local toolbar_buttons = {
  { label: "XF ON", command: 40927 },
  { label: "XF OFF", command: 40928 },
}

local button_width = 62

for k, v in ipairs(toolbar_buttons) do
  GUI.New("btn_"..k, "Button", (k - 1) * button_width, 0, button_width, 24, caption = v.label, func = function() reaper.Main_OnCommand(v.command, 0) end)
end


GUI.Init()
GUI.Main()
can i get a suggestion as to how to get this to work? if someone can show me, i should be able to create the rest of the buttons myself (i think).

edit:
tried looking at the example scripts but couldn't decipher them.

thanks,
babag

Last edited by babag; 10-21-2019 at 03:34 PM.
babag is offline   Reply With Quote
Old 10-21-2019, 08:01 PM   #535
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
started playing a little with the suggested code and have gotten my first error:

i decided to try making two buttons, one to enable, the other to disable 'crossfade on split.' started by taking a test script generated by the gui builder and editing the code into it. here's what threw the error:
Code:
local toolbar_buttons = {
  { label: "XF ON", command: 40927 },
  { label: "XF OFF", command: 40928 },
}
Oops, my bad - my brain was in Javascript mode. Those :s should be =s:
Code:
local toolbar_buttons = {
  { label = "XF ON", command = 40927 },
  { label = "XF OFF", command = 40928 },
}
Lokasenna is online now   Reply With Quote
Old 10-21-2019, 08:54 PM   #536
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

ah. thanks. but now i'm getting:
Quote:
toolbartest-01_GUI.lua:34: ')' expected near '='
that's this line:
Code:
  GUI.New("btn_"..k, "Button", (k - 1) * button_width, 0, button_width, 24, caption = v.label, func = function() reaper.Main_OnCommand(v.command, 0) end)
don't get that. looks right to my untrained eye.

thanks again,
babag

btw, this is really cool.
babag is offline   Reply With Quote
Old 10-21-2019, 09:00 PM   #537
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
ah. thanks. but now i'm getting:
that's this line:
Code:
  GUI.New("btn_"..k, "Button", (k - 1) * button_width, 0, button_width, 24, caption = v.label, func = function() reaper.Main_OnCommand(v.command, 0) end)
don't get that. looks right to my untrained eye.
Dammit, my mistake again. Take out "caption = " and "func = " - having the parameters named is an alternate syntax I added a while back.

Quote:
btw, this is really cool.
Thanks. I'm hoping to have the next version ready for testing in a week or two.
Lokasenna is online now   Reply With Quote
Old 10-21-2019, 09:22 PM   #538
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

well, it's getting better. now it draws the window but crashes with no buttons displaying in the window. crash report:
Quote:
Error: Class - Button.lua:62: attempt to perform arithmetic on a string value (field 'h')

Stack traceback:
Core.lua:88: in metamethod '__add'
Class - Button.lua:62: in method 'init'
Core.lua:214: in field 'update_elms_list'
Core.lua:288: in function <...am Scripts/Development/Lokasenna_GUI v2/Library/Core.lua:233>
[C]: in function 'xpcall'
Core.lua:233: in field 'Init'
toolbartest-01_GUI.lua:42: in main chunk

Lokasenna_GUI:
v2.16.8
Reaper:
5.984/linux64
Platform:
Other
and, here's the current state of the code:
Code:
-- Script generated by Lokasenna's GUI Builder


local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Set Lokasenna_GUI v2 library path.lua' in the Lokasenna_GUI folder.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()




GUI.req("Classes/Class - Button.lua")()
-- If any of the requested libraries weren't found, abort the script.
if missing_lib then return 0 end



GUI.name = "Toolbar Test GUI"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 1024, 240
GUI.anchor, GUI.corner = "mouse", "C"



local toolbar_buttons = {
  { label = "XFADE\nON", command = 40927 },
  { label = "XFADE\nOFF", command = 40928 },
}

local button_width = 62

for k, v in ipairs(toolbar_buttons) do
  GUI.New("btn_"..k, "Button", (k - 1) * button_width, 0, button_width, 24, v.label, function() reaper.Main_OnCommand(v.command, 0) end)
end






GUI.Init()
GUI.Main()
thanks again,
babag
babag is offline   Reply With Quote
Old 10-22-2019, 06:51 AM   #539
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Dammit, me again. I forgot to add a z value for the button. Try changing:
Code:
"Button", (k - 1) * button_width,
to
Code:
"Button", 1, (k - 1) * button_width,
Lokasenna is online now   Reply With Quote
Old 10-22-2019, 10:35 AM   #540
Supremo
Human being with feelings
 
Join Date: Mar 2019
Posts: 17
Default

Quote:
Originally Posted by Lokasenna View Post
It would be a bit of work to make the script docker-friendly - it needs to be able to save the docker state, load it again, and then apply that when it opens the window. Doable, but not something I can easily post here. :/

I will add that to the to-do list for v3 of the GUI library, so future scripts should be able to do it more easily.
BTW, a simple gfx.dock(0x901) line at the end of the script just did the trick.
Supremo is offline   Reply With Quote
Old 10-22-2019, 10:39 AM   #541
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by Supremo View Post
BTW, a simple gfx.dock(0x901) line at the end of the script just did the trick.
For that specific docker on your setup, absolutely.

The work I mentioned is having the script automatically read the current window state (position, docked state, which docker), save that when it closes, load that when it opens, and put itself back there.
Lokasenna is online now   Reply With Quote
Old 10-22-2019, 10:44 AM   #542
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

COOL! This is awesome! trying to figure out how to put in a second row now. i don't recognize anywhere a value that seems to set the y location inside a window.

not being a coder of any sort, i thought i'd try duplicating the 'local toolbar_buttons =' section as 'local toolbar_buttons2 =' and then duplicating the 'for' loop at a new 'y' position and having it call 'toolbar_buttons2' instead of 'toolbar_buttons'. couldn't see how to set the second row's position, though.

edit:
found the y position. it's in the 'for' loop at 'button_width, 0'. changing the 0 changes the y position. got a crash when i tried to run two 'for' loops, though, to get a second row.

thanks for all this! it's really awesome,
babag

Last edited by babag; 10-22-2019 at 11:02 AM.
babag is offline   Reply With Quote
Old 10-22-2019, 11:31 AM   #543
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
edit:
found the y position. it's in the 'for' loop at 'button_width, 0'. changing the 0 changes the y position. got a crash when i tried to run two 'for' loops, though, to get a second row.
- What message does the crash give you? Knowing the error it found and the line number can often tell you exactly what the problem was.

- I recommend using the alternate syntax for creating elements, as seen here. v3 of the GUI will only use that format because it's way easier to deal with.

(Don't forget to pass your elements to GUI.CreateElms if you do use that approach)

- Rather than two loops, you could put all of the buttons in a single list and then use some math to manage your rows:
Code:
local button_width = 32
local button_height = 24
local buttons_per_row = 8

for k, v in ipairs(toolbar_buttons) do
  GUI.New(
    "btn_"..k, 
    "Button", 
    1, 
    (k - 1) * button_width, -- x
    math.floor(k / buttons_per_row0) *  button_height, -- y
    button_width, -- w
    button_height, -- h
    v.label, 
    function() reaper.Main_OnCommand(v.command, 0) end
  )
end
Lokasenna is online now   Reply With Quote
Old 10-22-2019, 05:19 PM   #544
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

made some minor adjustments to get this to work but still some issues. using 'buttons_per_row0' returned an error:
Quote:
toolbartest-01_GUI.lua:78: attempt to perform arithmetic on a nil value (global 'buttons_per_row0')
changing to just 'buttons_per_row' does not return an error.
Code:
local button_width = 62
local button_height = 32
local buttons_per_row = 4

for k, v in ipairs(toolbar_buttons) do
  GUI.New(
    "btn_"..k, 
    "Button", 
    1, 
    (k - 1) * (button_width + 5), -- x
    math.floor((k - 1) / buttons_per_row) *  button_height, -- y
    button_width, -- w
    button_height, -- h
    v.label, 
    function() reaper.Main_OnCommand(v.command, 0) end
  )
end
the problem with the code above is that, while it does jump to a new row as defined in 'local buttons_per_row = 4', it does not reset the x position. it just goes on from the end of the preceding button rather than starting a new row at 0. been trying to figure out a way to flag that but haven't figured out yet.

if i can get this working, i'll give a go at the newer method. this seems so close, though, that i want to try to get it to work.

thanks,
babag
babag is offline   Reply With Quote
Old 10-22-2019, 07:28 PM   #545
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

this seems to work:
Code:
local button_width      = 62
local button_height     = 32
local buttons_per_row   = 13
local row_buttons       = -1

for k, v in ipairs(toolbar_buttons) do
  if row_buttons == (buttons_per_row - 1) then
      row_buttons = 0
  else
      row_buttons = (row_buttons + 1)
  end
    GUI.New(
    "btn_"..k, 
    "Button", 
    1, 
    (row_buttons) * (button_width + 1), -- x
    math.floor((k - 1) / buttons_per_row) *  button_height, -- y
    button_width, -- w
    button_height, -- h
    v.label, 
    function() reaper.Main_OnCommand(v.command, 0) end
  )

end
inelegant, i'm sure but it seems to put things in the right place. i had a lot of trouble getting that to happen.

thanks,
babag
babag is offline   Reply With Quote
Old 10-22-2019, 08:06 PM   #546
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

And that's why I shouldn't write code in a text editor where I can't check if it's correct... :/ Sorry.

Quote:
Originally Posted by babag View Post
inelegant, i'm sure but it seems to put things in the right place. i had a lot of trouble getting that to happen.
You can use a similar idea to how it calculates y to get x. Try:
Code:
  GUI.New(
    "btn_"..k, 
    "Button", 
    1, 
    ((k - 1) % buttons_per_row) * button_width, -- x
    math.floor((k - 1) / buttons_per_row) *  button_height, -- y
    button_width, -- w
    button_height, -- h
    v.label, 
    function() reaper.Main_OnCommand(v.command, 0) end
  )
Lokasenna is online now   Reply With Quote
Old 10-23-2019, 10:18 AM   #547
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

thanks, lokasenna. the basic drawing of the gui is working now. just tried the last code you put up and it also works fine.

now i'm getting something else, though. i put some custom actions into some of the buttons and, whenever i try to click one, the script crashes. here's the crash report:
Quote:
Error: toolbartest-02_GUI.lua:163: bad argument #1 to 'Main_OnCommand' (number expected, got nil)

Stack traceback:
Core.lua:88: in function <...am Scripts/Development/Lokasenna_GUI v2/Library/Core.lua:79>
[C]: in field 'Main_OnCommand'
toolbartest-02_GUI.lua:163: in field 'func'
Class - Button.lua:138: in method 'onmouseup'
Core.lua:883: in field 'Update'
Core.lua:435: in field 'Main_Update_Elms'
Core.lua:302: in function <...am Scripts/Development/Lokasenna_GUI v2/Library/Core.lua:298>
[C]: in function 'xpcall'
Core.lua:298: in function <...am Scripts/Development/Lokasenna_GUI v2/Library/Core.lua:297>

Lokasenna_GUI:
v2.16.8
Reaper:
5.984/linux64
Platform:
Other
i also have some buttons set to reaper native actions and they do not crash the script when clicked. any thoughts on this? does this not work with custom actions?

here's an offending custom action as listed in the script:
Code:
{ label = "REPLACE\nw1000ms", command = _fad0ff7281777ae665363b96d96f1651 },
and here's one that works:
Code:
{ label = "XFADE\nTOGGLE",    command = 40912 },
thanks,
babag
babag is offline   Reply With Quote
Old 10-23-2019, 10:29 AM   #548
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 3,790
Default

Quote:
Originally Posted by babag View Post
i also have some buttons set to reaper native actions and they do not crash the script when clicked. any thoughts on this? does this not work with custom actions?

here's an offending custom action as listed in the script:
Code:
{ label = "REPLACE\nw1000ms", command = _fad0ff7281777ae665363b96d96f1651 },
and here's one that works:
Code:
{ label = "XFADE\nTOGGLE",    command = 40912 },
Hi babag,

For custom action command id strings, use
Quote:
reaper.Main_OnCommand(reaper.NamedCommandLookup("_fad0ff7281777ae665363b 96d96f1651"), 0)
instead of
Quote:
reaper.Main_OnCommand(40912 , 0)
for native action IDs.
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 10-23-2019, 11:31 AM   #549
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

thanks, solger. not sure how to use that with the 'v.command' variable that lokasenna suggested. tried this:
Code:
function() reaper.Main_OnCommand(reaper.NamedCommandLookup(v.command), 0) end
tried with and without quotes around v.command. in either case i get crashing. if i paste a command id directly, as in your example, it works. looks like i have something wrong in syntax for the variable?

edit:
spoke too soon. looks like replacing this:
Code:
  { label = "REPLACE\nw1000ms", command = _fad0ff7281777ae665363b96d96f1651 },
with this:
Code:
  { label = "REPLACE\nw1000ms", command = "_fad0ff7281777ae665363b96d96f1651" },
makes it work. i'm guessing that's because the underscore at the start of the id necessitates quotes?

thanks again,
babag

Last edited by babag; 10-23-2019 at 11:39 AM.
babag is offline   Reply With Quote
Old 10-23-2019, 11:32 AM   #550
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
thanks, solger. not sure how to use that with the 'v.command' variable that lokasenna suggested. tried this:
Code:
function() reaper.Main_OnCommand(reaper.NamedCommandLookup(v.command), 0) end
tried with and without quotes around v.command. in either case i get crashing. if i paste a command id directly, as in your example, it works. looks like i have something wrong in syntax for the variable?

thanks again,
babag
When you put custom action or script commands into the list, you need quotes around the ID:
Code:
command = "_fad0ff7281777ae665363b96d96f1651"
Lokasenna is online now   Reply With Quote
Old 10-23-2019, 11:51 AM   #551
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

thanks! making a lot of progress now!
babag is offline   Reply With Quote
Old 10-23-2019, 11:52 AM   #552
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 3,790
Default

Quote:
Originally Posted by babag View Post
spoke too soon. looks like replacing this:
Code:
  { label = "REPLACE\nw1000ms", command = _fad0ff7281777ae665363b96d96f1651 },
with this:
Code:
  { label = "REPLACE\nw1000ms", command = "_fad0ff7281777ae665363b96d96f1651" },
makes it work. i'm guessing that's because the underscore at the start of the id necessitates quotes?
The ID for Reascripts or Custom Action is a string, hence quotes are required in this case.
In comparison the (native) command IDs are integer numbers which the reaper.Main_OnCommand(integer commandID, 0) function expects (that's why you got the 'Main_OnCommand' (number expected, got nil) error mentioned in post #547).

Using reaper.NamedCommandLookup(string commandName) in-between is for getting the commandID number from the commandName string.
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 10-23-2019, 11:53 AM   #553
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

thanks, solger!
babag is offline   Reply With Quote
Old 10-24-2019, 10:38 AM   #554
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

so, i started trying to convert the toolbar script over to the newer structure suggested here:

https://github.com/ReaTeam/ReaScript...tables.lua#L96

i managed to adapt that script to get rid of the things i don't need and to get the remaining button to perform one of my actions. what i couldn't figure out, though, is how to integrate the table for all of my buttons and the 'for' loop from the old way of structuring things.

the example script shows how to make a single button but there's nothing i could see like what i've got with settings for lots of buttons being read in and assigned.

thanks for any guidance on this,
babag
babag is offline   Reply With Quote
Old 10-24-2019, 10:48 AM   #555
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
so, i started trying to convert the toolbar script over to the newer structure suggested here:

https://github.com/ReaTeam/ReaScript...tables.lua#L96

i managed to adapt that script to get rid of the things i don't need and to get the remaining button to perform one of my actions. what i couldn't figure out, though, is how to integrate the table for all of my buttons and the 'for' loop from the old way of structuring things.

the example script shows how to make a single button but there's nothing i could see like what i've got with settings for lots of buttons being read in and assigned.

thanks for any guidance on this,
babag
Should just be:
Code:
local elms = {}
local toolbar_buttons = ...your existing table here...

for k, v in pairs(toolbar_buttons) do
  -- What you were doing before, but replace the old GUI.New(...) style with:
  elms["button_"..k] = {
    type = "Button",
    ...etc...
  }
end

GUI.createElms(elms)
Lokasenna is online now   Reply With Quote
Old 10-24-2019, 11:59 AM   #556
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

thanks! that's better but now it's only showing one button where there should be 26. the one that shows is the last one in the table and it does seem to be in the right place. if i comment out some of the last lines of the table, the new last line is the one that shows and it also appears where i'd expect it. it's like there's a redraw happening as each button is placed and is eliminating the previously drawn button. here's what i have in total:
Code:
-- NoIndex: true

-- The Core library must be loaded prior to anything else

local lib_path = reaper.GetExtState("Lokasenna_GUI", "lib_path_v2")
if not lib_path or lib_path == "" then
    reaper.MB("Couldn't load the Lokasenna_GUI library. Please run 'Script: Set Lokasenna_GUI v2 library path.lua' in your Action List.", "Whoops!", 0)
    return
end
loadfile(lib_path .. "Core.lua")()


GUI.req("Classes/Class - Button.lua")()


-- If any of the requested libraries weren't found, abort the script.
if missing_lib then return 0 end


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


local function btn_click()
	
	-- Be nice, give the user an Undo point
	reaper.Undo_BeginBlock()
	
	
    reaper.Main_OnCommand(reaper.NamedCommandLookup(v.command), 0)
    
	reaper.Undo_EndBlock("Typical script options", 0)	

    
    -- Exit the script on the next update
	GUI.quit = false
	
end


------------------------------------
-------- Window settings -----------
------------------------------------


GUI.name = "Example - Typical script options"
GUI.x, GUI.y, GUI.w, GUI.h = 0, 0, 940, 240
GUI.anchor, GUI.corner = "mouse", "C"


------------------------------------
-------- GUI Elements --------------
------------------------------------


local elms = {}

local toolbar_buttons = {
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
  { label = "REPLACE\nw50ms",     command = "_eed3041ab48a593fcd3909218c058b46" },
  { label = "REPLACE\nw100ms",    command = "_b1d758c949cfb993ac08348510785bca" },
  { label = "REPLACE\nw150ms",    command = "_783abc14cedb9ace0553c66e85d458c7" },
  { label = "REPLACE\nw250ms",    command = "_ddc0f5f3bbdebadf0e2feec56158ba80" },
  { label = "REPLACE\nw350ms",    command = "_af3926b79dc1641dc9bd654baf46b362" },
  { label = "REPLACE\nw500ms",    command = "_2abfd9c92dbc0e7b285de3b0d104214d" },
  { label = "REPLACE\nw650ms",    command = "_bba0abf47e24d1c844e66d20bb8d352a" },
  { label = "REPLACE\nw750ms",    command = "_8523a746e745a026f6f4f5d5ead51656" },
  { label = "REPLACE\nw850ms",    command = "_d49eef57e2e8b96b2ee2ecd6414d5a3a" },
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
  { label = "REPLACE\nw1000ms",   command = "_fad0ff7281777ae665363b96d96f1651" },
  { label = "REPLACE\nw1250ms",   command = "_719920ab0d8d00261a745b833cf4c17a" },
  { label = "REPLACE\nw1500ms",   command = "_031e4b0a90205d2bd1ebc56883fefb54" },
  { label = "REPLACE\nw2000ms",   command = "_a85b72f560781694ac339285f8fb5107" },
  { label = "REPLACE\nw2500ms",   command = "_5bf0c14e2f080ef093765d1c62f2c1bb" },
  { label = "REPLACE\nw3000ms",   command = "_f7479b2f90b9aad862d4ee030ea7d7de" },
  { label = "REPLACE\nw3500ms",   command = "_6c891165a600753b99f56897cf72cadd" },
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
  { label = "",                   command = 65535 },
}


local button_width      = 72
local button_height     = 32
local buttons_per_row   = 13
local buttons_count     = -1

for k, v in ipairs(toolbar_buttons) do
  if row_buttons == (buttons_per_row - 1) then
      row_buttons = 0
  else
      buttons_count = (buttons_count + 1)
  end

elms.btn_go = {
    type = "Button",
    z = 1,
    x = ((k - 1) % buttons_per_row) * button_width,
    y = math.floor((k - 1) / buttons_per_row) *  button_height,
    w = button_width,
    h = button_height,
    caption = v.label,
    func = btn_click,
    tooltip = "I'm a button"
}

end

GUI.CreateElms(elms)


GUI.Init()
GUI.Main()
babag is offline   Reply With Quote
Old 10-24-2019, 12:14 PM   #557
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

You're using the same name every time, so each button is overwriting the previous one.

Change:
Code:
elms.btn_go = {
to:
Code:
elms["button_"..k] = {
Lokasenna is online now   Reply With Quote
Old 10-24-2019, 12:18 PM   #558
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

that fixed the drawing! now i get a crash on a button click:
Quote:
Error: toolbartest-06_GUI.lua:33: attempt to index a nil value (global 'v')

Stack traceback:
Core.lua:88: in metamethod '__index'
toolbartest-06_GUI.lua:33: in field 'func'
Class - Button.lua:138: in method 'onmouseup'
Core.lua:883: in field 'Update'
Core.lua:435: in field 'Main_Update_Elms'
Core.lua:302: in function <...am Scripts/Development/Lokasenna_GUI v2/Library/Core.lua:298>
[C]: in function 'xpcall'
Core.lua:298: in function <...am Scripts/Development/Lokasenna_GUI v2/Library/Core.lua:297>

Lokasenna_GUI:
v2.16.8
Reaper:
5.984/linux64
Platform:
Other
thanks again!
babag
babag is offline   Reply With Quote
Old 10-24-2019, 12:57 PM   #559
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,345
Default

Quote:
Originally Posted by babag View Post
that fixed the drawing! now i get a crash on a button click:
thanks again!
babag
Your btn_click function doesn't know what v is - you need to have the button pass the command into it. I believe you just have to add:
Code:
func = btn_click,
params = {v.command} -- this line
Lokasenna is online now   Reply With Quote
Old 10-24-2019, 01:16 PM   #560
babag
Human being with feelings
 
Join Date: Nov 2009
Posts: 1,688
Default

that didn't seem to do it. this is what i have:
Code:
  elms["button_"..k] = {
    type = "Button",
    z = 1,
    x = ((k - 1) % buttons_per_row) * button_width,
    y = math.floor((k - 1) / buttons_per_row) *  button_height,
    w = button_width,
    h = button_height,
    caption = v.label,
    func = btn_click,
    params = {v.command},
    tooltip = "I'm a button"
  }
still crashes. tried also with/without comma at end of line. also tried wit parentheses instead of curly brackets.
babag is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 12:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.