Skip to content

Commit 7ac37dd

Browse files
authored
Probe individual mask sliders
1 parent 3889742 commit 7ac37dd

File tree

1 file changed

+89
-49
lines changed

1 file changed

+89
-49
lines changed

examples/x-touch.lua

Lines changed: 89 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
--[[
1919
X-Touch Mini flexible encoder shortcuts
2020
21-
This script will create virtual sliders that are mapped dynamically to
21+
This script will create virtual sliders that are mapped dynamically to
2222
the most relevant sliders for the currently focused processing module.
2323
Tailored modules are color zones, tone equalizer, color calibration and
2424
mask manager properties. The script can easily be amended for other
@@ -28,8 +28,8 @@ as well, that dynamically change meaning depending on current status.
2828
USAGE
2929
* require this script from your main lua file
3030
* restart darktable
31-
* create shortcuts for each of the encoders on the x-touch mini
32-
to a virtual slider under lua/x-touch
31+
* create shortcuts for each of the encoders on the x-touch mini
32+
to a virtual slider under lua/x-touch
3333
or import the following shortcutsrc file in the shortcuts dialog/preferences tab:
3434
3535
None;midi:CC1=lua/x-touch/knob 1
@@ -55,53 +55,93 @@ local du = require "lib/dtutils"
5555

5656
du.check_min_api_version("9.1.0", "x-touch")
5757

58-
function knob(action, element, effect, size)
59-
k = tonumber(action:sub(-1))
60-
61-
if dt.gui.action("iop/blend/tools/show and edit mask elements") ~= 0 then
62-
local s = { "opacity", "size", "feather", "hardness","rotation","curvature","compression" }
63-
which = "lib/masks/properties/" .. s[k]
64-
65-
elseif dt.gui.action("iop/colorzones", "focus") ~= 0 then
66-
which = "iop/colorzones/graph"
67-
local e = { "red", "orange", "yellow", "green", "aqua", "blue", "purple", "magenta" }
68-
element = e[k]
69-
70-
elseif dt.gui.action("iop/toneequal", "focus") ~= 0 then
71-
which ="iop/toneequal/simple/"..(k-9).." EV"
72-
73-
elseif dt.gui.action("iop/colorbalancergb", "focus") ~= 0 and k == 4 then
74-
which = "iop/colorbalancergb/contrast"
58+
-- set up 8 mimic sliders with the same function
59+
for k = 1,8 do
60+
dt.gui.mimic("slider", "knob ".. k,
61+
function(action, element, effect, size)
62+
-- take the number from the mimic name
63+
local k = tonumber(action:sub(-1))
64+
65+
-- only operate in darkroom; return NAN otherwise
66+
if dt.gui.current_view() ~= dt.gui.views.darkroom then
67+
return 0/0
68+
end
7569

76-
elseif dt.gui.action("iop/channelmixerrgb", "focus") ~= 0 and k >= 5 then
77-
if k == 5 then
78-
which = "iop/channelmixerrgb/page"
79-
element = "CAT"
80-
if effect == "up" then effect = "next"
81-
elseif effect == "down" then effect = "previous"
82-
else effect = "activate"
70+
-- first try if the mask slider at that position is active
71+
local s = { "opacity",
72+
"size",
73+
"feather",
74+
"hardness",
75+
"rotation",
76+
"curvature",
77+
"compression" }
78+
local maskval = dt.gui.action("lib/masks/properties/" .. s[k],
79+
element, effect, size)
80+
-- if a value different from NAN is returned, the slider was active
81+
if maskval == maskval then
82+
return maskval
83+
84+
-- try if colorzones module is focused; if so select element of graph
85+
elseif dt.gui.action("iop/colorzones", "focus") ~= 0 then
86+
which = "iop/colorzones/graph"
87+
local e = { "red",
88+
"orange",
89+
"yellow",
90+
"green",
91+
"aqua",
92+
"blue",
93+
"purple",
94+
"magenta" }
95+
element = e[k]
96+
97+
-- if the tone equalizer is focused,
98+
-- select one of the sliders in the "simple" tab
99+
elseif dt.gui.action("iop/toneequal", "focus") ~= 0 then
100+
which ="iop/toneequal/simple/"..(k-9).." EV"
101+
102+
-- if color calibration is focused,
103+
-- the last 4 knobs are sent there
104+
elseif dt.gui.action("iop/channelmixerrgb", "focus") ~= 0
105+
and k >= 5 then
106+
-- knob 5 selects the active tab; pressing it resets to CAT
107+
if k == 5 then
108+
which = "iop/channelmixerrgb/page"
109+
element = "CAT"
110+
-- since the tab action is not a slider,
111+
-- the effects need to be translated
112+
if effect == "up" then effect = "next"
113+
elseif effect == "down" then effect = "previous"
114+
else effect = "activate"
115+
end
116+
else
117+
-- knobs 6, 7 and 8 are for the three color sliders on each tab
118+
which = "iop/focus/sliders"
119+
local e = { "1st",
120+
"2nd",
121+
"3rd" }
122+
element = e[k - 5]
123+
end
124+
125+
-- the 4th knob is contrast;
126+
-- either colorbalance if it is focused, or filmic
127+
elseif dt.gui.action("iop/colorbalancergb", "focus") ~= 0
128+
and k == 4 then
129+
which = "iop/colorbalancergb/contrast"
130+
131+
-- in all other cases use a default selection
132+
else
133+
local s = { "iop/exposure/exposure",
134+
"iop/filmicrgb/white relative exposure",
135+
"iop/filmicrgb/black relative exposure",
136+
"iop/filmicrgb/contrast",
137+
"iop/crop/left",
138+
"iop/crop/right",
139+
"iop/crop/top",
140+
"iop/crop/bottom" }
141+
which = s[k]
83142
end
84-
else
85-
which = "iop/focus/sliders"
86-
local e = { "1st", "2nd", "3rd" }
87-
element = e[k - 5]
88-
end
89-
90-
else
91-
local s = { "iop/exposure/exposure",
92-
"iop/filmicrgb/white relative exposure",
93-
"iop/filmicrgb/black relative exposure",
94-
"iop/filmicrgb/contrast",
95-
"iop/crop/left",
96-
"iop/crop/right",
97-
"iop/crop/top",
98-
"iop/crop/bottom" }
99-
which = s[k]
100-
end
101-
102-
return dt.gui.action(which, element, effect, size)
103-
end
104143

105-
for k = 1,8 do
106-
dt.gui.mimic("slider", "knob ".. k, knob)
144+
-- now pass the element/effect/size to the selected slider
145+
return dt.gui.action(which, element, effect, size)
146+
end)
107147
end

0 commit comments

Comments
 (0)