diff --git a/healthdisplay/.idea/compiler.xml b/healthdisplay/.idea/compiler.xml index fa7a277..2e11072 100644 --- a/healthdisplay/.idea/compiler.xml +++ b/healthdisplay/.idea/compiler.xml @@ -25,6 +25,9 @@ + + + diff --git a/healthdisplay/.idea/libraries/Maven__asm_asm_3_0.xml b/healthdisplay/.idea/libraries/Maven__asm_asm_3_0.xml new file mode 100644 index 0000000..7967610 --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__asm_asm_3_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/libraries/Maven__asm_asm_commons_3_0.xml b/healthdisplay/.idea/libraries/Maven__asm_asm_commons_3_0.xml new file mode 100644 index 0000000..3cef17f --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__asm_asm_commons_3_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/libraries/Maven__asm_asm_tree_3_0.xml b/healthdisplay/.idea/libraries/Maven__asm_asm_tree_3_0.xml new file mode 100644 index 0000000..967bfbd --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__asm_asm_tree_3_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/libraries/Maven__com_intellij_forms_rt_7_0_3.xml b/healthdisplay/.idea/libraries/Maven__com_intellij_forms_rt_7_0_3.xml new file mode 100644 index 0000000..7c63da5 --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__com_intellij_forms_rt_7_0_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/libraries/Maven__com_jgoodies_forms_1_1_preview.xml b/healthdisplay/.idea/libraries/Maven__com_jgoodies_forms_1_1_preview.xml new file mode 100644 index 0000000..230ff65 --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__com_jgoodies_forms_1_1_preview.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/libraries/Maven__jdom_jdom_1_0.xml b/healthdisplay/.idea/libraries/Maven__jdom_jdom_1_0.xml new file mode 100644 index 0000000..3349d67 --- /dev/null +++ b/healthdisplay/.idea/libraries/Maven__jdom_jdom_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/healthdisplay/.idea/uiDesigner.xml b/healthdisplay/.idea/uiDesigner.xml index fbab987..c312b7a 100644 --- a/healthdisplay/.idea/uiDesigner.xml +++ b/healthdisplay/.idea/uiDesigner.xml @@ -119,7 +119,10 @@ - + + + + diff --git a/healthdisplay/README b/healthdisplay/README new file mode 100644 index 0000000..4a3b245 --- /dev/null +++ b/healthdisplay/README @@ -0,0 +1,5 @@ + + +compile with + +mvn clean compile ideauidesigner:javac2 assembly:single diff --git a/healthdisplay/healthdisplay.iml b/healthdisplay/healthdisplay.iml index e6e4b05..8a76843 100644 --- a/healthdisplay/healthdisplay.iml +++ b/healthdisplay/healthdisplay.iml @@ -1,16 +1,22 @@ - + - + + + + + + + diff --git a/healthdisplay/pom.xml b/healthdisplay/pom.xml index fe39b78..30de015 100644 --- a/healthdisplay/pom.xml +++ b/healthdisplay/pom.xml @@ -6,6 +6,8 @@ psychose psy + jar + com.illposed.osc @@ -18,6 +20,12 @@ netty 3.2.7.Final + + com.intellij + forms_rt + 7.0.3 + + @@ -33,4 +41,50 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + UTF-8 + + + + maven-assembly-plugin + + + + de.psychose.MainForm + + + + jar-with-dependencies + + + + + org.codehaus.mojo + ideauidesigner-maven-plugin + + + + javac2 + + + + + + true + true + true + + + + + + \ No newline at end of file diff --git a/healthdisplay/src/ActorDisplay.form b/healthdisplay/src/main/java/de/psychose/ActorDisplay.form similarity index 83% rename from healthdisplay/src/ActorDisplay.form rename to healthdisplay/src/main/java/de/psychose/ActorDisplay.form index 0506171..1884b4e 100644 --- a/healthdisplay/src/ActorDisplay.form +++ b/healthdisplay/src/main/java/de/psychose/ActorDisplay.form @@ -1,17 +1,17 @@ -
- + + - + - + - + @@ -22,12 +22,12 @@ - + - + @@ -77,7 +77,7 @@ - + @@ -120,16 +120,6 @@ - - - - - - - - - - @@ -150,6 +140,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/healthdisplay/src/ActorDisplay.java b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java similarity index 80% rename from healthdisplay/src/ActorDisplay.java rename to healthdisplay/src/main/java/de/psychose/ActorDisplay.java index cfcd95a..542cd83 100644 --- a/healthdisplay/src/ActorDisplay.java +++ b/healthdisplay/src/main/java/de/psychose/ActorDisplay.java @@ -1,3 +1,5 @@ +package de.psychose; + import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; @@ -19,6 +21,7 @@ public class ActorDisplay { private JLabel lblEkg; private JLabel lblEmg; private JLabel lblTemperature; + private JLabel lblBreath; private int counterHeartbeat = 0; private int counterPulse = 0; @@ -26,6 +29,7 @@ public class ActorDisplay { private int counterEkg = 0; private int counterEmg = 0; private int counterTemperature = 0; + private int counterBreath = 0; private int timeout = 20; // 20 * 100ms @@ -33,6 +37,11 @@ public class ActorDisplay { lblCaption.setText(caption); } + public void setBreath(String breath) { + lblBreath.setText(breath); + counterBreath = 0; + } + public void setTemperature(String temperature) { lblTemperature.setText(temperature); counterTemperature = 0; @@ -72,46 +81,53 @@ public class ActorDisplay { // actorPanel.setBackground(new Color(r.nextInt(), false)); - if(++counterTemperature > timeout) { + if (++counterTemperature > timeout) { lblTemperature.setForeground(offColor); } else { lblTemperature.setForeground(onColor); } - if(++counterPulse > timeout) { + if (++counterPulse > timeout) { lblPulse.setForeground(offColor); } else { lblPulse.setForeground(onColor); } - if(++counterOxy > timeout) { + if (++counterOxy > timeout) { lblOxy.setForeground(offColor); } else { lblOxy.setForeground(onColor); } - if(++counterEkg > timeout) { + if (++counterEkg > timeout) { lblEkg.setForeground(offColor); } else { lblEkg.setForeground(onColor); } - if(++counterEmg > timeout) { + if (++counterEmg > timeout) { lblEmg.setForeground(offColor); } else { lblEmg.setForeground(onColor); } - if(++counterHeartbeat > timeout) { + if (++counterHeartbeat > timeout) { lblHeartbeat.setForeground(offColor); } else { lblHeartbeat.setForeground(onColor); } + if (++counterBreath > timeout) { + lblBreath.setForeground(offColor); + } else { + lblBreath.setForeground(onColor); + } + } }); timer.setRepeats(true); timer.start(); } + } diff --git a/healthdisplay/src/ChaOSCclient.java b/healthdisplay/src/main/java/de/psychose/ChaOSCclient.java similarity index 87% rename from healthdisplay/src/ChaOSCclient.java rename to healthdisplay/src/main/java/de/psychose/ChaOSCclient.java index a277421..ec4fc9d 100644 --- a/healthdisplay/src/ChaOSCclient.java +++ b/healthdisplay/src/main/java/de/psychose/ChaOSCclient.java @@ -1,3 +1,5 @@ +package de.psychose; + import com.illposed.osc.OSCListener; import com.illposed.osc.OSCMessage; import com.illposed.osc.OSCPortIn; @@ -21,6 +23,7 @@ public class ChaOSCclient { public ChaOSCclient(String host, int port) throws UnknownHostException, SocketException { portOut = new OSCPortOut(InetAddress.getByName(host), port); + portIn = new OSCPortIn(OSC_CLIENT_PORT); } public void addListener(String address, OSCListener listener) { @@ -33,17 +36,8 @@ public class ChaOSCclient { } 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; + portIn.startListening(); + return changeChaoscSubscription(true); } private boolean changeChaoscSubscription(boolean subscribe) { diff --git a/healthdisplay/src/MainForm.form b/healthdisplay/src/main/java/de/psychose/MainForm.form similarity index 60% rename from healthdisplay/src/MainForm.form rename to healthdisplay/src/main/java/de/psychose/MainForm.form index aa1bed6..c3adf46 100644 --- a/healthdisplay/src/MainForm.form +++ b/healthdisplay/src/main/java/de/psychose/MainForm.form @@ -1,6 +1,6 @@ -
- + + @@ -14,36 +14,46 @@ - + - + - - + + - + + + + + + + + + + + - + + + + + + - + - + - + - - - - - - + diff --git a/healthdisplay/src/MainForm.java b/healthdisplay/src/main/java/de/psychose/MainForm.java similarity index 62% rename from healthdisplay/src/MainForm.java rename to healthdisplay/src/main/java/de/psychose/MainForm.java index c5f52db..d4cd4b1 100644 --- a/healthdisplay/src/MainForm.java +++ b/healthdisplay/src/main/java/de/psychose/MainForm.java @@ -1,7 +1,10 @@ +package de.psychose; + import com.illposed.osc.OSCListener; import com.illposed.osc.OSCMessage; import javax.swing.*; +import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.net.SocketException; @@ -19,14 +22,30 @@ public class MainForm { private ActorDisplay actor1; private ActorDisplay actor2; private ActorDisplay actor3; + private StatsDisplay statDisplay; + + private int totalMessageCount = 0; + private int messagesTempCounter = 0; + + public MainForm(ChaOSCclient chaOSCclient) { + osCclient = chaOSCclient; + + addActor("merle", "Proband 1", actor1); + addActor("uwe", "Proband 2", actor2); + addActor("bjoern", "Proband 3", actor3); - public MainForm(ChaOSCclient client) { - osCclient = client; osCclient.startReceiver(); - addActor("merle", "Merle", actor1); - addActor("uwe", "Uwe", actor2); - addActor("bjoern", "Björn", actor3); + final Timer timer = new Timer(1000, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + statDisplay.setMessagesPerSec(String.valueOf(totalMessageCount - messagesTempCounter)); + statDisplay.setMessageCount(String.valueOf(totalMessageCount)); + messagesTempCounter = totalMessageCount; + } + }); + timer.setRepeats(true); + timer.start(); } @@ -36,6 +55,7 @@ public class MainForm { @Override public void acceptMessage(Date time, OSCMessage message) { if (message.getArguments().length == 3) { + totalMessageCount++; actorDisplay.setHeartbeat(message.getArguments()[0].toString()); actorDisplay.setPulse(message.getArguments()[1].toString()); actorDisplay.setOxy(message.getArguments()[2].toString()); @@ -47,6 +67,7 @@ public class MainForm { @Override public void acceptMessage(Date time, OSCMessage message) { if (message.getArguments().length == 1) { + totalMessageCount++; actorDisplay.setEkg(message.getArguments()[0].toString()); } } @@ -56,6 +77,7 @@ public class MainForm { @Override public void acceptMessage(Date time, OSCMessage message) { if (message.getArguments().length == 1) { + totalMessageCount++; actorDisplay.setEmg(message.getArguments()[0].toString()); } } @@ -65,22 +87,35 @@ public class MainForm { @Override public void acceptMessage(Date time, OSCMessage message) { if (message.getArguments().length == 1) { + totalMessageCount++; actorDisplay.setTemperature(message.getArguments()[0].toString()); } } }); + + osCclient.addListener("/" + actor.toLowerCase() + "/airFlow", new OSCListener() { + @Override + public void acceptMessage(Date time, OSCMessage message) { + if (message.getArguments().length == 1) { + totalMessageCount++; + actorDisplay.setBreath(message.getArguments()[0].toString()); + } + } + }); } public static void main(String[] args) { - try { - final ChaOSCclient chaOSCclient = new ChaOSCclient("localhost", 7110); + final String host = args.length > 0 ? args[0] : "chaosc"; + final int port = args.length > 1 ? Integer.parseInt(args[1]) : 7110; + try { + final ChaOSCclient chaOSCclient = new ChaOSCclient(host, port); 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.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.addWindowListener(new WindowAdapter() { @@ -95,9 +130,7 @@ public class MainForm { new Streamer(8888, mainForm.mainPanel).run(); - } catch (UnknownHostException e) { - e.printStackTrace(); - } catch (SocketException e) { + } catch (UnknownHostException | SocketException e) { e.printStackTrace(); } } diff --git a/healthdisplay/src/main/java/de/psychose/StatsDisplay.form b/healthdisplay/src/main/java/de/psychose/StatsDisplay.form new file mode 100644 index 0000000..0dd0183 --- /dev/null +++ b/healthdisplay/src/main/java/de/psychose/StatsDisplay.form @@ -0,0 +1,92 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/healthdisplay/src/main/java/de/psychose/StatsDisplay.java b/healthdisplay/src/main/java/de/psychose/StatsDisplay.java new file mode 100644 index 0000000..4989777 --- /dev/null +++ b/healthdisplay/src/main/java/de/psychose/StatsDisplay.java @@ -0,0 +1,23 @@ +package de.psychose; + +import javax.swing.*; + +/** + * @author: lucas + * @date: 18.04.14 02:19 + */ +public class StatsDisplay { + private JLabel lblCaption; + private JLabel lblMessageCount; + private JLabel lblMessagesPerSec; + private JPanel statPanel; + + public void setMessageCount(String count) { + lblMessageCount.setText(count); + } + + public void setMessagesPerSec(String messagesPerSec) { + lblMessagesPerSec.setText(messagesPerSec); + } + +} diff --git a/healthdisplay/src/Streamer.java b/healthdisplay/src/main/java/de/psychose/Streamer.java similarity index 99% rename from healthdisplay/src/Streamer.java rename to healthdisplay/src/main/java/de/psychose/Streamer.java index 1796b55..deea16a 100644 --- a/healthdisplay/src/Streamer.java +++ b/healthdisplay/src/main/java/de/psychose/Streamer.java @@ -1,3 +1,5 @@ +package de.psychose; + import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.*; diff --git a/healthdisplay/src/Test.java b/healthdisplay/src/main/java/de/psychose/Test.java similarity index 59% rename from healthdisplay/src/Test.java rename to healthdisplay/src/main/java/de/psychose/Test.java index 2aec3a5..deb48b6 100644 --- a/healthdisplay/src/Test.java +++ b/healthdisplay/src/main/java/de/psychose/Test.java @@ -1,20 +1,50 @@ +package de.psychose; + import javax.sound.midi.*; import java.io.File; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; 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 final String[] NOTE_NAMES = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "H"}; + + private static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { + System.out.printf("Display name: %s%n", netint.getDisplayName()); + System.out.printf("Name: %s%n", netint.getName()); + Enumeration inetAddresses = netint.getInetAddresses(); + + for (InetAddress inetAddress : Collections.list(inetAddresses)) { + System.out.printf("InetAddress: %s%n", inetAddress); + } + System.out.printf("%n"); + } public static void main(String[] args) throws Exception { + + Enumeration nets = NetworkInterface.getNetworkInterfaces(); + for (NetworkInterface netint : Collections.list(nets)) { + displayInterfaceInformation(netint); + } + + + if(true) return; + Sequence sequence = MidiSystem.getSequence(new File("/home/lucas/jake-avril_14th.mid")); + HashSet notes = new HashSet(); + int trackNumber = 0; - for (Track track : sequence.getTracks()) { + 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++) { + for (int i = 0; i < track.size(); i++) { MidiEvent event = track.get(i); System.out.print("@" + event.getTick() + " "); MidiMessage message = event.getMessage(); @@ -23,14 +53,17 @@ public class Test { System.out.print("Channel: " + sm.getChannel() + " "); if (sm.getCommand() == NOTE_ON) { int key = sm.getData1(); - int octave = (key / 12)-1; + 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); + + notes.add(noteName + octave); + } else if (sm.getCommand() == NOTE_OFF) { int key = sm.getData1(); - int octave = (key / 12)-1; + int octave = (key / 12) - 1; int note = key % 12; String noteName = NOTE_NAMES[note]; int velocity = sm.getData2(); @@ -44,6 +77,11 @@ public class Test { } System.out.println(); + + } + + + System.out.println(notes); } } \ No newline at end of file