use of blue.orchestra.GenericInstrument in project blue by kunstmusik.
the class AudioLayer method generateInstrumentForAudioLayer.
protected int generateInstrumentForAudioLayer(CompileData compileData) {
if (compileData.getCompilationVariable(this.uniqueId) != null) {
return (Integer) compileData.getCompilationVariable(this.uniqueId);
}
Map<Channel, Integer> assignments = compileData.getChannelIdAssignments();
Channel c = null;
for (Channel channel : assignments.keySet()) {
if (uniqueId.equals(channel.getAssociation())) {
c = channel;
}
}
GenericInstrument instr = new GenericInstrument();
StringBuilder str = new StringBuilder();
try {
try (BufferedReader br = new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("playback_instrument.orc")))) {
String line;
while ((line = br.readLine()) != null) {
str.append(line).append("\n");
}
}
} catch (IOException ioe) {
throw new RuntimeException("[error] AudioLayer could not load instr text");
}
if (c != null) {
int channelId = assignments.get(c);
String var1 = Mixer.getChannelVar(channelId, 0);
String var2 = Mixer.getChannelVar(channelId, 1);
instr.setText(getInstrumentText(var1, var2));
// System.out.println("Instr Text: " + instr.getText());
} else {
throw new RuntimeException("Error: could not find Mixer Channels for Audio layer");
// instr.setText(getInstrumentText("a1", "a2") + "\noutc a1, a2\n");
}
int instrId = compileData.addInstrument(instr);
compileData.setCompilationVariable(this.uniqueId, instrId);
return instrId;
}
use of blue.orchestra.GenericInstrument in project blue by kunstmusik.
the class CeciliaModuleCompilationUnit method getMagicInstrument.
/**
* @return
*/
private Instrument getMagicInstrument() {
if (magicInstrument_instr.size() == 0) {
return null;
}
GenericInstrument instr = new GenericInstrument();
StringBuffer instrText = new StringBuffer();
for (Iterator iter = magicInstrument_instr.iterator(); iter.hasNext(); ) {
String line = (String) iter.next();
instrText.append(line).append("\n");
}
instr.setText(instrText.toString());
instr.setName("CeciliaModule Magic Instrument");
return instr;
}
use of blue.orchestra.GenericInstrument in project blue by kunstmusik.
the class CeciliaModuleCompilationUnit method parseOrchestra.
private void parseOrchestra(String orch) {
StringTokenizer st = new StringTokenizer(orch, "\n");
StringBuffer globalBuffer = new StringBuffer();
StringBuffer instrBuffer = new StringBuffer();
String instrID = "";
int mode = 0;
while (st.hasMoreTokens()) {
String line = st.nextToken().trim();
switch(mode) {
case 0:
if (line.startsWith("instr")) {
int index = line.indexOf(';');
if (index != -1) {
line = line.substring(0, index);
}
line = line.substring(line.indexOf("instr") + 5);
instrID = line.trim();
mode = 1;
} else if (line.startsWith("kr") || line.startsWith("sr") || line.startsWith("ksmps") || line.startsWith("nchnls")) {
// ignore
} else {
globalBuffer.append(line).append("\n");
}
break;
case 1:
if (line.startsWith("endin")) {
GenericInstrument instr = new GenericInstrument();
instr.setText(instrBuffer.toString());
if (instrID.indexOf(",") > 0) {
StringTokenizer idTokenizer = new StringTokenizer(instrID, ",");
while (idTokenizer.hasMoreElements()) {
String id = idTokenizer.nextToken();
instruments.put(id, instr.deepCopy());
}
} else {
instruments.put(instrID, instr);
}
instrID = "";
instrBuffer = new StringBuffer();
mode = 0;
} else {
instrBuffer.append(line).append("\n");
}
break;
}
}
globalOrc += globalBuffer.toString();
}
use of blue.orchestra.GenericInstrument 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());
}
use of blue.orchestra.GenericInstrument in project blue by kunstmusik.
the class ArrangementEditPanel method convertToBSB.
public void convertToBSB() {
int selectedRow = arrangementTable.getSelectedRow();
if (selectedRow < 0) {
return;
}
String instrumentId = (String) arrangement.getValueAt(selectedRow, 1);
Instrument instr = arrangement.getInstrument(selectedRow);
if (instr instanceof GenericInstrument) {
GenericInstrument genInstr = (GenericInstrument) instr;
BlueSynthBuilder bsb = new BlueSynthBuilder();
bsb.setName(genInstr.getName());
bsb.setComment(genInstr.getComment());
bsb.setGlobalOrc(genInstr.getGlobalOrc());
bsb.setGlobalSco(genInstr.getGlobalSco());
bsb.setInstrumentText(genInstr.getText());
bsb.setOpcodeList(genInstr.getOpcodeList());
arrangement.replaceInstrument(instrumentId, bsb);
}
}
Aggregations