Cancel plugin onScoreStateChanged function
In MS3, once this function is defined it continues to run even when the plugin is closed. I checked this by using a global property var initialsed to 0 and then incrementing each time the function executes, outputting the value to console.log.
After starting and stopping the plugin 4 times and checking the debug log, there were 4 separate instances of the global variable!
How do I cancel onScoreStateChanged on closing the plugin?
Comments
I'd like to know too. My workaround is adding a piece of hidden information to each opened score file and use them to invalidate all but the last onScoreStateChanged
https://musescore.org/en/node/320673#s43
In reply to I'd like to know too. My… by msfp
I haven't found any better solution unless this could be a use case for the infamous Qt.Quit()?
In reply to I haven't found any better… by yonah_ag
Nope. Qt.Quit() doesn't help either.
In reply to Nope. Qt.Quit() doesn't help… by yonah_ag
The developers handbook
https://musescore.org/nl/handbook/developers-handbook/plugins-3x
says/confirms: (search for listener)
• After plugin window is closed, listeners will continue to run, eg experimental onScoreStateChanged Handler
In reply to The developers handbook… by elsewhere
Oops!
There should be a corresponding cancel onScoreStateChanged.
In reply to Oops! There should be a… by yonah_ag
Also, please note that in the link onScoreStateChanged Handler
(https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…)
It warns:
If a plugin modifies score in this handler, then it should:
1. enclose all modifications within Score::startCmd() / Score::endCmd()
2. take care of preventing an infinite recursion, as plugin-originated changes will trigger this signal again after calling Score::endCmd()
In javascript documentation I see removeEventListener(), but not implemented here apparently.
I suspected that the slowing down of the plugin (looks good by the way) might be due to a memory leak, but I see no evidence of that.
After ‘horsing around’ with the plugin (clicking everything like a madman) I got a
cmd('select-all') not valid in current state
and a map timing of 55 sec! but I cannot reproduce
In reply to Also, please note that in… by elsewhere
I do now wrap score mods, (adding debug code letters), and have a flag for recursion but I didn't realise the need until about update 0.6 when I noticed it in a different plugin, (by BSG).
I think that in normal use the plugin will work OK but I might report this on GitHub in case Jojo can add the removeEventListener to 3.7.0.