18
18
--[[
19
19
X-Touch Mini flexible encoder shortcuts
20
20
21
- This script will create virtual sliders that are mapped dynamically to
21
+ This script will create virtual sliders that are mapped dynamically to
22
22
the most relevant sliders for the currently focused processing module.
23
23
Tailored modules are color zones, tone equalizer, color calibration and
24
24
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.
28
28
USAGE
29
29
* require this script from your main lua file
30
30
* 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
33
33
or import the following shortcutsrc file in the shortcuts dialog/preferences tab:
34
34
35
35
None;midi:CC1=lua/x-touch/knob 1
@@ -55,53 +55,93 @@ local du = require "lib/dtutils"
55
55
56
56
du .check_min_api_version (" 9.1.0" , " x-touch" )
57
57
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
75
69
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 ]
83
142
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
104
143
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 )
107
147
end
0 commit comments