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));
}
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;
}
Aggregations