@@ -4,8 +4,8 @@ function plugindef()
4
4
finaleplugin .NoStore = true
5
5
finaleplugin .Author = " Robert Patterson"
6
6
finaleplugin .Copyright = " CC0 https://creativecommons.org/publicdomain/zero/1.0/"
7
- finaleplugin .Version = " 1.0"
8
- finaleplugin .Date = " October 2 , 2024"
7
+ finaleplugin .Version = " 1.0.1 "
8
+ finaleplugin .Date = " October 6 , 2024"
9
9
finaleplugin .CategoryTags = " Document"
10
10
finaleplugin .MinJWLuaVersion = 0.75
11
11
finaleplugin .Notes = [[
54
54
55
55
-- luacheck: ignore 11./global_dialog
56
56
57
- local lfs = require (" lfs" )
58
57
local text = require (" luaosutils" ).text
59
58
60
59
local mixin = require (" library.mixin" )
61
60
local enigma_string = require (" library.enigma_string" )
61
+ local utils = require (" library.utils" )
62
62
63
63
do_folder = do_folder or false
64
64
65
- local logfile_name = " FinaleMuseScoreSettingsExportLog.txt"
65
+ local LOGFILE_NAME <const> = " FinaleMuseScoreSettingsExportLog.txt"
66
66
67
- local musx_extension = " .musx"
68
- local mus_extension = " .mus"
69
- local text_extension = " .mss"
70
- local part_extension = " .part" .. text_extension
71
- local mss_version = " 4.40"
67
+ local MUSX_EXTENSION <const> = " .musx"
68
+ local MUS_EXTENSION <const> = " .mus"
69
+ local TEXT_EXTENSION <const> = " .mss"
70
+ local PART_EXTENSION <const> = " .part" .. TEXT_EXTENSION
71
+ local MSS_VERSION <const> = " 4.40"
72
72
73
73
-- hard-coded scaling values
74
74
local EVPU_PER_INCH <const> = 288
@@ -159,22 +159,6 @@ function open_current_prefs()
159
159
text_exps :LoadAll ()
160
160
end
161
161
162
- -- returns Lua strings for path, file name without extension, full file path
163
- function get_file_path_no_extension (file_path_str )
164
- local path_name = finale .FCString ()
165
- local file_name = finale .FCString ()
166
- local file_path = finale .FCString (file_path_str )
167
- file_path :SplitToPathAndFile (path_name , file_name )
168
- local full_file_name = file_name .LuaString
169
- local extension = finale .FCString (file_name .LuaString )
170
- extension :ExtractFileExtension ()
171
- if extension .Length > 0 then
172
- file_name :TruncateAt (file_name :FindLast (" ." .. extension .LuaString ))
173
- end
174
- path_name :AssureEndingPathDelimiter ()
175
- return path_name .LuaString , file_name .LuaString , full_file_name
176
- end
177
-
178
162
function set_element_text (style_element , name , value )
179
163
local setter_func = " SetText"
180
164
if type (value ) == " nil" then
@@ -628,7 +612,7 @@ function write_xml(output_path)
628
612
local mssxml <close> = tinyxml2 .XMLDocument ()
629
613
mssxml :InsertEndChild (mssxml :NewDeclaration (nil ))
630
614
local ms_element = mssxml :NewElement (" museScore" )
631
- ms_element :SetAttribute (" version" , mss_version )
615
+ ms_element :SetAttribute (" version" , MSS_VERSION )
632
616
mssxml :InsertEndChild (ms_element )
633
617
local style_element = ms_element :InsertNewChildElement (" Style" )
634
618
currently_processing = output_path
@@ -664,13 +648,13 @@ function process_document(document_file_path)
664
648
local parts = finale .FCParts ()
665
649
parts :LoadAll ()
666
650
-- it is not actually necessary to switch to the part to get its settings
667
- local path_name , file_name_no_ext = get_file_path_no_extension (document_file_path )
651
+ local path_name , file_name_no_ext = utils . split_file_path (document_file_path )
668
652
current_is_part = false
669
- write_xml (path_name .. file_name_no_ext .. text_extension )
653
+ write_xml (path_name .. file_name_no_ext .. TEXT_EXTENSION )
670
654
for part in each (parts ) do
671
655
if not part :IsScore () then
672
656
current_is_part = true
673
- write_xml (path_name .. file_name_no_ext .. part_extension )
657
+ write_xml (path_name .. file_name_no_ext .. PART_EXTENSION )
674
658
break
675
659
end
676
660
end
@@ -724,9 +708,10 @@ function create_status_dialog(selected_directory, files_to_process)
724
708
dialog :RegisterHandleTimer (function (self , timer )
725
709
assert (timer == TIMER_ID , " incorrect timer id value " .. timer )
726
710
if # files_to_process <= 0 then
727
- self :GetControl (" folder" ):SetText (selected_directory )
728
- self :GetControl (" file_path" ):SetText (" Export complete." )
729
711
self :StopTimer (TIMER_ID )
712
+ self :GetControl (" folder" ):SetText (selected_directory )
713
+ self :GetControl (" file_path_label" ):SetText (" Log:" )
714
+ self :GetControl (" file_path" ):SetText (LOGFILE_NAME .. " (export complete)" )
730
715
currently_processing = selected_directory
731
716
log_message (" processing complete" )
732
717
self :GetControl (" cancel" ):SetText (" Close" )
@@ -754,40 +739,15 @@ function create_status_dialog(selected_directory, files_to_process)
754
739
dialog :RunModeless ()
755
740
end
756
741
757
- function collect_files (utf8_folder_path , files_to_process )
758
- local folder_path_fcstr = finale .FCString (utf8_folder_path )
759
- folder_path_fcstr :AssureEndingPathDelimiter ()
760
- utf8_folder_path = folder_path_fcstr .LuaString
761
- local lfs_folder_path = text .convert_encoding (utf8_folder_path , text .get_utf8_codepage (), text .get_default_codepage ())
762
- for lfs_finale_doc in lfs .dir (lfs_folder_path ) do
763
- if lfs_finale_doc ~= " ." and lfs_finale_doc ~= " .." then
764
- local utf8_finale_doc = text .convert_encoding (lfs_finale_doc , text .get_default_codepage (), text .get_utf8_codepage ())
765
- if (lfs_finale_doc :sub (- musx_extension :len ()) == musx_extension ) or (lfs_finale_doc :sub (- mus_extension :len ()) == mus_extension ) then
766
- if lfs_finale_doc :sub (1 , 2 ) == " ._" then
767
- currently_processing = utf8_folder_path .. utf8_finale_doc
768
- log_message (" skipping macOS resource fork" , true )
769
- else
770
- table.insert (files_to_process , {name = utf8_finale_doc , folder = utf8_folder_path })
771
- end
772
- else
773
- local attr = lfs .attributes (lfs_folder_path .. lfs_finale_doc )
774
- if attr and attr .mode == " directory" then
775
- collect_files (utf8_folder_path .. utf8_finale_doc , files_to_process )
776
- end
777
- end
778
- end
779
- end
780
- end
781
-
782
742
function select_target (file_path_str )
783
- local path_name , file_name_no_ext = get_file_path_no_extension (file_path_str )
784
- local file_name = file_name_no_ext .. (current_is_part and part_extension or text_extension )
743
+ local path_name , file_name_no_ext = utils . split_file_path (file_path_str )
744
+ local file_name = file_name_no_ext .. (current_is_part and PART_EXTENSION or TEXT_EXTENSION )
785
745
local save_dialog = finale .FCFileSaveAsDialog (finenv .UI ())
786
746
save_dialog :SetWindowTitle (finale .FCString (" Save MuseScore style settings as" ))
787
- save_dialog :AddFilter (finale .FCString (" *" .. text_extension ), finale .FCString (" MuseScore Style Settings File" ))
747
+ save_dialog :AddFilter (finale .FCString (" *" .. TEXT_EXTENSION ), finale .FCString (" MuseScore Style Settings File" ))
788
748
save_dialog :SetInitFolder (finale .FCString (path_name ))
789
749
save_dialog :SetFileName (finale .FCString (file_name ))
790
- save_dialog :AssureFileExtension (text_extension )
750
+ save_dialog :AssureFileExtension (TEXT_EXTENSION )
791
751
if not save_dialog :Execute () then
792
752
return nil
793
753
end
@@ -823,14 +783,18 @@ function document_options_to_musescore()
823
783
end
824
784
local selected_directory = select_directory ()
825
785
if selected_directory then
826
- logfile_path = text .convert_encoding (selected_directory , text .get_utf8_codepage (), text .get_default_codepage ()) .. logfile_name
786
+ logfile_path = text .convert_encoding (selected_directory , text .get_utf8_codepage (), text .get_default_codepage ()) .. LOGFILE_NAME
827
787
local file <close> = io.open (logfile_path , " w" )
828
788
if not file then
829
789
error (" unable to create logfile " .. logfile_path )
830
790
end
831
791
file :close ()
832
792
local files_to_process = {}
833
- collect_files (selected_directory , files_to_process )
793
+ for folder , filename in utils .eachfile (selected_directory , true ) do
794
+ if (filename :sub (- MUSX_EXTENSION :len ()) == MUSX_EXTENSION ) or (filename :sub (- MUS_EXTENSION :len ()) == MUS_EXTENSION ) then
795
+ table.insert (files_to_process , {name = filename , folder = folder })
796
+ end
797
+ end
834
798
create_status_dialog (selected_directory , files_to_process )
835
799
end
836
800
else
0 commit comments