Search in sources :

Example 6 with CsdRenderResult

use of blue.services.render.CsdRenderResult in project blue by kunstmusik.

the class CSDRender method generateCSDForBlueLiveImpl.

@Override
protected synchronized CsdRenderResult generateCSDForBlueLiveImpl(BlueData data, boolean usingAPI) {
    ProjectPluginManager.getInstance().preRender(data);
    StringChannelNameManager scnm = new StringChannelNameManager();
    ArrayList<StringChannel> stringChannels = getStringChannels(data.getArrangement(), scnm);
    ParameterHelper.clearCompilationVarNames(data);
    double totalDur = 36000f;
    // making copies to use for adding compileTime tables and instruments
    Tables tables = new Tables(data.getTableSet());
    ArrayList<Parameter> originalParameters = null;
    if (usingAPI) {
        originalParameters = ParameterHelper.getAllParameters(data.getArrangement(), data.getMixer());
        assignParameterNames(originalParameters, new ParameterNameManager());
    }
    Arrangement arrangement = new Arrangement(data.getArrangement());
    arrangement.clearUnusedInstrAssignments();
    String[] instrIds = arrangement.getInstrumentIds();
    // PolyObject tempPObj = (PolyObject) data.getPolyObject().clone();
    boolean hasInstruments = arrangement.size() > 0;
    GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
    OpcodeList udos = new OpcodeList(data.getOpcodeList());
    // add all UDO's from instruments and effects
    arrangement.generateUserDefinedOpcodes(udos);
    appendFtgenTableNumbers(globalOrcSco.getGlobalOrc(), tables);
    arrangement.generateFTables(tables);
    CompileData compileData = new CompileData(arrangement, tables);
    // SKIPPING ANYTHING RELATED TO SCORE
    boolean mixerEnabled = data.getMixer().isEnabled();
    Mixer mixer = null;
    if (mixerEnabled) {
        mixer = new Mixer(data.getMixer());
        assignChannelIds(compileData, mixer);
    }
    boolean generateMixer = mixerEnabled && (hasInstruments || mixer.hasSubChannelDependencies());
    int nchnls = getNchnls(data, true);
    ArrayList<Instrument> alwaysOnInstruments = new ArrayList<>();
    arrangement.preGenerateOrchestra(compileData, mixer, nchnls, alwaysOnInstruments);
    String globalSco = globalOrcSco.getGlobalSco() + "\n";
    globalSco += arrangement.generateGlobalSco(compileData) + "\n";
    globalSco = preprocessSco(globalSco, totalDur, 0, 0, null);
    NoteList generatedNotes = null;
    for (Instrument instrument : alwaysOnInstruments) {
        String sourceId = compileData.getInstrSourceId(instrument);
        if (StringUtils.isNumeric(sourceId)) {
            int instrId = arrangement.addInstrumentAtEnd(instrument);
            globalSco += "i" + instrId + " 0 " + totalDur + "\n";
        } else {
            String instrId = sourceId + "_alwaysOn";
            arrangement.addInstrumentWithId(instrument, instrId, false);
            globalSco += "i \"" + instrId + "\" 0 " + totalDur + "\n";
        }
    }
    if (usingAPI) {
        // ArrayList parameters = ParameterHelper.getAllParameters(
        // arrangement, mixer);
        generatedNotes = new NoteList();
        handleParametersForBlueLive(originalParameters, stringChannels, globalOrcSco, generatedNotes, arrangement, usingAPI);
    }
    if (generateMixer) {
        final String mixerId = "BlueMixer";
        clearUnusedMixerChannels(mixer, arrangement);
        globalOrcSco.appendGlobalOrc(mixer.getInitStatements(compileData, nchnls));
        arrangement.addInstrumentWithId(mixer.getMixerInstrument(compileData, udos, nchnls), mixerId, false);
        globalSco += "i \"BlueMixer\" 0 " + totalDur;
    }
    arrangement.addInstrument("blueAllNotesOff", createAllNotesOffInstrument(instrIds));
    String ftables = tables.getTables();
    StrBuilder score = new StrBuilder();
    score.append("<CsoundSynthesizer>\n\n");
    appendCsInstruments(compileData, data, udos, arrangement, globalOrcSco, score, mixer, true);
    appendCsScore(globalSco, ftables, generatedNotes, totalDur, score);
    score.append("</CsoundSynthesizer>");
    // Tempo tempo = data.getScore().getTempo();
    TempoMapper tempoMapper = null;
    // if (tempo.isEnabled()) {
    // tempoMapper = CSDRender.getTempoMapper(tempo);
    // } else {
    // tempoMapper = CSDRender.getTempoMapper(globalSco);
    // }
    CsdRenderResult renderResult = new CsdRenderResult(score.toString(), tempoMapper, originalParameters, stringChannels);
    return renderResult;
}
Also used : GlobalOrcSco(blue.GlobalOrcSco) NoteList(blue.soundObject.NoteList) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Mixer(blue.mixer.Mixer) ArrayList(java.util.ArrayList) Arrangement(blue.Arrangement) LinePoint(blue.components.lines.LinePoint) TempoMapper(blue.noteProcessor.TempoMapper) ParameterNameManager(blue.automation.ParameterNameManager) OpcodeList(blue.udo.OpcodeList) StringChannelNameManager(blue.orchestra.blueSynthBuilder.StringChannelNameManager) Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) Tables(blue.Tables) Parameter(blue.automation.Parameter) CompileData(blue.CompileData) StrBuilder(org.apache.commons.lang3.text.StrBuilder) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 7 with CsdRenderResult

use of blue.services.render.CsdRenderResult in project blue by kunstmusik.

the class CommandlineRunner method renderForBlueLive.

@Override
public void renderForBlueLive() throws SoundObjectException {
    CsdRenderResult result = CSDRenderService.getDefault().generateCSDForBlueLive(this.data, false);
    String tempCSD = result.getCsdText();
    File temp = FileUtilities.createTempTextFile("tempCsd", ".csd", BlueSystem.getCurrentProjectDirectory(), tempCSD);
    String osName = System.getProperty("os.name");
    String command;
    LiveData liveData = data.getLiveData();
    if (liveData.isCommandLineEnabled()) {
        if (liveData.isCommandLineOverride()) {
            command = liveData.getCommandLine();
        } else {
            command = ProjectPropertiesUtil.getRealtimeCommandLine(data.getProjectProperties());
            command += " -Lstdin ";
            command += liveData.getCommandLine();
        }
    } else {
        command = ProjectPropertiesUtil.getRealtimeCommandLine(data.getProjectProperties());
        command += " -Lstdin ";
    }
    command += " --omacro:BLUE_LIVE=1 --smacro:BLUE_LIVE=1 ";
    if (osName.contains("Windows")) {
        command += " \"" + temp.getAbsolutePath() + "\"";
    } else {
        command += " " + temp.getAbsolutePath();
    }
    play(command, BlueSystem.getCurrentProjectDirectory(), -1);
}
Also used : LiveData(blue.LiveData) File(java.io.File) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 8 with CsdRenderResult

use of blue.services.render.CsdRenderResult in project blue by kunstmusik.

the class CommandlineRunner method render.

@Override
public void render() throws SoundObjectException {
    if (this.data == null) {
        return;
    }
    shouldStop = false;
    String command;
    try {
        // String osName = System.getProperty("os.name");
        command = ProjectPropertiesUtil.getRealtimeCommandLine(data.getProjectProperties());
        // if (command.trim().length() == 0) {
        // command = ProgramOptions.getDefaultCommandline();
        // JOptionPane.showMessageDialog(null, BlueSystem
        // .getString("message.noCommandLineSet")
        // + " " + command);
        // 
        // }
        String globalSco = data.getGlobalOrcSco().getGlobalSco();
        globalSco = TextUtilities.stripMultiLineComments(globalSco);
        globalSco = TextUtilities.stripSingleLineComments(globalSco);
        // System.out.println(tempoMapper);
        // FIXME
        // timeManager.setRootPolyObject(data.getPolyObject());
        double startTime = data.getRenderStartTime();
        double endTime = data.getRenderEndTime();
        CsdRenderResult result = CSDRenderService.getDefault().generateCSD(data, startTime, endTime, true, false);
        RenderTimeManager timeManager = Lookup.getDefault().lookup(RenderTimeManager.class);
        timeManager.setTempoMapper(result.getTempoMapper());
        String csd = result.getCsdText();
        File temp = FileUtilities.createTempTextFile("tempCsd", ".csd", BlueSystem.getCurrentProjectDirectory(), csd);
        // if (osName.indexOf("Windows") >= 0) {
        command += " \"" + temp.getAbsolutePath() + "\"";
        // } else {
        // command += " " + temp.getAbsolutePath().replaceAll(" ", "\\\\ ");
        // }
        play(command, BlueSystem.getCurrentProjectDirectory(), data.getRenderStartTime());
    } catch (SoundObjectException soe) {
        throw soe;
    } catch (ScoreGenerationException ex) {
        NotificationDisplayer.getDefault().notify("Error", NotificationDisplayer.Priority.HIGH.getIcon(), BlueSystem.getString("message.generateScore.error") + "\n" + ex.getLocalizedMessage(), null);
        System.err.println("[" + BlueSystem.getString("message.error") + "] " + ex.getLocalizedMessage());
    }
}
Also used : ScoreGenerationException(blue.score.ScoreGenerationException) RenderTimeManager(blue.services.render.RenderTimeManager) SoundObjectException(blue.soundObject.SoundObjectException) File(java.io.File) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 9 with CsdRenderResult

use of blue.services.render.CsdRenderResult in project blue by kunstmusik.

the class ProcessConsole method renderToDisk.

@Override
public void renderToDisk(DiskRenderJob job) {
    if (this.io != null) {
        try {
            this.io.getOut().reset();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    try {
        io = IOProvider.getDefault().getIO("Csound (Disk)", false);
        IOColors.setColor(io, IOColors.OutputType.OUTPUT, Color.WHITE);
        io.select();
        String commandLine = StringUtils.join(job.getArgs(), " ");
        BlueData data = job.getData();
        double startTime = data.getRenderStartTime();
        double endTime = data.getRenderEndTime();
        if (data.getProjectProperties().diskAlwaysRenderEntireProject) {
            startTime = 0.0f;
            endTime = -1.0f;
        }
        CsdRenderResult result = CSDRenderService.getDefault().generateCSD(data, startTime, endTime, false, false);
        String csd = result.getCsdText();
        File temp = FileUtilities.createTempTextFile("tempCsd", ".csd", BlueSystem.getCurrentProjectDirectory(), csd);
        commandLine += " \"" + temp.getAbsolutePath() + "\"";
        commandLine += " -L stdin";
        execDisk(commandLine, job.getCurrentWorkingDirectory());
        process.waitFor();
        destroy(true, true);
    } catch (ScoreGenerationException | IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : BlueData(blue.BlueData) ScoreGenerationException(blue.score.ScoreGenerationException) IOException(java.io.IOException) File(java.io.File) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 10 with CsdRenderResult

use of blue.services.render.CsdRenderResult in project blue by kunstmusik.

the class CS6DiskRendererService method generateCsd.

/**
 * @param data
 * @return the absolute path of the temp CSD file on disk
 */
protected String generateCsd(BlueData data) {
    double startTime = data.getRenderStartTime();
    double endTime = data.getRenderEndTime();
    if (data.getProjectProperties().diskAlwaysRenderEntireProject) {
        startTime = 0.0f;
        endTime = -1.0f;
    }
    CsdRenderResult result;
    try {
        result = CSDRenderService.getDefault().generateCSD(data, startTime, endTime, false, true);
    } catch (ScoreGenerationException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
    String csd = result.getCsdText();
    File temp = FileUtilities.createTempTextFile("tempCsd", ".csd", BlueSystem.getCurrentProjectDirectory(), csd);
    return temp.getAbsolutePath();
}
Also used : ScoreGenerationException(blue.score.ScoreGenerationException) File(java.io.File) CsdRenderResult(blue.services.render.CsdRenderResult)

Aggregations

CsdRenderResult (blue.services.render.CsdRenderResult)12 File (java.io.File)8 BlueData (blue.BlueData)5 ScoreGenerationException (blue.score.ScoreGenerationException)5 SoundObjectException (blue.soundObject.SoundObjectException)3 IOException (java.io.IOException)3 Arrangement (blue.Arrangement)2 CompileData (blue.CompileData)2 GlobalOrcSco (blue.GlobalOrcSco)2 LiveData (blue.LiveData)2 Tables (blue.Tables)2 ParameterNameManager (blue.automation.ParameterNameManager)2 LinePoint (blue.components.lines.LinePoint)2 Mixer (blue.mixer.Mixer)2 TempoMapper (blue.noteProcessor.TempoMapper)2 GenericInstrument (blue.orchestra.GenericInstrument)2 Instrument (blue.orchestra.Instrument)2 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)2 StringChannelNameManager (blue.orchestra.blueSynthBuilder.StringChannelNameManager)2 RenderTimeManager (blue.services.render.RenderTimeManager)2