mscore/file.cpp: Potential Changes/Improvements

• Dec 16, 2015 - 17:25

I'm in the process of separating my SVG animation export code from the basic MuseScore SVG export code. To do this I'm making some changes in file.cpp, and I'd like to see if anyone foresees any issues with these changes. I'm not suggesting integrating this with MuseScore at this time, but this is a first step in that possible direction:

1) Adding two new file types to the standard file dialog filter, both of have the .vtt file extension, and both of which export a combination of SVG and VTT files. I'm using Windows 7, and don't have access to test on other OSes at the moment. Here is the code I'm adding, with a little context, to exportFile():
fl.append(tr("Uncompressed MuseScore File (*.mscx)"));
// two new types
fl.append(tr("SMAWS SVG+VTT (*.vtt"));
fl.append(tr("SMAWS Rulers (*_rul.vtt"));

This should work everywhere, as it is the same as the lines of code above. The only oddity is the pseudo file extension "_rul.vtt".

2) Class MuseScoreCore's first member variable is Score* cs; , yet in file.cpp all the MuseScore::saveXXX() methods pass around a Score* variable as an argument. This is made more confusing by the fact that this argument is sometimes named "cs" just like the member variable, and sometimes not. In changing exportFile(), I must also change saveAs(), the one with 4 args. To cut to the chase, here is what I want to do:
a) Remove all the Score* arguments in all these saveXXX() functions and use the "cs" member variable instead. It is the "current score", just like the arg being passed around.
b) Replace the "name" and "ext" args in saveAs() with a single QFileInfo* arg. So instead of:
bool MuseScore::saveAs(Score* cs, bool saveCopy, const QString& path, const QString& ext)
it would be:
bool MuseScore::saveAs(bool saveCopy, const QFileInfo* fi)
Both a) and b) require changes to musescore.h too. For b), all of the 3 functions that call saveAs() have a QFileInfo fully populated and ready to go, and this simplifies/consolidates bits of code inside saveAs(), as well as providing me all the info I need to deal with my "_rul" pseudo-file-extension.

Foresee any issues? Is 2) something that seems positive and integratable into MuseScore sooner rather than later?


Comments

In reply to by Jojo-Schmitz

I checked QFileInfo about that and no, it's not an issue. It deals with "." as a separator within a file name, nothing else. Maybe you're misunderstanding how this will work. The file dialog will display this as a separate type, but the file name it returns will be "xxx_rul.vtt" with a base name of "xxx_rul". I'll handle parsing the _rul inside the VTT exporter function, and use that to determine if I'm exporting rulers or music.
So what might you suggest as a way to export a single file type multiple ways? I'm looking at QFileDialog and it has no way of finding out which item in the file filters list was selected, all you get back is info about the file name, path, etc.
This would apply to MuseScore SVG export if it were to add "embedded" vs. "external" CSS/Fonts as an option. It's so much nicer to add it as simply another file type in the list, otherwise it must be a custom options dialog, right?

In reply to by sideways

I now have this working and posted to github, though it only works with Native Dialogs. It avoids the kludge of _rul.vtt and truly handles two different "types" with the same extention.
- New defines here:
https://github.com/sidewayss/MuseScore/compare/master...sidewayss:pxSMA…
- New arg in MuseScore::getSaveScoreName() here (only Native). This required changing to the QFileDialog::exec() methodology in order to get QFileDialog::selectedFilter() to work properly. That was the key to this whole process:
https://github.com/sidewayss/MuseScore/compare/master...sidewayss:pxSMA…
- New filters in MuseScore::ExportFile():
https://github.com/sidewayss/MuseScore/compare/master...sidewayss:pxSMA…
- Avoiding a new arg in MuseScore::SaveAs():
https://github.com/sidewayss/MuseScore/compare/master...sidewayss:pxSMA…
- Final handling of two different file "types" with the same file extension:
https://github.com/sidewayss/MuseScore/compare/master...sidewayss:pxSMA…

Do you still have an unanswered question? Please log in first to post your question.