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

Cross platform MIDI Ports Access, FM Synthesis, and Sound from the Java Standard Library #468

Closed
maximilien-noal opened this issue Jan 13, 2024 · 5 comments

Comments

@maximilien-noal
Copy link

maximilien-noal commented Jan 13, 2024

Hello,

It is my understanding that Java has built-in and cross-platform:

  • MIDI Ports control,
  • Audio Playback (I use PortAudio P/Invoke for that, but I have no mixer, like the SDL Mixer. Wasn't easy to setup!),
  • Audio Capture,
  • MIDI FM Synthesis, (I use either WinMM on Windows, or Meltysynth on other platforms with a 3rd party SF2 Soundfont. I love it, but I didn't find Meltysynth for a long while.)
  • Audio mixing and rendering
  • and more than I may be unaware of.

I'd love to have all that in the .NET BCL.

There's nothing cross platform (Windows/Mac/Linux desktop, at least) and unified in one package for any of that either in the .NET BCL or on Nuget.

Managed-midi has been abandoned.

So I'd love to have all that in IKVM.

What are the main hurdles for each ?

Thank you for this very important project!

@wasabii
Copy link
Contributor

wasabii commented Jan 13, 2024

So, the code in IKVM for the Java BCL is predominately sourced from the OpenJDK project. This code is checked out into a submodule named openjdk/.

The IKVM .NET build uses the IKVM.Net.SDK project type in the IKVM.Java project to compile this code, alone with a mix of other hand-written .java files together. It then converts it to a .NET DLL. Predominately our Java BCL is just OpenJDK code transpiled. However, a couple dozen class files from OpenJDK are removed, and replaced with custom implementations of our own. This was the traditional way IKVM was designed: Source as much OpenJDK code as possible. OpenJDK platform integration code (IO, etc) tends to be native libraries written in C which are then called out to using JNI. This was traditionally the way IKVM has been built: hand rewriting the C JNI code in C#.

However, in the last few releases, we've introduced an alternate path, which we now prefer: compile the OpenJDK C code using Clang and call that using JNI from IKVM. You'll notice a dozen projects in the IKVM solution now, mirroring what is output in a traditional OpenJDK distribution: libjvm, libjava, libverify, libnio, etc. These are built using our new .clangproj project type, incorporating the OpenJDK C code.

We're far along the path to replacing much of the custom written C# with this new approach. Though there will always be bits that need some custom C#.

That said, MIDI is most certainly predominately C code in OpenJDK. And chances are it'll run mostly unaltered on IKVM.

The one remaining problem is OpenJDK tends to sometimes have different .java implementations for different platforms, in additional to custom JNI code. So, for instance, java.lang.ProcessImpl has a Unix and Windows flavor. But, since we only distribute one cross platform IKVM.Java.dll at this time, we need an implementation of java.lang.ProcessImpl that works on both: so we still hand build that one.

So: if MIDI in OpenJDK uses the same .java files for each platform, we're golden. All that needs to be done is include them into IKVM.Java, and add a Clang project for the appropriate native libraries.

If not, though, it might require some hand tuning.

@wasabii
Copy link
Contributor

wasabii commented Feb 3, 2024

In progress on PR #483 on branch jsound.

@wasabii
Copy link
Contributor

wasabii commented Feb 3, 2024

The PR has support for Linux and Windows. However, it appears that we can't yet compile the C code for OS X because of a missing include of stdlib.h, which ends up getting added in JDK8u300+. So, short of a workaround I can't quite find, I'm going to leave OS X disabled until we bring the JDK further up to date.

@maximilien-noal
Copy link
Author

In progress on PR #483 on branch jsound.

Very interesting ! I'd love to see it on the main branch. :)

@wasabii
Copy link
Contributor

wasabii commented Apr 16, 2024

Techincally closed in 8.8. Though OS X support is missing and can be a new issue.

@wasabii wasabii closed this as completed Apr 16, 2024
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

No branches or pull requests

2 participants