musescore / MuseScore

MuseScore is an open source and free music notation software. For support, contribution, bug reports, visit MuseScore.org. Fork and make pull requests!
https://musescore.org
Other
12.36k stars 2.67k forks source link

Enable MIDI input state resets after switching between processes #24850

Open wizofaus opened 2 months ago

wizofaus commented 2 months ago

Issue type

UX/Interaction bug (incorrect behaviour)

Description with steps to reproduce

  1. Ensure MuseScore is configured for MIDI input, and that multiple instances can read from the MIDI device (on Windows this requires using LoopMIDI and something like MidiTools or MidiOX)
  2. In one instance of MuseSore with a score open, confirm that playing notes on a MIDI input device causes them to sound
  3. In the playback toolbar settings menu, turn off "Enable MIDI input" and confirm that notes played on the MIDI keyboard no longer sound
  4. Start a second instance of MuseScore with a (different) score, ensuring the current staff is for a different instrument than the first one. Note that "Enable MIDI input" is turned off there, so now turn it on.
  5. Confirm that MIDI keyboard plays back notes for just the instrument for the current staff in the second instance.
  6. Switch to the first instance and then back to second instance, and play notes via a MIDI device again.
  7. Expected: notes should continue to play just for the second (active) instance and not the first.
  8. Actual: MIDI playback now occurs via BOTH instances simultaneously (esp. noticeable if the current staff in one is a transposing instrument).

Supporting files, videos and screenshots

N/A, can record video if really needed a bit involved to demonstrate.

What is the latest version of MuseScore Studio where this issue is present?

4.4

Regression

I was unable to check

Operating system

Windows 11

Additional context

I've noted before that Windows doesn't handle MIDI input devices well with multiple processes - the fact that you need special software for it work at all is obviously not ideal, but in this case it's really MuseScore that's not doing what seems reasonable to expect, which is to maintain a separate "Enable MIDI input" state between instances - it seems to be trying to sync them all to use the same setting, though the menu itself doesn't always reflect that.

Ultimately all I want to do is to have MIDI input only work for the instance with the focus (exactly the same way computer keyboard input works), but if I'm able to at least turn it off for one instance and on for another, that's fine too.

Checklist

wizofaus commented 2 months ago

BTW this is easily fixed by changing NotationConfiguration::setIsMidiInputEnabled to use setLocalValue instead of setSharedValue.
Is there a good reason to use setSharedValue here? Personally I wouldn't expect any of the settings in this menu (auto-pan, play repeats etc.) to automatically sync between instances while they're still open. At most I'd expect that after changing such an option, the next instance I start of MuseScore will use that setting.

What I'd actually like to change it to is:

void NotationConfiguration::setIsMidiInputEnabled(bool enabled)
{
    settings()->setLocalValue(IS_MIDI_INPUT_ENABLED, Val(enabled));
    if (!enabled) {
        midiInPort()->disconnect();
    } else {
        midiInPort()->connect(midiConfiguration()->midiInputDeviceId());
    }
}

(requires injecting midiInPort and midiConfiguration into NotationConfiguration, but creates no additional dependencies). This allows you do disable MIDI input for one instance so another can grab exclusive access if you're not using LoopMIDI etc. However it's not really enough on its own to work smoothly, so is probably best done as part of a separate change.

cbjeukendrup commented 2 months ago

I think this should be solved in the following way:

Or, @bkunda, what is your opinion about the following?

Personally I wouldn't expect any of the settings in this menu (auto-pan, play repeats etc.) to automatically sync between instances while they're still open. At most I'd expect that after changing such an option, the next instance I start of MuseScore will use that setting.

wizofaus commented 2 months ago

"MuseScore instances should only react to MIDI input when they have focus; just like the computer keyboard"

Yes, that would be my preference too, though on Windows that means explicitly having to release the MIDI in port on losing focus, and on gaining focus, attempting to repeated grab it until it succeeds.

But then what's the purpose of that "Enable MIDI input" menu option at all?

wizofaus commented 2 months ago

BTW some related issues: https://github.com/musescore/MuseScore/issues/16075 https://github.com/musescore/MuseScore/issues/23870

If it's agreed the behaviour should be "only enable MIDI input when window has the focus" and that for Windows, it should release the MIDI port when it doesn't (and try at least a couple of times when it does receive the focus, to allow time for it to be released by other processes), then I'm more than happy to implement that.