added java based health display to show if values are send by the actors

This commit is contained in:
Lucas Pleß 2014-04-17 11:25:14 +02:00
parent ca3e271eab
commit 7e0bc24273
19 changed files with 1099 additions and 0 deletions

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
<profile default="false" name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<processorPath useClasspath="true" />
<module name="healthdisplay" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -0,0 +1,5 @@
<component name="CopyrightManager">
<settings default="">
<module2copyright />
</settings>
</component>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: com.illposed.osc:javaosc-core:0.2">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/illposed/osc/javaosc-core/0.2/javaosc-core-0.2.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/illposed/osc/javaosc-core/0.2/javaosc-core-0.2-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/illposed/osc/javaosc-core/0.2/javaosc-core-0.2-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.jboss.netty:netty:3.2.7.Final">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/netty/netty/3.2.7.Final/netty-3.2.7.Final.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/netty/netty/3.2.7.Final/netty-3.2.7.Final-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/netty/netty/3.2.7.Final/netty-3.2.7.Final-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/healthdisplay.iml" filepath="$PROJECT_DIR$/healthdisplay.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,5 @@
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
<item class="ActorDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
</item>
</group>
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.illposed.osc:javaosc-core:0.2" level="project" />
<orderEntry type="library" name="Maven: org.jboss.netty:netty:3.2.7.Final" level="project" />
</component>
</module>

36
healthdisplay/pom.xml Normal file
View File

@ -0,0 +1,36 @@
<project>
<modelVersion>4.0.0</modelVersion>
<name>Maven Default Project</name>
<version>1.0</version>
<artifactId>psychose</artifactId>
<groupId>psy</groupId>
<dependencies>
<dependency>
<groupId>com.illposed.osc</groupId>
<artifactId>javaosc-core</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.7.Final</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ActorDisplay">
<grid id="27dc6" binding="actorPanel" layout-manager="GridLayoutManager" row-count="8" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="4" left="6" bottom="4" right="6"/>
<constraints>
<xy x="20" y="20" width="220" height="220"/>
</constraints>
<properties>
<background color="-16777216"/>
<foreground color="-1"/>
<minimumSize width="220" height="220"/>
<preferredSize width="0" height="0"/>
</properties>
<border type="line">
<color color="-11447983"/>
</border>
<children>
<component id="bd8cd" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="Pulse"/>
</properties>
</component>
<vspacer id="1290">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="d0a2" class="javax.swing.JLabel" binding="lblPulse">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="-"/>
</properties>
</component>
<component id="87d0b" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="Oxy"/>
</properties>
</component>
<component id="8ed94" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="EKG"/>
</properties>
</component>
<component id="6b43c" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="EMG"/>
</properties>
</component>
<component id="c92b9" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="Heart"/>
</properties>
</component>
<component id="e1c6d" class="javax.swing.JLabel" binding="lblOxy">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="-"/>
</properties>
</component>
<component id="5ed45" class="javax.swing.JLabel" binding="lblEkg">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="-"/>
</properties>
</component>
<component id="c159" class="javax.swing.JLabel" binding="lblEmg">
<constraints>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="-"/>
</properties>
</component>
<component id="a5eac" class="javax.swing.JLabel" binding="lblHeartbeat">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="-"/>
</properties>
</component>
<component id="9b787" class="javax.swing.JLabel" binding="lblCaption">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="28" style="1"/>
<foreground color="-1"/>
<text value="Label"/>
</properties>
</component>
<component id="4d72a" class="javax.swing.JLabel">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="Temp"/>
</properties>
</component>
<component id="3a160" class="javax.swing.JLabel" binding="lblTemperature">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono" size="20"/>
<foreground color="-1"/>
<text value="-"/>
</properties>
</component>
</children>
</grid>
</form>

View File

@ -0,0 +1,117 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Random;
/**
* @author: lucas
* @date: 14.04.14 21:44
*/
public class ActorDisplay {
private final static Color onColor = Color.WHITE;
private final static Color offColor = Color.RED;
private JPanel actorPanel;
private JLabel lblCaption;
private JLabel lblHeartbeat;
private JLabel lblPulse;
private JLabel lblOxy;
private JLabel lblEkg;
private JLabel lblEmg;
private JLabel lblTemperature;
private int counterHeartbeat = 0;
private int counterPulse = 0;
private int counterOxy = 0;
private int counterEkg = 0;
private int counterEmg = 0;
private int counterTemperature = 0;
private int timeout = 20; // 20 * 100ms
public void setCaption(String caption) {
lblCaption.setText(caption);
}
public void setTemperature(String temperature) {
lblTemperature.setText(temperature);
counterTemperature = 0;
}
public void setEkg(String value) {
lblEkg.setText(value);
counterEkg = 0;
}
public void setPulse(String pulse) {
lblPulse.setText(pulse);
counterPulse = 0;
}
public void setEmg(String emg) {
lblEmg.setText(emg);
counterEmg = 0;
}
public void setOxy(String oxy) {
lblOxy.setText(oxy);
counterOxy = 0;
}
public void setHeartbeat(String heartbeat) {
lblHeartbeat.setText(heartbeat);
counterHeartbeat = 0;
}
public ActorDisplay() {
final Random r = new Random();
final Timer timer = new Timer(100, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
// actorPanel.setBackground(new Color(r.nextInt(), false));
if(++counterTemperature > timeout) {
lblTemperature.setForeground(offColor);
} else {
lblTemperature.setForeground(onColor);
}
if(++counterPulse > timeout) {
lblPulse.setForeground(offColor);
} else {
lblPulse.setForeground(onColor);
}
if(++counterOxy > timeout) {
lblOxy.setForeground(offColor);
} else {
lblOxy.setForeground(onColor);
}
if(++counterEkg > timeout) {
lblEkg.setForeground(offColor);
} else {
lblEkg.setForeground(onColor);
}
if(++counterEmg > timeout) {
lblEmg.setForeground(offColor);
} else {
lblEmg.setForeground(onColor);
}
if(++counterHeartbeat > timeout) {
lblHeartbeat.setForeground(offColor);
} else {
lblHeartbeat.setForeground(onColor);
}
}
});
timer.setRepeats(true);
timer.start();
}
}

View File

@ -0,0 +1,86 @@
import com.illposed.osc.OSCListener;
import com.illposed.osc.OSCMessage;
import com.illposed.osc.OSCPortIn;
import com.illposed.osc.OSCPortOut;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
/**
* @author: lucas
* @date: 13.04.14 17:03
*/
public class ChaOSCclient {
private final static int OSC_CLIENT_PORT = 8123;
private OSCPortIn portIn;
private OSCPortOut portOut;
public ChaOSCclient(String host, int port) throws UnknownHostException, SocketException {
portOut = new OSCPortOut(InetAddress.getByName(host), port);
}
public void addListener(String address, OSCListener listener) {
portIn.addListener(address, listener);
}
public boolean stopReceiver() {
portIn.stopListening();
return changeChaoscSubscription(false);
}
public boolean startReceiver() {
try {
portIn = new OSCPortIn(OSC_CLIENT_PORT);
portIn.startListening();
return changeChaoscSubscription(true);
} catch (SocketException e) {
System.out.println("could not create listening socket");
e.printStackTrace();
}
return false;
}
private boolean changeChaoscSubscription(boolean subscribe) {
try {
OSCMessage subscribeMessage = new OSCMessage("/" + (subscribe ? "subscribe" : "unsubscribe"));
subscribeMessage.addArgument(getLocalAddress().getHostAddress());
subscribeMessage.addArgument(OSC_CLIENT_PORT);
subscribeMessage.addArgument("sekret");
subscribeMessage.addArgument("statusmonitor");
portOut.send(subscribeMessage);
return true;
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("could not change chaosc subscription message");
return false;
}
private InetAddress getLocalAddress() throws SocketException {
final Enumeration<NetworkInterface> n = NetworkInterface.getNetworkInterfaces();
while (n.hasMoreElements()) {
NetworkInterface e = n.nextElement();
Enumeration<InetAddress> a = e.getInetAddresses();
for (; a.hasMoreElements(); ) {
InetAddress addr = a.nextElement();
if (addr.isSiteLocalAddress()) {
return addr;
}
}
}
throw new SocketException();
}
}

View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="MainForm">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<xy x="20" y="20" width="720" height="576"/>
</constraints>
<properties>
<background color="-16777216"/>
<foreground color="-1"/>
<maximumSize width="720" height="576"/>
<minimumSize width="720" height="576"/>
<preferredSize width="720" height="576"/>
</properties>
<border type="none"/>
<children>
<vspacer id="b61d">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<nested-form id="71726" form-file="/ActorDisplay.form" binding="actor1">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<nested-form id="a01e1" form-file="/ActorDisplay.form" binding="actor2">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<nested-form id="914d6" form-file="/ActorDisplay.form" binding="actor3">
<constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<hspacer id="8e2fe">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="f912c">
<constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>

View File

@ -0,0 +1,105 @@
import com.illposed.osc.OSCListener;
import com.illposed.osc.OSCMessage;
import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Date;
/**
* @author: lucas
* @date: 14.04.14 21:43
*/
public class MainForm {
private ChaOSCclient osCclient;
private JPanel mainPanel;
private ActorDisplay actor1;
private ActorDisplay actor2;
private ActorDisplay actor3;
public MainForm(ChaOSCclient client) {
osCclient = client;
osCclient.startReceiver();
addActor("merle", "Merle", actor1);
addActor("uwe", "Uwe", actor2);
addActor("bjoern", "Björn", actor3);
}
private void addActor(final String actor, final String label, final ActorDisplay actorDisplay) {
actorDisplay.setCaption(label);
osCclient.addListener("/" + actor.toLowerCase() + "/heartbeat", new OSCListener() {
@Override
public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 3) {
actorDisplay.setHeartbeat(message.getArguments()[0].toString());
actorDisplay.setPulse(message.getArguments()[1].toString());
actorDisplay.setOxy(message.getArguments()[2].toString());
}
}
});
osCclient.addListener("/" + actor.toLowerCase() + "/ekg", new OSCListener() {
@Override
public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) {
actorDisplay.setEkg(message.getArguments()[0].toString());
}
}
});
osCclient.addListener("/" + actor.toLowerCase() + "/emg", new OSCListener() {
@Override
public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) {
actorDisplay.setEmg(message.getArguments()[0].toString());
}
}
});
osCclient.addListener("/" + actor.toLowerCase() + "/temperatur", new OSCListener() {
@Override
public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) {
actorDisplay.setTemperature(message.getArguments()[0].toString());
}
}
});
}
public static void main(String[] args) {
try {
final ChaOSCclient chaOSCclient = new ChaOSCclient("localhost", 7110);
final MainForm mainForm = new MainForm(chaOSCclient);
final JFrame frame = new JFrame("MainForm");
frame.setContentPane(mainForm.mainPanel);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
chaOSCclient.stopReceiver();
super.windowClosing(e);
}
});
frame.setVisible(true);
new Streamer(8888, mainForm.mainPanel).run();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,254 @@
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.*;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.jboss.netty.handler.codec.frame.TooLongFrameException;
import org.jboss.netty.handler.codec.http.*;
import org.jboss.netty.handler.stream.ChunkedInput;
import org.jboss.netty.handler.stream.ChunkedWriteHandler;
import org.jboss.netty.util.CharsetUtil;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static org.jboss.netty.handler.codec.http.HttpMethod.GET;
import static org.jboss.netty.handler.codec.http.HttpResponseStatus.*;
import static org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1;
/**
* @author Maurus Cuelenaere <mcuelenaere@gmail.com>
* taken from http://blog.maurus.be/2012/05/09/netty-mjpeg-streamer/
*/
public class Streamer {
private final int port;
private final Component view;
private final ViewRenderer renderer;
private class ViewRenderer implements Runnable {
private final BufferedImage image;
private final AtomicReference<byte[]> currentBuffer;
private final AtomicInteger listenerCount;
private final int napTime;
private final ByteArrayOutputStream outputStream;
public ViewRenderer() {
this(10);
}
public ViewRenderer(int fps) {
this.napTime = 1000 / fps;
this.listenerCount = new AtomicInteger();
this.currentBuffer = new AtomicReference<byte[]>();
this.image = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_RGB);
this.outputStream = new ByteArrayOutputStream();
}
@Override
public void run() {
while (!Thread.interrupted()) {
long sleepTill = System.currentTimeMillis() + napTime;
if (listenerCount.get() > 0) {
Graphics g = image.createGraphics();
view.paint(g);
g.dispose();
byte[] newData = null;
try {
ImageIO.write(image, "jpg", outputStream);
newData = outputStream.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
outputStream.reset();
}
if (newData != null) {
currentBuffer.set(newData);
synchronized (currentBuffer) {
currentBuffer.notifyAll();
}
}
}
try {
long remainingTime = sleepTill - System.currentTimeMillis();
if (remainingTime > 0)
Thread.sleep(remainingTime);
} catch (InterruptedException e) {
return;
}
}
}
public void registerListener() {
listenerCount.incrementAndGet();
}
public void unregisterListener() {
listenerCount.decrementAndGet();
}
public void waitForData() throws InterruptedException {
synchronized (currentBuffer) {
currentBuffer.wait();
}
}
public byte[] getData() {
return currentBuffer.get();
}
}
private class HttpMultipartReplaceStream implements ChunkedInput {
private final byte[] header;
private boolean closed;
public HttpMultipartReplaceStream(String boundary) {
this.header = ("--" + boundary + "\r\nContent-Type: image/jpeg\r\n\r\n").getBytes();
renderer.registerListener();
}
@Override
public void close() throws Exception {
if (closed)
return;
closed = true;
renderer.unregisterListener();
}
@Override
public boolean hasNextChunk() throws Exception {
return !closed;
}
@Override
public boolean isEndOfInput() throws Exception {
return closed;
}
@Override
public Object nextChunk() throws Exception {
if (closed)
return null;
renderer.waitForData();
byte[] body = renderer.getData();
return ChannelBuffers.wrappedBuffer(header, body);
}
}
private class HttpStreamerHandler extends SimpleChannelUpstreamHandler {
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
HttpRequest request = (HttpRequest) e.getMessage();
if (request.getMethod() != GET) {
sendError(ctx, METHOD_NOT_ALLOWED);
return;
} else if (!"/stream".equals(request.getUri())) {
sendError(ctx, NOT_FOUND);
return;
}
final String boundary = "thisisourmagicboundary";
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
HttpHeaders.setHeader(response, "Connection", "close");
HttpHeaders.setHeader(response, "Content-Type", "multipart/x-mixed-replace;boundary=" + boundary);
HttpHeaders.setHeader(response, "Cache-control", "no-cache");
HttpHeaders.setHeader(response, "Pragma", "no-cache");
HttpHeaders.setHeader(response, "Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
Channel ch = e.getChannel();
final HttpMultipartReplaceStream replaceStream = new HttpMultipartReplaceStream(boundary);
ch.getCloseFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
// Stop the stream when the channel is closed
replaceStream.close();
}
});
// Write the initial line and the headers
ch.write(response);
// Write the content
ChannelFuture writeFuture = ch.write(replaceStream);
// Close the connection when the whole content is written out
writeFuture.addListener(ChannelFutureListener.CLOSE);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
Channel ch = e.getChannel();
Throwable cause = e.getCause();
if (cause instanceof TooLongFrameException) {
sendError(ctx, BAD_REQUEST);
return;
} else if (cause instanceof ClosedChannelException) {
ch.close();
return;
}
cause.printStackTrace();
if (ch.isConnected())
sendError(ctx, INTERNAL_SERVER_ERROR);
}
private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.setContent(ChannelBuffers.copiedBuffer("Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8));
// Close the connection as soon as the error message is sent.
ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
}
public Streamer(int port, Component view) {
this.port = port;
this.view = view;
this.renderer = new ViewRenderer();
}
public void run() {
// Configure the server.
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
// Set up the event pipeline factory.
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
pipeline.addLast("handler", new HttpStreamerHandler());
return pipeline;
}
});
// Bind and start to accept incoming connections.
bootstrap.bind(new InetSocketAddress(port));
// Start the renderer
new Thread(renderer, "Image renderer").start();
}
}

View File

@ -0,0 +1,49 @@
import javax.sound.midi.*;
import java.io.File;
public class Test {
public static final int NOTE_ON = 0x90;
public static final int NOTE_OFF = 0x80;
public static final String[] NOTE_NAMES = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
public static void main(String[] args) throws Exception {
Sequence sequence = MidiSystem.getSequence(new File("/home/lucas/jake-avril_14th.mid"));
int trackNumber = 0;
for (Track track : sequence.getTracks()) {
trackNumber++;
System.out.println("Track " + trackNumber + ": size = " + track.size());
System.out.println();
for (int i=0; i < track.size(); i++) {
MidiEvent event = track.get(i);
System.out.print("@" + event.getTick() + " ");
MidiMessage message = event.getMessage();
if (message instanceof ShortMessage) {
ShortMessage sm = (ShortMessage) message;
System.out.print("Channel: " + sm.getChannel() + " ");
if (sm.getCommand() == NOTE_ON) {
int key = sm.getData1();
int octave = (key / 12)-1;
int note = key % 12;
String noteName = NOTE_NAMES[note];
int velocity = sm.getData2();
System.out.println("Note on, " + noteName + octave + " key=" + key + " velocity: " + velocity);
} else if (sm.getCommand() == NOTE_OFF) {
int key = sm.getData1();
int octave = (key / 12)-1;
int note = key % 12;
String noteName = NOTE_NAMES[note];
int velocity = sm.getData2();
System.out.println("Note off, " + noteName + octave + " key=" + key + " velocity: " + velocity);
} else {
System.out.println("Command:" + sm.getCommand());
}
} else {
System.out.println("Other message: " + message.getClass());
}
}
System.out.println();
}
}
}