Search in sources :

Example 1 with Channel

use of blue.mixer.Channel in project blue by kunstmusik.

the class Arrangement method convertBlueMixerOut.

// TODO - Make this more efficient (made this way in case blueMixerOut is in
// comments
private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrangementId, String input, int nchnls) {
    if (!input.contains("blueMixerOut") && !input.contains("blueMixerIn")) {
        return input;
    }
    StrBuilder buffer = new StrBuilder();
    String[] lines = NEW_LINES.split(input);
    boolean blueMixerInFound = false;
    for (String line : lines) {
        int mixerInIndex = line.indexOf("blueMixerIn");
        if (mixerInIndex > 0) {
            String noCommentLine = TextUtilities.stripSingleLineComments(line);
            if (!noCommentLine.contains("blueMixerIn")) {
                buffer.append(line).append("\n");
                continue;
            }
            if (mixer == null || !mixer.isEnabled()) {
                throw new RuntimeException("Error: Instrument uses blueMixerIn but mixer is not enabled");
            }
            blueMixerInFound = true;
            String argText = noCommentLine.substring(0, mixerInIndex).trim();
            String[] args = argText.split(",");
            Channel c = getChannelForArrangementId(mixer, arrangementId);
            for (int i = 0; i < nchnls && i < args.length; i++) {
                String arg = args[i];
                String var;
                if (c == null) {
                    var = Mixer.getSubChannelVar(Channel.MASTER, i);
                } else {
                    var = Mixer.getChannelVar(data.getChannelIdAssignments().get(c), i);
                }
                buffer.append(arg).append(" = ");
                buffer.append(var).append("\n");
            }
        } else if (line.trim().startsWith("blueMixerOut")) {
            String argText = line.trim().substring(12);
            String[] args = argText.split(",");
            if (args[0].trim().matches("\".*\"")) {
                if (mixer == null || !mixer.isEnabled()) {
                    buffer.append("outc ");
                    for (int i = 1; i < args.length; i++) {
                        if (i > 1) {
                            buffer.append(",");
                        }
                        buffer.append(args[i]);
                    }
                    buffer.append("\n");
                } else {
                    String subChanBase = args[0].trim();
                    final String subChannelName = subChanBase.substring(1, subChanBase.length() - 1);
                    Optional<Channel> found = mixer.getSubChannels().stream().filter(chn -> subChannelName.equals(chn.getName())).findFirst();
                    if (!found.isPresent()) {
                        throw new RuntimeException("Unable to find subchannel with name: " + subChannelName);
                    }
                    mixer.addSubChannelDependency(subChannelName);
                    for (int i = 1; i < nchnls + 1 && i < args.length; i++) {
                        String arg = args[i];
                        String var = Mixer.getSubChannelVar(subChannelName, i - 1);
                        buffer.append(var);
                        if (!blueMixerInFound) {
                            buffer.append(" += ");
                        } else {
                            buffer.append(" = ");
                        }
                        buffer.append(arg).append("\n");
                    }
                }
            } else if (mixer == null || !mixer.isEnabled()) {
                buffer.append(line.replaceAll("blueMixerOut", "outc"));
                buffer.append("\n");
            } else {
                Channel c = getChannelForArrangementId(mixer, arrangementId);
                for (int i = 0; i < nchnls && i < args.length; i++) {
                    String arg = args[i];
                    String var;
                    if (c == null) {
                        var = Mixer.getSubChannelVar(Channel.MASTER, i);
                    } else {
                        var = Mixer.getChannelVar(data.getChannelIdAssignments().get(c), i);
                    }
                    buffer.append(var);
                    if (!blueMixerInFound) {
                        buffer.append(" += ");
                    } else {
                        buffer.append(" = ");
                    }
                    buffer.append(arg).append("\n");
                }
            }
        } else {
            buffer.append(line).append("\n");
        }
    }
    return buffer.toString();
}
Also used : Channel(blue.mixer.Channel) StrBuilder(org.apache.commons.lang3.text.StrBuilder)

Example 2 with Channel

use of blue.mixer.Channel in project blue by kunstmusik.

the class AutomationManager method getAutomationMenu.

public JPopupMenu getAutomationMenu(ParameterIdList paramIdList) {
    this.selectedParamIdList = paramIdList;
    // if (menu == null || dirty) {
    JPopupMenu menu = new JPopupMenu();
    // Build Instrument Menu
    JMenu instrRoot = new JMenu("Instrument");
    MenuScroller.setScrollerFor(instrRoot);
    Arrangement arrangement = data.getArrangement();
    for (int i = 0; i < arrangement.size(); i++) {
        InstrumentAssignment ia = arrangement.getInstrumentAssignment(i);
        if (ia.enabled && ia.instr instanceof Automatable) {
            ParameterList params = ((Automatable) ia.instr).getParameterList();
            if (params.size() <= 0) {
                continue;
            }
            final JMenu instrMenu = new JMenu();
            MenuScroller.setScrollerFor(instrMenu);
            instrMenu.setText(ia.arrangementId + ") " + ia.instr.getName());
            for (Parameter param : params.sorted()) {
                JMenuItem paramItem = new JMenuItem();
                paramItem.setText(param.getName());
                paramItem.addActionListener(parameterActionListener);
                if (param.isAutomationEnabled()) {
                    if (paramIdList.contains(param.getUniqueId())) {
                        paramItem.setForeground(Color.GREEN);
                    } else {
                        paramItem.setForeground(Color.ORANGE);
                    }
                }
                paramItem.putClientProperty("instr", ia.instr);
                paramItem.putClientProperty("param", param);
                instrMenu.add(paramItem);
            }
            instrRoot.add(instrMenu);
        }
    }
    menu.add(instrRoot);
    // Build Mixer Menu
    Mixer mixer = data.getMixer();
    if (mixer.isEnabled()) {
        JMenu mixerRoot = new JMenu("Mixer");
        MenuScroller.setScrollerFor(mixerRoot);
        // add channels
        ChannelList channels = mixer.getChannels();
        if (channels.size() > 0) {
            JMenu channelsMenu = new JMenu("Channels");
            for (int i = 0; i < channels.size(); i++) {
                channelsMenu.add(buildChannelMenu(channels.get(i), paramIdList));
            }
            mixerRoot.add(channelsMenu);
        }
        // add subchannels
        ChannelList subChannels = mixer.getSubChannels();
        if (subChannels.size() > 0) {
            JMenu subChannelsMenu = new JMenu("Sub-Channels");
            for (int i = 0; i < subChannels.size(); i++) {
                subChannelsMenu.add(buildChannelMenu(subChannels.get(i), paramIdList));
            }
            mixerRoot.add(subChannelsMenu);
        }
        // add master channel
        Channel master = mixer.getMaster();
        mixerRoot.add(buildChannelMenu(master, paramIdList));
        menu.add(mixerRoot);
    }
    menu.addSeparator();
    JMenuItem clearAll = new JMenuItem("Clear All");
    clearAll.addActionListener((ActionEvent e) -> {
        Object retVal = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation("Please Confirm Clearing All Parameter Data for this SoundLayer"));
        if (retVal == NotifyDescriptor.YES_OPTION) {
            ParameterIdList idList = selectedParamIdList;
            for (String paramId : idList.getParameters()) {
                Parameter param = getParameter(paramId);
                param.setAutomationEnabled(false);
                idList.removeParameterId(paramId);
            }
        }
    });
    menu.add(clearAll);
    clearAll.setEnabled(selectedParamIdList.size() > 0);
    // System.err.println(parameterMap);
    return menu;
}
Also used : ActionEvent(java.awt.event.ActionEvent) Mixer(blue.mixer.Mixer) Channel(blue.mixer.Channel) JPopupMenu(javax.swing.JPopupMenu) Arrangement(blue.Arrangement) NotifyDescriptor(org.openide.NotifyDescriptor) InstrumentAssignment(blue.InstrumentAssignment) PolyObject(blue.soundObject.PolyObject) JMenuItem(javax.swing.JMenuItem) ChannelList(blue.mixer.ChannelList) JMenu(javax.swing.JMenu)

Example 3 with Channel

use of blue.mixer.Channel in project blue by kunstmusik.

the class AudioHeaderListPanel method layersAdded.

public void layersAdded(LayerGroupDataEvent e) {
    final int index = e.getStartIndex();
    final AudioLayer sLayer = layerGroup.get(index);
    SwingUtilities.invokeLater(() -> {
        Channel c = mixer.findChannelById(sLayer.getUniqueId());
        AudioHeaderLayerPanel panel = new AudioHeaderLayerPanel(sLayer, c);
        add(panel, index);
        checkSize();
    });
}
Also used : Channel(blue.mixer.Channel) AudioLayer(blue.score.layers.audio.core.AudioLayer)

Example 4 with Channel

use of blue.mixer.Channel 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 5 with Channel

use of blue.mixer.Channel in project blue by kunstmusik.

the class CSDRender method assignChannelIds.

private void assignChannelIds(CompileData compileData, Mixer mixer) {
    Map<Channel, Integer> assignments = compileData.getChannelIdAssignments();
    int i = 0;
    for (Channel channel : mixer.getAllSourceChannels()) {
        assignments.put(channel, i++);
    }
    for (Channel channel : mixer.getSubChannels()) {
        assignments.put(channel, i++);
    }
    assignments.put(mixer.getMaster(), i);
}
Also used : Channel(blue.mixer.Channel) StringChannel(blue.orchestra.blueSynthBuilder.StringChannel) LinePoint(blue.components.lines.LinePoint)

Aggregations

Channel (blue.mixer.Channel)12 ChannelList (blue.mixer.ChannelList)8 Mixer (blue.mixer.Mixer)4 Instrument (blue.orchestra.Instrument)4 Arrangement (blue.Arrangement)3 InstrumentAssignment (blue.InstrumentAssignment)3 Automatable (blue.automation.Automatable)3 ArrayList (java.util.ArrayList)3 Parameter (blue.automation.Parameter)2 ParameterList (blue.automation.ParameterList)2 AudioLayer (blue.score.layers.audio.core.AudioLayer)2 LinePoint (blue.components.lines.LinePoint)1 GenericInstrument (blue.orchestra.GenericInstrument)1 StringChannel (blue.orchestra.blueSynthBuilder.StringChannel)1 Score (blue.score.Score)1 AudioLayerGroup (blue.score.layers.audio.core.AudioLayerGroup)1 AudioLayerChannelBinding (blue.score.layers.audio.ui.bindings.AudioLayerChannelBinding)1 AudioLayerGroupBinding (blue.score.layers.audio.ui.bindings.AudioLayerGroupBinding)1 PolyObject (blue.soundObject.PolyObject)1 Point (java.awt.Point)1