Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jack-midi support #19246

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open

jack-midi support #19246

wants to merge 33 commits into from

Conversation

lyrra
Copy link
Contributor

@lyrra lyrra commented Sep 1, 2023

  • I signed the CLA

Purpose

For linux users, the ability to at runtime switch between alsa and jack audio+midi driver.

Changes

  • Make both jack and alsa(linuxdriver) more similar to osx-driver
  • Make jack and alsa drivers "subdrivers" of linuxdriver (AudioDriverState).

class design changes

Before:

AudioModule
│
├── LinuxAudioDriver
│   │
│   Alsa
│   └──> device: "default"
│
├── OSXAudioDriver
│   ...
│
└── WasapiAudioDriver
    ...

MidiModule
│
├── LinuxAudioDriver
│   │
│   ├────> AlsaMidiOutPort
│   └────> AlsaMidiInPort
│   
:

After:


AudioModule
│
|         MidiModule
│             |
├── AudioMidiManager (was LinuxAudioDriver)
│        |      │
│        |      ├─── JackDriverState
│        |      │    │
│        |      │    (jack-code)
│        |      │    └──> jack client open
│        |      └──> AlsaDriverState
│        |                      │
│        |              (alsa-code)
│        |                      └──> device: "default"
│        │
│        + LinuxMidiOutPort
│        │
│        ├────> JackMidiOutPort
│        ├────> AlsaMidiOutPort
│        + LinuxMidiInPort
|          :
│
├── OSXAudioDriver
│   ...
│
└── WasapiAudioDriver
    ...

MidiModule
│
├── AudioMidiManager (was LinuxAudioDriver)
│   │
│   + LinuxMidiOutPort
│   │
│   ├────> JackMidiOutPort
│   ├────> AlsaMidiOutPort
│   + LinuxMidiInPort
:

Audio Tests

  • start with jack, play and hear audio OK
  • start with alsa, play and hear audio OK
  • start with jack, switch to alsa, then play OK
  • start with alsa, switch to jack, then play OK
  • switch from jack to alsa during play OK
  • switch from alsa to jack during play OK

Midi tests

  • start fluidsynth in verbose mode, musescore and qjackctl (to midi-connect them), verify midi-events are logged by fluidsynth.

Optional cleanups / redesign

Remove LinuxAudioDriver and keep only AlsaAudioDriver and JackAudioDriver as two independent implementations. To switch between them, you need to add another class, something like IAudioDriverProvider. This is what you need to add to IoC (and remove the drivers from IoC). Access the driver through this class, like:

class IAudioDriverProvider ...
{
...

        std::shared_ptr<IAudioDriver> driver() const;
  
        void swithDriver(const std::string& name); 
        async::Chanel<std::string /*name*/> dirverChanged() const;
}


class SomeClass
    Inject<IAudioDriverProvider > audioDriverProvider;


...

     audioDriverProvider()->driver();

This greatly simplifies everything, each class becomes simple and does one thing.
Moreover, such a system is easily scalable; we can easily add other drivers, cross-platform or platform-specific.

Not in scope for this PR

  • MIDI-channel-per-instrument

Known cleanups & fixes before merge

  • send foreign commits upstream:
    Misc. needed for jack #22373
  • cleanup: avoid global in app
  • If possible do mutual dependency Injection between module Audio and Midi.
    Testing confirmed, can't inject modules.
    Injection is used, but not at modul level.
  • de-pollute any interfaces that got sprinkled with data members
  • ensure no public data members begins with m_ (those should be private)
  • remove sample-rate dropdown OR make it work,
    No 'requires restart' added
  • automatic connection to audio ports upon start
    Not in scope, brings in too much arbitrary heuristics code from Mu3.
  • Possible to switch between jack/alsa driver (currently it crashes)
  • Possible to switch bufferSize in jack without crash (possible in alsa)

@lyrra lyrra force-pushed the jack branch 3 times, most recently from ce43ca7 to b218652 Compare September 1, 2023 09:42
@lyrra lyrra changed the title jack: cleanup, remove usage of static variables jack/alsa: cleanup, remove usage of static variables Sep 1, 2023
@lyrra lyrra force-pushed the jack branch 6 times, most recently from 7638762 to 22128db Compare September 2, 2023 11:18
@lyrra lyrra changed the title jack/alsa: cleanup, remove usage of static variables jack/alsa: switch runtime support Sep 2, 2023
@lyrra lyrra force-pushed the jack branch 2 times, most recently from 999e2a8 to 7a2a941 Compare September 2, 2023 12:29
@lyrra lyrra marked this pull request as ready for review September 2, 2023 13:20
@lyrra lyrra force-pushed the jack branch 7 times, most recently from 3e582e1 to 24705bc Compare September 8, 2023 04:57
@cbjeukendrup cbjeukendrup linked an issue Sep 8, 2023 that may be closed by this pull request
@lyrra lyrra mentioned this pull request Sep 11, 2023
lyrra added 22 commits April 27, 2024 12:51
- move out alsaaudiodriver things into alsaaudiodriver
- linuxaudiodriver is the driver hander, that musescore
  talks to, and is responsible for running jack or alsa
* separate linux-midi from linux-alsa
* move alsa to own directory
* midimodule separate linux/alsa
A commandline-option to handle changes in the
jack-transport delay caused by buffering.
* seek possible if not playing
* jack is soft-realtime, use separate musescore access thread
* start/stop transport from musescore
* take into account wall-clock elapse by
  non-realtime worker when calculating musescore seek position
* allow for some time-imprecision in playbackPositionInSeconds
* avoid playbackPositionInSeconds due to imprecision
* playbackposition remote{seek|playOrStop}
* adjustable delay by cli jackTransportDelay
The callback member isn't really a specification,
so we need to copy it around, because it is set
above the linuxdriver class, and needed if we change
driver
@cfirwin3
Copy link

cfirwin3 commented Apr 28, 2024

This is the only branch that seems to work for me in Ubuntu 24.04. Yikes! The master release doesn't properly connect to audio or play back in the latest OS (which is the LTS release). Jack capability may be necessary and most dependable going forward with Pipewre being the default sound server.

EDIT: Ubuntu (Studio) 24.04 has Pipewire set by default to 48000. That's why this branch works while the trunk does not. One can (if they figure it out) switch Pipewire to 44100 to use M4 master trunk.

I think that a sample rate selection is essential for M4 and if this branch can resolve that issue as well, that would be great.

@lyrra
Copy link
Contributor Author

lyrra commented Apr 29, 2024

I think that a sample rate selection is essential for M4 and if this branch can resolve that issue as well, that would be great.

This branch has a samplerate selection (dropdown), it should work. The only issue is that it requires a restart of Mu, so perhaps a warning message of that would be nice too (but not in scope for this PR as I dont know how).

Also, there should be a checkbox to turn off jack transport, because it is a bit intrusive if not being used. That shouldn't be too much work because there exist prior work we can copy.

@cfirwin3
Copy link

I think that a sample rate selection is essential for M4 and if this branch can resolve that issue as well, that would be great.

This branch has a samplerate selection (dropdown), it should work. The only issue is that it requires a restart of Mu, so perhaps a warning message of that would be nice too (but not in scope for this PR as I dont know how).

Also, there should be a checkbox to turn off jack transport, because it is a bit intrusive if not being used. That shouldn't be too much work because there exist prior work we can copy.

I see the drop down in the Linux build, but it only has the default 48000 in the closed field and the drop down box is empty. I remember a build quite a while ago that listed sample rates, but the current one doesn't seem to have options.

@cfirwin3
Copy link

cfirwin3 commented May 1, 2024

So it looks like you can run multiple M4 sessions in sync and mix down to DAW with this branch:
https://youtu.be/0Xdy4zMXPZ8?si=iLXVmH8moYENEmbp

If anyone was wondering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MuseScore not supporting JACK audio anymore (Linux)