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">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="0" />
</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>
</component>
</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">
<margin top="4" left="6" bottom="4" right="6"/>
<constraints>
<xy x="20" y="20" width="220" height="250"/>
<xy x="20" y="20" width="316" height="302"/>
</constraints>
<properties>
<background color="-16777216"/>
@ -11,7 +11,7 @@
<minimumSize width="220" height="250"/>
<preferredSize width="0" height="0"/>
</properties>
<border type="line">
<border type="none">
<color color="-11447983"/>
</border>
<children>

View File

@ -23,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) {
@ -35,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;
}
private boolean changeChaoscSubscription(boolean subscribe) {

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"/>
<constraints>
<xy x="20" y="20" width="720" height="576"/>
@ -14,21 +14,31 @@
</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>
<hspacer id="f912c">
<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>
</hspacer>
<nested-form id="bd9b" form-file="de/psychose/ActorDisplay.form" binding="actor1">
<hspacer id="6a2b8">
<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>
</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">
<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"/>
@ -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"/>
</constraints>
</nested-form>
<hspacer id="6a2b8">
<nested-form id="bd9b" form-file="de/psychose/ActorDisplay.form" binding="actor1">
<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>
</hspacer>
<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>
</nested-form>
</children>
</grid>
</form>

View File

@ -4,6 +4,7 @@ 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;
@ -21,14 +22,30 @@ public class MainForm {
private ActorDisplay actor1;
private ActorDisplay actor2;
private ActorDisplay actor3;
private StatsDisplay statDisplay;
public MainForm(ChaOSCclient client) {
osCclient = client;
osCclient.startReceiver();
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);
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
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());
@ -49,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());
}
}
@ -58,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());
}
}
@ -67,6 +87,7 @@ public class MainForm {
@Override
public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) {
totalMessageCount++;
actorDisplay.setTemperature(message.getArguments()[0].toString());
}
}
@ -76,6 +97,7 @@ public class MainForm {
@Override
public void acceptMessage(Date time, OSCMessage message) {
if (message.getArguments().length == 1) {
totalMessageCount++;
actorDisplay.setBreath(message.getArguments()[0].toString());
}
}
@ -84,16 +106,16 @@ public class MainForm {
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 {
final ChaOSCclient chaOSCclient = new ChaOSCclient(host, 7110);
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() {
@ -108,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();
}
}

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 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 {
@ -9,7 +14,27 @@ public class Test {
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"};
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 {
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"));
HashSet<String> notes = new HashSet<String>();
@ -19,7 +44,7 @@ public class Test {
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();
@ -28,17 +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);
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();
@ -57,7 +82,6 @@ public class Test {
}
System.out.println(notes);
}
}