+
+ private boolean isMidiFile(File f) {
+ if(f != null) {
+ String extension = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase().trim();
+ if (extension.equals("mid")) return true;
+ }
+ return false;
+ }
+ /**
+ * Gets the users command of takes and properiate action
+ * @param e The action perfomed.
+ */
+ public void actionPerformed(ActionEvent e) {
+ String command = e.getActionCommand();
+ Sequence seq;
+
+ if(command == "New") {
+ if (!Moosique.promptOnUnsavedChanges()) Moosique.clearSequence();
+ } else if (command == "Open...") {
+ // Shows a file chooser. If shown previously, starts in the current directory.
+ if (directory != null) {
+ chooser = new JFileChooser(directory);
+ } else {
+ chooser = new JFileChooser();
+ }
+ chooser.addChoosableFileFilter(new MidiFileFilter());
+ int returnVal = chooser.showOpenDialog(this);
+
+ // Stores the current directory and loads the selected file.
+ File file = chooser.getSelectedFile();
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
+ directory = chooser.getSelectedFile().getParentFile();
+ if (!Moosique.promptOnUnsavedChanges())
+ Moosique.load(chooser.getSelectedFile().getAbsolutePath());
+ }
+ } else if (command == "Save") {
+ if (!Moosique.save()) showSaveAsDialog();
+ } else if (command == "Save as...") {
+ showSaveAsDialog();
+ } else if (command == "Exit") {
+ Moosique.quit();
+ } else if (command == "Copy") {
+
+ } else if (command == "Cut") {
+
+ } else if (command == "Paste") {
+
+ } else if (command == "Select all") {
+
+ } else if (command == "Invert selection") {
+
+ } else if (command == "Preferences...") {
+
+ } else if (command == "Play") {
+ if (!Moosique.getSequencer().isRunning()) Moosique.play();
+ } else if (command == "Pause") {
+ if (Moosique.getSequencer().isRunning()) Moosique.pause();
+ } else if (command == "Stop") {
+ Moosique.stop();
+ } else if (command == "Set position...") {
+ MooDialog newDialog = new MooDialog(MooDialog.SET_POSITION);
+ // Moosique.setPosition(???); Räkna ut från msr, beats, ticks, time sig.
+ } else if (command.startsWith("Octave")) {
+ MooKeyboard.setOctave(Integer.parseInt(command.substring(7,8)));
+ } else if (command == "Add track...") {
+ MooDialog newDialog = new MooDialog(MooDialog.ADD_TRACK);
+ Moosique.getSequence().createTrack();
+ } else if (command == "Delete track...") {
+
+ MooDialog newDialog = new MooDialog(MooDialog.DELETE_TRACK);
+
+ /* Let the user select a track from a list.
+ seq = Moosique.getSequence();
+ seq.deleteTrack(seq.getTracks()[NUMBER]);
+ */
+ } else if (command == "Copy track...") {
+ MooDialog newDialog = new MooDialog(MooDialog.COPY_TRACK);
+ } else if (command == "Move track...") {
+ MooDialog newDialog = new MooDialog(MooDialog.MOVE_TRACK);
+ } else if (command == "Insert measure...") {
+ MooDialog newDialog = new MooDialog(MooDialog.INSERT_MEASURE);
+ } else if (command == "Delete measure...") {
+ MooDialog newDialog = new MooDialog(MooDialog.DELETE_MEASURE);
+ } else if (command == "Set time signature...") {
+
+ } else if (command == "Set tempo...") {
+ MooDialog newDialog = new MooDialog(MooDialog.SET_TEMPO);
+
+ } else if (command == "Scale velocity...") {
+ MooDialog newDialog = new MooDialog(MooDialog.SCALE_VELOCITY);
+
+ } else if (command == "Transpose...") {
+ MooDialog newDialog = new MooDialog(MooDialog.TRANSPOSE);
+
+ } else if (command == "User manual") {
+ MooDialog manual = new MooDialog(MooDialog.MANUAL);
+ } else if (command == "About") {
+ JOptionPane.showMessageDialog(null,
+ "Moosique\nversion 1.0\n\n© 2003\nRoland Andersson\nMichael Andreen\nBjörn Lanneskog\nEinar Pehrson",
+ "About Moosique",
+ JOptionPane.INFORMATION_MESSAGE,
+ new ImageIcon(Moosique.getGUI().logo));
+ }
+ }
+
+ private void showSaveAsDialog() {
+ // Shows a file chooser. If shown previously, starts in the current directory.
+ if (directory != null) {
+ chooser = new JFileChooser(directory);
+ } else {
+ chooser = new JFileChooser();
+ }
+ chooser.addChoosableFileFilter(new MidiFileFilter());
+ int returnVal = chooser.showSaveDialog(this);
+
+ // Stores the current directory and loads the selected file.
+ File file = chooser.getSelectedFile();
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
+ directory = file.getParentFile();
+ Moosique.saveAs(file.getAbsolutePath());
+ }
+ }
+
+ class MidiFileFilter extends javax.swing.filechooser.FileFilter {
+ public boolean accept(File f) {
+ if(f != null) {
+ if (f.isDirectory() || isMidiFile(f)) return true;
+ }
+ return false;
+ }
+
+ /**
+ * gets the description of the filetype
+ * @return "Midifiles the only filetyp compatibel with the program
+ */
+ public String getDescription() {
+ return "MIDI files";
+ }
+ }
+
+