ideas about logging all OSC data
in
Contributed Library Questions
•
2 years ago
I was trying to design something that can continuously record all OSC data coming in either to memory or disk, with some kind of timing index... and then be able to send the events back out over OSC with some kind of resemblance of the original timing...
I implemented something that was working using Daniel Howe's RiTa ( the HistoryQueue class hidden in rita.support.* and the ObjectPair class... he-he!) and OSCulator to send all sorts of events....
It works , but because its being clocked by the frameCount and trying to store things in a growing array, the streams are downsampled to frameRate. Also, the growing HistoryQueue array could end up consuming all the memory and is not the safest way.
I am sure there is a much simpler route. Any ideas or suggestions?
I implemented something that was working using Daniel Howe's RiTa ( the HistoryQueue class hidden in rita.support.* and the ObjectPair class... he-he!) and OSCulator to send all sorts of events....
It works , but because its being clocked by the frameCount and trying to store things in a growing array, the streams are downsampled to frameRate. Also, the growing HistoryQueue array could end up consuming all the memory and is not the safest way.
I am sure there is a much simpler route. Any ideas or suggestions?
- // OSC activity recorder and replayer idea by Cristian Vogel
- // needs oscP5 and RiTa
import rita.support.*;
import oscP5.*;
import netP5.*;
OscP5 osculator ;
OscMessage outMessage;
NetAddress sendLocation = new NetAddress("127.0.0.1", 12001); // local to OSCulator or somewhere
PrintWriter output;
HistoryQueue history = new HistoryQueue(); // RiTa HistoryQueue class
ObjectPair keyAndEvent; // RiTa ObjectPair class
ObjectPair lookedUp;
int i=0; // reanimate iterator
int reFrameCount=0;
int readRange = 1000; // an OSC event count for repeating over
int recordedValue=0;
int tapeLength=0;
boolean recordingEvents=true;
void setup() {
// Create a new file in the sketch directory
output = createWriter("positions.txt");
history.setGrowable(true);
/* start oscP5, listening for incoming messages at port 8000 */
osculator = new OscP5(this, 9000);
frameRate(100);
}
void draw() {
fill(127, 10);
rect(0, 0, width, height);
if (history.size()>readRange) {
recordingEvents=false;
tapeLength=lookupKey(readRange); println(tapeLength);
recordedValue = lookupKey(i);
while (recordedValue==reFrameCount) {
ping(recordedValue);
// println((OscMessage) lookedUp.second());
send((OscMessage) lookedUp.second());
i++;
if (i>readRange) i=0;
recordedValue = lookupKey(i);
}
reFrameCount++;
reFrameCount = reFrameCount%(tapeLength+1);
println("look up value:" + recordedValue + " actual count:"+reFrameCount);
}
}
int lookupKey(int index) {
lookedUp=(ObjectPair) history.get(index);
int value= int ( lookedUp.first().toString());
return value;
}
void ping(int value) {
fill(value, 0, 0);
ellipse(50, 50, 50, 50);
// println("ping!");
}
void keyPressed() {
output.println(history.toString());
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
//exit(); // Stops the program
}
void mousePressed() {
println(history);
}
void oscEvent(OscMessage inOsc) {
println("address: "+inOsc.addrPattern()+" history size:"+history.size());
if (recordingEvents) {
keyAndEvent = new ObjectPair(frameCount, inOsc);
history.add(keyAndEvent);
}
// println(history);
}
void send (OscMessage oscMessage) {
String addressPattern = oscMessage.addrPattern();
OscMessage sendOut = new OscMessage(addressPattern);
sendOut.add(oscMessage.arguments());
osculator.send(sendOut, sendLocation);
}
1