use of blue.soundObject.PolyObject in project blue by kunstmusik.
the class ScoreObjectEditorTopComponent method resultChanged.
@Override
public void resultChanged(LookupEvent ev) {
if (!(TopComponent.getRegistry().getActivated() instanceof SoundObjectProvider)) {
return;
}
Collection<? extends ScoreObject> scoreObjects = result.allInstances();
if (scoreObjects.size() == 1) {
SwingUtilities.invokeLater(() -> {
BlueData data = BlueProjectManager.getInstance().getCurrentBlueData();
ScoreObject sObj = scoreObjects.iterator().next();
if (sObj instanceof PolyObject && data.getSoundObjectLibrary().contains(sObj)) {
PolyObject pObj = (PolyObject) sObj;
ScoreController.getInstance().editLayerGroup(pObj);
editScoreObject(null);
} else {
editScoreObject(sObj);
}
});
// FIXME - figure out how to discern if editing is from BlueLive...
} else {
SwingUtilities.invokeLater(() -> {
editScoreObject(null);
});
}
}
use of blue.soundObject.PolyObject in project blue by kunstmusik.
the class SoundObjectLibraryUtils method removeSoundObjectInstances.
protected static void removeSoundObjectInstances(PolyObject polyObject, SoundObject sObj) {
for (int i = 0; i < polyObject.size(); i++) {
SoundLayer layer = polyObject.get(i);
ArrayList<SoundObject> instances = new ArrayList<>();
for (SoundObject tempObject : layer) {
if (tempObject instanceof Instance) {
Instance instance = (Instance) tempObject;
if (instance.getSoundObject() == sObj) {
instances.add(instance);
}
} else if (tempObject instanceof PolyObject) {
removeSoundObjectInstances((PolyObject) tempObject, sObj);
}
}
for (SoundObject tempObject : instances) {
layer.remove(tempObject);
}
}
}
use of blue.soundObject.PolyObject in project blue by kunstmusik.
the class SoundObjectLibraryUtils method removeLibrarySoundObject.
public static void removeLibrarySoundObject(BlueData data, SoundObject sObj) {
SoundObjectLibrary library = data.getSoundObjectLibrary();
library.removeSoundObject(sObj);
for (SoundObject tempObj : library) {
if (tempObj instanceof PolyObject) {
removeSoundObjectInstances((PolyObject) tempObj, sObj);
}
}
Score score = data.getScore();
for (LayerGroup layerGroup : score) {
if (layerGroup instanceof PolyObject) {
PolyObject pObj = (PolyObject) layerGroup;
removeSoundObjectInstances(pObj, sObj);
}
}
}
use of blue.soundObject.PolyObject in project blue by kunstmusik.
the class ScoreTimelineDropTargetListener method drop.
/*
* (non-Javadoc)
*
* @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
*/
@Override
public void drop(DropTargetDropEvent dtde) {
try {
Transferable tr = dtde.getTransferable();
if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_LINK);
List list = (List) tr.getTransferData(DataFlavor.javaFileListFlavor);
if (list.size() != 1) {
dtde.dropComplete(false);
return;
}
String s = list.get(0).toString().trim();
if (!s.toLowerCase().endsWith("wav") && !s.toLowerCase().endsWith("aif") && !s.toLowerCase().endsWith("aiff")) {
dtde.dropComplete(false);
return;
}
String sObjName = s.substring(s.lastIndexOf(File.separator) + 1);
Point p = dtde.getLocation();
int index = sTimeCanvas.pObj.getLayerNumForY(p.y);
AudioFile af = new AudioFile();
af.setName(sObjName);
af.setSoundFileName(BlueSystem.getRelativePath(s));
PolyObject pObj = sTimeCanvas.getPolyObject();
float startTime = (float) p.x / timeState.getPixelSecond();
float dur = SoundFileUtilities.getDurationInSeconds(s);
af.setStartTime(startTime);
af.setSubjectiveDuration(dur);
pObj.addSoundObject(index, af);
dtde.dropComplete(true);
return;
} else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) {
dtde.acceptDrop(DnDConstants.ACTION_LINK);
String str = (String) tr.getTransferData(DataFlavor.stringFlavor);
if (!str.startsWith("file://")) {
dtde.dropComplete(false);
return;
}
str = str.substring(7).trim();
if (!str.toLowerCase().endsWith("wav") && !str.toLowerCase().endsWith("aif") && !str.toLowerCase().endsWith("aiff")) {
System.err.println("Could not open file: " + str);
dtde.dropComplete(false);
return;
}
str = URLDecoder.decode(str);
str = str.replaceAll(" ", "\\ ");
File f = new File(str);
if (!f.exists()) {
dtde.dropComplete(false);
return;
}
String sObjName = str.substring(str.lastIndexOf(File.separator) + 1);
Point p = dtde.getLocation();
int index = sTimeCanvas.pObj.getLayerNumForY(p.y);
AudioFile af = new AudioFile();
af.setName(sObjName);
af.setSoundFileName(str);
PolyObject pObj = sTimeCanvas.getPolyObject();
float startTime = (float) p.x / timeState.getPixelSecond();
float dur = SoundFileUtilities.getDurationInSeconds(str);
af.setStartTime(startTime);
af.setSubjectiveDuration(dur);
pObj.addSoundObject(index, af);
dtde.dropComplete(true);
return;
}
dtde.rejectDrop();
} catch (UnsupportedFlavorException | IOException | UnsupportedAudioFileException e) {
e.printStackTrace();
dtde.rejectDrop();
}
}
Aggregations