Reading and writing from a file
I'm working on a project where I need to read .mcsz or .xml files and copy them into an existing score. According the API documentation, readScore() reads a score from file but opens it in a new tab, and read() reads file contents and returns a string.
readScore won't work because I need to copy it into an existing file, and there is no information on what read() returns.
I am on Musescore 4 so I can't debug using the plugin creator.
Is there a workaround to this? I am thinking reading the xml file as plain text and somehow parsing it.
Comments
I don't think that readScore() and writeScore() are available yet in the MS4 plugin api. In MS3 you can readScore into a new tab, writeScore it out to a different file, then close the new tab.
file.read() reads an entire file into a variable and you can process it however you like. If it's a human readable text format then you can treat the variable as text. (I wouldn't recommend trying to process non-text files).
I think that javascript xml parsing libraries are available.
In reply to I don't think that readScore… by yonah_ag
I see, so file.read() is meant for reading in .txt files and not files like mcsz, correct?
thanks!
In reply to I see, so file.read() is… by squirrel fish
Correct.
MSCZ is a compressed file, (zip format), so not plain text but you can read MSCX as plain text.
In reply to I see, so file.read() is… by squirrel fish
MS4 plugin writers are eagerly awaiting readScore and writeScore but the FileIO read and write functions do work already.