Search in sources :

Example 6 with StrBuilder

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

the class Mixer method getMixerInstrument.

public GenericInstrument getMixerInstrument(CompileData data, OpcodeList udos, int nchnls) {
    GenericInstrument instr = new GenericInstrument();
    instr.setName("Blue Mixer Instrument");
    StrBuilder buffer = new StrBuilder();
    MixerNode node = MixerNode.getMixerGraph(this);
    EffectManager manager = new EffectManager();
    buffer.append(MixerNode.getMixerCode(data, this, udos, manager, node, nchnls));
    buffer.append("outc ");
    for (int i = 0; i < nchnls; i++) {
        if (i > 0) {
            buffer.append(", ");
        }
        buffer.append(getVar(data, master, i));
    }
    buffer.append("\n").append(getClearStatements(data, nchnls));
    instr.setText(buffer.toString());
    return instr;
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 7 with StrBuilder

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

the class Mixer method getInitStatements.

public String getInitStatements(CompileData data, int nchnls) {
    StrBuilder buffer = new StrBuilder();
    List<Channel> allChannels = getAllSourceChannels();
    for (Channel c : allChannels) {
        for (int j = 0; j < nchnls; j++) {
            buffer.append(getChannelVar(data.getChannelIdAssignments().get(c), j)).append("\tinit\t0\n");
        }
    }
    for (int i = 0; i < subChannels.size(); i++) {
        Channel c = subChannels.get(i);
        for (int j = 0; j < nchnls; j++) {
            buffer.append(getSubChannelVar(c.getName(), j)).append("\tinit\t0\n");
        }
    }
    for (int j = 0; j < nchnls; j++) {
        buffer.append(getSubChannelVar(MASTER_CHANNEL, j)).append("\tinit\t0\n");
    }
    return buffer.toString();
}
Also used : StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 8 with StrBuilder

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

the class Arrangement method preGenerateOrchestra.

/**
 * Called before generating Mixer instrument in CSD Render. This needs to be
 * called earlier as it will go and find out what subchannels have
 * non-channel dependencies which result from SoundObject's that contain
 * blueMixerOut code that uses subchannels.
 *
 * @param mixer
 * @param nchnls
 */
public void preGenerateOrchestra(CompileData data, Mixer mixer, int nchnls, ArrayList<Instrument> alwaysOnInstruments) {
    if (preGenerationCache == null) {
        preGenerationCache = new StrBuilder();
        preGenList = new ArrayList<>();
    }
    for (Iterator<InstrumentAssignment> iter = arrangement.iterator(); iter.hasNext(); ) {
        InstrumentAssignment ia = iter.next();
        preGenList.add(ia);
        if (!ia.enabled) {
            continue;
        }
        appendInstrumentText(data, preGenerationCache, ia, mixer, nchnls);
        Instrument alwaysOnInstr = createAlwaysOnInstrument(data, ia, mixer, nchnls);
        if (alwaysOnInstr != null) {
            alwaysOnInstruments.add(alwaysOnInstr);
            data.addInstrSourceId(alwaysOnInstr, ia.arrangementId);
        }
    }
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) Instrument(blue.orchestra.Instrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 9 with StrBuilder

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

the class Arrangement method convertBlueMixerOut.

// TODO - Make this more efficient (made this way in case blueMixerOut is in
// comments
private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrangementId, String input, int nchnls) {
    if (!input.contains("blueMixerOut") && !input.contains("blueMixerIn")) {
        return input;
    }
    StrBuilder buffer = new StrBuilder();
    String[] lines = NEW_LINES.split(input);
    boolean blueMixerInFound = false;
    for (String line : lines) {
        int mixerInIndex = line.indexOf("blueMixerIn");
        if (mixerInIndex > 0) {
            String noCommentLine = TextUtilities.stripSingleLineComments(line);
            if (!noCommentLine.contains("blueMixerIn")) {
                buffer.append(line).append("\n");
                continue;
            }
            if (mixer == null || !mixer.isEnabled()) {
                throw new RuntimeException("Error: Instrument uses blueMixerIn but mixer is not enabled");
            }
            blueMixerInFound = true;
            String argText = noCommentLine.substring(0, mixerInIndex).trim();
            String[] args = argText.split(",");
            Channel c = getChannelForArrangementId(mixer, arrangementId);
            for (int i = 0; i < nchnls && i < args.length; i++) {
                String arg = args[i];
                String var;
                if (c == null) {
                    var = Mixer.getSubChannelVar(Channel.MASTER, i);
                } else {
                    var = Mixer.getChannelVar(data.getChannelIdAssignments().get(c), i);
                }
                buffer.append(arg).append(" = ");
                buffer.append(var).append("\n");
            }
        } else if (line.trim().startsWith("blueMixerOut")) {
            String argText = line.trim().substring(12);
            String[] args = argText.split(",");
            if (args[0].trim().matches("\".*\"")) {
                if (mixer == null || !mixer.isEnabled()) {
                    buffer.append("outc ");
                    for (int i = 1; i < args.length; i++) {
                        if (i > 1) {
                            buffer.append(",");
                        }
                        buffer.append(args[i]);
                    }
                    buffer.append("\n");
                } else {
                    String subChanBase = args[0].trim();
                    final String subChannelName = subChanBase.substring(1, subChanBase.length() - 1);
                    Optional<Channel> found = mixer.getSubChannels().stream().filter(chn -> subChannelName.equals(chn.getName())).findFirst();
                    if (!found.isPresent()) {
                        throw new RuntimeException("Unable to find subchannel with name: " + subChannelName);
                    }
                    mixer.addSubChannelDependency(subChannelName);
                    for (int i = 1; i < nchnls + 1 && i < args.length; i++) {
                        String arg = args[i];
                        String var = Mixer.getSubChannelVar(subChannelName, i - 1);
                        buffer.append(var);
                        if (!blueMixerInFound) {
                            buffer.append(" += ");
                        } else {
                            buffer.append(" = ");
                        }
                        buffer.append(arg).append("\n");
                    }
                }
            } else if (mixer == null || !mixer.isEnabled()) {
                buffer.append(line.replaceAll("blueMixerOut", "outc"));
                buffer.append("\n");
            } else {
                Channel c = getChannelForArrangementId(mixer, arrangementId);
                for (int i = 0; i < nchnls && i < args.length; i++) {
                    String arg = args[i];
                    String var;
                    if (c == null) {
                        var = Mixer.getSubChannelVar(Channel.MASTER, i);
                    } else {
                        var = Mixer.getChannelVar(data.getChannelIdAssignments().get(c), i);
                    }
                    buffer.append(var);
                    if (!blueMixerInFound) {
                        buffer.append(" += ");
                    } else {
                        buffer.append(" = ");
                    }
                    buffer.append(arg).append("\n");
                }
            }
        } else {
            buffer.append(line).append("\n");
        }
    }
    return buffer.toString();
}
Also used : Channel(blue.mixer.Channel) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 10 with StrBuilder

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

the class CS6DiskRendererService method execWaitAndCollect.

@Override
public String execWaitAndCollect(String[] args, File currentWorkingDirectory) {
    initialize();
    Csound csound = new Csound();
    blueCallbackWrapper = new BlueCallbackWrapper(csound);
    blueCallbackWrapper.SetMessageCallback();
    StrBuilder buffer = new StrBuilder();
    blueCallbackWrapper.setStringBuffer(buffer);
    CsoundArgVList argsList = new CsoundArgVList();
    for (int i = 0; i < args.length; i++) {
        if (args[i].startsWith("\"") && args[i].endsWith("\"")) {
            args[i] = args[i].substring(1, args[i].length() - 1);
        }
        argsList.Append(args[i]);
    }
    if (currentWorkingDirectory != null) {
        String sfdir = "--env:SFDIR=" + currentWorkingDirectory.getAbsolutePath();
        argsList.Append(sfdir);
    }
    int retVal = csound.Compile(argsList.argc(), argsList.argv());
    if (retVal != 0) {
        blueCallbackWrapper.setStringBuffer(null);
        csound.Stop();
        csound.Cleanup();
        csound.SetMessageCallback(null);
        csound.Reset();
        return buffer.toString();
    }
    while (csound.PerformKsmps() == 0 && keepRunning) {
    // empty
    }
    csound.Stop();
    csound.Cleanup();
    csound.SetMessageCallback(null);
    csound.Reset();
    keepRunning = false;
    blueCallbackWrapper.setStringBuffer(null);
    return buffer.toString();
}
Also used : Csound(csnd6.Csound) StrBuilder(org.apache.commons.lang3.text.StrBuilder) CsoundArgVList(csnd6.CsoundArgVList)

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