load_score based on file extension
fosfrancesco opened this issue · 3 comments
Right now load_score works by trying all possible parsers in try-except.
While this seems nice, so it can handle files with slightly different extensions strings, it creates many other problems:
- speed: for file types at the end of the try except list, all the other parsers need to start and fail before the right one is used
- failing clause: sometimes a parser just doesn't fail and yields invalid results. For example there is not universal way of knowing for example if a file is of XML type. I implemented some heuristics for the Kern and MEI parser to stop them earlier, but I'm not sure this is covering all possible cases.
For example I was trying to load musescore scores without having musescore installed. Instead of an error it was loading the musescore file as match file. Producing a score with 0 parts.
All considered I vote to use an extension-based system, where a set of possible extension strings is hardcoded for each file type. E.g., for XML ".musicxml, .mxml, .mxl, .MusicXML, etc.."
From my experience at Apple, where the same software (QuickTime first, and then AVFoundation) could open anything from .mov to .mp3 to .jpg: we insisted on only using file extension, and never sniffing inside the file to see which parser to use. And we were VERY glad of that decision over the years.
I guess this could be a good change, which will reduce some overhead of the try
except
clauses. Although I was in favor of the original implementation, I've come to see that there are a few quirks that would require unnecessarily convoluted bolierplate code. So yes, I think it would be better to just check the extension.
Ok, I will work on that then!