diff --git a/java/src/pm/Device.java b/java/src/pm/Device.java index 0c84f5a..53c152a 100644 --- a/java/src/pm/Device.java +++ b/java/src/pm/Device.java @@ -33,17 +33,17 @@ public abstract class Device { protected void add(Sequence startSequence, Sequence stopSequence, Continuous continuous) { add(startSequence, continuous); - add(stopSequence, new Stopper(continuous)); + add(stopSequence, new Stopper(continuous)); } protected void add(Event startEvent, Event stopEvent, Continuous continuous) { add(startEvent, continuous); - add(stopEvent, new Stopper(continuous)); + add(stopEvent, new Stopper(continuous)); } protected void add(Press startPress, Press stopPress, Continuous continuous) { add(new Macro(startPress), continuous); - add(new Macro(stopPress), new Stopper(continuous)); + add(new Macro(stopPress), new Stopper(continuous)); } protected void add(Hold hold, Continuous continuous) { diff --git a/java/src/pm/Task.java b/java/src/pm/Task.java index 5f0dbc4..e426e6f 100644 --- a/java/src/pm/Task.java +++ b/java/src/pm/Task.java @@ -8,6 +8,10 @@ public class Task { this.action = action; this.target = target; } + + public Task(Action action) { + this(action, Target.MAIN); + } public Action getAction() { return action; diff --git a/java/src/pm/application/Winamp/WinampApplication.java b/java/src/pm/application/Winamp/WinampApplication.java index 5b3a920..220f1c4 100644 --- a/java/src/pm/application/Winamp/WinampApplication.java +++ b/java/src/pm/application/Winamp/WinampApplication.java @@ -52,13 +52,7 @@ public class WinampApplication extends Application { WinampController.rew5Secs(); break; case MUTE: - if(muted) { - WinampController.setVolume(volume); - } else { - volume = WinampController.getVolume(); - WinampController.setVolume(0); - } - muted = !muted; + toggleMute(); break; case VOLUME_UP: WinampController.increaseVolume(); @@ -67,7 +61,16 @@ public class WinampApplication extends Application { WinampController.decreaseVolume(); break; } - } catch (InvalidHandle e) { + } catch (InvalidHandle e) {} + } + + protected void toggleMute() throws InvalidHandle { + if (!muted) { + volume = WinampController.getVolume(); + } + try { + WinampController.setVolume(muted ? volume : 0); } catch (InvalidParameter e) {} + muted = !muted; } } diff --git a/java/src/pm/device/gui/GUIDevice.java b/java/src/pm/device/gui/GUIDevice.java index ecc299a..3814b77 100644 --- a/java/src/pm/device/gui/GUIDevice.java +++ b/java/src/pm/device/gui/GUIDevice.java @@ -2,8 +2,7 @@ package pm.device.gui; import pm.Device; -public class GUIDevice extends Device { - +public class GUIDevice extends Device { protected GUIDeviceUI gui; public GUIDevice() { diff --git a/java/src/pm/device/gui/GUIDeviceUI.java b/java/src/pm/device/gui/GUIDeviceUI.java index eb2b572..d2c9da4 100644 --- a/java/src/pm/device/gui/GUIDeviceUI.java +++ b/java/src/pm/device/gui/GUIDeviceUI.java @@ -7,27 +7,28 @@ import javax.swing.JButton; import javax.swing.JFrame; import pm.Action; import pm.Target; -import pm.task.ActionProvider; +import pm.Task; +import pm.task.TaskGatherer; import layout.TableLayout; import layout.TableLayoutConstraints; public class GUIDeviceUI extends JFrame { - private static final long serialVersionUID = 1L; + protected static final long serialVersionUID = 1L; - private JButton play; - private JButton pause; - private JButton resume; - private JButton next; - private JButton previous; - private JButton forward; - private JButton rewind; - private JButton mute; - private JButton volumeUp; - private JButton volumeDown; + protected JButton play; + protected JButton pause; + protected JButton resume; + protected JButton next; + protected JButton previous; + protected JButton forward; + protected JButton rewind; + protected JButton mute; + protected JButton volumeUp; + protected JButton volumeDown; - //ActionProvider.add + //TaskGatherer.add public GUIDeviceUI() { initComponents(); setSize(30, 300); @@ -155,43 +156,43 @@ public class GUIDeviceUI extends JFrame { add(volumeDown, new TableLayoutConstraints(0, 9, 0, 9, TableLayoutConstraints.FULL, TableLayoutConstraints.FULL)); } - private void playAction(ActionEvent e) { - ActionProvider.add(Action.PLAY.setTarget(Target.APPLICATION)); + protected void playAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.PLAY, Target.APPLICATION)); } - private void pauseAction(ActionEvent e) { - ActionProvider.add(Action.PAUSE.setTarget(Target.APPLICATION)); + protected void pauseAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.PAUSE, Target.APPLICATION)); } - private void resumeAction(ActionEvent e) { - ActionProvider.add(Action.RESUME.setTarget(Target.APPLICATION)); + protected void resumeAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.RESUME, Target.APPLICATION)); } - private void nextAction(ActionEvent e) { - ActionProvider.add(Action.NEXT.setTarget(Target.APPLICATION)); + protected void nextAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.NEXT, Target.APPLICATION)); } - private void previousAction(ActionEvent e) { - ActionProvider.add(Action.PREVIOUS.setTarget(Target.APPLICATION)); + protected void previousAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.PREVIOUS, Target.APPLICATION)); } - private void forwardAction(ActionEvent e) { - ActionProvider.add(Action.FORWARD.setTarget(Target.APPLICATION)); + protected void forwardAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.FORWARD, Target.APPLICATION)); } - private void rewindAction(ActionEvent e) { - ActionProvider.add(Action.REWIND.setTarget(Target.APPLICATION)); + protected void rewindAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.REWIND, Target.APPLICATION)); } - private void muteAction(ActionEvent e) { - ActionProvider.add(Action.MUTE.setTarget(Target.APPLICATION)); + protected void muteAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.MUTE, Target.APPLICATION)); } - private void volumeUpAction(ActionEvent e) { - ActionProvider.add(Action.VOLUME_UP.setTarget(Target.APPLICATION)); + protected void volumeUpAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.VOLUME_UP, Target.APPLICATION)); } - private void volumeDownAction(ActionEvent e) { - ActionProvider.add(Action.VOLUME_DOWN.setTarget(Target.APPLICATION)); + protected void volumeDownAction(ActionEvent e) { + TaskGatherer.add(new Task(Action.VOLUME_DOWN, Target.APPLICATION)); } } diff --git a/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java b/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java index 3ef232e..6ab9b02 100644 --- a/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java +++ b/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java @@ -12,6 +12,7 @@ import pm.exception.event.UnknownDirectionException; import pm.macro.event.Hold; import pm.macro.event.Press; import pm.task.Continuous; +import pm.task.Dynamic; import de.hardcode.jxinput.event.JXInputButtonEvent; import de.hardcode.jxinput.event.JXInputDirectionalEvent; @@ -37,12 +38,10 @@ public class RumblepadDevice extends JavaInputDevice { new Task(Action.PREVIOUS, Target.APPLICATION)); add( new Hold(RumblepadButton.FIVE), - new Continuous(Action.FORWARD, Target.APPLICATION, 200){ - public int getSleep() {return sleep - 30 * iteration;}}); + new Dynamic(Action.FORWARD, Target.APPLICATION, 200, -30)); add( new Hold(RumblepadButton.SEVEN), - new Continuous(Action.REWIND, Target.APPLICATION, 200){ - public int getSleep() {return sleep - 30 * iteration;}}); + new Dynamic(Action.REWIND, Target.APPLICATION, 200, -30)); add( new Hold(RumblepadButton.NINE), new Continuous(Action.VOLUME_DOWN, Target.APPLICATION, 100)); diff --git a/java/src/pm/device/jintellitype/JIntellitypeDevice.java b/java/src/pm/device/jintellitype/JIntellitypeDevice.java index 1262d67..d0ced27 100644 --- a/java/src/pm/device/jintellitype/JIntellitypeDevice.java +++ b/java/src/pm/device/jintellitype/JIntellitypeDevice.java @@ -56,7 +56,7 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell public void onHotKey(int id) { Hotkey hotkey = hotkeyList.get(id); add(hotkeyList.get(id)); - add(new Release(hotkey.getButton())); + add(new Release(hotkey.getButton())); } public void exit() { diff --git a/java/src/pm/task/Continuous.java b/java/src/pm/task/Continuous.java index 8d8d303..3768a95 100644 --- a/java/src/pm/task/Continuous.java +++ b/java/src/pm/task/Continuous.java @@ -5,6 +5,8 @@ import pm.Target; import pm.Task; public class Continuous extends Task { + protected static final int SLEEP = 0; + protected int sleep; protected int iteration; protected boolean stop; @@ -16,7 +18,7 @@ public class Continuous extends Task { } public Continuous(Action action, Target target) { - this(action, target, 0); + this(action, target, SLEEP); } public void nextIteration() { diff --git a/java/src/pm/task/Dynamic.java b/java/src/pm/task/Dynamic.java new file mode 100644 index 0000000..ba83463 --- /dev/null +++ b/java/src/pm/task/Dynamic.java @@ -0,0 +1,24 @@ +package pm.task; + +import pm.Action; +import pm.Target; + +public class Dynamic extends Continuous { + protected static final int RATE = 10; + + protected int rate; + + public Dynamic(Action action, Target target, int sleep, int rate) { + super(action, target, sleep); + this.rate = rate; + } + + public Dynamic(Action action, Target target, int sleep) { + super(action, target, sleep); + this.rate = RATE; + } + + public int getSleep() { + return sleep + rate * iteration; + } +} \ No newline at end of file