Search in sources :

Example 31 with Line

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

the class Channel method setLevel.

public void setLevel(double level) {
    if (levelParameter.isAutomationEnabled()) {
        double time = ParameterTimeManagerFactory.getInstance().getTime();
        if (time < 0) {
            return;
        }
        updatingLine = true;
        LinePoint found = null;
        Line line = levelParameter.getLine();
        for (int i = 0; i < line.size(); i++) {
            LinePoint point = line.getLinePoint(i);
            if (point.getX() == time) {
                found = point;
                break;
            }
        }
        if (found != null) {
            found.setLocation(found.getX(), level);
        } else {
            LinePoint lp = new LinePoint();
            lp.setLocation(time, level);
            line.insertLinePoint(lp);
        }
        updatingLine = false;
    } else {
        levelParameter.setValue(level);
    }
    double oldVal = this.level;
    this.level = level;
    firePropertyChange(LEVEL, new Double(oldVal), new Double(level));
}
Also used : Line(blue.components.lines.Line) LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint)

Example 32 with Line

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

the class ZakLineObject method loadFromXML.

/* SERIALIZATION */
/**
 * Load object's state from XML
 */
public static SoundObject loadFromXML(Element data, Map<String, Object> objRefMap) throws Exception {
    ZakLineObject lObj = new ZakLineObject();
    SoundObjectUtilities.initBasicFromXML(data, lObj);
    Elements lines = data.getElements();
    while (lines.hasMoreElements()) {
        Element node = lines.next();
        if (node.getName().equals("zakline")) {
            Line l = Line.loadFromXML(node);
            lObj.getLines().add(l);
        }
    }
    return lObj;
}
Also used : Line(blue.components.lines.Line) Element(electric.xml.Element) Elements(electric.xml.Elements)

Example 33 with Line

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

the class TempoEditor method paintComponent.

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (this.tempo == null) {
        return;
    }
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(STROKE2);
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHints(hints);
    Color currentColor = null;
    ModeManager modeManager = ModeManager.getInstance();
    Line tempoLine = this.tempo.getLine();
    boolean enabled = this.tempo.isEnabled();
    if (enabled) {
        if (tempo.isVisible()) {
            g2d.setColor(Color.GREEN);
        } else {
            g2d.setColor(Color.GREEN.darker().darker());
        }
        drawLine(g2d, tempoLine, this.tempo.isVisible());
    } else {
        g2d.setColor(Color.DARK_GRAY);
        drawLine(g2d, tempoLine, false);
        g2d.setColor(Color.WHITE);
        g2d.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
        return;
    }
    if (enabled && selectedPoint != null) {
        double min = tempoLine.getMin();
        double max = tempoLine.getMax();
        int x = doubleToScreenX(selectedPoint.getX());
        int y = doubleToScreenY(selectedPoint.getY(), min, max);
        g2d.setColor(Color.red);
        paintPoint(g2d, x, y);
        drawPointInformation(g2d, x, y);
    }
    g2d.setColor(Color.WHITE);
    g2d.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
}
Also used : Line(blue.components.lines.Line) Color(java.awt.Color) RenderingHints(java.awt.RenderingHints) Point(java.awt.Point) LinePoint(blue.components.lines.LinePoint) Graphics2D(java.awt.Graphics2D) ModeManager(blue.ui.core.score.ModeManager)

Example 34 with Line

use of blue.components.lines.Line 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 35 with Line

use of blue.components.lines.Line 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)

Aggregations

Line (blue.components.lines.Line)35 LinePoint (blue.components.lines.LinePoint)22 Point (java.awt.Point)11 SoundObjectParameterLine (blue.components.lines.SoundObjectParameterLine)4 Color (java.awt.Color)4 Iterator (java.util.Iterator)4 Graphics2D (java.awt.Graphics2D)3 RenderingHints (java.awt.RenderingHints)3 ModeManager (blue.ui.core.score.ModeManager)2 Element (electric.xml.Element)2 Elements (electric.xml.Elements)2 Rectangle (java.awt.Rectangle)2 BigDecimal (java.math.BigDecimal)2 GraphicsContext (javafx.scene.canvas.GraphicsContext)2 Color (javafx.scene.paint.Color)2 StrBuilder (org.apache.commons.lang3.text.StrBuilder)2 GenericInstrument (blue.orchestra.GenericInstrument)1 LineSelector (blue.orchestra.editor.blueSynthBuilder.jfx.LineSelector)1 ParameterLineView (blue.soundObject.editor.sound.ParameterLineView)1 TimeBar (blue.soundObject.editor.sound.TimeBar)1