Page 1 of 1

Help including a Csound API library in java

Posted: Thu Apr 21, 2022 2:08 pm
by boonier
Hi,

I'm trying out the module designer with hopefully a simple idea (granted not THE simplest of ideas!). I'm a developer but Java is not a language I have much familiarity with, I've dabbled with it would be an accurate summary of my experience.

I want to incorporate the Csound API with Java wrappers (https://github.com/csound/csoundAPI_exa ... aster/java) into the module code, but seem to be falling at the first hurdle. I've added the csnd6.jar lib file in the module properties > additional JAR files, imported at the top of the module code. To test something comes to life I add to the Initialize() method,

Code: Select all

@Override
public void Initialize()
   {
      // add your own code here
      csnd6.csoundInitialize(csnd6.CSOUNDINIT_NO_ATEXIT | csnd6.CSOUNDINIT_NO_SIGNAL_HANDLER);
      
      // Create an instance of the Csound object
      Csound c = new Csound();
}
but on running debug, the console prints "Jar file creation succeeded", but the test window appears briefly then terminates.

I've probably made too many naive assumptions that it would be this simple. Any tips as to what might be happening?

I'm on macOS Monterey, M1 silicon. One thought I had was that Csound is running in rosetta 2, which might be an issue.

any help much appreciated

thanks :)

Re: Help including a Csound API library in java

Posted: Fri Apr 22, 2022 5:33 pm
by seal58
Hi,
I found that some things of a module cannot be accessed within Initialize() yet. Sometimes then I've got error messages like "null pointer error".

That's the way I went:
- I created a

Code: Select all

private void Init()
{
...
}
to initialize all variables and arrays.
- In my own variables there is

Code: Select all

boolean init = true;
- At the beginning of ProcessSample():

Code: Select all

if init {
  Init();
  init = false;
}

Re: Help including a Csound API library in java

Posted: Mon Apr 25, 2022 8:33 am
by boonier
Thanks @seal58 your approach does indeed seem to work, in that, the debug window opens now, but I think there is something up with the Csound api side of things - the paths or linkage stuff. Not sure. Will keep investigating!

Re: Help including a Csound API library in java

Posted: Mon Apr 25, 2022 6:49 pm
by seal58
By the way, I just found that dubugger's test window sometimes also stays empty, when an error occured during module initalization. When starting debugger with F5, you will see the reason in the output pane, but when starting with Strg-F5 you will not.

Re: Help including a Csound API library in java

Posted: Wed Nov 22, 2023 10:50 am
by JaneVanceek
Surround the code inside your Initialize method with a try-catch block to catch any exceptions and print out the stack trace. This will give you more information about what's causing the issue.

@Override
public void Initialize() {
try {
// add your own code here
csnd6.csoundInitialize(csnd6.CSOUNDINIT_NO_ATEXIT | csnd6.CSOUNDINIT_NO_SIGNAL_HANDLER);

// Create an instance of the Csound object
Csound c = new Csound();
} catch (Exception e) {
e.printStackTrace();
// Handle the exception, log details, or take appropriate action
}
}

Ensure that all required dependencies for the Csound API are available and properly configured, especially if you are considering B2B API integration. This includes not just the csnd6.jar file but also any native libraries or dependencies that the Csound API relies on.

Given your mention that Csound might be running in Rosetta 2, it's crucial to consider potential compatibility issues, particularly if there are specific dependencies that may not be fully supported in the Rosetta 2 environment on M1. Investigate whether there are any updated instructions or patches for running Csound on M1.

Addressing these considerations will help ensure a smoother B2B API integration process, minimizing potential disruptions and enhancing the overall reliability of your application on the M1 architecture.

Re: Help including a Csound API library in java

Posted: Wed Nov 22, 2023 12:39 pm
by ColinP
I don't have detailed knowledge of Csound but here are some thoughts...

Integrating Csound with VM is perhaps not a great first project if you are fairly new to both Java and VM even if you are a very experienced developer.

I'd recommend attacking such an ambitious project in three phases.

1) Getting Csound working in a vanilla Java environment so that you can explore the issues of using it in Java without having to worry about the quirks of Voltage Modular.
2) Using VM Designer to develop a couple of simple modules to learn more about the VM environment. Perhaps focusing on the user interface and connectivity you want your Csound engine to present to the world.
3) Then combine the knowledge gained from 1) and 2) and attempt to iron out any issues specific to running Csound in VM.

You might be lucky and it all goes smoothly but in my experience getting anything fiddly to work in VM is hard work even when you aren't using third-party code. There are several pitfalls such as threading issues and the fact that modules are not isolated programs (so for instance static variables can trip things up when multiple instances of a module are run).

I don't mean to put you off. It's an interesting idea and I wish you every success.

------

Edited to add: I've just noticed the OP was from April 2022 so this project has probably been abandoned.