Search in sources :

Example 1 with OpcodeList

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

the class MixerNodeTest method testGetMixerCode4.

// public void testGetMixerCode() {
// CompileData data = CompileData.createEmptyCompileData();
// Mixer mixer = getTestMixer(1, 1);
// 
// mixer.getChannel(0).setLevel(-96.0f);
// mixer.getSubChannel(0).setLevel(-96.0f);
// 
// OpcodeList opcodeList = new OpcodeList();
// EffectManager manager = new EffectManager();
// int nchnls = 2;
// 
// MixerNode node = MixerNode.getMixerGraph(mixer);
// Send[] allSends = mixer.getAllSends();
// 
// assignChannelIds(data, mixer);
// 
// String output = MixerNode.getMixerCode(data, mixer, opcodeList, manager,
// node, nchnls);
// 
// assertEquals("", output);
// }
/**
 * Should *not* output any signals (channel must look ahead when doing sends
 * to see if it will hit master or be a dead end)
 */
// public void testGetMixerCode2() {
// 
// CompileData data = CompileData.createEmptyCompileData();
// Send send = new Send();
// send.setSendChannel("subChannel1");
// 
// Mixer mixer = getTestMixer(1, 1);
// mixer.getChannel(0).setLevel(-96.0f);
// mixer.getChannel(0).getPreEffects().addSend(send);
// mixer.getSubChannel(0).setLevel(-96.0f);
// 
// OpcodeList opcodeList = new OpcodeList();
// EffectManager manager = new EffectManager();
// int nchnls = 2;
// 
// MixerNode node = MixerNode.getMixerGraph(mixer);
// 
// assignChannelIds(data, mixer);
// 
// String out = MixerNode.getMixerCode(data, mixer, opcodeList, manager, node,
// nchnls);
// 
// assertEquals("", out);
// }
// /**
// * Should output channel1->send->subChannel1->mixer; subchannel2 is dead end
// *
// */
// public void testGetMixerCode3() {
// 
// CompileData data = CompileData.createEmptyCompileData();
// Send send = new Send();
// send.setSendChannel("subChannel1");
// 
// Mixer mixer = getTestMixer(1, 2);
// mixer.getChannel(0).getPostEffects().addSend(send);
// mixer.getChannel(0).setOutChannel("subChannel2");
// 
// mixer.getSubChannel(1).setLevel(-96.0f);
// 
// OpcodeList opcodeList = new OpcodeList();
// EffectManager manager = new EffectManager();
// int nchnls = 2;
// 
// MixerNode node = MixerNode.getMixerGraph(mixer);
// assignChannelIds(data, mixer);
// 
// String out = MixerNode.getMixerCode(data, mixer, opcodeList, manager, node,
// nchnls);
// 
// String expected = "ga_bluesub_subChannel1_0\t+=\tga_bluemix_0_0\n"
// + "ga_bluesub_subChannel1_1\t+=\tga_bluemix_0_1\n"
// + "ga_bluesub_Master_0\t+=\tga_bluesub_subChannel1_0\n"
// + "ga_bluesub_Master_1\t+=\tga_bluesub_subChannel1_1\n";
// 
// assertEquals(expected, out);
// }
public void testGetMixerCode4() {
    CompileData data = CompileData.createEmptyCompileData();
    Mixer mixer = getTestMixer(3, 2);
    mixer.getChannel(1).setOutChannel("subChannel1");
    mixer.getChannel(2).setOutChannel("subChannel1");
    OpcodeList opcodeList = new OpcodeList();
    EffectManager manager = new EffectManager();
    int nchnls = 2;
    MixerNode node = MixerNode.getMixerGraph(mixer);
    assignChannelIds(data, mixer);
    String out = MixerNode.getMixerCode(data, mixer, opcodeList, manager, node, nchnls);
    String expected = "ga_bluesub_subChannel1_0\t+=\tga_bluemix_1_0\n" + "ga_bluesub_subChannel1_1\t+=\tga_bluemix_1_1\n" + "ga_bluesub_subChannel1_0\t+=\tga_bluemix_2_0\n" + "ga_bluesub_subChannel1_1\t+=\tga_bluemix_2_1\n" + "ga_bluesub_Master_0\t+=\tga_bluemix_0_0\n" + "ga_bluesub_Master_1\t+=\tga_bluemix_0_1\n" + "ga_bluesub_Master_0\t+=\tga_bluesub_subChannel1_0\n" + "ga_bluesub_Master_1\t+=\tga_bluesub_subChannel1_1\n";
    assertEquals(expected, out);
}
Also used : OpcodeList(blue.udo.OpcodeList) CompileData(blue.CompileData)

Example 2 with OpcodeList

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

the class BlueData method loadFromXML.

public static BlueData loadFromXML(Element data) throws Exception {
    UpgradeManager.getInstance().performUpgrades(data);
    BlueData blueData = new BlueData();
    Map<String, Object> objRefMap = new HashMap<>();
    Elements nodes = data.getElements();
    Element instrumentLibraryNode = null;
    Element arrangementNode = null;
    Mixer m = null;
    Attribute versionAttribute = data.getAttribute("version");
    if (versionAttribute != null) {
        blueData.setVersion(versionAttribute.getValue());
    }
    BlueDataObjectManager bdoManager = Lookup.getDefault().lookup(BlueDataObjectManager.class);
    while (nodes.hasMoreElements()) {
        Element node = nodes.next();
        String nodeName = node.getName();
        switch(nodeName) {
            case "projectProperties":
                blueData.projectProperties = ProjectProperties.loadFromXML(node);
                break;
            case "instrumentLibrary":
                instrumentLibraryNode = node;
                break;
            case "arrangement":
                arrangementNode = node;
                break;
            case "mixer":
                m = Mixer.loadFromXML(node);
                break;
            case "tables":
                blueData.tableSet = Tables.loadFromXML(node);
                break;
            case "soundObjectLibrary":
                blueData.sObjLib = SoundObjectLibrary.loadFromXML(node, objRefMap);
                break;
            case "globalOrcSco":
                blueData.globalOrcSco = GlobalOrcSco.loadFromXML(node);
                break;
            case "udo":
                {
                    // blueData.setUserDefinedOpcodes(node.getTextString());
                    String udoText = node.getTextString();
                    if (udoText == null) {
                        udoText = "";
                    }
                    OpcodeList results = UDOUtilities.parseUDOText(udoText);
                    blueData.setOpcodeList(results);
                    break;
                }
            case "opcodeList":
                {
                    OpcodeList results = OpcodeList.loadFromXML(node);
                    blueData.setOpcodeList(results);
                    break;
                }
            case "liveData":
                blueData.liveData = LiveData.loadFromXML(node, objRefMap);
                break;
            case "score":
                blueData.score = Score.loadFromXML(node, objRefMap);
                break;
            case "scratchPadData":
                blueData.scratchData = ScratchPadData.loadFromXML(node);
                break;
            case "noteProcessorChainMap":
                blueData.noteProcessorChainMap = NoteProcessorChainMap.loadFromXML(node);
                break;
            case "renderStartTime":
                blueData.setRenderStartTime(Double.parseDouble(node.getTextString()));
                break;
            case "renderEndTime":
                blueData.setRenderEndTime(Double.parseDouble(node.getTextString()));
                break;
            case "markersList":
                blueData.setMarkersList(MarkersList.loadFromXML(node));
                break;
            case "loopRendering":
                blueData.setLoopRendering(node.getTextString().equalsIgnoreCase("true"));
                break;
            case "midiInputProcessor":
                blueData.midiInputProcessor = MidiInputProcessor.loadFromXML(node);
                break;
            case "pluginData":
                Elements pluginElems = node.getElements();
                while (pluginElems.hasMoreElements()) {
                    blueData.pluginData.add(bdoManager.loadFromXML(pluginElems.next()));
                }
                break;
        }
    }
    if (instrumentLibraryNode != null) {
        InstrumentLibrary instrumentLibrary = InstrumentLibrary.loadFromXML(instrumentLibraryNode);
        blueData.arrangement = Arrangement.loadFromXML(arrangementNode, instrumentLibrary);
    } else {
        blueData.arrangement = Arrangement.loadFromXML(arrangementNode);
    }
    if (m != null) {
        blueData.mixer = m;
    } else {
        blueData.mixer.setEnabled(false);
    }
    return blueData;
}
Also used : BlueDataObjectManager(blue.data.BlueDataObjectManager) Attribute(electric.xml.Attribute) OpcodeList(blue.udo.OpcodeList) Element(electric.xml.Element) Mixer(blue.mixer.Mixer) Elements(electric.xml.Elements)

Example 3 with OpcodeList

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

the class Effect method loadFromXML.

public static Effect loadFromXML(Element data) throws Exception {
    Effect effect = new Effect(false);
    Elements nodes = data.getElements();
    while (nodes.hasMoreElements()) {
        Element node = nodes.next();
        String nodeName = node.getName();
        switch(nodeName) {
            case "name":
                effect.setName(node.getTextString());
                break;
            case "enabled":
                effect.setEnabled(XMLUtilities.readBoolean(node));
                break;
            case "numIns":
                effect.setNumIns(XMLUtilities.readInt(node));
                break;
            case "numOuts":
                effect.setNumOuts(XMLUtilities.readInt(node));
                break;
            case "code":
                effect.setCode(node.getTextString());
                break;
            case "comments":
                effect.setComments(node.getTextString());
                break;
            case "opcodeList":
                effect.opcodeList = OpcodeList.loadFromXML(node);
                break;
            case "graphicInterface":
                effect.setGraphicInterface(BSBGraphicInterface.loadFromXML(node));
                break;
            case "bsbParameterList":
            case "parameterList":
                effect.parameterList = (ParameterList) ParameterList.loadFromXML(node);
                break;
        }
    }
    if (effect.opcodeList == null) {
        effect.opcodeList = new OpcodeList();
    }
    if (effect.graphicInterface == null) {
        effect.graphicInterface = new BSBGraphicInterface();
    }
    if (effect.parameterList == null) {
        effect.parameterList = new ParameterList();
    }
    effect.graphicInterface.getRootGroup().setParameterList(effect.parameterList);
    return effect;
}
Also used : BSBGraphicInterface(blue.orchestra.blueSynthBuilder.BSBGraphicInterface) OpcodeList(blue.udo.OpcodeList) Element(electric.xml.Element) ParameterList(blue.automation.ParameterList) Elements(electric.xml.Elements)

Example 4 with OpcodeList

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

the class CSDRender method generateCSDImpl.

@Override
protected CsdRenderResult generateCSDImpl(BlueData data, double startTime, double endTime, boolean isRealTime, boolean _usingAPI) {
    ProjectPluginManager.getInstance().preRender(data);
    StringChannelNameManager scnm = new StringChannelNameManager();
    ParameterNameManager pnm = new ParameterNameManager();
    ArrayList<StringChannel> stringChannels = getStringChannels(data.getArrangement(), scnm);
    ParameterHelper.clearCompilationVarNames(data);
    boolean usingAPI = isRealTime && _usingAPI;
    double renderStartTime = data.getRenderStartTime();
    // making copies to use for adding compileTime tables and instruments
    Tables tables = new Tables(data.getTableSet());
    ArrayList originalParameters;
    // if (usingAPI) {
    originalParameters = ParameterHelper.getAllParameters(data.getArrangement(), data.getMixer());
    // } else {
    // originalParameters = ParameterHelper.getActiveParameters(
    // data.getArrangement(), data.getMixer());
    // }
    assignParameterNames(originalParameters, pnm);
    Arrangement arrangement = new Arrangement(data.getArrangement());
    arrangement.clearUnusedInstrAssignments();
    boolean hasInstruments = arrangement.size() > 0;
    CompileData compileData = new CompileData(arrangement, tables, stringChannels, originalParameters, scnm, pnm);
    Mixer mixer = null;
    boolean mixerEnabled = data.getMixer().isEnabled();
    if (mixerEnabled) {
        mixer = new Mixer(data.getMixer());
        assignChannelIds(compileData, mixer);
    }
    NoteList generatedNotes;
    try {
        generatedNotes = data.getScore().generateForCSD(compileData, startTime, endTime);
    } catch (ScoreGenerationException ex) {
        throw new RuntimeException(ex);
    }
    compileData.setHandleParametersAndChannels(false);
    // assignParameterNames(originalParameters);
    // get parameters
    // ArrayList parameters;
    // if (usingAPI) {
    // parameters = ParameterHelper.getAllParameters(
    // arrangement, mixer);
    // } else {
    // parameters = ParameterHelper.getActiveParameters(
    // arrangement, mixer);
    // }
    GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
    OpcodeList udos = new OpcodeList(data.getOpcodeList());
    // add all UDO's from instruments and effects
    arrangement.generateUserDefinedOpcodes(udos);
    // adding all compile-time instruments from soundObjects to arrangement
    appendFtgenTableNumbers(globalOrcSco.getGlobalOrc(), tables);
    // generating ftables
    arrangement.generateFTables(tables);
    String ftables = tables.getTables();
    // Handle Render End Instrument and Note
    if (endTime > 0.0f && endTime > startTime) {
        Instrument instr = createRenderEndInstrument();
        int instrId = arrangement.addInstrument(instr);
        double endStartTime = endTime - startTime;
        try {
            Note renderEndNote = Note.createNote("i" + instrId + " " + endStartTime + " 0.1");
            generatedNotes.add(renderEndNote);
        } catch (NoteParseException e1) {
        }
    }
    Tempo tempo = data.getScore().getTempo();
    TempoMapper tempoMapper = null;
    if (tempo.isEnabled()) {
        tempoMapper = getTempoMapper(tempo);
        globalOrcSco.appendGlobalSco(getTempoScore(tempo, renderStartTime, endTime));
    } else {
        tempoMapper = getTempoMapper(globalOrcSco.getGlobalSco());
    }
    double totalDur = blue.utility.ScoreUtilities.getTotalDuration(generatedNotes);
    // double processingStart = blue.utility.ScoreUtilities.getProcessingStartTime(
    // tempPObj);
    // FIXME - figure out what to do about PROCESSING_START
    double processingStart = renderStartTime;
    System.out.println("<TOTAL_DUR> = " + totalDur);
    System.out.println("<RENDER_START> = " + renderStartTime);
    System.out.println("<PROCESSING_START> = " + processingStart);
    int nchnls = getNchnls(data, isRealTime);
    ArrayList<Instrument> alwaysOnInstruments = new ArrayList<>();
    // boolean generateMixer = mixerEnabled && (hasInstruments || mixer.hasSubChannelDependencies());
    arrangement.preGenerateOrchestra(compileData, mixer, nchnls, alwaysOnInstruments);
    String globalSco = globalOrcSco.getGlobalSco() + "\n";
    globalSco += arrangement.generateGlobalSco(compileData) + "\n";
    globalSco = preprocessSco(globalSco, totalDur, renderStartTime, processingStart, tempoMapper);
    double globalDur;
    try {
        globalDur = getGlobalDuration(globalSco);
    } catch (SoundObjectException ex) {
        throw new RuntimeException(ex);
    }
    if (globalDur < totalDur) {
        globalDur = totalDur;
    }
    System.out.println("Global Duration = " + globalDur);
    if (mixerEnabled) {
        globalDur += mixer.getExtraRenderTime();
    }
    for (Instrument instrument : alwaysOnInstruments) {
        String sourceId = compileData.getInstrSourceId(instrument);
        String noteStr;
        if (StringUtils.isNumeric(sourceId)) {
            int instrId = arrangement.addInstrumentAtEnd(instrument);
            noteStr = "i" + instrId + " 0 " + totalDur;
        } else {
            String instrId = sourceId + "_alwaysOn";
            arrangement.addInstrumentWithId(instrument, instrId, false);
            noteStr = "i \"" + instrId + "\" 0 " + totalDur;
        }
        try {
            Note n = Note.createNote(noteStr);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    if (mixerEnabled) {
        final String mixerId = "BlueMixer";
        // globalDur += mixer.getExtraRenderTime();
        clearUnusedMixerChannels(mixer, arrangement);
        globalOrcSco.appendGlobalOrc(mixer.getInitStatements(compileData, nchnls) + "\n");
        arrangement.addInstrumentWithId(mixer.getMixerInstrument(compileData, udos, nchnls), mixerId, false);
        try {
            Note n = Note.createNote("i \"BlueMixer\" 0 " + globalDur);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    handleParameters(originalParameters, stringChannels, globalOrcSco, generatedNotes, arrangement, startTime, startTime + globalDur, isRealTime, _usingAPI);
    if (isRealTime && !usingAPI) {
        Instrument instr = createBlueTimePointerInstrument();
        int instrId = arrangement.addInstrument(instr);
        try {
            Note n = Note.createNote("i" + instrId + " 0 " + globalDur);
            generatedNotes.add(n);
        } catch (NoteParseException ex) {
            ex.printStackTrace();
        }
    }
    String tempGlobalOrc = compileData.getGlobalOrc();
    if (tempGlobalOrc != null && tempGlobalOrc.length() > 0) {
        globalOrcSco.appendGlobalOrc(tempGlobalOrc);
    }
    StrBuilder csd = new StrBuilder();
    appendProjectInfo(data, csd);
    csd.append("<CsoundSynthesizer>\n\n");
    appendCsInstruments(compileData, data, udos, arrangement, globalOrcSco, csd, mixer, isRealTime);
    appendCsScore(globalSco, ftables, generatedNotes, totalDur, csd);
    csd.append("</CsoundSynthesizer>");
    CsdRenderResult renderResult = new CsdRenderResult(csd.toString(), tempoMapper, originalParameters, stringChannels);
    return renderResult;
}
Also used : GlobalOrcSco(blue.GlobalOrcSco) NoteList(blue.soundObject.NoteList) NoteParseException(blue.soundObject.NoteParseException) Mixer(blue.mixer.Mixer) ArrayList(java.util.ArrayList) SoundObjectException(blue.soundObject.SoundObjectException) Tables(blue.Tables) CompileData(blue.CompileData) StrBuilder(org.apache.commons.lang3.text.StrBuilder) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Arrangement(blue.Arrangement) LinePoint(blue.components.lines.LinePoint) TempoMapper(blue.noteProcessor.TempoMapper) Tempo(blue.score.tempo.Tempo) ParameterNameManager(blue.automation.ParameterNameManager) ScoreGenerationException(blue.score.ScoreGenerationException) OpcodeList(blue.udo.OpcodeList) StringChannelNameManager(blue.orchestra.blueSynthBuilder.StringChannelNameManager) Note(blue.soundObject.Note) Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 5 with OpcodeList

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

the class UserDefinedOpcodeTopComponent method reinitialize.

private void reinitialize() {
    BlueProject project = BlueProjectManager.getInstance().getCurrentProject();
    if (project == null) {
        opcodeListEditPanel1.setOpcodeList(null);
    } else {
        OpcodeList opcodeList = project.getData().getOpcodeList();
        opcodeListEditPanel1.setOpcodeList(opcodeList);
    }
}
Also used : OpcodeList(blue.udo.OpcodeList) BlueProject(blue.projects.BlueProject)

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