This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
forked from Inversil/LESosx
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
LESmain.lua
2462 lines (2197 loc) · 105 KB
/
LESmain.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
require("helpers")
require("menus.keys.menu")
require("menus.keys.chords")
require("menus.keys.scales")
require("globals.filepaths")
version = "release v15" -- allows users to check the version of the script file by testing the variable "version" in the console
if console then
console:close()
end -- if the console is up, close the console. This workaround prevents hammerspoon from shoving the console in your face at startup.
----------------------
-- Initialisation --
----------------------
-- Hammerspoon's default behavior is to look for an init.lua file in the ~/.les filder; otherwise it will show a popup with a getting started guide.
-- The modified LES .app package will instead drop the included /Contents/Resources/init.lua into the right spot and force hammerspoon to restart; causing it to check for the init.lua file again (which now exists)
-- This init.lua file redirects back to the application folder and opens LESmain.lua (this file) inside the app bundle.
-- This is a super janky way to go about including a script inside a hammerspoon package...
-- ...but it saved me from installing xcode and other tools nescesary to recompile hammerspoon. My old 2011 macbook air doesn't have enough space for them so this'll have to do.
-- the initial section of my shitty install code can be found in the .app/contents/resources/extensions/hs/_coresetup/init.lua around line 540.
-- and the actual redirect can be found inside your hammerspoon folder or at /Contents/Resources/init.lua
function testfirstrun() -- tests if "firstrun.txt" exists. I use this text file on both mac and windows to keep track of the current version.
local filepath = GetDataPath("resources/firstrun.txt")
local f = io.open(filepath, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
if testfirstrun() == false then -- stuff to do when you start the program for the first time
print("This is the first time running LES")
function setautoadd(newval) -- declaring the function that replaces the "addtostartup" variable in the settings text file to match the users' dialog box selection.
local hFile = io.open(GetDataPath("settings.ini"), "r") -- Reading settings.
local restOfFile
local lineCt = 1
local newline = "addtostartup = " .. newval .. [[]]
local lines = {}
for line in hFile:lines() do
if string.find(line, "addtostartup =") then -- Is this the line to modify?
-- print(newline)
lines[#lines + 1] = newline -- Change old line into new line.
restOfFile = hFile:read("*a")
break
else
lineCt = lineCt + 1
lines[#lines + 1] = line
end
end
hFile:close()
hFile = io.open(GetDataPath("settings.ini"), "w") -- write the file.
for i, line in ipairs(lines) do
hFile:write(line, "\n")
end
hFile:write(restOfFile)
hFile:close()
end
ShellCreateDirectory(ScriptUserResourcesPath)
-- Making sure the section of this script doesn't trigger twice
ShellCreateEmptyFile(JoinPaths(ScriptUserResourcesPath, FirstRun))
-- Enables strict time by default
ShellCreateEmptyFile(JoinPaths(ScriptUserResourcesPath, StrictTimeModifier))
ShellCopy(GetBundleAssetsPath(ConfigFile), ScriptUserPath .. PathDelimiter)
ShellCopy(GetBundleAssetsPath(MenuConfigFile), ScriptUserPath .. PathDelimiter)
ShellCopy(GetBundleAssetsPath("readmejingle.ini"), ScriptUserPath .. PathDelimiter)
b, t, o = hs.osascript.applescript(
[[tell application "System Events" to display dialog "You're all set! Would you like to set LES to launch on login? (this can be changed later)" buttons {"Yes", "No"} default button "No" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath)
-- I'm using applescript to create dialog boxes, becuase it gives me more options about how to present them. I only keep the user's "option", the other variables are basically always cleared right after to save memory.
print(o)
b = nil
t = nil
if o == [[{ 'bhit':'utxt'("Yes") }]] then
setautoadd(1) -- execute that function
elseif o == [[{ 'bhit':'utxt'("No") }]] then
setautoadd(0)
end
end
----------------
-- Updating --
----------------
-- updating LES using the installer basically only replaces the .app file in your applications folder with the new one.
-- this area of the script makes sure that the init.lua script file is replaced again if I ever make a change to it.
-- the init.lua file is not THIS file, it's the redirect that's dropped into ~/.les.
function testcurrentversion(ver)
print("testing for: " .. ver)
local filepath = GetDataPath("resources/version.txt")
local boi = io.open(filepath, "r") -- some of my variable names are super dumb; "version" was already in use so "boi" seemed like the next best choice?
if boi ~= nil then
local versionarr = {}
for line in boi:lines() do
table.insert(versionarr, line);
end
for i = 1, 1, 1 do
if string.match(versionarr[i], ver) then
return true
else
return false
end
end
io.close(boi)
return false
else
ShellOverwriteFile("beta 9", JoinPaths(ScriptUserResourcesPath, VersionFile))
return true
end
end
if testcurrentversion("beta 9") == false and testfirstrun() == true then -- this section of the code basically checks if your .app version is different from the version already in the dir.
hs.notify.show("Live Enhancement Suite", "Updating and restarting...", "Old installation detected")
local var = hs.osascript.applescript([[delay 2]])
if var == true then
ShellOverwriteFile("beta 9", JoinPaths(ScriptUserPath, JoinPaths("resources", "version.txt")))
ShellCopy(JoinPaths(BundleResourcePath, ScriptInitFile), ScriptUserPath .. PathDelimiter)
hs.alert.show("Restarting..")
hs.osascript.applescript([[delay 2]])
hs.reload()
end
end
------------------------
-- Integrity checks --
------------------------
-- these functions check the if the files nescesary for the script to function; exist.
-- hammerspoon completely spaces out of they don't.
-- I declare them up here because it fits the theme of this section of the script.
function testsettings()
local filepath = GetDataPath("settings.ini")
local f = io.open(filepath, "r")
local var = nil
if f ~= nil then
io.close(f)
var = true
else
var = false
end
if var == false then
b, t, o = hs.osascript.applescript(
[[tell application "System Events" to display dialog "Your settings.ini is missing or corrupt." & return & "Do you want to restore the default settings?" buttons {"Yes", "No"} default button "Yes" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath)
print(o)
b = nil
t = nil
if o == [[{ 'bhit':'utxt'("Yes") }]] then
ShellCopy(GetBundleAssetsPath(ConfigFile), ScriptUserPath .. PathDelimiter)
elseif o == [[{ 'bhit':'utxt'("No") }]] then
os.exit()
end
o = nil
end
end
function testmenuconfig()
local filepath = GetDataPath("menuconfig.ini")
local f = io.open(filepath, "r")
local var = nil
if f ~= nil then
io.close(f)
var = true
else
var = false
end
if var == false then
b, t, o = hs.osascript.applescript(
[[tell application "System Events" to display dialog "Your menuconfig.ini is missing or corrupt." & return & "Do you want to restore the default menuconfig?" buttons {"Yes", "No"} default button "Yes" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath)
print(o)
b = nil
t = nil
if o == [[{ 'bhit':'utxt'("Yes") }]] then
ShellCopy(JoinPaths(BundleResourcePath, MenuConfigFile), ScriptUserPath .. PathDelimiter)
elseif o == [[{ 'bhit':'utxt'("No") }]] then
os.exit()
end
o = nil
end
end
---------------------------
-- Stock menu contents --
---------------------------
-- these are the tables that store the contents of both menubars
-- I was too lazy to make a script that changes the table contents so there's just two tables, one for when there's debug, and one for when there's not.
menubarwithdebugoff = {{
title = "Configure Menu",
fn = function()
ShellNSOpen(JoinPaths(ScriptUserPath, "menuconfig.ini"), "TextEdit")
end
}, {
title = "Configure Settings",
fn = function()
ShellNSOpen(JoinPaths(ScriptUserPath, "settings.ini"), "TextEdit")
end
}, {title = "-"}, {
title = "Donate",
fn = function()
hs.osascript.applescript([[open location "https://www.paypal.me/enhancementsuite"]])
end
}, {title = "-"}, {
title = "Project Time",
fn = function()
requesttime()
end
}, {
title = "Strict Time",
fn = function()
setstricttime()
end
}, {title = "-"}, {
title = "Reload",
fn = function()
reloadLES()
end
}, {
title = "Install InsertWhere",
fn = function()
InstallInsertWhere()
end
}, {
title = "Manual",
fn = function()
hs.osascript.applescript([[open location "https://docs.enhancementsuite.me"]])
end
}, {
title = "Exit",
fn = function()
if trackname then
coolfunc();
end
os.exit()
end
}}
menubartabledebugon = {{
title = "Console",
fn = function()
hs.openConsole(true)
end
}, {
title = "Restart",
fn = function()
if trackname then
coolfunc();
end
hs.reload()
end
}, {
title = "Open Hammerspoon Folder",
fn = function()
ShellNSOpen(ScriptUserPath, "Finder")
end
}, {title = "-"}, {
title = "Configure Menu",
fn = function()
ShellNSOpen(JoinPaths(ScriptUserPath, "menuconfig.ini"), "TextEdit")
end
}, {
title = "Configure Settings",
fn = function()
ShellNSOpen(JoinPaths(ScriptUserPath, "settings.ini"), "TextEdit")
end
}, {title = "-"}, {
title = "Donate",
fn = function()
hs.osascript.applescript([[open location "https://www.paypal.me/enhancementsuite"]])
end
}, {title = "-"}, {
title = "Project Time",
fn = function()
requesttime()
end
}, {
title = "Strict Time",
fn = function()
setstricttime()
end
}, {title = "-"}, {
title = "Reload",
fn = function()
reloadLES()
end
}, {
title = "Install InsertWhere",
fn = function()
InstallInsertWhere()
end
}, {
title = "Manual",
fn = function()
hs.osascript.applescript([[open location "https://docs.enhancementsuite.me"]])
end
}, {
title = "Exit",
fn = function()
if trackname then
coolfunc();
end
os.exit()
end
}}
filepath = GetDataPath("resources/strict.txt")
f = io.open(filepath, "r")
if f ~= nil then
io.close(f)
_G.stricttimevar = true
menubarwithdebugoff[7].state = "on"
menubartabledebugon[11].state = "on"
else
_G.stricttimevar = false
menubarwithdebugoff[7].state = "off"
menubartabledebugon[11].state = "off"
end
f = nil
filepath = nil -- sets the strict time setting
-- this is what happens when you hit "readme" in the default plugin menu.
function readme()
local readmejingleobj = hs.sound.getByFile(GetDataPath("resources/readmejingle.wav"))
readmejingleobj:device(nil)
readmejingleobj:loopSound(false)
readmejingleobj:play()
local bigboyvar = hs.osascript.applescript(
[[tell application "Live Enhancement Suite" to display dialog "Welcome to the Live Enhancement Suite MacOS rewrite developed by @InvertedSilence, @DirectOfficial, with an installer by @actuallyjamez 🐦" & return & "Double right click to open up the custom plug-in menu." & return & "Click on the LES logo in the menu bar to add your own plug-ins, change settings, and read our manual." & return & "Happy producing : )" buttons {"Ok"} default button "Ok" with title "Live Enhancement Suite"]])
readmejingleobj = nil
bigboyvar = nil
end
-------------------------------------
-- digesting the menuconfig file --
-------------------------------------
-- Direct helped make me recreate the original AHK menu file parser in lua before I got started on the project.
-- While it's the first part of the program we made, it's the last thing that worked.
-- This part of the code will always be difficult to comprehend for me, so I figure it's basically impossible to understand you.
-- Turn back while you still can.
-- notice how I'm just declaring function; it's executed later when I run reloadLES().
function buildPluginMenu()
file = io.open("menuconfig.ini", "r")
local arr = {}
for line in file:lines() do
table.insert(arr, line);
end -- this part of the code puts the entire config file into a table.
if pluginArray ~= nil then
delcount = #pluginArray -- delete plugin list table if there's something in it, to prevent double entries when using reloadLES()
for i = 0, delcount do
pluginArray[i] = nil
end
end
if menu ~= nil then
delcount = #menu -- delete the root menu table if there's something in it, to prevent double entries when using reloadLES()
for i = 0, delcount do
menu[i] = nil
end
end
-- Reverses the Array. This could be done inline
-- but I made it a helper function just in case.
-- -- Direct
function Reverse(arr)
local i, j = 1, #arr
while i < j do
arr[i], arr[j] = arr[j], arr[i]
i = i + 1
j = j - 1
end
end
-- Reverse the order of the array.
print(hs.inspect(arr))
Reverse(arr)
readmevar = false
for i = #arr, 1, -1 -- this part of the code replaces parts of the menu config file with stuff that's easier to parse in lua.
do
arr[i] = string.gsub(arr[i], "“", "\"")
if arr[i] == "—\r" or arr[i] == "-\n" or arr[i] == "—" then
print("divider line found")
arr[i] = "--"
table.insert(arr, i, "--")
elseif string.len(arr[i]) < 2 and not string.match(arr[i], "%w") then -- this is a bandaid fix preventing lots of empty menu entires
table.remove(arr, i)
elseif arr[i] == nil then
table.remove(arr, i)
elseif string.find(arr[i], ";") == 1 then
table.remove(arr, i)
elseif string.match(arr[i], "Readme") or string.match(arr[i], "readme") then
readmevar = true -- I decided to just have the readme always stick on the bottom since it was easier to program and nobody cares anyway :^)
table.remove(arr, i)
elseif string.find(arr[i], "%-%-") == 1 then
table.insert(arr, i, "--")
elseif string.find(arr[i], "End") then
table.remove(arr, i)
elseif string.find(arr[i], "") then
end
end
local subfolderval = 0
local subfoldername = ""
local subfolderuponelevel = ""
subfolderhistory = {}
pluginArray = {}
for i = #arr, 1, -1 do
if string.find(string.sub(arr[i], 1, 1), "/") and not string.find(string.sub(arr[i], 1, 2), "//") and
not string.find(arr[i], "nocategory") then
subfoldername = string.gsub(arr[i], '', '')
table.insert(subfolderhistory, subfoldername)
subfolderval = 1
string = subfolderval .. ", " .. subfoldername .. ", " .. "❗️"
table.insert(pluginArray, string)
table.insert(pluginArray, string)
table.remove(arr, i)
elseif string.find(string.sub(arr[i], 1, 2), "//") then
table.insert(subfolderhistory, subfoldername)
subfoldername = string.gsub(arr[i], '', '')
local _, count = string.gsub(arr[i], "%/", "")
subfolderval = count
string = subfolderval .. ", " .. subfoldername .. ", " .. "❗️"
table.insert(pluginArray, string)
table.insert(pluginArray, string)
table.remove(arr, i)
elseif string.find(string.sub(arr[i], 1, 2), "%.%.") then
subfoldername = subfolderhistory[subfolderval]
subfolderval = subfolderval - 1
-- table.remove(arr, i)
-- table.insert(arr[i])
elseif string.find(arr[i], "/nocategory") then
subfolderval = 0
table.remove(arr, i)
else
string = subfolderval .. ", " .. subfoldername .. ", " .. arr[i]
table.insert(pluginArray, string)
end
end
print("------pluginarray-----")
print(hs.inspect(pluginArray))
print("----------------------")
function mysplit(inputstr)
local t = {};
i = 1
if inputstr == nil then
return
end
for str in string.gmatch(inputstr, "([^,]+)") do
t[i] = str
i = i + 1
end
return t
end
-- for i = 1, #arr do
-- print(pluginArray[i])
-- end
function RemoveSlashes(string, scope)
newstring = string:gsub("^%s*(.-)%s*$", "%1")
newstring = string.sub(newstring, scope + 1)
return newstring
end
local lastLevel = 0
local level = 0
lastcatagoryName = "menu"
scopes = {}
for i = 1, #pluginArray, 2 do
if pluginArray[i] == nil then
table.remove(pluginArray, i)
goto pls
end
if pluginArray[i + 1] == nil then
table.remove(pluginArray, (i + 1))
goto pls
end
-- print(hs.inspect(scopes))
local level = tonumber(string.sub(pluginArray[i], 1, 1))
local thisIndex = mysplit(pluginArray[i])
local nextIndex = mysplit(pluginArray[i + 1])
local categoryName = RemoveSlashes(thisIndex[2], level)
-- RUNS RIGHT AT THE START IF A PLUGIN IS INSERTED FIRST IN THE MENU
if i == 1 and level == 0 then
if _G[lastcatagoryName] == nil then
_G[lastcatagoryName] = {}
end
if string.find(string.sub(pluginArray[i], 1, 2), "%-%-") or
string.find(string.sub(pluginArray[i], 1, 2), "—") then
table.insert(_G[lastcatagoryName], {title = "-"})
else
table.insert(_G[lastcatagoryName], {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}) -- inserts the first plugin
print("START. current scope: " .. categoryName .. " level: " .. level .. "item: " .. nextIndex[3])
end
-- RUNS RIGHT AT THE START IF A FOLDER IS INSERTED FIRST IN THE MENU
elseif i == 1 and level == 1 then
if _G[lastcatagoryName] == nil then
_G[lastcatagoryName] = {}
end
print("START : NEW FOLDER. current scope: " .. categoryName .. " level: " .. level .. "item: " ..
nextIndex[3])
if string.find(nextIndex[3], "❗️") then
_G[categoryName] = {} -- don't insert the !
else
_G[categoryName] = {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}
end
if string.find(string.sub(pluginArray[i], 1, 2), "%-%-") or
string.find(string.sub(pluginArray[i], 1, 2), "-") then
table.insert(_G[lastcatagoryName], {title = "-"})
else
table.insert(_G[lastcatagoryName], {title = categoryName, menu = _G[categoryName]})
-- table.insert(_G[lastcatagoryName], {title = string.sub(thisIndex[3],2), fn = function() loadPlugin(nextIndex[3]) end }) -- inserts the first plugin
end
table.insert(scopes, lastcatagoryName)
-- THIS IS IF WE GO BACK TO THE ROOT FOLDER AFTER BEING IN A SUBFOLDER
elseif level == 0 then
if string.find(string.sub(thisIndex[3], 1, 4), "%-%-") or
string.find(string.sub(thisIndex[3], 1, 4), "%—") then
table.insert(menu, {title = "-"})
else
print(string.sub(pluginArray[i], 1, 4))
table.insert(menu, {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}) -- inserts the first plugin
print("RETURN TO ROOT. current scope: " .. categoryName .. " level: " .. level .. "item: " ..
nextIndex[3])
end
-- Up scope
elseif level > lastLevel then
print("UP SCOPE. current scope: " .. categoryName .. " level: " .. level .. "item: " .. nextIndex[3])
if _G[lastcatagoryName] == nil then
_G[lastcatagoryName] = {}
end
if string.find(nextIndex[3], "❗️") then
_G[categoryName] = {}
else
_G[categoryName] = {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}
end
if string.find(string.sub(pluginArray[i], 1, 2), "%-%-") or
string.find(string.sub(pluginArray[i], 1, 2), "—") then
table.insert(_G[lastcatagoryName], {title = "-"})
else
table.insert(_G[lastcatagoryName], {title = categoryName, menu = _G[categoryName]}) -- Inserts the new menu
end
table.insert(scopes, lastcatagoryName)
-- Same scope
elseif level == lastLevel and categoryName == lastcatagoryName then
print("SAME SCOPE. current scope: " .. categoryName .. " level: " .. level .. "item: " .. nextIndex[3])
if string.find(pluginArray[i], "%-%-") or string.find(pluginArray[i], "—") then
table.insert(_G[categoryName], {title = "-"})
else
table.insert(_G[categoryName], {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}) -- inserts plugin
end
-- Same scope new folder
elseif level == lastLevel and categoryName ~= lastcatagoryName then
print("scopes: " .. scopes[level])
table.remove(scopes, level + 1)
if _G[categoryName] == nil then
_G[categoryName] = {}
end
if string.find(string.sub(pluginArray[i], 1, 2), "%-%-") or
string.find(string.sub(pluginArray[i], 1, 2), "—") then
table.insert(_G[scopes[level]], {title = "-"})
else
table.insert(_G[scopes[level]], {title = categoryName, menu = _G[categoryName]}) -- Inserts the new menu
end
print("SAME SCOPE NEW FOLDER. current scope: " .. categoryName .. " level: " .. level .. "item: " ..
nextIndex[3])
-- Down scope with new folder
elseif level < lastLevel and categoryName ~= lastcatagoryName then
print("DOWN SCOPE NEW FOLDER. current scope: " .. categoryName .. " level: " .. level .. "item: " ..
nextIndex[3])
print("scopes: " .. scopes[level])
if scopes[level] == "menu" then
scopes = {"menu"}
end
-- table.insert(scopes, lastcatagoryName)
if _G[categoryName] == nil then
_G[categoryName] = {}
table.insert(_G[scopes[level]], {title = categoryName, menu = _G[categoryName]}) -- Inserts the new menu
end
if string.find(string.sub(pluginArray[i], 1, 2), "%-%-") or
string.find(string.sub(pluginArray[i], 1, 2), "—") then
table.insert(_G[categoryName], {title = "-"})
else
if string.find(nextIndex[3], "❗️") then
table.insert(_G[categoryName], {}) -- inserts plugin
else
table.insert(_G[categoryName], {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}) -- inserts plugin
end
end
-- Down scope
elseif level < lastLevel and categoryName == lastcatagoryName then
print("DOWN SCOPE. current scope: " .. categoryName .. " level: " .. level .. "item: " .. nextIndex[3])
if _G[categoryName] == nil then
_G[categoryName] = {}
end
if string.find(string.sub(pluginArray[i], 1, 2), "%-%-") or
string.find(string.sub(pluginArray[i], 1, 2), "—") then
table.insert(_G[categoryName], {title = "-"})
else
table.insert(_G[categoryName], {
title = string.sub(thisIndex[3], 2),
fn = function()
loadPlugin(nextIndex[3])
end
}) -- inserts plugin
end
end
lastLevel = level
-- this conditional basically checks if we are 'home' and if we are
-- then we last category = menu.
if categorycount == nil then
categorycount = 0 -- 0 because the count is increased to 1 by the first item causing the first entry to be nil (it's a stupid workaround)
categoryhistory = {}
end
if lastLevel == 0 then
lastcatagoryName = "menu"
else
if lastcatagoryName ~= nil then -- this part of the code keeps track of all the subfolder names, so they can be cleared later; preventing double entires on reloadLES()
if lastcatagoryName ~= categoryName then
categorycount = (categorycount + 1)
end
end
lastcatagoryName = categoryName
categoryhistory[categorycount] = lastcatagoryName
end
::pls::
end
if readmevar == true then
-- table.insert(menu, {title = "-"})
table.insert(menu, {
title = "read me",
fn = function()
readme()
end
})
end
categoryName = nil
lastcatagoryName = nil
lastlevel = nil
level = nil
scope = nil
categorycount = nil
end
function clearcategories()
-- this part of the code goes back through the folder structure history created around line 585 to clear all folders it before rebuilding the menu again.
-- this prevents double entries from showing up after reloadLES() was executed.
if categoryhistory ~= nil then
print("category history exists")
for i = 1, #categoryhistory, 1 do
_G[categoryhistory[i]] = nil
end
categoryhistory = nil
end
end
-----------------------------------
-- Digesting the settings file --
-----------------------------------
function settingserrorbinary(message, range) -- this is a generic error message box function so I didn't have to write this long line out every time
if hs.osascript.applescript(
[[tell application "System Events" to display dialog "Error found in settings.ini" & return & "Value for \"]] ..
message .. [[\" is not ]] .. range ..
[[." buttons {"Ok"} default button "Ok" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath) then
ShellNSOpen(JoinPaths(ScriptUserPath, "settings.ini"), "TextEdit")
os.exit()
end
end
function msgBox(message) -- another generic message box function. I only used it once; that's why it's still here.
msgboxscript = [[display dialog "]] .. message ..
[[" buttons {"ok"} default button "ok" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath
local b, t, o = hs.osascript.applescript(msgboxscript)
b = nil
t = nil
if o == [[{ 'bhit':'utxt'("ok") }]] then
return true
else
return false
end
end
function buildSettings() -- this function digests the settings.ini file.
if settingsArray ~= nil then -- if there's something left in the settings file table
delcount = #settingsArray -- delete the table (to prevent problems when using reloadLES() )
for i = 0, delcount do
settingsArray[i] = nil
end
end
scaling = 0
settings = io.open("settings.ini", "r")
settingsArray = {}
for line in settings:lines() do
table.insert(settingsArray, line)
end -- put the settings file into a table
for i = 1, #settingsArray, 1 do
::loopstart:: -- this is a LUA goto. yes, you're seeting this right; I used a goto
if i > #settingsArray then
break
end
if settingsArray[i] == nil then -- if the line is empty, skip it.
table.remove(settingsArray, i)
elseif string.find(settingsArray[i], ";") == 1 then -- if the line is an ahk comment, skip it
table.remove(settingsArray, i)
i = i + 1
goto loopstart
elseif string.find(settingsArray[i], "End") then -- if the line is End, skip the entry and mark the line as empty.
table.remove(settingsArray, i)
i = i + 1
goto loopstart
end
-- below this part you're going to find a bunch of repeat code with slight variations for every settings menu item.
-- I could've turned it into a function, that would've been neater; since I deal with some options differently this would've also been a hassle.
-- luckily, I kept all of the settings routines in the same order as the order of variables in the default settings file, so it should be easy to find each entry.
if string.find(settingsArray[i], "autoadd =") then
print("autoadd found")
_G.autoadd = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.autoadd, "%D") then
settingserrorbinary("autoadd", "a number between 0 and 1")
end
_G.autoadd = tonumber(_G.autoadd)
if _G.autoadd > 1 or _G.autoadd < 0 then
settingserrorbinary("autoadd", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "loadspeed =") then
print("loadspeed found")
_G.loadspeed = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.find(_G.loadspeed, "%D%.") then
settingserrorbinary("loadspeed", "a number")
end
_G.loadspeed = tonumber(_G.loadspeed)
if _G.loadspeed < 0 then
settingserrorbinary("loadspeed", "a number higher than 0")
end
end
if string.find(settingsArray[i], "resettobrowserbookmark =") then
print("resettobrowserbookmark found")
_G.resettobrowserbookmark = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.find(_G.resettobrowserbookmark, "%D%.") then
settingserrorbinary("resettobrowserbookmark", "a number")
end
_G.resettobrowserbookmark = tonumber(_G.resettobrowserbookmark)
if _G.resettobrowserbookmark < 0 then
settingserrorbinary("resettobrowserbookmark", "a number higher than 0")
end
end
if string.find(settingsArray[i], "bookmarkx =") then
_G.bookmarkx = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
print("bookmarkx found")
if string.find(_G.bookmarkx, "%D%.") then
settingserrorbinary("bookmarkx", "a number")
end
_G.bookmarkx = tonumber(_G.bookmarkx)
if _G.bookmarkx < 0 then
settingserrorbinary("bookmarkx", "a number higher than 0")
end
end
if string.find(settingsArray[i], "bookmarky =") then
_G.bookmarky = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
print("bookmarky found")
if string.find(_G.bookmarky, "%D%.") then
settingserrorbinary("bookmarky", "a number")
end
_G.bookmarky = tonumber(_G.bookmarky)
if _G.bookmarky < 0 then
settingserrorbinary("bookmarky", "a number higher than 0")
end
end
if string.find(settingsArray[i], "disableloop =") then
print("disableloop found")
_G.disableloop = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.disableloop, "%D") then
settingserrorbinary("disableloop", "a number between 0 and 1")
end
_G.disableloop = tonumber(_G.disableloop)
if _G.disableloop > 1 or _G.disableloop < 0 then
settingserrorbinary("disableloop", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "saveasnewver =") then
print("saveasnewver found")
_G.saveasnewver = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.saveasnewver, "%D") then
settingserrorbinary("saveasnewver", "a number between 0 and 1")
end
_G.saveasnewver = tonumber(_G.saveasnewver)
if _G.saveasnewver > 1 or _G.saveasnewver < 0 then
settingserrorbinary("saveasnewver", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "altgrmarker =") then
print("altgrmarker found")
_G.altgrmarker = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.altgrmarker, "%D") then
settingserrorbinary("altgrmarker", "a number between 0 and 1")
end
_G.altgrmarker = tonumber(_G.altgrmarker)
if _G.altgrmarker > 1 or _G.altgrmarker < 0 then
settingserrorbinary("altgrmarker", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "double0todelete =") then
print("double0todelete found")
_G.double0todelete = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.double0todelete, "%D") then
settingserrorbinary("double0todelete", "a number between 0 and 1")
end
_G.double0todelete = tonumber(_G.double0todelete)
msgboxscript = [[display dialog "]] .. _G.double0todelete ..
[[" buttons {"ok"} default button "ok" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath
if _G.double0todelete > 1 or _G.double0todelete < 0 then
settingserrorbinary("double0todelete", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "absolutereplace =") then
print("absolutereplace found")
_G.absolutereplace = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.absolutereplace, "%D") then
settingserrorbinary("absolutereplace", "a number between 0 and 1")
end
_G.absolutereplace = tonumber(_G.absolutereplace)
if _G.absolutereplace > 1 or _G.absolutereplace < 0 then
settingserrorbinary("absolutereplace", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "enableclosewindow =") then
print("enableclosewindow found")
_G.enableclosewindow = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.enableclosewindow, "%D") then
settingserrorbinary("enableclosewindow", "a number between 0 and 1")
end
_G.enableclosewindow = tonumber(_G.enableclosewindow)
if _G.enableclosewindow > 1 or _G.enableclosewindow < 0 then
settingserrorbinary("enableclosewindow", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "vstshortcuts =") then
print("vstshortcuts found")
_G.vstshortcuts = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.vstshortcuts, "%D") then
settingserrorbinary("vstshortcuts", "a number between 0 and 1")
end
_G.vstshortcuts = tonumber(_G.vstshortcuts)
if _G.vstshortcuts > 1 or _G.vstshortcuts < 0 then
settingserrorbinary("vstshortcuts", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "ctrlabsoluteduplicate =") then
print("ctrlabsoluteduplicate found")
_G.ctrlabsoluteduplicate = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.ctrlabsoluteduplicate, "%D") then
settingserrorbinary("ctrlabsoluteduplicate", "a number between 0 and 1")
end
_G.ctrlabsoluteduplicate = tonumber(_G.ctrlabsoluteduplicate)
if _G.ctrlabsoluteduplicate > 1 or _G.ctrlabsoluteduplicate < 0 then
settingserrorbinary("ctrlabsoluteduplicate", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "pianorollmacro =") then
print("pianorollmacro found")
if hs.keycodes.map[settingsArray[i]:gsub(".*(.*)%=%s", "%1")] == nil and _G.nomacro == nil then -- checks if the entered key exists on the keyboard.
-- there is an alternate error message here because the generic one confused too many people.
hs.osascript.applescript(
[[tell application "System Events" to display dialog "Hey! The settings entry for \"pianorollmacro\" is not a character corresponding to a key on your keyboard." & return & "" & return & "Closing this dialog box will open the settings file for you; please change the character under \"pianorollmacro\" to a key that exists on your keyboard and then restart the program. You won't be able to properly use many features without it." & return & "" & return & "LES will continue to run without a proper pianoroll macro mapped." buttons {"Ok"} default button "Ok" with title "Live Enhancement Suite" with icon POSIX file ]] ..
BundleIconPath)
ShellNSOpen(JoinPaths(ScriptUserPath, "settings.ini"), "TextEdit")
_G.nomacro = true -- a variable that keeps track of whether or not there's a working macro, functions that use it will be excluded when there's not.
else
_G.pianorollmacro = hs.keycodes.map[settingsArray[i]:gsub(".*(.*)%=%s", "%1")]
_G.nomacro = false
end
end
if string.find(settingsArray[i], "dynamicreload =") then
print("dynamicreload found")
_G.dynamicreload = settingsArray[i]:gsub(".*(.*)%=%s", "%1")
if string.match(_G.dynamicreload, "%D") then
settingserrorbinary("dynamicreload", "a number between 0 and 1")
end
_G.dynamicreload = tonumber(_G.dynamicreload)
if _G.dynamicreload > 1 or _G.dynamicreload < 0 then
settingserrorbinary("dynamicreload", "a number between 0 and 1")
end
end
if string.find(settingsArray[i], "enabledebug =") then
print("enabledebug found")