CPJKU / partitura

A python package for handling modern staff notation of music
https://partitura.readthedocs.io
Apache License 2.0
227 stars 15 forks source link

load_score based on file extension #312

Closed fosfrancesco closed 1 year ago

fosfrancesco commented 1 year ago

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:

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.."

gregchapman-dev commented 1 year ago

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.

neosatrapahereje commented 1 year ago

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.

fosfrancesco commented 1 year ago

Ok, I will work on that then!