Search in sources :

Example 26 with Instrument

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

the class UserInstrumentTreePopup method getAddInstrumentMenu.

private JMenu getAddInstrumentMenu() {
    JMenu instrumentMenu = new JMenu("Add Instrument");
    List<LazyPlugin<Instrument>> plugins = LazyPluginFactory.loadPlugins("blue/instruments", Instrument.class);
    JMenuItem temp;
    this.setLabel("Add Instrument");
    ActionListener al = (ActionEvent e) -> {
        LazyPlugin<Instrument> plugin = (LazyPlugin<Instrument>) ((JMenuItem) e.getSource()).getClientProperty("plugin");
        Instrument instrTemplate = plugin.getInstance();
        try {
            Instrument newInstrument = instrTemplate.getClass().newInstance();
            addInstrument(newInstrument);
        } catch (InstantiationException | IllegalAccessException ex) {
            Exceptions.printStackTrace(ex);
        }
    };
    for (LazyPlugin<Instrument> plugin : plugins) {
        temp = new JMenuItem();
        temp.setText(plugin.getDisplayName());
        temp.putClientProperty("plugin", plugin);
        temp.addActionListener(al);
        instrumentMenu.add(temp);
    }
    return instrumentMenu;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Instrument(blue.orchestra.Instrument) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) LazyPlugin(blue.ui.nbutilities.lazyplugin.LazyPlugin)

Example 27 with Instrument

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

the class UserInstrumentTreePopup method getSelectedInstrument.

public Instrument getSelectedInstrument() {
    TreePath selectionPath = libraryTree.getSelectionPath();
    if (selectionPath == null) {
        return null;
    }
    Object obj = selectionPath.getLastPathComponent();
    if (obj instanceof Instrument) {
        return (Instrument) obj;
    }
    return null;
}
Also used : TreePath(javax.swing.tree.TreePath) Instrument(blue.orchestra.Instrument)

Example 28 with Instrument

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

the class InstrumentTreeDropTarget method drop.

@Override
public void drop(DropTargetDropEvent dtde) {
    Point pt = dtde.getLocation();
    DropTargetContext dtc = dtde.getDropTargetContext();
    JTree tree = (JTree) dtc.getComponent();
    TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y);
    Object node = parentpath.getLastPathComponent();
    if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_CAT_FLAVOR)) {
        if (!(node instanceof InstrumentCategory)) {
            dtde.rejectDrop();
            return;
        }
        if (dtde.getDropAction() == DnDConstants.ACTION_MOVE) {
            dtde.acceptDrop(dtde.getDropAction());
            Transferable tr = dtde.getTransferable();
            try {
                Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_CAT_FLAVOR);
                InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
                InstrumentCategory parentNode = (InstrumentCategory) node;
                InstrumentCategory instrumentCategory = (InstrumentCategory) transferNode;
                // iLibrary.removeCategory(instrumentCategory);
                iLibrary.addCategory(parentNode, instrumentCategory);
                dtde.dropComplete(true);
            } catch (UnsupportedFlavorException | IOException e) {
                dtde.dropComplete(false);
            }
        } else {
            dtde.rejectDrop();
        }
    } else if (dtde.isDataFlavorSupported(TransferableInstrument.INSTR_FLAVOR)) {
        dtde.acceptDrop(dtde.getDropAction());
        try {
            Transferable tr = dtde.getTransferable();
            Object transferNode = tr.getTransferData(TransferableInstrument.INSTR_FLAVOR);
            Instrument instrument = (Instrument) transferNode;
            InstrumentLibrary iLibrary = (InstrumentLibrary) tree.getModel();
            if (instrument instanceof BlueSynthBuilder) {
                ((BlueSynthBuilder) instrument).clearParameters();
            }
            // iLibrary.removeInstrument(instrument);
            if (node instanceof InstrumentCategory) {
                InstrumentCategory parentNode = (InstrumentCategory) node;
                iLibrary.addInstrument(parentNode, instrument);
            } else if (node instanceof Instrument) {
                InstrumentCategory parentNode = (InstrumentCategory) parentpath.getPathComponent(parentpath.getPathCount() - 2);
                int index = ListUtil.indexOfByRef(parentNode.getInstruments(), node);
                int closestRow = tree.getClosestRowForLocation(pt.x, pt.y);
                Rectangle bounds = tree.getRowBounds(closestRow);
                if (pt.y > bounds.y + bounds.height) {
                    iLibrary.addInstrument(parentNode, instrument);
                } else {
                    iLibrary.addInstrument(parentNode, index, instrument);
                }
            }
            dtde.dropComplete(true);
        } catch (UnsupportedFlavorException | IOException e) {
            dtde.dropComplete(false);
        }
    } else {
        dtde.rejectDrop();
    }
}
Also used : DropTargetContext(java.awt.dnd.DropTargetContext) Transferable(java.awt.datatransfer.Transferable) Rectangle(java.awt.Rectangle) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) InstrumentLibrary(blue.InstrumentLibrary) Instrument(blue.orchestra.Instrument) InstrumentCategory(blue.orchestra.InstrumentCategory)

Example 29 with Instrument

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

the class CSDRender method generateCSDForBlueLiveImpl.

@Override
protected synchronized CsdRenderResult generateCSDForBlueLiveImpl(BlueData data, boolean usingAPI) {
    ProjectPluginManager.getInstance().preRender(data);
    StringChannelNameManager scnm = new StringChannelNameManager();
    ArrayList<StringChannel> stringChannels = getStringChannels(data.getArrangement(), scnm);
    ParameterHelper.clearCompilationVarNames(data);
    double totalDur = 36000f;
    // making copies to use for adding compileTime tables and instruments
    Tables tables = new Tables(data.getTableSet());
    ArrayList<Parameter> originalParameters = null;
    if (usingAPI) {
        originalParameters = ParameterHelper.getAllParameters(data.getArrangement(), data.getMixer());
        assignParameterNames(originalParameters, new ParameterNameManager());
    }
    Arrangement arrangement = new Arrangement(data.getArrangement());
    arrangement.clearUnusedInstrAssignments();
    String[] instrIds = arrangement.getInstrumentIds();
    // PolyObject tempPObj = (PolyObject) data.getPolyObject().clone();
    boolean hasInstruments = arrangement.size() > 0;
    GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
    OpcodeList udos = new OpcodeList(data.getOpcodeList());
    // add all UDO's from instruments and effects
    arrangement.generateUserDefinedOpcodes(udos);
    appendFtgenTableNumbers(globalOrcSco.getGlobalOrc(), tables);
    arrangement.generateFTables(tables);
    CompileData compileData = new CompileData(arrangement, tables);
    // SKIPPING ANYTHING RELATED TO SCORE
    boolean mixerEnabled = data.getMixer().isEnabled();
    Mixer mixer = null;
    if (mixerEnabled) {
        mixer = new Mixer(data.getMixer());
        assignChannelIds(compileData, mixer);
    }
    boolean generateMixer = mixerEnabled && (hasInstruments || mixer.hasSubChannelDependencies());
    int nchnls = getNchnls(data, true);
    ArrayList<Instrument> alwaysOnInstruments = new ArrayList<>();
    arrangement.preGenerateOrchestra(compileData, mixer, nchnls, alwaysOnInstruments);
    String globalSco = globalOrcSco.getGlobalSco() + "\n";
    globalSco += arrangement.generateGlobalSco(compileData) + "\n";
    globalSco = preprocessSco(globalSco, totalDur, 0, 0, null);
    NoteList generatedNotes = null;
    for (Instrument instrument : alwaysOnInstruments) {
        String sourceId = compileData.getInstrSourceId(instrument);
        if (StringUtils.isNumeric(sourceId)) {
            int instrId = arrangement.addInstrumentAtEnd(instrument);
            globalSco += "i" + instrId + " 0 " + totalDur + "\n";
        } else {
            String instrId = sourceId + "_alwaysOn";
            arrangement.addInstrumentWithId(instrument, instrId, false);
            globalSco += "i \"" + instrId + "\" 0 " + totalDur + "\n";
        }
    }
    if (usingAPI) {
        // ArrayList parameters = ParameterHelper.getAllParameters(
        // arrangement, mixer);
        generatedNotes = new NoteList();
        handleParametersForBlueLive(originalParameters, stringChannels, globalOrcSco, generatedNotes, arrangement, usingAPI);
    }
    if (generateMixer) {
        final String mixerId = "BlueMixer";
        clearUnusedMixerChannels(mixer, arrangement);
        globalOrcSco.appendGlobalOrc(mixer.getInitStatements(compileData, nchnls));
        arrangement.addInstrumentWithId(mixer.getMixerInstrument(compileData, udos, nchnls), mixerId, false);
        globalSco += "i \"BlueMixer\" 0 " + totalDur;
    }
    arrangement.addInstrument("blueAllNotesOff", createAllNotesOffInstrument(instrIds));
    String ftables = tables.getTables();
    StrBuilder score = new StrBuilder();
    score.append("<CsoundSynthesizer>\n\n");
    appendCsInstruments(compileData, data, udos, arrangement, globalOrcSco, score, mixer, true);
    appendCsScore(globalSco, ftables, generatedNotes, totalDur, score);
    score.append("</CsoundSynthesizer>");
    // Tempo tempo = data.getScore().getTempo();
    TempoMapper tempoMapper = null;
    // if (tempo.isEnabled()) {
    // tempoMapper = CSDRender.getTempoMapper(tempo);
    // } else {
    // tempoMapper = CSDRender.getTempoMapper(globalSco);
    // }
    CsdRenderResult renderResult = new CsdRenderResult(score.toString(), tempoMapper, originalParameters, stringChannels);
    return renderResult;
}
Also used : GlobalOrcSco(blue.GlobalOrcSco) NoteList(blue.soundObject.NoteList) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) Mixer(blue.mixer.Mixer) ArrayList(java.util.ArrayList) Arrangement(blue.Arrangement) LinePoint(blue.components.lines.LinePoint) TempoMapper(blue.noteProcessor.TempoMapper) ParameterNameManager(blue.automation.ParameterNameManager) OpcodeList(blue.udo.OpcodeList) StringChannelNameManager(blue.orchestra.blueSynthBuilder.StringChannelNameManager) Instrument(blue.orchestra.Instrument) GenericInstrument(blue.orchestra.GenericInstrument) Tables(blue.Tables) Parameter(blue.automation.Parameter) CompileData(blue.CompileData) StrBuilder(org.apache.commons.lang3.text.StrBuilder) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 30 with Instrument

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

the class CeciliaModuleCompilationUnit method generateInstruments.

/**
 * @param arrangement
 */
public void generateInstruments(Arrangement arrangement) {
    Instrument magicInstrument = getMagicInstrument();
    if (magicInstrument != null) {
        magicInstrId = arrangement.addInstrument(magicInstrument);
    }
    for (Iterator iter = instruments.keySet().iterator(); iter.hasNext(); ) {
        String key = (String) iter.next();
        GenericInstrument instr = (GenericInstrument) instruments.get(key);
        instr.setText(setGlobalUnique(instr.getText()));
        instr.setText(setFtableUnique(instr.getText()));
        instr.setText(replaceCeciliaVariables(instr.getText()));
        int newNum = arrangement.addInstrument(instr);
        String newId = Integer.toString(newNum);
        // System.out.println("Key/ID: " + key + " : " + newId);
        instrIDMap.put(key.trim(), newId);
    }
}
Also used : GenericInstrument(blue.orchestra.GenericInstrument) Instrument(blue.orchestra.Instrument) Iterator(java.util.Iterator) GenericInstrument(blue.orchestra.GenericInstrument)

Aggregations

Instrument (blue.orchestra.Instrument)32 GenericInstrument (blue.orchestra.GenericInstrument)14 Arrangement (blue.Arrangement)6 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)5 InstrumentCategory (blue.orchestra.InstrumentCategory)5 StrBuilder (org.apache.commons.lang3.text.StrBuilder)5 TransferableInstrument (blue.TransferableInstrument)4 Automatable (blue.automation.Automatable)4 Channel (blue.mixer.Channel)4 ChannelList (blue.mixer.ChannelList)4 Mixer (blue.mixer.Mixer)4 Point (java.awt.Point)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 TreePath (javax.swing.tree.TreePath)4 InstrumentAssignment (blue.InstrumentAssignment)3 Parameter (blue.automation.Parameter)3 LinePoint (blue.components.lines.LinePoint)3 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)3 BlueData (blue.BlueData)2