Search in sources :

Example 1 with Csound

use of csnd6.Csound in project blue by kunstmusik.

the class CS6DiskRendererService method execWaitAndCollect.

@Override
public String execWaitAndCollect(String[] args, File currentWorkingDirectory) {
    initialize();
    Csound csound = new Csound();
    blueCallbackWrapper = new BlueCallbackWrapper(csound);
    blueCallbackWrapper.SetMessageCallback();
    StrBuilder buffer = new StrBuilder();
    blueCallbackWrapper.setStringBuffer(buffer);
    CsoundArgVList argsList = new CsoundArgVList();
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("\"") && args[i].endsWith("\"")) {
            args[i] = args[i].substring(1, args[i].length() - 1);
        }
        argsList.Append(args[i]);
    }
    if (currentWorkingDirectory != null) {
        String sfdir = "--env:SFDIR=" + currentWorkingDirectory.getAbsolutePath();
        argsList.Append(sfdir);
    }
    int retVal = csound.Compile(argsList.argc(), argsList.argv());
    if (retVal != 0) {
        blueCallbackWrapper.setStringBuffer(null);
        csound.Stop();
        csound.Cleanup();
        csound.SetMessageCallback(null);
        csound.Reset();
        return buffer.toString();
    }
    while (csound.PerformKsmps() == 0 && keepRunning) {
    // empty
    }
    csound.Stop();
    csound.Cleanup();
    csound.SetMessageCallback(null);
    csound.Reset();
    keepRunning = false;
    blueCallbackWrapper.setStringBuffer(null);
    return buffer.toString();
}
Also used : Csound(csnd6.Csound) StrBuilder(org.apache.commons.lang3.text.StrBuilder) CsoundArgVList(csnd6.CsoundArgVList)

Example 2 with Csound

use of csnd6.Csound in project blue by kunstmusik.

the class CS6DiskRendererService method exec.

private void exec(String[] args, File currentWorkingDirectory, double startTime, TempoMapper mapper, ArrayList<Parameter> parameters) {
    // csnd.csoundInitialize(null, null, csnd.CSOUNDINIT_NO_SIGNAL_HANDLER);
    Csound csound = new Csound();
    blueCallbackWrapper = new BlueCallbackWrapper(csound);
    blueCallbackWrapper.SetMessageCallback();
    final InputOutput ioProvider = IOProvider.getDefault().getIO("Csound", false);
    try {
        // this.io.closeInputOutput();
        ioProvider.getOut().reset();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    IOColors.setColor(ioProvider, IOColors.OutputType.OUTPUT, Color.WHITE);
    blueCallbackWrapper.setInputOutput(ioProvider);
    notifyPlayModeListeners(PlayModeListener.PLAY_MODE_PLAY);
    CsoundArgVList argsList = new CsoundArgVList();
    ioProvider.getOut().append("Render Command (");
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("\"") && args[i].endsWith("\"")) {
            args[i] = args[i].substring(1, args[i].length() - 1);
        }
        argsList.Append(args[i]);
        ioProvider.getOut().append(" ").append(args[i]);
    }
    if (currentWorkingDirectory != null) {
        String sfdir = "--env:SFDIR=" + currentWorkingDirectory.getAbsolutePath();
        argsList.Append(sfdir);
        ioProvider.getOut().append(" ").append(sfdir);
    }
    ioProvider.getOut().append(" )\n");
    int retVal = csound.Compile(argsList.argc(), argsList.argv());
    if (retVal != 0) {
        notifyPlayModeListeners(PlayModeListener.PLAY_MODE_STOP);
        csound.Stop();
        csound.Cleanup();
        csound.SetMessageCallback(null);
        csound.Reset();
        return;
    }
    int updateRate = (int) (csound.GetKr() / PlaybackSettings.getInstance().getPlaybackFPS());
    int counter = 0;
    RenderTimeManager manager = Lookup.getDefault().lookup(RenderTimeManager.class);
    manager.initiateRender(startTime);
    Parameter param;
    do {
        counter++;
        double scoreTime = (double) csound.GetScoreTime();
        if (counter > updateRate) {
            manager.updateTimePointer(scoreTime);
            counter = 0;
        }
        double currentTime = 0.0f;
        if (startTime >= 0.0f) {
            if (mapper != null) {
                double renderStartSeconds = mapper.beatsToSeconds(startTime);
                currentTime = mapper.secondsToBeats(scoreTime + renderStartSeconds);
                currentTime -= startTime;
            } else {
                currentTime = startTime + scoreTime;
            }
        }
        if (parameters != null) {
            for (int i = 0; i < parameters.size(); i++) {
                param = parameters.get(i);
                String varName = param.getCompilationVarName();
                double value = param.getValue(currentTime);
                csound.SetChannel(varName, (double) value);
            }
        }
    } while (csound.PerformKsmps() == 0 && keepRunning);
    csound.Stop();
    csound.Cleanup();
    csound.SetMessageCallback(null);
    csound.Reset();
    manager.endRender();
    keepRunning = false;
    notifyPlayModeListeners(PlayModeListener.PLAY_MODE_STOP);
}
Also used : Csound(csnd6.Csound) InputOutput(org.openide.windows.InputOutput) RenderTimeManager(blue.services.render.RenderTimeManager) Parameter(blue.automation.Parameter) IOException(java.io.IOException) CsoundArgVList(csnd6.CsoundArgVList)

Example 3 with Csound

use of csnd6.Csound in project blue by kunstmusik.

the class CS6DiskRendererService method renderToDisk.

@Override
@SuppressWarnings("empty-statement")
public void renderToDisk(DiskRenderJob job) {
    String csdPath = generateCsd(job.getData());
    if (csdPath == null) {
        return;
    }
    initialize();
    Csound csound = new Csound();
    blueCallbackWrapper = new BlueCallbackWrapper(csound);
    blueCallbackWrapper.SetMessageCallback();
    final InputOutput ioProvider = IOProvider.getDefault().getIO("Csound (Disk)", false);
    try {
        ioProvider.getOut().reset();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    IOColors.setColor(ioProvider, IOColors.OutputType.OUTPUT, Color.WHITE);
    blueCallbackWrapper.setInputOutput(ioProvider);
    notifyPlayModeListeners(PlayModeListener.PLAY_MODE_PLAY);
    CsoundArgVList argsList = new CsoundArgVList();
    ioProvider.getOut().append("Render Command (");
    String[] args = job.getArgs();
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("\"") && args[i].endsWith("\"")) {
            args[i] = args[i].substring(1, args[i].length() - 1);
        }
        argsList.Append(args[i]);
        ioProvider.getOut().append(" ").append(args[i]);
    }
    if (job.getCurrentWorkingDirectory() != null) {
        String sfdir = "--env:SFDIR=" + job.getCurrentWorkingDirectory().getAbsolutePath();
        argsList.Append(sfdir);
        ioProvider.getOut().append(" ").append(sfdir);
    }
    argsList.Append(csdPath);
    ioProvider.getOut().append(" " + csdPath + " )\n");
    int retVal = csound.Compile(argsList.argc(), argsList.argv());
    if (retVal != 0) {
        notifyPlayModeListeners(PlayModeListener.PLAY_MODE_STOP);
        csound.Stop();
        csound.Cleanup();
        csound.SetMessageCallback(null);
        csound.Reset();
        return;
    }
    while (csound.PerformKsmps() == 0 && keepRunning) {
    }
    ;
    csound.Stop();
    csound.Cleanup();
    csound.SetMessageCallback(null);
    csound.Reset();
    keepRunning = false;
    notifyPlayModeListeners(PlayModeListener.PLAY_MODE_STOP);
}
Also used : Csound(csnd6.Csound) InputOutput(org.openide.windows.InputOutput) IOException(java.io.IOException) CsoundArgVList(csnd6.CsoundArgVList)

Example 4 with Csound

use of csnd6.Csound in project blue by kunstmusik.

the class CS6RealtimeRenderService method play.

public void play(BlueData blueData, CsdRenderResult result, String[] args, File currentWorkingDirectory, double renderStart) {
    if (runnerThread != null) {
        runnerThread.setKeepRunning(false);
        runnerThread.await();
    }
    this.csound = new Csound();
    blueCallbackWrapper = new BlueCallbackWrapper(csound);
    blueCallbackWrapper.SetMessageCallback();
    if (this.io != null) {
        try {
            this.io.getOut().reset();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    io = IOProvider.getDefault().getIO("Csound", false);
    IOColors.setColor(io, IOColors.OutputType.OUTPUT, Color.WHITE);
    blueCallbackWrapper.setInputOutput(io);
    CsoundArgVList argsList = new CsoundArgVList();
    io.getOut().append("Render Command (");
    for (int i = 0; i < args.length; i++) {
        argsList.Append(args[i]);
        io.getOut().append(" ").append(args[i]);
    }
    if (currentWorkingDirectory != null) {
        String sfdir = "--env:SFDIR=" + currentWorkingDirectory.getAbsolutePath();
        argsList.Append(sfdir);
        io.getOut().append(" ").append(sfdir);
    }
    io.getOut().append(" )\n");
    int retVal = csound.Compile(argsList.argc(), argsList.argv());
    if (retVal != 0) {
        if (GeneralSettings.getInstance().isCsoundErrorWarningEnabled()) {
            if (errorPanel == null) {
                errorPanel = new JPanel(new BorderLayout());
                errorPanel.add(new JLabel("<html>There was an error in " + "running Csound.<br>" + "Please view the Csound Output Dialog for " + "more information.<br><br></html>"), BorderLayout.CENTER);
                disableMessagesBox = new JCheckBox("Disable Error Message Dialog");
                errorPanel.add(disableMessagesBox, BorderLayout.SOUTH);
            }
            disableMessagesBox.setSelected(false);
            SwingUtilities.invokeLater(() -> {
                JOptionPane.showMessageDialog(null, errorPanel, "Csound Error", JOptionPane.ERROR_MESSAGE);
                if (disableMessagesBox.isSelected()) {
                    GeneralSettings.getInstance().setCsoundErrorWarningEnabled(false);
                    GeneralSettings.getInstance().save();
                }
            });
        }
        notifyPlayModeListeners(PlayModeListener.PLAY_MODE_STOP);
        csound.Stop();
        csound.Cleanup();
        csound.SetMessageCallback(null);
        csound.Reset();
        csound = null;
        blueCallbackWrapper = null;
        return;
    }
    runnerThread = new APIRunnerThread(blueData, csound, this, result.getParameters(), result.getStringChannels(), result.getTempoMapper(), renderStart, bindings);
    notifyPlayModeListeners(PlayModeListener.PLAY_MODE_PLAY);
    Thread t = new Thread(runnerThread);
    t.setPriority(Thread.MAX_PRIORITY);
    t.start();
}
Also used : JCheckBox(javax.swing.JCheckBox) Csound(csnd6.Csound) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JLabel(javax.swing.JLabel) IOException(java.io.IOException) CsoundArgVList(csnd6.CsoundArgVList)

Aggregations

Csound (csnd6.Csound)4 CsoundArgVList (csnd6.CsoundArgVList)4 IOException (java.io.IOException)3 InputOutput (org.openide.windows.InputOutput)2 Parameter (blue.automation.Parameter)1 RenderTimeManager (blue.services.render.RenderTimeManager)1 BorderLayout (java.awt.BorderLayout)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 StrBuilder (org.apache.commons.lang3.text.StrBuilder)1