X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Moosique.java;h=5cf7af5b814f6c6eb07dcab4755d1bd894223f21;hb=a8b0b5e27d120df964c5b6d8554a6207951b00d0;hp=ee9a7453b492e35a0fba5f907b3d80eca856e67e;hpb=fbafab9c4127f793cfe955003860dcde0d6a0588;p=moosique.git diff --git a/Moosique.java b/Moosique.java index ee9a745..5cf7af5 100644 --- a/Moosique.java +++ b/Moosique.java @@ -28,7 +28,7 @@ public class Moosique { 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; @@ -44,8 +44,9 @@ public class Moosique { // 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. @@ -63,7 +64,7 @@ public class Moosique { setActiveChannel(0); } catch (MidiUnavailableException e) { System.out.println("Failed, quitting."); - // System.exit(1); + System.exit(1); } System.out.println("Done"); @@ -106,8 +107,8 @@ public class Moosique { /* *** - ** ACCESSOR METHODS ** - *** */ + ** ACCESSOR METHODS ** + *** */ @@ -156,6 +157,22 @@ public class Moosique { 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 @@ -189,6 +206,21 @@ public class Moosique { // 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 @@ -224,8 +256,8 @@ public class Moosique { /* *** - ** MUTATOR METHODS ** - *** */ + ** MUTATOR METHODS ** + *** */ @@ -296,6 +328,14 @@ public class Moosique { 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)); + } @@ -305,8 +345,8 @@ public class Moosique { /* *** - ** PLAYBACK METHODS ** - *** */ + ** PLAYBACK METHODS ** + *** */ @@ -333,22 +373,21 @@ public class Moosique { } 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(); @@ -405,8 +444,8 @@ public class Moosique { /* *** - ** SYSTEM & IO METHODS ** - *** */ + ** SYSTEM & IO METHODS ** + *** */ @@ -425,6 +464,8 @@ public class Moosique { 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); @@ -574,12 +615,4 @@ public class Moosique { 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)); - } }