Skip to content

Commit

Permalink
send also seconds since start of the day
Browse files Browse the repository at this point in the history
  • Loading branch information
gisogrimm committed May 2, 2024
1 parent d8496c9 commit c94f20b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions plugins/src/tascarmod_systime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ class tascar_systime_t : public TASCAR::module_base_t {

private:
std::string path = "/systime";
std::string secpath = "/seconds";
lo_message msg;
lo_message msgsec;
double* p_year;
double* p_month;
double* p_day;
double* p_hour;
double* p_min;
double* p_sec;
double* p_daysec;
#ifndef _WIN32
struct timeval tv;
struct timezone tz;
Expand All @@ -50,19 +53,27 @@ tascar_systime_t::tascar_systime_t(const TASCAR::module_cfg_t& cfg)
{
GET_ATTRIBUTE(path, "", "OSC path where time stamps are dispatched");
msg = lo_message_new();
if(!msg)
throw TASCAR::ErrMsg("Unable to allocate OSC message");
msgsec = lo_message_new();
if(!msgsec)
throw TASCAR::ErrMsg("Unable to allocate OSC message");
lo_message_add_double(msg, 0.0);
lo_message_add_double(msg, 0.0);
lo_message_add_double(msg, 0.0);
lo_message_add_double(msg, 0.0);
lo_message_add_double(msg, 0.0);
lo_message_add_double(msg, 0.0);
lo_message_add_double(msgsec, 0.0);
auto argv = lo_message_get_argv(msg);
p_year = &(argv[0]->d);
p_month = &(argv[1]->d);
p_day = &(argv[2]->d);
p_hour = &(argv[3]->d);
p_min = &(argv[4]->d);
p_sec = &(argv[5]->d);
argv = lo_message_get_argv(msgsec);
p_daysec = &(argv[0]->d);
#ifndef _WIN32
memset(&tv, 0, sizeof(timeval));
memset(&tz, 0, sizeof(timezone));
Expand All @@ -79,8 +90,8 @@ void tascar_systime_t::update(uint32_t, bool)
#ifndef _WIN32
gettimeofday(&tv, &tz);
struct tm* caltime = localtime(&(tv.tv_sec));
*p_year = caltime->tm_year;
*p_month = caltime->tm_mon;
*p_year = caltime->tm_year + 1900;
*p_month = caltime->tm_mon + 1;
*p_day = caltime->tm_mday;
*p_hour = caltime->tm_hour;
*p_min = caltime->tm_min;
Expand All @@ -97,7 +108,11 @@ void tascar_systime_t::update(uint32_t, bool)
*p_sec = caltime.wSecond;
*p_sec += 0.001 * caltime.wMilliseconds;
#endif
session->dispatch_data_message(path.c_str(), msg);
*p_daysec = *p_sec + 60 * *p_min + 3600 * *p_hour;
if(!path.empty())
session->dispatch_data_message(path.c_str(), msg);
if(!secpath.empty())
session->dispatch_data_message(secpath.c_str(), msgsec);
}

REGISTER_MODULE(tascar_systime_t);
Expand Down

0 comments on commit c94f20b

Please sign in to comment.