Search in sources :

Example 41 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class TempoEditor method setBoundaryXValues.

public void setBoundaryXValues() {
    Line currentLine = tempo.getLine();
    if (selectedPoint == currentLine.getLinePoint(0)) {
        leftBoundaryX = 0;
        rightBoundaryX = 0;
        return;
    } else if (selectedPoint == currentLine.getLinePoint(currentLine.size() - 1)) {
        LinePoint p1 = currentLine.getLinePoint(currentLine.size() - 2);
        leftBoundaryX = doubleToScreenX(p1.getX());
        rightBoundaryX = this.getWidth();
        return;
    }
    for (int i = 0; i < currentLine.size(); i++) {
        if (currentLine.getLinePoint(i) == selectedPoint) {
            LinePoint p1 = currentLine.getLinePoint(i - 1);
            LinePoint p2 = currentLine.getLinePoint(i + 1);
            leftBoundaryX = doubleToScreenX(p1.getX());
            rightBoundaryX = doubleToScreenX(p2.getX());
            return;
        }
    }
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint)

Example 42 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class CSDRender method appendParameterScore.

private void appendParameterScore(Parameter param, int instrId, StrBuilder paramScore, double renderStart, double renderEnd) {
    Line line = param.getLine();
    if (line.size() < 2) {
        return;
    }
    // TODO - re-evaluate this strategy for generating values
    double resolution = param.getResolution().doubleValue();
    double startAdj = 0;
    double durationAdj = 1.0;
    boolean adjustPoints = (line instanceof SoundObjectParameterLine);
    if (adjustPoints) {
        SoundObjectParameterLine paramLine = (SoundObjectParameterLine) line;
        startAdj = paramLine.getSourceStart();
        durationAdj = paramLine.getSourceDuration();
    }
    if (resolution > 0.0f) {
        for (int i = 1; i < line.size(); i++) {
            LinePoint p1 = line.getLinePoint(i - 1);
            LinePoint p2 = line.getLinePoint(i);
            double startTime = p1.getX();
            double endTime = p2.getX();
            if (adjustPoints) {
                startTime = (startTime * durationAdj) + startAdj;
                endTime = (endTime * durationAdj) + startAdj;
            }
            if (renderEnd > 0 && startTime >= renderEnd) {
                return;
            }
            if (endTime <= renderStart) {
                continue;
            }
            double startVal = p1.getY();
            double endVal = p2.getY();
            // to skip points that don't contribute to end value
            if (startTime == endTime) {
                if (i == line.size() - 1) {
                    createParamNote(paramScore, instrId, endTime, .0001f, p2.getY(), p2.getY());
                }
                continue;
            }
            if (startVal == endVal) {
                continue;
            }
            double dur = endTime - startTime;
            double currentVal = startVal;
            int numSteps = (int) Math.abs(Math.round((endVal - startVal) / resolution));
            double step = dur / numSteps;
            double start = startTime;
            double valStep = resolution;
            if (endVal < startVal) {
                valStep = -valStep;
            }
            // skip the first value as it will be already defined
            for (int j = 0; j < numSteps - 1; j++) {
                currentVal += valStep;
                start += step;
                if (start <= renderStart) {
                    continue;
                }
                if (renderEnd > 0 && start >= renderEnd) {
                    return;
                }
                paramScore.append("i");
                paramScore.append(instrId).append("\t");
                paramScore.append(NumberUtilities.formatDouble(start - renderStart)).append("\t");
                paramScore.append(".0001\t");
                paramScore.append(NumberUtilities.formatDouble(currentVal)).append("\n");
            }
            start += step;
            if (renderEnd > 0 && start >= renderEnd) {
                return;
            }
            paramScore.append("i");
            paramScore.append(instrId).append("\t");
            paramScore.append(NumberUtilities.formatDouble(start - renderStart)).append("\t");
            paramScore.append(".0001\t");
            paramScore.append(NumberUtilities.formatDouble(endVal)).append("\n");
        }
    } else {
        double lastValue = line.getLinePoint(0).getY();
        for (int i = 1; i < line.size(); i++) {
            LinePoint p1 = line.getLinePoint(i - 1);
            LinePoint p2 = line.getLinePoint(i);
            double startTime = p1.getX();
            double endTime = p2.getX();
            if (adjustPoints) {
                startTime = (startTime * durationAdj) + startAdj;
                endTime = (endTime * durationAdj) + startAdj;
            }
            if (renderEnd > 0 && startTime >= renderEnd) {
                return;
            }
            if (endTime <= renderStart) {
                lastValue = p2.getY();
                continue;
            }
            if (p1.getX() == p2.getX()) {
                if (i == line.size() - 1) {
                    createParamNote(paramScore, instrId, p2.getX(), .0001f, p2.getY(), p2.getY());
                }
                continue;
            }
            // if (p1.getY() == p2.getY() && p1.getY() == lastValue) {
            // continue;
            // }
            double startVal = p1.getY();
            double endVal = p2.getY();
            if (startTime < renderStart) {
                startVal = line.getValue(renderStart);
                startTime = renderStart;
            }
            if (renderEnd > 0 && endTime > renderEnd) {
                endVal = line.getValue(renderEnd);
                endTime = renderEnd;
            }
            lastValue = endVal;
            double dur;
            if (p1.getY() == p2.getY()) {
                dur = .0001f;
            } else {
                dur = endTime - startTime;
            }
            startTime -= renderStart;
            createParamNote(paramScore, instrId, startTime, dur, startVal, endVal);
            if (i == line.size() - 1) {
                createParamNote(paramScore, instrId, startTime + dur, .0001f, endVal, endVal);
            }
        }
    }
}
Also used : SoundObjectParameterLine(blue.components.lines.SoundObjectParameterLine) Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) SoundObjectParameterLine(blue.components.lines.SoundObjectParameterLine) LinePoint(blue.components.lines.LinePoint)

Example 43 with LinePoint

use of blue.components.lines.LinePoint in project blue by kunstmusik.

the class PasteBSBAsSoundAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    double start = (double) p.x / timeState.getPixelSecond();
    if (timeState.isSnapEnabled()) {
        start = ScoreUtilities.getSnapValueStart(start, timeState.getSnapValue());
    }
    Object obj = CopyBuffer.getBufferedObject(CopyBuffer.INSTRUMENT);
    Sound sound = new Sound();
    sound.setStartTime(start);
    BlueSynthBuilder bsbCopy = ((BlueSynthBuilder) obj).deepCopy();
    // clear out any existing automations
    for (Parameter param : bsbCopy.getParameterList()) {
        param.setAutomationEnabled(false);
        param.getLine().clear();
        param.getLine().addLinePoint(new LinePoint(0.0, param.getValue(0.0)));
        param.getLine().addLinePoint(new LinePoint(1.0, param.getValue(0.0)));
    }
    sound.setBlueSynthBuilder(bsbCopy);
    Layer layer = scorePath.getGlobalLayerForY(p.y);
    if (!layer.accepts(sound)) {
        JOptionPane.showMessageDialog(null, "Unable to paste due to target layers not " + "accepting types of objects within the copy buffer (i.e. trying to " + "paste a SoundObject into an AudioLayer");
        return;
    }
    SoundLayer sLayer = (SoundLayer) layer;
    sLayer.add(sound);
    BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
    AddScoreObjectEdit undoEdit = new AddScoreObjectEdit(sLayer, sound);
    BlueUndoManager.setUndoManager("score");
    BlueUndoManager.addEdit(undoEdit);
}
Also used : BlueData(blue.BlueData) LinePoint(blue.components.lines.LinePoint) AddScoreObjectEdit(blue.ui.core.score.undo.AddScoreObjectEdit) SoundLayer(blue.SoundLayer) Parameter(blue.automation.Parameter) ScoreObject(blue.score.ScoreObject) Sound(blue.soundObject.Sound) BlueSynthBuilder(blue.orchestra.BlueSynthBuilder) SoundLayer(blue.SoundLayer) Layer(blue.score.layers.Layer)

Aggregations

LinePoint (blue.components.lines.LinePoint)43 Line (blue.components.lines.Line)18 Point (java.awt.Point)13 Paint (javafx.scene.paint.Paint)6 SoundObjectParameterLine (blue.components.lines.SoundObjectParameterLine)3 Rectangle (java.awt.Rectangle)3 MenuItem (javafx.scene.control.MenuItem)3 Parameter (blue.automation.Parameter)2 DragDirection (blue.components.DragDirection)2 LineList (blue.components.lines.LineList)2 BlueFX (blue.jfx.BlueFX)2 Sound (blue.soundObject.Sound)2 NumberUtilities (blue.utility.NumberUtilities)2 BigDecimal (java.math.BigDecimal)2 Optional (java.util.Optional)2 BooleanProperty (javafx.beans.property.BooleanProperty)2 ObjectProperty (javafx.beans.property.ObjectProperty)2 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)2 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)2 ListChangeListener (javafx.collections.ListChangeListener)2