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

[BUG] MIDI failure in JVM on fresh install cause alda and alda-player to both fail #496

Open
BurntChromium opened this issue Feb 27, 2024 · 3 comments

Comments

@BurntChromium
Copy link

BurntChromium commented Feb 27, 2024

🐞 Bug report 🐞

Description

On a fresh install, the software seems unable to start due to Java issues with MIDI. (WSL Debian / Java 17 / more details below)

Steps to Reproduce

  1. Install latest Java available in apt (Java 17, which is behind the newest 21 LTS on Adoptium but alda.io doesn't list a minimum required version).
  2. Download alda
$ sudo apt-get install openjdk-17-jre
$ java -version

openjdk version "17.0.10" 2024-01-16
OpenJDK Runtime Environment (build 17.0.10+7-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 17.0.10+7-Debian-1deb11u1, mixed mode, sharing)

$ wget https://alda-releases.nyc3.digitaloceanspaces.com/2.2.7/client/linux-amd64/alda
$ wget https://alda-releases.nyc3.digitaloceanspaces.com/2.2.7/player/non-windows/alda-player
  1. Both programs added to .bashrc
  2. Check installation
$ alda version
alda 2.2.7
$ alda-player info
alda-player 2.2.7
log path: /home/<redacted>/.cache/alda/logs

$ alda doctor
...
ERR Export score as MIDI

---

Oops! Something went wrong:
  open /tmp/alda-doctor3543009648/1709073986.mid: no such file or directory

$ alda play -c "(tempo! 160) trumpet: (quant 60) f12 b- > d f6 d12 f1"
Starting player processes...
It looks like Alda is having trouble starting player processes in the
background.

$  alda-player -v run -p 27278
...
nyb INFO  2024-02-27 17:48:14 MidiEngine.<init>:281 - Initializing MIDI synthesizer...
Exception in thread "main" javax.sound.midi.MidiUnavailableException: Can not open line
        at java.desktop/com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1183)
        at java.desktop/com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1093)
        at io.alda.player.MidiEngine.<init>(MidiEngine.kt:283)
        at io.alda.player.PlayerKt.midi(Player.kt:19)
        at io.alda.player.Run.run(Main.kt:86)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:139)
        at com.github.ajalt.clikt.parsers.Parser.parse(Parser.kt:14)
        at com.github.ajalt.clikt.core.CliktCommand.parse(CliktCommand.kt:215)
        at com.github.ajalt.clikt.core.CliktCommand.parse$default(CliktCommand.kt:212)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:230)
        at com.github.ajalt.clikt.core.CliktCommand.main(CliktCommand.kt:253)
        at io.alda.player.MainKt.main(Main.kt:144)
Caused by: java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.
        at java.desktop/javax.sound.sampled.AudioSystem.getLine(AudioSystem.java:425)
        at java.desktop/javax.sound.sampled.AudioSystem.getSourceDataLine(AudioSystem.java:534)
        at java.desktop/com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1123)
        ... 11 more

Expected Behavior

The post-install verification commands should successfully execute.

Actual Behavior

Both programs error out.

Environment

Operating system and version: Windows 11

Run in WSL 2 - Debian.

$ cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
...

Alda version:

$ alda version
alda 2.2.7
$ alda-player info
alda-player 2.2.7

Health check:

$ alda doctor
OK  Parse source code
OK  Generate score model
OK  Ensure that there are no stale player processes
OK  Find an open port
OK  Send and receive OSC messages
OK  Locate alda-player executable on PATH
OK  Check alda-player version
OK  Spawn a player process
OK  Ping player process
OK  Play score
ERR Export score as MIDI

---

Oops! Something went wrong:
  open /tmp/alda-doctor4015254632/1709074203.mid: no such file or directory

This might be a bug. For help, consider filing an issue at:
  https://github.com/alda-lang/alda/issues/new/choose

Or come chat with us on Slack:
  https://slack.alda.io

Logs:

The server seems locked in a loop where it tries to restart the MIDI engine. However, no actual errors are logged to the file.

erw INFO  2024-02-27 17:00:12 Main.run:77 - Starting receiver, listening on port 43273...
uzg INFO  2024-02-27 17:00:12 MidiEngine.<init>:276 - Initializing MIDI sequencer...
xky INFO  2024-02-27 17:00:12 MidiEngine.<init>:276 - Initializing MIDI sequencer...
uzg INFO  2024-02-27 17:00:12 MidiEngine.<init>:281 - Initializing MIDI synthesizer...
xky INFO  2024-02-27 17:00:12 MidiEngine.<init>:281 - Initializing MIDI synthesizer...
erw INFO  2024-02-27 17:00:12 MidiEngine.<init>:276 - Initializing MIDI sequencer...
erw INFO  2024-02-27 17:00:12 MidiEngine.<init>:281 - Initializing MIDI synthesizer...

(Something similar to the above on different ports comprises the majority of the logfiles).

@daveyarwood
Copy link
Member

Hi, thanks for reporting this!

I did a little googling, and it seems like maybe audio doesn't work out of the box in WSL. I found this page, which looks like it has some good information about setting up audio in WSL.

I'm curious - if you install and run Firefox (or other programs that produce sound) inside WSL, does the audio work?

@BurntChromium
Copy link
Author

Hi, thanks for reporting this!

I did a little googling, and it seems like maybe audio doesn't work out of the box in WSL. I found this page, which looks like it has some good information about setting up audio in WSL.

I'm curious - if you install and run Firefox (or other programs that produce sound) inside WSL, does the audio work?

Hi, thanks for looking at this! The linked blog post is out of date (it's for the WSL 1 Beta from 7 years ago). In WSL2, audio has been built in since the release of the WSLg project a few years ago (https://github.com/microsoft/wslg). Any installation of WSL 2 inside of Windows 11 will include WSLg by default. The workaround suggested in the blog (install PulseAudio) is now a native component within WSL2, so I don't think that's the issue. Various scattered comments seem to corroborate this (microsoft/WSL#7107 (comment)).

I could be misunderstanding the dependency chain, but the alda doctor output suggests that while audio playback is fine, the MIDI translation to send data to the playback device is the issue. This is corroborated by MIDI being the source of the exception in the alda-player.

 MidiEngine.<init>:281 - Initializing MIDI synthesizer...
Exception in thread "main" javax.sound.midi.MidiUnavailableException: Can not open line
...
Caused by: java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian is supported.

I will note that installed under Windows rather than WSL, the application does seem to work.

Further investigation

I've tried the following:

  • remove openjdk-17-jre
  • install default-jdk (which is version "11.0.22")

So I don't think it's an issue with Java per se.

At any rate, I've found scattered comments with similar issues (https://stackoverflow.com/questions/71381472/issues-with-javax-sound-midi-with-midiunavailableexception-and-illegalargumentex), but none with a clean resolution. My suspicion is that it's some deeper issue between JVM's MIDI engine and WSL but I realize that's not much to go on. If nothing jumps out at you I'll just run it on Windows I guess.

@daveyarwood
Copy link
Member

My suspicion is that it's some deeper issue between JVM's MIDI engine and WSL but I realize that's not much to go on.

This is where I'm at, as well. I wish I understood better what the issue was... I'll leave this issue open in the hope that someone comes along who can be of more help.

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

No branches or pull requests

2 participants