Old 11-09-2019, 10:12 AM   #601
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 402
Default

Quote:
Originally Posted by Lokasenna View Post
The previous versions were all double quotes as well. As for why:
- IMO doubles make slightly more sense since single quotes/apostrophes are more likely to appear in a UI's text.
I think this is the best argument... sold.

Looks like there may be enough image support here for me to port my IControl class over to V3 without having to edit the base classes (which I did before). I'll submit it for your inspection when I get something working.
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 11-09-2019, 11:45 PM   #602
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 402
Default

I'm trying to figure out what the (...) syntax does in LUA. I'm searching on google, and it doesn't seem to be 'searchable'! Google turns nothing up for it.

Do you know where I might be able to read up on it?
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 11-10-2019, 12:24 AM   #603
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,835
Default

They're called vararg functions: https://www.lua.org/manual/5.3/manual.html#3.4.11. The vararg expression ... (three dots) stores all extra parameters that were given to the function (it's not a table, more like functions with multiple return values).

Last edited by cfillion; 11-10-2019 at 12:46 AM.
cfillion is online now   Reply With Quote
Old 11-10-2019, 10:18 PM   #604
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 402
Default

Quote:
Originally Posted by cfillion View Post
They're called vararg functions: https://www.lua.org/manual/5.3/manual.html#3.4.11. The vararg expression ... (three dots) stores all extra parameters that were given to the function (it's not a table, more like functions with multiple return values).
Thanks! A lot of good information there about how arguments work.

I'm going to have to get my head around passing functions around. It's all new to me and makes my head spin a bit....

As an example, in 'working with images' I find:

Code:
if self:containsPoint(state.mouse.x, state.mouse.y) then

		self.func(table.unpack(self.params))
self.params here refers to func's self, is that right? Am I right in thinking that func as an argument to the control should be the function we want it to execute when the button is pressed?

I'm trying to imagine what syntax I would use to have the func parameter call an action that required the value of self.state as an argument... I've figured other ways to do that without func, (basically overriding the control's mouse methods with direct calls) but it seems like I'm missing the point. There is an easier way, correct?

Okay, searched in Knob.lua, and it looks like the func argument is not being used in this way there, so maybe I was mistaken. Is what I'm talking about above possible? or desirable?
__________________
eric moon
Very Stable Genius
https://gogolab.com/

Last edited by woodslanding; 11-10-2019 at 10:55 PM.
woodslanding is offline   Reply With Quote
Old 11-11-2019, 07:35 AM   #605
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,356
Default

Quote:
Originally Posted by woodslanding View Post
Thanks! A lot of good information there about how arguments work.

I'm going to have to get my head around passing functions around. It's all new to me and makes my head spin a bit....

As an example, in 'working with images' I find:

Code:
if self:containsPoint(state.mouse.x, state.mouse.y) then

		self.func(table.unpack(self.params))
self.params here refers to func's self, is that right? Am I right in thinking that func as an argument to the control should be the function we want it to execute when the button is pressed?
self is just an argument; in this case self is the IButton. If you're used to something like Javascript's this, self isn't passed around the same way.

Quote:
I'm trying to imagine what syntax I would use to have the func parameter call an action that required the value of self.state as an argument... I've figured other ways to do that without func, (basically overriding the control's mouse methods with direct calls) but it seems like I'm missing the point. There is an easier way, correct?
I've just pushed an update for you. . User functions for Button, Menubar, and the IButton example in the image script all receive self as their first argument. i.e. when creating them you would use:
Code:
func = function(self, a, b, c) Msg(self.name, a, b, c) end,
params = {"a", "b", "c"}
Lokasenna is online now   Reply With Quote
Old 11-11-2019, 10:31 AM   #606
woodslanding
Human being with feelings
 
woodslanding's Avatar
 
Join Date: Mar 2007
Location: Denver, CO
Posts: 402
Default

oh, sweet, thanks!
__________________
eric moon
Very Stable Genius
https://gogolab.com/
woodslanding is offline   Reply With Quote
Old 11-13-2019, 10:36 AM   #607
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 234
Default

Is it possible to set the inc paramter of the Slider class to something smaller than 1? I´d like to keep the range at 1 top at the beginning and inc something like 0,01, cause then i wouldnt need to do any math, should the user change the range of the fader.
reapero is online now   Reply With Quote
Old 11-13-2019, 10:38 AM   #608
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,356
Default

Quote:
Originally Posted by reapero View Post
Is it possible to set the inc paramter of the Slider class to something smaller than 1? I´d like to keep the range at 1 top at the beginning and inc something like 0,01, cause then i wouldnt need to do any math, should the user change the range of the fader.
Yup. One of the sliders in the General Demonstration example has increments of 0.25:
Code:
GUI.New("my_sldr", 	"Slider",		4, 128, 256, 128, "Slider", 0, 10, 20, 0.25, "v")
Lokasenna is online now   Reply With Quote
Old 11-14-2019, 02:00 AM   #609
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 234
Default

So how come this doesnt work? I kept the formatting that your GUI builder puked:

Code:
GUI.New("Offset", "Slider", {
    z = 11,
    x = 64.0,
    y = 340,
    w = 96,
    caption = "Offset",
    min = offset_min,
    max = offset_max,
    defaults = {0,0},
    inc = 0.1,
    dir = "h",
    font_a = 2,
    font_b = 4,
    col_txt = "txt",
    col_fill = "elm_fill",
    bg = "wnd_bg",
    show_handles = true,
    show_values = true,
    cap_x = 0,
    cap_y = 0
    
})
Offset_min is 0 and offset_max is 1. The slider goes straight from 0 to 1, no steps allowed.

Last edited by reapero; 11-14-2019 at 03:37 AM.
reapero is online now   Reply With Quote
Old 11-14-2019, 07:17 AM   #610
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,356
Default

My bad; it wasn't picking up the inc parameter for elements created as a table. Pushing a fix up now.
Lokasenna is online now   Reply With Quote
Old 11-14-2019, 01:05 PM   #611
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 234
Default

Thanks Loka. Working nicely now!
reapero is online now   Reply With Quote
Old 11-16-2019, 09:11 AM   #612
reapero
Human being with feelings
 
Join Date: Aug 2011
Posts: 234
Default

Ok, please bear with me. This is more like a SetExtState quetion but related to the usage of this GUI library somehow.

So i have set up this script with 10 sliders, most of them are double (table output). I want to create presets for the script, so i´d like to use ExtStates to store these settings. Now looking at the API:

Code:
reaper.SetExtState( section, key, value, persist )
Correct me if i am wrong but for this case this will turn out to be something like this:

reaper.SetExtState( "MY_PLUGIN", "PRESET_NUMBER_X", data, true)

That means i have to store A LOT of values in the "data" string. A lot like meaning every fader has its own max and min, its couple values if its a table, etc. That will probably become an ugly long string like "0,10,01,07,0,100,0,0,2,20,0...." separated by comma or space.

Is that the way to go here? Its going to be very hard for me to navigate thru this string to locate problems, cause i´ll probably forget what is what. I can create a function that separates this values and sends them into the right variables but even so, i wonder if i am just making things more complicated than they should.

thank you
reapero is online now   Reply With Quote
Old 11-16-2019, 02:25 PM   #613
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,356
Default

Quote:
Originally Posted by reapero View Post
i wonder if i am just making things more complicated than they should.
Putting a bunch of values into one string and splitting them back out again is actually the most common way to do this.

If your presets are flat - that is, they don't have any nested tables - it's really easy:

Code:
-- Make sure the characters you use aren't in the data, or you'll have to add
-- some logic to hande them
local keyValueSeparator = "="
local fieldSeparator = "&"

local function hashToExtString(hash)
  local out = {}
  for k, v in pairs(hash) do
    out[#out + 1] = k .. keyValueSeparator .. v
  end
  return out.concat(fieldSeparator)
end

local function hashFromExtString(ext)
  local out = {}
  for pair in ext:gmatch("[^" .. fieldSeparator .. "]+") do
    local k, v = pair:match("(.+)=(.+)")

    if tonumber(v) then
      v = tonumber(v)
    elseif v == "true" then
      v = true
    elseif v == "false" then
      v = false
    end

    out[k] = v
  end

  return out
end


--------------------
-- To save:

local presets = {
  {
    name = "apple",
    min = 5,
    max = 10,
  },
  {
    name = "banana",
    min = 0,
    max = 3,
  },
  {
    name = "cherry",
    min = 2,
    max = 9,
  }
}

for i, preset in pairs(presets) do
  local extString = hashToExtString(preset)
  reaper.SetExtState("MY_PLUGIN", "PRESET_NUMBER_" .. i, extString, true)
end

--------------------
-- To load:

local presets = {}

for i = 1, NUMBER_OF_PRESETS do
  local extString = reaper.GetExtState("MY_PLUGIN", "PRESET_NUMBER_"..i)

  presets[i] = hashFromExtString(extString)
end
(Note: Don't have a chance to test this)

If you do have nested tables, it's a bit more work. Radial Menu stores its settings in a text file, and I found a function that writes all of the table contents as Lua code: https://github.com/ReaTeam/ReaScript...Menu.lua#L5000 . Loading them again is just a matter of reading in the file and telling Lua to execute it.
Lokasenna is online now   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 11:11 AM.


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