ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.15k stars 109 forks source link

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

Closed maximilien-noal closed 2 months ago

maximilien-noal commented 5 months ago

Hello,

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

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 commented 5 months ago

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 commented 5 months ago

In progress on PR #483 on branch jsound.

wasabii commented 5 months ago

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 commented 5 months ago

In progress on PR #483 on branch jsound.

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

wasabii commented 2 months ago

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