Skip to content

Commit

Permalink
Fix bugs with arranger loading & saving
Browse files Browse the repository at this point in the history
  • Loading branch information
DC37 committed Jan 7, 2015
1 parent bfa9714 commit 8c797d2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Version History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.951 (Semantic version 0.12.1) [current]
Fix bugs with arranger loading/saving.

v0.95 (Semantic version 0.12.0) [current]
Beta release - major functionality should be equivalent to and/or exceed that of MPC2.0.
Added more support for external soundfonts (two instruments that used to be swapped are not swapped anymore)
Expand Down
10 changes: 6 additions & 4 deletions src/smp/components/buttons/LoadButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ private void loadSong() {
return;
init = new File(inputFile.getParent());
StaffSequence loaded = Utilities.loadSong(inputFile);
Utilities.populateStaff(loaded, inputFile, false, theStaff,
controller);
String fname = Utilities.populateStaff(loaded, inputFile,
false, theStaff, controller);
controller.getNameTextField().setText(fname);
StateMachine.setSongModified(false);
} catch (ClassCastException | EOFException | ClassNotFoundException
| StreamCorruptedException e) {
try {
StaffSequence loaded = MPCDecoder.decode(inputFile);
Utilities.populateStaff(loaded, inputFile, true, theStaff,
controller);
String fname = Utilities.populateStaff(loaded, inputFile,
true, theStaff, controller);
controller.getNameTextField().setText(fname);
StateMachine.setSongModified(false);
} catch (Exception e1) {
e1.printStackTrace();
Expand Down
42 changes: 29 additions & 13 deletions src/smp/components/general/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,25 @@ public static void loadSequenceFromArrangement(File inputFile,
inputFile = new File(Values.SONGFOLDER + inputFile.getName());
StaffSequence loaded = loadSong(inputFile);
populateStaff(loaded, inputFile, false, theStaff, controller);
} catch (ClassCastException | EOFException | StreamCorruptedException e) {
} catch (ClassCastException | EOFException | StreamCorruptedException
| ClassNotFoundException e) {
try {
StaffSequence loaded = MPCDecoder.decode(inputFile);
Utilities.populateStaff(loaded, inputFile, true, theStaff,
controller);
} catch (Exception e1) {
e1.printStackTrace();
Dialog.showDialog("Not a valid song file.");
return;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Dialog.showDialog("Not a valid song file.");
return;
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
Dialog.showDialog("Not a valid song file.");
return;
}
}

Expand All @@ -243,7 +247,7 @@ public static void loadSequenceFromArrangement(File inputFile,
* @param mpc
* Whether this is an MPC file.
*/
public static void populateStaff(StaffSequence loaded, File inputFile,
public static String populateStaff(StaffSequence loaded, File inputFile,
boolean mpc, Staff theStaff, SMPFXController controller) {
Utilities.normalize(loaded);
theStaff.setSequence(loaded);
Expand All @@ -269,16 +273,18 @@ public static void populateStaff(StaffSequence loaded, File inputFile,
// Do nothing
}
theStaff.setSequenceName(fname);
controller.getNameTextField().setText(fname);
theStaff.getTopPanel().getButtonLine().setNoteExtension(loaded.getNoteExtensions());
theStaff.getTopPanel().getButtonLine()
.setNoteExtension(loaded.getNoteExtensions());
return fname;
}

public static void populateStaffArrangement(StaffArrangement loaded, File inputFile,
boolean mpc, Staff theStaff, SMPFXController controller) {
public static void populateStaffArrangement(StaffArrangement loaded,
File inputFile, boolean mpc, Staff theStaff,
SMPFXController controller) {
File firstFile = loaded.getTheSequenceFiles().get(0);
loadSequenceFromArrangement(firstFile, theStaff,
controller);
loadSequenceFromArrangement(firstFile, theStaff, controller);
String fname = inputFile.getName();
controller.getNameTextField().setText(fname);
try {
if (mpc)
fname = fname.substring(0, fname.indexOf(']'));
Expand All @@ -297,11 +303,21 @@ public static void populateStaffArrangement(StaffArrangement loaded, File inputF
ArrayList<StaffSequence> seq = new ArrayList<StaffSequence>();
for (int i = 0; i < files.size(); i++) {
try {
seq.add(MPCDecoder.decode(files.get(i)));
} catch (IOException e) {
seq.add(Utilities.loadSong(files.get(i)));
} catch (ClassCastException | EOFException
| StreamCorruptedException | ClassNotFoundException e) {
try {
seq.add(MPCDecoder.decode(files.get(i)));
} catch (Exception e1) {
e1.printStackTrace();
return;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (ParseException e) {
return;
} catch (IOException e) {
e.printStackTrace();
return;
}
}
theStaff.getArrangement().setTheSequences(seq);
Expand Down

0 comments on commit 8c797d2

Please sign in to comment.