|
|
|
06-01-2016, 10:00 AM
|
#41
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
Please can you add font color?Now it can be changed only globally.Thank you very much for this script!
|
|
|
06-01-2016, 11:04 AM
|
#42
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Added in this version:
Simple GUI template.lua
For example -
(80,20,50,30, 0.6,0.4,0.1,0.3, "Btn2","Arial",15, {0.7, 0.9, 0.4, 1}, etc )
Last edited by eugen2777; 06-04-2016 at 02:06 AM.
|
|
|
06-03-2016, 07:17 PM
|
#43
|
Human being with feelings
Join Date: Oct 2011
Posts: 173
|
Thank you for this, and the clean code, with absolutely no knowledge in coding I was able to create buttons. But of course it stop there
Could someone please join an example of a full working script with button(s) launching a script or any action (I want to create a custom toolbar)
Just to understand how it works (and by understand I mean copy/paste , the Timbaland way)
|
|
|
06-04-2016, 01:42 AM
|
#44
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
It's very simple. Here is a simple example
.............
Code:
local btn1 = Button:new(20,20,50,30, 0.5,0.3,0.4,0.3, "Btn1","Arial",15, {0.7,0.9,0.4,1} )
local btn2 = Button:new(80,20,50,30, 0.6,0.4,0.1,0.3, "Btn2","Arial",15, {0.7,0.9,0.4,1} )
local Button_TB = {btn1,btn2}
-- Example --
btn1.onClick =
function() -- Here you can add something else --
reaper.Main_OnCommand(40757, 0) -- Split - see in action list - action ID
end
btn2.onClick =
function()
reaper.Main_OnCommand(41588, 0) -- Glue - see in action list - action ID
end
-- etc
Last edited by eugen2777; 06-04-2016 at 02:07 AM.
|
|
|
06-04-2016, 08:51 AM
|
#45
|
Human being with feelings
Join Date: Oct 2011
Posts: 173
|
Eugen2777, thank you so much !
|
|
|
06-04-2016, 09:55 AM
|
#46
|
Human being with feelings
Join Date: Nov 2006
Posts: 2,182
|
They all look so cute !
Is it possible to click&drag the range sliders/knobs in the middle to adjust both values at once?
|
|
|
06-04-2016, 10:19 AM
|
#47
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
They look awful. When I have time, I will change their look and functionality.
Quote:
Is it possible to click&drag the range sliders/knobs in the middle to adjust both values at once?
|
Okay, it will be added.
|
|
|
06-05-2016, 01:45 AM
|
#48
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
One more request if possible,can you make radio button menu?
|
|
|
06-06-2016, 08:07 AM
|
#49
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
can someone give me an example how to trigger something when value in checkbox is selected?
|
|
|
06-07-2016, 08:05 AM
|
#50
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Quote:
Originally Posted by Sexan
can someone give me an example how to trigger something when value in checkbox is selected?
|
So, for example:
Code:
ch_box1.onClick =
function()
local track = reaper.GetTrack(0, ch_box1.norm_val-1)
if track then reaper.SetOnlyTrackSelected(track) end
end
Range sliders/knobs in the middle to adjust both values at once added in this version:
Simple GUI template.lua
Code:
make radio button menu?
Yes, it will be added later
|
|
|
06-07-2016, 08:30 AM
|
#51
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
I've done it this way:
Code:
ch_box1.onClick = function()
local tr = reaper.BR_GetMediaTrackByGUID(0,ch_GUID)
local items = ch_box.norm_val2[ch_box.norm_val].chunk
restoreTrackItems(tr,items)
end
is that ok? I mean everything works as it should
Quote:
Originally Posted by eugen2777
Yes, it will be added later
|
Thank you very much!
|
|
|
06-07-2016, 11:32 AM
|
#52
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Eugen, is your mouse-driven GUI designer available yet ?
|
|
|
06-08-2016, 03:38 AM
|
#53
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Quote:
mouse-driven GUI designer available yet
|
No, this is a test version, there is a lot of redundant code, and it is inconvenient for the understanding and application of the code in the script.
Initially I didn't think that my template can someone come in handy.
But in the future I want to make a big change, leaving the code simple to use, yet expandable functionality.
I need only free time, I can't say when it will be ready.
|
|
|
06-08-2016, 07:21 AM
|
#54
|
Human being with feelings
Join Date: Aug 2006
Location: Berlin
Posts: 11,818
|
Thank Eugen.
I'll try to use the script template. SPK77 has made one that can use images too, so perhaps I'll combine the two.
|
|
|
06-08-2016, 07:38 PM
|
#55
|
Human being with feelings
Join Date: Oct 2011
Posts: 173
|
Questions again
With the cool code for knobs and sliders , I'm trying now to build some kind of channel strip/frontend of fxs
In my quest of coding by copying random lines without understand anything (The justin bieber trick), I've done that, and it works :
knb1.onMove = function() Track = reaper.GetSelectedTrack(0,0)
if Track then reaper.TrackFX_SetParam(Track, 0, 3, knb1.norm_val) end end
Problem is I don't know how to target a fx by his name instead of his order number in the stack.
And I can't make my knobs/sliders work both way, moving the knob change the fx parameter as expected, but moving the fx param in the plugin doesn't move the slider/knob or selecting a track with my fxs doesn't reflect their values in my knobs script.
|
|
|
06-09-2016, 04:43 AM
|
#56
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
1. Getting an the index number for an FX by name:
Code:
plugin_id = reaper.TrackFX_GetByName(track_current, plugin_name, 0)
2. I'm not sure exactly how eugen2777's template is set up, but you just need to include a section in your defer loop that checks if the track selection or FX values have changed, and if they have, updates their knobs accordingly. i.e.
Code:
if selected_track ~= current_track then current_track = selected_track
if param1 ~= knob1.value then knob1.value = param1
...etc...
|
|
|
06-09-2016, 03:06 PM
|
#57
|
Human being with feelings
Join Date: Oct 2011
Posts: 173
|
Thanks Lokasenna ! With your help I made that and it works like a charm (I put the lines here if it can help total noob like me)
-- Add function for knb1 --
knb1.onMove = function() Track = reaper.GetSelectedTrack(0,0)
fx_ReaEQ = reaper.TrackFX_GetByName(Track, "ReaEQ", 0)--fx named as in Track Insert Fx
if Track then reaper.TrackFX_SetParam(Track, fx_ReaEQ, 1, knb1.norm_val) end end --ReaEQ Gain Band 1
The part 2 is already too complex for me (I don't even know what is a defer loop)
|
|
|
06-09-2016, 03:45 PM
|
#58
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
reaper.defer() is the command used in every GUI script to maintain the GUI. If you look through eugen2777's template, you should see it being used inside one of the functions like so:
Code:
function Main()
...stuff...
reaper.defer(Main)
...more stuff...
end
This tells Reaper "hey, next time you're updating everything, call Main again plzkthx". Without defer, GUI scripts would just open a window and immediately close it.
|
|
|
06-09-2016, 03:59 PM
|
#59
|
Human being with feelings
Join Date: Oct 2011
Posts: 173
|
Thank you again, for teaching stuff, here and in your awesome thread about GUI. I will dig into this
|
|
|
06-10-2016, 12:56 PM
|
#60
|
Human being with feelings
Join Date: Oct 2011
Posts: 173
|
Ok, ran out of luck (yes all my skills are only based on luck ), I'm stuck, always end with beautiful reascript errors, you were super helpful Lokasenna, the weak link is me.
Eugen2777, if you have time of course, could you please give an example of a knob linked to a fx parameter, and working both ways ?
And values of knobs go to 0 to 1, any way to reflect the fx value instead ? (but I can easily live without that)
|
|
|
06-11-2016, 06:56 AM
|
#61
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Thanks again for this GUI script - it's a good template for testing different ideas.
Feature request:
Mouse wheel support for checkbox element (by the way, isn't it more like a "drop-down list combo box": https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
Something like this:
|
|
|
08-09-2016, 01:13 AM
|
#62
|
Human being with feelings
Join Date: May 2010
Location: France
Posts: 97
|
Hi
I added right click support on buttons
add this new function (under function Element:mouseClick() for example)
Code:
function Element:mouseRightClick()
return gfx.mouse_cap&2==0 and last_mouse_cap&2==2 and
self:pointIN(gfx.mouse_x,gfx.mouse_y) and self:pointIN(mouse_ox,mouse_oy)
end
replace function Button:draw() by this one
Code:
function Button:draw()
self:update_xywh() -- Update xywh(if wind changed)
local r,g,b,a = self.r,self.g,self.b,self.a
local fnt,fnt_sz = self.fnt, self.fnt_sz
-- Get 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() and self.onClick then self.onClick() end
-- right click support
if self:mouseRightClick() and self.onRightClick then self.onRightClick() end
-- Draw btn body, frame ----
gfx.set(r,g,b,a) -- set body color
self:draw_body() -- body
self:draw_frame() -- frame
-- Draw label --------------
gfx.set(0.7, 0.9, 0.4, 1) -- set label color
gfx.setfont(1, fnt, fnt_sz) -- set label fnt
self:draw_lbl() -- draw lbl
end
for testing:
Code:
local btn1 = Button:new(20,20,50,30, 0.5,0.3,0.4,0.3, "Btn1","Arial",15, 0 )
local btn2 = Button:new(80,20,50,30, 0.6,0.4,0.1,0.3, "Btn2","Arial",15, 0 )
local Button_TB = {btn1,btn2}
btn1.onClick = function()
reaper.ShowConsoleMsg("btn1 click\n")
end
btn1.onRightClick = function()
reaper.ShowConsoleMsg("btn1 right click\n")
end
btn2.onClick = function()
reaper.ShowConsoleMsg("btn2 click\n")
end
btn2.onRightClick = function()
reaper.ShowConsoleMsg("btn2 right click\n")
end
|
|
|
08-30-2016, 09:21 AM
|
#63
|
Human being with feelings
Join Date: Mar 2007
Location: Denver, CO
Posts: 633
|
I'm wondering the appropriate way to change the text of a button.
I have a set of buttons and would like to change the text of a fifth button depending on which of the first 4 was most recently selected....
Actually I have lots of use cases for changing the text and the color of buttons. Right now, it seems like it is hard-wired into 'new'.
There don't seem to be any getters or setters for things like text or color. But I'm still getting a feel for LUA, so the architecture is a bit confusing yet.
thanks,
-eric
|
|
|
09-07-2016, 08:06 AM
|
#64
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
Would you consider implementing radio buttons? checkbox but not like drop down menu but radio buttons?
|
|
|
09-07-2016, 09:57 AM
|
#65
|
Human being with feelings
Join Date: Aug 2012
Posts: 271
|
Sexan, I think this is quite easy, but now, unfortunately, I do not have time for this. You can try to do it yourself.
=====
woodslanding,
You can add new methods are very easy.
For example:
Code:
function Button:Set_lbl(new_lbl) -- for buttons only
self.lbl = new_lbl
end
or
Code:
function Element:Set_lbl(new_lbl) - for parent class(btns,sldrs etc)
self.lbl = new_lbl
end
=====
Also, in a pinch, you can get or set the values directly, but be careful,to avoid confusion.
For example:
Code:
current_lbl = btn5.lbl -- get curr
btn5.lbl = "new label" -- set new(but it is better not to do!)
In this script, all methods and variables are public, not private.
Of course, in Lua there is a way to make them private, but here it is not necessary. I was guided by this:
"If you do not want to access something inside an object, just do not do it"("Programming in Lua" ).
|
|
|
12-21-2016, 09:41 PM
|
#66
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Sexan asked me to put together some radio buttons for this, since his requests went sadly unheeded. I did one better and made a checklist as well.
- The radio buttons' value is just 1 to N.
- The checklist's values are stored as an array, indexed 1 to N, with each value either 0 or 1. You can also use it to make a simple toggle, by leaving the label blank and only putting one item in the array.
See the :New parameters at the end of the file for an example.
Edit: I just realized that I added my code to the original version of Eugen2777's template, not the newer one; I've copied them over to the new one. Additionally, I added:
- The right-click code from earlier in this thread. See the buttons in the example.
- Mousewheel support for the checkbox element.
- A global_font setting just before the elements are created that you can use instead of manually specifying the color if you want.
Script template here.
Last edited by Lokasenna; 06-09-2017 at 11:09 AM.
|
|
|
12-22-2016, 04:10 AM
|
#67
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
Nice template !
I think it would be cool to have it on ReaScript template, with others scripts templates :P
|
|
|
12-22-2016, 06:32 AM
|
#68
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Edited my post above with a few more updates to the template.
|
|
|
12-22-2016, 07:40 AM
|
#69
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
Awesome and thank you very much!! I've added that functionality myself when I've downloaded your modification (and also added other modification in order to work with my script). One thing I cannot figure out is resizing of the radio box
since I am adding the buttons dinamically I want them all to be the same size (the box to expand bellow)
Here it the script:
https://stash.reaper.fm/29276/radioboxversion.lua
Code:
function create_button(name,GUID,chunk,type,nv)
in this function script creates new boxes
Last edited by Sexan; 12-22-2016 at 08:08 AM.
|
|
|
12-22-2016, 09:22 AM
|
#70
|
Human being with feelings
Join Date: Sep 2009
Posts: 863
|
Quote:
Originally Posted by Lokasenna
Sexan asked me to put together some radio buttons for this, since his requests went sadly unheeded. I did one better and made a checklist as well.
- The radio buttons' value is just 1 to N.
- The checklist's values are stored as an array, indexed 1 to N, with each value either 0 or 1. You can also use it to make a simple toggle, by leaving the label blank and only putting one item in the array.
See the :New parameters at the end of the file for an example.
Edit: I just realized that I added my code to the original version of Eugen2777's template, not the newer one; I've copied them over to the new one. Additionally, I added:
[...]
|
This is great, Lokasenna - many thanks !
|
|
|
12-22-2016, 11:53 AM
|
#71
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Quote:
Originally Posted by Sexan
One thing I cannot figure out is resizing of the radio box
since I am adding the buttons dinamically I want them all to be the same size (the box to expand bellow)
|
The spacing is calculated by h / #self.norm_val2, so if you want to change the number of options and keep the spacing consistent, just increase the height proportionally. i.e.
If your original list has four options, and the total height is 100px, then opt_spacing will come out to 25px. When you change the number of options, just add this after:
Code:
my_checklist.h = 25px * #self.norm_val2
The only problem is that eugen's resizing code at the top of the file ALSO changes all of the elements' dimensions, so adding that code would break resizing for that element. If you wanted to make it work without breaking anything, I think this would do:
Code:
local opt_spacing = my_checklist.h / #my_checklist.norm_val2
-- change the number of items here --
my_checklist.h = opt_spacing * #self.norm_val2
|
|
|
12-22-2016, 12:20 PM
|
#72
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
Thank you very much! I've modified euguens function for updating size just could not figure out that part. Thank you again
|
|
|
12-22-2016, 01:36 PM
|
#73
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
Really sorry for bothering you but I cannot start your latest script
Code:
if not self.opt_spacing then self.opt_spacing = (h / (#self.norm_val2 or 1)) end
Code:
lua:265: attempt to perform arithemtic on a nil value (global 'h')
and the same error in line 405
Im not loading it from my script, I am loading it stanalone
Last edited by Sexan; 12-22-2016 at 02:24 PM.
|
|
|
12-22-2016, 02:24 PM
|
#74
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Sorry, that should be self.h. I've uploaded a corrected version.
|
|
|
12-22-2016, 03:19 PM
|
#75
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
omg I cannot make this right... when script restarts the positions are different, on start they are big (while single) later on restart is ok they get normal.
This is unmodified script, but when modifing its the same
https://stash.reaper.fm/29282/radioboxversion.lua
|
|
|
12-22-2016, 05:10 PM
|
#76
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
I'm not sure, but I think I see two problems:
1. It looks like you aren't changing the number of radio buttons in the original element (i.e. adding "Version __" to the norm_val2, you're just adding new, separate elements each time. If you do that they have no way of knowing how many buttons there are, and so they're being sized individually.
2. As per my response above about resizing, I don't see any code to increase the element's height by one button.
I've uploaded another version of the template, this time with a button to add radio buttons and resize them.
|
|
|
12-23-2016, 03:52 AM
|
#77
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
no no, the script creates 1 element per track. The way it is coded is to check is there a checklist for selected track, if no then create one and give it track GUID. After that there is a check to see if track has checklist that has track GUID if there is then it does not create new element but just adds new state to norm_val2.
Code:
for k,v in ipairs(CheckBox_TB)do
if v.id == GUID then
v.norm_val2[#v.norm_val2+1] = state
this is exaclty the same code as in your newest example and you can see in the main table that this is true :
new states are all in norm_val2 sub table of original element
I will see with the new line for height you added . Thank you very much for your help!
Last edited by Sexan; 12-23-2016 at 03:59 AM.
|
|
|
12-23-2016, 04:49 AM
|
#78
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
Ok I've made modifications (on classes) for my needs and now it works perfectly. Insted of depending on the height it is dependant to the fonz size + 10 pixels (that ratio seems good visually)
edit:
Simplified ALL modification to just one line (for dinamically creating only)
Code:
self.h = self.h * #self.norm_val2
Code:
function Radio_Btns:draw()
self:update_xywh()
local r,g,b,a = self.r,self.g,self.b,self.a
local fnt,fnt_sz = self.fnt, self.fnt_sz
self.h = self.h * #self.norm_val2 <---------------------ADDED THIS LINE
self.opt_spacing = (self.h / (#self.norm_val2 or 1))
no additional code is needed
Last edited by Sexan; 12-23-2016 at 10:12 AM.
|
|
|
12-28-2016, 08:52 AM
|
#79
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 4,687
|
One tricky question for gurus:
Right now checkbox,radio buttons etc follow norm_val in order to change value,so if we have:
Code:
#norm_val2 (lets say its 4)
x.norm_val2.1 = 1
x.norm_val2.2 = 2
x.norm_val2.3 = 3
x.norm_val2.4 = 4
changing norm_val to any of 1-4 will select appropriate result. BUT if I have:
Code:
#norm_val2 (its still 4)
x.norm_val2.1 = 1
x.norm_val2.3 = 3 --- (x.norm_val2.2) IS REMOVED
x.norm_val2.4 = 4
x.norm_val2.5 = 5
now the script will break which is normal because on "norm_val = 2" there is nothing , key 2 does not exists in this table anymore. Is there a simple workaround for this (I need this behavior). I've been trying to modify but no luck for now (currently this is above my skills)
|
|
|
12-28-2016, 09:30 AM
|
#80
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
If I understand you correct, you're talking about trying to run through the second example with a for i = 1, #x.norm_val2 do loop. Lua considers a table's length to be one less than the first nil value, so it's not starting with the correct length.
To me the simplest solution would be to still set x.norm_val2.2 and just give it a value that it would never actually be on its own - i.e. if all the values your script uses are positive numbers, set it to -1. Then your table length is still correct, and the for loop can look like this:
Code:
for i = 1, #x.norm_val2 do
if x.norm_val2[i] ~= -1 then
-- normal loop code here
end
end
Or, if it's not important to go through the table in numerical order, you could just use for key, val in pairs(x.norm_val2) do instead, since it doesn't care about the overall length.
|
|
|
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 12:53 AM.
|