Commit 353c20e4 authored by Marios Fanourakis's avatar Marios Fanourakis

added separate int and float outlets

parent 51750663
......@@ -2,8 +2,8 @@
* Creates an LSL outlet. If numChannels>0, the channel_format will be lsl::cf_float32. numChannels==0 then the channel format will be lsl::cf_string.
*
* @param outletName Name of the outlet (ex. "CSGO_Player0_steamID")
* @param outletType Type of outlet e.g. "positioning data".
* @param channelLabels Channel names (ex. "x_position;y_position"). Set to "markers" to create a single channel marker outlet.
* @param outletType Type of outlet in this format "int/float/string <description>" e.g." float positioning data".
* @param channelLabels Channel names (ex. "x_position;y_position"). Ignored if string type outlet (marker).
* @param rate Rate of data in Hz.
* @param streamID Reference to put stream ID once outlet is created.
* @return Number of channels of outlet based on channelLabels.
......@@ -18,7 +18,17 @@ native int createLSLoutlet(char[] outletName, char[] outletType, char[] channelL
* @param timestamp Float of local clock value. Default=-1.
* @return Success code.
*/
native int push_sample(char[] streamID, float[] sample, float timestamp=-1.0);
native int push_intSample(char[] streamID, int[] sample, float timestamp=-1.0);
/**
* Pushes a sample to an outlet. Do not use for markers!
*
* @param outlet Outlet stream ID to push sample to.
* @param sample data to send.
* @param timestamp Float of local clock value. Default=-1.
* @return Success code.
*/
native int push_floatSample(char[] streamID, float[] sample, float timestamp=-1.0);
/**
* Pushes a marker to an outlet.
......@@ -28,4 +38,4 @@ native int push_sample(char[] streamID, float[] sample, float timestamp=-1.0);
* @param timestamp Float of local clock value. Default=-1.
* @return Success code.
*/
native int push_marker(char[] streamID, char[] marker, float timestamp=-1.0);
\ No newline at end of file
native int push_stringSample(char[] streamID, char[] marker, float timestamp=-1.0);
\ No newline at end of file
......@@ -48,8 +48,9 @@ SMEXT_LINK(&g_LSLext);
const sp_nativeinfo_t MyNatives[] =
{
{"createLSLoutlet", createLSLoutlet},
{"push_sample", push_sample},
{"push_marker", push_marker},
{"push_intSample", push_intSample},
{"push_floatSample", push_floatSample},
{"push_stringSample", push_stringSample},
{NULL, NULL},
};
......@@ -77,13 +78,27 @@ cell_t createLSLoutlet(IPluginContext *pContext, const cell_t *params)
strcat(streamID, outletName);
strcat(streamID, outletType);
int numChannels = -1;
int numChannels = 0;
bool isMarkerOutlet = false;
bool isIntOutlet = false;
bool isFloatOutlet = false;
if(strcmp(channelLabels,"marker")==0){
isMarkerOutlet=true;
numChannels=1;
}else if(strlen(channelLabels)>0){
if(strncmp("string",outletType,6)==0 || strncmp("String",outletType,6)==0){
isMarkerOutlet = true;
numChannels = 1;
}else if(strncmp("int",outletType,3)==0 || strncmp("Int",outletType,3)==0){
isIntOutlet = true;
}else if(strncmp("float",outletType,5)==0 || strncmp("Float",outletType,5)==0){
isFloatOutlet = true;
}else{
return 0;
}
// Get number of channels from the labels
if((isIntOutlet || isFloatOutlet) && strlen(channelLabels)>0){
numChannels=1;
char * pch;
pch=strchr(channelLabels,';');
......@@ -92,11 +107,28 @@ cell_t createLSLoutlet(IPluginContext *pContext, const cell_t *params)
numChannels++;
pch=strchr(pch+1,';');
}
}else{
return 0;
}else if(isIntOutlet || isFloatOutlet){
return -1;
}
if(!isMarkerOutlet)// Regular data rate outlet
if(isIntOutlet)// Regular data rate outlet
{
lsl::stream_info info(outletName,outletType,numChannels,rate,lsl::cf_int32,streamID);
// add some description fields
info.desc().append_child_value("Game", "CS:GO");
lsl::xml_element chns = info.desc().append_child("channels");
char * label = std::strtok(channelLabels,";");
while(label!=NULL)
{
chns.append_child("channel")
.append_child_value("label",label);
label = std::strtok(NULL,";");
}
outlets.emplace_back(info);
}else if(isFloatOutlet)// Regular data rate outlet
{
lsl::stream_info info(outletName,outletType,numChannels,rate,lsl::cf_float32,streamID);
// add some description fields
......@@ -113,17 +145,59 @@ cell_t createLSLoutlet(IPluginContext *pContext, const cell_t *params)
}
outlets.emplace_back(info);
}else //marker outlet, create single channel outlet of string format
}else if(isMarkerOutlet) //marker outlet, create single channel outlet of string format
{
lsl::stream_info info(outletName,outletType,1,lsl::IRREGULAR_RATE,lsl::cf_string,streamID);
outlets.emplace_back(lsl::stream_info(outletName,outletType,1,lsl::IRREGULAR_RATE,lsl::cf_string,streamID));
}else{
return -2;
}
return numChannels;
}
cell_t push_sample(IPluginContext *pContext, const cell_t *params)
cell_t push_intSample(IPluginContext *pContext, const cell_t *params)
{
char *streamID;
pContext->LocalToString(params[1], &streamID);
cell_t *c_sample;
pContext->LocalToPhysAddr(params[2], &c_sample);
float timestamp = sp_ctof(params[3]);
for(auto& outlet: outlets){
if(std::strcmp(outlet.info().source_id().c_str(),streamID)==0)
{
// convert cell_t to a regular float array to push it in the outlet.
int numChannels = outlet.info().channel_count();
int sample[numChannels];
for(int i=0; i<numChannels; i++)
{
sample[i] = c_sample[i];
}
if(timestamp<0)
{
outlet.push_sample(sample);
}else
{
outlet.push_sample(sample, timestamp);
}
return 0;
}
}
return 1;
}
cell_t push_floatSample(IPluginContext *pContext, const cell_t *params)
{
char *streamID;
pContext->LocalToString(params[1], &streamID);
......@@ -165,7 +239,7 @@ cell_t push_sample(IPluginContext *pContext, const cell_t *params)
}
cell_t push_marker(IPluginContext *pContext, const cell_t *params)
cell_t push_stringSample(IPluginContext *pContext, const cell_t *params)
{
char *streamID, *marker;
pContext->LocalToString(params[1], &streamID);
......
......@@ -44,8 +44,9 @@
cell_t createLSLoutlet(IPluginContext *pContext, const cell_t *params);
cell_t push_sample(IPluginContext *pContext, const cell_t *params);
cell_t push_marker(IPluginContext *pContext, const cell_t *params);
cell_t push_intSample(IPluginContext *pContext, const cell_t *params);
cell_t push_floatSample(IPluginContext *pContext, const cell_t *params);
cell_t push_stringSample(IPluginContext *pContext, const cell_t *params);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment