Search in sources :

Example 1 with Library

use of blue.library.Library 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 2 with Library

use of blue.library.Library 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)

Aggregations

Library (blue.library.Library)2 SoundObject (blue.soundObject.SoundObject)2 UDOLibrary (blue.udo.UDOLibrary)2 EnvironmentVars (blue.utility.EnvironmentVars)2 FileUtilities (blue.utility.FileUtilities)2 ObjectUtilities (blue.utility.ObjectUtilities)2 Document (electric.xml.Document)2 ParseException (electric.xml.ParseException)2 Image (java.awt.Image)2 Toolkit (java.awt.Toolkit)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 Locale (java.util.Locale)2 Map (java.util.Map)2 MissingResourceException (java.util.MissingResourceException)2 ResourceBundle (java.util.ResourceBundle)2 JMenuItem (javax.swing.JMenuItem)2