Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node Connection Updates #164

Merged
merged 7 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions ActorContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ struct ActorContainer {

char* typeStr = zconfig_value(type);
if ( streq(typeStr, "OSC")) {
input_slots.push_back({ "OSC", ActorSlotOSC });
input_slots.push_back({ "OSC", ActorSlotOSC, false });
}
else if ( streq(typeStr, "NatNet")) {
input_slots.push_back({ "NatNet", ActorSlotNatNet });
input_slots.push_back({ "NatNet", ActorSlotNatNet, false });
}
else if ( streq(typeStr, "Any")) {
input_slots.push_back({ "Any", ActorSlotAny, true });
}
else {
zsys_error("Unsupported input type: %s", typeStr);
Expand All @@ -112,10 +115,13 @@ struct ActorContainer {

char* typeStr = zconfig_value(type);
if ( streq(typeStr, "OSC")) {
output_slots.push_back({ "OSC", ActorSlotOSC });
output_slots.push_back({ "OSC", ActorSlotOSC, false });
}
else if ( streq(typeStr, "NatNet")) {
output_slots.push_back({ "NatNet", ActorSlotNatNet });
output_slots.push_back({ "NatNet", ActorSlotNatNet, false });
}
else if ( streq(typeStr, "Any")) {
output_slots.push_back({ "Any", ActorSlotAny, true });
}
else {
zsys_error("Unsupported output type: %s", typeStr);
Expand Down
40 changes: 24 additions & 16 deletions Actors/NatNetActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ zmsg_t * NatNet::handleInit( sphactor_event_t * ev )
}
ziflist_destroy(&ifList);

//build report
SetReport(ev->actor);

if ( ifNames.size() == 0 ) {
zsys_info("Error: no available interfaces");
return nullptr;
}

// initially we use the first interface
activeInterface = ifNames[0];

Expand All @@ -72,9 +80,6 @@ zmsg_t * NatNet::handleInit( sphactor_event_t * ev )
rc = sphactor_actor_poller_add((sphactor_actor_t*)ev->actor, CommandSocket );
assert(rc == 0);

//build report
SetReport(ev->actor);

return NULL;
}

Expand Down Expand Up @@ -125,19 +130,22 @@ zmsg_t * NatNet::handleAPI( sphactor_event_t * ev )
zsys_info("SET HOST: %s", host_addr);
zstr_free(&host_addr);

// Say hello to our new host
// send initial ping command
sPacket PacketOut;
PacketOut.iMessage = NAT_PING;
PacketOut.nDataBytes = 0;
int nTries = 3;
while (nTries--) {
//int iRet = sendto(CommandSocket, (char *)&PacketOut, 4 + PacketOut.nDataBytes, 0, (sockaddr *)&HostAddr, sizeof(HostAddr));
std::string url = host + ":" + PORT_COMMAND_STR;
zstr_sendm(CommandSocket, url.c_str());
int rc = zsock_send(CommandSocket, "b", (char *) &PacketOut, 4 + PacketOut.nDataBytes);
if (rc != -1) {
zsys_info("Sent ping to %s", url.c_str());

if ( CommandSocket != nullptr ) {
// Say hello to our new host
// send initial ping command
sPacket PacketOut;
PacketOut.iMessage = NAT_PING;
PacketOut.nDataBytes = 0;
int nTries = 3;
while (nTries--) {
//int iRet = sendto(CommandSocket, (char *)&PacketOut, 4 + PacketOut.nDataBytes, 0, (sockaddr *)&HostAddr, sizeof(HostAddr));
std::string url = host + ":" + PORT_COMMAND_STR;
zstr_sendm(CommandSocket, url.c_str());
int rc = zsock_send(CommandSocket, "b", (char *) &PacketOut, 4 + PacketOut.nDataBytes);
if (rc != -1) {
zsys_info("Sent ping to %s", url.c_str());
}
}
}
}
Expand Down
67 changes: 37 additions & 30 deletions Actors/OSCRecordActor.cpp → Actors/RecordActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Created by Aaron Oostdijk on 28/10/2021.
//

#include "OSCRecordActor.h"
#include "RecordActor.h"

const char * OSCRecord::capabilities =
const char * Record::capabilities =
"capabilities\n"
" data\n"
" name = \"fileName\"\n"
Expand All @@ -21,12 +21,16 @@ const char * OSCRecord::capabilities =
" name = \"Stop\"\n"
" type = \"trigger\"\n"
" api_call = \"STOP_RECORD\"\n"
" value = \"\"\n"
" data\n"
" name = \"Play\"\n"
" type = \"trigger\"\n"
" api_call = \"PLAY_RECORDING\"\n"
" value = \"\"\n"
" data\n"
" name = \"overwrite\"\n"
" type = \"bool\"\n"
" api_call = \"SET OVERWRITE\"\n"
" value = \"False\"\n"
" api_value = \"s\"\n"
" data\n"
" name = \"loop\"\n"
" type = \"bool\"\n"
Expand All @@ -41,13 +45,13 @@ const char * OSCRecord::capabilities =
" api_value = \"s\"\n"
"inputs\n"
" input\n"
" type = \"OSC\"\n"
" type = \"Any\"\n"
"outputs\n"
" output\n"
" type = \"OSC\"\n";
" type = \"Any\"\n";


void OSCRecord::handleEOF(sphactor_actor_t* actor) {
void Record::handleEOF(sphactor_actor_t* actor) {
if ( loop ) {
// reset playback values
read_offset = 0;
Expand All @@ -71,7 +75,7 @@ void OSCRecord::handleEOF(sphactor_actor_t* actor) {
}
}

void OSCRecord::setReport(sphactor_actor_t* actor) {
void Record::setReport(sphactor_actor_t* actor) {
// Build report
std::string time_display;
time_display += zsys_sprintf("%i", read_offset);
Expand All @@ -83,7 +87,7 @@ void OSCRecord::setReport(sphactor_actor_t* actor) {
}

zmsg_t *
OSCRecord::handleTimer( sphactor_event_t *ev ) {
Record::handleTimer(sphactor_event_t *ev ) {
zmsg_destroy(&ev->msg);

// Read data from current message
Expand Down Expand Up @@ -146,32 +150,32 @@ OSCRecord::handleTimer( sphactor_event_t *ev ) {
}

zmsg_t *
OSCRecord::handleAPI( sphactor_event_t *ev )
Record::handleAPI(sphactor_event_t *ev )
{
//pop msg for command
char * cmd = zmsg_popstr(ev->msg);
if (cmd) {
if ( streq(cmd, "START_RECORD") ) {
zsys_info("TODO: start recording if valid file & not recording");

// if ! recording

// if file does not exist
// TODO: OR overwrite (for now, always overwrite)
if ( file == nullptr ) {
if ( !zfile_exists(fileName) ) {
if ( !zfile_exists(fileName) || overwrite ) {
file = zfile_new(NULL, fileName);
zfile_output(file);
offset = 0;
zsys_info("file created");

// Build report
zosc_t * msg = zosc_create("/report", "ss", "Recording", "...");
sphactor_actor_set_custom_report_data((sphactor_actor_t*)ev->actor, msg);
int rc = zfile_output(file);
if (rc == 0) {
write_offset = 0;
zsys_info("file created");

// Build report
zosc_t* msg = zosc_create("/report", "ss", "Recording", "...");
sphactor_actor_set_custom_report_data((sphactor_actor_t*)ev->actor, msg);
}
else{
file = nullptr;
zsys_info("Invalid output file");
}
}
else {
// TODO: how do we deal with an existing file?
zsys_info("file exists");
zsys_info("File exists. Check overwrite to replace before hitting record.");
}
}
else {
Expand Down Expand Up @@ -231,14 +235,17 @@ OSCRecord::handleAPI( sphactor_event_t *ev )
else if ( streq(cmd, "SET BLOCKING") ) {
blockDuringPlay = streq( zmsg_popstr(ev->msg), "True" );
}
else if ( streq(cmd, "SET OVERWRITE") ) {
overwrite = streq( zmsg_popstr(ev->msg), "True" );
}
}

zmsg_destroy(&ev->msg);
return nullptr;
}

zmsg_t *
OSCRecord::handleSocket( sphactor_event_t *ev )
Record::handleSocket(sphactor_event_t *ev )
{
if ( file && !playing ) {
zframe_t * frame = zmsg_pop(ev->msg);
Expand All @@ -257,10 +264,10 @@ OSCRecord::handleSocket( sphactor_event_t *ev )
tc->bytes = zchunk_size(chunk);
zchunk_t *headerChunk = zchunk_new(tc, sizeof(time_bytes));

int rc = zfile_write(file, headerChunk, offset);
offset += zchunk_size(headerChunk);
rc = zfile_write(file, chunk, offset);
offset += zchunk_size(chunk);
int rc = zfile_write(file, headerChunk, write_offset);
write_offset += zchunk_size(headerChunk);
rc = zfile_write(file, chunk, write_offset);
write_offset += zchunk_size(chunk);

if ( rc != 0 ) {
zsys_info("error writing");
Expand Down
23 changes: 13 additions & 10 deletions Actors/OSCRecordActor.h → Actors/RecordActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by Aaron Oostdijk on 28/10/2021.
//

#ifndef GAZEBOSC_OSCRECORDACTOR_H
#define GAZEBOSC_OSCRECORDACTOR_H
#ifndef GAZEBOSC_RECORDACTOR_H
#define GAZEBOSC_RECORDACTOR_H

#include "libsphactor.hpp"
#include <string>
Expand All @@ -14,25 +14,28 @@ struct time_bytes {
unsigned int bytes;
};

class OSCRecord : public Sphactor {
class Record : public Sphactor {
private:

public:
static const char *capabilities;

const char* fileName = nullptr;
// State variables
zfile_t * file = nullptr;
int offset = 0;
bool playing = false;
bool loop = false;
bool blockDuringPlay = false;

unsigned int startTimeCode = 0;
unsigned int startRecordTimeCode = 0;
unsigned int read_offset = 0;
unsigned int write_offset = 0;
time_bytes * current_tc = nullptr;

OSCRecord() : Sphactor() {
// Controls
const char* fileName = nullptr;
bool loop = false;
bool blockDuringPlay = false;
bool overwrite = false;

Record() : Sphactor() {

}

Expand All @@ -46,4 +49,4 @@ class OSCRecord : public Sphactor {
// Or perhaps a fixed buffer, that writes when something is bigger than it can store?
};

#endif //GAZEBOSC_OSCRECORDACTOR_H
#endif //GAZEBOSC_RECORDACTOR_H
Loading