Search in sources :

Example 1 with CsdRenderResult

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

the class CSDRender method generateCSDImpl.

@Override
protected CsdRenderResult generateCSDImpl(BlueData data, double startTime, double endTime, boolean isRealTime, boolean _usingAPI) {
    ProjectPluginManager.getInstance().preRender(data);
    StringChannelNameManager scnm = new StringChannelNameManager();
    ParameterNameManager pnm = new ParameterNameManager();
    ArrayList<StringChannel> stringChannels = getStringChannels(data.getArrangement(), scnm);
    ParameterHelper.clearCompilationVarNames(data);
    boolean usingAPI = isRealTime && _usingAPI;
    double renderStartTime = data.getRenderStartTime();
    // making copies to use for adding compileTime tables and instruments
    Tables tables = new Tables(data.getTableSet());
    ArrayList originalParameters;
    // if (usingAPI) {
    originalParameters = ParameterHelper.getAllParameters(data.getArrangement(), data.getMixer());
    // } else {
    // originalParameters = ParameterHelper.getActiveParameters(
    // data.getArrangement(), data.getMixer());
    // }
    assignParameterNames(originalParameters, pnm);
    Arrangement arrangement = new Arrangement(data.getArrangement());
    arrangement.clearUnusedInstrAssignments();
    boolean hasInstruments = arrangement.size() > 0;
    CompileData compileData = new CompileData(arrangement, tables, stringChannels, originalParameters, scnm, pnm);
    Mixer mixer = null;
    boolean mixerEnabled = data.getMixer().isEnabled();
    if (mixerEnabled) {
        mixer = new Mixer(data.getMixer());
        assignChannelIds(compileData, mixer);
    }
    NoteList generatedNotes;
    try {
        generatedNotes = data.getScore().generateForCSD(compileData, startTime, endTime);
    } catch (ScoreGenerationException ex) {
        throw new RuntimeException(ex);
    }
    compileData.setHandleParametersAndChannels(false);
    // assignParameterNames(originalParameters);
    // get parameters
    // ArrayList parameters;
    // if (usingAPI) {
    // parameters = ParameterHelper.getAllParameters(
    // arrangement, mixer);
    // } else {
    // parameters = ParameterHelper.getActiveParameters(
    // arrangement, mixer);
    // }
    GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
    OpcodeList udos = new OpcodeList(data.getOpcodeList());
    // add all UDO's from instruments and effects
    arrangement.generateUserDefinedOpcodes(udos);
    // adding all compile-time instruments from soundObjects to arrangement
    appendFtgenTableNumbers(globalOrcSco.getGlobalOrc(), tables);
    // generating ftables
    arrangement.generateFTables(tables);
    String ftables = tables.getTables();
    // Handle Render End Instrument and Note
    if (endTime > 0.0f && endTime > startTime) {
        Instrument instr = createRenderEndInstrument();
        int instrId = arrangement.addInstrument(instr);
        double endStartTime = endTime - startTime;
        try {
            Note renderEndNote = Note.createNote("i" + instrId + " " + endStartTime + " 0.1");
            generatedNotes.add(renderEndNote);
        } catch (NoteParseException e1) {
        }
    }
    Tempo tempo = data.getScore().getTempo();
    TempoMapper tempoMapper = null;
    if (tempo.isEnabled()) {
        tempoMapper = getTempoMapper(tempo);
        globalOrcSco.appendGlobalSco(getTempoScore(tempo, renderStartTime, endTime));
    } else {
        tempoMapper = getTempoMapper(globalOrcSco.getGlobalSco());
    }
    double totalDur = blue.utility.ScoreUtilities.getTotalDuration(generatedNotes);
    // double processingStart = blue.utility.ScoreUtilities.getProcessingStartTime(
    // tempPObj);
    // FIXME - figure out what to do about PROCESSING_START
    double processingStart = renderStartTime;
    System.out.println("<TOTAL_DUR> = " + totalDur);
    System.out.println("<RENDER_START> = " + renderStartTime);
    System.out.println("<PROCESSING_START> = " + processingStart);
    int nchnls = getNchnls(data, isRealTime);
    ArrayList<Instrument> alwaysOnInstruments = new ArrayList<>();
    // boolean generateMixer = mixerEnabled && (hasInstruments || mixer.hasSubChannelDependencies());
    arrangement.preGenerateOrchestra(compileData, mixer, nchnls, alwaysOnInstruments);
    String globalSco = globalOrcSco.getGlobalSco() + "\n";
    globalSco += arrangement.generateGlobalSco(compileData) + "\n";
    globalSco = preprocessSco(globalSco, totalDur, renderStartTime, processingStart, tempoMapper);
    double globalDur;
    try {
        globalDur = getGlobalDuration(globalSco);
    } catch (SoundObjectException ex) {
        throw new RuntimeException(ex);
    }
    if (globalDur < totalDur) {
        globalDur = totalDur;
    }
    System.out.println("Global Duration = " + globalDur);
    if (mixerEnabled) {
        globalDur += mixer.getExtraRenderTime();
    }
    for (Instrument instrument : alwaysOnInstruments) {
        String sourceId = compileData.getInstrSourceId(instrument);
        String noteStr;
        if (StringUtils.isNumeric(sourceId)) {
            int instrId = arrangement.addInstrumentAtEnd(instrument);
            noteStr = "i" + instrId + " 0 " + totalDur;
        } else {
            String instrId = sourceId + "_alwaysOn";
            arrangement.addInstrumentWithId(instrument, instrId, false);
            noteStr = "i \"" + instrId + "\" 0 " + totalDur;
        }
        try {
            Note n = Note.createNote(noteStr);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    if (mixerEnabled) {
        final String mixerId = "BlueMixer";
        // globalDur += mixer.getExtraRenderTime();
        clearUnusedMixerChannels(mixer, arrangement);
        globalOrcSco.appendGlobalOrc(mixer.getInitStatements(compileData, nchnls) + "\n");
        arrangement.addInstrumentWithId(mixer.getMixerInstrument(compileData, udos, nchnls), mixerId, false);
        try {
            Note n = Note.createNote("i \"BlueMixer\" 0 " + globalDur);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    handleParameters(originalParameters, stringChannels, globalOrcSco, generatedNotes, arrangement, startTime, startTime + globalDur, isRealTime, _usingAPI);
    if (isRealTime && !usingAPI) {
        Instrument instr = createBlueTimePointerInstrument();
        int instrId = arrangement.addInstrument(instr);
        try {
            Note n = Note.createNote("i" + instrId + " 0 " + globalDur);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    String tempGlobalOrc = compileData.getGlobalOrc();
    if (tempGlobalOrc != null && tempGlobalOrc.length() > 0) {
        globalOrcSco.appendGlobalOrc(tempGlobalOrc);
    }
    StrBuilder csd = new StrBuilder();
    appendProjectInfo(data, csd);
    csd.append("<CsoundSynthesizer>\n\n");
    appendCsInstruments(compileData, data, udos, arrangement, globalOrcSco, csd, mixer, isRealTime);
    appendCsScore(globalSco, ftables, generatedNotes, totalDur, csd);
    csd.append("</CsoundSynthesizer>");
    CsdRenderResult renderResult = new CsdRenderResult(csd.toString(), tempoMapper, originalParameters, stringChannels);
    return renderResult;
}
Also used : GlobalOrcSco(blue.GlobalOrcSco) NoteList(blue.soundObject.NoteList) NoteParseException(blue.soundObject.NoteParseException) Mixer(blue.mixer.Mixer) ArrayList(java.util.ArrayList) SoundObjectException(blue.soundObject.SoundObjectException) Tables(blue.Tables) CompileData(blue.CompileData) StrBuilder(org.apache.commons.lang3.text.StrBuilder) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Arrangement(blue.Arrangement) LinePoint(blue.components.lines.LinePoint) TempoMapper(blue.noteProcessor.TempoMapper) Tempo(blue.score.tempo.Tempo) ParameterNameManager(blue.automation.ParameterNameManager) ScoreGenerationException(blue.score.ScoreGenerationException) OpcodeList(blue.udo.OpcodeList) StringChannelNameManager(blue.orchestra.blueSynthBuilder.StringChannelNameManager) Note(blue.soundObject.Note) Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 2 with CsdRenderResult

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

the class GenerateCsdAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    final Frame mainWindow = WindowManager.getDefault().getMainWindow();
    File rValue = FileChooserManager.getDefault().showSaveDialog(FILE_GEN, mainWindow);
    if (rValue != null) {
        BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
        File temp = rValue;
        if (!(temp.getName().trim().endsWith(".csd"))) {
            temp = new File(temp.getAbsolutePath() + ".csd");
        }
        try {
            try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(temp)))) {
                final CsdRenderResult renderResult = CSDRenderService.getDefault().generateCSD(data, data.getRenderStartTime(), data.getRenderEndTime(), false, false);
                out.print(renderResult.getCsdText());
                out.flush();
            }
            StatusDisplayer.getDefault().setStatusText(BlueSystem.getString("message.generateScore.success") + " " + temp.getName());
        } catch (Exception ex) {
            ExceptionDialog.showExceptionDialog(mainWindow, ex);
            throw new RuntimeException("CSDRender Failed");
        }
    }
// if (rValue == JFileChooser.CANCEL_OPTION) {
// StatusDisplayer.getDefault().setStatusText(BlueSystem.getString(
// "message.actionCancelled"));
// }
}
Also used : BlueData(blue.BlueData) Frame(java.awt.Frame) FileWriter(java.io.FileWriter) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 3 with CsdRenderResult

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

the class GenerateRealtimeCsdToScreenAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    StatusDisplayer.getDefault().setStatusText(BlueSystem.getString("message.generatingCSD"));
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    try {
        double startTime = data.getRenderStartTime();
        double endTime = data.getRenderEndTime();
        /*
             * try { tempStart = Double.parseDouble(playStartText.getText()); }
             * catch(NumberFormatException nfe) { tempStart = 0.0f;
             * playStartText.setText(Double.toString(tempStart));
             * JOptionPane.showMessageDialog(null, BlueSystem
             * .getString("message.generateScore.startingFromZero")); }
             */
        boolean isApi = CommandlineRealtimeRenderServiceFactory.class != RealtimeRenderSettings.getInstance().renderServiceFactory.getClass();
        CsdRenderResult result = CSDRenderService.getDefault().generateCSD(data, startTime, endTime, true, isApi);
        String csd = result.getCsdText();
        InfoDialog.showInformationDialog(WindowManager.getDefault().getMainWindow(), csd, BlueSystem.getString("message.generateScore.csdTest"));
    } catch (Exception ex) {
        ExceptionDialog.showExceptionDialog(WindowManager.getDefault().getMainWindow(), ex);
        throw new RuntimeException("CSDRender Failed");
    }
}
Also used : BlueData(blue.BlueData) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 4 with CsdRenderResult

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

the class GenerateCsdToScreenAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    StatusDisplayer.getDefault().setStatusText(BlueSystem.getString("message.generatingCSD"));
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    try {
        double startTime = data.getRenderStartTime();
        double endTime = data.getRenderEndTime();
        /*
             * try { tempStart = Double.parseDouble(playStartText.getText()); }
             * catch(NumberFormatException nfe) { tempStart = 0.0f;
             * playStartText.setText(Double.toString(tempStart));
             * JOptionPane.showMessageDialog(null, BlueSystem
             * .getString("message.generateScore.startingFromZero")); }
             */
        CsdRenderResult result = CSDRenderService.getDefault().generateCSD(data, startTime, endTime, false, false);
        String csd = result.getCsdText();
        InfoDialog.showInformationDialog(WindowManager.getDefault().getMainWindow(), csd, BlueSystem.getString("message.generateScore.csdTest"));
    } catch (Exception ex) {
        ExceptionDialog.showExceptionDialog(WindowManager.getDefault().getMainWindow(), ex);
        throw new RuntimeException("CSDRender Failed");
    }
}
Also used : BlueData(blue.BlueData) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 5 with CsdRenderResult

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

the class CompileProcessor method process.

@Override
protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
    String compileFileName = null;
    String outFileName = null;
    if (optionValues.containsKey(c)) {
        compileFileName = optionValues.get(c)[0];
    }
    if (optionValues.containsKey(o)) {
        outFileName = optionValues.get(o)[0];
    }
    if (compileFileName == null && outFileName == null) {
        return;
    }
    if (compileFileName == null && outFileName != null) {
        throw new CommandException(1, ".blue project not given as argument");
    }
    File in = new File(compileFileName);
    if (!in.exists() || !in.isFile()) {
        throw new CommandException(1, "Could not open .blue file: " + in.getAbsolutePath());
    }
    if (outFileName == null) {
        outFileName = compileFileName.substring(0, compileFileName.indexOf(".blue")) + ".csd";
    }
    OpenProjectAction.open(in);
    PrintWriter out = null;
    try {
        BlueData tempData = BlueProjectManager.getInstance().getCurrentBlueData();
        out = new PrintWriter(new BufferedWriter(new FileWriter(outFileName)));
        CsdRenderResult renderResult = CSDRenderService.getDefault().generateCSD(tempData, 0.0F, -1.0F, false, false);
        out.print(renderResult.getCsdText());
        out.close();
        throw new CommandException(0, compileFileName + " " + BlueSystem.getString("blue.compiledTo") + " " + outFileName);
    } catch (IOException | ScoreGenerationException | CommandException e) {
        if (out != null) {
            out.close();
        }
        if (e instanceof CommandException) {
            throw (CommandException) e;
        }
        throw new CommandException(1, BlueSystem.getString("message.errorLabel") + " " + BlueSystem.getString("blue.csdCompileError") + e.getMessage());
    }
}
Also used : BlueData(blue.BlueData) ScoreGenerationException(blue.score.ScoreGenerationException) FileWriter(java.io.FileWriter) CommandException(org.netbeans.api.sendopts.CommandException) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) 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