Move all files from java subdirectory to project root
This commit is contained in:
13
exec.test/build.gradle
Normal file
13
exec.test/build.gradle
Normal file
@@ -0,0 +1,13 @@
|
||||
dependencies {
|
||||
compile project(':core.mimis')
|
||||
compile project(':device.wiimote')
|
||||
|
||||
compile 'com.github.boukefalos:jlibmimis:0.1'
|
||||
compile 'com.github.boukefalos:jlibitunes:0.3'
|
||||
compile 'com.github.boukefalos:jlibwiiuse:0.13'
|
||||
compile 'com.github.boukefalos:jlibintellitype:1.3.9'
|
||||
compile 'com.github.boukefalos:jlibxinput:1.0'
|
||||
|
||||
compile 'net.java.dev.jna:jna:4.2.2'
|
||||
compile 'org.apache.logging.log4j:log4j-api:2.+'
|
||||
}
|
||||
BIN
exec.test/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
exec.test/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
6
exec.test/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
6
exec.test/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
#Mon Jul 11 23:15:35 BST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip
|
||||
164
exec.test/gradlew
vendored
Normal file
164
exec.test/gradlew
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
90
exec.test/gradlew.bat
vendored
Normal file
90
exec.test/gradlew.bat
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
31
exec.test/src/main/java/jna/HelloTest.java
Normal file
31
exec.test/src/main/java/jna/HelloTest.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package jna;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
|
||||
public class HelloTest {
|
||||
public interface HelloLibrary extends Library {
|
||||
public void helloFromC();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
HelloLibrary ctest = (HelloLibrary) Native.loadLibrary("ctest", HelloLibrary.class);
|
||||
ctest.helloFromC();
|
||||
}
|
||||
}
|
||||
311
exec.test/src/main/java/jni/TestIntellitype.java
Normal file
311
exec.test/src/main/java/jni/TestIntellitype.java
Normal file
@@ -0,0 +1,311 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package jni;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Event;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
|
||||
import com.melloware.jintellitype.HotkeyListener;
|
||||
import com.melloware.jintellitype.IntellitypeListener;
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
/**
|
||||
* Swing based test application to test all the functions of the JIntellitype library.
|
||||
* <p>
|
||||
* Copyright (c) 2006 Melloware, Inc. <http://www.melloware.com>
|
||||
* @author Emil A. Lefkof III <elefkof@ksmpartners.com>
|
||||
* @version 1.0
|
||||
*/
|
||||
public class TestIntellitype extends JFrame implements HotkeyListener, IntellitypeListener {
|
||||
|
||||
private static TestIntellitype mainFrame;
|
||||
private static final int WINDOWS_A = 88;
|
||||
private static final int ALT_SHIFT_B = 89;
|
||||
private static final int CTRL_SHIFT_C = 90;
|
||||
private static final int PRINT_SCREEN = 91;
|
||||
private static final int F11 = 92;
|
||||
private static final int F12 = 93;
|
||||
private static final int SEMICOLON = 94;
|
||||
private static final int TICK = 95;
|
||||
private final JButton btnRegisterHotKey = new JButton();
|
||||
private final JButton btnUnregisterHotKey = new JButton();
|
||||
private final JPanel bottomPanel = new JPanel();
|
||||
private final JPanel mainPanel = new JPanel();
|
||||
private final JPanel topPanel = new JPanel();
|
||||
private final JScrollPane scrollPane = new JScrollPane();
|
||||
private final JTextArea textArea = new JTextArea();
|
||||
|
||||
/**
|
||||
* Creates new form.
|
||||
*/
|
||||
public TestIntellitype() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main method to launch this application.
|
||||
* <p>
|
||||
* @param args any command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new File(".").getAbsolutePath());
|
||||
// first check to see if an instance of this application is already
|
||||
// running, use the name of the window title of this JFrame for checking
|
||||
if (JIntellitype.checkInstanceAlreadyRunning("JIntellitype Test Application")) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// next check to make sure JIntellitype DLL can be found and we are on
|
||||
// a Windows operating System
|
||||
if (!JIntellitype.isJIntellitypeSupported()) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
mainFrame = new TestIntellitype();
|
||||
mainFrame.setTitle("JIntellitype Test Application");
|
||||
center(mainFrame);
|
||||
mainFrame.setVisible(true);
|
||||
mainFrame.initJIntellitype();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.melloware.jintellitype.HotkeyListener#onHotKey(int)
|
||||
*/
|
||||
public void onHotKey(int aIdentifier) {
|
||||
output("WM_HOTKEY message received " + Integer.toString(aIdentifier));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.melloware.jintellitype.IntellitypeListener#onIntellitype(int)
|
||||
*/
|
||||
public void onIntellitype(int aCommand) {
|
||||
|
||||
switch (aCommand) {
|
||||
case JIntellitype.APPCOMMAND_BROWSER_BACKWARD:
|
||||
output("BROWSER_BACKWARD message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_BROWSER_FAVOURITES:
|
||||
output("BROWSER_FAVOURITES message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_BROWSER_FORWARD:
|
||||
output("BROWSER_FORWARD message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_BROWSER_HOME:
|
||||
output("BROWSER_HOME message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_BROWSER_REFRESH:
|
||||
output("BROWSER_REFRESH message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_BROWSER_SEARCH:
|
||||
output("BROWSER_SEARCH message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_BROWSER_STOP:
|
||||
output("BROWSER_STOP message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_LAUNCH_APP1:
|
||||
output("LAUNCH_APP1 message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_LAUNCH_APP2:
|
||||
output("LAUNCH_APP2 message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_LAUNCH_MAIL:
|
||||
output("LAUNCH_MAIL message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK:
|
||||
output("MEDIA_NEXTTRACK message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE:
|
||||
output("MEDIA_PLAY_PAUSE message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK:
|
||||
output("MEDIA_PREVIOUSTRACK message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_MEDIA_STOP:
|
||||
output("MEDIA_STOP message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_VOLUME_DOWN:
|
||||
output("VOLUME_DOWN message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_VOLUME_UP:
|
||||
output("VOLUME_UP message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
case JIntellitype.APPCOMMAND_VOLUME_MUTE:
|
||||
output("VOLUME_MUTE message received " + Integer.toString(aCommand));
|
||||
break;
|
||||
default:
|
||||
output("Undefined INTELLITYPE message caught " + Integer.toString(aCommand));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Centers window on desktop.
|
||||
* <p>
|
||||
* @param aFrame the Frame to center
|
||||
*/
|
||||
private static void center(JFrame aFrame) {
|
||||
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
final Point centerPoint = ge.getCenterPoint();
|
||||
final Rectangle bounds = ge.getMaximumWindowBounds();
|
||||
final int w = Math.min(aFrame.getWidth(), bounds.width);
|
||||
final int h = Math.min(aFrame.getHeight(), bounds.height);
|
||||
final int x = centerPoint.x - (w / 2);
|
||||
final int y = centerPoint.y - (h / 2);
|
||||
aFrame.setBounds(x, y, w, h);
|
||||
if ((w == bounds.width) && (h == bounds.height)) {
|
||||
aFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
}
|
||||
aFrame.validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to register a hotkey using the RegisterHotKey Windows API call.
|
||||
* <p>
|
||||
* @param aEvent the ActionEvent fired.
|
||||
*/
|
||||
private void btnRegisterHotKey_actionPerformed(ActionEvent aEvent) {
|
||||
// assign the WINDOWS+A key to the unique id 88 for identification
|
||||
JIntellitype.getInstance().registerHotKey(WINDOWS_A, JIntellitype.MOD_WIN, 'A');
|
||||
JIntellitype.getInstance().registerHotKey(ALT_SHIFT_B, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, 'B');
|
||||
JIntellitype.getInstance().registerSwingHotKey(CTRL_SHIFT_C, Event.CTRL_MASK + Event.SHIFT_MASK, 'C');
|
||||
|
||||
// use a 0 for the modifier if you just want a single keystroke to be a
|
||||
// hotkey
|
||||
JIntellitype.getInstance().registerHotKey(PRINT_SCREEN, 0, 44);
|
||||
JIntellitype.getInstance().registerHotKey(F11, "F11");
|
||||
JIntellitype.getInstance().registerHotKey(F12, JIntellitype.MOD_ALT, 123);
|
||||
JIntellitype.getInstance().registerHotKey(SEMICOLON, 0, 186);
|
||||
JIntellitype.getInstance().registerHotKey(TICK, 0, 192);
|
||||
// clear the text area
|
||||
textArea.setText("");
|
||||
output("RegisterHotKey WINDOWS+A was assigned uniqueID 88");
|
||||
output("RegisterHotKey ALT+SHIFT+B was assigned uniqueID 89");
|
||||
output("RegisterHotKey CTRL+SHIFT+C was assigned uniqueID 90");
|
||||
output("RegisterHotKey PRINT_SCREEN was assigned uniqueID 91");
|
||||
output("RegisterHotKey F9 was assigned uniqueID 92");
|
||||
output("RegisterHotKey F12 was assigned uniqueID 93");
|
||||
output("RegisterHotKey SEMICOLON was assigned uniqueID 94");
|
||||
output("Press WINDOWS+A or ALT+SHIFT+B or CTRL+SHIFT+C in another application and you will see the debug output in the textarea.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to unregister a hotkey using the UnregisterHotKey Windows API call.
|
||||
* <p>
|
||||
* @param aEvent the ActionEvent fired.
|
||||
*/
|
||||
private void btnUnregisterHotKey_actionPerformed(ActionEvent aEvent) {
|
||||
JIntellitype.getInstance().unregisterHotKey(WINDOWS_A);
|
||||
JIntellitype.getInstance().unregisterHotKey(ALT_SHIFT_B);
|
||||
JIntellitype.getInstance().unregisterHotKey(CTRL_SHIFT_C);
|
||||
JIntellitype.getInstance().unregisterHotKey(PRINT_SCREEN);
|
||||
JIntellitype.getInstance().unregisterHotKey(F11);
|
||||
JIntellitype.getInstance().unregisterHotKey(F12);
|
||||
JIntellitype.getInstance().unregisterHotKey(SEMICOLON);
|
||||
output("UnregisterHotKey WINDOWS+A");
|
||||
output("UnregisterHotKey ALT+SHIFT+B");
|
||||
output("UnregisterHotKey CTRL+SHIFT+C");
|
||||
output("UnregisterHotKey PRINT_SCREEN");
|
||||
output("UnregisterHotKey F9");
|
||||
output("UnregisterHotKey F12");
|
||||
output("UnregisterHotKey SEMICOLON");
|
||||
output("Press WINDOWS+A or ALT+SHIFT+B in another application and you will NOT see the debug output in the textarea.");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
*/
|
||||
private void initComponents() {
|
||||
mainPanel.setLayout(new BorderLayout());
|
||||
topPanel.setBorder(new EtchedBorder(1));
|
||||
bottomPanel.setLayout(new BorderLayout());
|
||||
bottomPanel.setBorder(new EtchedBorder(1));
|
||||
btnRegisterHotKey.setText("RegisterHotKey");
|
||||
btnRegisterHotKey.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
btnRegisterHotKey_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
btnUnregisterHotKey.setText("UnregisterHotKey");
|
||||
btnUnregisterHotKey.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
btnUnregisterHotKey_actionPerformed(e);
|
||||
}
|
||||
});
|
||||
topPanel.add(btnRegisterHotKey);
|
||||
topPanel.add(btnUnregisterHotKey);
|
||||
scrollPane.getViewport().add(textArea);
|
||||
bottomPanel.add(scrollPane, BorderLayout.CENTER);
|
||||
mainPanel.add(topPanel, BorderLayout.NORTH);
|
||||
mainPanel.add(bottomPanel, BorderLayout.CENTER);
|
||||
|
||||
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(java.awt.event.WindowEvent evt) {
|
||||
// don't forget to clean up any resources before close
|
||||
JIntellitype.getInstance().cleanUp();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
this.getContentPane().add(mainPanel);
|
||||
this.pack();
|
||||
this.setSize(800, 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the JInitellitype library making sure the DLL is located.
|
||||
*/
|
||||
public void initJIntellitype() {
|
||||
try {
|
||||
|
||||
// initialize JIntellitype with the frame so all windows commands can
|
||||
// be attached to this window
|
||||
JIntellitype.getInstance().addHotKeyListener(this);
|
||||
JIntellitype.getInstance().addIntellitypeListener(this);
|
||||
output("JIntellitype initialized");
|
||||
} catch (RuntimeException ex) {
|
||||
output("Either you are not on Windows, or there is a problem with the JIntellitype library!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the output to the log and the text area.
|
||||
* <p>
|
||||
* @param text the text to output
|
||||
*/
|
||||
private void output(String text) {
|
||||
textArea.append(text);
|
||||
textArea.append("\n");
|
||||
}
|
||||
|
||||
}
|
||||
26
exec.test/src/main/java/jni/TestNative.java
Normal file
26
exec.test/src/main/java/jni/TestNative.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package jni;
|
||||
|
||||
import mimis.util.Native;
|
||||
import mimis.value.Registry;
|
||||
|
||||
public class TestNative {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Native.getValue(Registry.CURRENT_USER, "Software\\LIRC", "password"));
|
||||
}
|
||||
}
|
||||
25
exec.test/src/main/java/jni/TestWiiuse.java
Normal file
25
exec.test/src/main/java/jni/TestWiiuse.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package jni;
|
||||
|
||||
import wiiusej.WiiUseApiManager;
|
||||
|
||||
public class TestWiiuse {
|
||||
public static void main(String[] args) {
|
||||
WiiUseApiManager.getWiimotes(0, false);
|
||||
}
|
||||
}
|
||||
25
exec.test/src/main/java/jni/TestXinput.java
Normal file
25
exec.test/src/main/java/jni/TestXinput.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package jni;
|
||||
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
|
||||
public class TestXinput {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(JXInputManager.getNumberOfDevices());
|
||||
}
|
||||
}
|
||||
27
exec.test/src/main/java/jni/TestiTunes.java
Normal file
27
exec.test/src/main/java/jni/TestiTunes.java
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package jni;
|
||||
|
||||
import com.dt.iTunesController.iTunes;
|
||||
|
||||
public class TestiTunes {
|
||||
public static void main(String[] args) {
|
||||
iTunes iTunes = new iTunes();
|
||||
iTunes.connect();
|
||||
iTunes.playPause();
|
||||
}
|
||||
}
|
||||
45
exec.test/src/main/java/test/BufferedSound.java
Normal file
45
exec.test/src/main/java/test/BufferedSound.java
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package test;
|
||||
|
||||
public class BufferedSound {
|
||||
private byte[][] soundData;
|
||||
private int sampleRate;
|
||||
private int sampleSize;
|
||||
|
||||
public BufferedSound(byte[][] soundData, int sampleRate, int sampleSize) {
|
||||
this.soundData = soundData;
|
||||
this.sampleRate = sampleRate;
|
||||
this.sampleSize = sampleSize;
|
||||
}
|
||||
|
||||
public byte[] getReport(int i) {
|
||||
return soundData[i];
|
||||
}
|
||||
|
||||
public int numReports() {
|
||||
return soundData.length;
|
||||
}
|
||||
|
||||
public int getSampleRate() {
|
||||
return sampleRate;
|
||||
}
|
||||
|
||||
public int getSampleSize() {
|
||||
return sampleSize;
|
||||
}
|
||||
}
|
||||
43
exec.test/src/main/java/test/CustomAppender.java
Normal file
43
exec.test/src/main/java/test/CustomAppender.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package test;
|
||||
|
||||
import org.apache.log4j.AppenderSkeleton;
|
||||
import org.apache.log4j.spi.LoggingEvent;
|
||||
|
||||
public class CustomAppender extends AppenderSkeleton {
|
||||
protected int bla = 9999;
|
||||
|
||||
public void setBla(int bla) {
|
||||
this.bla = bla;
|
||||
}
|
||||
|
||||
public int getBla() {
|
||||
return bla;
|
||||
}
|
||||
|
||||
public boolean requiresLayout() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void close() {}
|
||||
|
||||
protected void append(LoggingEvent loggingEvent) {
|
||||
System.out.print(layout.format(loggingEvent));
|
||||
}
|
||||
|
||||
}
|
||||
196
exec.test/src/main/java/test/Ir.java
Normal file
196
exec.test/src/main/java/test/Ir.java
Normal file
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package test;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import mimis.device.lirc.LircButton;
|
||||
import mimis.device.lirc.LircButtonListener;
|
||||
import mimis.device.lirc.LircService;
|
||||
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
|
||||
import mimis.device.wiimote.WiimoteDevice;
|
||||
import mimis.device.wiimote.WiimoteService;
|
||||
import mimis.exception.device.DeviceNotFoundException;
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.wiiusejevents.physicalevents.IREvent;
|
||||
|
||||
public class Ir extends WiimoteDevice implements LircButtonListener {
|
||||
protected Graph graph;
|
||||
protected Point tl, tr, br, bl, raw, point;
|
||||
protected Line t, r, b, l;
|
||||
|
||||
public Ir() {
|
||||
tl = tr = br = bl = new Point(0, 0);
|
||||
graph = new Graph();
|
||||
/*try {
|
||||
while (true) {
|
||||
graph.draw(new Point(Math.random(), Math.random()));
|
||||
Thread.sleep(100);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
LircService lircService = new LircService();
|
||||
lircService.put(PhiliphsRCLE011Button.NAME,
|
||||
PhiliphsRCLE011Button.values());
|
||||
lircService.add(this);
|
||||
lircService.start();
|
||||
WiimoteService wiimoteService = new WiimoteService();
|
||||
try {
|
||||
Wiimote wiimote = wiimoteService.getDevice(this);
|
||||
wiimote.activateIRTRacking();
|
||||
Thread.sleep(10000000);
|
||||
} catch (DeviceNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void add(LircButton lircButton) {
|
||||
if (lircButton instanceof PhiliphsRCLE011Button) {
|
||||
boolean t = false, r = false, b = false, l = false;
|
||||
switch ((PhiliphsRCLE011Button) lircButton) {
|
||||
case RED:
|
||||
tl = raw;
|
||||
l = bl != null;
|
||||
t = tr != null;
|
||||
break;
|
||||
case GREEN:
|
||||
tr = raw;
|
||||
t = tl != null;
|
||||
r = br != null;
|
||||
break;
|
||||
case YELLOW:
|
||||
br = raw;
|
||||
r = tr != null;
|
||||
b = bl != null;
|
||||
break;
|
||||
case BLUE:
|
||||
bl = raw;
|
||||
b = br != null;
|
||||
l = tl != null;
|
||||
break;
|
||||
}
|
||||
if (t) {
|
||||
this.t = new Line(tl, tr);
|
||||
}
|
||||
if (r) {
|
||||
this.r = new Line(tr, br);
|
||||
}
|
||||
if (b) {
|
||||
this.b = new Line(br, bl);
|
||||
}
|
||||
if (l) {
|
||||
this.l = new Line(bl, tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onIrEvent(IREvent event) {
|
||||
// log.debug(event);
|
||||
raw = new Point(event.getAx(), event.getAy());
|
||||
logger.debug(String.format("%d %d", raw.x, raw.y));
|
||||
if (t != null && r != null && b != null && l != null) {
|
||||
double w = r.getX(raw.y) - l.getX(raw.y);
|
||||
double h = t.getY(raw.x) - b.getY(raw.x);
|
||||
point = new Point((w - l.getX(raw.y)) / w, (h - b.getY(raw.x)) / h);
|
||||
graph.draw(point);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Ir();
|
||||
}
|
||||
|
||||
protected class Point {
|
||||
public double x, y;
|
||||
|
||||
public Point(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
protected class Line {
|
||||
protected double a, b;
|
||||
|
||||
public Line(Point p1, Point p2) {
|
||||
a = (p2.y - p1.y) / (p2.x - p1.x);
|
||||
b = p2.y - a * p2.x;
|
||||
}
|
||||
|
||||
public double getY(double x) {
|
||||
return a * x + b;
|
||||
}
|
||||
|
||||
public double getX(double y) {
|
||||
return (y - b) / a;
|
||||
}
|
||||
}
|
||||
|
||||
public class Graph extends JPanel {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
|
||||
final int PAD = 20;
|
||||
final double X = 1;
|
||||
final double Y = 2;
|
||||
JFrame f;
|
||||
Graphics2D g2;
|
||||
double w, h;
|
||||
|
||||
public Graph() {
|
||||
f = new JFrame();
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.add(this);
|
||||
f.setSize(400, 400);
|
||||
f.setLocation(200, 200);
|
||||
f.setVisible(true);
|
||||
g2 = (Graphics2D) f.getGraphics();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
w = getWidth();
|
||||
h = getHeight();
|
||||
axes();
|
||||
}
|
||||
|
||||
protected void draw(Point point) {
|
||||
g2.clearRect(0, 0, 400, 400);
|
||||
axes();
|
||||
double xInc = (double) (w - 2 * PAD) / X;
|
||||
double scale = (double) (h - 2 * PAD) / Y;
|
||||
// Mark data points.
|
||||
g2.setPaint(Color.blue);
|
||||
double x = PAD + point.x * xInc;
|
||||
double y = h - PAD - scale * point.y;
|
||||
g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
|
||||
}
|
||||
|
||||
protected void axes() {
|
||||
// Draw ordinate.
|
||||
g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
|
||||
// Draw abcissa.
|
||||
g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
|
||||
}
|
||||
}
|
||||
}
|
||||
230
exec.test/src/main/java/test/Sound.java
Normal file
230
exec.test/src/main/java/test/Sound.java
Normal file
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.DataLine;
|
||||
import javax.sound.sampled.SourceDataLine;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
import wiiusej.Wiimote;
|
||||
import mimis.device.wiimote.WiimoteDevice;
|
||||
import mimis.device.wiimote.WiimoteService;
|
||||
|
||||
//Sample Rate - equation is y = -280x + 7280, where x is the actual sample rate. ex: sample rate of 4200 = 0x0B
|
||||
//Freq (y=real, x=wii) y=-1070*ln(x)+4442.6 of 2788.1*e^(-0.041*x)
|
||||
|
||||
public class Sound {
|
||||
public static final byte PCM = 0x40; // signed 8-bit PCM
|
||||
public static final byte ADPCM = 0x00; // Yamaha 4-bit ADPCM
|
||||
public static final byte BLOCK_SIZE = 20;
|
||||
|
||||
public static final int yamaha_indexscale[] = {
|
||||
230, 230, 230, 230, 307, 409, 512, 614,
|
||||
230, 230, 230, 230, 307, 409, 512, 614};
|
||||
|
||||
public static final int yamaha_difflookup[] = {
|
||||
1, 3, 5, 7, 9, 11, 13, 15,
|
||||
-1, -3, -5, -7, -9, -11, -13, 15};
|
||||
|
||||
public Object object = new Object();
|
||||
|
||||
public static void main(String[] args) {
|
||||
/*File file = new File("sound.wav");
|
||||
try {
|
||||
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
|
||||
AudioFormat au = inputStream.getFormat();
|
||||
System.out.println(au.getSampleRate());// Hz
|
||||
System.out.println(au.getSampleSizeInBits());// bits
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
new Sound().start();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
File file = new File("1kSine16 (3130).wav");
|
||||
play(file);
|
||||
System.exit(0);//if (true) return;
|
||||
|
||||
WiimoteService wiimoteService = new WiimoteService();
|
||||
try {
|
||||
WiimoteDevice wiimoteDevice = new WiimoteDevice();
|
||||
Wiimote wiimote = wiimoteService.getDevice(wiimoteDevice);
|
||||
|
||||
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
|
||||
AudioFormat audioFormat = audioInputStream.getFormat();
|
||||
// BufferedSound bufferedSound = bufferSound(inputStream);
|
||||
System.out.println(audioInputStream.getFormat().getSampleRate());
|
||||
System.out.println(audioInputStream.getFormat().getFrameRate());
|
||||
|
||||
//System.out.println(bufferedSound.getSampleRate());
|
||||
//byte rate = (byte) (48000 / bufferedSound.getSampleRate());
|
||||
//wiimote.setSpeakerRate((byte) rate, (byte) 0x00);
|
||||
|
||||
wiimote.setSpeakerFormat(PCM);
|
||||
//wiimote.setSpeakerRate((byte) 0, rate);
|
||||
wiimote.setSpeakerRate((byte) 0x00, (byte) (48000 / audioFormat.getSampleRate())); // pcm
|
||||
//wiimote.setSpeakerRate((byte) 0xd0, (byte) 0x07); // adpcm
|
||||
wiimote.setSpeakerVolume(1);
|
||||
|
||||
wiimote.activateSpeaker();
|
||||
|
||||
/* File file = new File("volbeat_pcm_u8_32_1500.raw");
|
||||
FileInputStream fin = new FileInputStream(file);
|
||||
byte[] block = new byte[20];
|
||||
while (fin.read(block) != -1) {
|
||||
wiimote.streamSpeakerData(block);
|
||||
}*/
|
||||
|
||||
//playBufferedSound(wiimote, bufferedSound, step);
|
||||
playSound(wiimote, audioInputStream);
|
||||
synchronized (object) {
|
||||
object.wait();
|
||||
}
|
||||
wiimoteService.exit();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void playSound(final Wiimote wiimote, final AudioInputStream audioInputStream) {
|
||||
Timer timer = new Timer();
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
public void run() {
|
||||
try {
|
||||
byte[] buffer = new byte[20];
|
||||
if (audioInputStream.read(buffer) != -1) {
|
||||
buffer[0] = -2;
|
||||
System.out.format("%2x\n", buffer[0]);
|
||||
wiimote.streamSpeakerData(buffer);
|
||||
} else {
|
||||
cancel();
|
||||
synchronized (object) {
|
||||
object.notifyAll();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
AudioFormat audioFormat = audioInputStream.getFormat();
|
||||
double sampleSizeInBytes = audioFormat.getSampleSizeInBits() / 8D;
|
||||
double samplesPerBlock = BLOCK_SIZE / sampleSizeInBytes;
|
||||
int step = (int) Math.round(1000 * samplesPerBlock / (float) audioFormat.getSampleRate());
|
||||
System.out.println("step: " + step);
|
||||
timer.scheduleAtFixedRate(timerTask, 0, step);
|
||||
}
|
||||
|
||||
public void playBufferedSound(final Wiimote wiimote, final BufferedSound bufferedSound, int step) {
|
||||
Timer timer = new Timer();
|
||||
TimerTask timerTask = new TimerTask() {
|
||||
int i = 0;
|
||||
public void run() {
|
||||
wiimote.streamSpeakerData(bufferedSound.getReport(i));
|
||||
/*if (i % 10 == 0) {
|
||||
wiimote.setSpeakerVolume(Math.random());
|
||||
wiimote.setSpeakerConfig();
|
||||
}*/
|
||||
if (++i > bufferedSound.numReports()) {
|
||||
cancel();
|
||||
object.notifyAll();
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.scheduleAtFixedRate(timerTask, 0, step);
|
||||
}
|
||||
|
||||
public BufferedSound bufferSound(AudioInputStream audioInputStream) throws IOException {
|
||||
AudioFormat audioFormat = audioInputStream.getFormat();
|
||||
int size = (int) (audioInputStream.getFrameLength() * audioFormat.getFrameSize());
|
||||
byte[][] sound = new byte[size / BLOCK_SIZE + 1][BLOCK_SIZE];
|
||||
for (int i = 0; i < sound.length; ++i) {
|
||||
byte[] block = new byte[BLOCK_SIZE];
|
||||
int j = 0;
|
||||
do {
|
||||
int read = audioInputStream.read(block, j, BLOCK_SIZE - j);
|
||||
if (read == -1) {
|
||||
break;
|
||||
}
|
||||
j += read;
|
||||
} while (j < BLOCK_SIZE);
|
||||
for (j = 0; j < BLOCK_SIZE; ++j) {
|
||||
if ((i * BLOCK_SIZE + j) > size) {
|
||||
break;
|
||||
}
|
||||
//sound[i][j] = block[j];
|
||||
sound[i][j] = (byte) ((j % 2 == 0) ? 0x33 : 0xcc);
|
||||
//sound[i][j] = (byte) (Math.random() * 0xff);
|
||||
}
|
||||
}
|
||||
audioInputStream.close();
|
||||
return new BufferedSound(sound, (int) audioFormat.getSampleRate(), audioFormat.getSampleSizeInBits());
|
||||
}
|
||||
|
||||
public void play(File file) {
|
||||
|
||||
|
||||
try {
|
||||
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
|
||||
AudioFormat audioFormat = audioInputStream.getFormat();
|
||||
System.out.println(audioFormat.getEncoding());
|
||||
System.out.println(audioFormat.getSampleRate());
|
||||
System.out.println(audioFormat.getFrameRate());
|
||||
AudioFormat newFormat = new AudioFormat(
|
||||
AudioFormat.Encoding.PCM_SIGNED,
|
||||
3130, 8, 1, 1, 3130, false);
|
||||
AudioInputStream newAudioInputStream = new AudioInputStream(
|
||||
audioInputStream,
|
||||
newFormat,
|
||||
audioInputStream.getFrameLength() * audioFormat.getFrameSize());
|
||||
play(newAudioInputStream);
|
||||
} catch (UnsupportedAudioFileException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void play(AudioInputStream audioInputStream) {
|
||||
try {
|
||||
AudioFormat audioFormat = audioInputStream.getFormat();
|
||||
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
|
||||
SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
|
||||
sourceDataLine.open(audioFormat);
|
||||
sourceDataLine.start();
|
||||
int i;
|
||||
byte[] buffer = new byte[128];
|
||||
while ((i = audioInputStream.read(buffer, 0, buffer.length)) != -1) {
|
||||
sourceDataLine.write(buffer, 0, i);
|
||||
}
|
||||
sourceDataLine.drain();
|
||||
sourceDataLine.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
70
exec.test/src/main/java/test/Test.java
Normal file
70
exec.test/src/main/java/test/Test.java
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Rik Veenboer <rik.veenboer@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package test;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new Test().start();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void start() throws Throwable {
|
||||
input((Object) new A());
|
||||
input((Object) new B());
|
||||
input((Object) new String[] {"a", "b"});
|
||||
}
|
||||
|
||||
public void input(Object object) throws Throwable {
|
||||
System.out.println("Object");
|
||||
MethodType methodType = MethodType.methodType(void.class, object.getClass());
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
MethodHandle methodHandle = lookup.findVirtual(getClass(), "input", methodType);
|
||||
try {
|
||||
methodHandle.invoke(this, object);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void input(A object) {
|
||||
System.out.println("A");
|
||||
}
|
||||
|
||||
public void input(B object) {
|
||||
System.out.println("B");
|
||||
}
|
||||
|
||||
public void input(String[] object) {
|
||||
System.out.println("String[]");
|
||||
}
|
||||
|
||||
public class A {
|
||||
|
||||
}
|
||||
|
||||
public class B {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user