Search in sources :

Example 11 with SoundLayer

use of blue.SoundLayer in project blue by kunstmusik.

the class PolyObjectTest method testIsScoreGenerationEmpty.

public final void testIsScoreGenerationEmpty() {
    PolyObject pObj = new PolyObject();
    PolyObject pObj2 = new PolyObject();
    SoundLayer sLayer = new SoundLayer();
    SoundLayer sLayer2 = new SoundLayer();
    sLayer.add(pObj2);
    pObj2.add(sLayer2);
    Comment comment = new Comment();
    GenericScore genScore = new GenericScore();
    assertTrue(pObj.isScoreGenerationEmpty());
    pObj.add(sLayer);
    assertTrue(pObj.isScoreGenerationEmpty());
    sLayer.add(comment);
    assertTrue(pObj.isScoreGenerationEmpty());
    assertTrue(pObj2.isScoreGenerationEmpty());
    sLayer.remove(comment);
    sLayer2.add(comment);
    assertTrue(pObj.isScoreGenerationEmpty());
    assertTrue(pObj2.isScoreGenerationEmpty());
    sLayer.add(genScore);
    assertFalse(pObj.isScoreGenerationEmpty());
    assertTrue(pObj2.isScoreGenerationEmpty());
    sLayer.remove(genScore);
    sLayer2.add(genScore);
    assertFalse(pObj.isScoreGenerationEmpty());
    assertFalse(pObj2.isScoreGenerationEmpty());
}
Also used : SoundLayer(blue.SoundLayer)

Example 12 with SoundLayer

use of blue.SoundLayer in project blue by kunstmusik.

the class AutomationManager method layerGroupChanged.

@Override
public void layerGroupChanged(LayerGroupDataEvent event) {
    if (event.getType() != LayerGroupDataEvent.DATA_REMOVED || !(event.getSource() instanceof PolyObject)) {
        return;
    }
    final ArrayList<Layer> layers = event.getLayers();
    if (layers == null) {
        return;
    }
    for (Layer layer : layers) {
        SoundLayer sLayer = (SoundLayer) layer;
        ParameterIdList idList = sLayer.getAutomationParameters();
        for (int i = 0; i < idList.size(); i++) {
            String paramId = idList.getParameterId(i);
            Parameter param = getParameter(paramId);
            if (param != null) {
                param.setAutomationEnabled(false);
            }
        }
    }
}
Also used : SoundLayer(blue.SoundLayer) SoundLayer(blue.SoundLayer) Layer(blue.score.layers.Layer) PolyObject(blue.soundObject.PolyObject)

Example 13 with SoundLayer

use of blue.SoundLayer in project blue by kunstmusik.

the class AutomationManager method parameterRemoved.

public void parameterRemoved(Parameter param) {
    allParameters.remove(param);
    for (LayerGroup<? extends Layer> layerGroup : score) {
        if (layerGroup instanceof PolyObject) {
            PolyObject pObj = (PolyObject) layerGroup;
            for (SoundLayer layer : pObj) {
                ParameterIdList automationParameters = layer.getAutomationParameters();
                String paramId = param.getUniqueId();
                if (automationParameters.contains(paramId)) {
                    automationParameters.removeParameterId(paramId);
                }
            }
        }
    }
// dirty = true;
}
Also used : SoundLayer(blue.SoundLayer) PolyObject(blue.soundObject.PolyObject)

Example 14 with SoundLayer

use of blue.SoundLayer in project blue by kunstmusik.

the class AutomationManager method parameterSelected.

/**
 * When parameter is selected, check if this parameter is in use and if by
 * this soundLayer, turn it off, otherwise move it to this soundLayer.
 *
 * @param soundLayer
 * @param param
 */
private void parameterSelected(ParameterIdList paramIdList, Parameter param) {
    String uniqueId = param.getUniqueId();
    if (param.isAutomationEnabled()) {
        if (paramIdList.contains(uniqueId)) {
            param.setAutomationEnabled(false);
            paramIdList.removeParameterId(uniqueId);
        } else {
            // TODO - This class needs further updating for generic
            // LayerGroup Design
            Score score = data.getScore();
            for (LayerGroup<? extends Layer> layerGroup : score) {
                if (!(layerGroup instanceof PolyObject)) {
                    continue;
                }
                PolyObject pObj = (PolyObject) layerGroup;
                for (SoundLayer layer : pObj) {
                    if (layer.getAutomationParameters() == paramIdList) {
                        continue;
                    }
                    ParameterIdList automationParameters = layer.getAutomationParameters();
                    if (automationParameters.contains(uniqueId)) {
                        automationParameters.removeParameterId(uniqueId);
                    }
                }
            }
            paramIdList.addParameterId(uniqueId);
        }
    } else {
        param.setAutomationEnabled(true);
        param.getLine().setColor(LineColors.getColor(paramIdList.size()));
        paramIdList.addParameterId(uniqueId);
        param.fireUpdateFromTimeChange();
    }
}
Also used : Score(blue.score.Score) SoundLayer(blue.SoundLayer) PolyObject(blue.soundObject.PolyObject)

Example 15 with SoundLayer

use of blue.SoundLayer in project blue by kunstmusik.

the class MidiImportUtilities method convertMidiFile.

/**
 * Converts a MIDI file to a blue polyObject. Will return null if unable to
 * open or process the file.
 *
 * @param midiFile
 * @return
 * @throws NoteParseException
 */
public static PolyObject convertMidiFile(Frame root, File midiFile) throws NoteParseException {
    if (midiFile == null || !midiFile.exists()) {
        return null;
    }
    Sequence sequence = null;
    try {
        sequence = MidiSystem.getSequence(midiFile);
    } catch (InvalidMidiDataException imde) {
        imde.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    if (sequence == null) {
        return null;
    }
    PolyObject pObj = new PolyObject(true);
    Track[] tracks = sequence.getTracks();
    double divType = sequence.getDivisionType();
    if (divType == Sequence.PPQ) {
        divType = 1.0f;
    }
    double ticksLength = (double) sequence.getResolution();
    MidiImportSettings settings = getMidiImportSettings(tracks);
    if (settings.getRowCount() == 0) {
        return null;
    }
    boolean retVal = MidiImportSettingsDialog.ask(root, settings);
    if (!retVal) {
        return null;
    }
    for (int i = 0; i < tracks.length; i++) {
        TrackImportSettings trSettings = settings.getTrackSettingsForTrackNum(i);
        if (trSettings == null) {
            continue;
        }
        Track track = tracks[i];
        NoteList nl = getNoteListForTrack(track, divType, ticksLength, trSettings.getNoteTemplate(), trSettings.getInstrId());
        if (nl == null || nl.size() == 0) {
            continue;
        }
        GenericScore genSco = new GenericScore();
        if (trSettings.isTrim()) {
            // Assumes NoteList is already sorted
            double start = nl.get(0).getStartTime();
            genSco.setStartTime(start);
            ScoreUtilities.normalizeNoteList(nl);
        } else {
            genSco.setStartTime(0.0f);
        }
        genSco.setSubjectiveDuration(ScoreUtilities.getTotalDuration(nl));
        genSco.setText(nl.toString());
        genSco.setName("Track " + i);
        SoundLayer sLayer = pObj.newLayerAt(-1);
        sLayer.add(genSco);
    }
    return pObj;
}
Also used : InvalidMidiDataException(javax.sound.midi.InvalidMidiDataException) NoteList(blue.soundObject.NoteList) GenericScore(blue.soundObject.GenericScore) Sequence(javax.sound.midi.Sequence) IOException(java.io.IOException) SoundLayer(blue.SoundLayer) PolyObject(blue.soundObject.PolyObject) Track(javax.sound.midi.Track)

Aggregations

SoundLayer (blue.SoundLayer)27 SoundObject (blue.soundObject.SoundObject)10 PolyObject (blue.soundObject.PolyObject)9 Point (java.awt.Point)8 Layer (blue.score.layers.Layer)6 Instance (blue.soundObject.Instance)6 BlueData (blue.BlueData)5 ScoreObject (blue.score.ScoreObject)5 GenericScore (blue.soundObject.GenericScore)5 ArrayList (java.util.ArrayList)5 Score (blue.score.Score)3 AddScoreObjectEdit (blue.ui.core.score.undo.AddScoreObjectEdit)3 Test (org.junit.Test)3 SoundObjectLibrary (blue.SoundObjectLibrary)2 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)2 Parameter (blue.automation.Parameter)1 LinePoint (blue.components.lines.LinePoint)1 BlueSynthBuilder (blue.orchestra.BlueSynthBuilder)1 External (blue.soundObject.External)1 NoteList (blue.soundObject.NoteList)1