add working base tools

This commit is contained in:
Philipp Kramer 2021-11-11 11:03:30 +01:00
commit 16ba9d6f36
5 changed files with 80166 additions and 0 deletions

View file

@ -0,0 +1,21 @@
Table table;
float frequency=4; //data frequency in Hz
int duration=1000*10; //in ms
void setup() {
table = new Table();
table.addColumn("time"); // in milliseconds
table.addColumn("heartrate");
table.addColumn("random");
for (int i=0;i<(int)(duration/frequency);i++) {
TableRow newRow = table.addRow();
newRow.setInt("time", (int)(i*(1000/frequency)));
newRow.setFloat("heartrate", noise(i/10)*40.0+60);
newRow.setFloat("random", random(1));
}
saveTable(table, "data.csv");
println("Finished");
}

40001
csvrandomwriter/data.csv Normal file

File diff suppressed because it is too large Load diff

40001
oscplayer/data.csv Normal file

File diff suppressed because it is too large Load diff

67
oscplayer/oscplayer.pde Normal file
View file

@ -0,0 +1,67 @@
String baseaddress="/oscplayer/";
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
Table data;
TableRow datarow;
int rowid=0;
long time=0;
void setup() {
size(400,400);
frameRate(60);
data = loadTable("data.csv", "header, csv");
println(data.getRowCount() + " total rows in data");
println("Header:");
for (String title : data.getColumnTitles()) {
print(title+", ");
}
println();
datarow = data.getRow(rowid); //get first row
oscP5 = new OscP5(this,12000); //Port for input OSC Messages
myRemoteLocation = new NetAddress("127.0.0.1",7000); //connect to remote, IP, Port
}
void draw() {
time=millis();
background(0);
long rowtime=datarow.getInt("time"); //time of the currently loaded row (next to send)
if (time>=rowtime) //time to send next row
{
//Send all columns
for (String title : data.getColumnTitles()) {
sendOSC(title,datarow.getFloat(title));
}
datarow = data.getRow(rowid++); //load next row
}
}
void sendOSC(String name,float data) {
OscMessage myMessage = new OscMessage(baseaddress+name);
//println("Sending name="+name+" with data="+data);
myMessage.add(data);
oscP5.send(myMessage, myRemoteLocation);
}
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/* print the address pattern and the typetag of the received OscMessage */
print("### received an osc message.");
print(" addrpattern: "+theOscMessage.addrPattern());
println(" typetag: "+theOscMessage.typetag());
}

76
oscviewer/oscviewer.pde Normal file
View file

@ -0,0 +1,76 @@
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
String baseaddress="/oscplayer/";
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
class OSCMsg {
long time;
OscArgument arg0;
String address;
OSCMsg (long ptime, OscArgument parg, String paddress) {
time=ptime;
arg0=parg;
address=paddress;
}
String argString(){
return ""+arg0.floatValue(); //TODO
}
}
List<OSCMsg> msglist;;
void setup() {
size(400,400);
frameRate(60);
oscP5 = new OscP5(this,7000); //Port for input OSC Messages
msglist = new CopyOnWriteArrayList<OSCMsg>();
}
void draw() {
background(0);
//positions
int ystart=10; //distance from top
int xstartTime=5;
int xstartAddr=80;
int xstartArg0=200;
int ydist=12;
int row=0;
for (OSCMsg m : msglist) { //check if address already known
text(m.time, xstartTime,ystart+row*ydist);
text(m.address, xstartAddr,ystart+row*ydist);
text(m.argString(), xstartArg0,ystart+row*ydist);
row++;
}
}
void oscEvent(OscMessage cmsg) {
boolean found=false;
for (OSCMsg m : msglist) { //check if address already known
if (m.address.equals(cmsg.addrPattern())) { //found, then update data
m.arg0=cmsg.get(0);
m.time=millis();
found=true;
}
}
if (!found) { //address not known yet
msglist.add(new OSCMsg(millis(),cmsg.get(0),cmsg.addrPattern()));
}
//print("### received an osc message.");
//print(" addrpattern: "+theOscMessage.addrPattern());
//println(" typetag: "+theOscMessage.typetag());
}