Is this project you can find a sketch.js file which is a p5.js file that is rendered in a browser tab. Click the GUI button (next to the Scope button) in the IDE to see the rendering of this file.
This example sends a buffer of data from the Bela render to the browser via a web socket: gui.sendBuffer(0, dateTimeComponents);
The p5.js file displays the received data (time and date).
#include <libraries/Gui/Gui.h>
#include <string>
#include <sstream>
#include <math.h>
#include <time.h>
std::vector<int> dateTimeComponents;
float gTimePeriod = 0.01;
const std::vector<std::string> currentDateTime() {
time_t now = time(0);
struct tm tstruct;
std::vector<std::string> dateTime;
char date[50];
char time[50];
tstruct = *localtime(&now);
strftime(date, sizeof(date), "%Y-%m-%d", &tstruct);
strftime(time, sizeof(time), "%T", &tstruct);
dateTime.emplace_back(date);
dateTime.emplace_back(time);
return dateTime;
}
std::vector<std::string>
split(
const std::string& s,
char delimiter)
{
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter))
{
tokens.push_back(token);
}
return tokens;
}
void calcDate(unsigned int samplesElapsed, unsigned int sampleRate, std::vector<int> &date)
{
unsigned int miliseconds = floor(1000 * samplesElapsed / sampleRate) + date[6];
date[6] = miliseconds % 1000;
unsigned int seconds = floor(miliseconds / 1000) + date[5];
date[5] = seconds%60;
unsigned int minutes = floor(seconds/60) + date[4];
date[4] = minutes%60;
unsigned int hours = floor(minutes/60) + date[3];
date[3] = hours%24;
unsigned int days = floor(hours/60) + date[2];
date[2] = days%30;
unsigned int months = floor(days/30) + date[1];
date[1] = months%12;
date[0] = floor(months/12) + date[0];
}
{
std::vector<std::string> dateComponents =
split(currentDateTime()[0],
'-');
for(unsigned int i=0; i<dateComponents.size(); i++)
dateTimeComponents.push_back(atoi(dateComponents[i].c_str()));
std::vector<std::string> timeComponents =
split(currentDateTime()[1],
':');
for(unsigned int i=0; i<timeComponents.size(); i++)
dateTimeComponents.push_back(atoi(timeComponents[i].c_str()));
dateTimeComponents.push_back(0);
return true;
}
{
static unsigned int count = 0;
for(
unsigned int n = 0; n < context->
audioFrames; n++) {
{
count = 0;
}
count++;
}
}
{
}