From: Michael Andreen Date: Sun, 11 May 2003 19:21:54 +0000 (+0000) Subject: global keylistener.. X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=commitdiff_plain;h=ba84468acd609e00f4c2df575712b4ffd1399e58 global keylistener.. --- diff --git a/MooGUI.java b/MooGUI.java index 7019828..146ca6d 100644 --- a/MooGUI.java +++ b/MooGUI.java @@ -55,6 +55,19 @@ public class MooGUI extends JFrame { statusBar.setBackground(bgColor); view.setBackground(bgColor); + ActionMap am = getRootPane().getActionMap(); + + Action playAction = new AbstractAction() { + public void actionPerformed(ActionEvent ae) { + Moosique.resumepause(); + }}; + am.put("play", playAction); + + InputMap im = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + KeyStroke playKey = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0); + im.put(playKey, "play"); + + // Configures window. addWindowListener(new MooGUICloser()); pack(); @@ -74,7 +87,7 @@ public class MooGUI extends JFrame { comps[i].setBackground(bgColor); } } - + /** * Changes the sequence of the GUI. * @param sequence the MIDI sequence to visualize @@ -100,7 +113,7 @@ public class MooGUI extends JFrame { // Calls on the toolbar to update the progress indicator. //toolbar.updateProgInd(); } - + class MooGUICloser extends WindowAdapter { public void windowClosing(WindowEvent e) { Moosique.quit(); diff --git a/Moosique.java b/Moosique.java index 13d7ce6..5ee3bcc 100644 --- a/Moosique.java +++ b/Moosique.java @@ -22,6 +22,7 @@ public class Moosique { private static String filename, fileArg; private static long position; private static boolean makeGUI = true; + private static boolean playing = false; /** * Starts the application. @@ -146,6 +147,7 @@ public class Moosique { * Starts playback of the current sequence. */ public static void play() { + playing = true; sequencer.setTickPosition(position); sequencer.start(); } @@ -154,6 +156,7 @@ public class Moosique { * Pauses playback of the current sequence. */ public static void pause() { + playing = false; sequencer.stop(); } @@ -161,6 +164,7 @@ public class Moosique { * Resumes playback of the current sequence. */ public static void resume() { + playing = true; sequencer.start(); } @@ -168,10 +172,22 @@ public class Moosique { * Stops playback of the current sequence. */ public static void stop() { + playing = false; sequencer.stop(); sequencer.setTickPosition(position); } + /** + * Pauses if playing and resumes if stopped. + */ + public static void resumepause() + { + if (playing) + pause(); + else + resume(); + } + /** * Rewinds the current sequence the given number of measures. * @param measures the number of measures to rewind @@ -288,4 +304,4 @@ public class Moosique { if (synthesizer.isOpen()) synthesizer.close(); System.exit(0); } -} \ No newline at end of file +} diff --git a/To Do.txt b/To Do.txt index 73c80d9..1e1528c 100644 --- a/To Do.txt +++ b/To Do.txt @@ -131,6 +131,7 @@ MooGUI InputMap im = rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke helpKey = KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0); im.put(helpKey, "help"); + * Globala kommandon @@ -138,7 +139,8 @@ MooGUI Mappa F9-F12 till MooKeyboard.setOctave(n) där n = {2, 4, 6, 8} * Play / Stop - Mappa till blanksteg. + Mappa till blanksteg. <-- Detta fungerar inte.. blanksteget + används av vår toolbar. Moosique