use of blue.Arrangement in project blue by kunstmusik.
the class AutomationManager method setData.
public void setData(BlueData data) {
if (this.data != null) {
Arrangement arrangement = this.data.getArrangement();
arrangement.removeAutomatableCollectionListener(this);
for (int i = 0; i < arrangement.size(); i++) {
Instrument instr = arrangement.getInstrument(i);
if (instr instanceof Automatable) {
Automatable temp = (Automatable) instr;
ParameterList parameters = temp.getParameterList();
// parameterMap.put(temp, parameters);
parameters.removeListener(parameterListListener);
}
}
Mixer mixer = this.data.getMixer();
mixer.getChannelListGroups().removeListener(channelListListener);
for (ChannelList list : mixer.getChannelListGroups()) {
list.removeListener(this);
for (Channel c : list) {
removeListenerFromChannel(c);
}
}
ChannelList channels = mixer.getChannels();
channels.removeListener(this);
for (Channel c : channels) {
removeListenerFromChannel(c);
}
ChannelList subChannels = mixer.getSubChannels();
subChannels.removeListener(this);
for (int i = 0; i < subChannels.size(); i++) {
removeListenerFromChannel(subChannels.get(i));
}
removeListenerFromChannel(mixer.getMaster());
if (this.score != null) {
for (LayerGroup<? extends Layer> layerGroup : score) {
layerGroup.removeLayerGroupListener(this);
}
}
this.data.removePropertyChangeListener(renderTimeListener);
}
// menu = null;
// dirty = false;
allParameters.clear();
if (data == null) {
return;
}
// Build Map from Instruments
Arrangement arrangement = data.getArrangement();
for (int i = 0; i < arrangement.size(); i++) {
Instrument instr = arrangement.getInstrument(i);
if (instr instanceof Automatable) {
Automatable temp = (Automatable) instr;
ParameterList parameters = temp.getParameterList();
allParameters.addAll(parameters);
parameters.addListener(parameterListListener);
}
}
arrangement.addAutomatableCollectionListener(this);
Mixer mixer = data.getMixer();
mixer.getChannelListGroups().addListener(channelListListener);
for (ChannelList list : mixer.getChannelListGroups()) {
list.addListener(this);
for (Channel c : list) {
addListenerToChannel(c);
}
}
ChannelList channels = mixer.getChannels();
channels.addListener(this);
for (Channel c : channels) {
addListenerToChannel(c);
}
ChannelList subChannels = mixer.getSubChannels();
subChannels.addListener(this);
for (int i = 0; i < subChannels.size(); i++) {
addListenerToChannel(subChannels.get(i));
}
addListenerToChannel(mixer.getMaster());
// System.err.println(this);
this.data = data;
this.score = data.getScore();
for (LayerGroup<? extends Layer> layerGroup : this.score) {
layerGroup.addLayerGroupListener(this);
}
this.data.addPropertyChangeListener(renderTimeListener);
// Build Map from Mixer Channels
}
use of blue.Arrangement in project blue by kunstmusik.
the class ScoreSection method parseCsOrc.
private static void parseCsOrc(BlueData data, String orc) {
StringTokenizer st = new StringTokenizer(orc, "\n");
String line = "";
StringBuilder globalOrch = new StringBuilder();
String sr = null;
String kr = null;
String ksmps = null;
String instrIds = "";
StringBuffer iBody = new StringBuffer();
UserDefinedOpcode udo = null;
GenericInstrument instr = null;
Arrangement arrangement = data.getArrangement();
OpcodeList opcodeList = data.getOpcodeList();
int state = 0;
while (st.hasMoreTokens()) {
line = st.nextToken();
String trimLine = line.trim();
switch(state) {
case 0:
if (trimLine.startsWith("instr")) {
int index = line.indexOf(';');
String iName = "";
if (index != -1) {
iName = line.substring(index + 1).trim();
line = line.substring(0, index);
}
instrIds = line.substring(line.indexOf("instr") + 5).trim();
instr = new GenericInstrument();
instr.setName(iName);
state = 1;
} else if (trimLine.startsWith("opcode")) {
int index = line.indexOf(';');
if (index != -1) {
line = line.substring(0, index);
}
line = line.substring(line.indexOf("opcode") + 6).trim();
String[] parts = line.split(",");
if (parts.length != 3) {
System.err.println("Error parsing UDO: 3 args " + "not found for definition");
} else {
udo = new UserDefinedOpcode();
udo.setOpcodeName(parts[0].trim());
udo.outTypes = parts[1].trim();
udo.inTypes = parts[2].trim();
}
state = 2;
} else {
if (trimLine.startsWith("kr")) {
kr = line.substring(line.indexOf('=') + 1).trim();
} else if (trimLine.startsWith("sr")) {
sr = line.substring(line.indexOf('=') + 1).trim();
} else if (trimLine.startsWith("nchnls")) {
data.getProjectProperties().channels = line.substring(line.indexOf('=') + 1).trim();
} else if (trimLine.startsWith("ksmps")) {
ksmps = line.substring(line.indexOf('=') + 1).trim();
} else {
globalOrch.append(line).append("\n");
}
}
break;
case 1:
if (trimLine.startsWith("endin")) {
if (instr != null && instrIds != null) {
instr.setText(iBody.toString());
if (instrIds.indexOf(',') > -1) {
String[] ids = instrIds.split(",");
for (int i = 0; i < ids.length; i++) {
arrangement.insertInstrument(ids[i], instr);
}
} else {
arrangement.insertInstrument(instrIds, instr);
}
}
instr = null;
instrIds = null;
iBody = new StringBuffer();
state = 0;
} else {
if (instr != null) {
iBody.append(line).append("\n");
}
}
break;
case 2:
if (trimLine.startsWith("endop")) {
if (udo != null) {
udo.codeBody = iBody.toString();
opcodeList.addOpcode(udo);
iBody = new StringBuffer();
udo = null;
}
state = 0;
} else {
if (udo != null) {
iBody.append(line).append("\n");
}
}
break;
}
}
/* HANDLE RESERVED GLOBAL VARIABLES */
if (kr != null && ksmps == null) {
try {
double krDouble = Double.parseDouble(kr);
double srDouble = Double.parseDouble(sr);
ksmps = Integer.toString((int) (srDouble / krDouble));
} catch (NumberFormatException nfe) {
ksmps = null;
}
}
if (sr != null) {
data.getProjectProperties().sampleRate = sr;
}
if (ksmps != null) {
data.getProjectProperties().ksmps = ksmps;
}
data.getGlobalOrcSco().setGlobalOrc(globalOrch.toString());
}
use of blue.Arrangement 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;
}
use of blue.Arrangement in project blue by kunstmusik.
the class SubChannelListPanel method reconcileSubChannelRemoveInBlueArrangement.
/**
* A hack to explicitly walk the current blue orchestra to find any
* BlueSynthBuilder's that contain BSBSubChannelDropdown's and to reconcile
* with the removed channel
*
* @param removedChannel
*
* @param oldName
* @param newName
*/
private void reconcileSubChannelRemoveInBlueArrangement(String removedChannel) {
BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
if (data == null) {
return;
}
Arrangement arr = data.getArrangement();
for (int i = 0; i < arr.size(); i++) {
Instrument instr = arr.getInstrument(i);
if (instr instanceof BlueSynthBuilder) {
BlueSynthBuilder bsb = (BlueSynthBuilder) instr;
BSBGraphicInterface bsbInterface = bsb.getGraphicInterface();
for (BSBObject bsbObj : bsbInterface.getAllSet()) {
if (bsbObj instanceof BSBSubChannelDropdown) {
BSBSubChannelDropdown bsbSubDrop = (BSBSubChannelDropdown) bsbObj;
if (bsbSubDrop.getChannelOutput().equals(removedChannel)) {
bsbSubDrop.setChannelOutput(Channel.MASTER);
}
}
}
}
}
}
Aggregations