Search in sources :

Example 11 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode in project blue by kunstmusik.

the class MixerNode method applyEffects.

private static void applyEffects(EffectsChain chain, OpcodeList udos, EffectManager manager, String signalChannels, StrBuilder buffer, final int lastSendIndex, Set<String> inputSignalCache) {
    int lastIndex = lastSendIndex;
    if (lastIndex == Integer.MAX_VALUE) {
        lastIndex = chain.size() - 1;
    } else if (lastIndex < 0) {
        return;
    }
    for (int i = 0; i <= lastIndex; i++) {
        Object obj = chain.getElementAt(i);
        if (obj instanceof Effect) {
            Effect effect = (Effect) obj;
            if (effect.isEnabled()) {
                UserDefinedOpcode udo = effect.generateUDO(udos);
                udo.commentText = effect.getName();
                String effectName = udos.getNameOfEquivalentCopy(udo);
                if (effectName == null) {
                    effectName = manager.getEffectName();
                    udo.opcodeName = effectName;
                    udos.addOpcode(udo);
                }
                buffer.append(signalChannels).append("\t");
                buffer.append(effectName).append("\t");
                buffer.append(signalChannels).append("\n");
            }
        } else if (obj instanceof Send) {
            Send send = (Send) obj;
            if (send.isEnabled()) {
                String[] parts = signalChannels.split(",");
                String sendChannelName = send.getSendChannel();
                inputSignalCache.add(sendChannelName);
                for (int j = 0; j < parts.length; j++) {
                    String subVar = Mixer.getSubChannelVar(sendChannelName, j);
                    buffer.append(subVar).append("\t+=\t");
                    Parameter levelParam = send.getLevelParameter();
                    if (levelParam.isAutomationEnabled()) {
                        String compilationVarName = levelParam.getCompilationVarName();
                        buffer.append("(").append(parts[j].trim()).append(" * ");
                        buffer.append(compilationVarName).append(")\n");
                    } else if (send.getLevel() == 1.0f) {
                        buffer.append(parts[j].trim()).append("\n");
                    } else {
                        String levelStr = NumberUtilities.formatDouble(send.getLevel());
                        buffer.append("(").append(parts[j].trim()).append(" * ");
                        buffer.append(levelStr).append(")\n");
                    }
                }
            }
        }
    }
}
Also used : UserDefinedOpcode(blue.udo.UserDefinedOpcode) Parameter(blue.automation.Parameter)

Example 12 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode in project blue by kunstmusik.

the class Effect method generateUDO.

public UserDefinedOpcode generateUDO(OpcodeList udoList) {
    HashMap udoReplacementValues = UDOUtilities.appendUserDefinedOpcodes(opcodeList, udoList);
    UserDefinedOpcode udo = new UserDefinedOpcode();
    BSBCompilationUnit bsbUnit = new BSBCompilationUnit();
    graphicInterface.setupForCompilation(bsbUnit);
    StrBuilder buffer = new StrBuilder();
    buffer.append(getXinText()).append("\n");
    buffer.append(bsbUnit.replaceBSBValues(code)).append("\n");
    buffer.append(getXoutText()).append("\n");
    String udoCode = buffer.toString();
    if (udoReplacementValues != null) {
        udoCode = TextUtilities.replaceOpcodeNames(udoReplacementValues, udoCode);
    }
    udo.codeBody = udoCode;
    udo.inTypes = getSigTypes(numIns);
    udo.outTypes = getSigTypes(numOuts);
    return udo;
}
Also used : HashMap(java.util.HashMap) UserDefinedOpcode(blue.udo.UserDefinedOpcode) BSBCompilationUnit(blue.orchestra.blueSynthBuilder.BSBCompilationUnit) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 13 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode 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 14 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode 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)

Example 15 with UserDefinedOpcode

use of blue.udo.UserDefinedOpcode in project blue by kunstmusik.

the class OpcodeListEditPanel method copyUDO.

protected void copyUDO() {
    UserDefinedOpcode[] udos = getSelectedUDOs();
    if (udos != null) {
        UserDefinedOpcode[] copies = new UserDefinedOpcode[udos.length];
        for (int i = 0; i < udos.length; i++) {
            copies[i] = new UserDefinedOpcode(udos[i]);
        }
        UDOBuffer.getInstance().setBufferedObject(copies);
    }
}
Also used : UserDefinedOpcode(blue.udo.UserDefinedOpcode) Point(java.awt.Point)

Aggregations

UserDefinedOpcode (blue.udo.UserDefinedOpcode)22 UDOCategory (blue.udo.UDOCategory)6 Point (java.awt.Point)6 IOException (java.io.IOException)4 File (java.io.File)3 TreePath (javax.swing.tree.TreePath)3 OpcodeList (blue.udo.OpcodeList)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 Arrangement (blue.Arrangement)1 Parameter (blue.automation.Parameter)1 GenericInstrument (blue.orchestra.GenericInstrument)1 BSBCompilationUnit (blue.orchestra.blueSynthBuilder.BSBCompilationUnit)1 UDOLibrary (blue.udo.UDOLibrary)1 Document (electric.xml.Document)1 Element (electric.xml.Element)1 ParseException (electric.xml.ParseException)1 Rectangle (java.awt.Rectangle)1