-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathharp_pedal_wizard.lua
1596 lines (1516 loc) · 74.9 KB
/
harp_pedal_wizard.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
function plugindef()
finaleplugin.RequireSelection = false
finaleplugin.Author = "Jacob Winkler"
finaleplugin.Copyright = "2022"
finaleplugin.Version = "2.0.3"
finaleplugin.Date = "2024-01-15"
finaleplugin.HandlesUndo = true
finaleplugin.MinJWLuaVersion = 0.63 -- https://robertgpatterson.com/-fininfo/-rgplua/rgplua.html
return "Harp Pedal Wizard...", "Harp Pedal Wizard", "Creates Harp Diagrams and Pedal Changes"
end
-- just for now
-- luacheck: no global, no unused
local library = require("library.general_library")
local configuration = require("library.configuration")
--------------------------------------
-- borrowed JetStream function
function remove_spaces_in_windows_os(standard_name)
local font_name = standard_name
local ui = finenv.UI()
if ui:IsOnWindows() then
font_name = string.gsub(standard_name, "%s", "")
end
return font_name
end
--------------------------------------
function harp_pedal_wizard()
local script_name = "harp_pedal_wizard"
local config = {root = 2, accidental = 1, scale = 0, scale_check = 1, chord = 0, chord_check = 0, diagram_check = 1, names_check = 0, partial_check = 0, stack = 1, pedal_lanes = 1, last_notes = "D, C, B, E, F, G, A"}
local partial = false
local changes = false
local stack = true
local pedal_lanes = true
local direct = false
local override = false
context = context or -- keep context as global so that it survives across calls
{
window_pos_x = nil,
window_pos_y = nil
}
local SMuFL = library.is_font_smufl_font(nil)
harpstrings = {}
diagram_string = finale.FCString()
description = finale.FCString()
local changes_str = finale.FCString()
changes_str.LuaString = ""
local default_music_font = library.get_default_music_font_name()
local diagram_font = "^fontTxt(" .. default_music_font .. ")"
--
local flat_char = utf8.char(0xe680) -- SMuFL: Harp pedal raised (flat)
local nat_char = utf8.char(0xe681) -- SMuFL: Harp pedal centered (natural)
local sharp_char = utf8.char(0xe682) -- SMuFL: Harp pedal lowered (sharp)
local divider_char = utf8.char(0xe683) -- SMuFL: Harp pedal divider
local desc_prefix = finale.FCString()
desc_prefix.LuaString = ""
local ui = finenv.UI()
local direct_notes = {0, 0, 0, 0, 0, 0, 0}
configuration.get_user_settings(script_name, config, true)
function split(s, delimiter)
result = {};
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match);
end
return result;
end
function trim(s)
return s:match'^()%s*$' and '' or s:match'^%s*(.*%S)'
end
function process_return(harpnotes)
local is_error = false
direct_notes = {0, 0, 0, 0, 0, 0, 0}
--
local harp_tbl = split(harpnotes, ",")
local count = 0
for i,k in pairs(harp_tbl) do
harp_tbl[i] = trim(harp_tbl[i])
if string.len(harp_tbl[i]) > 2 then
is_error = true
-- goto on_error
end
harp_tbl[i] = string.lower(harp_tbl[i])
local first = harp_tbl[i]:sub(1,1)
local second = harp_tbl[i]:sub(2,2)
if second == "f" then second = "b" end
if second == "s" then second = "#" end
if second == "n" then second = "" end
local first_upper = string.upper(first)
harp_tbl[i] = first_upper .. second
if string.len(harp_tbl[i]) == 2 then
if string.sub(harp_tbl[i], -1) ~= "b"
and string.sub(harp_tbl[i], -1) ~= "#"
and string.sub(harp_tbl[i], -1) ~= "n" then
is_error = true
--goto on_error
end
end -- if length is 2 .. .
---- Assign to strings .. .
if harp_tbl[i]:sub(1,1) == "A" then
harpstrings[7] = harp_tbl[i]
direct_notes[7] = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "B" then
harpstrings[3] = harp_tbl[i]
direct_notes[3] = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "C" then
harpstrings[2] = harp_tbl[i]
direct_notes[2] = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "D" then
harpstrings[1] = harp_tbl[i]
direct_notes[1] = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "E" then
harpstrings[4] = harp_tbl[i]
direct_notes[4] = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "F" then
harpstrings[5] = harp_tbl[i]
direct_notes[5] = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "G" then
harpstrings[6] = harp_tbl[i]
direct_notes[6] = harp_tbl[i]
end -- End string assignments
count = i
end -- for i,j
end
function changes_update()
changes_str.LuaString = ""
if not harpstrings[1] then
harpstrings = {"D", "C", "B", "E", "F", "G", "A"}
end
local new_pedals = {0, 0, 0, 0, 0, 0, 0}
local compare_notes = split(config.last_notes, ",")
for i, k in pairs(compare_notes) do
compare_notes[i] = trim(compare_notes[i])
end
local changes_temp
for i = 1, 7, 1 do
if harpstrings[i] == compare_notes[i] then
new_pedals[i] = 0
else
new_pedals[i] = tonumber(harpstrings[i]) or 0
if changes_str.LuaString == "" then
changes_str.LuaString = "New: "
end
changes_str.LuaString = changes_str.LuaString .. harpstrings[i] .. ", "
changes_temp = true
end
end
if not changes_temp then
changes_str.LuaString = ""
else
local length = string.len(changes_str.LuaString) - 2
changes_str.LuaString = string.sub(changes_str.LuaString, 1, length)
end
changes_static:SetText(changes_str)
end
function harp_diagram(harpnotes, use_diagram, scale_info, partial) -- luacheck: ignore partial
if use_diagram then
desc_prefix.LuaString = "Hp. Diagram: "
else
desc_prefix.LuaString = "Hp. Pedals: "
end
if partial then scale_info = nil end
local region = finenv.Region()
harp_error = false
local use_tech = false
local sysstaves = finale.FCSystemStaves()
sysstaves:LoadScrollView()
local sysstaff = finale.FCSystemStaff()
local left_strings = finale.FCString()
left_strings.LuaString = ""
local new_pedals = {0, 0, 0, 0, 0, 0, 0}
description.LuaString = desc_prefix.LuaString
diagram_string.LuaString = ""
if not SMuFL then
diagram_font = "^fontTxt(Engraver Text H)"
flat_char = "o"
nat_char = "O"
sharp_char = "p"
divider_char = "P"
end
---------------------------------
-- Initialize harpstring variables to 0
A = "A"
B = "B"
C = "C"
D = "D"
E = "E"
F = "F"
G = "G"
-----------------------------
local compare_notes = split(config.last_notes, ",")
for i, k in pairs(compare_notes) do
compare_notes[i] = trim(compare_notes[i])
end
--
local harp_tbl = split(harpnotes, ",")
local count = 0
for i,k in pairs(harp_tbl) do
harp_tbl[i] = trim(harp_tbl[i])
if string.len(harp_tbl[i]) > 2 then
harp_error = true
goto on_error
end
harp_tbl[i] = string.lower(harp_tbl[i])
local first = harp_tbl[i]:sub(1,1)
local second = harp_tbl[i]:sub(2,2)
if second == "f" then second = "b" end
if second == "s" then second = "#" end
if second == "n" then second = "" end
local first_upper = string.upper(first)
harp_tbl[i] = first_upper .. second
if string.len(harp_tbl[i]) == 2 then
if string.sub(harp_tbl[i], -1) ~= "b"
and string.sub(harp_tbl[i], -1) ~= "#"
and string.sub(harp_tbl[i], -1) ~= "n" then
harp_error = true
goto on_error
end
end -- if length is 2 .. .
---- Assign to strings .. .
if harp_tbl[i]:sub(1,1) == "A" then
A = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "B" then
B = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "C" then
C = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "D" then
D = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "E" then
E = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "F" then
F = harp_tbl[i]
elseif harp_tbl[i]:sub(1,1) == "G" then
G = harp_tbl[i]
else
harp_error = true
goto on_error
end -- End string assignments
count = i
end -- for i,j
--
harpstrings = {D, C, B, E, F, G, A}
pedals_update()
if count > 7 then
harp_error = true
goto on_error
end
if partial then
for i = 1, 7, 1 do
if harpstrings[i] == compare_notes[i] then
new_pedals[i] = 0
else
new_pedals[i] = tonumber(harpstrings[i]) or 0
changes = true
end
end
else
new_pedals = harpstrings
end
if not changes and partial then
if direct then
local alert = ui:AlertYesNo("There are no pedal changes required.\rAdd anyway?", nil)
if alert == 3 then
override = true
elseif alert == 2 then
new_pedals = direct_notes
changes = true
end
end
end
changes_update()
for i = 1, 7, 1 do
if use_diagram then
description.LuaString = description.LuaString .. harpstrings[i]
if string.len(harpstrings[i]) == 1 then
diagram_string.LuaString = diagram_string.LuaString .. nat_char
elseif string.len(harpstrings[i]) == 2 then
if string.sub(harpstrings[i], -1) == "b" then
diagram_string.LuaString = diagram_string.LuaString .. flat_char
elseif string.sub(harpstrings[i], -1) == "#" then
diagram_string.LuaString = diagram_string.LuaString .. sharp_char
elseif string.sub(harpstrings[i], -1) == "n" then
diagram_string.LuaString = diagram_string.LuaString .. nat_char
end
end
if i == 3 then
diagram_string.LuaString = diagram_string.LuaString .. divider_char
description.LuaString = description.LuaString .. " | "
elseif i < 7 then
description.LuaString = description.LuaString .. " "
end
elseif not use_diagram then -- Settings for 'Note names'
if i < 3 then
if new_pedals[i] ~= 0 then
description.LuaString = description.LuaString .. harpstrings[i] .. " "
left_strings.LuaString = left_strings.LuaString .. harpstrings[i]
if string.len(harpstrings[i]) == 1 then
left_strings.LuaString = left_strings.LuaString .. "n"
end
left_strings.LuaString = left_strings.LuaString .. " "
end
elseif i == 3 then
if new_pedals[i] ~= 0 then
description.LuaString = description.LuaString .. harpstrings[i] .. " "
left_strings.LuaString = left_strings.LuaString .. harpstrings[i]
if string.len(harpstrings[i]) == 1 then
left_strings.LuaString = left_strings.LuaString .. "n"
end
end
if new_pedals[i + 1] ~= 0 then
description.LuaString = description.LuaString .. "| "
end
elseif i > 3 and i ~= 7 then
if new_pedals[i] ~= 0 then
description.LuaString = description.LuaString .. harpstrings[i] .. " "
diagram_string.LuaString = diagram_string.LuaString .. harpstrings[i]
if string.len(harpstrings[i]) == 1 then
diagram_string.LuaString = diagram_string.LuaString .. "n"
end
diagram_string.LuaString = diagram_string.LuaString .. " "
end
elseif i == 7 then
if new_pedals[i] ~= 0 then
description.LuaString = description.LuaString .. harpstrings[i]
diagram_string.LuaString = diagram_string.LuaString .. harpstrings[i]
if string.len(harpstrings[i]) == 1 then
diagram_string.LuaString = diagram_string.LuaString .. "n"
end
end
end
end -- if use_diagram .. .
end -- i 1 to 7
--
if not use_diagram then
if not stack then
if diagram_string.LuaString ~= "" then
left_strings.LuaString = left_strings.LuaString .. " "
end
diagram_string.LuaString = left_strings.LuaString .. diagram_string.LuaString
elseif stack and (diagram_string.LuaString ~= ""and not config.pedal_lanes)
or stack and not partial
or pedal_lanes and partial then
diagram_string.LuaString = diagram_string.LuaString .. "\r" .. left_strings.LuaString
elseif (partial and diagram_string.LuaString == "" and not pedal_lanes) then
diagram_string.LuaString = left_strings.LuaString
end
diagram_string.LuaString = string.gsub(diagram_string.LuaString, "n", "^natural()")
diagram_string.LuaString = string.gsub(diagram_string.LuaString, "b", "^flat()")
diagram_string.LuaString = string.gsub(diagram_string.LuaString, "#", "^sharp()")
diagram_string.LuaString = string.gsub(diagram_string.LuaString, " %\13", "\r")
end
if scale_info then description.LuaString = description.LuaString .. " (" .. scale_info .. ")" end
::on_error::
if harp_error then
local result = ui:AlertYesNo("There seems to be a problem with your harp diagram. \n Would you like to try again?", nil)
if result == 2 then
config.last_notes = "D, C, B, E, F, G, A" -- reset the last notes in case there is a problem with them
end
end -- error
if is_dialog_assigned then
ui:AlertInfo("There is already a harp diagram assigned to this region.", nil)
end
end
function pedals_add(use_diagram, partial) -- luacheck: ignore partial
local undo_str = ""
if use_diagram then
undo_str = "Create harp diagram"
else
undo_str = "Create harp pedals"
end
finenv.StartNewUndoBlock(undo_str, false)
local categorydefs = finale.FCCategoryDefs()
local misc_cat = finale.FCCategoryDef()
categorydefs:LoadAll()
local diagrams = 0
local region = finenv.Region()
local start = region.StartMeasure
local font = finale.FCFontInfo()
local textexpressiondefs = finale.FCTextExpressionDefs()
textexpressiondefs:LoadAll()
local add_expression = finale.FCExpression()
local diag_ted = 0
is_dialog_assigned = false
local expressions = finale.FCExpressions()
local measure_num = region.StartMeasure
local measure_pos = region.StartMeasurePos
local staff_num = region.EndStaff
local and_cell = finale.FCCell(measure_num, staff_num)
--
---- deal with categories
for cat in eachbackwards(categorydefs) do
if cat:CreateName().LuaString == "Technique Text" and diagrams == 0 then
diagrams = cat.ID
diagrams_cat = cat
use_tech = true
if use_diagram then
print("No Harp Diagrams category found. Using Technique Text,",diagrams)
else
print("No Harp Pedals category found. Using Technique Text,",diagrams)
end
elseif string.lower(cat:CreateName().LuaString) == "harp diagrams" and use_diagram == true then
print("Found Harp Diagrams category")
diagrams = cat.ID
diagrams_cat = cat
elseif string.lower(cat:CreateName().LuaString) == "harp pedals" and use_diagram == false then
print("Found Harp Pedals category")
diagrams = cat.ID
diagrams_cat = cat
end -- if cat .. .
end -- for cat
-----
-- find an existing diagram
--
textexpressiondefs:LoadAll()
for ted in each(textexpressiondefs) do
if ted.CategoryID == diagrams and ted:CreateDescription().LuaString == description.LuaString then
print ("Diagram found at",ted.ItemNo)
diag_ted = ted.ItemNo
end -- if ted.CategoryID
end -- for ted .. .
--
-- if there is no existing diagram .. .', create one
if diag_ted == 0 then
local ex_ted = finale.FCTextExpressionDef()
local ted_text = finale.FCString()
if use_diagram then
local text_font = diagram_font
ted_text.LuaString = text_font .. diagram_string.LuaString
else
ted_text.LuaString = diagram_string.LuaString
end -- if use_diagram
ex_ted:AssignToCategory(diagrams_cat)
ex_ted:SetDescription(description)
ex_ted:SaveNewTextBlock(ted_text)
if use_tech then -- If using the Techniques category, override positioning
ex_ted:SetUseCategoryPos(false)
--ex_ted.HorizontalJustification = 1 -- Justify Center
--ex_ted.HorizontalAlignmentPoint = 5 -- Center on Music
--ex_ted.HorizontalOffset = nudge
ex_ted.VerticalAlignmentPoint = 9 -- align to
ex_ted.VerticalBaselineOffset = 12
ex_ted.VerticalEntryOffset = -36
end
ex_ted:SaveNew()
diag_ted = ex_ted.ItemNo
end -- if diag_ted == 0
-- Test to see if diagram is there already .. .
expressions:LoadAllForRegion(region)
for e in each(expressions) do
local ted = e:CreateTextExpressionDef()
local ted_desc = ted:CreateDescription()
if ted_desc:ContainsLuaString(desc_prefix.LuaString) then
is_dialog_assigned = true
goto on_error
end
end -- for e in expressions .. . ]]
-- add the harp diagram
add_expression:SetStaff(staff_num)
add_expression:SetMeasurePos(measure_pos)
add_expression:SetID(diag_ted)
add_expression:SaveNewToCell(and_cell)
-------
::on_error::
finenv.EndUndoBlock(true)
if harp_error then
print("There seems to be a problem with your harp diagram.")
local result = ui:AlertYesNo("There seems to be a problem with your harp diagram. \n Would you like to try again?", nil)
-- if result == 2 then harp_dialog() end
end -- error
if is_dialog_assigned then
ui:AlertInfo("There is already a harp diagram assigned to this region.", nil)
is_dialog_assigned = false
end
end -- function add_pedals
-------
function harp_scale(root, scale, use_diagram, use_chord, partial) -- luacheck: ignore partial
local scale_error = false
local enharmonic = finale.FCString()
local scale_info = root .. " " .. scale
if use_chord then scale_info = root .. scale end
-------------------
---- Set up tables for all strings, as both numbers (C = 0) and letters.
local C_num = {11, 0, 1}
local C_ltr = {"Cb", "C", "C#"}
--
local D_num = {1, 2, 3}
local D_ltr = {"Db", "D", "D#"}
--
local E_num = {3, 4, 5}
local E_ltr = {"Eb", "E", "E#"}
--
local F_num = {4, 5, 6}
local F_ltr = {"Fb", "F", "F#"}
--
local G_num = {6, 7, 8}
local G_ltr = {"Gb", "G", "G#"}
--
local A_num = {8, 9, 10}
local A_ltr = {"Ab", "A", "A#"}
--
local B_num = {10, 11, 0}
local B_ltr = {"Bb", "B", "B#"}
---- And also master lists of all notes and numbers
local all_ltr = {"Cb", "C", "C#", "Db", "D", "D#", "Eb", "E", "E#", "Fb", "F", "F#", "Gb", "G", "G#", "Ab", "A", "A#", "Bb", "B", "B#"}
local enh_ltr = {"B", "B#", "Db", "C#", "D", "Eb", "D#", "Fb", "F", "E", "E#", "Gb", "F#", "G", "Ab", "G#", "A", "Bb", "A#", "Cb", "C"}
local all_num = {11, 0, 1, 1, 2, 3, 3, 4, 5, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 0}
for i,j in pairs(all_ltr) do
if all_ltr[i] == root then enharmonic.LuaString = enh_ltr[i] end
end
-- 1) Find root offset
local root_off = 0
for a, b in pairs(all_ltr) do
if all_ltr[a] == root then
root_off = all_num[a]
end -- if
end -- for a, b .. .
----
-- 2) Find scale and transpose it
scale = string.lower(scale)
local scale_new = {}
-----------------------
if scale == "major" or scale == "ionian" then scale_new = {0, 2, 4, 5, 7, 9, 11} end
if scale == "dorian" then scale_new = {0, 2, 3, 5, 7, 9, 10} end
if scale == "phrygian" then scale_new = {0, 1, 3, 5, 7, 8, 10} end
if scale == "lydian" then scale_new = {0, 2, 4, 6, 7, 9, 11} end
if scale == "mixolydian" then scale_new = {0, 2, 4, 5, 7, 9, 10} end
if scale == "natural minor" or scale == "aeolian" then scale_new = {0, 2, 3, 5, 7, 8, 10} end
if scale == "locrian" then scale_new = {0, 1, 3, 5, 6, 8, 10} end
if scale == "harmonic minor" then scale_new = {0, 2, 3, 5, 7, 8, 11} end
if scale == "hungarian minor" then scale_new = {0, 2, 3, 6, 7, 8, 11} end
----- 'Exotic' scales, with something other than 7 scale degrees. Will be treated as chords.
if scale == "whole tone" then scale_new = {0, 2, 4, 6, 8, 10} end
if scale == "major pentatonic" then scale_new = {0, 2, 4, 7, 9} end
if scale == "minor pentatonic" then scale_new = {0, 3, 5, 7, 10} end
----- Chords - Listed in order of matching priority.
if scale == "dom7" then scale_new = {0, 4, 7, 10, 2, 9, 5} end
if scale == "maj7" then scale_new = {11, 0, 4, 7, 9, 2, 5} end
if scale == "min7" then scale_new = {0, 3, 7, 10, 2, 5, 9} end
if scale == "m7b5" then scale_new = {0, 3, 6, 10, 2, 5, 8} end
if scale == "dim7" then scale_new = {0, 3, 6, 9, 2, 5, 8} end
if scale == "aug" then scale_new = {0, 4, 8, 2, 10, 6} end
--
for a, b in pairs(scale_new) do
scale_new[a] = math.fmod (scale_new[a] + root_off , 12)
end
--------------------------
-- 3) build out scale using letternames
local scale_ltrs = root -- This is where we will build scale (as string of letter-names)
local root_string = string.sub(root, 1, 1) -- the base string, A-G
local last = root_string -- the last string added to the list
local scale_deg = 2 -- will advance through scale. Root was already added, so we will start at 2 .. .
----
if scale == "whole tone" or scale == "major pentatonic" or scale == "minor pentatonic" then
use_chord = true
end -- temporary change for exotic scales!
if not use_chord then
for i = 1, 2, 1 do --- run through this twice .. .
if last == "A" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if B_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. B_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "B"
end
if last == "B" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if C_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. C_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "C"
end
if last == "C" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if D_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. D_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "D"
end
if last == "D" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if E_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. E_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "E"
end
if last == "E" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if F_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. F_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "F"
end
if last == "F" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if G_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. G_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "G"
end
if last == "G" and scale_deg <= 7 then
local is_found = false
for j = 1, 3, 1 do
if A_num[j] == scale_new[scale_deg] then
scale_ltrs = scale_ltrs .. ", " .. A_ltr[j]
is_found = true
end
end -- for j
if not is_found then
scale_error = true
goto scale_error
end
scale_deg = scale_deg + 1
last = "A"
end
end -- for i .. .
elseif use_chord then
local ind_string_ltrs = {A_ltr, B_ltr, C_ltr, D_ltr, E_ltr, F_ltr, G_ltr}
local ind_string_nums = {A_num, B_num, C_num, D_num, E_num, F_num, G_num}
for string_key, j in pairs(ind_string_ltrs) do
if ind_string_ltrs[string_key][2] ~= root_string then
local match = false
local count = 0
repeat
for scale_key, l in pairs(scale_new) do
for string_num_key,n in pairs(ind_string_nums[string_key]) do
if ind_string_nums[string_key][string_num_key] == scale_new[scale_key] then
scale_ltrs = scale_ltrs .. ", " .. ind_string_ltrs[string_key][string_num_key]
match = true
local update_scale = false
if scale == "major pentatonic" and scale_key == 2 then
scale_new = {0, 4, 7, 2, 9}
update_scale = true
elseif scale == "minor pentatonic" and scale_key == 3 then
scale_new = {0, 3, 7, 5, 10}
update_scale = true
elseif scale == "whole tone" and scale_key == 2 then
scale_new = {0, 4, 2, 6, 8, 10}
update_scale = true
end
if update_scale then
for a, b in pairs(scale_new) do
scale_new[a] = math.fmod (scale_new[a] + root_off , 12)
end
update_scale = false
end
goto continue
end
end
end
count = count + 1
if count == 25 then
print("Something clearly went wrong .. .")
match = true
end
::continue::
until ( match == true )
end -- if ind_string_ltrs[i][2] .. .
end -- for i, j .. .
end -- if use_chord .. .
if scale == "whole tone" or scale == "major pentatonic" or scale == "minor pentatonic" then
use_chord = false
end -- temporary change for exotic scales!
harp_diagram(scale_ltrs, use_diagram, scale_info, partial)
---
::scale_error::
if scale_error then
local str = finale.FCString()
str.LuaString = "That scale won't work, sorry. \n Try again using " .. enharmonic.LuaString .. " " .. scale .. "?"
local result = ui:AlertYesNo(str.LuaString, nil)
if result == 2 then
sel_acc:SetSelectedItem(1)
for i, k in pairs(roots) do
if string.sub(enharmonic.LuaString, 1, 1) == roots[i] then
sel_root:SetSelectedItem(i-1)
end
end
if string.len(enharmonic.LuaString) == 2 then
if string.sub(enharmonic.LuaString, -1) == "b" then
sel_acc:SetSelectedItem(0)
elseif string.sub(enharmonic.LuaString, -1) == "#" then
sel_acc:SetSelectedItem(2)
end
end
end
end -- error
end -- function harp_scale()
-------
function harp_dialog()
local str = finale.FCString()
local use_diagram = true
local use_chord = false
local scale_info = ""
if config.chord_check == 0 or config.chord_check == "0" then use_chord = false
elseif config.chord_check == 1 or config.chord_check == "1" then use_chord = true end
if config.diagram_check == 0 or config.diagram_check == "0" then use_diagram = true
elseif config.diagram_check == 1 or config.diagram_check == "1" then use_diagram = false end
local row_y = 0 -- The various controls will use this to consistently place themselves vertically
--
function format_ctrl(ctrl, h, w, st)
ctrl:SetHeight(h)
ctrl:SetWidth(w)
if ctrl:ClassName() ~= "FCCtrlPopup" then
str.LuaString = st
ctrl:SetText(str)
end
end -- function format_ctrl
--
local dialog = finale.FCCustomLuaWindow()
if context.window_pos_x ~= nil and context.window_pos_y ~= nil then
dialog:StorePosition()
dialog:SetRestorePositionOnlyData(context.window_pos_x, context.window_pos_y)
dialog:RestorePosition()
end
str.LuaString = "Harp Pedal Wizard"
dialog:SetTitle(str)
-----
local scale_static = dialog:CreateStatic(0, row_y)
format_ctrl(scale_static, 120, 320,
[[Choose a root and accidental, then either a scale
or a chord from the drop down lists.]])
----
row_y = row_y + 52
roots = {"A", "B", "C", "D", "E", "F", "G"}
local root_label = dialog:CreateStatic(8,row_y-14)
format_ctrl(root_label, 15, 30, "Root")
sel_root = dialog:CreatePopup(8, row_y)
format_ctrl(sel_root, 20, 36, "Root")
for i,j in pairs(roots) do
str.LuaString = roots[i]
sel_root:AddString(str)
end
sel_root:SetSelectedItem(config.root)
local accidentals = {"b", "♮", "#"} -- unicode symbols .. . natural at least displays as 'n' on Windows
-- local accidentals = {"♭", "♮", "♯"} -- unicode symbols
sel_acc = dialog:CreatePopup(42, row_y)
format_ctrl(sel_acc, 20, 32, "Accidental")
for i,j in pairs(accidentals) do
str.LuaString = accidentals[i]
sel_acc:AddString(str)
end
sel_acc:SetSelectedItem(config.accidental)
-- Setup Scales
str.LuaString = " Scale"
local scale_check = dialog:CreateCheckbox(86, row_y-14)
format_ctrl(scale_check, 16, 70, str.LuaString)
scale_check:SetCheck(config.scale_check)
local scales = {"Major", "Natural Minor", "Harmonic Minor", "Ionian",
"Dorian", "Phrygian", "Lydian", "Mixolydian", "Aeolian", "Locrian", "Hungarian Minor",
"Whole tone", "Major Pentatonic", "Minor Pentatonic"}
local sel_scale = dialog:CreatePopup(86, row_y)
format_ctrl(sel_scale, 20, 120, "Scale")
local standard_scales_count = 0
for i,j in pairs(scales) do
str.LuaString = scales[i]
sel_scale:AddString(str)
standard_scales_count = i
end
sel_scale:SetSelectedItem(config.scale)
if scale_check:GetCheck() == 0 then
sel_scale:SetEnable(false)
end
--- Setup Chords
str.LuaString = " Chord"
local chord_check = dialog:CreateCheckbox(220, row_y-14)
format_ctrl(chord_check, 16, 70, str.LuaString)
chord_check:SetCheck(config.chord_check)
local chords = {"dom7", "maj7", "min7", "m7b5", "dim7", "aug"}
local sel_chord = dialog:CreatePopup(220, row_y)
format_ctrl(sel_chord, 20, 100, "Chord")
for i,j in pairs(chords) do
str.LuaString = chords[i]
sel_chord:AddString(str)
end
sel_chord:SetSelectedItem(config.chord)
if chord_check:GetCheck() == 0 then
sel_chord:SetEnable(false)
end
if scale_check:GetCheck() == 0 and chord_check:GetCheck() == 0 then
sel_root:SetEnable(false)
sel_acc:SetEnable(false)
end
--
row_y = row_y + 32
local horz_line1 = dialog:CreateHorizontalLine(0, row_y - 6, 320)
-- Setup diagram or Note Names
str.LuaString = "Style:"
local style_label = dialog:CreateStatic(0, row_y-1)
format_ctrl(style_label, 20, 70, str.LuaString)
--
local diagram_checkbox = dialog:CreateCheckbox(40, row_y)
str.LuaString = " Diagram"
format_ctrl(diagram_checkbox, 16, 70, str.LuaString)
diagram_checkbox:SetCheck(config.diagram_check)
--
local names_checkbox = dialog:CreateCheckbox(132, row_y)
str.LuaString = " Note Names"
format_ctrl(names_checkbox, 16, 90, str.LuaString)
names_checkbox:SetCheck(config.names_check)
--
local partial_checkbox = dialog:CreateCheckbox(224, row_y)
str.LuaString = " Partial"
format_ctrl(partial_checkbox, 16, 70, str.LuaString)
partial_checkbox:SetCheck(config.partial_check)
--
row_y = row_y + 18
local stack_checkbox = dialog:CreateCheckbox(132, row_y)
str.LuaString = " Stack"
format_ctrl(stack_checkbox, 16, 70, str.LuaString)
stack_checkbox:SetCheck(config.stack)
--
local lanes_checkbox = dialog:CreateCheckbox(224, row_y)
str.LuaString = " Preserve Lanes"
format_ctrl(lanes_checkbox, 16, 100, str.LuaString)
lanes_checkbox:SetCheck(config.pedal_lanes)
--
row_y = row_y + 26
local horz_line3 = dialog:CreateHorizontalLine(0, row_y-8, 320)
--
str.LuaString = "D"
local blank = finale.FCString()
blank.LuaString = ""
local col_x = 0
local col_width = 20
local col = 0
local row_h = 20
local flat_y = row_y + row_h
local nat_y = flat_y + row_h
local sharp_y = nat_y + row_h
-- On MacOS in Dark Mode, the horizontal/vertical lines representing the natural position and center line of the harp are too faint.
-- Therefore, on the Mac I have opted to create these lines using vertical pipe and hyphen characters.
if ui:IsOnMac() then
local pedals_h_line = {}
str.LuaString = "-"
for i = 1, 7, 1 do
local line_off
if i < 4 then
line_off = 11
else
line_off = -0
end
pedals_h_line[i] = dialog:CreateStatic(col_x + ((i-1) * col_width + line_off), nat_y)
format_ctrl(pedals_h_line[i], 20, 10, str.LuaString)
end
else
local pedals_h_line1 = dialog:CreateHorizontalLine(col_x, nat_y + 6, col_width * 7)
end
--
local d_stg_static = dialog:CreateStatic(col_x + (col * col_width), row_y-1)
format_ctrl(d_stg_static, 20, 20, str.LuaString)
local d_stg_flat = dialog:CreateCheckbox(col_x + (col * col_width), flat_y)
format_ctrl(d_stg_flat, 16, 13, str.LuaString)
d_stg_flat:SetText(blank)
local d_stg_nat = dialog:CreateCheckbox(col_x + (col * col_width), nat_y)
format_ctrl(d_stg_nat, 16, 13, str.LuaString)
d_stg_nat:SetText(blank)
local d_stg_sharp = dialog:CreateCheckbox(col_x + (col * col_width), sharp_y)
format_ctrl(d_stg_sharp, 16, 13, str.LuaString)
d_stg_sharp:SetText(blank)
col = col + 1
--
str.LuaString = "C"
local c_stg_static = dialog:CreateStatic(col_x + (col * col_width), row_y-1)
format_ctrl(c_stg_static, 20, 20, str.LuaString)
local c_stg_flat = dialog:CreateCheckbox(col_x + (col * col_width), flat_y)
format_ctrl(c_stg_flat, 16, 13, str.LuaString)
c_stg_flat:SetText(blank)
local c_stg_nat = dialog:CreateCheckbox(col_x + (col * col_width), nat_y)
format_ctrl(c_stg_nat, 16, 13, str.LuaString)
c_stg_nat:SetText(blank)
local c_stg_sharp = dialog:CreateCheckbox(col_x + (col * col_width), sharp_y)
format_ctrl(c_stg_sharp, 16, 13, str.LuaString)
c_stg_sharp:SetText(blank)
col = col + 1
--
str.LuaString = "B"
local b_stg_static = dialog:CreateStatic(col_x + (col * col_width), row_y-1)
format_ctrl(b_stg_static, 20, 20, str.LuaString)
local b_stg_flat = dialog:CreateCheckbox(col_x + (col * col_width), flat_y)
format_ctrl(b_stg_flat, 16, 13, str.LuaString)
b_stg_flat:SetText(blank)
local b_stg_nat = dialog:CreateCheckbox(col_x + (col * col_width), nat_y)
format_ctrl(b_stg_nat, 16, 13, str.LuaString)
b_stg_nat:SetText(blank)
local b_stg_sharp = dialog:CreateCheckbox(col_x + (col * col_width), sharp_y)
format_ctrl(b_stg_sharp, 16, 13, str.LuaString)
b_stg_sharp:SetText(blank)
col = col + 1
--
if ui:IsOnMac() then
str.LuaString = "|"
local pedals_v_line = {}
for i = 1, 5, 1 do
pedals_v_line[i] = dialog:CreateStatic(col_x + (col * col_width) - 4, flat_y+(10*(i-1)))
format_ctrl(pedals_v_line[i], 20, 10, str.LuaString)
end
else
local pedals_v_line1 = dialog:CreateVerticalLine(col_x + (col * col_width) - 1, flat_y, row_h * 3)
end
col = col + 1
--
local nudge_rt_ped = 12
str.LuaString = "E"
local e_stg_static = dialog:CreateStatic(col_x + (col * col_width) - nudge_rt_ped, row_y-1)
format_ctrl(e_stg_static, 20, 20, str.LuaString)
local e_stg_flat = dialog:CreateCheckbox(col_x + (col * col_width) - nudge_rt_ped, flat_y)
format_ctrl(e_stg_flat, 16, 13, str.LuaString)
e_stg_flat:SetText(blank)
local e_stg_nat = dialog:CreateCheckbox(col_x + (col * col_width) - nudge_rt_ped, nat_y)
format_ctrl(e_stg_nat, 16, 13, str.LuaString)
e_stg_nat:SetText(blank)
local e_stg_sharp = dialog:CreateCheckbox(col_x + (col * col_width) - nudge_rt_ped, sharp_y)
format_ctrl(e_stg_sharp, 16, 13, str.LuaString)
e_stg_sharp:SetText(blank)