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;
}
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();
}
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);
}
}
}
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();
}
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();
}
Aggregations