Search in sources :

Example 6 with OpcodeList

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);
            }
        }
    }
}
Also used : OpcodeList(blue.udo.OpcodeList) File(java.io.File) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ParseException(electric.xml.ParseException) IOException(java.io.IOException)

Example 7 with OpcodeList

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"));
    }
}
Also used : BlueData(blue.BlueData) GlobalOrcSco(blue.GlobalOrcSco) NoteList(blue.soundObject.NoteList) OpcodeList(blue.udo.OpcodeList) Tables(blue.Tables) Arrangement(blue.Arrangement) PolyObject(blue.soundObject.PolyObject) CompileData(blue.CompileData)

Example 8 with OpcodeList

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;
}
Also used : OpcodeList(blue.udo.OpcodeList) Element(electric.xml.Element) ParameterList(blue.automation.ParameterList) Elements(electric.xml.Elements)

Example 9 with OpcodeList

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;
}
Also used : StringTokenizer(java.util.StringTokenizer) OpcodeList(blue.udo.OpcodeList) UserDefinedOpcode(blue.udo.UserDefinedOpcode)

Example 10 with OpcodeList

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());
}
Also used : UserDefinedOpcode(blue.udo.UserDefinedOpcode) OpcodeList(blue.udo.OpcodeList) GenericInstrument(blue.orchestra.GenericInstrument) Arrangement(blue.Arrangement)

Aggregations

OpcodeList (blue.udo.OpcodeList)12 Arrangement (blue.Arrangement)4 CompileData (blue.CompileData)4 GlobalOrcSco (blue.GlobalOrcSco)3 Tables (blue.Tables)3 Mixer (blue.mixer.Mixer)3 GenericInstrument (blue.orchestra.GenericInstrument)3 NoteList (blue.soundObject.NoteList)3 Element (electric.xml.Element)3 Elements (electric.xml.Elements)3 ParameterList (blue.automation.ParameterList)2 ParameterNameManager (blue.automation.ParameterNameManager)2 LinePoint (blue.components.lines.LinePoint)2 TempoMapper (blue.noteProcessor.TempoMapper)2 Instrument (blue.orchestra.Instrument)2 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)2 StringChannelNameManager (blue.orchestra.blueSynthBuilder.StringChannelNameManager)2 CsdRenderResult (blue.services.render.CsdRenderResult)2 UserDefinedOpcode (blue.udo.UserDefinedOpcode)2 ArrayList (java.util.ArrayList)2