Search in sources :

Example 1 with ProcessRunner

use of blue.utilities.ProcessRunner in project blue by kunstmusik.

the class ExternalScoreEngine method evalCode.

@Override
public String evalCode(String code, Map<String, Object> initValues) throws ScriptException {
    ProcessRunner processRunner = new ProcessRunner();
    File currentWorkingDirectory = null;
    try {
        // output text from soundObject to a temp file for processing by
        // external program
        File temp = FileUtilities.createTempTextFile("blueTempText", ".txt", BlueSystem.getCurrentProjectDirectory(), code);
        StringBuilder buffer = new StringBuilder();
        String commandLine = (String) initValues.get("commandline");
        currentWorkingDirectory = temp.getParentFile();
        // and grab from stdin
        if (!commandLine.contains("$outfile")) {
            commandLine = getPreparedCommandLine(commandLine, temp.getName());
            System.out.println("Calling command: " + commandLine);
            System.out.println("Using directory: " + currentWorkingDirectory.getAbsolutePath());
            processRunner.execWaitAndCollect(commandLine, currentWorkingDirectory);
            buffer.append(processRunner.getCollectedOutput());
        } else {
            File outFile = File.createTempFile("blueTempOutFile", ".sco", BlueSystem.getCurrentProjectDirectory());
            outFile.deleteOnExit();
            commandLine = this.getPreparedCommandLine(commandLine, temp.getName(), outFile.getName());
            System.out.println("Calling command: " + commandLine);
            System.out.println("Using directory: " + currentWorkingDirectory.getAbsolutePath());
            processRunner.execWait(commandLine, currentWorkingDirectory);
            buffer.append(blue.utility.TextUtilities.getTextFromFile(outFile));
        }
        return buffer.toString();
    } catch (Exception ex) {
        throw new ScriptException(ex);
    }
}
Also used : ScriptException(javax.script.ScriptException) ProcessRunner(blue.utilities.ProcessRunner) File(java.io.File) IOException(java.io.IOException) SoundObjectException(blue.soundObject.SoundObjectException) ScriptException(javax.script.ScriptException)

Example 2 with ProcessRunner

use of blue.utilities.ProcessRunner in project blue by kunstmusik.

the class DriverUtilities method getAudioDevicesJackLsp.

protected static List<DeviceInfo> getAudioDevicesJackLsp(boolean isInput) {
    List<DeviceInfo> devices = new ArrayList<>();
    ProcessRunner pc = new ProcessRunner();
    String retVal = null;
    String portType = "audio";
    String subType = isInput ? "output" : "input";
    String prepend = isInput ? "adc:" : "dac:";
    String path = System.getenv("PATH");
    if (!File.pathSeparator.equals(";")) {
        path += File.pathSeparator + "/usr/local/bin";
    }
    String[] paths = path.split(File.pathSeparator);
    String jackLspPath = findExecutableInPath("jack_lsp", paths);
    if (jackLspPath == null || jackLspPath.length() == 0) {
        return null;
    }
    try {
        pc.execWaitAndCollect(jackLspPath + " -t -p", null);
        retVal = pc.getCollectedOutput();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    if (retVal == null || retVal.length() == 0) {
        return null;
    }
    parseJackLspOutput(retVal, portType, subType, prepend, devices);
    return devices;
}
Also used : DeviceInfo(blue.services.render.DeviceInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ProcessRunner(blue.utilities.ProcessRunner)

Aggregations

ProcessRunner (blue.utilities.ProcessRunner)2 IOException (java.io.IOException)2 DeviceInfo (blue.services.render.DeviceInfo)1 SoundObjectException (blue.soundObject.SoundObjectException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ScriptException (javax.script.ScriptException)1