Skip to content

angular-java-server-midi "modernisation" #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
target
*~
.*
238 changes: 131 additions & 107 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,113 +1,137 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.ng.piano</groupId>
<artifactId>angular-java-server-midi</artifactId>
<packaging>war</packaging>
<version>0.1-SNAPSHOT</version>
<name>angular-java-server-midi Java EE 6 Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.ng.piano</groupId>
<artifactId>angular-java-server-midi</artifactId>
<packaging>war</packaging>
<version>0.1-SNAPSHOT</version>
<name>angular-java-server-midi Java EE 6 Webapp</name>
<url>http://maven.apache.org</url>
<repositories>
<repository>
<id>java.net2</id>
<name>Repository hosting the jee6 artifacts</name>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>

<!-- Jersey (RESTful Web services) -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.7</version>
</dependency>
<!-- Jersey (RESTful Web services) -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.7</version>
</dependency>

<!-- Jackson (JSON processor) -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.8.1</version>
</dependency>
<!-- Jackson (JSON processor) -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.8.1</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.0.2.v20100331</version>
</plugin>
<plugin>
<!-- https://github.com/searls/jasmine-maven-plugin -->
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.0.2-beta-2</version>
<executions>
<execution>
<goals>
<goal>generateManualRunner</goal>
<goal>resources</goal>
<goal>testResources</goal>
<goal>test</goal>
<goal>preparePackage</goal>
</goals>
<configuration>
<jsSrcDir>${project.basedir}/src/main/webapp/js</jsSrcDir>
<sourceIncludes>
<include>*.js</include>
</sourceIncludes>
<jsTestSrcDir>${project.basedir}/src/test/js</jsTestSrcDir>
<specIncludes>
<include>lib/angular-mocks.js</include>
<include>spec/*.js</include>
</specIncludes>
<preloadSources>
<source>lib/angular-0.9.17.patched.js</source>
<source>lib/angular-mocks.js</source>
</preloadSources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>angular-java-server-midi</finalName>
</build>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.0.2.v20100331</version>
</plugin>
<plugin>
<!-- https://github.com/searls/jasmine-maven-plugin -->
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>1.3.1.2</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<jsSrcDir>${project.basedir}/src/main/webapp/js</jsSrcDir>
<jasmineTargetDir>${project.build.directory}/surefire-reports</jasmineTargetDir>
<sourceIncludes>
<include>*.js</include>
</sourceIncludes>
<jsTestSrcDir>${project.basedir}/src/test/js</jsTestSrcDir>
<specIncludes>
<include>spec/*.js</include>
</specIncludes>
<preloadSources>
<source>http://code.jquery.com/jquery-1.9.1.js</source>
<source>${project.basedir}/src/main/webapp/js/lib/angular-1.0.7.min.js</source>
<source>${project.basedir}/src/test/js/lib/angular-mocks-1.0.7.js</source>
</preloadSources>
<!--webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName -->
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<!-- Ensure surefire runs after Jasmine. - https://issues.jenkins-ci.org/browse/JENKINS-13188
- Maven plugins are run in the order specified in pom.xml, with inherited
plugins first. - So we must redefine the "test" goal's execution to be after
Jasmine. -->
<id>surefire-test</id>
<phase>test</phase>

<goals>
<goal>test</goal>
</goals>

<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</execution>
</executions>
<configuration>
<!-- Disable the default maven-surefire-plugin execution from parent
pom. -->
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
<finalName>angular-java-server-midi</finalName>
</build>
</project>

28 changes: 14 additions & 14 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
<!doctype html>
<html>
<html ng-app="piano">
<head>
<title>Server Side Piano</title>
<script src="js/lib/angular-0.9.17.patched.js" ng:autobind></script>
<script src="js/lib/angular-1.0.7.min.js"></script>
<script src="js/controllers.js"></script>
</head>
<body ng:controller="PianoCtrl">
<body ng-controller="PianoCtrl">
<div id="piano">
<div id="top">
<div id="logo">Server Side Piano</div>
<div id="box">
Keys
<select id="start-octave" name="startOctave" ng:format="number" ng:change="resetKeyboard()">
<select id="start-octave" ng-model="startOctave" ng-format="number" ng-change="resetKeyboard()">
<option value="0">A0</option>
<option value="1">A1</option>
<option value="2">A2</option>
<option value="3">A3</option>
</select>
-
<select id="end-octave" name="endOctave" ng:format="number" ng:change="resetKeyboard()">
<select id="end-octave" ng-model="endOctave" ng-format="number" ng-change="resetKeyboard()">
<option value="5">C5</option>
<option value="6">C6</option>
<option value="7">C7</option>
<option value="8">C8</option>
</select>
Note names <input type="checkbox" name="showNames" />
Note names <input type="checkbox" ng-model="showNames" />
</div>
</div>

<div id="keyboard">
<div ng:repeat="key in keyboard.$filter({color:'white'})"
<div ng-repeat="key in keyboard | filter:{color:'white'}"
class="key white"
ng:style="key.cssPosition"
ng:click="sendMidiCommand(NOTE_ON, key.midiNote)">
<span ng:show="showNames" class="key-name">{{key.name}}</span>
ng-style="key.cssPosition"
ng-click="sendMidiCommand(NOTE_ON, key.midiNote)">
<span ng-show="showNames" class="key-name">{{key.name}}</span>
</div>
<div ng:repeat="key in keyboard.$filter({color:'black'})"
<div ng-repeat="key in keyboard | filter:{color:'black'}"
class="key black"
ng:style="key.cssPosition"
ng:click="sendMidiCommand(NOTE_ON, key.midiNote)">
<span ng:show="showNames" class="key-name">{{key.name}}</span>
ng-style="key.cssPosition"
ng-click="sendMidiCommand(NOTE_ON, key.midiNote)">
<span ng-show="showNames" class="key-name">{{key.name}}</span>
</div>
</div>
</div>
Expand Down
49 changes: 24 additions & 25 deletions src/main/webapp/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function PianoCtrl($xhr) {
$xhr.defaults.headers.post['Content-Type'] = 'application/json';
var scope = this;
angular.module('piano', []);

function PianoCtrl($scope, $http) {
var genKeyboard = function(startOctave, endOctave) {
if (startOctave < 0 || endOctave > 8 || startOctave >= endOctave) throw "Bad arguments";
var notes = [
Expand All @@ -25,39 +24,39 @@ function PianoCtrl($xhr) {
});
}
return keys;
}
};
var keys = genOctave(startOctave, 9, 12); // A, Bb, B
for (var oct=startOctave+1; oct < endOctave; oct++) {
keys = keys.concat( genOctave(oct, 0, 12) ); // Full octave
}
return keys.concat( genOctave(endOctave, 0, 1) ); // C
}
};

scope.NOTE_ON = 144;
scope.NOTE_OFF = 128;
scope.sendMidiCommand = function(command, midiNote) {
$scope.NOTE_ON = 144;
$scope.NOTE_OFF = 128;
$scope.sendMidiCommand = function(command, midiNote) {
var midiMessage = {
command: command,
channel: scope.channel,
channel: $scope.channel,
note: midiNote,
velocity: scope.velocity
}
velocity: $scope.velocity
};
var timeStart = new Date().getTime();
$xhr('POST', '/data/midi/send', midiMessage, function(code, response) {
scope.latency = new Date().getTime() - timeStart;
$http.post('data/midi/send', midiMessage).success(function(response, code) {
$scope.latency = new Date().getTime() - timeStart;
});
}
};

scope.startOctave = 2;
scope.endOctave = 6;
scope.resetKeyboard = function() {
scope.keyboard = genKeyboard(scope.startOctave, scope.endOctave);
}
scope.resetKeyboard();
$scope.startOctave = 2;
$scope.endOctave = 6;
$scope.resetKeyboard = function() {
$scope.keyboard = genKeyboard($scope.startOctave, $scope.endOctave);
};
$scope.resetKeyboard();

scope.latency = 0;
scope.showNames = true;
scope.channel = 0;
scope.velocity = 60;
$scope.latency = 0;
$scope.showNames = true;
$scope.channel = 0;
$scope.velocity = 60;
}
PianoCtrl.$inject = ['$xhr'];
PianoCtrl.$inject = ['$scope', '$http'];
Loading