Search in sources :

Example 21 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class SoundObjectImportPane method importSoundObject.

private void importSoundObject() {
    SoundObjectOption iOption = iTableModel.getSoundObjectOption(instrumentTable.getSelectedRow());
    if (iOption == null) {
        return;
    }
    try {
        SoundObject soundObject = BlueShareRemoteCaller.getSoundObject(iOption);
        if (soundObject == null) {
            String error = "Error: Could not import this SoundObject.";
            JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
            return;
        }
        // data.getOrchestra().addSoundObject(instrument);
        // instrumentTreeModel.reload();
        Library<SoundObject> instrLib = BlueSystem.getSoundObjectLibrary();
        importSoundObjectToLibrary(instrLib, soundObject);
        String message = BlueSystem.getString("blueShare.importSuccess");
        JOptionPane.showMessageDialog(null, message, BlueSystem.getString("common.success"), JOptionPane.PLAIN_MESSAGE);
    } catch (ParseException pe) {
        String error = BlueSystem.getString("blueShare.selectServer.couldNotReadResponse");
        JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
        return;
    } catch (XmlRpcException xre) {
        String error = "Error: " + xre.getLocalizedMessage();
        JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
        return;
    } catch (IOException ioe) {
        String error = "Error: " + ioe.getLocalizedMessage();
        JOptionPane.showMessageDialog(null, error, BlueSystem.getString("message.error"), JOptionPane.ERROR_MESSAGE);
        return;
    }
}
Also used : SoundObject(blue.soundObject.SoundObject) ParseException(electric.xml.ParseException) IOException(java.io.IOException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 22 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class InstanceEditor method editScoreObject.

@Override
public void editScoreObject(ScoreObject sObj) {
    if (sObj == null) {
        instance = null;
        return;
    }
    if (!sObj.getClass().getName().equals("blue.soundObject.Instance")) {
        instance = null;
        return;
    }
    this.instance = (Instance) sObj;
    editorLabel.setText(BlueSystem.getString("instanceObject.instanceOf") + " " + instance.getSoundObject().getName());
    String generatedNoteText = null;
    try {
        SoundObject clone = instance.getSoundObject().deepCopy();
        generatedNoteText = clone.generateForCSD(CompileData.createEmptyCompileData(), 0.0f, -1.0f).toString();
    } catch (Exception e) {
        Exceptions.printStackTrace(e);
        // TODO - TRANSLATE
        generatedNoteText = "Could not generate notes";
    }
    scoreEditPane.setText(BlueSystem.getString("instanceObject.scoreGenMessage") + "\n\n" + generatedNoteText);
}
Also used : SoundObject(blue.soundObject.SoundObject)

Example 23 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class BlueSystem method saveSoundObjectLibrary.

public static void saveSoundObjectLibrary() {
    if (soundObjectLibrary == null) {
        return;
    }
    String userSObjFileName = BlueSystem.getUserConfigurationDirectory() + File.separator + "soundObjectLibrary.xml";
    String tmpFileName = userSObjFileName + ".tmp";
    PrintWriter out = null;
    try {
        out = new PrintWriter(new FileWriter(tmpFileName));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (out != null) {
        Map<Object, String> dummyRefMap = new HashMap<>();
        String lib = soundObjectLibrary.saveAsXML(sObj -> sObj.getValue().saveAsXML(dummyRefMap)).toString();
        out.print(lib);
        out.flush();
        out.close();
        System.out.println("Saved SoundObject Library: " + userSObjFileName);
    } else {
        System.err.println("Unable to Save SoundObject Library: " + userSObjFileName);
        return;
    }
    File f = new File(userSObjFileName);
    if (f.exists()) {
        File backup = new File(userSObjFileName + "~");
        if (backup.exists()) {
            backup.delete();
        }
        f.renameTo(backup);
    }
    f = new File(tmpFileName);
    f.renameTo(new File(userSObjFileName));
}
Also used : Library(blue.library.Library) PrintWriter(java.io.PrintWriter) Document(electric.xml.Document) UDOLibrary(blue.udo.UDOLibrary) Image(java.awt.Image) FileUtilities(blue.utility.FileUtilities) SoundObject(blue.soundObject.SoundObject) FileWriter(java.io.FileWriter) MissingResourceException(java.util.MissingResourceException) EnvironmentVars(blue.utility.EnvironmentVars) IOException(java.io.IOException) HashMap(java.util.HashMap) JOptionPane(javax.swing.JOptionPane) File(java.io.File) ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem) Locale(java.util.Locale) Map(java.util.Map) ParseException(electric.xml.ParseException) ObjectUtilities(blue.utility.ObjectUtilities) Toolkit(java.awt.Toolkit) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) SoundObject(blue.soundObject.SoundObject) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 24 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class BlueSystem method getSoundObjectLibrary.

public static Library<SoundObject> getSoundObjectLibrary() {
    if (soundObjectLibrary == null) {
        String userInstrFileName = BlueSystem.getUserConfigurationDirectory() + File.separator + "soundObjectLibrary.xml";
        File f = new File(userInstrFileName);
        if (f.exists()) {
            boolean error = false;
            try {
                Document doc = new Document(f);
                Map<String, Object> objRefMap = new HashMap<>();
                soundObjectLibrary = Library.loadLibrary(doc.getRoot(), elem -> {
                    try {
                        return (SoundObject) ObjectUtilities.loadFromXML(elem, objRefMap);
                    } catch (Exception ex) {
                        throw new RuntimeException(ex);
                    }
                });
            } catch (ParseException e1) {
                e1.printStackTrace();
                error = true;
            } catch (Exception e) {
                e.printStackTrace();
                error = true;
            }
            if (error) {
                JOptionPane.showMessageDialog(null, "There was an error loading " + f.getAbsolutePath() + "\nPlease fix this file or remove it and restart blue.", "Error", JOptionPane.ERROR_MESSAGE);
                System.exit(0);
            }
        } else {
            soundObjectLibrary = Library.createLibrary("SoundObjects");
        }
    }
    return soundObjectLibrary;
}
Also used : Library(blue.library.Library) PrintWriter(java.io.PrintWriter) Document(electric.xml.Document) UDOLibrary(blue.udo.UDOLibrary) Image(java.awt.Image) FileUtilities(blue.utility.FileUtilities) SoundObject(blue.soundObject.SoundObject) FileWriter(java.io.FileWriter) MissingResourceException(java.util.MissingResourceException) EnvironmentVars(blue.utility.EnvironmentVars) IOException(java.io.IOException) HashMap(java.util.HashMap) JOptionPane(javax.swing.JOptionPane) File(java.io.File) ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem) Locale(java.util.Locale) Map(java.util.Map) ParseException(electric.xml.ParseException) ObjectUtilities(blue.utility.ObjectUtilities) Toolkit(java.awt.Toolkit) HashMap(java.util.HashMap) SoundObject(blue.soundObject.SoundObject) ParseException(electric.xml.ParseException) Document(electric.xml.Document) File(java.io.File) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) ParseException(electric.xml.ParseException)

Example 25 with SoundObject

use of blue.soundObject.SoundObject in project blue by kunstmusik.

the class SoundLayer method loadFromXML.

public static SoundLayer loadFromXML(Element data, Map<String, Object> objRefMap) throws Exception {
    SoundLayer sLayer = new SoundLayer();
    sLayer.setName(data.getAttributeValue("name"));
    sLayer.setMuted(Boolean.valueOf(data.getAttributeValue("muted")).booleanValue());
    sLayer.setSolo(Boolean.valueOf(data.getAttributeValue("solo")).booleanValue());
    String heightIndexStr = data.getAttributeValue("heightIndex");
    if (heightIndexStr != null) {
        sLayer.setHeightIndex(Integer.parseInt(heightIndexStr));
    }
    Element npcNode = data.getElement("noteProcessorChain");
    if (npcNode != null) {
        sLayer.setNoteProcessorChain(NoteProcessorChain.loadFromXML(npcNode));
    }
    Elements sObjects = data.getElements("soundObject");
    while (sObjects.hasMoreElements()) {
        Object obj = ObjectUtilities.loadFromXML(sObjects.next(), objRefMap);
        sLayer.add((SoundObject) obj);
    }
    Elements parameters = data.getElements("parameterId");
    while (parameters.hasMoreElements()) {
        String id = parameters.next().getTextString();
        sLayer.automationParameters.addParameterId(id);
    }
    return sLayer;
}
Also used : Element(electric.xml.Element) SoundObject(blue.soundObject.SoundObject) ScoreObject(blue.score.ScoreObject) Elements(electric.xml.Elements)

Aggregations

SoundObject (blue.soundObject.SoundObject)53 SoundLayer (blue.SoundLayer)12 Instance (blue.soundObject.Instance)11 PolyObject (blue.soundObject.PolyObject)11 ScoreObject (blue.score.ScoreObject)8 ArrayList (java.util.ArrayList)8 Element (electric.xml.Element)7 Point (java.awt.Point)7 IOException (java.io.IOException)6 BlueData (blue.BlueData)5 Layer (blue.score.layers.Layer)5 NoteList (blue.soundObject.NoteList)5 ScoreController (blue.ui.core.score.ScoreController)5 HashMap (java.util.HashMap)5 SoundObjectLibrary (blue.SoundObjectLibrary)4 ScoreObjectLayer (blue.score.layers.ScoreObjectLayer)4 Document (electric.xml.Document)4 ParseException (electric.xml.ParseException)4 File (java.io.File)4 LiveObject (blue.blueLive.LiveObject)3