static bool ctl_init(void) { bool ret; malloc_mutex_lock(&ctl_mtx); if (ctl_initialized == false) { #ifdef JEMALLOC_STATS unsigned i; #endif /* * Allocate space for one extra arena stats element, which * contains summed stats across all arenas. */ ctl_stats.arenas = (ctl_arena_stats_t *)base_alloc( (narenas + 1) * sizeof(ctl_arena_stats_t)); if (ctl_stats.arenas == NULL) { ret = true; goto RETURN; } memset(ctl_stats.arenas, 0, (narenas + 1) * sizeof(ctl_arena_stats_t)); /* * Initialize all stats structures, regardless of whether they * ever get used. Lazy initialization would allow errors to * cause inconsistent state to be viewable by the application. */ #ifdef JEMALLOC_STATS for (i = 0; i <= narenas; i++) { if (ctl_arena_init(&ctl_stats.arenas[i])) { ret = true; goto RETURN; } } #endif ctl_stats.arenas[narenas].initialized = true; ctl_epoch = 0; ctl_refresh(); ctl_initialized = true; } ret = false; RETURN: malloc_mutex_unlock(&ctl_mtx); return (ret); }
static bool ctl_init(void) { bool ret; malloc_mutex_lock(&ctl_mtx); if (ctl_initialized == false) { /* * Allocate space for one extra arena stats element, which * contains summed stats across all arenas. */ assert(narenas_auto == narenas_total_get()); ctl_stats.narenas = narenas_auto; ctl_stats.arenas = (ctl_arena_stats_t *)base_alloc( (ctl_stats.narenas + 1) * sizeof(ctl_arena_stats_t)); if (ctl_stats.arenas == NULL) { ret = true; goto label_return; } memset(ctl_stats.arenas, 0, (ctl_stats.narenas + 1) * sizeof(ctl_arena_stats_t)); /* * Initialize all stats structures, regardless of whether they * ever get used. Lazy initialization would allow errors to * cause inconsistent state to be viewable by the application. */ if (config_stats) { unsigned i; for (i = 0; i <= ctl_stats.narenas; i++) { if (ctl_arena_init(&ctl_stats.arenas[i])) { ret = true; goto label_return; } } } ctl_stats.arenas[ctl_stats.narenas].initialized = true; ctl_epoch = 0; ctl_refresh(); ctl_initialized = true; } ret = false; label_return: malloc_mutex_unlock(&ctl_mtx); return (ret); }
static int epoch_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { int ret; uint64_t newval; malloc_mutex_lock(&ctl_mtx); WRITE(newval, uint64_t); if (newp != NULL) ctl_refresh(); READ(ctl_epoch, uint64_t); ret = 0; label_return: malloc_mutex_unlock(&ctl_mtx); return (ret); }
static void ctl_event(CtlEvent *e) { switch(e->type) { case CTLE_NOW_LOADING: ctl_file_name((char *)e->v1); break; case CTLE_PLAY_START: ctl_total_time((int)e->v1); break; case CTLE_CURRENT_TIME: ctl_current_time((int)e->v1, (int)e->v2); break; case CTLE_MASTER_VOLUME: ctl_master_volume((int)e->v1); break; case CTLE_LYRIC: ctl_lyric((int)e->v1); break; case CTLE_REFRESH: ctl_refresh(); break; } }
static void ctl_event(CtlEvent *e) { switch(e->type) { case CTLE_NOW_LOADING: ctl_file_name((char *)e->v1); break; case CTLE_LOADING_DONE: break; case CTLE_PLAY_START: ctl_total_time((int)e->v1); break; case CTLE_PLAY_END: break; case CTLE_TEMPO: break; case CTLE_METRONOME: /* update_indicator(); */ break; case CTLE_CURRENT_TIME: ctl_current_time((int)e->v1, (int)e->v2); break; case CTLE_NOTE: ctl_note((int)e->v1, (int)e->v2, (int)e->v3, (int)e->v4); break; case CTLE_MASTER_VOLUME: ctl_master_volume((int)e->v1); break; case CTLE_PROGRAM: ctl_program((int)e->v1, (int)e->v2); break; case CTLE_VOLUME: ctl_volume((int)e->v1, (int)e->v2); break; case CTLE_EXPRESSION: ctl_expression((int)e->v1, (int)e->v2); break; case CTLE_PANNING: ctl_panning((int)e->v1, (int)e->v2); break; case CTLE_SUSTAIN: ctl_sustain((int)e->v1, (int)e->v2); break; case CTLE_PITCH_BEND: ctl_pitch_bend((int)e->v1, (int)e->v2); break; case CTLE_MOD_WHEEL: ctl_pitch_bend((int)e->v1, e->v2 ? -1 : 0x2000); break; case CTLE_CHORUS_EFFECT: break; case CTLE_REVERB_EFFECT: break; case CTLE_LYRIC: ctl_lyric((int)e->v1); break; case CTLE_REFRESH: ctl_refresh(); break; case CTLE_RESET: ctl_reset(); break; } }
static void display_lyric(char *lyric, int sep) { char *p; int len, idlen, sepoffset; static int crflag = 0; if(lyric == NULL) { indicator_last_update = get_current_calender_time(); crflag = 0; return; } if(indicator_mode != INDICATOR_LYRIC || crflag) { memset(comment_indicator_buffer, 0, indicator_width); SLsmg_gotorc(lyric_row,0); SLsmg_erase_eol(); ctl_refresh(); indicator_mode = INDICATOR_LYRIC; crflag = 0; } if(*lyric == '\0') { indicator_last_update = get_current_calender_time(); return; } else if(*lyric == '\n') { if(!ctl.trace_playing) { crflag = 1; lyric_row++; SLsmg_gotorc(0,lyric_row); return; } else lyric = " / "; } if(strchr(lyric, '\r') != NULL) { crflag = 1; if(!ctl.trace_playing) { int i; for(i = title_row+1; i <= lyric_row; i++) { SLsmg_gotorc(i,0); SLsmg_erase_eol(); } lyric_row = title_row+1; } if(lyric[0] == '\r' && lyric[1] == '\0') { indicator_last_update = get_current_calender_time(); return; } } idlen = strlen(comment_indicator_buffer); len = strlen(lyric); if(sep) { while(idlen > 0 && comment_indicator_buffer[idlen - 1] == ' ') comment_indicator_buffer[--idlen] = '\0'; while(len > 0 && lyric[len - 1] == ' ') len--; } if(len == 0) { /* update time stamp */ indicator_last_update = get_current_calender_time(); reuse_mblock(&tmpbuffer); return; } sepoffset = (sep != 0); if(len >= indicator_width - 2) { memcpy(comment_indicator_buffer, lyric, indicator_width - 1); comment_indicator_buffer[indicator_width - 1] = '\0'; } else if(idlen == 0) { memcpy(comment_indicator_buffer, lyric, len); comment_indicator_buffer[len] = '\0'; } else if(len + idlen + 2 < indicator_width) { if(sep) comment_indicator_buffer[idlen] = sep; memcpy(comment_indicator_buffer + idlen + sepoffset, lyric, len); comment_indicator_buffer[idlen + sepoffset + len] = '\0'; } else { int spaces; p = comment_indicator_buffer; spaces = indicator_width - idlen - 2; while(spaces < len) { char *q; /* skip one word */ if((q = strchr(p, ' ')) == NULL) { p = NULL; break; } do q++; while(*q == ' '); spaces += (q - p); p = q; } if(p == NULL) { SLsmg_gotorc(lyric_row,0); SLsmg_erase_eol(); memcpy(comment_indicator_buffer, lyric, len); comment_indicator_buffer[len] = '\0'; } else { int d, l, r, i, j; d = (p - comment_indicator_buffer); l = strlen(p); r = len - (indicator_width - 2 - l - d); j = d - r; for(i = 0; i < j; i++) comment_indicator_buffer[i] = ' '; for(i = 0; i < l; i++) comment_indicator_buffer[j + i] = comment_indicator_buffer[d + i]; if(sep) comment_indicator_buffer[j + i] = sep; memcpy(comment_indicator_buffer + j + i + sepoffset, lyric, len); comment_indicator_buffer[j + i + sepoffset + len] = '\0'; } } SLsmg_printfrc(lyric_row,0,"%s",comment_indicator_buffer); ctl_refresh(); reuse_mblock(&tmpbuffer); indicator_last_update = get_current_calender_time(); }
static void update_indicator(void) { double t; int i; char c; t = get_current_calender_time(); if(indicator_mode != INDICATOR_DEFAULT) { int save_chan; if(indicator_last_update + SCRMODE_OUT_THRESHOLD > t) return; save_chan = next_indicator_chan; reset_indicator(); next_indicator_chan = save_chan; } else { if(indicator_last_update + INDICATOR_UPDATE_TIME > t) return; } indicator_last_update = t; if(indicator_msgptr != NULL && *indicator_msgptr == '\0') indicator_msgptr = NULL; if(indicator_msgptr == NULL) { if(next_indicator_chan >= 0 && instr_comment[next_indicator_chan].comm != NULL && *instr_comment[next_indicator_chan].comm) { current_indicator_chan = next_indicator_chan; } else { int prog; prog = instr_comment[current_indicator_chan].prog; for(i = 0; i < MAX_CHANNELS; i++) { current_indicator_chan++; if(current_indicator_chan == MAX_CHANNELS) current_indicator_chan = 0; if(instr_comment[current_indicator_chan].comm != NULL && *instr_comment[current_indicator_chan].comm && instr_comment[current_indicator_chan].prog != prog && (instr_comment[current_indicator_chan].last_note_on + CHECK_NOTE_SLEEP_TIME > t || instr_comment[current_indicator_chan].disp_cnt == 0)) break; } if(i == MAX_CHANNELS) return; } next_indicator_chan = -1; if(instr_comment[current_indicator_chan].comm == NULL || *instr_comment[current_indicator_chan].comm == '\0') return; snprintf(current_indicator_message, indicator_width, "%03d:%s ", instr_comment[current_indicator_chan].prog, instr_comment[current_indicator_chan].comm); instr_comment[current_indicator_chan].disp_cnt++; indicator_msgptr = current_indicator_message; } c = *indicator_msgptr++; for(i = 0; i < indicator_width - 2; i++) comment_indicator_buffer[i] = comment_indicator_buffer[i + 1]; comment_indicator_buffer[indicator_width - 2] = c; SLsmg_printfrc(2,0,comment_indicator_buffer); ctl_refresh(); }