void init_periodic(void){ struct periodic_event_st *ev = &gevents[0]; struct minutely_event_st *mev = &gmevents[0]; time_t now; int minute_now; /* * If the default periods above are changed by the configuration file * we use that instead. */ gevents[EVENT_REPT_PCTL_QUOTA].period = g.queue_quota_logperiod_secs; gevents[EVENT_REPT_QDB_QUOTA].period = g.queue_quota_logperiod_secs; gevents[EVENT_LOG_QSTATE].period = g.qstate_logperiod_secs; gevents[EVENT_UPDATE_NBSP_STATS].period = g.nbspstats_logperiod_secs; gevents[EVENT_SERVER_STATE].period = g.serverstate_logperiod_secs; gevents[EVENT_FILTERSERVER_STATE].period = g.serverstate_logperiod_secs; gevents[EVENT_LOADAVE_COND].period = g.loadave_checkperiod_secs; gevents[EVENT_RTXDB_TRUNCATE].period = g.rtxdb_truncate_minutes * 60; gevents[EVENT_MSPOOLBDB_DBSTATS].period = g.mspoolbdb_dbstats_logperiod_secs; now = time(NULL); minute_now = current_minute(now); while(ev->proc != NULL){ ev->next = now + ev->period; ++ev; } while(mev->proc != NULL){ mev->last_minute = minute_now; ++mev; } }
static void prv_handle_tick(struct tm *tick_time, TimeUnits units_changed) { uint16_t now = current_minute(); if(now > s_northbound.time || now > s_southbound.time) { prv_update_times(); } else { prv_update_ui(); } }
int main(int argc, char** argv) { if (argc != 3) { printf("usage: %s device key\n", argv[0]); printf(" device: /dev/midi\n"); printf(" key: 36\n"); printf(" -1 for key means display mode\n"); exit(1); } int key = atoi(argv[2]); int display_mode = key == -1; if (!display_mode && (key < 0 || key > 127)) { printf("key must be between 0 and 127. The dtx500 kick drum is 36\n"); exit(1); } int fd = open(argv[1], O_RDONLY); if (fd == -1) { perror("tempo: open"); exit(1); } int state = INITIAL; double ts[SAMPLES]; int pos = 0; unsigned char c; while (1) { read(fd, &c, 1); if (state == INITIAL) { if (c >= 0x90 && c < 0xA0) { state = SAW_NOTE_ON; } } else if (state == SAW_NOTE_ON) { if (display_mode) { printf(" %d\n", c); } else if (c == key) { ts[pos % SAMPLES] = current_minute(); if (pos > SAMPLES) { int tempo = (SAMPLES-1)/( ts[pos % SAMPLES] - ts[(pos+1) % SAMPLES]) + 0.5; display_tempo(tempo); } pos++; } state = INITIAL; } } }
void periodic(void){ /* * This function is called from the main loop thread. * * Call first the functions that are scheduled to run at some * specified intervals. Then those that should be run each time * periodic() is called. */ struct periodic_event_st *ev = &gevents[0]; struct minutely_event_st *mev = &gmevents[0]; time_t now; int minute_now; now = time(NULL); minute_now = current_minute(now); while(ev->proc != NULL){ if(now >= ev->next){ ev->next += ev->period; ev->proc(); } ++ev; } while(mev->proc != NULL){ if(minute_now != mev->last_minute){ mev->last_minute = minute_now; mev->proc(); } ++mev; } /* * This causes to check if the state fifo is opened for reading (on the * other end), and then open it for writing (on this end) to report the * state of the queue. */ set_reopen_qstatefifo_flag(); /* * This is the mechanism used to reload the filters. Just let * the filter and server threads know they should reload the filters. */ if(get_hup_flag() != 0){ set_reload_filters_flag(); set_reload_server_filters_flag(); } }