diff --git a/MainWindow.fxml b/MainWindow.fxml index 37408320..7b9c6ba5 100644 --- a/MainWindow.fxml +++ b/MainWindow.fxml @@ -80,7 +80,7 @@ - + diff --git a/README.md b/README.md index 1bf7a99d..0460bd4e 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,8 @@ Tasklist: * Volume bars implemented (done - December 17, 2013) * Save & Load songs (done - December 18, 2013) * Loop button loops the song (done - December 18, 2013) -* End-of-File Behaviour fix -* Release to a smallish test group (v0.9 - **Alpha Release** - Scheduled December 25, 2013) +* End-of-File Behaviour fix (done - December 25, 2013) +* Release to a smallish test group (v0.9 - **Alpha Release** - December 25, 2013) * Measure line numbers * Staff extension lines * Splash screen is actually a splash screen diff --git a/src/smp/SuperMarioPaint.java b/src/smp/SuperMarioPaint.java index f03cc8a1..e35b6b12 100644 --- a/src/smp/SuperMarioPaint.java +++ b/src/smp/SuperMarioPaint.java @@ -5,21 +5,13 @@ import java.net.MalformedURLException; import javafx.application.Application; -import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; -import javafx.geometry.Pos; import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.control.Label; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyEvent; -import javafx.scene.layout.FlowPane; -import javafx.scene.layout.VBox; import javafx.stage.Stage; -import javafx.stage.StageStyle; -import javafx.stage.WindowEvent; import smp.fx.SMPFXController; import smp.fx.SplashScreen; import smp.stateMachine.Settings; @@ -37,7 +29,7 @@ * The GUI is primarily written with JavaFX2.2.
* @author RehdBlob * @since 2012.08.16 - * @version 0.85 + * @version 0.90 */ public class SuperMarioPaint extends Application { diff --git a/src/smp/components/Values.java b/src/smp/components/Values.java index 5fb7c297..a2df29b6 100644 --- a/src/smp/components/Values.java +++ b/src/smp/components/Values.java @@ -12,7 +12,7 @@ public class Values { /** The current version number of the program. */ - public static double VERSION = 0.85; + public static double VERSION = 0.90; /** The number of instruments. */ public static int NUMINSTRUMENTS = 19; @@ -72,7 +72,7 @@ public class Values { * The number of lines in the staff, by default. This number * is typically 384. */ - public static int DEFAULT_LINES_PER_SONG = 384; + public static int DEFAULT_LINES_PER_SONG = 400; /** The default speed. */ public static int DEFAULT_TEMPO = 400; diff --git a/src/smp/components/controls/LoadButton.java b/src/smp/components/controls/LoadButton.java index d7186fe4..9f03c3e4 100644 --- a/src/smp/components/controls/LoadButton.java +++ b/src/smp/components/controls/LoadButton.java @@ -1,5 +1,6 @@ package smp.components.controls; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -7,9 +8,11 @@ import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; +import javafx.stage.FileChooser; import smp.components.general.ImagePushButton; import smp.components.staff.Staff; import smp.components.staff.sequences.StaffSequence; +import smp.fx.Dialog; import smp.fx.SMPFXController; import smp.stateMachine.StateMachine; @@ -52,26 +55,43 @@ public void setStaff(Staff s) { /** This loads the song. */ private void load() { - try { - String outputFile = SMPFXController.getSongName().getText(); - outputFile = outputFile + ".txt"; - FileInputStream f_in = new - FileInputStream (outputFile); - ObjectInputStream o_in = new - ObjectInputStream(f_in); - StaffSequence loaded = (StaffSequence) o_in.readObject(); - theStaff.setSequence(loaded); - StateMachine.setTempo(loaded.getTempo()); - theStaff.getControlPanel().updateCurrTempo(); - theStaff.getNoteMatrix().redraw(); - o_in.close(); - f_in.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); + boolean cont = true; + if (StateMachine.isModified()) + cont = Dialog.showYesNoDialog("The current song has been modified!\n" + + "Load the song anyway?"); + if (cont) { + try { + FileChooser f = new FileChooser(); + f.setInitialDirectory(new File(System.getProperty("user.dir"))); + File inputFile = f.showOpenDialog(null); + if (inputFile == null) + return; + FileInputStream f_in = new + FileInputStream (inputFile); + ObjectInputStream o_in = new + ObjectInputStream(f_in); + StaffSequence loaded = (StaffSequence) o_in.readObject(); + theStaff.setSequence(loaded); + StateMachine.setTempo(loaded.getTempo()); + theStaff.getControlPanel().updateCurrTempo(); + theStaff.getNoteMatrix().redraw(); + o_in.close(); + f_in.close(); + String fname = inputFile.getName(); + try { + fname = fname.substring(0, fname.indexOf(".")); + } catch (IndexOutOfBoundsException e) { + + } + SMPFXController.getSongName().setText(fname); + StateMachine.setModified(false); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } } } diff --git a/src/smp/components/controls/MuteInstButton.java b/src/smp/components/controls/MuteInstButton.java index 47c659c0..8ceab923 100644 --- a/src/smp/components/controls/MuteInstButton.java +++ b/src/smp/components/controls/MuteInstButton.java @@ -3,7 +3,6 @@ import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import smp.ImageIndex; -import smp.components.general.ImageRadioButton; import smp.components.general.ImageToggleButton; import smp.stateMachine.StateMachine; diff --git a/src/smp/components/controls/NewButton.java b/src/smp/components/controls/NewButton.java index 7f0e79b4..c6d61ae6 100644 --- a/src/smp/components/controls/NewButton.java +++ b/src/smp/components/controls/NewButton.java @@ -1,8 +1,5 @@ package smp.components.controls; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import smp.components.general.ImagePushButton; @@ -63,6 +60,7 @@ private void newSong() { if (cont) { theStaff.setSequence(new StaffSequence()); theStaff.getNoteMatrix().redraw(); + StateMachine.setModified(false); } } diff --git a/src/smp/components/controls/SaveButton.java b/src/smp/components/controls/SaveButton.java index d5ce8bf7..a50b6dc9 100644 --- a/src/smp/components/controls/SaveButton.java +++ b/src/smp/components/controls/SaveButton.java @@ -1,5 +1,6 @@ package smp.components.controls; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; @@ -8,12 +9,13 @@ import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; +import javafx.stage.FileChooser; +import javafx.stage.FileChooser.ExtensionFilter; import smp.components.Values; import smp.components.general.ImagePushButton; import smp.components.staff.Staff; import smp.components.staff.sequences.StaffNoteLine; import smp.components.staff.sequences.StaffSequence; -import smp.fx.Dialog; import smp.fx.SMPFXController; import smp.stateMachine.StateMachine; @@ -31,7 +33,7 @@ public class SaveButton extends ImagePushButton { * Sort of hacky move here, but we're going to save a few songs * in a different format, so this exists. */ - private boolean saveTxt = true; + private boolean saveTxt = false; /** This is the staff that we want to save a song from. */ private Staff theStaff; @@ -70,7 +72,6 @@ private void save() { } else { saveTxt(); } - Dialog.showDialog("Song saved!"); } @@ -81,10 +82,16 @@ private void save() { */ private void saveObject() { try { - String outputFile = SMPFXController.getSongName().getText(); - outputFile = outputFile + ".txt"; + FileChooser f = new FileChooser(); + f.setInitialDirectory(new File(System.getProperty("user.dir"))); + f.setInitialFileName(SMPFXController.getSongName().getText()); + f.getExtensionFilters().add(new ExtensionFilter( + "Text file", "*.txt")); + File outputFile = f.showSaveDialog(null); + if (outputFile == null) + return; FileOutputStream f_out = new - FileOutputStream("./" + outputFile); + FileOutputStream(outputFile); ObjectOutputStream o_out = new ObjectOutputStream(f_out); StaffSequence out = theStaff.getSequence(); @@ -92,7 +99,7 @@ private void saveObject() { o_out.writeObject(out); o_out.close(); f_out.close(); - + StateMachine.setModified(false); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/src/smp/components/staff/Staff.java b/src/smp/components/staff/Staff.java index 81844d4e..1f99bc49 100644 --- a/src/smp/components/staff/Staff.java +++ b/src/smp/components/staff/Staff.java @@ -17,7 +17,6 @@ import smp.components.staff.sequences.StaffNote; import smp.components.staff.sequences.StaffNoteLine; import smp.components.staff.sequences.StaffSequence; -import smp.components.staff.sounds.SMPSequencer; import smp.fx.SMPFXController; import smp.stateMachine.Settings; import smp.stateMachine.StateMachine; @@ -388,13 +387,13 @@ class AnimationTask extends Task { protected Staff call() throws Exception { playBars = staffImages.getPlayBars(); currMeasureLine = StateMachine.getMeasureLineNum(); - int counter = 0; + int counter = currMeasureLine; do { playNextLine(); counter++; if (counter % Values.NOTELINES_IN_THE_WINDOW == 0) currMeasureLine += Values.NOTELINES_IN_THE_WINDOW; - if (counter % 4 == 0 && counter >= lastLine) { + if (counter % 4 == 0 && counter > lastLine) { if (StateMachine.isLoopPressed()) { currMeasureLine = 0; counter = 0; diff --git a/src/smp/components/staff/StaffInstrumentEventHandler.java b/src/smp/components/staff/StaffInstrumentEventHandler.java index 8e0067a8..948a84dc 100644 --- a/src/smp/components/staff/StaffInstrumentEventHandler.java +++ b/src/smp/components/staff/StaffInstrumentEventHandler.java @@ -164,10 +164,15 @@ private void placeNote(InstrumentIndex theInd) { theStaffNote.setImage( ImageLoader.getSpriteFX( theInd.imageIndex())); - } else { + } else if (mute) { theStaffNote.setImage( ImageLoader.getSpriteFX( theInd.imageIndex().alt())); + } else if (muteA) { + theStaffNote.setImage( + ImageLoader.getSpriteFX( + theInd.imageIndex().silhouette())); + } else if (muteA) { } accidental = new StaffAccidental(theStaffNote); diff --git a/src/smp/fx/Dialog.java b/src/smp/fx/Dialog.java index e3b6092b..0223f1b1 100644 --- a/src/smp/fx/Dialog.java +++ b/src/smp/fx/Dialog.java @@ -3,16 +3,13 @@ import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; -import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.FlowPane; import javafx.scene.layout.VBox; -import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.stage.StageStyle; -import javafx.stage.WindowEvent; /** * Generates a dialog box, depending on what we do. @@ -27,17 +24,36 @@ public class Dialog { /** * Shows a dialog box with the text given to this method. - * @param s The text to show. + * @param txt The text to show. */ - public static void showDialog(String s) { - Stage dialog = new Stage(); + public static void showDialog(String txt) { + final Stage dialog = new Stage(); + dialog.setHeight(150); + dialog.setWidth(250); dialog.setResizable(false); - dialog.setHeight(100); - dialog.setWidth(100); dialog.initStyle(StageStyle.UTILITY); - Scene scene = new Scene(new Group(new Text(10, 30, s))); - dialog.setScene(scene); - dialog.show(); + Label label = new Label(txt); + Button okButton = new Button("OK"); + + okButton.setOnAction(new EventHandler() { + + @Override + public void handle(ActionEvent event) { + dialog.close(); + } + + }); + + FlowPane pane = new FlowPane(10, 10); + pane.setAlignment(Pos.CENTER); + pane.getChildren().addAll(okButton); + VBox vBox = new VBox(10); + vBox.setAlignment(Pos.CENTER); + vBox.getChildren().addAll(label, pane); + Scene scene1 = new Scene(vBox); + dialog.setScene(scene1); + dialog.showAndWait(); + } /** @@ -83,7 +99,6 @@ public void handle(ActionEvent event) { Scene scene1 = new Scene(vBox); dialog.setScene(scene1); dialog.showAndWait(); - System.out.println(choice); return choice; }