added stats display, removed border from actor display

This commit is contained in:
Lucas Pleß 2014-04-18 03:06:41 +02:00
parent a6a3666c15
commit a53cf435de
8 changed files with 205 additions and 46 deletions

View File

@ -122,6 +122,9 @@
<item class="main.java.de.psychose.ActorDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false"> <item class="main.java.de.psychose.ActorDisplay" icon="" removable="true" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" /> <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
</item> </item>
<item class="de.psychose.StatsDisplay" 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> </group>
</component> </component>
</project> </project>

View File

@ -3,7 +3,7 @@
<grid id="27dc6" binding="actorPanel" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="actorPanel" layout-manager="GridLayoutManager" row-count="9" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="4" left="6" bottom="4" right="6"/> <margin top="4" left="6" bottom="4" right="6"/>
<constraints> <constraints>
<xy x="20" y="20" width="220" height="250"/> <xy x="20" y="20" width="316" height="302"/>
</constraints> </constraints>
<properties> <properties>
<background color="-16777216"/> <background color="-16777216"/>
@ -11,7 +11,7 @@
<minimumSize width="220" height="250"/> <minimumSize width="220" height="250"/>
<preferredSize width="0" height="0"/> <preferredSize width="0" height="0"/>
</properties> </properties>
<border type="line"> <border type="none">
<color color="-11447983"/> <color color="-11447983"/>
</border> </border>
<children> <children>

View File

@ -23,6 +23,7 @@ public class ChaOSCclient {
public ChaOSCclient(String host, int port) throws UnknownHostException, SocketException { public ChaOSCclient(String host, int port) throws UnknownHostException, SocketException {
portOut = new OSCPortOut(InetAddress.getByName(host), port); portOut = new OSCPortOut(InetAddress.getByName(host), port);
portIn = new OSCPortIn(OSC_CLIENT_PORT);
} }
public void addListener(String address, OSCListener listener) { public void addListener(String address, OSCListener listener) {
@ -35,17 +36,8 @@ public class ChaOSCclient {
} }
public boolean startReceiver() { public boolean startReceiver() {
try {
portIn = new OSCPortIn(OSC_CLIENT_PORT);
portIn.startListening(); portIn.startListening();
return changeChaoscSubscription(true); return changeChaoscSubscription(true);
} catch (SocketException e) {
System.out.println("could not create listening socket");
e.printStackTrace();
}
return false;
} }
private boolean changeChaoscSubscription(boolean subscribe) { private boolean changeChaoscSubscription(boolean subscribe) {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.MainForm"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.MainForm">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="4" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/> <margin top="5" left="5" bottom="5" right="5"/>
<constraints> <constraints>
<xy x="20" y="20" width="720" height="576"/> <xy x="20" y="20" width="720" height="576"/>
@ -14,21 +14,31 @@
</properties> </properties>
<border type="none"/> <border type="none"/>
<children> <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>
<hspacer id="f912c"> <hspacer id="f912c">
<constraints> <constraints>
<grid row="0" column="5" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="5" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<nested-form id="bd9b" form-file="de/psychose/ActorDisplay.form" binding="actor1"> <hspacer id="6a2b8">
<constraints> <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"/> <grid row="1" column="1" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="67192">
<constraints>
<grid row="1" column="3" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<nested-form id="5519b" form-file="de/psychose/StatsDisplay.form" binding="statDisplay">
<constraints>
<grid row="3" 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> </constraints>
</nested-form> </nested-form>
<vspacer id="ad2ab">
<constraints>
<grid row="2" 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="736bf" form-file="de/psychose/ActorDisplay.form" binding="actor2"> <nested-form id="736bf" form-file="de/psychose/ActorDisplay.form" binding="actor2">
<constraints> <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"/> <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"/>
@ -39,16 +49,11 @@
<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"/> <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> </constraints>
</nested-form> </nested-form>
<hspacer id="6a2b8"> <nested-form id="bd9b" form-file="de/psychose/ActorDisplay.form" binding="actor1">
<constraints> <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"/> <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> </constraints>
</hspacer> </nested-form>
<hspacer id="67192">
<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> </children>
</grid> </grid>
</form> </form>

View File

@ -4,6 +4,7 @@ import com.illposed.osc.OSCListener;
import com.illposed.osc.OSCMessage; import com.illposed.osc.OSCMessage;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.net.SocketException; import java.net.SocketException;
@ -21,14 +22,30 @@ public class MainForm {
private ActorDisplay actor1; private ActorDisplay actor1;
private ActorDisplay actor2; private ActorDisplay actor2;
private ActorDisplay actor3; private ActorDisplay actor3;
private StatsDisplay statDisplay;
public MainForm(ChaOSCclient client) { private int totalMessageCount = 0;
osCclient = client; private int messagesTempCounter = 0;
osCclient.startReceiver();
public MainForm(ChaOSCclient chaOSCclient) {
osCclient = chaOSCclient;
addActor("merle", "Proband 1", actor1); addActor("merle", "Proband 1", actor1);
addActor("uwe", "Proband 2", actor2); addActor("uwe", "Proband 2", actor2);
addActor("bjoern", "Proband 3", actor3); addActor("bjoern", "Proband 3", actor3);
osCclient.startReceiver();
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();
} }
@ -38,6 +55,7 @@ public class MainForm {
@Override @Override
public void acceptMessage(Date time, OSCMessage message) { public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 3) { if (message.getArguments().length == 3) {
totalMessageCount++;
actorDisplay.setHeartbeat(message.getArguments()[0].toString()); actorDisplay.setHeartbeat(message.getArguments()[0].toString());
actorDisplay.setPulse(message.getArguments()[1].toString()); actorDisplay.setPulse(message.getArguments()[1].toString());
actorDisplay.setOxy(message.getArguments()[2].toString()); actorDisplay.setOxy(message.getArguments()[2].toString());
@ -49,6 +67,7 @@ public class MainForm {
@Override @Override
public void acceptMessage(Date time, OSCMessage message) { public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) { if (message.getArguments().length == 1) {
totalMessageCount++;
actorDisplay.setEkg(message.getArguments()[0].toString()); actorDisplay.setEkg(message.getArguments()[0].toString());
} }
} }
@ -58,6 +77,7 @@ public class MainForm {
@Override @Override
public void acceptMessage(Date time, OSCMessage message) { public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) { if (message.getArguments().length == 1) {
totalMessageCount++;
actorDisplay.setEmg(message.getArguments()[0].toString()); actorDisplay.setEmg(message.getArguments()[0].toString());
} }
} }
@ -67,6 +87,7 @@ public class MainForm {
@Override @Override
public void acceptMessage(Date time, OSCMessage message) { public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) { if (message.getArguments().length == 1) {
totalMessageCount++;
actorDisplay.setTemperature(message.getArguments()[0].toString()); actorDisplay.setTemperature(message.getArguments()[0].toString());
} }
} }
@ -76,6 +97,7 @@ public class MainForm {
@Override @Override
public void acceptMessage(Date time, OSCMessage message) { public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) { if (message.getArguments().length == 1) {
totalMessageCount++;
actorDisplay.setBreath(message.getArguments()[0].toString()); actorDisplay.setBreath(message.getArguments()[0].toString());
} }
} }
@ -84,16 +106,16 @@ public class MainForm {
public static void main(String[] args) { public static void main(String[] args) {
String host = args.length > 0 ? args[0] : "chaosc"; final String host = args.length > 0 ? args[0] : "chaosc";
final int port = args.length > 1 ? Integer.parseInt(args[1]) : 7110;
try { try {
final ChaOSCclient chaOSCclient = new ChaOSCclient(host, 7110); final ChaOSCclient chaOSCclient = new ChaOSCclient(host, port);
final MainForm mainForm = new MainForm(chaOSCclient); final MainForm mainForm = new MainForm(chaOSCclient);
final JFrame frame = new JFrame("MainForm"); final JFrame frame = new JFrame("MainForm");
frame.setContentPane(mainForm.mainPanel); frame.setContentPane(mainForm.mainPanel);
frame.setResizable(false); frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack(); frame.pack();
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
@ -108,9 +130,7 @@ public class MainForm {
new Streamer(8888, mainForm.mainPanel).run(); new Streamer(8888, mainForm.mainPanel).run();
} catch (UnknownHostException e) { } catch (UnknownHostException | SocketException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="de.psychose.StatsDisplay">
<grid id="27dc6" binding="statPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="248" height="180"/>
</constraints>
<properties>
<background color="-16777216"/>
<foreground color="-1"/>
<minimumSize width="220" height="180"/>
</properties>
<border type="none"/>
<children>
<component id="69530" class="javax.swing.JLabel" binding="lblCaption">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" 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="Statistik"/>
</properties>
</component>
<vspacer id="9a59f">
<constraints>
<grid row="4" 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="1d950" 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="Events"/>
</properties>
</component>
<component id="442f5" 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="Ev/Sek"/>
</properties>
</component>
<component id="4b993" 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="Herz"/>
</properties>
</component>
<component id="54c59" class="javax.swing.JLabel" binding="lblMessageCount">
<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="eaaf9" class="javax.swing.JLabel" binding="lblMessagesPerSec">
<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="a2840" class="javax.swing.JLabel">
<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>
</children>
</grid>
</form>

View File

@ -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);
}
}

View File

@ -2,6 +2,11 @@ package de.psychose;
import javax.sound.midi.*; import javax.sound.midi.*;
import java.io.File; 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; import java.util.HashSet;
public class Test { public class Test {
@ -9,7 +14,27 @@ public class Test {
public static final int NOTE_OFF = 0x80; public static final int NOTE_OFF = 0x80;
public static final String[] NOTE_NAMES = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "H"}; 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<InetAddress> 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 { public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> 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")); Sequence sequence = MidiSystem.getSequence(new File("/home/lucas/jake-avril_14th.mid"));
HashSet<String> notes = new HashSet<String>(); HashSet<String> notes = new HashSet<String>();
@ -57,7 +82,6 @@ public class Test {
} }
System.out.println(notes); System.out.println(notes);
} }
} }