-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-zoom.lua
1890 lines (1646 loc) · 63.4 KB
/
auto-zoom.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Auto Zoom Plugin for XYZ Tracking
-- _
-- | |
-- __ _ _ _| |_ ___ _______ ___ _ __ ___
-- / _` | | | | __/ _ \_ / _ \ / _ \| '_ ` _ \
-- | (_| | |_| | || (_) / / (_) | (_) | | | | | |
-- \__,_|\__,_|\__\___/___\___/ \___/|_| |_| |_|
-- For Grandma2
--
-- Released under MIT License by Naostage (www.naostage.com)
-- __
-- ____ _____ ____ _______/ |______ ____ ____
-- / \\__ \ / _ \/ ___/\ __\__ \ / ___\_/ __ \
-- | | \/ __ \( <_> )___ \ | | / __ \_/ /_/ > ___/
-- |___| (____ /\____/____ > |__| (____ /\___ / \___ >
-- \/ \/ \/ \//_____/ \/
--
-- MIT License
--
-- Copyright (c) 2023 Olivier Le Doeuff
-- Copyright (c) 2023 Naostage
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
-- Check README.md for more information and usage
-- ------------------------------------------------------------------------------
-- GrandMa2 API
-- ------------------------------------------------------------------------------
-- gma.sleep(number:sleep_seconds)
-- gma.echo(all kind of values)
-- gma.feedback(all kind of values)
--
-- string:build_date = gma.build_date()
-- string:build_time = gma.build_time()
-- string:version_hash = gma.git_version()
--
-- gma.export(string:filename,table:export_data)
-- gma.export_csv(string:filename,table:export_data)
-- gma.export_json(string:filename,table:export_data)
-- table:import_data = gma.import(string:filename, [string:gma_subfolder])
--
-- gma.cmd(string:command)
-- gma.timer(function:name,number:dt,number:max_count,[function:cleanup])
-- number:time = gma.gettime()
-- string:result = gma.textinput(string:title,[string:old_text])
--
-- bool:result = gma.gui.confirm(string:title,string:message)
-- = gma.gui.msgbox(string:title,string:message)
--
-- number:handle = gma.gui.progress.start(string:progress_name)
-- gma.gui.progress.stop(number:progress_handle)
-- gma.gui.progress.settext(number:progress_handle,string:text)
-- gma.gui.progress.setrange(number:progress_handle,number:from,number:to)
-- gma.gui.progress.set(number:progress_handle,number:value)
--
-- number:value = gma.show.getdmx(number:dmx_addr)
-- table:values = gma.show.getdmx(table:recycle,number:dmx_addr,number:amount)
--
-- number:handle = gma.show.getobj.handle(string:name)
-- string:classname = gma.show.getobj.class(number:handle)
-- number:index = gma.show.getobj.index(number:handle)
-- number:commandline_number= gma.show.getobj.number(number:handle)
-- string:name = gma.show.getobj.name(number:handle)
-- string:label = gma.show.getobj.label(number:handle) returns nil if object has no label set
-- number:amount_children = gma.show.getobj.amount(number:handle)
-- number:child_handle = gma.show.getobj.child(number:handle, number:index)
-- number:parent_handle = gma.show.getobj.parent(number:handle)
-- bool:result = gma.show.getobj.verify(number:handle)
-- bool:result = gma.show.getobj.compare(number:handle1,number:handle2)
--
-- number:amount = gma.show.property.amount(number:handle)
-- string:property_name = gma.show.property.name(number:handle,number:index)
-- string:property = gma.show.property.get(number:handle,number:index/string:property_name)
--
-- string:value = gma.show.getvar(string:varname)
-- gma.show.setvar(string:varname,string:value)
--
-- string:value = gma.user.getvar(string:varname)
-- gma.user.setvar(string:varname,string:value")
-- number:object handle = gma.user.getcmddest()
-- number:object_handle = gma.user.getselectedexec()
--
-- string:type = gma.network.gethosttype()
-- string:subtype = gma.network.gethostsubtype()
-- string:ip = gma.network.getprimaryip()
-- string:ip = gma.network.getsecondaryip()
-- string:status = gma.network.getstatus()
-- number:session_number = gma.network.getsessionnumber()
-- string:session_name = gma.network.getsessionname()
-- number:slot = gma.network.getslot()
--
-- table:host_data = gma.network.gethostdata(string:ip,[table:recycle])
-- table:slot_data = gma.network.getmanetslot(number:slot,[table:recycle])
-- table:performance_data = gma.network.getperformance(number:slot,[table:recycle])
-- string:type = gma.gethardwaretype()
local GmaCmd = gma.cmd;
local GmaSleep = gma.sleep;
local GmaTimer = gma.timer;
local GmaShowPropertyAmount = gma.show.property.amount;
local GmaShowPropertyName = gma.show.property.name;
local GmaShowPropertyValue = gma.show.property.get;
local GmaUserGetCmdDest = gma.user.getcmddest;
local GmaShowGetObjHandle = gma.show.getobj.handle;
local GmaShowGetObjParent = gma.show.getobj.parent;
local GmaShowGetObjClass = gma.show.getobj.class;
local GmaShowGetObjIndex = gma.show.getobj.index;
local GmaShowGetObjNumber = gma.show.getobj.number;
local GmaShowGetObjChild = gma.show.getobj.child;
local GmaShowGetObjAmount = gma.show.getobj.amount;
local GmaShowGetObjName = gma.show.getobj.name;
local GmaShowGetObjLabel = gma.show.getobj.label;
local GmaShowSetVar = gma.show.setvar;
local GmaShowGetVar = gma.show.getvar;
local GmaUserSetVar = gma.user.setvar;
local GmaUserGetVar = gma.user.getvar;
-- ------------------------------------------------------------------------------
-- Constants
-- ------------------------------------------------------------------------------
-- Plugin functions that are expected to be called from macros are prefixed with "AZ."
-- This is a namespace that stands for "Auto Zoom"
-- It aims to avoid conflicts with other plugins
AZ = AZ or {}
local MODE = {
PROGRAMMER = 1,
EXECUTOR = 2,
}
local SETTINGS = {
PRINT_TO_ECHO = true,
PRINT_TO_FEEDBACK = true,
VERBOSE = true,
REFRESH_RATE = 30,
-- User variable to store the enabled state
ENABLE_VAR = "AUTO_ZOOM_PLUGIN_ENABLED",
-- User variable to store the current mode
MODE_VAR = "AUTO_ZOOM_PLUGIN_MODE",
-- Enable or disable the use of the Iris for zooming
USE_IRIS = true,
-- Prefix for every exec that will control something for the fixture
EXEC_PREFIX = "XYZ",
FADER_OFF = 0,
FADER_FULL = 100,
EXECUTOR_MODE_ENABLE_XYZ_EXEC = false,
EXECUTOR_MODE_ENABLE_ZOOM_EXEC = true,
EXECUTOR_MODE_ENABLE_IRIS_EXEC = true,
}
local INTERNAL_NAME = select(1, ...);
local VISIBLE_NAME = select(2, ...);
local MAIN_MODULE_ID = 1;
-- ------------------------------------------------------------------------------
-- Variables
-- ------------------------------------------------------------------------------
-- Set to true when the plugin is initialized with Start()
local g_initialized = false;
-- Keep if update loop is running
-- Can be controlled with AZ.Enable() and AZ.Disable()
local g_enabled = false;
-- Keep track of the current mode for XYZ and zoom tracking
-- Can be controlled with AZ.SetMode()
local g_mode = MODE.EXECUTOR;
-- Table of fixture with active XYZ tracking
-- {
-- [fixture_id] = {
-- fixture_id = 1,
-- marker_id = 1001,
-- beam_size:number = 1, -- in meters
-- },
-- ...
-- },
local g_fixtures = {};
-- Table of fixture infos, indexed by fixture id
-- {
-- [fixture_id] = {
-- position = {
-- x = x_position,
-- y = y_position,
-- z = z_position,
-- },
-- fixture_type_id = fixture_type_id,
-- fixture_id = fixture_id,
-- },
-- ...
-- }
local g_fixture_infos = {};
-- Table of fixture types infos, indexed by fixture type id
-- {
-- [fixture_type_id] = {
-- fixture_type_id = 1,
-- zoom = {
-- from = 0,
-- to = 255,
-- from_phys = 0,
-- to_phys = 100
-- },
-- iris = {
-- from = 0,
-- to = 255,
-- from_phys = 0,
-- to_phys = 100
-- },
-- },
-- [...] = {
-- ...
-- },
-- },
-- }
local g_fixture_types_info = {};
-- ------------------------------------------------------------------------------
-- Utils
-- ------------------------------------------------------------------------------
-- print to gma.echo and gma.feedback
-- Output can be controlled with SETTINGS.PRINT_TO_ECHO and SETTINGS.PRINT_TO_FEEDBACK
-- If both are false, nothing will be printed
-- This is useful for debugging
local function GmaPrint(...)
if not SETTINGS.PRINT_TO_ECHO and not SETTINGS.PRINT_TO_FEEDBACK then
return;
end
local args = { ... };
local str = "";
for i = 1, #args do
str = str .. tostring(args[i]);
end
str = VISIBLE_NAME .. ": " .. str;
if SETTINGS.PRINT_TO_ECHO then
gma.echo(str);
end
if SETTINGS.PRINT_TO_FEEDBACK then
gma.feedback(str);
end
end
-- print a table to gma.echo
--
-- param t:table table to print
local function GmaPrintTable(t)
for k, v in pairs(t) do
GmaPrint(k .. ":" .. type(k) .. " = " .. v .. ":" .. type(v));
end
end
-- convert an array to a string
--
-- param array:table array to convert
-- return a string with the array elements separated by a space
local function Array2String(array)
local str = "{";
for i = 1, #array do
str = str .. " " .. array[i];
end
str = str .. " }";
return str;
end
local function Position2String(table)
return "{" .. table.x .. ", " .. table.y .. ", " .. table.z .. "}";
end
local function GmaPrintProperties(handle)
local amount = GmaShowPropertyAmount(handle);
if amount == 0 then
GmaPrint("No properties exist");
end
for i = 0, amount - 1 do
local name = GmaShowPropertyName(handle, i);
local value = GmaShowPropertyValue(handle, i);
GmaPrint("Property[" .. i .. "]: " .. name .. "=" .. value);
end
end
local function GmaPrintObject(handle)
local class = GmaShowGetObjClass(handle);
local index = GmaShowGetObjIndex(handle);
local number = GmaShowGetObjNumber(handle);
local name = GmaShowGetObjName(handle);
local label = GmaShowGetObjLabel(handle);
local amount = GmaShowGetObjAmount(handle);
GmaPrint("-----Object Info-----");
GmaPrint(" Index:", index);
GmaPrint(" Class:", class);
GmaPrint(" Name:", name);
GmaPrint(" Label:", label);
GmaPrint(" Cmd_Num:", number);
GmaPrint("Children:", amount);
GmaPrint("-----Properties-----");
GmaPrintProperties(handle);
end
local function GetDistanceVector3(a, b)
local x = a.x - b.x;
local y = a.y - b.y;
local z = a.z - b.z;
return math.sqrt(x * x + y * y + z * z);
end
-- Get the angle of a beam with a given distance and radius
-- The angle is in radians
local function GetBeamAngle(distance, radius)
if distance <= 0 or radius <= 0 then
return 0;
end
return math.atan(radius / distance) * 2;
end
local function Lerp(a, b, t)
return a + (b - a) * t;
end
local function InvLerp(a, b, v)
return (v - a) / (b - a);
end
local function Remap(value, from1, to1, from2, to2)
return Lerp(from2, to2, InvLerp(from1, to1, value));
end
local function Clamp(value, min, max)
if min > max then
local tmp = min;
min = max;
max = tmp;
end
if value < min then
return min;
elseif value > max then
return max;
end
return value;
end
-- ------------------------------------------------------------------------------
-- Object ids
-- ------------------------------------------------------------------------------
local ROOT_OBJECTS = {
SHOWFILE = 1,
TIMECONFIG = 2,
SETTINGS = 3,
DMX_PROTOCOLS = 4,
NET_CONFIG = 5,
CITP_NET_CONFIG = 6,
TRACKING_SYSTEMS = 7,
USER_IMAGE_POOL = 8,
RDM_DATA = 9,
LIVE_SETUP = 10,
EDIT_SETUP = 11,
MACROS = 13,
FLIGHT_RECORDINGS = 14,
PLUGINS = 15,
GELS = 16,
PRESETS = 17,
WORLDS = 18,
FILTERS = 19,
FADE_PATHS = 20,
PROGRAMMER = 21,
GROUPS = 22,
FORMS = 23,
EFFECTS = 24,
SEQUENCES = 25,
TIMERS = 26,
MASTER_SECTIONS = 27,
EXECUTOR_PAGES = 30,
CHANNEL_PAGES = 31,
SONGS = 33,
AGENDAS = 34,
TIMECODES = 35,
REMOTE_TYPES = 36,
DMX_SNAPSHOT_TOOL = 37,
LAYOOUTS = 38,
USER_PROFILES = 39,
USERS = 40,
PIXEL_MAPPER_CONTAINER = 41,
NDP_ROOT = 42,
}
local LIVE_SETUP_OBJECTS = {
DMX_PROFILES = 1,
PRESET_TYPES = 2,
FIXTURE_TYPES = 3,
LAYERS = 4,
UNIVERSES = 5,
OBJECTS3D = 6,
}
local FIXTURE_TYPE_OBJECTS = {
MODULES = 1,
INSTANCES = 2,
WHEELS = 3,
PRESET_REFERENCES = 5,
FIXTURE_MACRO_COLLECT = 6,
RDM_NOTIFICATIONS = 7,
}
-- ------------------------------------------------------------------------------
-- Property ids
-- ------------------------------------------------------------------------------
local FIXTURE_PROPERTIES = {
NAME = 0,
FIX_ID = 1,
CHA_ID = 2,
FIXTURE_TYPE = 3,
PATCH = 4,
NO_PARAMETERS = 5,
POS_X = 6,
POS_Y = 7,
POS_Z = 8,
ROT_X = 9,
ROT_Y = 10,
ROT_Z = 11,
INFO = 12,
RDM_ID = 13,
}
local SUBFIXTURE_PROPERTIES = {
FIX_ID = 0,
CHA_ID = 1,
NAME = 2,
FIXTURE_TYPE = 3,
PATCH = 4,
REACT_TO_MASTER = 5,
PAN_DMX_INVERT = 6,
TILT_DMX_INVERT = 7,
PAN_ENC_INVERT = 8,
TILT_ENC_INVERT = 9,
PAN_OFFSET = 10,
TILT_OFFSET = 11,
SWAP = 12,
BITMAP_DISABLE = 13,
COLOR = 14,
POS_X = 15,
POS_Y = 16,
POS_Z = 17,
ROT_X = 18,
ROT_Y = 19,
ROT_Z = 20,
NO_PARAMETERS = 21,
RDM_ID = 22,
}
local FIXTURETYPE_PROPERTIES = {
NO = 0,
LONG_NAME = 1,
SHORT_NAME = 2,
MANUFACTURER = 3,
SHORT_MANU = 4,
DMX_FOOTPRINT = 5,
INSTANCES = 6,
MODE = 7,
USED = 8,
XYZ = 9,
MODEL = 10,
RDM_FIXTURE_TYPE = 11,
}
local CHANNELTYPE_PROPERTIES = {
NO = 0,
ATTRIB = 1,
BREAK = 2,
COARSE = 3,
FINE = 4,
ULTRA = 5,
DEFAULT = 6,
HIGHLIGHT = 7,
STAGE = 8,
SNAP = 9,
INVERT = 10,
REACT_TO_MASTER = 11,
MIB_DISABLE = 12,
MIB_FADE = 13,
PROFILE = 14,
MODE = 15,
REACT_TO_DIM = 16,
COLOR = 17,
MINIMUM_DMX_TIME = 18,
TRIGGER = 19,
}
local CHANNELFUNCTION_PROPERTIES = {
NO = 0,
SUBATTRIB = 1,
NAME = 2,
WHEEL = 3,
FROM = 4,
TO = 5,
FROM_DMX = 6,
TO_DMX = 7,
FROM_PHYS = 8,
TO_PHYS = 9,
ADDITIONAL_PHYS = 10,
MINIMUM_3D_TIME = 11,
MODE_START = 12,
MODE_END = 13,
}
local PSNTRACKER_PROPERTIES = {
PSN_ID = 0,
FIX_ID = 1,
NAME = 2,
POS_X = 3,
POS_Y = 4,
POS_Z = 5,
ROT_X = 6,
ROT_Y = 7,
ROT_Z = 8,
PREDICT = 9,
}
-- ------------------------------------------------------------------------------
-- Execs
-- ------------------------------------------------------------------------------
local function GoExec(exec_name)
GmaCmd("Go Exec " .. exec_name);
end
local function OffExec(exec_name)
GmaCmd("Off Exec " .. exec_name);
end
local function GoExecCue(exec_name, cue_name)
GmaCmd("Go Exec " .. exec_name .. " Cue " .. cue_name);
end
local function ExecAt(exec_name, value)
GmaCmd("Exec " .. exec_name .. " At " .. value);
end
-- ------------------------------------------------------------------------------
-- Objects methods
-- ------------------------------------------------------------------------------
-- cache handle to root, seems to always be 1
local g_root_handle_cached = nil;
-- get the handle of the root object
-- return the handle of the root object
local function GetRootHandle()
if g_root_handle_cached then
return g_root_handle_cached;
end
local handle = GmaUserGetCmdDest();
while true do
local parent_handle = GmaShowGetObjParent(handle);
if parent_handle == nil then
break;
end
handle = parent_handle;
end
g_root_handle_cached = handle;
return handle;
end
function TestGetRootHandle()
GmaPrint("TestGetRootHandle")
gma.cmd("cd /; cd 10")
local root_handle = GetRootHandle();
if root_handle == nil then
GmaPrint("TestGetRootHandle failed");
else
GmaPrint("TestGetRootHandle succeeded, value is " .. root_handle);
end
-- benchmark the function call
local start_time = os.clock();
local count = 1000;
for _ = 1, count do
GetRootHandle();
end
local end_time = os.clock();
GmaPrint("GetRootHandle takes " .. (end_time - start_time) / count * 1000 .. " ms on average");
gma.cmd("cd /");
end
-- get the handle of an object from its path
-- param path:list(number) path of the object
-- return the handle of the object or nil if the object does not exist
local function GetHandleFromRoot(path)
local handle = GetRootHandle();
for i = 1, #path do
handle = GmaShowGetObjChild(handle, path[i] - 1);
if handle == nil then
GmaPrint("Warning: GetHandleFromPath called with invalid path \"" ..
Array2String(path) .. "\":" .. type(path),
", fail to find object at index " .. i .. " which is " .. path[i]);
return nil;
end
end
return handle;
end
function AZ.TestGetHandleFromPath()
GmaPrint("TestGetHandleFromPath");
GmaPrint("Try to find LIVE_SETUP/LAYERS")
local handle = GetHandleFromRoot({ ROOT_OBJECTS.LIVE_SETUP, LIVE_SETUP_OBJECTS.LAYERS });
if handle == nil then
GmaPrint("Could not find LIVE_SETUP/LAYERS");
else
if GmaShowGetObjClass(handle) == "CMD_FIXTURE_LAYER_COLLECT" then
GmaPrint("Found LIVE_SETUP/LAYERS with handle " .. handle);
else
GmaPrint("Error: Found LIVE_SETUP/LAYERS with handle " ..
handle .. ", but class is " .. GmaShowGetObjClass(handle));
end
end
-- benchmark GetHandleFromRoot
local start_time = os.clock();
local count = 100;
for _ = 1, count do
GetHandleFromRoot({ ROOT_OBJECTS.LIVE_SETUP, LIVE_SETUP_OBJECTS.LAYERS });
end
local end_time = os.clock();
GmaPrint("GetHandleFromRoot takes " .. (end_time - start_time) / count * 1000 .. " ms on average");
end
-- get the handle of an object from its parent
--
-- param parent_handle:number handle of the parent object
-- param child_id:number id of the child object, 1 indexed
--
-- return the handle of the child object or nil if the object does not exist
local function GetChildHandle(handle, child_id)
local ch_amount = GmaShowGetObjAmount(handle);
if child_id < 1 or child_id > ch_amount then
GmaPrint("Invalid child id " .. child_id);
return nil;
end
return GmaShowGetObjChild(handle, child_id - 1);
end
-- ------------------------------------------------------------------------------
-- Subfixtures methods
-- ------------------------------------------------------------------------------
-- get the sub fixture position
-- param sub_fixture_handle:number sub fixture handle. Can be obtained by gma.show.getobj.handle("Fixture 1")
-- Then you need to get the 0 index sub fixture handle by gma.show.getobj.child(fixture_handle, 0)
-- It the caller responsibility to make sure the handle is valid
-- return a table with the following keys:
-- - x:number x position
-- - y:number y position
-- - z:number z position
local function GetSubFixturePosition(sub_fixture_handle)
return {
x = tonumber(GmaShowPropertyValue(sub_fixture_handle, SUBFIXTURE_PROPERTIES.POS_X)),
y = tonumber(GmaShowPropertyValue(sub_fixture_handle, SUBFIXTURE_PROPERTIES.POS_Y)),
z = tonumber(GmaShowPropertyValue(sub_fixture_handle, SUBFIXTURE_PROPERTIES.POS_Z)),
}
end
-- ------------------------------------------------------------------------------
-- Fixture methods
-- ------------------------------------------------------------------------------
--- Get all fixture ids in a group
--- @param group string|integer : group number or name of the group
--- @return table|nil : a list of fixture ids, return nil if the group does not exist or something when wrong
local function GetFixtureIdsInGroup(group)
-- Create a list of int
local fixture_ids = {};
GmaCmd("SelectDrive 1");
local file_name = "aztemp.xml";
local file_path = GmaShowGetVar("PATH") .. "/" .. "importexport" .. "/";
local full_path = file_path .. file_name;
-- Export the group to a file
GmaCmd("Export Group " .. group .. " \"" .. file_name .. "\"");
-- Read the exported file
local file_read = io.open(full_path, "r");
if file_read == nil then
GmaPrint("Could not open file " .. full_path);
return nil;
end
local file_content = file_read:read("*all");
file_read:close();
-- Remove the temp file
os.remove(full_path);
-- Parse the file (which is XML file)
-- We want to match the fix_id in line "<Subfixture fix_id="2003" />"
for match in file_content:gmatch("<Subfixture fix_id=\"(%d+)\" />") do
local number_match = tonumber(match);
if number_match ~= nil then
table.insert(fixture_ids, number_match);
else
GmaPrint("WARNING: Could not convert fix_id " .. match .. " to a number");
end
end
return fixture_ids;
end
function AZ.TestGetFixtureIdsFromGroup(group)
GmaPrint("GetFixtureIdsFromGroup " .. group);
local fixtures = GetFixtureIdsInGroup(group);
if fixtures == nil then
GmaPrint("Could not get fixture ids from group " .. group);
return;
else
for _, fixture_id in ipairs(fixtures) do
GmaPrint("Fixture " .. fixture_id);
end
end
end
-- get the fixture transform
-- param handle:number fixture handle. Can be obtained by gma.show.getobj.handle("Fixture 1")
-- It the caller responsibility to make sure the handle is valid
-- return a table with the following keys:
-- - x:number x position
-- - y:number y position
-- - z:number z position
local function GetFixturePositionFromSubFixture(fixture_handle)
-- position/rotation is a property of the first child of the fixture
-- The fixture also has a property pos/rot, but it is always 0 for some reason
local sub_fixture_handle = GmaShowGetObjChild(fixture_handle, 0);
return GetSubFixturePosition(sub_fixture_handle);
end
-- get the fixture id
--
-- param handle:number fixture handle. Can be obtained by gma.show.getobj.handle("Fixture 1")
-- It the caller responsibility to make sure the handle is valid
-- return the fixture id
local function GetFixtureId(fixture_handle)
return tonumber(GmaShowPropertyValue(fixture_handle, FIXTURE_PROPERTIES.FIX_ID));
end
-- get the fixture type
--
-- param handle:number fixture handle. Can be obtained by gma.show.getobj.handle("Fixture 1")
-- It the caller responsibility to make sure the handle is valid
-- return the fixture type, in the form "15 Mistral Standard"
--
-- Note: You can get the fixture type id by calling GetFixtureTypeIdFromFixtureType
local function GetFixtureType(fixture_handle)
return GmaShowPropertyValue(fixture_handle, FIXTURE_PROPERTIES.FIXTURE_TYPE);
end
-- get the fixture type id.
--
-- param fixture_type:string fixture type, in the form "15 Mistral Standard"
--
-- return number the fixture type id
local function GetFixtureTypeIdFromFixtureType(fixture_type)
-- fixture type is in the form "15 Mistral Standard"
-- we need to extract the number
local fixture_type_id = string.match(fixture_type, "%d+");
return tonumber(fixture_type_id);
end
function AZ.TestGetFixtureTransform()
-- For this test to work you must have a fixture named "Fixture 1"
GmaPrint("TestGetFixtureTransform");
local fixture_name = "Fixture 1"
local handle = GmaShowGetObjHandle(fixture_name);
local fixture_transform = GetFixturePositionFromSubFixture(handle);
GmaPrint("Fixture transform for " .. fixture_name .. ":");
GmaPrintTable(fixture_transform);
-- Run benchmark of function call
local start_time = os.clock();
local count = 1000;
for _ = 1, count do
GetFixturePositionFromSubFixture(handle);
end
local end_time = os.clock();
GmaPrint("GetFixtureTransform takes " .. (end_time - start_time) / count * 1000 .. " ms on average");
end
-- Get the info for a fixture.
--
-- Return a table with the following keys:
-- {
-- position = {
-- x = x_position,
-- y = y_position,
-- z = z_position,
-- },
-- fixture_type_id = fixture_type_id,
-- fixture_id = fixture_id,
-- }
-- The value can also be null if the fixture doesn't have a fixture id
local function GetFixtureInfo(fixture_handle)
local position = GetFixturePositionFromSubFixture(fixture_handle);
local fixture_id = GetFixtureId(fixture_handle);
if fixture_id == nil then
return nil;
end
local fixture_type = GetFixtureType(fixture_handle);
local fixture_type_id = GetFixtureTypeIdFromFixtureType(fixture_type);
return {
fixture_id = fixture_id,
fixture_type_id = fixture_type_id,
position = position,
}
end
-- Get the position of all fixtures.
--
-- The returned table has the following structure:
-- {
-- [fixture_id] = {
-- position = {
-- x = x_position,
-- y = y_position,
-- z = z_position,
-- },
-- fixture_type_id = fixture_type_id,
-- fixture_id = fixture_id,
-- },
-- ...
-- }
local function GetAllFixturesInfo()
local infos = {};
local handle = GetHandleFromRoot({ ROOT_OBJECTS.LIVE_SETUP, LIVE_SETUP_OBJECTS.LAYERS });
local ch_amount = GmaShowGetObjAmount(handle);
-- loop through all layers
-- we ignore child 0 (layer 1 Auto-Created) that doesn't contain fixtures
for i = 1, ch_amount - 1 do
local layer_handle = GmaShowGetObjChild(handle, i);
-- loop through all fixtures in the layer
local fixture_amount = GmaShowGetObjAmount(layer_handle);
for j = 0, fixture_amount - 1 do
local fixture_handle = GmaShowGetObjChild(layer_handle, j);
local info = GetFixtureInfo(fixture_handle);
if info ~= nil then
infos[info.fixture_id] = info;
end
end
end
return infos;
end
function AZ.TestGetAllFixtureInfo()
GmaPrint("TestGetAllFixturePosition");
local start_time = os.clock();
local infos = GetAllFixturesInfo();
local end_time = os.clock();
GmaPrint("GetAllFixturesPosition takes " .. (end_time - start_time) * 1000 .. " ms");
for fixture_id, info in pairs(infos) do
GmaPrint("Fixture " ..
fixture_id ..
" has position " .. Position2String(info.position) .. ", fixturetype id " .. info.fixture_type_id);
end
end
-- Update the fixture positions info cache.
-- This function should be called when the fixture positions change
-- It is the caller responsibility to make sure the cache is updated when needed
--
-- You can call this function from a macro using the following code:
-- LUA "UpdateFixturePositionsCache()"
function AZ.UpdateFixtureInfo()
g_fixture_infos = GetAllFixturesInfo();
if SETTINGS.VERBOSE then
GmaPrint("Fixture positions cache updated");
for fixture_id, info in pairs(g_fixture_infos) do
GmaPrint("Fixture " ..
fixture_id ..
" has position " .. Position2String(info.position) .. ", fixturetype id " .. info.fixture_type_id);
end
end
end
-- ------------------------------------------------------------------------------
-- Fixture types methods
-- ------------------------------------------------------------------------------
local function GetFixtureTypesHandle()
local fixture_types_handle = GetHandleFromRoot({ ROOT_OBJECTS.LIVE_SETUP, LIVE_SETUP_OBJECTS.FIXTURE_TYPES });
if fixture_types_handle == nil then
GmaPrint("Can't find fixture types handle");
return nil;
end
return fixture_types_handle;
end
-- Get the fixture type handle.
--
-- param fixture_type_id:number fixture type id
--
-- return number the fixture type handle
-- return nil if the fixture type id is invalid or the fixture type handle can't be found
local function GetFixtureTypeHandle(fixture_type_id)
local fixture_types_handle = GetFixtureTypesHandle();
return GetChildHandle(fixture_types_handle, fixture_type_id);
end
local function GetFixtureTypeModulesHandle(fixture_type_handle)
return GetChildHandle(fixture_type_handle, FIXTURE_TYPE_OBJECTS.MODULES);
end
-- Get the module handle of a fixture type.
-- We assume the module is the first child of the fixture type.
--
-- param modules_handle:number the modules handle, can be obtained by calling GetFixtureTypeModulesHandle
-- param module_id:number the module id. The main module is MAIN_MODULE_ID
--
-- return number the module handle
local function GetFixtureTypeModuleHandle(modules_handle, module_id)
return GetChildHandle(modules_handle, module_id);
end
-- Get the channel type of a module attribute.
--
-- param module_handle:number module handle. The handle can be obtained by calling GetFixtureTypeMainModule
-- param attribute_name:string the attribute name, e.g. "Pan"
local function GetModuleChannelTypeHandle(module_handle, attribute_name)
GmaPrint("GetModuleChannelTypeHandle: " .. attribute_name);
local ch_amount = GmaShowGetObjAmount(module_handle);
-- loop through all ChannelType until we find the one with the same name as attribute_name
for i = 0, ch_amount - 1 do
local channel_type_handle = GmaShowGetObjChild(module_handle, i);
local attrib_value = GmaShowPropertyValue(channel_type_handle, CHANNELTYPE_PROPERTIES.ATTRIB)
if attrib_value == attribute_name then
return channel_type_handle;
end
end
return nil
end
function AZ.TestGetModuleChannelType()
local fixture = "Fixture 1";
local attrib = "Zoom";
local fixture_type_id = GetFixtureTypeIdFromFixtureType(GetFixtureType(GmaShowGetObjHandle(fixture)))
local fixture_type_handle = GetFixtureTypeHandle(fixture_type_id);
local modules_handle = GetFixtureTypeModulesHandle(fixture_type_handle);
local module_handle = GetFixtureTypeModuleHandle(modules_handle, MAIN_MODULE_ID);
local channel_type_handle = GetModuleChannelTypeHandle(module_handle, "ZOOM (Zoom)");
if channel_type_handle == nil then
GmaPrint("Can't find channel type handle for attribute " .. attrib);
else
GmaPrint("Channel type handle is " .. channel_type_handle .. " for attribute " .. attrib);
GmaPrintObject(channel_type_handle);