Search in sources :

Example 31 with StrBuilder

use of org.apache.commons.lang3.text.StrBuilder in project blue by kunstmusik.

the class Effect method generateUDO.

public UserDefinedOpcode generateUDO(OpcodeList udoList) {
    HashMap udoReplacementValues = UDOUtilities.appendUserDefinedOpcodes(opcodeList, udoList);
    UserDefinedOpcode udo = new UserDefinedOpcode();
    BSBCompilationUnit bsbUnit = new BSBCompilationUnit();
    graphicInterface.setupForCompilation(bsbUnit);
    StrBuilder buffer = new StrBuilder();
    buffer.append(getXinText()).append("\n");
    buffer.append(bsbUnit.replaceBSBValues(code)).append("\n");
    buffer.append(getXoutText()).append("\n");
    String udoCode = buffer.toString();
    if (udoReplacementValues != null) {
        udoCode = TextUtilities.replaceOpcodeNames(udoReplacementValues, udoCode);
    }
    udo.codeBody = udoCode;
    udo.inTypes = getSigTypes(numIns);
    udo.outTypes = getSigTypes(numOuts);
    return udo;
}
Also used : HashMap(java.util.HashMap) UserDefinedOpcode(blue.udo.UserDefinedOpcode) BSBCompilationUnit(blue.orchestra.blueSynthBuilder.BSBCompilationUnit) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 32 with StrBuilder

use of org.apache.commons.lang3.text.StrBuilder in project blue by kunstmusik.

the class TempoMapper method toString.

@Override
public String toString() {
    StrBuilder buffer = new StrBuilder();
    buffer.append("[TempoMapper]").append("\n");
    for (int i = 0; i < timeMap.length; i++) {
        BeatTempoPair pair = timeMap[i];
        buffer.append(pair.beat).append(" : ").append(pair.tempo).append("\n");
    }
    return buffer.toString();
}
Also used : StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 33 with StrBuilder

use of org.apache.commons.lang3.text.StrBuilder 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 34 with StrBuilder

use of org.apache.commons.lang3.text.StrBuilder in project blue by kunstmusik.

the class CSDRender method createAllNotesOffInstrument.

protected Instrument createAllNotesOffInstrument(String[] instrIds) {
    GenericInstrument instr = new GenericInstrument();
    StrBuilder buffer = new StrBuilder();
    buffer.append("koff init 0\n" + "if (koff == 0) then\n");
    for (int i = 0; i < instrIds.length; i++) {
        String id = instrIds[i];
        String[] parts = StringUtils.split(id, ",");
        for (int j = 0; j < parts.length; j++) {
            String tempId = parts[j];
            try {
                int instrIdNum = Integer.parseInt(tempId.trim());
                buffer.append("turnoff2 ").append(instrIdNum);
                buffer.append(", 0, 1\n");
            } catch (NumberFormatException nfe) {
                buffer.append("insno").append(i).append(j);
                buffer.append(" nstrnum \"").append(tempId).append("\"\n");
                buffer.append("turnoff2 insno").append(i).append(j);
                buffer.append(", 0, 1\n");
            }
        }
    }
    buffer.append("koff = 1\nelse\nturnoff\nendif\n");
    instr.setText(buffer.toString());
    return instr;
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder) LinePoint(blue.components.lines.LinePoint)

Example 35 with StrBuilder

use of org.apache.commons.lang3.text.StrBuilder in project blue by kunstmusik.

the class CSDRender method getParameterInstrument.

private GenericInstrument getParameterInstrument(Parameter param) {
    GenericInstrument instr = new GenericInstrument();
    instr.setName("Param: " + param.getName());
    StrBuilder buffer = new StrBuilder();
    String compilationVarName = param.getCompilationVarName();
    if (param.getResolution().doubleValue() > 0.0f) {
        buffer.append(compilationVarName);
        buffer.append(" init p4\nturnoff");
    } else {
        buffer.append("if (p4 == p5) then\n");
        buffer.append(compilationVarName);
        buffer.append(" init p4\nturnoff\nelse\n");
        buffer.append(compilationVarName);
        buffer.append(" line p4, p3, p5\nendif");
    }
    instr.setText(buffer.toString());
    return instr;
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Aggregations

StrBuilder (org.apache.commons.lang3.text.StrBuilder)44 GenericInstrument (blue.orchestra.GenericInstrument)9 LinePoint (blue.components.lines.LinePoint)8 Instrument (blue.orchestra.Instrument)5 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)4 Parameter (blue.automation.Parameter)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 ParameterNameManager (blue.automation.ParameterNameManager)2 Line (blue.components.lines.Line)2 SoundObjectParameterLine (blue.components.lines.SoundObjectParameterLine)2 Mixer (blue.mixer.Mixer)2 TempoMapper (blue.noteProcessor.TempoMapper)2 StringChannelNameManager (blue.orchestra.blueSynthBuilder.StringChannelNameManager)2 EnvelopePoint (blue.orchestra.blueX7.EnvelopePoint)2 CsdRenderResult (blue.services.render.CsdRenderResult)2