+ try {seq = MidiSystem.getSequence(new File(filename));}
+ catch (Exception e) {return false;}
+ edited = false;
+
+ Track[] tracks = seq.getTracks();
+ emptyTracks = new ArrayList();
+ trackMute = new HashMap();
+ trackSolo = new HashMap();
+ copyBuffer = new ArrayList();
+
+ // Searches track 0 for changes in tempo and time signature.
+ MidiEvent event;
+ MetaMessage metaMsg;
+ ArrayList ts = new ArrayList(), tc = new ArrayList();
+ for (int i = 0; i < tracks[0].size(); i++) {
+ event = tracks[0].get(i);
+ if (event.getMessage().getStatus() == MetaMessage.META) {
+ metaMsg = (MetaMessage)event.getMessage();
+ switch(metaMsg.getType()) {
+ case 81: tc.add(event); break;
+ case 88: ts.add(event);
+ }
+ }
+ }
+ // timeSignatures = ts.toArray(timeSignatures);
+ // tempoChanges = tc.toArray(tempoChanges);
+
+ // Converts tracks.
+ for (int i = 0; i < tracks.length; i++) {
+ convertTrack(tracks[i], false);
+ }
+
+ // Sends sequence to GUI and sequencer, then returns
+ if (gui != null) gui.setSequence(seq);
+ try {
+ sequencer.setSequence(seq);
+ } catch (InvalidMidiDataException e) {}
+ return true;
+ }
+
+ /**
+ * Quantizes the given list of MIDI events
+ * @param notes a list of the notes to quantize
+ * @param resolution the note size to round each note to
+ * @param location whether the quantize should affect the location of the note
+ * @param duration whether the quantize should affect the duration of the note
+ */
+ public static void quantize(List notes, int resolution, boolean location, boolean duration) {
+ // Math.round(mn.getTick() / ticksPerSixteenth);
+ }
+
+ /**
+ * Loads the user preferences.
+ */
+ public static void loadPreferences() {
+
+ }
+
+ /**
+ * Saves the user preferences.
+ */
+ public static void savePreferences() {
+
+ }
+
+ /**
+ * Prompts the user .
+ */
+ public static boolean promptOnUnsavedChanges() {
+ if (!edited) return false;
+ int exitOption = JOptionPane.showConfirmDialog(gui,
+ "The current sequence has been edited, but not saved.\nDo you wish to continue anyway?",
+ "File not saved - continue?",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.WARNING_MESSAGE);
+ if (exitOption == JOptionPane.CANCEL_OPTION || exitOption == JOptionPane.CLOSED_OPTION) return true;
+ return false;