📄 view_utils.c
字号:
{ static Event e; event_init(&e); event_set_x(&e,v->time_to_x(v,v->cursor_time)); event_set_y(&e,v->yval_to_y(v,v->cursor_yval)); event_set_window(&e,v->canvas); return(&e);} /*********************************************************************//* Should be called vodo op. Makes it possible to issue simple-minded (and under-specified) commands like: oname op, where oname is a display ensemble name, and op is any named operator in any of the Menuop lists. */void view_do_op(v,op) View *v; char *op;{ Canvas canvas = v->canvas; if(v && canvas && op && *op) { Event *event = (Event*)view_state_to_event(v); extern Menuop *find_operator(); Moplist *menu_get_op_lists(), *mol = menu_get_op_lists(); Menuop *mo; if(event) { char *ce = op + strlen(op)-1; while(*op && WhiteSpace(*op)) op++; if(*op) { while(WhiteSpace(*ce) && (ce > op)) ce--; *(++ce) = 0; while(mol) { if((mo = find_operator(mol->first_op,op)) && mo->proc) { mo->proc(canvas, event, mo->data); return; } mol = mol->next; } } } } fprintf(stderr,"Problems in view_do_op(%s) %x\n",op,v);}/*************************************************************************/arg_to_simple_string(str, n, se) char **str; int *n; Selector *se;{ char *get_next_item(); if(arg_to_string(str, n, se)) { char *cp = get_next_item(*str); int i; cp[(i = strlen(cp))-1] = 0; strcpy(*str, cp); return((i) ? i : -1); /* indicate success, but null value */ } return(0);} /*************************************************************************/char *value_as_string(sp, name) Selector *sp; char *name;{ static char *cp = NULL; static int nstr = 0; if(!cp) { cp = malloc(MES_BUF_SIZE); nstr = MES_BUF_SIZE; } while(sp) { if(!strcmp(sp->name,name)) { if(arg_to_simple_string(&cp, &nstr, sp)) return(cp); } sp = sp->next; } return(NULL);}/*************************************************************************/static char *view_get_overlays(v) View *v;{ if(v) { static char *rv = NULL; static int svl = 0; char *c; if(v->overlay_n >= 0) { /* does it have any overlays? */ int slen = ((NAMELEN+1) * (v->overlay_n + 1)) + 1; if(slen > svl) { if(rv) free(rv); svl = 0; if(!(rv = malloc(slen))) { fprintf(stderr,"Allocation problems in view_get_overlays\n"); return(""); } svl = slen; } *rv = 0; while(v = v->next) { if((v->extra_type == VIEW_OVERLAY) && (v->sig)) sprintf(rv+strlen(rv),"%s ",v->sig->name); } return(rv); } return(""); } return("");}/*************************************************************************/static char *view_get_is_iconized(v) View *v;{ if(!v) return(""); else if(!v->canvas || xv_get(xv_get(v->canvas,XV_OWNER),FRAME_CLOSED)) return("1"); else return("0");}/*************************************************************************/static char *view_get_cursor_samp(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", time_to_sample(v->sig,v->cursor_time)); return(rv); } else return("");}/*************************************************************************/static char *view_get_l_marker_samp(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", time_to_sample(v->sig,v->lmarker_time)); return(rv); } else return("");}/*************************************************************************/static char *view_get_l_marker_samp_from_start(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", time_to_sample (v->sig,v->lmarker_time) - s_range_offset); return(rv); } else return("");}/*************************************************************************/static char *view_get_r_marker_samp(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", time_to_sample(v->sig,v->rmarker_time)); return(rv); } else return("");}/*************************************************************************/static char *view_get_tmarker_chan(v) View *v;{ static char rv[10]; if(v) { sprintf(rv,"%d", v->tmarker_chan + c_range_offset); return(rv); } else return("");}/*************************************************************************/static char *view_get_bmarker_chan(v) View *v;{ static char rv[10]; if(v) { sprintf(rv,"%d", v->bmarker_chan + c_range_offset); return(rv); } else return("");}/*************************************************************************/static char *view_get_cursor_label(v) View *v;{ static char rv[100]; char *cp; List *l, *l2; if(v && v->sig && (l = v->sig->idents)) { int dim, curi, i; curi = v->cursor_channel; for(i = 0, l2 = l; i < curi; i++) if(l2->next) l2 = l2->next; strcpy(rv,l2->str); if((cp = strchr(rv,'['))) *cp = 0; return(rv); } else return("");}/*************************************************************************/static char *view_get_cursor_element(v) View *v;{ static char rv[100]; char *cp, *ce; List *l, *l2; if(v && v->sig && (l = v->sig->idents)) { int dim, curi, i; curi = v->cursor_channel; for(i = 0, l2 = l; i < curi; i++) if(l2->next) l2 = l2->next; strcpy(rv,l2->str); if((cp = strchr(rv,'['))) { if((ce = strchr(cp,']'))) *ce = 0; return (cp+1); } else return "0"; } else return("");}/*************************************************************************/static char *view_get_cursor_chan(v) View *v;{ static char rv[10]; if(v) { sprintf(rv,"%d", v->cursor_channel + c_range_offset); return(rv); } else return("");}/*************************************************************************/static char *view_get_range_time(v) View *v;{ static char rv[20]; if(v) { sprintf(rv,"%s%6f:%6f", time_range_prefix, v->lmarker_time,v->rmarker_time); return(rv); } return("");}/*************************************************************************/static char *view_get_range_samp(v) View *v;{ static char rv[20]; if(v && v->sig) { sprintf(rv,"%s%d:%d",samp_range_prefix, time_to_sample(v->sig,v->lmarker_time), time_to_sample(v->sig,v->rmarker_time)); return(rv); } else return("");}/*************************************************************************/static char *view_get_range_yval(v) View *v;{ static char rv[20]; if(v && v->sig) { if(v->tmarker_yval < v->bmarker_yval) sprintf(rv,"%6f:%6f",v->tmarker_yval, v->bmarker_yval); else sprintf(rv,"%6f:%6f",v->bmarker_yval, v->tmarker_yval); return(rv); } else return("");}/*************************************************************************/static char *view_get_range_chan(v) View *v;{ static char rv[20]; if(v) { sprintf(rv,"%d:%d",v->bmarker_chan + c_range_offset, v->tmarker_chan + c_range_offset); return(rv); } return("");}/*************************************************************************//* Returns the displayed element numbercounting from zero at bottom of display. */view_invert_display_index(v,ind) View *v; int ind; /* signal element number */{ if(v && (v->dims > 1)) { int i; if(isa_spectrogram_view(v)) return(ind); for(i=0; i < v->dims; i++) if(v->elements[i] == ind) return(i); } return(0);}/*************************************************************************/static char *view_get_cursor_channels(v) View *v;{ static char *rv = NULL; static char nch = 0; if(v && (v->dims >= 1)) { int is = view_invert_display_index(v,v->bmarker_chan), ie = view_invert_display_index(v,v->tmarker_chan), need = (ie-is+1) * 4; if(need > nch) { if(rv) free(rv); nch = 0; if(!(rv = malloc(need))) { fprintf(stderr,"Allocation problems in view_get_range_chan()\n"); return(""); } nch = need; } *rv = 0; if(!isa_spectrogram_view(v)) for(; is <= ie; is++) sprintf(rv+strlen(rv),"%d ",v->elements[is] + c_range_offset); else for(; is <= ie; is++) sprintf(rv+strlen(rv),"%d ",is + c_range_offset); return(rv); } return("");}/*************************************************************************/static char *view_get_win_x(v) View *v;{ if (v && v->canvas) { static char info[10]; Frame frm = (Frame) xv_get(v->canvas, XV_OWNER); Rect rec; frame_get_rect(frm, &rec); sprintf(info, "%d", rec.r_left); return(info); } else return("");}/*************************************************************************/static char *view_get_loc_x(v) View *v;{ if (v && v->canvas) { static char info[10]; Frame frm = (Frame) xv_get(v->canvas, XV_OWNER); Rect rec; frame_get_rect(frm, &rec); sprintf(info, "%d", rec.r_left + *(v->x_offset)); return(info); } else return("");}/*************************************************************************/static char *view_get_loc_y(v) View *v;{ if (v && v->canvas) { static char info[10]; Frame frm = (Frame) xv_get(v->canvas, XV_OWNER); Rect rec; frame_get_rect(frm, &rec); sprintf(info, "%d", rec.r_top); return(info); } else return("");}/*************************************************************************/static char *view_get_sec_cm(v) View *v;{ static char rv[10]; if(v) { sprintf(rv, "%lf", *(v->x_scale)); return(rv); } return("");}/*************************************************************************/static char *view_get_val_cm(v) View *v;{ static char rv[10]; if(v) { int i; for(*rv = 0, i = 0; i < v->dims; i++) if(v->elements[i] == v->cursor_channel) { sprintf(rv,"%lf",v->y_scale[i]); break; } return(rv); } return("");}/*************************************************************************/static char *view_get_cursor_value(v) View *v;{ static char rv[10]; double signal_get_value(); if(v) { *rv = 0; if(v->sig) { sprintf(rv,"%.6e", signal_get_value(v->sig,v->cursor_channel,time_to_index(v->sig,v->cursor_time))); } return(rv); } return("");}/*************************************************************************/static char *view_get_cursor_labels(v) View *v;{ static char *rv = NULL; static int nrv = 0; int i; List *l, *l2; if(v && v->sig && (l = v->sig->idents)) { int needed = v->sig->dim * 15; if(needed > nrv) { if(rv) free(rv); nrv = 0; if(!(rv = malloc(needed))) { fprintf(stderr,"Allocation problems in view_get_cursor_labels()\n"); return(""); } nrv = needed; } *rv = 0; for(i = 0, l2 = l; i < v->sig->dim; i++) { sprintf(rv+strlen(rv),"%s ",l2->str); if(l2->next) l2 = l2->next; } return(rv); } return("");}/*************************************************************************/static char *view_get_cursor_values(v) View *v;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -