Search in sources :

Example 36 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class ConvertToPolyObjectAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    int retVal = JOptionPane.showConfirmDialog(null, "This operation can not be undone.\nAre you sure?");
    if (retVal != JOptionPane.OK_OPTION) {
        return;
    }
    List<Layer> allLayers = scorePath.getAllLayers();
    List<SoundObject> sObjList = new ArrayList<>();
    List<Integer> layerIndexes = new ArrayList<>();
    int layerMin = Integer.MAX_VALUE;
    int layerMax = Integer.MIN_VALUE;
    double start = Double.POSITIVE_INFINITY;
    for (SoundObject sObj : soundObjects) {
        sObjList.add(sObj);
        double sObjStart = sObj.getStartTime();
        if (sObj.getStartTime() < start) {
            start = sObj.getStartTime();
        }
        for (int i = 0; i < allLayers.size(); i++) {
            if (allLayers.get(i).contains(sObj)) {
                layerIndexes.add(i);
                if (i < layerMin) {
                    layerMin = i;
                }
                if (i > layerMax) {
                    layerMax = i;
                }
                break;
            }
        }
        if (sObjList.size() != layerIndexes.size()) {
            throw new RuntimeException("Error: Unable to find layer for SoundObject.");
        }
    }
    int numLayers = layerMax - layerMin + 1;
    for (int i = 0; i < numLayers; i++) {
        pObj.newLayerAt(-1);
    }
    for (int i = 0; i < sObjList.size(); i++) {
        SoundObject sObj = sObjList.get(i);
        int layerNum = layerIndexes.get(i);
        SoundLayer layer = (SoundLayer) allLayers.get(layerNum);
        layer.remove(sObj);
        // don't need to clone here...
        pObj.get(layerNum - layerMin).add(sObj);
    }
    pObj.normalizeSoundObjects();
    pObj.setStartTime(start);
    ((SoundLayer) scorePath.getGlobalLayerForY(p.y)).add(pObj);
    ScoreController.getInstance().setSelectedScoreObjects(Collections.singleton(pObj));
}
Also used : SoundObject(blue.soundObject.SoundObject) SoundLayer(blue.SoundLayer) ArrayList(java.util.ArrayList) SoundLayer(blue.SoundLayer) Layer(blue.score.layers.Layer) Point(java.awt.Point)

Example 37 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class GenericRenderer method render.

@Override
public void render(Graphics graphics, SoundObjectView sObjView, int pixelSeconds) {
    Graphics2D g = (Graphics2D) graphics;
    int w = sObjView.getSize().width;
    int h = sObjView.getSize().height;
    Color bgColor;
    Color border1;
    Color border2;
    Color fontColor;
    SoundObject sObj = sObjView.getSoundObject();
    if (sObjView.isSelected()) {
        bgColor = selectedBgColor;
        border1 = selectedBorder1;
        border2 = selectedBorder2;
        fontColor = selectedFontColor;
    } else {
        bgColor = sObj.getBackgroundColor();
        border1 = bgColor.brighter().brighter();
        border2 = bgColor.darker().darker();
        int total = bgColor.getRed() + bgColor.getGreen() + bgColor.getBlue();
        if (total > 128 * 3) {
            fontColor = Color.black;
        } else {
            fontColor = Color.white;
        }
    }
    g.setPaint(BlueGradientFactory.getGradientPaint(bgColor));
    g.fillRect(0, 2, w, h - 4);
    // DRAW BORDERS
    // if (ProgramOptions.getGeneralSettings().isDrawFlatSObjBorders()) {
    // g.setColor(Color.LIGHT_GRAY);
    // g.drawRect(0, 2, w - 1, h - 4);
    // 
    // } else {
    g.setColor(border1);
    g.drawLine(0, 2, w - 1, 2);
    g.drawLine(0, 2, 0, h - 4);
    g.setColor(border2);
    g.drawLine(0, h - 3, w, h - 3);
    g.drawLine(w - 1, h - 3, w - 1, 2);
    // }
    // paint repeat
    double repeatPoint = sObj.getRepeatPoint();
    if (sObj.getTimeBehavior() == SoundObject.TIME_BEHAVIOR_REPEAT && repeatPoint > 0.0f) {
        double lineTime = repeatPoint;
        double dur = sObj.getSubjectiveDuration();
        int[] x = new int[3];
        int[] y = new int[3];
        while (lineTime <= dur) {
            g.setColor(border2);
            int lineX = (int) (lineTime * pixelSeconds);
            // g.drawLine(lineX, 3, lineX, h - 4);
            x[0] = lineX - 5;
            x[1] = lineX;
            x[2] = lineX;
            y[0] = 3;
            y[1] = 8;
            y[2] = 3;
            g.fillPolygon(x, y, 3);
            y[0] = h - 3;
            y[1] = h - 8;
            y[2] = h - 3;
            g.fillPolygon(x, y, 3);
            lineTime += repeatPoint;
        }
    }
    g.setPaint(fontColor);
    if (h >= 20) {
        g.setComposite(AlphaComposite.Src);
        g.setFont(renderFont);
        String[] parts = sObjView.getSoundObject().getName().split("\\\\[n]");
        for (int i = 0; i < parts.length; i++) {
            int y = 15 + (i * Layer.LAYER_HEIGHT);
            g.drawString(parts[i], labelOffset, y);
        }
    }
// EMPTY OUT CORNERS
// g.setColor(Color.BLACK);
// g.drawLine(0, 2, 0, 2);
// g.drawLine(0, h - 3, 0, h - 3);
// g.drawLine(w - 1, 2, w - 1, 2);
// g.drawLine(w - 1, h - 3, w - 1, h - 3);
}
Also used : SoundObject(blue.soundObject.SoundObject)

Example 38 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class ExportAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (scoreObjects.size() == 1 && soundObjects.size() == 1) {
        File retVal = FileChooserManager.getDefault().showSaveDialog(EXPORT_DIALOG, WindowManager.getDefault().getMainWindow());
        if (retVal != null) {
            File f = retVal;
            if (f.exists()) {
                int overWrite = JOptionPane.showConfirmDialog(SwingUtilities.getRoot(WindowManager.getDefault().getMainWindow()), "Please confirm you would like to overwrite this file.");
                if (overWrite != JOptionPane.OK_OPTION) {
                    return;
                }
            }
            SoundObject sObj = soundObjects.iterator().next();
            if ((sObj instanceof Instance) || ((sObj instanceof PolyObject) && containsInstance((PolyObject) sObj))) {
                JOptionPane.showMessageDialog(WindowManager.getDefault().getMainWindow(), "Error: Export of Instance or " + "PolyObjects containing Instance " + "is not allowed.", "Error", JOptionPane.ERROR_MESSAGE);
                return;
            }
            Element node = sObj.saveAsXML(null);
            PrintWriter out;
            try {
                out = new PrintWriter(new FileWriter(f));
                out.print(node.toString());
                out.flush();
                out.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) Instance(blue.soundObject.Instance) Element(electric.xml.Element) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) PolyObject(blue.soundObject.PolyObject) PrintWriter(java.io.PrintWriter)

Example 39 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class FreezeUnfreezeAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    List<Layer> allLayers = scorePath.getAllLayers();
    List<SoundObject> sObjList = new ArrayList<>(soundObjects);
    List<Layer> layers = new ArrayList<>();
    for (SoundObject sObj : sObjList) {
        for (Layer layer : allLayers) {
            if (layer.contains(sObj)) {
                layers.add(layer);
                break;
            }
        }
    }
    if (layers.size() != sObjList.size()) {
        throw new RuntimeException("Error: Could not find layers for selected SoundObjects");
    }
    ProgressUtils.showProgressDialogAndRun(new FreezeRunnable(sObjList, layers), "Freeze/Unfreeze SoundObjects", true);
}
Also used : FrozenSoundObject(blue.soundObject.FrozenSoundObject) SoundObject(blue.soundObject.SoundObject) ArrayList(java.util.ArrayList) SoundLayer(blue.SoundLayer) Layer(blue.score.layers.Layer)

Example 40 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class RealtimeRenderManager method getPolyObjectPath.

private List<PolyObject> getPolyObjectPath(PolyObject pObj, SoundObject soundObject) {
    List<SoundObject> allSObj = pObj.getSoundObjects(true);
    List<PolyObject> retVal = null;
    if (allSObj.contains(soundObject)) {
        retVal = new ArrayList<>();
        retVal.add(pObj);
    } else {
        List<SoundObject> pObjs = allSObj.stream().filter(a -> a instanceof PolyObject).collect(Collectors.toList());
        for (SoundObject obj : pObjs) {
            PolyObject tempPObj = (PolyObject) obj;
            retVal = getPolyObjectPath(tempPObj, soundObject);
            if (retVal != null) {
                retVal.add(0, pObj);
                break;
            }
        }
    }
    return retVal;
}
Also used : RealtimeRenderService(blue.services.render.RealtimeRenderService) Score(blue.score.Score) PolyObject(blue.soundObject.PolyObject) ScoreObjectLayer(blue.score.layers.ScoreObjectLayer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PlayModeListener(blue.event.PlayModeListener) WindowManager(org.openide.windows.WindowManager) RealtimeRenderSettings(blue.settings.RealtimeRenderSettings) Iterator(java.util.Iterator) SoundObject(blue.soundObject.SoundObject) Set(java.util.Set) Layer(blue.score.layers.Layer) Collectors(java.util.stream.Collectors) ExceptionDialog(blue.gui.ExceptionDialog) ScoreObjectLayerGroup(blue.score.layers.ScoreObjectLayerGroup) Mixer(blue.mixer.Mixer) LayerGroup(blue.score.layers.LayerGroup) BlueData(blue.BlueData) List(java.util.List) BlueSystem(blue.BlueSystem) ScoreObject(blue.score.ScoreObject) CsoundBinding(blue.services.render.CsoundBinding) RealtimeRenderServiceFactory(blue.services.render.RealtimeRenderServiceFactory) SoundObjectException(blue.soundObject.SoundObjectException) StatusDisplayer(org.openide.awt.StatusDisplayer) SoundObject(blue.soundObject.SoundObject) PolyObject(blue.soundObject.PolyObject)

Aggregations

SoundObject (blue.soundObject.SoundObject)53 SoundLayer (blue.SoundLayer)12 Instance (blue.soundObject.Instance)11 PolyObject (blue.soundObject.PolyObject)11 ScoreObject (blue.score.ScoreObject)8 ArrayList (java.util.ArrayList)8 Element (electric.xml.Element)7 Point (java.awt.Point)7 IOException (java.io.IOException)6 BlueData (blue.BlueData)5 Layer (blue.score.layers.Layer)5 NoteList (blue.soundObject.NoteList)5 ScoreController (blue.ui.core.score.ScoreController)5 HashMap (java.util.HashMap)5 SoundObjectLibrary (blue.SoundObjectLibrary)4 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)4 Document (electric.xml.Document)4 ParseException (electric.xml.ParseException)4 File (java.io.File)4 LiveObject (blue.blueLive.LiveObject)3