Search in sources :

Example 1 with AlignEdit

use of blue.ui.core.score.undo.AlignEdit in project blue by kunstmusik.

the class AlignLeftAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (selected.size() < 2) {
        return;
    }
    double[] initialStartTimes = new double[selected.size()];
    double[] endingStartTimes = new double[selected.size()];
    double farLeft = Double.MAX_VALUE;
    int i = 0;
    for (ScoreObject scoreObj : selected) {
        initialStartTimes[i] = scoreObj.getStartTime();
        if (initialStartTimes[i] < farLeft) {
            farLeft = initialStartTimes[i];
        }
        i++;
    }
    i = 0;
    for (ScoreObject scoreObj : selected) {
        scoreObj.setStartTime(farLeft);
        endingStartTimes[i] = farLeft;
        i++;
    }
    BlueUndoManager.setUndoManager("score");
    AlignEdit edit = new AlignEdit(selected.toArray(new ScoreObject[0]), initialStartTimes, endingStartTimes);
    edit.setPresentationName("Align Left");
    BlueUndoManager.addEdit(edit);
}
Also used : AlignEdit(blue.ui.core.score.undo.AlignEdit) ScoreObject(blue.score.ScoreObject)

Example 2 with AlignEdit

use of blue.ui.core.score.undo.AlignEdit in project blue by kunstmusik.

the class AlignRightAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    if (selected.size() < 2) {
        return;
    }
    double[] initialStartTimes = new double[selected.size()];
    double[] endingStartTimes = new double[selected.size()];
    double farRight = Double.MIN_VALUE;
    int i = 0;
    for (ScoreObject scoreObj : selected) {
        initialStartTimes[i] = scoreObj.getStartTime();
        double end = initialStartTimes[i] + scoreObj.getSubjectiveDuration();
        if (end > farRight) {
            farRight = end;
        }
        i++;
    }
    i = 0;
    for (ScoreObject scoreObj : selected) {
        double newTime = farRight - scoreObj.getSubjectiveDuration();
        scoreObj.setStartTime(newTime);
        endingStartTimes[i] = newTime;
        i++;
    }
    BlueUndoManager.setUndoManager("score");
    AlignEdit edit = new AlignEdit(selected.toArray(new ScoreObject[0]), initialStartTimes, endingStartTimes);
    edit.setPresentationName("Align Right");
    BlueUndoManager.addEdit(edit);
}
Also used : AlignEdit(blue.ui.core.score.undo.AlignEdit) ScoreObject(blue.score.ScoreObject)

Example 3 with AlignEdit

use of blue.ui.core.score.undo.AlignEdit in project blue by kunstmusik.

the class ShiftAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (selected == null || selected.size() <= 0) {
        return;
    }
    String value = JOptionPane.showInputDialog(null, BlueSystem.getString("scoreGUI.action.shift.message"));
    try {
        double val = Double.parseDouble(value);
        for (ScoreObject scoreObj : selected) {
            if ((scoreObj.getStartTime() + val) < 0) {
                JOptionPane.showMessageDialog(null, BlueSystem.getString("scoreGUI.action.shift.error"));
                return;
            }
        }
        int len = selected.size();
        ScoreObject[] objects = selected.<ScoreObject>toArray(new ScoreObject[selected.size()]);
        double[] startTimes = new double[len];
        double[] endTimes = new double[len];
        for (int i = 0; i < len; i++) {
            ScoreObject scoreObj = objects[i];
            startTimes[i] = scoreObj.getStartTime();
            endTimes[i] = startTimes[i] + val;
            scoreObj.setStartTime(endTimes[i]);
        }
        AlignEdit edit = new AlignEdit(objects, startTimes, endTimes);
        BlueUndoManager.setUndoManager("score");
        BlueUndoManager.addEdit(edit);
    } catch (NumberFormatException nfe) {
        System.err.println(nfe.getMessage());
    }
}
Also used : AlignEdit(blue.ui.core.score.undo.AlignEdit) ScoreObject(blue.score.ScoreObject)

Example 4 with AlignEdit

use of blue.ui.core.score.undo.AlignEdit in project blue by kunstmusik.

the class AlignCenterAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent ev) {
    if (selected.size() < 2) {
        return;
    }
    double[] initialStartTimes = new double[selected.size()];
    double[] endingStartTimes = new double[selected.size()];
    double farLeft = Double.MAX_VALUE;
    double farRight = Double.MIN_VALUE;
    double end;
    int i = 0;
    for (ScoreObject scoreObj : selected) {
        initialStartTimes[i] = scoreObj.getStartTime();
        end = initialStartTimes[i] + scoreObj.getSubjectiveDuration();
        if (initialStartTimes[i] < farLeft) {
            farLeft = initialStartTimes[i];
        }
        if (end > farRight) {
            farRight = end;
        }
        i++;
    }
    double centerTime = ((farRight - farLeft) / 2) + farLeft;
    double newEndTime;
    i = 0;
    for (ScoreObject scoreObj : selected) {
        newEndTime = centerTime - (scoreObj.getSubjectiveDuration() / 2);
        scoreObj.setStartTime(newEndTime);
        endingStartTimes[i] = newEndTime;
        i++;
    }
    BlueUndoManager.setUndoManager("score");
    AlignEdit edit = new AlignEdit(selected.toArray(new ScoreObject[0]), initialStartTimes, endingStartTimes);
    edit.setPresentationName("Align Center");
    BlueUndoManager.addEdit(edit);
}
Also used : AlignEdit(blue.ui.core.score.undo.AlignEdit) ScoreObject(blue.score.ScoreObject)

Example 5 with AlignEdit

use of blue.ui.core.score.undo.AlignEdit in project blue by kunstmusik.

the class FollowTheLeaderAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    List<ScoreObject> scoreObjs = new ArrayList<>(selected);
    Collections.sort(scoreObjs, (ScoreObject o1, ScoreObject o2) -> {
        double diff = o1.getStartTime() - o2.getStartTime();
        if (diff > 0) {
            return 1;
        } else if (diff < 0) {
            return -1;
        }
        return 0;
    });
    double[] initialStartTimes = new double[scoreObjs.size()];
    double[] endStartTimes = new double[scoreObjs.size()];
    for (int i = 0; i < scoreObjs.size(); i++) {
        initialStartTimes[i] = scoreObjs.get(i).getStartTime();
    }
    ScoreObject initial = scoreObjs.get(0);
    double runningTotal = initial.getStartTime() + initial.getSubjectiveDuration();
    endStartTimes[0] = initial.getStartTime();
    for (int i = 1; i < scoreObjs.size(); i++) {
        ScoreObject current = scoreObjs.get(i);
        endStartTimes[i] = runningTotal;
        current.setStartTime(runningTotal);
        runningTotal += current.getSubjectiveDuration();
    }
    BlueUndoManager.setUndoManager("score");
    AlignEdit edit = new AlignEdit(scoreObjs.toArray(new ScoreObject[0]), initialStartTimes, endStartTimes);
    edit.setPresentationName("Follow the Leader");
    BlueUndoManager.addEdit(edit);
}
Also used : AlignEdit(blue.ui.core.score.undo.AlignEdit) ScoreObject(blue.score.ScoreObject) ArrayList(java.util.ArrayList)

Aggregations

ScoreObject (blue.score.ScoreObject)5 AlignEdit (blue.ui.core.score.undo.AlignEdit)5 ArrayList (java.util.ArrayList)1