diff --git a/java/src/pm/Device.java b/java/src/pm/Device.java index 55b6111..61b5c68 100644 --- a/java/src/pm/Device.java +++ b/java/src/pm/Device.java @@ -6,6 +6,8 @@ import pm.event.task.Continuous; import pm.event.task.Stopper; import pm.exception.device.DeviceExitException; import pm.exception.device.DeviceInitialiseException; +import pm.interrupt.InterruptListener; +import pm.interrupt.Interruptible; import pm.macro.Sequence; import pm.macro.SequenceListener; import pm.macro.State; @@ -15,10 +17,12 @@ import pm.macro.state.Release; public abstract class Device extends EventListener { protected SequenceListener sequenceListener; + protected InterruptListener interruptListener; public Device() { super(); sequenceListener = new SequenceListener(this); + interruptListener = new InterruptListener(this); } /* Register macro's */ @@ -67,6 +71,11 @@ public abstract class Device extends EventListener { Button button = hold.getButton(); add(new Press(button), new Release(button), continuous); } + + /* Register interruptibles */ + protected void add(Interruptible interruptible) { + interruptListener.add(interruptible); + } /* Recognize events */ protected void add(State state) { diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 2b8726a..84855e6 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -8,10 +8,13 @@ import org.apache.commons.logging.LogFactory; import pm.application.ApplicationCycle; import pm.application.example.ExampleApplication; import pm.application.itunes.iTunesApplication; +import pm.application.mpc.MPCApplication; +import pm.application.vlc.VLCApplication; import pm.application.winamp.WinampApplication; import pm.application.windows.gomplayer.GomPlayerApplication; import pm.application.windows.wmp.WMPApplication; import pm.device.gui.GUIDevice; +import pm.device.javainput.extreme3d.Extreme3DDevice; import pm.device.javainput.rumblepad.RumblepadDevice; import pm.device.jintellitype.JIntellitypeDevice; import pm.device.player.PlayerDevice; @@ -48,20 +51,23 @@ public class Main extends EventListener { } public void initialise() throws DeviceInitialiseException { - add(new JIntellitypeDevice()); + //add(new JIntellitypeDevice()); //add(new PlayerDevice()); //add(new RumblepadDevice()); - add(new WiimoteDevice()); + //add(new WiimoteDevice()); //add(new GUIDevice()); //add(new TextDevice()); //add(new LanTextDevice()); + add(new Extreme3DDevice()); startDevices(); //add(new ExampleApplication()); - //add(new WMPApplication()); + add(new WMPApplication()); //add(new GomPlayerApplication()); //add(new WinampApplication()); - add(new iTunesApplication()); + //add(new iTunesApplication()); + //add(new VLCApplication()); + //add(new MPCApplication()); startApplications(); } diff --git a/java/src/pm/application/windows/WindowsApplication.java b/java/src/pm/application/windows/WindowsApplication.java index c4bf76e..88f4cdb 100644 --- a/java/src/pm/application/windows/WindowsApplication.java +++ b/java/src/pm/application/windows/WindowsApplication.java @@ -37,9 +37,12 @@ abstract public class WindowsApplication extends Application { if (handle < 1) { String key = String.format("%s\\%s", REGISTRY, program); String path = Native.getValue(key); + System.out.println("PATH=" + path); try { - String command = String.format("\"%s\"", path); + String command = path.startsWith("\"") ? path : String.format("\"%s\"", path); + System.out.println("COMMAND=" + command); command = Native.replaceVariables(command); + System.out.println("COMMAND=" + command); process = Runtime.getRuntime().exec(command); sleep(START_SLEEP); handle = Windows.findWindow(name, null); diff --git a/java/src/pm/application/windows/wmp/WMPApplication.java b/java/src/pm/application/windows/wmp/WMPApplication.java index 6854082..0b379fa 100644 --- a/java/src/pm/application/windows/wmp/WMPApplication.java +++ b/java/src/pm/application/windows/wmp/WMPApplication.java @@ -30,7 +30,7 @@ public class WMPApplication extends WindowsApplication { command(18813); break; case REWIND: - command(18814); + command(18812); break; case MUTE: command(18817); diff --git a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java index 41dc978..bf43e62 100644 --- a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java +++ b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java @@ -9,6 +9,7 @@ import pm.exception.MacroException; import pm.exception.button.UnknownButtonException; import pm.exception.button.UnknownDirectionException; import pm.exception.device.DeviceInitialiseException; +import pm.interrupt.Interruptible; import pm.macro.state.Hold; import pm.macro.state.Press; import pm.macro.state.Release; @@ -33,6 +34,12 @@ public class Extreme3DDevice extends JavaInputDevice { new Press(Extreme3DButton.ELEVEN), new Release(Extreme3DButton.ONE)), new Task(Action.EXIT, Target.MAIN)); + add( + new Interruptible( + new Press(Extreme3DButton.NINE), + new Task(Action.FORWARD), + new Press(Extreme3DButton.TEN), + new Task(Action.PLAY))); } catch (MacroException e) { e.printStackTrace(); } diff --git a/java/src/pm/interrupt/InterruptListener.java b/java/src/pm/interrupt/InterruptListener.java new file mode 100644 index 0000000..1beb7dc --- /dev/null +++ b/java/src/pm/interrupt/InterruptListener.java @@ -0,0 +1,34 @@ +package pm.interrupt; + +import java.util.ArrayList; + +import pm.event.EventListener; +import pm.event.EventManager; +import pm.macro.State; + +public class InterruptListener { + protected EventListener eventListener; + protected ArrayList interruptibleList; + + public InterruptListener(EventListener eventListener) { + this.eventListener = eventListener; + interruptibleList = new ArrayList(); + } + + public void add(Interruptible interruptible) { + interruptibleList.add(interruptible); + } + + public void add(State state) { + for (Interruptible interruptible : interruptibleList) { + if(interruptible.triggerPress.equals(state)) { + EventManager.add(interruptible.triggerTask); + interruptible.triggered = true; + } else if(interruptible.interruptPress.equals(state) && interruptible.triggered) { + EventManager.add(interruptible.interruptTask); + interruptible.interrupted = true; + interruptibleList.remove(interruptible); + } + } + } +} diff --git a/java/src/pm/interrupt/Interruptible.java b/java/src/pm/interrupt/Interruptible.java new file mode 100644 index 0000000..fb83f30 --- /dev/null +++ b/java/src/pm/interrupt/Interruptible.java @@ -0,0 +1,26 @@ +package pm.interrupt; + +import pm.event.Task; +import pm.macro.state.Press; + +public class Interruptible extends Task { + protected static final int SLEEP = 0; + + protected boolean triggered; + protected boolean interrupted; + protected Press triggerPress; + protected Task triggerTask; + protected Press interruptPress; + protected Task interruptTask; + + + public Interruptible(Press triggerPress, Task triggerTask, Press interruptPress, Task interruptTask) { + super(null, null); + triggered = false; + interrupted = false; + this.triggerPress = triggerPress; + this.triggerTask = triggerTask; + this.interruptPress = interruptPress; + this.interruptTask = interruptTask; + } +} \ No newline at end of file diff --git a/java/src/pm/value/Action.java b/java/src/pm/value/Action.java index f71dc18..6d08e7e 100644 --- a/java/src/pm/value/Action.java +++ b/java/src/pm/value/Action.java @@ -15,5 +15,6 @@ public enum Action { TEST, VOLUME_DOWN, VOLUME_UP, + FULLSCREEN, TRAIN, STOP, SAVE, RECOGNIZE, LOAD, SHUFFLE; }