Skip to content

Commit 26ee378

Browse files
committed
Don't modify input file by removing xml processing instructions
1 parent e928d96 commit 26ee378

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/musicxml_massage_export.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ function plugindef()
44
finaleplugin.NoStore = true
55
finaleplugin.Author = "Robert Patterson"
66
finaleplugin.Copyright = "CC0 https://creativecommons.org/publicdomain/zero/1.0/"
7-
finaleplugin.Version = "1.0"
8-
finaleplugin.Date = "September 24, 2024"
7+
finaleplugin.Version = "1.0.1"
8+
finaleplugin.Date = "September 25, 2024"
99
finaleplugin.CategoryTags = "Document"
1010
finaleplugin.MinJWLuaVersion = 0.74
1111
finaleplugin.Notes = [[
@@ -29,7 +29,7 @@ end
2929

3030
local text_extension = ".musicxml"
3131

32-
local function remove_processing_instructions(file_path)
32+
local function remove_processing_instructions(file_path, output_name)
3333
-- Open the original file for reading
3434
local input_file <close> = io.open(file_path, "r")
3535
if not input_file then
@@ -45,8 +45,8 @@ local function remove_processing_instructions(file_path)
4545
end
4646
-- Close the input file
4747
input_file:close()
48-
-- Open the file for writing (overwrite the original file)
49-
local output_file <close> = io.open(file_path, "w")
48+
-- Open the file for writing (overwrite any file already there)
49+
local output_file <close> = io.open(output_name, "w")
5050
if not output_file then
5151
error("Cannot open file for writing: " .. file_path)
5252
end
@@ -164,10 +164,11 @@ function music_xml_massage_export()
164164
if not xml_file then
165165
return
166166
end
167+
local output_name = append_massaged_to_filename(xml_file)
167168
-- tinyxml2 can't parse processing instructions, so remove them
168-
remove_processing_instructions(xml_file) -- hopefully not necessary forever
169+
remove_processing_instructions(xml_file, output_name) -- hopefully not necessary forever
169170
local musicxml = tinyxml2.XMLDocument()
170-
local result = musicxml:LoadFile(xml_file)
171+
local result = musicxml:LoadFile(output_name)
171172
if result ~= tinyxml2.XML_SUCCESS then
172173
error("Unable to process " .. xml_file .. ". " .. musicxml:ErrorStr())
173174
return
@@ -177,7 +178,6 @@ function music_xml_massage_export()
177178
error("File " .. xml_file .. " does not appear to be a Finale-exported MusicXML file.")
178179
end
179180
process_xml(score_partwise)
180-
local output_name = append_massaged_to_filename(xml_file)
181181
musicxml:SaveFile(output_name)
182182
finenv.UI():AlertInfo("Processed to " .. output_name .. ".", "Processed File")
183183
end

0 commit comments

Comments
 (0)