Note jumps and skips intervals when moved with up/down arrow keys

• Dec 26, 2020 - 23:21
Reported version
3.5
Type
Plugins
Frequency
Once
Severity
S3 - Major
Reproducibility
Always
Status
closed
Regression
No
Workaround
No
Project

Also: "Note pitch cannot be changed correctly by QML plugin"

The bug shows up after I run a plugin that changes a note's pitch using the pitch property. The attached animated GIF shows what happens when I select the note and press the up arrow keys. At some points, the note jumps up by a certain interval. Later in the animation, I press the down key and there are jumps as well.

What my plugin does:

    onRun: {
        curScore.startCmd()
        applyToChordsInSelection(chord => {
            let note = chord.notes[0]
            let pitch = note.pitch + 2
            console.log(`Changing ${note.pitch} to ${pitch}`)
            console.log(`Before: tpc1 = ${note.tpc1}, tpc2 = ${note.tpc2}, pitch = ${note.pitch}`)
            note.pitch = pitch
            console.log(`After: tpc1 = ${note.tpc1}, tpc2 = ${note.tpc2}, pitch = ${note.pitch}`)
            console.log("--------------------------------")
        })
        curScore.endCmd()
    }

The applyToChordsInSelection function is adopted from the colornotes sample plugin.

Steps to reproduce:

  1. Type a single note in MuseScore.
  2. Open the attached plugin in the plugin editor.
  3. Select the measure containing the note.
  4. Run the plugin.
  5. Confirm that the note is jumping when it is selected and the up/down arrow keys are used.

Also, the attached plugin does not reliably changes a note pitch. Changing line or tpc* has no effect. Changing pitch has weird effects.

Remarks:

  • The MIDI sound on moving the note up/down is correct (always in semitone steps), no matter whether the note jumps or moves correctly in semitone steps.
  • tpc, tpc1, and tpc2 are different from the pitch, e.g. 14 instead of 60
  • When I save and re-open the .mscz file, the wrong behaviour is gone.
  • Documentation: https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…
Attachment Size
Peek 2020-12-27 00-04.gif 61.97 KB
test.qml 2.84 KB

Comments

When you change pitch, you generally need to change tpc as well. Results are undefined if they are not in agreement (eg, a pitch of 60 needs a tpc of either C, B#, or Dbb).

So as far as I know there is no bug here, other than perhaps the documentation could stand to be clearer on this point?

pitch and tpc* are not in agreement before I run my plugin:

Debug: Before: tpc = 17, tpc1 = 17, tpc2 = 17, pitch = 69

I changed my plugin to set pitch and tpc* all to the same MIDI pitch value 71:

  1. This makes MuseScore freeze and crash after 3 seconds:
            note.pitch = pitch
            note.tpc = pitch
            note.tpc1 = pitch
            note.tpc2 = pitch // <-- this line causes the crash
  1. This has the same problem than the plugin code in the initial report (no visible change, jumping):
            note.pitch = pitch
            note.tpc = pitch
            note.tpc1 = pitch

The console output here is:

Debug: Changing 69 to 71
Debug: Before: tpc = 17, tpc1 = 17, tpc2 = 17, pitch = 69
Warning: PluginAPI::Note::setTpc: invalid tpc: 71
Debug: After: tpc = 17, tpc1 = 71, tpc2 = 17, pitch = 71
Debug: --------------------------------

Yes, a more clear documentation would help. Forum posts on the topic tell that I have to change some tpc* but that doesn't really help.

Unless I'm doing something substantially wrong in the plugin code, there are apparently some related bugs.

TPC is not supposed to the same as pitch, it's supposed to be in agreement with it. As I said, for a pitch of 60, you need to set the TPC values to either C, B#, or Dbb (probably accessed in plugins as enums, not sure how the framework exposes these). See the documentation on TPC to understand how those values work. But 60 is surely a meaningless value for TPC, as is 71.