├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .travis.yml
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
└── java
│ └── org
│ └── rjung
│ └── util
│ └── launchpad
│ ├── Channel.java
│ ├── Color.java
│ ├── Launchpad.java
│ ├── LaunchpadReceiver.java
│ └── Pad.java
└── test
└── java
└── org
└── rjung
└── util
└── launchpad
├── ChannelTest.java
├── ColorTest.java
└── PadTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | .settings/
4 | target/
5 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rynr/launchpad/042a26b9fdde782302c8c42fb891b08bc585acc7/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 | sudo: false
5 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Changelog
2 | =========
3 |
4 | launchpad-1.1
5 | -------------
6 |
7 | - Bugfix concerning detection of buttons 0-8 beeing pressed
8 |
9 | launchpad-1.0
10 | -------------
11 |
12 | - Complete rewrite of the code using `javax.sound.midi`-package
13 |
14 | launchpad-0.4
15 | -------------
16 |
17 | - Added some tests
18 | - Sonar cleanups
19 |
20 | launchpad-0.3
21 | -------------
22 |
23 | - Starting the reader-thread is not automaticly any more
24 |
25 | launchpad-0.2
26 | -------------
27 |
28 | - Class-Restructuring
29 | - Fixed some Issues from sonar
30 |
31 | launchpad-0.1
32 | -------------
33 |
34 | - Initial version
35 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at Rainer.Jung@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Launchpad
2 | =========
3 |
4 | This library can be used to access a
5 | [Novation Launchpad](http://uk.novationmusic.com/midi-controllers-digital-dj/launchpad)
6 | from a java application.
7 |
8 | Usage
9 | -----
10 |
11 | You can directly use it from maven central:
12 | ```xml
13 |
14 | org.rjung.util
15 | launchpad
16 | 1.0
17 |
18 | ```
19 |
20 | To send colors the the launchpad, the methods `set(pad, color)`:
21 |
22 | ```java
23 | launchpad.set(Pad.A4, Color.RED);
24 | launchpad.set(Pad.find(3, 1), Color.GREEN);
25 | ```
26 |
27 | To retrieve messages, implement a
28 | [LaunchpadReceiver](https://github.com/rynr/launchpad/blob/master/src/main/java/org/rjung/util/launchpad/LaunchpadReceiver.java)
29 | and register it to the launchpad instance. The LaunchpadReceiver will now be
30 | called always, when a Command is received.
31 |
32 | ```java
33 | new Launchpad(new LaunchpadHandler() {
34 | public void recieve(MidiCommand command) {
35 | System.out.println(command);
36 | }
37 | });
38 | ```
39 |
40 | Example
41 | -------
42 |
43 | [](https://www.youtube.com/watch?v=9cYpqWWpjjY)
44 |
45 | There's also a rewritten version of the [Games of Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) in the branch [life](https://github.com/rynr/launchpad/tree/life).
46 |
47 | Build it yourself
48 | -----------------
49 |
50 | The build uses maven. You don't need to install anything besides a java 8 development kit (jdk8). Now just run:
51 |
52 | ```sh
53 | ./mvn clean package
54 | ```
55 |
56 | The build jar can be found in the `target`-folder.
57 |
58 | Info
59 | ----
60 |
61 | - [Info](https://rynr.github.io/launchpad/)
62 | - [Github](https://github.com/rynr/launchpad)
63 | - [Bugs](https://github.com/rynr/launchpad/issues)
64 | - [Sonar](https://sonarqube.com/dashboard/index?id=org.rjung.util%3Alaunchpad)
65 | - [](https://gitter.im/rynr/launchpad)
66 | - [](https://travis-ci.org/rynr/launchpad)
67 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | org.rjung.util
5 | launchpad
6 | 1.1-SNAPSHOT
7 | jar
8 |
9 | launchpad
10 | http://rynr.github.io/launchpad
11 | Library to access a Novation Launchpad in a unix environment
12 |
13 |
14 | Apache License, Version 2.0
15 | http://www.apache.org/licenses/LICENSE-2.0.txt
16 |
17 |
18 |
19 |
20 | org.sonatype.oss
21 | oss-parent
22 | 9
23 |
24 |
25 |
26 | UTF-8
27 | 1.8
28 |
29 |
30 |
31 | scm:git:http://github.com/rynr/launchpad.git
32 | scm:git:git@github.com:rynr/launchpad.git
33 | launchpad-0.1
34 | http://github.com/rynr/launchpad
35 |
36 |
37 |
38 |
39 | rynr
40 | Rainer Jung
41 | Rainer.Jung@gmail.com
42 | http://about.me/rjung
43 |
44 | developer
45 |
46 | +1
47 |
48 |
49 |
50 |
51 |
52 | junit
53 | junit
54 | 4.12
55 | test
56 |
57 |
58 | org.mockito
59 | mockito-core
60 | 3.3.3
61 | test
62 |
63 |
64 |
65 |
66 |
67 | org.apache.maven.plugins
68 | maven-compiler-plugin
69 | 3.8.1
70 |
71 | ${java.version}
72 | ${java.version}
73 |
74 |
75 |
76 | org.apache.maven.plugins
77 | maven-release-plugin
78 |
79 | true
80 | false
81 | release
82 | deploy
83 |
84 |
85 |
86 | org.sonatype.plugins
87 | nexus-staging-maven-plugin
88 | 1.6.8
89 | true
90 |
91 | ossrh
92 | https://oss.sonatype.org/
93 | true
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 | org.codehaus.mojo
103 | findbugs-maven-plugin
104 | 3.0.5
105 |
106 | Max
107 | Low
108 | true
109 |
110 |
111 |
112 | org.codehaus.mojo
113 | cobertura-maven-plugin
114 | 2.7
115 |
116 |
117 | org.codehaus.sonar-plugins
118 | maven-report
119 | 0.1
120 |
121 |
122 |
123 |
124 |
125 |
126 | ossrh
127 | https://oss.sonatype.org/content/repositories/snapshots
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/src/main/java/org/rjung/util/launchpad/Channel.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | /**
4 | * Usually you don't need to think about the {@link Channel}. A launchpad is usually configured to
5 | * use the default Midi-Channel 1. Only if you have configured yours differently, this is the
6 | * Channel you should give the {@link Launchpad#Launchpad(Channel)} or
7 | * {@link Launchpad#Launchpad(Channel, LaunchpadReceiver)} constructors.
8 | *
9 | * To find out more about midi-channels, checkout the
10 | * midi specifications.
11 | */
12 | public enum Channel {
13 |
14 | C1(0), C2(1), C3(2), C4(3), C5(4), C6(5), C7(6), C8(7), //
15 | C9(8), C10(9), C11(10), C12(11), C13(12), C14(13), C15(14), C16(15);
16 |
17 | private final int systemChannel;
18 |
19 | Channel(int channel) {
20 | this.systemChannel = channel;
21 | }
22 |
23 | public int channelForSystem() {
24 | return this.systemChannel;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/rjung/util/launchpad/Color.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | /**
4 | * The {@link Color} describes any color that a {@link Pad} of a {@link Launchpad} could have.
5 | * Currently this library only supports the colors of a launchpad mini (as I don't have another one
6 | * to try).
7 | *
8 | * The colors are a combination of 4 different levels of red and green. They mix up for amber. So
9 | * these colors are available:
10 | *
11 | *
12 | *
13 | *
R0G0 / BLANK
14 | *
R1G0
15 | *
R2G0
16 | *
R3G0 / RED
17 | *
18 | *
19 | *
R0G1
20 | *
R1G1
21 | *
R2G1
22 | *
R3G1
23 | *
24 | *
25 | *
R0G2
26 | *
R1G2
27 | *
R2G2
28 | *
R3G2
29 | *
30 | *
31 | *
R0G3 / GREEN
32 | *
R1G3
33 | *
R2G3
34 | *
R3G3 / AMBER
35 | *
36 | *
37 | *
38 | * Support for other launchpads will follow, if you can help me, you can find all information via
39 | * github.
40 | */
41 | public enum Color {
42 |
43 | R0G0(0x00), R1G0(0x01), R2G0(0x02), R3G0(0x03), //
44 | R0G1(0x10), R1G1(0x11), R2G1(0x12), R3G1(0x13), //
45 | R0G2(0x20), R1G2(0x21), R2G2(0x22), R3G2(0x23), //
46 | R0G3(0x30), R1G3(0x31), R2G3(0x32), R3G3(0x33);
47 |
48 | /**
49 | * Alias for {@link #R0G0}
50 | */
51 | public static final Color BLANK = R0G0;
52 | /**
53 | * Alias for {@link #R0G3}
54 | */
55 | public static final Color GREEN = R0G3;
56 | /**
57 | * Alias for {@link #R3G0}
58 | */
59 | public static final Color RED = R3G0;
60 | /**
61 | * Alias for {@link #R3G3}
62 | */
63 | public static final Color AMBER = R3G3;
64 |
65 | private int code;
66 |
67 | private Color(int code) {
68 | this.code = code;
69 | }
70 |
71 | /**
72 | * Provide the code to be sent to the launchpad device.
73 | *
74 | * @return the code to be sent to the launchpad device
75 | */
76 | public int getCode() {
77 | return code;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/rjung/util/launchpad/Launchpad.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | import javax.sound.midi.InvalidMidiDataException;
4 | import javax.sound.midi.MidiMessage;
5 | import javax.sound.midi.MidiSystem;
6 | import javax.sound.midi.MidiUnavailableException;
7 | import javax.sound.midi.Receiver;
8 | import javax.sound.midi.ShortMessage;
9 | import javax.sound.midi.Transmitter;
10 |
11 | /**
12 | * The {@link Launchpad} provides access to a Launchpad via the midi-device.
13 | *
14 | * To get a notication when a button is pressed on the Launchpad you can add a
15 | * {@link LaunchpadReceiver} with the constructors {@link Launchpad#Launchpad(LaunchpadReceiver)}
16 | * and {@link Launchpad#Launchpad(Channel, LaunchpadReceiver)}.
17 | */
18 | public class Launchpad implements Receiver {
19 |
20 | private final Channel channel;
21 | private final Transmitter transmitter;
22 | private final Receiver receiver;
23 | private final LaunchpadReceiver launchpadReceiver;
24 |
25 | /**
26 | * Use this constructor if you want to use the default implementation, and don't whant to receive
27 | * the event of a {@link Pad} being pressed. You probably have only one midi device, and the
28 | * default channel is {@link Channel#C1}.
29 | *
30 | * @throws MidiUnavailableException No midi device could be found, is your launchpad connected to
31 | * your computer?
32 | */
33 | public Launchpad() throws MidiUnavailableException {
34 | this(Channel.C1);
35 | }
36 |
37 | /**
38 | * Use this constructor if you have configured your launchpad to receive on a specific midi
39 | * channel that is not the default {@link Channel#C1}. You will not receive any messages if a
40 | * {@link Pad} is beeing pressed.
41 | *
42 | * @param channel The {@link Channel} to send and receive data to and from.
43 | * @throws MidiUnavailableException No midi device could be found, is your launchpad connected to
44 | * your computer?
45 | */
46 | public Launchpad(Channel channel) throws MidiUnavailableException {
47 | this(channel, null);
48 | }
49 |
50 | /**
51 | * This is the simpliest solution if you want to receive notifications if a {@link Pad} is being
52 | * pressed, but you still use the default midi channel ({@link Channel#C1}) of your launchpad.
53 | *
54 | * @param launchpadReceiver The {@link LaunchpadReceiver} implementation that will receive the
55 | * information if a {@link Pad} is pressed.
56 | * @throws MidiUnavailableException No midi device could be found, is your launchpad connected to
57 | * your computer?
58 | */
59 | public Launchpad(LaunchpadReceiver launchpadReceiver) throws MidiUnavailableException {
60 | this(Channel.C1, launchpadReceiver);
61 | }
62 |
63 | /**
64 | * This is the full configured solution if you want to receive notifications if a {@link Pad} is
65 | * being pressed, and want to configure the midi channel (default is {@link Channel#C1}) of your
66 | * launchpad.
67 | *
68 | * @param channel The {@link Channel} to send and receive data to and from.
69 | * @param launchpadReceiver The {@link LaunchpadReceiver} implementation that will receive the
70 | * information if a {@link Pad} is pressed.
71 | * @throws MidiUnavailableException No midi device could be found, is your launchpad connected to
72 | * your computer?
73 | */
74 | public Launchpad(Channel channel, LaunchpadReceiver launchpadReceiver)
75 | throws MidiUnavailableException {
76 | this.channel = channel;
77 | transmitter = MidiSystem.getTransmitter();
78 | receiver = MidiSystem.getReceiver();
79 | this.launchpadReceiver = launchpadReceiver;
80 |
81 | transmitter.setReceiver(this);
82 | }
83 |
84 | /**
85 | * To set the {@link Color} of a {@link Pad}, use this method.
86 | *
87 | * @param pad The {@link Pad} that you want to set to a {@link Color}.
88 | * @param color The {@link Color} that you want the {@link Pad} to be lit up.
89 | * @throws InvalidMidiDataException The communication failed.
90 | */
91 | public void set(final Pad pad, final Color color) throws InvalidMidiDataException {
92 | receiver.send(new ShortMessage(pad.getCommand(), this.channel.channelForSystem(), pad.getCode(),
93 | color.getCode()), -1);
94 | }
95 |
96 | /**
97 | * Please do not use this method. It's the internal implementation to receive midi commands.
98 | */
99 | @Override
100 | public void send(MidiMessage message, long timeStamp) {
101 | if (this.launchpadReceiver != null && message instanceof ShortMessage) {
102 | ShortMessage sm = (ShortMessage) message;
103 | Pad pad = Pad.findMidi(sm);
104 | if (pad != null) {
105 | this.launchpadReceiver.receive(pad);
106 | }
107 | }
108 | }
109 |
110 | /**
111 | * Before not using the {@link Launchpad} any more (for example when exiting the application),
112 | * please {@link #close()} the {@link Launchpad} to release resources bound by it.
113 | */
114 | @Override
115 | public void close() {
116 | this.receiver.close();
117 | this.transmitter.close();
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/org/rjung/util/launchpad/LaunchpadReceiver.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | public interface LaunchpadReceiver {
4 | public void receive(Pad pad);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/org/rjung/util/launchpad/Pad.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | import java.util.Arrays;
4 |
5 | import javax.sound.midi.ShortMessage;
6 |
7 | public enum Pad {
8 |
9 | CON1(6, 8, ShortMessage.CONTROL_CHANGE), CON2(6, 9, ShortMessage.CONTROL_CHANGE), //
10 | CON3(6, 10, ShortMessage.CONTROL_CHANGE), CON4(6, 11, ShortMessage.CONTROL_CHANGE), //
11 | CON5(6, 12, ShortMessage.CONTROL_CHANGE), CON6(6, 13, ShortMessage.CONTROL_CHANGE), //
12 | CON7(6, 14, ShortMessage.CONTROL_CHANGE), CON8(6, 15, ShortMessage.CONTROL_CHANGE), //
13 | A1(0, 0), A2(0, 1), A3(0, 2), A4(0, 3), A5(0, 4), A6(0, 5), A7(0, 6), A8(0, 7), A(0, 8), //
14 | B1(1, 0), B2(1, 1), B3(1, 2), B4(1, 3), B5(1, 4), B6(1, 5), B7(1, 6), B8(1, 7), B(1, 8), //
15 | C1(2, 0), C2(2, 1), C3(2, 2), C4(2, 3), C5(2, 4), C6(2, 5), C7(2, 6), C8(2, 7), C(2, 8), //
16 | D1(3, 0), D2(3, 1), D3(3, 2), D4(3, 3), D5(3, 4), D6(3, 5), D7(3, 6), D8(3, 7), D(3, 8), //
17 | E1(4, 0), E2(4, 1), E3(4, 2), E4(4, 3), E5(4, 4), E6(4, 5), E7(4, 6), E8(4, 7), E(4, 8), //
18 | F1(5, 0), F2(5, 1), F3(5, 2), F4(5, 3), F5(5, 4), F6(5, 5), F7(5, 6), F8(5, 7), F(5, 8), //
19 | G1(6, 0), G2(6, 1), G3(6, 2), G4(6, 3), G5(6, 4), G6(6, 5), G7(6, 6), G8(6, 7), G(6, 8), //
20 | H1(7, 0), H2(7, 1), H3(7, 2), H4(7, 3), H5(7, 4), H6(7, 5), H7(7, 6), H8(7, 7), H(7, 8);
21 |
22 | private final int x;
23 | private final int y;
24 | private final int command;
25 |
26 | private Pad(int x, int y) {
27 | this(x, y, ShortMessage.NOTE_ON);
28 | }
29 |
30 | private Pad(int x, int y, int command) {
31 | this.x = x;
32 | this.y = y;
33 | this.command = command;
34 | }
35 |
36 | public int getX() {
37 | return x;
38 | }
39 |
40 | public int getY() {
41 | return y;
42 | }
43 |
44 | public int getCode() {
45 | return x * 16 + y;
46 | }
47 |
48 | public int getCommand() {
49 | return command;
50 | }
51 |
52 | public static Pad find(int x, int y) {
53 | return Arrays.stream(values())
54 | .filter(p -> p.command == ShortMessage.NOTE_ON && p.x == x && p.y == y).findFirst()
55 | .orElse(null);
56 | }
57 |
58 | static Pad findMidi(ShortMessage message) {
59 | return Arrays.stream(values())
60 | .filter(p -> p.command == message.getCommand() && p.getCode() == message.getData1())
61 | .findFirst().orElse(null);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/rjung/util/launchpad/ChannelTest.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | import static org.junit.Assert.assertThat;
4 | import static org.hamcrest.CoreMatchers.is;
5 |
6 | import org.junit.Test;
7 |
8 | public class ChannelTest {
9 |
10 | @Test
11 | public void verifyChannelForSystem() {
12 | assertThat(Channel.C1.channelForSystem(), is(0));
13 | assertThat(Channel.C2.channelForSystem(), is(1));
14 | assertThat(Channel.C3.channelForSystem(), is(2));
15 | assertThat(Channel.C4.channelForSystem(), is(3));
16 | assertThat(Channel.C5.channelForSystem(), is(4));
17 | assertThat(Channel.C6.channelForSystem(), is(5));
18 | assertThat(Channel.C7.channelForSystem(), is(6));
19 | assertThat(Channel.C8.channelForSystem(), is(7));
20 | assertThat(Channel.C9.channelForSystem(), is(8));
21 | assertThat(Channel.C10.channelForSystem(), is(9));
22 | assertThat(Channel.C11.channelForSystem(), is(10));
23 | assertThat(Channel.C12.channelForSystem(), is(11));
24 | assertThat(Channel.C13.channelForSystem(), is(12));
25 | assertThat(Channel.C14.channelForSystem(), is(13));
26 | assertThat(Channel.C15.channelForSystem(), is(14));
27 | assertThat(Channel.C16.channelForSystem(), is(15));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/org/rjung/util/launchpad/ColorTest.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 |
4 | import static org.junit.Assert.assertThat;
5 | import static org.hamcrest.CoreMatchers.is;
6 |
7 | import org.junit.Test;
8 |
9 | public class ColorTest {
10 |
11 | @Test
12 | public void verifyColorCodes() {
13 | assertThat(Color.R0G0.getCode(), is(0x00));
14 | assertThat(Color.R1G0.getCode(), is(0x01));
15 | assertThat(Color.R2G0.getCode(), is(0x02));
16 | assertThat(Color.R3G0.getCode(), is(0x03));
17 |
18 | assertThat(Color.R0G1.getCode(), is(0x10));
19 | assertThat(Color.R1G1.getCode(), is(0x11));
20 | assertThat(Color.R2G1.getCode(), is(0x12));
21 | assertThat(Color.R3G1.getCode(), is(0x13));
22 |
23 | assertThat(Color.R0G2.getCode(), is(0x20));
24 | assertThat(Color.R1G2.getCode(), is(0x21));
25 | assertThat(Color.R2G2.getCode(), is(0x22));
26 | assertThat(Color.R3G2.getCode(), is(0x23));
27 |
28 | assertThat(Color.R0G3.getCode(), is(0x30));
29 | assertThat(Color.R1G3.getCode(), is(0x31));
30 | assertThat(Color.R2G3.getCode(), is(0x32));
31 | assertThat(Color.R3G3.getCode(), is(0x33));
32 |
33 | assertThat(Color.BLANK.getCode(), is(0x00));
34 | assertThat(Color.GREEN.getCode(), is(0x30));
35 | assertThat(Color.RED.getCode(), is(0x03));
36 | assertThat(Color.AMBER.getCode(), is(0x33));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/rjung/util/launchpad/PadTest.java:
--------------------------------------------------------------------------------
1 | package org.rjung.util.launchpad;
2 |
3 | import static org.hamcrest.CoreMatchers.is;
4 | import static org.junit.Assert.assertThat;
5 |
6 | import java.util.Arrays;
7 |
8 | import javax.sound.midi.InvalidMidiDataException;
9 | import javax.sound.midi.ShortMessage;
10 |
11 | import org.junit.Test;
12 |
13 | public class PadTest {
14 |
15 | @Test
16 | public void verifyCode() {
17 | assertThat(Pad.A1.getCode(), is(0x00));
18 | assertThat(Pad.A2.getCode(), is(0x01));
19 | assertThat(Pad.A3.getCode(), is(0x02));
20 | assertThat(Pad.A4.getCode(), is(0x03));
21 | assertThat(Pad.A5.getCode(), is(0x04));
22 | assertThat(Pad.A6.getCode(), is(0x05));
23 | assertThat(Pad.A7.getCode(), is(0x06));
24 | assertThat(Pad.A8.getCode(), is(0x07));
25 |
26 | assertThat(Pad.B1.getCode(), is(0x10));
27 | assertThat(Pad.B2.getCode(), is(0x11));
28 | assertThat(Pad.B3.getCode(), is(0x12));
29 | assertThat(Pad.B4.getCode(), is(0x13));
30 | assertThat(Pad.B5.getCode(), is(0x14));
31 | assertThat(Pad.B6.getCode(), is(0x15));
32 | assertThat(Pad.B7.getCode(), is(0x16));
33 | assertThat(Pad.B8.getCode(), is(0x17));
34 |
35 | assertThat(Pad.C1.getCode(), is(0x20));
36 | assertThat(Pad.C2.getCode(), is(0x21));
37 | assertThat(Pad.C3.getCode(), is(0x22));
38 | assertThat(Pad.C4.getCode(), is(0x23));
39 | assertThat(Pad.C5.getCode(), is(0x24));
40 | assertThat(Pad.C6.getCode(), is(0x25));
41 | assertThat(Pad.C7.getCode(), is(0x26));
42 | assertThat(Pad.C8.getCode(), is(0x27));
43 |
44 | assertThat(Pad.D1.getCode(), is(0x30));
45 | assertThat(Pad.D2.getCode(), is(0x31));
46 | assertThat(Pad.D3.getCode(), is(0x32));
47 | assertThat(Pad.D4.getCode(), is(0x33));
48 | assertThat(Pad.D5.getCode(), is(0x34));
49 | assertThat(Pad.D6.getCode(), is(0x35));
50 | assertThat(Pad.D7.getCode(), is(0x36));
51 | assertThat(Pad.D8.getCode(), is(0x37));
52 |
53 | assertThat(Pad.E1.getCode(), is(0x40));
54 | assertThat(Pad.E2.getCode(), is(0x41));
55 | assertThat(Pad.E3.getCode(), is(0x42));
56 | assertThat(Pad.E4.getCode(), is(0x43));
57 | assertThat(Pad.E5.getCode(), is(0x44));
58 | assertThat(Pad.E6.getCode(), is(0x45));
59 | assertThat(Pad.E7.getCode(), is(0x46));
60 | assertThat(Pad.E8.getCode(), is(0x47));
61 |
62 | assertThat(Pad.F1.getCode(), is(0x50));
63 | assertThat(Pad.F2.getCode(), is(0x51));
64 | assertThat(Pad.F3.getCode(), is(0x52));
65 | assertThat(Pad.F4.getCode(), is(0x53));
66 | assertThat(Pad.F5.getCode(), is(0x54));
67 | assertThat(Pad.F6.getCode(), is(0x55));
68 | assertThat(Pad.F7.getCode(), is(0x56));
69 | assertThat(Pad.F8.getCode(), is(0x57));
70 |
71 | assertThat(Pad.G1.getCode(), is(0x60));
72 | assertThat(Pad.G2.getCode(), is(0x61));
73 | assertThat(Pad.G3.getCode(), is(0x62));
74 | assertThat(Pad.G4.getCode(), is(0x63));
75 | assertThat(Pad.G5.getCode(), is(0x64));
76 | assertThat(Pad.G6.getCode(), is(0x65));
77 | assertThat(Pad.G7.getCode(), is(0x66));
78 | assertThat(Pad.G8.getCode(), is(0x67));
79 |
80 | assertThat(Pad.H1.getCode(), is(0x70));
81 | assertThat(Pad.H2.getCode(), is(0x71));
82 | assertThat(Pad.H3.getCode(), is(0x72));
83 | assertThat(Pad.H4.getCode(), is(0x73));
84 | assertThat(Pad.H5.getCode(), is(0x74));
85 | assertThat(Pad.H6.getCode(), is(0x75));
86 | assertThat(Pad.H7.getCode(), is(0x76));
87 | assertThat(Pad.H8.getCode(), is(0x77));
88 |
89 | assertThat(Pad.A.getCode(), is(0x08));
90 | assertThat(Pad.B.getCode(), is(0x18));
91 | assertThat(Pad.C.getCode(), is(0x28));
92 | assertThat(Pad.D.getCode(), is(0x38));
93 | assertThat(Pad.E.getCode(), is(0x48));
94 | assertThat(Pad.F.getCode(), is(0x58));
95 | assertThat(Pad.G.getCode(), is(0x68));
96 | assertThat(Pad.H.getCode(), is(0x78));
97 |
98 | assertThat(Pad.CON1.getCode(), is(0x68));
99 | assertThat(Pad.CON2.getCode(), is(0x69));
100 | assertThat(Pad.CON3.getCode(), is(0x6a));
101 | assertThat(Pad.CON4.getCode(), is(0x6b));
102 | assertThat(Pad.CON5.getCode(), is(0x6c));
103 | assertThat(Pad.CON6.getCode(), is(0x6d));
104 | assertThat(Pad.CON7.getCode(), is(0x6e));
105 | assertThat(Pad.CON8.getCode(), is(0x6f));
106 | }
107 |
108 | @Test
109 | public void verifyCommand() {
110 | for (Pad pad : Arrays.asList( //
111 | Pad.A1, Pad.A2, Pad.A3, Pad.A4, Pad.A5, Pad.A6, Pad.A7, Pad.A8, //
112 | Pad.B1, Pad.B2, Pad.B3, Pad.B4, Pad.B5, Pad.B6, Pad.B7, Pad.B8, //
113 | Pad.C1, Pad.C2, Pad.C3, Pad.C4, Pad.C5, Pad.C6, Pad.C7, Pad.C8, //
114 | Pad.D1, Pad.D2, Pad.D3, Pad.D4, Pad.D5, Pad.D6, Pad.D7, Pad.D8, //
115 | Pad.E1, Pad.E2, Pad.E3, Pad.E4, Pad.E5, Pad.E6, Pad.E7, Pad.E8, //
116 | Pad.F1, Pad.F2, Pad.F3, Pad.F4, Pad.F5, Pad.F6, Pad.F7, Pad.F8, //
117 | Pad.G1, Pad.G2, Pad.G3, Pad.G4, Pad.G5, Pad.G6, Pad.G7, Pad.G8, //
118 | Pad.H1, Pad.H2, Pad.H3, Pad.H4, Pad.H5, Pad.H6, Pad.H7, Pad.H8, //
119 | Pad.A, Pad.B, Pad.C, Pad.D, Pad.E, Pad.F, Pad.G, Pad.H)) {
120 | assertThat(pad.getCommand(), is(ShortMessage.NOTE_ON));
121 | }
122 |
123 | for (Pad pad : Arrays.asList( //
124 | Pad.CON1, Pad.CON2, Pad.CON3, Pad.CON4, Pad.CON5, Pad.CON6, Pad.CON7, Pad.CON8)) {
125 | assertThat(pad.getCommand(), is(ShortMessage.CONTROL_CHANGE));
126 | }
127 | }
128 |
129 | @Test
130 | public void verifyPadsAreFoundByCoordinate() {
131 | for (Pad pad : Pad.values()) {
132 | // Do not tests CON?-Pads
133 | if (pad.getCommand() == ShortMessage.NOTE_ON) {
134 | assertThat(Pad.find(pad.getX(), pad.getY()), is(pad));
135 | }
136 | }
137 | }
138 |
139 | @Test
140 | public void verifyFindByMidiMessage() throws InvalidMidiDataException {
141 | for (Pad pad : Pad.values()) {
142 | assertThat(Pad.findMidi(new ShortMessage(pad.getCommand(), 0, pad.getCode(), 0)), is(pad));
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------