Search in sources :

Example 1 with StringChannel

use of blue.orchestra.blueSynthBuilder.StringChannel in project blue by kunstmusik.

the class CSDRender method getStringChannels.

private ArrayList<StringChannel> getStringChannels(Arrangement arrangement, StringChannelNameManager scnm) {
    ArrayList<StringChannel> params = new ArrayList<>();
    for (int i = 0; i < arrangement.size(); i++) {
        InstrumentAssignment ia = arrangement.getInstrumentAssignment(i);
        if (ia.enabled) {
            Instrument instr = ia.instr;
            if (instr instanceof Automatable) {
                Automatable auto = (Automatable) instr;
                ArrayList<StringChannel> stringChannels = auto.getStringChannels();
                if (stringChannels != null) {
                    params.addAll(stringChannels);
                }
            }
        }
    }
    for (StringChannel strChannel : params) {
        strChannel.setChannelName(scnm.getUniqueStringChannel());
    }
    return params;
}
Also used : StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) ArrayList(java.util.ArrayList) Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) InstrumentAssignment(blue.InstrumentAssignment) LinePoint(blue.components.lines.LinePoint) Automatable(blue.automation.Automatable)

Example 2 with StringChannel

use of blue.orchestra.blueSynthBuilder.StringChannel 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 3 with StringChannel

use of blue.orchestra.blueSynthBuilder.StringChannel in project blue by kunstmusik.

the class CSDRender method handleParameters.

private void handleParameters(ArrayList parameters, ArrayList<StringChannel> stringChannels, GlobalOrcSco globalOrcSco, NoteList notes, Arrangement arrangement, double startTime, double endTime, boolean isRealTime, boolean _usingAPI) {
    Object[] varNum = new Object[1];
    StrBuilder initStatements = new StrBuilder();
    StrBuilder paramScore = new StrBuilder();
    boolean useAPI = isRealTime && _usingAPI;
    for (StringChannel strChannel : stringChannels) {
        String varName = strChannel.getChannelName();
        initStatements.append(varName);
        initStatements.append(" = ");
        initStatements.append("\"").append(strChannel.getValue()).append("\"\n");
        if (useAPI) {
            initStatements.append(varName).append(" chnexport \"");
            initStatements.append(varName).append("\", 3\n");
        }
    }
    for (int i = 0; i < parameters.size(); i++) {
        Parameter param = (Parameter) parameters.get(i);
        varNum[0] = new Integer(i);
        String varName = param.getCompilationVarName();
        // param.setCompilationVarName(varName);
        double initialVal;
        if (param.isAutomationEnabled()) {
            initialVal = param.getLine().getValue(startTime);
        } else {
            initialVal = param.getFixedValue();
        }
        // init statements
        initStatements.append(varName);
        initStatements.append(" init ");
        initStatements.append(NumberUtilities.formatDouble(initialVal));
        initStatements.append("\n");
        if (useAPI) {
            initStatements.append(varName).append(" chnexport \"");
            initStatements.append(varName).append("\", 3\n");
        } else if (param.isAutomationEnabled()) {
            // gk instrument
            GenericInstrument instr = getParameterInstrument(param);
            int instrId = arrangement.addInstrumentAtEnd(instr);
            // score for values
            appendParameterScore(param, instrId, paramScore, startTime, endTime);
        }
    }
    globalOrcSco.appendGlobalOrc(initStatements.toString());
    try {
        notes.addAll(ScoreUtilities.getNotes(paramScore.toString()));
    } catch (NoteParseException ex) {
        ex.printStackTrace();
    }
// globalOrcSco.appendGlobalSco(paramScore.toString());
}
Also used : NoteParseException(blue.soundObject.NoteParseException) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Parameter(blue.automation.Parameter) GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder) LinePoint(blue.components.lines.LinePoint)

Example 4 with StringChannel

use of blue.orchestra.blueSynthBuilder.StringChannel in project blue by kunstmusik.

the class CompileData method addInstrument.

/**
 * Adds and instrument to the Arrangement
 * @return instrument id that was assigned
 */
public int addInstrument(Instrument instrument) {
    if (handleParametersAndChannels && stringChannels != null && originalParameters != null) {
        if (instrument instanceof Automatable) {
            Automatable auto = (Automatable) instrument;
            ArrayList<StringChannel> tempStringChannels = auto.getStringChannels();
            if (tempStringChannels != null) {
                stringChannels.addAll(tempStringChannels);
                for (StringChannel sChan : tempStringChannels) {
                    sChan.setChannelName(scnm.getUniqueStringChannel());
                }
            }
            ParameterList paramList = auto.getParameterList();
            if (paramList != null) {
                originalParameters.addAll(paramList);
                for (Parameter param : paramList) {
                    param.setCompilationVarName(pnm.getUniqueParamName());
                }
            }
        }
    }
    return arrangement.addInstrument(instrument);
}
Also used : StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) ParameterList(blue.automation.ParameterList) Parameter(blue.automation.Parameter) Automatable(blue.automation.Automatable)

Example 5 with StringChannel

use of blue.orchestra.blueSynthBuilder.StringChannel 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)

Aggregations

StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)6 LinePoint (blue.components.lines.LinePoint)5 Parameter (blue.automation.Parameter)4 GenericInstrument (blue.orchestra.GenericInstrument)4 StrBuilder (org.apache.commons.lang3.text.StrBuilder)4 Instrument (blue.orchestra.Instrument)3 NoteParseException (blue.soundObject.NoteParseException)3 ArrayList (java.util.ArrayList)3 Arrangement (blue.Arrangement)2 CompileData (blue.CompileData)2 GlobalOrcSco (blue.GlobalOrcSco)2 Tables (blue.Tables)2 Automatable (blue.automation.Automatable)2 ParameterNameManager (blue.automation.ParameterNameManager)2 Mixer (blue.mixer.Mixer)2 TempoMapper (blue.noteProcessor.TempoMapper)2 StringChannelNameManager (blue.orchestra.blueSynthBuilder.StringChannelNameManager)2 CsdRenderResult (blue.services.render.CsdRenderResult)2 NoteList (blue.soundObject.NoteList)2 OpcodeList (blue.udo.OpcodeList)2