Skip to content

Commit

Permalink
Default address to 0x01, clean up preferences saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammy1Am committed May 4, 2018
1 parent 12514cc commit 5e1c413
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Arduino/Moppy/MoppyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ public void run() {
}
});

//
//// Load Settings / Defaults
//

//mappers.addMapper(new MIDIScriptMapper());

//
//// Initialize and start the UI
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class MoppyConfig {
private String fileLoadDirectory = ".";
private List<MIDIScriptMapperConfig> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<Events>
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
</Events>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -92,6 +97,11 @@ private void initComponents() {
pack();
}// </editor-fold>//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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public void loadMappersFromConfig(List<MIDIScriptMapperConfig> configList) {
public void saveMappersToConfig() {
List<MIDIScriptMapperConfig> 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);
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 5e1c413

Please sign in to comment.