diff --git a/java/src/pm/Action.java b/java/src/pm/Action.java index 7f6b40a..4d68e1f 100644 --- a/java/src/pm/Action.java +++ b/java/src/pm/Action.java @@ -14,7 +14,15 @@ public enum Action { EXIT ("exit"), PLAY ("play"), PAUSE ("pause"), - RESUME ("resume"); + RESUME ("resume"), + NEXT ("next"), + PREVIOUS ("previous"), + FORWARD ("forward"), + REWIND ("rewind"), + MUTE ("mute"), + VOLUME_UP ("volumeUp"), + VULUME_DOWN ("volumeDown"); + protected String action; protected Target target; diff --git a/java/src/pm/Main.java b/java/src/pm/Main.java index 64ee917..5bc5517 100644 --- a/java/src/pm/Main.java +++ b/java/src/pm/Main.java @@ -54,7 +54,7 @@ public class Main { //add(new ExampleDevice()); add(new RumblepadDevice()); //add(new Extreme3DDevice()); - add(new JIntellitypeDevice()); + //add(new JIntellitypeDevice()); //add(new WiimoteDevice()); for (Device device : deviceList) { device.start(); diff --git a/java/src/pm/application/iTunes/iTunesApplication.java b/java/src/pm/application/iTunes/iTunesApplication.java index 52d58a1..1d218fd 100644 --- a/java/src/pm/application/iTunes/iTunesApplication.java +++ b/java/src/pm/application/iTunes/iTunesApplication.java @@ -8,6 +8,10 @@ import com.dt.iTunesController.iTunes; import com.dt.iTunesController.iTunesEventsInterface; public class iTunesApplication extends Application implements iTunesEventsInterface { + + protected final int VOLUME_CHANGE_RATE = 5; + protected final int SEEK_TIME = 1000; + protected iTunes iTunes; protected boolean connected; @@ -15,7 +19,7 @@ public class iTunesApplication extends Application implements iTunesEventsInterf iTunes = new iTunes(); connected = false; } - + public void start() { if (!connected) { iTunes.connect(); @@ -49,6 +53,70 @@ public class iTunesApplication extends Application implements iTunesEventsInterf } } + public void next() { + if (connected) { + iTunes.nextTrack(); + } + } + + public void previous() { + if (connected) { + iTunes.previousTrack(); + } + } + + public void forward() { + if (connected) { + iTunes.fastForward(); + //sleep(SEEK_TIME); + //resume(); + } + } + + public void rewind() { + if (connected) { + iTunes.rewind(); + //sleep(SEEK_TIME); + //resume(); + } + } + + protected void sleep(int time) { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + public void mute() { + if (connected) { + iTunes.setMute(iTunes.getMute()); + } + } + + protected int volume() { + if (connected) { + return iTunes.getSoundVolume(); + } else { + return 0; + } + } + + public void volumeUp() { + if (connected) { + iTunes.setSoundVolume(volume() + VOLUME_CHANGE_RATE); + } + } + + public void volumeDown() { + if (connected) { + iTunes.setSoundVolume(volume() - VOLUME_CHANGE_RATE); + } + } + + + /* iTunesEventInterface => naar eigen class? */ @Override public void onDatabaseChangedEvent(int[][] deletedObjectIDs, diff --git a/java/src/pm/device/javainput/EightfoldDirection.java b/java/src/pm/device/javainput/DirectionalSwitch.java similarity index 62% rename from java/src/pm/device/javainput/EightfoldDirection.java rename to java/src/pm/device/javainput/DirectionalSwitch.java index 2531c7b..253c92e 100644 --- a/java/src/pm/device/javainput/EightfoldDirection.java +++ b/java/src/pm/device/javainput/DirectionalSwitch.java @@ -4,7 +4,7 @@ import pm.Button; import pm.exception.event.UnknownDirectionException; import de.hardcode.jxinput.event.JXInputDirectionalEvent; -public enum EightfoldDirection implements Button { +public enum DirectionalSwitch implements Button { NORTH (0), NORTHEAST (45), EAST (90), @@ -16,7 +16,7 @@ public enum EightfoldDirection implements Button { protected int code; - private EightfoldDirection(int code) { + private DirectionalSwitch(int code) { this.code = code; } @@ -24,8 +24,8 @@ public enum EightfoldDirection implements Button { return code; } - public static EightfoldDirection create(int angle) throws UnknownDirectionException { - for (EightfoldDirection button : EightfoldDirection.values()) { + public static DirectionalSwitch create(int angle) throws UnknownDirectionException { + for (DirectionalSwitch button : DirectionalSwitch.values()) { if (button.getCode() == angle) { return button; } @@ -33,7 +33,7 @@ public enum EightfoldDirection implements Button { throw new UnknownDirectionException(); } - public static EightfoldDirection create(JXInputDirectionalEvent event) throws UnknownDirectionException { + public static DirectionalSwitch create(JXInputDirectionalEvent event) throws UnknownDirectionException { return create(event.getDirectional().getDirection() / 100); } } diff --git a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java index 4f48f25..d3984e6 100644 --- a/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java +++ b/java/src/pm/device/javainput/extreme3d/Extreme3DDevice.java @@ -6,7 +6,7 @@ import pm.Action; import pm.Button; import pm.Macro; import pm.Target; -import pm.device.javainput.EightfoldDirection; +import pm.device.javainput.DirectionalSwitch; import pm.device.javainput.JavaInputDevice; import pm.exception.DeviceException; import pm.exception.MacroException; @@ -46,6 +46,6 @@ public class Extreme3DDevice extends JavaInputDevice { } protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException { - return EightfoldDirection.create(event); + return DirectionalSwitch.create(event); } } diff --git a/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java b/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java index c230152..926cb03 100644 --- a/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java +++ b/java/src/pm/device/javainput/rumblepad/RumblepadDevice.java @@ -4,7 +4,7 @@ import pm.Action; import pm.Button; import pm.Macro; import pm.Target; -import pm.device.javainput.EightfoldDirection; +import pm.device.javainput.DirectionalSwitch; import pm.device.javainput.JavaInputDevice; import pm.exception.DeviceException; import pm.exception.MacroException; @@ -35,10 +35,23 @@ public class RumblepadDevice extends JavaInputDevice { new Press(RumblepadButton.THREE), Action.RESUME.setTarget(Target.APPLICATION)); add( - new Macro( - new Press(RumblepadButton.NINE) - ), - Action.EXIT.setTarget(Target.MAIN)); + new Press(RumblepadButton.SIX), + Action.NEXT.setTarget(Target.APPLICATION)); + add( + new Press(RumblepadButton.EIGHT), + Action.PREVIOUS.setTarget(Target.APPLICATION)); + add( + new Press(RumblepadButton.FIVE), + Action.FORWARD.setTarget(Target.APPLICATION)); + add( + new Press(RumblepadButton.SEVEN), + Action.REWIND.setTarget(Target.APPLICATION)); + add( + new Press(RumblepadButton.NINE), + Action.VULUME_DOWN.setTarget(Target.APPLICATION)); + add( + new Press(RumblepadButton.TEN), + Action.VOLUME_UP.setTarget(Target.APPLICATION)); } catch (MacroException e) { e.printStackTrace(); } @@ -49,6 +62,6 @@ public class RumblepadDevice extends JavaInputDevice { } protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException { - return EightfoldDirection.create(event); + return DirectionalSwitch.create(event); } }