From 5e1c4136c3a3dafb312ad6920d3e39a11bb679c5 Mon Sep 17 00:00:00 2001 From: SammyIAm Date: Thu, 3 May 2018 21:50:02 -0700 Subject: [PATCH] Default address to 0x01, clean up preferences saving --- Arduino/Moppy/MoppyConfig.h | 2 +- .../com/moppy/control/MoppyControlGUI.java | 6 ------ .../com/moppy/control/config/MoppyConfig.java | 5 +++++ .../com/moppy/control/gui/MainWindow.form | 3 +++ .../com/moppy/control/gui/MainWindow.java | 10 +++++++++ .../mapperpanel/MapperCollectionPanel.java | 6 ++++-- .../control/gui/mapperpanel/MapperPanel.java | 21 +++++++------------ 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Arduino/Moppy/MoppyConfig.h b/Arduino/Moppy/MoppyConfig.h index 0cc0a9a..4d87a60 100644 --- a/Arduino/Moppy/MoppyConfig.h +++ b/Arduino/Moppy/MoppyConfig.h @@ -18,7 +18,7 @@ #define PLAY_STARTUP_SOUND true // Device address information -#define DEVICE_ADDRESS 0x02 +#define DEVICE_ADDRESS 0x01 #define MIN_SUB_ADDRESS 1 #define MAX_SUB_ADDRESS 8 diff --git a/Java/MoppyControlGUI/src/main/java/com/moppy/control/MoppyControlGUI.java b/Java/MoppyControlGUI/src/main/java/com/moppy/control/MoppyControlGUI.java index 575db75..b296c37 100644 --- a/Java/MoppyControlGUI/src/main/java/com/moppy/control/MoppyControlGUI.java +++ b/Java/MoppyControlGUI/src/main/java/com/moppy/control/MoppyControlGUI.java @@ -62,12 +62,6 @@ public void run() { } }); - // - //// Load Settings / Defaults - // - - //mappers.addMapper(new MIDIScriptMapper()); - // //// Initialize and start the UI // diff --git a/Java/MoppyControlGUI/src/main/java/com/moppy/control/config/MoppyConfig.java b/Java/MoppyControlGUI/src/main/java/com/moppy/control/config/MoppyConfig.java index e699112..2e7f3e6 100644 --- a/Java/MoppyControlGUI/src/main/java/com/moppy/control/config/MoppyConfig.java +++ b/Java/MoppyControlGUI/src/main/java/com/moppy/control/config/MoppyConfig.java @@ -16,6 +16,11 @@ public class MoppyConfig { private String fileLoadDirectory = "."; private List mapperConfigs = new ArrayList<>(); + public MoppyConfig() { + // Add a new default mapper (will be overridden if the user loads preferences) + mapperConfigs.add(new MIDIScriptMapperConfig()); + } + @Data public static class MIDIScriptMapperConfig { private String conditionChoice = ConditionScripts.ALL_EVENTS.displayName(); diff --git a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.form b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.form index d7e3e7a..4d52421 100644 --- a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.form +++ b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.form @@ -15,6 +15,9 @@ + + + diff --git a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.java b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.java index baeed84..a017d88 100644 --- a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.java +++ b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/MainWindow.java @@ -51,6 +51,11 @@ private void initComponents() { setTitle("Moppy Control"); setMinimumSize(new java.awt.Dimension(1024, 600)); setSize(new java.awt.Dimension(800, 600)); + addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent evt) { + formWindowClosing(evt); + } + }); sequencerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); @@ -92,6 +97,11 @@ private void initComponents() { pack(); }// //GEN-END:initComponents + private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing + // Save our mappers before closing + mapperCollectionPanel.saveMappersToConfig(); + }//GEN-LAST:event_formWindowClosing + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane1; diff --git a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperCollectionPanel.java b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperCollectionPanel.java index 9b16167..e63eedd 100644 --- a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperCollectionPanel.java +++ b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperCollectionPanel.java @@ -45,7 +45,9 @@ public void loadMappersFromConfig(List configList) { public void saveMappersToConfig() { List configList = Stream.of(this.getComponents()) .filter(c -> c instanceof MapperPanel) - .map(mp -> {return ((MapperPanel)mp).getMapperConfig();}) + .map(mp -> { + MapperPanel panel = (MapperPanel)mp; + return ((MapperPanel)mp).getMapperConfig();}) .collect(Collectors.toList()); MoppyPreferences.getConfiguration().setMapperConfigs(configList); @@ -110,7 +112,7 @@ public void receiveUpdate(StatusUpdate update) { switch (update.getType()) { case SEQUENCE_START: enableMapperEditing(false); - saveMappersToConfig(); // TODO: This might be a slightly awkward place to save configs, but it'll do for now. + saveMappersToConfig(); // Go ahead and proactively save the mappers when we start playing break; case SEQUENCE_END: case SEQUENCE_PAUSE: diff --git a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperPanel.java b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperPanel.java index 1744272..751c1cc 100644 --- a/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperPanel.java +++ b/Java/MoppyControlGUI/src/main/java/com/moppy/control/gui/mapperpanel/MapperPanel.java @@ -70,19 +70,14 @@ public MIDIScriptMapper getMapper() { } public MIDIScriptMapperConfig getMapperConfig() { - return mapperConfig; - } - - private void saveToConfig() { + // First update the config with the currently selected items (don't do this + // in real-time so that programatic menu-selections don't overwrite user choices mapperConfig.setConditionChoice(conditionComboBox.getSelectedItem().toString()); - mapperConfig.setConditionCustomScript(conditionTextArea.getText()); mapperConfig.setDeviceAddressChoice(deviceAddressComboBox.getSelectedItem().toString()); - mapperConfig.setDeviceAddressCustomScript(deviceAddressTextArea.getText()); mapperConfig.setSubAddressChoice(subAddressComboBox.getSelectedItem().toString()); - mapperConfig.setSubAddressCustomScript(subAddressTextArea.getText()); mapperConfig.setNoteChoice(noteComboBox.getSelectedItem().toString()); - mapperConfig.setNoteCustomScript(noteTextArea.getText()); - mapperPanel.saveMappersToConfig(); + + return mapperConfig; } public void enableEditing(boolean enable) { @@ -391,7 +386,7 @@ private void deleteMapperButtonActionPerformed(java.awt.event.ActionEvent evt) { private void conditionTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_conditionTextAreaFocusLost try { mapper.setConditionScript(conditionTextArea.getText()); - saveToConfig(); + mapperConfig.setConditionCustomScript(conditionTextArea.getText()); conditionTextArea.setForeground(Color.BLACK); } catch (ScriptException ex) { Logger.getLogger(MapperPanel.class.getName()).log(Level.WARNING, null, ex); @@ -402,7 +397,7 @@ private void conditionTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FI private void deviceAddressTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_deviceAddressTextAreaFocusLost try { mapper.setDeviceAddressScript(deviceAddressTextArea.getText()); - saveToConfig(); + mapperConfig.setDeviceAddressCustomScript(deviceAddressTextArea.getText()); deviceAddressTextArea.setForeground(Color.BLACK); } catch (ScriptException ex) { Logger.getLogger(MapperPanel.class.getName()).log(Level.WARNING, null, ex); @@ -413,7 +408,7 @@ private void deviceAddressTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GE private void subAddressTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_subAddressTextAreaFocusLost try { mapper.setSubAddressScript(subAddressTextArea.getText()); - saveToConfig(); + mapperConfig.setSubAddressCustomScript(subAddressTextArea.getText()); subAddressTextArea.setForeground(Color.BLACK); } catch (ScriptException ex) { Logger.getLogger(MapperPanel.class.getName()).log(Level.WARNING, null, ex); @@ -424,7 +419,7 @@ private void subAddressTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-F private void noteTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_noteTextAreaFocusLost try { mapper.setNoteScript(noteTextArea.getText()); - saveToConfig(); + mapperConfig.setNoteCustomScript(noteTextArea.getText()); noteTextArea.setForeground(Color.BLACK); } catch (ScriptException ex) { Logger.getLogger(MapperPanel.class.getName()).log(Level.WARNING, null, ex);