use of blue.udo.OpcodeList in project blue by kunstmusik.
the class OpcodeListEditPanel method importCsoundUdo.
protected void importCsoundUdo() {
List<File> retVal = FileChooserManager.getDefault().showOpenDialog(IMPORT_CSOUND_UDO_DIALOG, SwingUtilities.getRoot(OpcodeListEditPanel.this));
if (retVal != null && retVal.size() == 1) {
File f = retVal.get(0);
if (f.exists()) {
try {
String text = TextUtilities.getTextFromFile(f);
OpcodeList opList = UDOUtilities.parseUDOText(text);
opcodeList.addAll(opList);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
use of blue.udo.OpcodeList in project blue by kunstmusik.
the class PolyObjectEditor method testSoundObject.
public final void testSoundObject() {
if (this.pObj == null) {
return;
}
BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
if (data == null) {
System.err.println("PolyObjectEditor::testSoundObject() - " + "Could not get reference to current BlueData object");
return;
}
Tables tables = new Tables(data.getTableSet());
Arrangement arrangement = new Arrangement(data.getArrangement());
PolyObject tempPObj = new PolyObject(this.pObj);
OpcodeList opcodeList = new OpcodeList(data.getOpcodeList());
GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
// adding all compile-time instruments from soundObjects to arrangement
arrangement.generateFTables(tables);
CompileData compileData = new CompileData(arrangement, tables);
// grabbing all notes from soundObjects
NoteList generatedNotes = null;
try {
generatedNotes = tempPObj.generateForCSD(compileData, 0.0f, -1.0f);
} catch (Exception e) {
Exceptions.printStackTrace(e);
return;
}
if (generatedNotes != null) {
InfoDialog.showInformationDialog(SwingUtilities.getRoot(this), generatedNotes.toString(), BlueSystem.getString("soundObject.generatedScore"));
}
}
use of blue.udo.OpcodeList in project blue by kunstmusik.
the class BlueSynthBuilder method loadFromXML.
// private void doPostCompilation() {
// bsbCompilationUnit = null;
// }
/* XML SERIALIZATION */
public static Instrument loadFromXML(Element data) throws Exception {
BlueSynthBuilder bsb = new BlueSynthBuilder(false);
InstrumentUtilities.initBasicFromXML(data, bsb);
String editEnabledStr = data.getAttributeValue("editEnabled");
if (editEnabledStr != null) {
bsb.setEditEnabled(Boolean.valueOf(editEnabledStr).booleanValue());
}
Elements nodes = data.getElements();
while (nodes.hasMoreElements()) {
Element node = nodes.next();
String nodeName = node.getName();
switch(nodeName) {
case "globalOrc":
bsb.setGlobalOrc(node.getTextString());
break;
case "globalSco":
bsb.setGlobalSco(node.getTextString());
break;
case "instrumentText":
bsb.setInstrumentText(node.getTextString());
break;
case "alwaysOnInstrumentText":
bsb.setAlwaysOnInstrumentText(node.getTextString());
break;
case "graphicInterface":
bsb.setGraphicInterface(BSBGraphicInterface.loadFromXML(node));
break;
case "presetGroup":
bsb.setPresetGroup(PresetGroup.loadFromXML(node));
break;
case "bsbParameterList":
case "parameterList":
bsb.parameterList = ParameterList.loadFromXML(node);
break;
case "opcodeList":
bsb.opcodeList = OpcodeList.loadFromXML(node);
break;
}
}
if (bsb.presetGroup == null) {
bsb.presetGroup = new PresetGroup();
}
if (bsb.graphicInterface == null) {
bsb.graphicInterface = new BSBGraphicInterface();
}
if (bsb.parameterList == null) {
bsb.parameterList = new ParameterList();
}
if (bsb.opcodeList == null) {
bsb.opcodeList = new OpcodeList();
}
bsb.graphicInterface.getRootGroup().setParameterList(bsb.parameterList);
return bsb;
}
use of blue.udo.OpcodeList in project blue by kunstmusik.
the class UDOUtilities method parseUDOText.
public static OpcodeList parseUDOText(final String udoText) {
OpcodeList retVal = new OpcodeList();
String cleanedText = TextUtilities.stripMultiLineComments(udoText);
StringTokenizer st = new StringTokenizer(cleanedText, "\n");
String line = "";
int state = 0;
UserDefinedOpcode currentUDO = null;
StringBuffer codeBody = null;
while (st.hasMoreTokens()) {
line = st.nextToken();
switch(state) {
case 0:
if (line.trim().startsWith("opcode")) {
line = TextUtilities.stripSingleLineComments(line.trim());
String[] parts = line.substring(6).split(",");
if (parts.length == 3) {
currentUDO = new UserDefinedOpcode();
currentUDO.opcodeName = parts[0].trim();
currentUDO.outTypes = parts[1].trim();
currentUDO.inTypes = parts[2].trim();
codeBody = new StringBuffer();
state = 1;
}
}
break;
case 1:
if (line.trim().startsWith("opcode")) {
currentUDO = null;
state = 0;
} else if (line.trim().startsWith("endop")) {
currentUDO.codeBody = codeBody.toString();
retVal.add(currentUDO);
// System.out.println(currentUDO);
currentUDO = null;
state = 0;
// } else if(line.indexOf("setksmps") > -1) {
// line =
// TextUtilities.stripSingleLineComments(line.trim());
//
// String ksmpsString = line.substring(8).trim();
// int ksmps = Integer.parseInt(ksmpsString);
//
// currentUDO.useLocalKsmps = true;
// currentUDO.localKsmps = ksmps;
//
// } else if(line.indexOf("xin") > -1) {
// line =
// TextUtilities.stripSingleLineComments(line.trim());
//
// String args = line.substring(0,line.indexOf("xin"));
//
// currentUDO.inArgs = args;
//
// } else if(line.indexOf("xout") > -1) {
// line =
// TextUtilities.stripSingleLineComments(line.trim());
//
// String args = line.substring(line.indexOf("xout") +
// 4).trim();
//
// currentUDO.outArgs = args;
} else {
codeBody.append(line).append("\n");
}
break;
}
}
return retVal;
}
use of blue.udo.OpcodeList 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());
}
Aggregations