private static String filename;
private static long editPosition;
- private static boolean makeGUI = true, isEdited = false, drawEmptyTracks = false;
+ private static boolean makeGUI = true, initSound = true, isEdited = false, drawEmptyTracks = false;
private static Thread player;
public static final int DEFAULT_RESOLUTION = 96, DEFAULT_TRACKS = 4;
// Parses command-line arguments.
String fileArg = null;
for (int i = 0; i < args.length; i++) {
- if (args[i].equals("-n")) {makeGUI = false;}
- else if (fileArg == null) {fileArg = args[i];}
+ if (args[i].equals("-n")) makeGUI = false;
+ else if (args[i].equals("-m")) initSound = false;
+ else if (fileArg == null) fileArg = args[i];
}
// Acquires MIDI devices and connects them.
setActiveChannel(0);
} catch (MidiUnavailableException e) {
System.out.println("Failed, quitting.");
- // System.exit(1);
+ System.exit(1);
}
System.out.println("Done");
/* ***
- ** ACCESSOR METHODS **
- *** */
+ ** ACCESSOR METHODS **
+ *** */
return gui;
}
+ /**
+ * Calculates the position (measures, beats, ticks) in the current sequence for the given tick position.
+ * @return an array of integers where index 0 is measures, 1 is beats and 2 is ticks.
+ */
+ public static int[] getPositionForTick(long ticks) {
+ /*
+ int measures, beats, ticks;
+ for (int i = 0; i < timeSignatures.length; i++) {
+ long tick = timeSignatures[i].getTick();
+ // Split the ticks in the interval into measures, beats and ticks.
+ }
+ */
+ int[] pos = {1, 1, 1};
+ return pos;
+ }
+
/**
* Returns the receiver of the current sequencer.
* @return the receiver
// if (tempoMsg == null) return 0;
}
+ /**
+ * Calculates the tick position in the current sequence for the given position (measures, beats, ticks).
+ * @return the tick position.
+ */
+ public static long getTicksForPosition(int measures, int beats, int ticks) {
+ long tickPos = 0;
+ /*
+ for (int i = 0; i < timeSignatures.length; i++) {
+ long tick = timeSignatures[i].getTick();
+ // Add the measures, beats and ticks in the interval.
+ }
+ */
+ return tickPos;
+ }
+
/**
* Returns the tempo of the current sequence.
* @return the tick position
/* ***
- ** MUTATOR METHODS **
- *** */
+ ** MUTATOR METHODS **
+ *** */
public static void setTimeSig(int bpm) {
// timeSigMsg
}
+
+ public static void setTrackSolo(Track track, boolean on){
+ trackSolo.put(track, new Boolean(on));
+ }
+
+ public static void setTrackMute(Track track, boolean on){
+ trackMute.put(track, new Boolean(on));
+ }
/* ***
- ** PLAYBACK METHODS **
- *** */
+ ** PLAYBACK METHODS **
+ *** */
} catch (InvalidMidiDataException e) {}
Track[] tracks = seq.getTracks();
+ sequencer.start();
+
for (int i = 0; i < tracks.length; i++) {
Object ob = trackSolo.get(tracks[i]);
if(ob instanceof Boolean){
- System.out.println("Track solo " + i + "= "+ ob);
sequencer.setTrackSolo(i,((Boolean)ob).booleanValue());
}
ob = trackMute.get(tracks[i]);
if(ob instanceof Boolean){
- System.out.println("Track mute " + i + "= "+ ob);
sequencer.setTrackMute(i,((Boolean)ob).booleanValue());
}
}
- sequencer.start();
// Disables input to volatile components
// gui.disable();
/* ***
- ** SYSTEM & IO METHODS **
- *** */
+ ** SYSTEM & IO METHODS **
+ *** */
sequencer.setSequence(seq);
filename = null;
emptyTracks = new ArrayList();
+ trackSolo = new HashMap();
+ trackMute = new HashMap();
} catch (InvalidMidiDataException e) {}
// Sends sequence to GUI.
if (gui != null) gui.setSequence(seq);
if (noteOns.size() == 0) emptyTracks.add(tracks[i]);
// Sorts the note lists by tick position.
- Comparator c = new Comparator() {
- public int compare(Object o1, Object o2) {
- return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
- }
- };
+ Comparator c = new NoteComparator();
Collections.sort(noteOns, c);
Collections.sort(noteOffs, c);
if (off != null) {
tracks[i].add(new MooNote(on, off));
} else {
- tracks[i].add(new MooNote(on));
+ tracks[i].add(new MooNote(on, new MidiEvent((ShortMessage)on.getMessage().clone(), on.getTick() + 48)));
}
iOn.remove();
}
return true;
}
+ /**
+ * Prompts the user .
+ */
+ public static boolean promptOnUnsavedChanges() {
+ if (!isEdited) 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;
+ }
+
/**
* Saves the current sequence to the previously given filename.
*/
try {
MidiSystem.write(seq, 1, new File(file));
filename = file;
+ isEdited = false;
gui.setStatus("Saved " + file);
return true;
} catch (IOException e) {
* Releases all reserved devices and exits the program.
*/
public static void quit() {
- if (isEdited && gui != null) {
- int exitOption = JOptionPane.showConfirmDialog(gui,
- "The current sequence has been edited, but not saved.\nDo you wish to quit anyway?",
- "File not saved - really quit?",
- JOptionPane.OK_CANCEL_OPTION,
- JOptionPane.WARNING_MESSAGE);
- if (exitOption == JOptionPane.CANCEL_OPTION || exitOption == JOptionPane.CLOSED_OPTION) return;
+ if (gui != null) {
+ if (promptOnUnsavedChanges()) return;
}
if (sequencer.isOpen()) sequencer.close();
if (synthesizer.isOpen()) synthesizer.close();
System.exit(0);
}
- public static void setTrackSolo(Track track, boolean on){
- trackSolo.put(track, new Boolean(on));
- }
-
- public static void setTrackMute(Track track, boolean on){
- trackMute.put(track, new Boolean(on));
+ /**
+ * A Comparator for sorting lists of MidiEvents.
+ */
+ public static class NoteComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ return (int)(((MidiEvent)o1).getTick() - ((MidiEvent)o2).getTick());
+ }
}
}