Undefined properties and function

• Nov 8, 2021 - 01:56

Writing my first plugin. I have this code:

        console.log("curScore: " + curScore)
        console.log("\ttypeof: " + typeof curScore)
        console.log("\tversion:  " + curScore.version)
        console.log("\tcomposer:  " + curScore.composer)
        console.log("\ttitle:  " + curScore.title)
        console.log("\tsubtitle:  " + curScore.subtitle)
        console.log("\tfileName: " + curScore.fileName)
        console.log("\tmeasures: " + curScore.measures)
        curScore.appendMeasures(11)
        curScore.close()

which outputs:

Debug: curScore: Ms::PluginAPI::Score(0x75a9190)
Debug: typeof: object
Debug: version: undefined
Debug: composer:
Debug: title: The Spruce
Debug: subtitle: undefined
Debug: fileName: undefined
Debug: measures: undefined
Debug: Exception TypeError: Property 'close' of object Ms::PluginAPI::Score(0x77d4840) is not a function

  1. I have the composer, title, and subtitle text defined in the file, yet they do not show up here. Why not?
  2. Why is version undefined?
  3. The appendMeasures() works.
  4. It says close is not a function but I see it defined here:
    https://musescore.org/en/handbook/developers-handbook/plugin-developmen…
    What is happening here?

Comments

I'm no expert on the plugin framework, but I know a decent amount about MuseScore internal architecture. I'm guessing you only added text for title, etc, but didn't actually define them in the metadata (File / Score Properties). For the version, my guess is that info doesn't get generated until you save - it's meant to convey the version of MuseScore used to save the file. No real idea about close().

  1. Because those are taken from the Score Properties and I'm willing to bet you don't have those set
  2. Because that property isn't defined by the plugin api
  3. yes, existing methods work
  4. There's that big fat warning on the page you linked that that is a page for MuseScore 1.x
    You are most likely not developing a plugin for MuseScore 1.

So use the correct reference for the current version, such as https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…

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