Skip to content

Commit

Permalink
feat: update to use Csound FFM and require Java 22
Browse files Browse the repository at this point in the history
  • Loading branch information
kunstmusik committed Jul 31, 2024
1 parent 09ccf51 commit 9e1ad22
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 43 deletions.
8 changes: 4 additions & 4 deletions application/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

<property environment="env"/>

<property name="jdk.src.root" value="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.7%2B7/"/>
<property name="jdk.src.root" value="https://github.com/adoptium/temurin22-binaries/releases/download/jdk-22.0.2%2B9/"/>

<property name="jdk.windows"
value="OpenJDK17U-jdk_x64_windows_hotspot_17.0.7_7.zip"/>
value="OpenJDK22U-jdk_x64_windows_hotspot_22.0.2_9.zip"/>

<property name="jdk.mac.arm64"
value="OpenJDK17U-jdk_aarch64_mac_hotspot_17.0.7_7.tar.gz"/>
value="OpenJDK22U-jdk_aarch64_mac_hotspot_2.0.2_9.tar.gz"/>

<property name="jdk.mac.x86_64"
value="OpenJDK17U-jdk_x64_mac_hotspot_17.0.7_7.tar.gz"/>
value="OpenJDK22U-jdk_x64_mac_hotspot_22.0.2_9.tar.gz"/>

<condition property="isMac">
<os family="mac" />
Expand Down
11 changes: 9 additions & 2 deletions blue-csnd6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@
</dependency>
<dependency>
<groupId>com.kunstmusik</groupId>
<artifactId>CsoundJNI</artifactId>
<version>1.0.6</version>
<artifactId>csoundffm</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub kunstmusik Apache Maven Packages</name>
<url>https://maven.pkg.github.com/kunstmusik/CsoundFFM</url>
</repository>
</distributionManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down
7 changes: 4 additions & 3 deletions blue-csnd6/src/main/java/blue/csnd6/render/API6Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package blue.csnd6.render;

import com.kunstmusik.csoundjni.CsoundJNI;
import com.kunstmusik.csoundffm.Csound;

/**
*
Expand All @@ -24,8 +24,9 @@ public static boolean isCsoundAPIAvailable() {
apiAvailable = false;
} else {
try {
CsoundJNI.csoundInitialize(CsoundJNI.CSOUNDINIT_NO_ATEXIT |
CsoundJNI.CSOUNDINIT_NO_SIGNAL_HANDLER);
System.out.println("Csound Version Found: " + Csound.getVersion());
// CsoundJNI.csoundInitialize(CsoundJNI.CSOUNDINIT_NO_ATEXIT |
// CsoundJNI.CSOUNDINIT_NO_SIGNAL_HANDLER);
// System.loadLibrary("_jcsound6");
// csnd6.csoundInitialize(csnd6.CSOUNDINIT_NO_ATEXIT |
// csnd6.CSOUNDINIT_NO_SIGNAL_HANDLER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package blue.csnd6.render;

import com.kunstmusik.csoundjni.MessageCallback;
import com.kunstmusik.csoundffm.MessageCallback;
import java.io.IOException;
import java.lang.foreign.MemorySegment;

import org.openide.util.Exceptions;
import org.openide.windows.InputOutput;
Expand Down Expand Up @@ -30,14 +31,17 @@ public void setStringBuffer(StringBuilder buffer) {
}

@Override
public void callback(int attr, String msg) {
public void callback(MemorySegment csound, int attr, MemorySegment msg) {

String msgText = msg.reinterpret(Integer.MAX_VALUE).getString(0);

if (buffer != null) {
buffer.append(msg);
buffer.append(msgText);
} else if (io == null) {
System.out.print(msg);
System.out.print(msgText);
System.out.flush();
} else {
io.getOut().append(msg);
io.getOut().append(msgText);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,8 @@

import blue.automation.Parameter;
import blue.event.PlayModeListener;
import blue.score.ScoreGenerationException;
import blue.services.render.CSDRenderService;
import blue.services.render.CsdRenderResult;
import blue.services.render.DiskRenderJob;
import blue.services.render.DiskRenderService;
import blue.services.render.RenderTimeManager;
import blue.settings.PlaybackSettings;
import blue.time.TempoMap;
import blue.utility.FileUtilities;
import com.kunstmusik.csoundjni.Csound;

import java.awt.Color;
import java.io.IOException;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.windows.IOColors;
import org.openide.windows.IOProvider;
import org.openide.windows.InputOutput;
import blue.score.ScoreGenerationException;
import blue.services.render.CSDRenderService;
import blue.services.render.CsdRenderResult;
Expand All @@ -35,7 +19,7 @@
import blue.services.render.RenderTimeManager;
import blue.settings.PlaybackSettings;
import blue.utility.FileUtilities;
import com.kunstmusik.csoundjni.Csound;
import com.kunstmusik.csoundffm.Csound;
import java.awt.Color;
import java.io.IOException;
import org.openide.util.Exceptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import blue.services.render.CsdRenderResult;
import blue.BlueData;
//import blue.BlueMainFrame;
import blue.BlueSystem;
import blue.LiveData;
import blue.automation.Parameter;
Expand All @@ -23,12 +22,14 @@
import blue.time.TempoMap;
import blue.utility.FileUtilities;
import blue.utility.TextUtilities;
import com.kunstmusik.csoundjni.Csound;
import com.kunstmusik.csoundffm.Csound;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.nio.DoubleBuffer;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import static java.lang.foreign.ValueLayout.JAVA_DOUBLE;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
Expand Down Expand Up @@ -66,8 +67,6 @@ public class CS6RealtimeRenderService implements RealtimeRenderService, PlayMode
private Csound csound;

public CS6RealtimeRenderService() {
// csnd6.csoundInitialize(csnd6.CSOUNDINIT_NO_ATEXIT
// | csnd6.CSOUNDINIT_NO_SIGNAL_HANDLER);
}

@Override
Expand Down Expand Up @@ -156,7 +155,6 @@ public void play(BlueData blueData, CsdRenderResult result,
csound.stop();
csound.cleanup();
csound.setMessageCallback(null);
csound.delete();
csound = null;
blueCallbackWrapper = null;
return;
Expand Down Expand Up @@ -403,7 +401,7 @@ static class APIRunnerThread implements Runnable {
private double startTime;
private BlueData blueData;
private double[] valuesCache;
private DoubleBuffer[] channelPtrCache;
private MemorySegment[] channelPtrCache;
public boolean isRunning = true;
CountDownLatch latch = new CountDownLatch(1);
private final List<CsoundBinding> bindings;
Expand Down Expand Up @@ -547,7 +545,7 @@ public void run() {

if (value != valuesCache[i]) {
valuesCache[i] = value;
channelPtrCache[i].put(0, value);
channelPtrCache[i].set(ValueLayout.JAVA_DOUBLE, 0, value);
}
}

Expand Down Expand Up @@ -581,7 +579,6 @@ public void run() {
csound.stop();
csound.cleanup();
csound.setMessageCallback(null);
csound.delete();

if (renderUpdatesTime) {
manager.endRender();
Expand All @@ -598,7 +595,7 @@ private void createValuesCache(double currentTime) {
final int size = parameters.size();

valuesCache = new double[size];
channelPtrCache = new DoubleBuffer[size];
channelPtrCache = new MemorySegment[size];

for (int i = 0; i < size; i++) {
param = (Parameter) parameters.get(i);
Expand All @@ -612,7 +609,7 @@ private void createValuesCache(double currentTime) {
}

channelPtrCache[i] = csound.getControlChannelPtr(varName);
channelPtrCache[i].put(0, valuesCache[i]);
channelPtrCache[i].set(JAVA_DOUBLE, 0, valuesCache[i]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<plugin>
<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<version>4.8</version>
<version>14.1</version>
<extensions>true</extensions>
<configuration>
<brandingToken>${brandingToken}</brandingToken>
Expand Down

0 comments on commit 9e1ad22

Please sign in to comment.