Hi everybody
These past days I've been working on a solution that enable to write plugins in Java, by mapping the SDK
C++ classes to Java classes.
Initially I didn't know if that was possible without being a headache, and the good news is that I have a working prototype!
The prototype is capable of writing tags fully from java and gets playback notifications (play_callback).
classes metadb_handle, file_info_impl and metadb_io are mapped.
The test function that just add a custom tag to selected items looks like this in java
public static void test(Vector<metadb_handle> items) {
for(metadb_handle item : items) {
file_info_impl finfo = new file_info_impl();
item.get_info(finfo);
finfo.meta_set("JAVA", "java");
_metadb_io.update_info(item, finfo, (int)_mainwin_handle, false);
}
}
track changed notification:
public static void on_playback_new_track(metadb_handle item) {
file_info_impl finfo = new file_info_impl();
item.get_info(finfo);
label.setText(finfo.meta_get("ARTIST", 0) + " - " + finfo.meta_get("TITLE", 0));
}
Pros:
- way way easier and less error prone to write complex UIs than old win32 common control APIs. Plus
you have access to all Swing fancy widgets.
- easier to write plugins than in C++ (for thoses who don't master C++)
Cons:
- use more memory
- potentially slower for huge calculations so don't write a DSP with it
How does it work ?
- you still have a minimal C++ DLL plugin whose main task is to redirect actions (menu item action, notification) to a java Plugin class. Menu items are still created in C++ and I'm not sure it'll be possible to create them in Java
- SWIG is used to generate JNI code and DLL + Java proxy classes that contains the JNI bindings to the SDK
I'll expand what I have to see how far I can go but this is promising ! Also with SWIG it should be possible to generate bindings for other languages.