Search in sources :

Example 6 with GenericInstrument

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) Channel(blue.mixer.Channel) BufferedReader(java.io.BufferedReader) GenericInstrument(blue.orchestra.GenericInstrument) IOException(java.io.IOException)

Example 7 with GenericInstrument

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;
}
Also used : Iterator(java.util.Iterator) GenericInstrument(blue.orchestra.GenericInstrument)

Example 8 with GenericInstrument

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

Example 9 with GenericInstrument

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());
}
Also used : NoteParseException(blue.soundObject.NoteParseException) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Parameter(blue.automation.Parameter) GenericInstrument(blue.orchestra.GenericInstrument) StrBuilder(org.apache.commons.lang3.text.StrBuilder) LinePoint(blue.components.lines.LinePoint)

Example 10 with GenericInstrument

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);
    }
}
Also used : Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) TransferableInstrument(blue.TransferableInstrument) GenericInstrument(blue.orchestra.GenericInstrument) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) Point(java.awt.Point)

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