Questions regarding profiles.lua
I'm really struggling with trying to make the profiles directory relative to the currently loaded profile. I want to make sure I understand the profiles.lua specifics as written. I'll use comments to ask my questions:
local loadedprofile = ''-- loaded profile name as shown in MIDI2LR app. i.e. profile.xml or
../profile.xml if loaded w/ relative link?
local profilepath = '' --according to the profile folder setting in the app. i.e. absolute link?
local function setDirectory(value)
profilepath = value
end -- setDirectory is the absolute link from above?
local function setFile(value)
if loadedprofile ~= value then
doprofilechange(value)
end --compares file names?
end
local function setFullPath(value)
local path, profile = value:match("(.-)([^\\/]-%.?([^%.\\/]*))$") --returns file name w/o path?
profilepath = path --absolute link set by local profilepath?
if profile ~= loadedprofile then
doprofilechange(profile)
end
end
Is there anywhere in the code where the currently loaded profile is loaded with it's full path, or any way in which it could be (I don't see it)? Perhaps currentTMP, Profile ?
Is the LuaFileSystem or Debug libraries included in the package? I could possibly use a debug.getinfo call to load the path?
Starting from the last question and working back.
The Lua standard io library is included, debug is not. It's safest to do file system work with the Lightroom SDK PathUtils and FileUtils. You can download the SDK documentation from Adobe. If you don't use the LR SDK utilities, Lua doesn't do a good job with Unicode in the file name or path, and you'd also have to watch your path styles to make sure it will work with OSX and Windows.
You can get the full path of the currently loaded profile with LrPathUtils.child(profilepath,loadedprofile).
That first line in setFullPath sets two function-local variables: path, with the path to the file, and profile, which is the profile's file name. The second line stores the path into the module-local profilepath variable, which is used by functions in the Profiles.lua module. I couldn't find a way to use the LR SDK for this task. The regex used is fairly strict, so it has a high likelihood of working.
setFile compares file names. If the file name hasn't changed, it doesn't order a profilechange.
setDirectory is the absolute link--it is getting the directory name from the app.
local profilepath is getting the profile folder setting from the app, through either setDirectory or setFullPath. loadedprofile is getting the profile file name from either the plugin or the app, depending upon which initiated the profile change. It looks like 'profile.xml', If you load from the plugin with a relative link, this will have that portion of the path included--so it would have '../profile.xml' in your example. The question is whether the app would properly respond to receiving '../profile.xml' as the profile to switch to. I'm not sure.
Thank you. I'll try the LR function.
I understood the first line of setFullPath to be two variables, but with the same result. If I'm reading the match correctly the result would be the profile name (last entry w/o slashes and with optional dot in the middle. i.e. profile.xml).
Putting relative or absolute links into the profiles options location field does work, and the application functions fine. The profile manager also shows subfolders w/in the "profiles folder" and allows them to be loaded/edited. The "problem" I am trying to resolve is that it reverts to the default profile location when the next profile is called. I want it to look in the folder the loaded profile is in.
The benefit of this is the ability to call multiple instances of a profile with the same name, but with different settings for expanded functionality. This would be a major improvement in capability for a controller with limited CC's. In my case, I have all panel profiles and all 10 additional profiles defined, and I'm out of options. The behavior would be that the top profile in the base profile folder (defined setting) would load with the app (as it currently does). The next profile would load from the current (default) folder or as linked (absolute links would work best). For most, the behavior would be the same as it is currently. But you could define several profiles with absolute links as "root profiles" to enable this expanded behavior/functionality.
Would it be easier to have more than 10 profiles available? I can easily change that to 20--I just stopped at 10 arbitrarily.
Not really. I think I could add more if I needed.
I want to switch between "configurations." In one configuration I have the ability to adjust multiple parameters in multiple panels (i.e. basic/tone/sharpening). In the other I open panels and the encoders all sync with that panel. The problem is that the opening panels/loading profiles of the second configuration interferes with the first configuration.
I suppose that since the CC's are changed between controller profiles I could make much larger (more confusing) xml profiles that load with the panels to work in both scenarios... I haven't tried that yet.
Is it possible for assigned encoders to sync with their settings in closed panels? They don't at present.
I understood the first line of setFullPath to be two variables, but with the same result. If I'm reading the match correctly the result would be the profile name (last entry w/o slashes and with optional dot in the middle. i.e. profile.xml).
Lua statements can return multiple values that can be assigned to multiple variables. That's what that line does. A simpler example would be:
a,b = 23,'three'
after which a = 23 and b = 'three'.
Another example:
x = 3
y = 4
x,y = y,x
after which x = 4 and y = 3.
Thanks for helping me understand the code. So in that statement the match only applies to the second variable? I'm not seeing the separator in the return... the "," in your examples.
What does local profilePath look like when loaded by setFullPath? If it is the full path w/o the file name I shouldn't need to use LrPathUtils.child(profilepath,loadedprofile) in order to attach the file name, I'll only have to remove it again. But it seems to be the same as setDirectory even if I have a profile loaded from another folder. If it wasn't, switching to a profile in a new folder using an absolute link should work with the existing code.
Merged with #181