Search in sources :

Example 11 with GenericInstrument

use of blue.orchestra.GenericInstrument in project blue by kunstmusik.

the class AbstractLineObject method generateInstruments.

public void generateInstruments(CompileData compileData, Integer[] instrLineArray, HashMap ftableNumMap) {
    int i = 0;
    for (Iterator iter = lines.iterator(); iter.hasNext(); ) {
        Line line = (Line) iter.next();
        String lineName;
        if (line.isZak()) {
            lineName = "zak" + line.getChannel();
        } else {
            lineName = line.getVarName();
        }
        String lineId = line.getUniqueID();
        String key = "AbstractLineObject." + lineName;
        Object val = compileData.getCompilationVariable(key);
        int instrNum = -1;
        Integer lineNum = (Integer) ftableNumMap.get(lineId);
        if (val == null) {
            String instrText = generateLineInstrument(line);
            GenericInstrument instr = new GenericInstrument();
            instr.setText(instrText);
            instrNum = compileData.addInstrument(instr);
            compileData.setCompilationVariable(key, new Integer(instrNum));
        } else {
            instrNum = ((Integer) val).intValue();
        }
        instrLineArray[i++] = new Integer(instrNum);
        instrLineArray[i++] = lineNum;
    }
}
Also used : Line(blue.components.lines.Line) Iterator(java.util.Iterator) GenericInstrument(blue.orchestra.GenericInstrument) LinePoint(blue.components.lines.LinePoint)

Example 12 with GenericInstrument

use of blue.orchestra.GenericInstrument 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 13 with GenericInstrument

use of blue.orchestra.GenericInstrument in project blue by kunstmusik.

the class CSDRender method createAllNotesOffInstrument.

protected Instrument createAllNotesOffInstrument(String[] instrIds) {
    GenericInstrument instr = new GenericInstrument();
    StrBuilder buffer = new StrBuilder();
    buffer.append("koff init 0\n" + "if (koff == 0) then\n");
    for (int i = 0; i < instrIds.length; i++) {
        String id = instrIds[i];
        String[] parts = StringUtils.split(id, ",");
        for (int j = 0; j < parts.length; j++) {
            String tempId = parts[j];
            try {
                int instrIdNum = Integer.parseInt(tempId.trim());
                buffer.append("turnoff2 ").append(instrIdNum);
                buffer.append(", 0, 1\n");
            } catch (NumberFormatException nfe) {
                buffer.append("insno").append(i).append(j);
                buffer.append(" nstrnum \"").append(tempId).append("\"\n");
                buffer.append("turnoff2 insno").append(i).append(j);
                buffer.append(", 0, 1\n");
            }
        }
    }
    buffer.append("koff = 1\nelse\nturnoff\nendif\n");
    instr.setText(buffer.toString());
    return instr;
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder) LinePoint(blue.components.lines.LinePoint)

Example 14 with GenericInstrument

use of blue.orchestra.GenericInstrument in project blue by kunstmusik.

the class CSDRender method createBlueTimePointerInstrument.

private Instrument createBlueTimePointerInstrument() {
    GenericInstrument instr = new GenericInstrument();
    int fps = PlaybackSettings.getInstance().getPlaybackFPS();
    double time = 1.0f / fps;
    String instrText = "ktime	times\n" + "printks \"blueTimePointer=%f\\\\n\", " + time + ", ktime";
    instr.setText(instrText);
    return instr;
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) LinePoint(blue.components.lines.LinePoint)

Example 15 with GenericInstrument

use of blue.orchestra.GenericInstrument in project blue by kunstmusik.

the class CSDRender method getParameterInstrument.

private GenericInstrument getParameterInstrument(Parameter param) {
    GenericInstrument instr = new GenericInstrument();
    instr.setName("Param: " + param.getName());
    StrBuilder buffer = new StrBuilder();
    String compilationVarName = param.getCompilationVarName();
    if (param.getResolution().doubleValue() > 0.0f) {
        buffer.append(compilationVarName);
        buffer.append(" init p4\nturnoff");
    } else {
        buffer.append("if (p4 == p5) then\n");
        buffer.append(compilationVarName);
        buffer.append(" init p4\nturnoff\nelse\n");
        buffer.append(compilationVarName);
        buffer.append(" line p4, p3, p5\nendif");
    }
    instr.setText(buffer.toString());
    return instr;
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Aggregations

GenericInstrument (blue.orchestra.GenericInstrument)17 LinePoint (blue.components.lines.LinePoint)4 StrBuilder (org.apache.commons.lang3.text.StrBuilder)4 Instrument (blue.orchestra.Instrument)3 Iterator (java.util.Iterator)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 Arrangement (blue.Arrangement)1 TransferableInstrument (blue.TransferableInstrument)1 Parameter (blue.automation.Parameter)1 Line (blue.components.lines.Line)1 Channel (blue.mixer.Channel)1 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)1 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)1 NoteParseException (blue.soundObject.NoteParseException)1 OpcodeList (blue.udo.OpcodeList)1 UserDefinedOpcode (blue.udo.UserDefinedOpcode)1 Point (java.awt.Point)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1