Procedure for writing our own API for HiseScript?
-
I am curious what the procedure is for writing/incorporating our own Scripting API that may not already exist.
This might be a question specifically for Chirstoph, though perhaps @d-healey or some others here have experience with this.
In my particular use case I am interested in the addition of a Markov API, specifically this one (though betters may exist):
https://github.com/yeeking/MarkovModelCPP/tree/mainHowever, thinking about this did make me wonder what the procedure was and the level of difficulty it takes. I've never really dived to deep into the scripting api section of the HISE source code.
This is my general guess from looking into the source code:
-
Create flag for it in
hi_core/hi_core/HiseSettings.h
DECLARE_ID(EnableMarkov);
As well as adding some documentation. -
Add the
MarkovModelCPP
source to the tools folder -
Create two new files in
hi_scripting/scripting/api/
:
-
ScriptMarkovModel.h
-
ScriptMarkovModel.cpp
-
Create a wrapper class that inherits from
ConstScriptingObject
to bridge the CPP library with JavaScript. This part has me quite confused still I have to learn more about how this works, but it seems to crop up in each class that isn't natively part of JUCE. -
Register the class with the JavaScript Engine (no idea on how this is done).
I imagine there are probably some flags I need to add elsewhere to enable building with this new library as well. This is about as far as I made it though I could be delusional and completley overlooked some critical steps/details!
Sidenote:
My reasons for adding this library may not be the most justified. I am making a MIDI browser for finding MIDI files with certain similarities. This is probably better done offline in Python mind you and I can just generate a fat JSON file I could bring into HISE for this. A second option is just using the Math API that already exists. Still curious however. -
-
@HISEnberg You've probably seen this already, but - https://docs.hise.dev/cpp_api/index.html#create-your-own-classes
-
@d-healey yes thank you
-
you might get 90% there by copy & pasting any scripting object. There are a few virtual methods that you need to overwrite but hooking methods up is usually done through the internal
Wrapper
subclass and theAPI_VOID_METHOD_WRAPPER_X()
preprocessor.Register the class with the JavaScript Engine (no idea on how this is done).
Usually this is done by adding a method to the Engine / Synth class which creates and returns an object, just look at the myriad of existing methods like this one.
If you want to conditionally include the class without too much intrusion into the HISE codebase, take a look at how the BeatportManager / the NKS manager are integrated.
-
@Christoph-Hart I remember a while back you added some new class along with a bunch of comments to make it a kind of demo of how to implement a new class. But I can't remember which one it was, any idea?
-
@Christoph-Hart Thank you for the nudge I was trying to find a good example to build from and this is giving me a better sense of the folder/file hierarchy relationship. I am still in the poke around the codebase and find out phase so will report back once I understand more.
Happy to make a pull request to add it to the official version of HISE as well if I get it working, but I know this is a pretty niche case so unless there is a demand for it I won't bother!