forked from CJGarciaMusic/PowerUserWorkflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJetStreamV2.lua
9295 lines (8378 loc) · 323 KB
/
JetStreamV2.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.Version = "210306"
finaleplugin.Date = "03/06/2021"
return "JetStream Finale Controller", "JetStream Finale Controller", "Input four digit codes to access JetStream Finale Controller features."
end
local dialog = finenv.UserValueInput()
dialog.Title = "JetStream Finale Controller"
function to_EVPUs(text)
local str = finale.FCString()
str.LuaString = text
return str:GetMeasurement(finale.MEASUREMENTUNIT_DEFAULT)
end
local full_art_table = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
function tremolo_assignment(tremolo_type)
if tremolo_type == "metered tremolo" then
for noteentry in eachentrysaved(finenv.Region()) do
if noteentry:IsNote() then
local articulation = finale.FCArticulation()
articulation:SetNoteEntry(noteentry)
if noteentry.Duration < 512 then
articulation:SetID(full_art_table[7])
articulation:SaveNew()
elseif (noteentry.Duration >= 512) and (noteentry.Duration < 1024) then
articulation:SetID(full_art_table[8])
articulation:SaveNew()
elseif noteentry.Duration >= 1024 then
articulation:SetID(full_art_table[9])
articulation:SaveNew()
end
end
end
else
for noteentry in eachentrysaved(finenv.Region()) do
if noteentry:IsNote() then
local articulation = finale.FCArticulation()
articulation:SetNoteEntry(noteentry)
articulation:SetID(tremolo_type)
articulation:SaveNew()
end
end
end
end
function roll_articulation_assignment(defualt_roll_num)
local has_acc = false
local is_polyphony = false
for note_entry in eachentry(finenv.Region()) do
has_acc = false
is_polyphony = false
for note in each(note_entry) do
if (note:CalcAccidental()) then
has_acc = true
end
end
if note_entry:GetCount() > 1 then
is_polyphony = true
end
if is_polyphony then
if has_acc then
local entry_artics = note_entry:CreateArticulations()
entry_artics:LoadAll()
for art in each(entry_artics) do
local art_def = art:CreateArticulationDef()
if (art_def:GetAboveSymbolChar() == defualt_roll_num) then
local entry_metrics = finale.FCEntryMetrics()
if note_entry:IsNote() then
local arg_point = finale.FCPoint(0, 0)
entry_metrics:Load(note_entry)
local artic_pos = 0
if note_entry:CalcStemUp() then
artic_pos = entry_metrics:GetStemLeftPosition() - note_entry:CalcWidestNoteheadWidth()
else
artic_pos = entry_metrics:GetStemLeftPosition() - 6
end
local roll_cushion = 9
local accidental_pos = entry_metrics:GetFirstAccidentalPosition()
local distance = artic_pos - entry_metrics:GetFirstAccidentalPosition()
art:SetHorizontalPos(0 - (distance + roll_cushion))
art:Save()
end
end
end
end
end
end
end
function assignArticulation(art_id)
if (art_id == "metered tremolo") or (art_id == full_art_table[7]) or (art_id == full_art_table[8]) or (art_id == full_art_table[9]) then
tremolo_assignment(art_id)
else
for noteentry in eachentrysaved(finenv.Region()) do
local a = finale.FCArticulation()
a:SetNoteEntry(noteentry)
local ad = finale.FCArticulationDef()
if (art_id == full_art_table[20]) or (art_id == full_art_table[21]) or (art_id == full_art_table[25]) or (art_id == full_art_table[26]) then
if (noteentry:IsNote()) and (noteentry:IsTied() == false) then
a:SetID(art_id)
a:SaveNew()
end
elseif (art_id == full_art_table[12]) or (art_id == full_art_table[11]) then
if noteentry:IsNote() then
a:SetID(art_id)
a:SaveNew()
end
else
if (noteentry:IsNote()) and (noteentry:IsTiedBackwards() == false) then
a:SetID(art_id)
a:SaveNew()
else
if ad:GetAboveSymbolChar() == 85 then
a:SetID(art_id)
a:SaveNew()
end
end
end
end
end
end
function assignNewArticulation(noteentry, art_id)
local a = finale.FCArticulation()
a:SetNoteEntry(noteentry)
if (art_id == full_art_table[27]) or (art_id == full_art_table[28]) or (art_id == full_art_table[29]) or (art_id == full_art_table[30]) then
if noteentry:IsTiedBackwards() == false then
a:SetID(art_id)
a:SaveNew()
end
elseif (art_id == full_art_table[31]) or (art_id == full_art_table[32]) or (art_id == full_art_table[33]) or (art_id == full_art_table[34]) then
if noteentry:IsTied() == false then
a:SetID(art_id)
a:SaveNew()
end
elseif noteentry:IsTiedBackwards() == false then
a:SetID(art_id)
a:SaveNew()
end
end
function createArticulation(table_placement, MainSymbolChar, MainSymbolFont, AboveSymbolChar, AboveUsesMain, AlwaysPlaceOutsideStaff, AttachToTopNote, AttackIsPercent, AutoPosSide, AvoidStaffLines, BelowSymbolChar, BelowUsesMain, BottomAttack, BottomDuration, BottomVelocity, CenterHorizontally, CopyMainSymbol, CopyMainSymbolHorizontally, DefaultVerticalPos, DurationIsPercent, MainHandleHorizontalOffset, MainHandleVerticalOffset, FlippedHandleHorizontalOffset, FlippedHandleVerticalOffset, FlippedSymbolChar, FlippedSymbolFont, InsideSlurs, OnScreenOnly, Playback, TopAttack, TopDuration, TopVelocity, VelocityIsPercent, fm_Absolute, fm_Bold, fm_EnigmaStyles, fm_Hidden, fm_Italic, fm_Name, fm_Size, fm_SizeFloat, fm_StrikeOut, fm_Underline, ff_Absolute, ff_Bold, ff_EnigmaStyles, ff_Hidden, ff_Italic, ff_Name, ff_Size, ff_SizeFloat, ff_StrikeOut, ff_Underline)
local ad = finale.FCArticulationDef()
ad:SetMainSymbolChar(MainSymbolChar)
ad:SetMainSymbolFont(MainSymbolFont)
ad:SetAboveSymbolChar(AboveSymbolChar)
ad:SetAboveUsesMain(AboveUsesMain)
ad:SetAlwaysPlaceOutsideStaff(AlwaysPlaceOutsideStaff)
ad:SetAttachToTopNote(AttachToTopNote)
ad:SetAttackIsPercent(AttackIsPercent)
ad:SetAutoPosSide(AutoPosSide)
ad:SetAvoidStaffLines(AvoidStaffLines)
-- ad:SetBelowSymbolChar(BelowSymbolChar)
ad:SetBelowUsesMain(BelowUsesMain)
ad:SetBottomAttack(BottomAttack)
ad:SetBottomDuration(BottomDuration)
ad:SetBottomVelocity(BottomVelocity)
ad:SetCenterHorizontally(CenterHorizontally)
ad:SetCopyMainSymbol(CopyMainSymbol)
ad:SetCopyMainSymbolHorizontally(CopyMainSymbolHorizontally)
ad:SetDefaultVerticalPos(DefaultVerticalPos)
ad:SetDurationIsPercent(DurationIsPercent)
ad:SetMainHandleHorizontalOffset(MainHandleHorizontalOffset)
ad:SetMainHandleVerticalOffset(MainHandleVerticalOffset)
ad:SetFlippedHandleHorizontalOffset(FlippedHandleHorizontalOffset)
ad:SetFlippedHandleVerticalOffset(FlippedHandleVerticalOffset)
ad:SetFlippedSymbolChar(FlippedSymbolChar)
ad:SetFlippedSymbolFont(FlippedSymbolFont)
ad:SetInsideSlurs(InsideSlurs)
ad:SetOnScreenOnly(OnScreenOnly)
ad:SetPlayback(Playback)
ad:SetTopAttack(TopAttack)
ad:SetTopDuration(TopDuration)
ad:SetTopVelocity(TopVelocity)
ad:SetVelocityIsPercent(VelocityIsPercent)
local fonti = ad:CreateMainSymbolFontInfo()
fonti:SetAbsolute(fm_Absolute)
fonti:SetBold(fm_Bold)
fonti:SetEnigmaStyles(fm_EnigmaStyles)
fonti:SetHidden(fm_Hidden)
fonti:SetItalic(fm_Italic)
fonti:SetName(fm_Name)
fonti:SetSize(fm_Size)
fonti:SetSizeFloat(fm_SizeFloat)
fonti:SetStrikeOut(fm_StrikeOut)
fonti:SetUnderline(fm_Underline)
ad:SetMainSymbolFontInfo(fonti)
local fontif = ad:CreateFlippedSymbolFontInfo()
fontif:SetAbsolute(ff_Absolute)
fontif:SetBold(ff_Bold)
fontif:SetEnigmaStyles(ff_EnigmaStyles)
fontif:SetHidden(ff_Hidden)
fontif:SetItalic(ff_Italic)
fontif:SetName(ff_Name)
fontif:SetSize(ff_Size)
fontif:SetSizeFloat(ff_SizeFloat)
fontif:SetStrikeOut(ff_StrikeOut)
fontif:SetUnderline(ff_Underline)
ad:SetFlippedSymbolFontInfo(fontif)
ad:SaveNew()
full_art_table[table_placement] = ad:GetItemNo()
assignArticulation(full_art_table[table_placement])
end
function createNewArticulation(table_placement, MainSymbolChar, MainSymbolFont, AboveSymbolChar, AboveUsesMain, AlwaysPlaceOutsideStaff, AttachToTopNote, AttackIsPercent, AutoPosSide, AvoidStaffLines, BelowSymbolChar, BelowUsesMain, BottomAttack, BottomDuration, BottomVelocity, CenterHorizontally, CopyMainSymbol, CopyMainSymbolHorizontally, DefaultVerticalPos, DurationIsPercent, MainHandleHorizontalOffset, MainHandleVerticalOffset, FlippedHandleHorizontalOffset, FlippedHandleVerticalOffset, FlippedSymbolChar, FlippedSymbolFont, InsideSlurs, OnScreenOnly, Playback, TopAttack, TopDuration, TopVelocity, VelocityIsPercent, fm_Absolute, fm_Bold, fm_EnigmaStyles, fm_Hidden, fm_Italic, fm_Name, fm_Size, fm_SizeFloat, fm_StrikeOut, fm_Underline, ff_Absolute, ff_Bold, ff_EnigmaStyles, ff_Hidden, ff_Italic, ff_Name, ff_Size, ff_SizeFloat, ff_StrikeOut, ff_Underline)
local ad = finale.FCArticulationDef()
ad:SetMainSymbolChar(MainSymbolChar)
ad:SetMainSymbolFont(MainSymbolFont)
ad:SetAboveSymbolChar(AboveSymbolChar)
ad:SetAboveUsesMain(AboveUsesMain)
ad:SetAlwaysPlaceOutsideStaff(AlwaysPlaceOutsideStaff)
ad:SetAttachToTopNote(AttachToTopNote)
ad:SetAttackIsPercent(AttackIsPercent)
ad:SetAutoPosSide(AutoPosSide)
ad:SetAvoidStaffLines(AvoidStaffLines)
-- ad:SetBelowSymbolChar(BelowSymbolChar)
ad:SetBelowUsesMain(BelowUsesMain)
ad:SetBottomAttack(BottomAttack)
ad:SetBottomDuration(BottomDuration)
ad:SetBottomVelocity(BottomVelocity)
ad:SetCenterHorizontally(CenterHorizontally)
ad:SetCopyMainSymbol(CopyMainSymbol)
ad:SetCopyMainSymbolHorizontally(CopyMainSymbolHorizontally)
ad:SetDefaultVerticalPos(DefaultVerticalPos)
ad:SetDurationIsPercent(DurationIsPercent)
ad:SetMainHandleHorizontalOffset(MainHandleHorizontalOffset)
ad:SetMainHandleVerticalOffset(MainHandleVerticalOffset)
ad:SetFlippedHandleHorizontalOffset(FlippedHandleHorizontalOffset)
ad:SetFlippedHandleVerticalOffset(FlippedHandleVerticalOffset)
ad:SetFlippedSymbolChar(FlippedSymbolChar)
ad:SetFlippedSymbolFont(FlippedSymbolFont)
ad:SetInsideSlurs(InsideSlurs)
ad:SetOnScreenOnly(OnScreenOnly)
ad:SetPlayback(Playback)
ad:SetTopAttack(TopAttack)
ad:SetTopDuration(TopDuration)
ad:SetTopVelocity(TopVelocity)
ad:SetVelocityIsPercent(VelocityIsPercent)
local fonti = ad:CreateMainSymbolFontInfo()
fonti:SetAbsolute(fm_Absolute)
fonti:SetBold(fm_Bold)
fonti:SetEnigmaStyles(fm_EnigmaStyles)
fonti:SetHidden(fm_Hidden)
fonti:SetItalic(fm_Italic)
fonti:SetName(fm_Name)
fonti:SetSize(fm_Size)
fonti:SetSizeFloat(fm_SizeFloat)
fonti:SetStrikeOut(fm_StrikeOut)
fonti:SetUnderline(fm_Underline)
ad:SetMainSymbolFontInfo(fonti)
local fontif = ad:CreateFlippedSymbolFontInfo()
fontif:SetAbsolute(ff_Absolute)
fontif:SetBold(ff_Bold)
fontif:SetEnigmaStyles(ff_EnigmaStyles)
fontif:SetHidden(ff_Hidden)
fontif:SetItalic(ff_Italic)
fontif:SetName(ff_Name)
fontif:SetSize(ff_Size)
fontif:SetSizeFloat(ff_SizeFloat)
fontif:SetStrikeOut(ff_StrikeOut)
fontif:SetUnderline(ff_Underline)
ad:SetFlippedSymbolFontInfo(fontif)
ad:SaveNew()
full_art_table[table_placement] = ad:GetItemNo()
end
function deleteArticulation(id_num)
for noteentry in eachentrysaved(finenv.Region()) do
local artics = noteentry:CreateArticulations()
for a in eachbackwards(artics) do
local defs = a:CreateArticulationDef()
if defs:GetItemNo() == id_num then
a:DeleteData()
end
end
end
end
function deleteNewArticulation(noteentry, id_num)
local artics = noteentry:CreateArticulations()
for a in eachbackwards(artics) do
local defs = a:CreateArticulationDef()
if defs:GetItemNo() == id_num then
a:DeleteData()
end
end
end
function addArticulation(art_id)
local artic_ids = {}
for noteentry in eachentrysaved(finenv.Region()) do
local artics = noteentry:CreateArticulations()
for a in each(artics) do
local defs = a:CreateArticulationDef()
table.insert(artic_ids, defs:GetItemNo())
end
end
local found_artic = 0
for key, value in pairs(artic_ids) do
if value == art_id then
found_artic = 1
end
end
if found_artic ~= 0 then
deleteArticulation(art_id)
else
assignArticulation(art_id)
end
end
function addNewArticulation(note_entry, art_id)
local artic_ids = {}
local artics = note_entry:CreateArticulations()
for a in each(artics) do
local defs = a:CreateArticulationDef()
table.insert(artic_ids, defs:GetItemNo())
end
local found_artic = 0
for key, value in pairs(artic_ids) do
if value == art_id then
found_artic = 1
end
end
if found_artic ~= 0 then
deleteNewArticulation(note_entry, art_id)
else
assignNewArticulation(note_entry, art_id)
end
end
function findArticulation(table_placement, AboveSymbolChar, font_name)
local articulationdefs = finale.FCArticulationDefs()
articulationdefs:LoadAll()
local first_id_table = {}
for ad in each(articulationdefs) do
if font_name == "" then
if (ad:GetAboveSymbolChar() == AboveSymbolChar) then
table.insert(first_id_table, ad.ItemNo)
end
else
if (ad:GetAboveSymbolChar() == AboveSymbolChar) and (ad:GetMainSymbolFont() == font_name) then
table.insert(first_id_table, ad.ItemNo)
end
end
end
if first_id_table[1] ~= nil then
full_art_table[table_placement] = first_id_table[1]
end
end
function articulations_lv_poly()
local region = finenv.Region()
local start = region.StartMeasure
local stop = region.EndMeasure
local sys_staves = finale.FCSystemStaves()
sys_staves:LoadAllForRegion(region)
local lv_up = 0
local lv_down = 0
local lv_auto = 0
local articulationdefs = finale.FCArticulationDefs()
local horz = 39
local vert = 0
avoid = false
auto_avoid = true
articulationdefs:LoadAll()
for ad in each(articulationdefs) do
if (ad:GetMainSymbolFont() == "Engraver Font Set") then
if (ad:GetAboveSymbolChar() == 105 and ad:GetBelowSymbolChar() == 105 and ad.AvoidStaffLines == avoid) then
lv_up = ad.ItemNo
elseif (ad:GetAboveSymbolChar() == 73 and ad:GetBelowSymbolChar() == 73 and ad.AvoidStaffLines == avoid) then
lv_down = ad.ItemNo
elseif (ad:GetAboveSymbolChar() == 105 and ad:GetBelowSymbolChar() == 73 and ad.AvoidStaffLines == auto_avoid) then
lv_auto = ad.ItemNo
end
end
end
if lv_up == 0 then
local ad = finale.FCArticulationDef()
ad.MainSymbolChar = 105
ad.MainSymbolFont = "Engraver Font Set"
ad.MainSymbolIsShape = false
ad.MainSymbolSize = 24
ad.FlippedSymbolChar = 105
ad.FlippedSymbolFont = "Engraver Font Set"
ad.FlippedSymbolIsShape = false
ad.FlippedSymbolSize = 24
ad.AboveSymbolChar = 105
ad.AboveUsesMain = true
ad.BelowSymbolChar = 105
ad.BelowUsesMain = true
ad.DefaultVerticalPos = 0
ad.MainHandleHorizontalOffset = horz
ad.MainHandleVerticalOffset = vert
ad.FlippedHandleHorizontalOffset = horz
ad.FlippedHandleVerticalOffset = vert
ad.AlwaysPlaceOutsideStaff = false
ad.AttachToTopNote = false
ad.AutoPosSide = 0
ad.AvoidStaffLines = avoid
ad.CenterHorizontally = false
ad.CopyMainSymbol = false
ad.CopyMainSymbolHorizontally = false
ad.InsideSlurs = false
ad.OnScreenOnly = false
ad.Playback = false
ad.AttackIsPercent = false
ad.TopAttack = 0
ad.BottomAttack = 0
ad.DurationIsPercent = false
ad.TopDuration = 0
ad.BottomDuration = 0
ad.TopVelocity = 0
ad.BottomVelocity = 0
ad:SaveNew()
lv_up = ad.ItemNo
end
if lv_down == 0 then
local ad = finale.FCArticulationDef()
ad.MainSymbolChar = 73
ad.MainSymbolFont = "Engraver Font Set"
ad.MainSymbolIsShape = false
ad.MainSymbolSize = 24
ad.FlippedSymbolChar = 73
ad.FlippedSymbolFont = "Engraver Font Set"
ad.FlippedSymbolIsShape = false
ad.FlippedSymbolSize = 24
ad.AboveSymbolChar = 73
ad.AboveUsesMain = true
ad.BelowSymbolChar = 73
ad.BelowUsesMain = true
ad.DefaultVerticalPos = 0
ad.MainHandleHorizontalOffset = horz
ad.MainHandleVerticalOffset = -vert
ad.FlippedHandleHorizontalOffset = horz
ad.FlippedHandleVerticalOffset = vert
ad.AlwaysPlaceOutsideStaff = false
ad.AttachToTopNote = false
ad.AutoPosSide = 0
ad.AvoidStaffLines = avoid
ad.CenterHorizontally = false
ad.CopyMainSymbol = false
ad.CopyMainSymbolHorizontally = false
ad.InsideSlurs = false
ad.OnScreenOnly = false
ad.Playback = false
ad.AttackIsPercent = false
ad.TopAttack = 0
ad.BottomAttack = 0
ad.DurationIsPercent = false
ad.TopDuration = 0
ad.BottomDuration = 0
ad.TopVelocity = 0
ad.BottomVelocity = 0
ad:SaveNew()
lv_down = ad.ItemNo
end
if lv_auto == 0 then
local ad = finale.FCArticulationDef()
--ad.MainSymbolChar = 105
ad.MainSymbolFont = "Engraver Font Set"
ad.MainSymbolIsShape = false
ad.MainSymbolSize = 24
ad.FlippedSymbolChar = 73
ad.FlippedSymbolFont = "Engraver Font Set"
ad.FlippedSymbolIsShape = false
ad.FlippedSymbolSize = 24
ad.AboveSymbolChar = 105
ad.AboveUsesMain = true
ad.BelowSymbolChar = 73
ad.BelowUsesMain = false
ad.DefaultVerticalPos = 0
ad.MainHandleHorizontalOffset = horz
ad.MainHandleVerticalOffset = -6
ad.FlippedHandleHorizontalOffset = horz
ad.FlippedHandleVerticalOffset = 7
ad.AlwaysPlaceOutsideStaff = false
ad.AttachToTopNote = false
ad.AutoPosSide = 2
--ad.AvoidStaffLines = avoid
ad.AvoidStaffLines = auto_avoid
ad.CenterHorizontally = true
ad.CopyMainSymbol = false
ad.CopyMainSymbolHorizontally = false
ad.InsideSlurs = false
ad.OnScreenOnly = false
ad.Playback = false
ad.AttackIsPercent = false
ad.TopAttack = 0
ad.BottomAttack = 0
ad.DurationIsPercent = false
ad.TopDuration = 0
ad.BottomDuration = 0
ad.TopVelocity = 0
ad.BottomVelocity = 0
ad:SaveNew()
ad.MainSymbolChar = 105
ad:Save()
lv_auto = ad.ItemNo
end
local found = 0
for noteentry in eachentrysaved(finenv.Region()) do
noteentry:TieAll(false)
local artics = noteentry:CreateArticulations()
for a in each(artics) do
local defs = a:CreateArticulationDef()
if defs:GetItemNo() == lv_auto or defs:GetItemNo() == lv_up or defs:GetItemNo() == lv_down then
found = 1
end
end
end
if found ~= 0 then
deleteArticulation(lv_auto)
deleteArticulation(lv_up)
deleteArticulation(lv_down)
goto continue
end
local count = 0
for noteentry in eachentrysaved(finenv.Region()) do
local interval = {}
local tiedir = {}
local i = 1
if noteentry:IsNote() and noteentry:IsTied() == false then
local horz_pad = 24 * noteentry:CalcDots()
local a = finale.FCArticulation()
a:SetNoteEntry(noteentry)
local rightside_note = false
local ledger = false
count = noteentry.Count
local middle = 0
local clashes = 0
if count % 2 == 1 then
middle = count / 2 + .5
end
local lowestnote = noteentry:CalcHighestStaffPosition() - noteentry:CalcDisplacementRange()
local lastnote = lowestnote
for note in each(noteentry) do
interval[i] = note:CalcStaffPosition() - lastnote
lastnote = note:CalcStaffPosition()
if i > 1 and interval[i] <= 1 then
clashes = clashes + 1
end
if i > 1 and interval[i] >= 3 and interval[i-1] <= 1 then
clashes = clashes - 1
end
if note:CalcRightsidePlacement() and noteentry:CalcStemUp() then
rightside_note = true
end
if note:CalcOnLedgerLine() then
ledger = true
end
i = i + 1
end
if rightside_note == true then
horz_pad = horz_pad + 28
end
if ledger == true then
horz_pad = horz_pad + 6
end
a.HorizontalPos = a.HorizontalPos + horz_pad
i = 1
for note in each(noteentry) do
if count == 1 then
tiedir[i] = "a"
elseif count > 1 then
if i <= count / 2 and j ~= middle then
tiedir[i] = "d"
else
tiedir[i] = "u"
end -- if
if i == middle and noteentry:CalcStemUp() == true then
tiedir[i] = "d"
end
if i > 1 and interval[i] <= 1 and clashes < 2 then
tiedir[i] = "fu"
tiedir[i-1] = "fd"
end
i = i + 1
end
end
i = 1
for note in each(noteentry) do
local cell = finale.FCNoteEntryCell(noteentry.Measure, noteentry.Staff)
cell:Load()
if cell:CalcEntriesInMultiLayers() then
if noteentry.LayerNumber % 2 == 1 then
tiedir[i] = "u"
else
tiedir[i] = "d"
end
end
i = i + 1
end
for i = i, 1, -1 do
if tiedir[i] == "fd" and tiedir[i-1] == "u" then
tiedir[i-1] = "fd"
end
end
i = 1
for note in each(noteentry) do --3rd...
local vert_pad = 0
if tiedir[i] == "a" then
a:SetID(lv_auto)
elseif tiedir[i] == "d" or tiedir[i] == "fd" then
a:SetID(lv_down)
else
a:SetID(lv_up)
end
local staffpos = note:CalcStaffPosition()
if staffpos < -9 or staffpos > 1 then
--print("Note is outside staff. No adjustment necessary")
elseif staffpos % 2 == 1 then
if (tiedir[i] == "d" or tiedir[i] == "fd") then
vert_pad = vert_pad + 4
elseif (tiedir[i] == "u" or tiedir[i] == "fu") then
vert_pad = vert_pad - 3
end
else
if (tiedir[i] == "d" or tiedir[i] == "fd") then
vert_pad = vert_pad - 4
elseif (tiedir[i] == "u" or tiedir[i] == "fu") then
vert_pad = vert_pad + 4
end
end
if (tiedir[i] == "d" or tiedir[i] == "fd") and (tiedir[i+1] == "d" or tiedir[i+1] == "fd") and interval[i+1] <= 1 then
vert_pad = vert_pad - 6
if staffpos >= -9 and staffpos % 2 == 1 then
vert_pad = vert_pad - 12
end
elseif (tiedir[i] == "u" or tiedir[i] == "fu") and (tiedir[i-1] == "u" or tiedir[i-1] == "fu") and interval[i] <= 1 then
vert_pad = vert_pad + 6
if staffpos <= 1 and staffpos % 2 == 1 then
vert_pad = vert_pad + 10
end
end
a.VerticalPos = (note:CalcStaffPosition() - lowestnote) * 12 + vert_pad
a:SaveNew()
i = i + 1
end
end
end
::continue::
end
function delete_duplicate_articulations(note_entry)
local art_list = {}
local arts = note_entry:CreateArticulations()
for a in each(arts) do
table.insert(art_list, a:GetID())
end
local sort_list = {}
local unique_list = {}
for k,v in ipairs(art_list) do
if (not sort_list[v]) then
unique_list[#unique_list + 1] = v
sort_list[v] = true
end
end
for key, value in pairs(art_list) do
for a in each(arts) do
a:DeleteData()
end
end
for key, value in pairs(unique_list) do
local art = finale.FCArticulation()
art:SetNoteEntry(note_entry)
art:SetID(value)
art:SaveNew()
end
end
function split_articulations()
local articulationdefs = finale.FCArticulationDefs()
articulationdefs:LoadAll()
local art_table = {0, 0, 0, 0}
for k, v in pairs({46, 62, 45, 94}) do
local first_id_table = {}
for ad in each(articulationdefs) do
if (ad:GetAboveSymbolChar() == v) and (ad:GetFlippedSymbolChar() > 0) then
table.insert(first_id_table, ad.ItemNo)
end
end
if first_id_table[1] ~= nil then
art_table[k] = first_id_table[1]
end
end
for noteentry in eachentry(finenv.Region()) do
local remove_duplicates = 0
local arts = noteentry:CreateArticulations()
for a in each(arts) do
local ad = finale.FCArticulationDef()
if ad:Load(a:GetID()) then
if ad:GetAboveSymbolChar() == 249 then
a:SetID(art_table[2])
a:Save()
a:SetID(art_table[1])
a:SaveNew()
remove_duplicates = remove_duplicates + 1
end
if (ad:GetAboveSymbolChar() == 138) or (ad:GetAboveSymbolChar() == 251) then
a:SetID(art_table[2])
a:Save()
a:SetID(art_table[3])
a:SaveNew()
remove_duplicates = remove_duplicates + 1
end
if ad:GetAboveSymbolChar() == 248 then
a:SetID(art_table[3])
a:Save()
a:SetID(art_table[1])
a:SaveNew()
remove_duplicates = remove_duplicates + 1
end
if ad:GetAboveSymbolChar() == 172 then
a:SetID(art_table[4])
a:Save()
a:SetID(art_table[1])
a:SaveNew()
remove_duplicates = remove_duplicates + 1
end
end
end
if remove_duplicates > 0 then
delete_duplicate_articulations(noteentry)
end
end
end
function getUsedFontName(standard_name)
local font_name = standard_name
if string.find(os.tmpname(), "/") then
font_name = standard_name
elseif string.find(os.tmpname(), "\\") then
font_name = string.gsub(standard_name, "%s", "")
end
return font_name
end
function vertical_dynamic_adjustment(region, direction)
local lowest_item = {}
local staff_pos = {}
local has_dynamics = false
local has_hairpins = false
local arg_point = finale.FCPoint(0, 0)
local expressions = finale.FCExpressions()
expressions:LoadAllForRegion(region)
for e in each(expressions) do
local create_def = e:CreateTextExpressionDef()
local cd = finale.FCCategoryDef()
if cd:Load(create_def:GetCategoryID()) then
if ((cd:GetID() == finale.DEFAULTCATID_DYNAMICS) or (string.find(cd:CreateName().LuaString, "Dynamic"))) then
if e:CalcMetricPos(arg_point) then
has_dynamics = true
table.insert(lowest_item, arg_point:GetY())
end
end
end
end
local ssmm = finale.FCSmartShapeMeasureMarks()
ssmm:LoadAllForRegion(region, true)
for mark in each(ssmm) do
local smart_shape = mark:CreateSmartShape()
if smart_shape:IsHairpin() then
has_hairpins = true
if smart_shape:CalcLeftCellMetricPos(arg_point) then
table.insert(lowest_item, arg_point:GetY())
elseif smart_shape:CalcRightCellMetricPos(arg_point) then
table.insert(lowest_item, arg_point:GetY())
end
end
end
table.sort(lowest_item)
if has_dynamics == true then
local expressions = finale.FCExpressions()
expressions:LoadAllForRegion(region)
for e in each(expressions) do
local create_def = e:CreateTextExpressionDef()
local cd = finale.FCCategoryDef()
if cd:Load(create_def:GetCategoryID()) then
if ((cd:GetID() == finale.DEFAULTCATID_DYNAMICS) or (string.find(cd:CreateName().LuaString, "Dynamic"))) then
if e:CalcMetricPos(arg_point) then
local difference_pos = arg_point:GetY() - lowest_item[1]
if direction == "near" then
difference_pos = lowest_item[#lowest_item] - arg_point:GetY()
end
local current_pos = e:GetVerticalPos()
if direction == "far" then
e:SetVerticalPos(current_pos - difference_pos)
else
e:SetVerticalPos(current_pos + difference_pos)
end
e:Save()
end
end
end
end
else
for noteentry in eachentrysaved(region) do
if noteentry:IsNote() then
for note in each(noteentry) do
table.insert(staff_pos, note:CalcStaffPosition())
end
end
end
table.sort(staff_pos)
if staff_pos[1] ~= nil then
if staff_pos[1] > -7 then
lowest_item[1] = -160
else
local below_note_cushion = 45
lowest_item[1] = (staff_pos[1] * 12) - below_note_cushion
end
end
end
if has_hairpins == true then
local ssmm = finale.FCSmartShapeMeasureMarks()
ssmm:LoadAllForRegion(region, true)
for mark in each(ssmm) do
local smart_shape = mark:CreateSmartShape()
if smart_shape:IsHairpin() then
if smart_shape:CalcLeftCellMetricPos(arg_point) then
local left_seg = smart_shape:GetTerminateSegmentLeft()
local right_seg = smart_shape:GetTerminateSegmentRight()
local current_pos = left_seg:GetEndpointOffsetY()
local difference_pos = arg_point:GetY() - lowest_item[1]
if direction == "near" then
difference_pos = lowest_item[#lowest_item] - arg_point:GetY()
end
if has_dynamics == true then
if direction == "far" then
left_seg:SetEndpointOffsetY((current_pos - difference_pos) + 12)
right_seg:SetEndpointOffsetY((current_pos - difference_pos) + 12)
else
left_seg:SetEndpointOffsetY((current_pos + difference_pos) + 12)
right_seg:SetEndpointOffsetY((current_pos + difference_pos) + 12)
end
else
left_seg:SetEndpointOffsetY(lowest_item[1])
right_seg:SetEndpointOffsetY(lowest_item[1])
end
smart_shape:Save()
end
end
end
end
end
function horizontal_hairpin_adjustment(left_or_right, hairpin, region_settings, cushion_bool, multiple_hairpin_bool)
local the_seg = hairpin:GetTerminateSegmentLeft()
local left_dynamic_cushion = 9
local right_dynamic_cushion = -9
local left_selection_cushion = 0
local right_selection_cushion = -18
if left_or_right == "left" then
the_seg = hairpin:GetTerminateSegmentLeft()
end
if left_or_right == "right" then
the_seg = hairpin:GetTerminateSegmentRight()
end
local region = finenv.Region()
region:SetStartStaff(region_settings[1])
region:SetEndStaff(region_settings[1])
if multiple_hairpin_bool == false then
region:SetStartMeasure(region_settings[2])
region:SetEndMeasure(region_settings[2])
region:SetStartMeasurePos(region_settings[3])
region:SetEndMeasurePos(region_settings[3])
the_seg:SetMeasurePos(region_settings[3])
else
region:SetStartMeasure(the_seg:GetMeasure())
region:SetStartMeasurePos(the_seg:GetMeasurePos())
region:SetEndMeasure(the_seg:GetMeasure())
region:SetEndMeasurePos(the_seg:GetMeasurePos())
end
local expressions = finale.FCExpressions()
expressions:LoadAllForRegion(region)
local expression_list = {}
for e in each(expressions) do
local create_def = e:CreateTextExpressionDef()
local cd = finale.FCCategoryDef()
if cd:Load(create_def:GetCategoryID()) then
if ((cd:GetID() == finale.DEFAULTCATID_DYNAMICS) or (string.find(cd:CreateName().LuaString, "Dynamic"))) then
local text_met = finale.FCTextMetrics()
local string = create_def:CreateTextString()
string:TrimEnigmaTags()
text_met:LoadString(string, create_def:CreateTextString():CreateLastFontInfo(), 100)
table.insert(expression_list, {text_met:CalcWidthEVPUs(), e, e:GetItemInci()})
end
end
end
if #expression_list > 0 then
local dyn_width = (expression_list[1][1] / 2)
local dyn_def = expression_list[1][2]:CreateTextExpressionDef()
local manual_horizontal = expression_list[1][2]:GetHorizontalPos()
local horizontal_offset = dyn_def:GetHorizontalOffset()
local total_offset = manual_horizontal + horizontal_offset
if left_or_right == "left" then
local total_x = dyn_width + left_dynamic_cushion + total_offset
the_seg:SetEndpointOffsetX(total_x)
elseif left_or_right == "right" then
cushion_bool = false
local total_x = (0 - dyn_width) + right_dynamic_cushion + total_offset
the_seg:SetEndpointOffsetX(total_x)
end
end
if cushion_bool == true then
the_seg = hairpin:GetTerminateSegmentRight()
the_seg:SetEndpointOffsetX(right_selection_cushion)
end
hairpin:Save()
end
function hairpin_adjustments(range_settings, adjustment_type)
local music_reg = finenv.Region()
music_reg:SetStartStaff(range_settings[1])
music_reg:SetEndStaff(range_settings[1])
music_reg:SetStartMeasure(range_settings[2])
music_reg:SetEndMeasure(range_settings[3])
local hairpin_list = {}
local ssmm = finale.FCSmartShapeMeasureMarks()
ssmm:LoadAllForRegion(music_reg, true)
for mark in each(ssmm) do
local smartshape = mark:CreateSmartShape()
if smartshape:IsHairpin() then
table.insert(hairpin_list, smartshape)
end
end
function has_dynamic(region)
local expressions = finale.FCExpressions()
expressions:LoadAllForRegion(region)
local expression_list = {}
for e in each(expressions) do
local create_def = e:CreateTextExpressionDef()
local cd = finale.FCCategoryDef()
if cd:Load(create_def:GetCategoryID()) then
if ((cd:GetID() == finale.DEFAULTCATID_DYNAMICS) or (string.find(cd:CreateName().LuaString, "Dynamic"))) then
table.insert(expression_list, e)
end
end
end
if #expression_list > 0 then