Problem with curScore in plugin.

• Jun 24, 2012 - 21:02
Type
Plugins
Severity
S4 - Minor
Status
closed
Project

When using the following code to check for the presence of a score at the start of the MIDISightReader plugin:

if (typeof curScore === 'undefined')
{
// There's no current score loaded.
showMessage("Error", "Please load a score before using the MIDI sight reader plugin.\n");
return;
}

... it normally works fine.

However, if you load a score, run the MIDISightReaderPlugin, then close the score without saving, the variable curScore is not 'undefined' anymore. So when running the plugin again, the above code does not get called and MuseScore crashes when curScore.save(...) is subsequently called.
It is possibly related to the MIDISightReaderPlugin using OSC to change the colour of notes in the score.

Nightly build 5659.
Windows Vista 32-bit.


Comments

With the new QML plugin framework, checking for curScore with the code below does not work at all - MuseScore crashes whever there is no score open.

if (typeof curScore === 'undefined')
Qt.quit();

Try this QML file on nightly build MuseScoreNightly-2012-08-10-c65f00f.7z for Windows (Vista 32-bit):

import QtQuick 1.0
import MuseScore 1.0
import FileIO 1.0

MuseScore
{
menuPath: "Plugins.RunTest"
version: "0.01"
description: "TEST."

onRun:
{
if (typeof curScore === 'undefined')
Qt.quit();

console.log("-----------------");
console.log(menuPath);
console.log(midiFile.source);

// Write the score to a MIDI file.
writeScore(curScore, midiFile.source, "mid");
Qt.quit()
}

FileIO
{
id: midiFile
source: tempPath() + "/MIDI_Sight_Reader.mid"
onError: console.log(msg)
}
}

The crash happens on writeScore() so the condition is not working. A working condition is

if (curScore == null)

I will protect the writeScore method again null scores.

Yes, the condition (in many of the QML example files) does not seem to work.
This does:

if (curScore == null)
{
Qt.quit();
return;
}

Or to be sure to be sure:

if (typeof curScore === 'undefined' || curScore == null)
{
Qt.quit();
return;
}