📄 view_utils.c
字号:
{ static char *rv = NULL; static int nrv = 0; double signal_get_value(); int i; if(v && v->sig) { int ch, ind = time_to_index(v->sig, v->cursor_time), 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_values()\n"); return(""); } nrv = needed; } *rv = 0; for(i = 0; i < v->sig->dim; i++) sprintf(rv+strlen(rv),"%.6e ",signal_get_value(v->sig,i,ind)); return(rv); } return("");}/*************************************************************************/static char *view_get_view_channels(v) View *v;{ static char *rv = NULL; static int nrv = 0; int i; if(v && (v->dims > 1)) { int needed = v->dims * 5; if(needed > nrv) { if(rv) free(rv); nrv = 0; if(!(rv = malloc(needed))) { fprintf(stderr,"Allocation problems in view_get_view_channels()\n"); return(""); } nrv = needed; } *rv = 0; for(i=0; i < v->dims; i++) sprintf(rv+strlen(rv),"%d ",v->elements[i] + c_range_offset); return(rv); } else return("0");}/*************************************************************************/static char *view_get_view_end_time(v) View *v;{ static char rv[10]; if(v) { sprintf(rv,"%lf",ET(v)); return(rv); } return("");}/*************************************************************************/static char *view_get_computed_value(v, name) View *v; char *name;{ Activator *a = &vb0; while(a) { if(!strcmp(name, a->name)) return(a->proc(v)); a = a->next; } return(NULL);}/*************************************************************************/char *view_get_value(v, name) char *name; View *v;{ if( name && *name) { char *rv; if((rv = view_get_computed_value(v, name))) return(rv); else { Selector *vs = view_setup_access(v); if((rv = value_as_string(vs, name))) return(rv); else { extern Selector g1; if((rv = value_as_string(&g1, name))) return(rv); } } } return("null");}/*************************************************************************//* This destroys all views of this signal that are NOT in this signal's view list, but refer to it. */View *find_and_destroy_overlay_views(s) Signal *s;{ View *vr = NULL; if(s && s->obj) { Signal *so = ((Object*)s->obj)->signals; while(so) { if(so != s) { View *v = so->views, *v2; while(v) { if((v->sig == s) && /* found a view to be destroyed == v */ (v->extra_type == VIEW_OVERLAY) && v->extra) { vr = (View*)v->extra; v2 = so->views; if(v2 == v) so->views = v->next; else while(v2) { if(v2->next == v) v2->next = v2->next->next; v2 = v2->next; } v2 = v->next; v->sig = NULL; v->next = NULL; free_view(v); v = v2; } else v = v->next; } } so = so->others; } } return(vr);}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*//* Return the "active element" number whose identification string matches str. If a channel label can not be found to match str, -1 is returned. */get_active_labeled_chan(v,str) View *v; char *str;{ Signal *s = v->sig; register List *l, *l2; if(s && (l = s->idents)) { register int curi, i, dim; for(dim=0; dim < v->dims; dim++) { /* for each active dimension... */ curi = v->elements[dim]; for(i = 0, l2 = l; i < curi; i++) { /* get label for this chan. */ if(l2->next) l2 = l2->next; } /* falls through with l2 set */ if(!strcmp(l2->str,str)) return(dim); } } return(-1);}/*********************************************************************/char *get_channels_name(v,n) register View *v; register int n;{ register List *l; if(v && v->sig && (n < v->sig->dim) && (l = v->sig->idents)) { while((n-- > 0) && l->next) l = l->next; return(l->str); } return(NULL);}/*********************************************************************/clear_active_channels(v) View *v;{ extern char active_ids[], active_numbers[]; int i, dim; Signal *s; char *cp, name[50], *get_next_item(); if(v && (s = v->sig)) { cp = active_ids; while(*cp) { sscanf(cp,"%s",name); if((i = get_active_labeled_chan(v,name)) >= 0) { for(dim=i+1; (v->dims > 1) && (dim < v->dims); dim++) v->elements[dim-1] = v->elements[dim]; v->dims--; } cp = get_next_item(cp); } cp = active_numbers; while(*cp) { sscanf(cp,"%d",&dim); if(dim < s->dim) { for(i=0; i < v->dims; i++) if(v->elements[i] == dim) { for(dim=i+1; (v->dims > 1) && (dim < v->dims); dim++) v->elements[dim-1] = v->elements[dim]; v->dims--; break; } } cp = get_next_item(cp); } *active_numbers = *active_ids = 0; for(i=0, cp = active_numbers; i < v->dims; i++) { sprintf(cp," %d",v->elements[i]); cp = active_numbers + strlen(active_numbers); } }}/*********************************************************************/add_active_channels(v) View *v;{ extern char active_ids[], active_numbers[]; int i, dim; Signal *s; char *cp, name[50]; if(v && (s = v->sig)) { if(*active_ids && s->idents) for(i=0; i < v->dims; i++) { strcat(active_ids," "); strcat(active_ids,get_channels_name(v,v->elements[i])); } if(*active_numbers) for(i=0; i < v->dims; i++) { cp = active_numbers + strlen(active_numbers); sprintf(cp," %d",v->elements[i]); } set_active_channels(v); }}/*********************************************************************/set_active_channels(v) View *v;{ extern char active_ids[], active_numbers[]; int i, dim; Signal *s; char *cp, name[50], *get_next_item(); if(v && (s = v->sig) && (*active_ids || *active_numbers)) { if(isa_spectrogram_view(v)) return; for(i=0; i < s->dim; i++) v->elements[i] = 0; cp = active_ids; while(*cp) { sscanf(cp,"%s",name); if((i = get_labeled_chan(s,name)) >= 0) v->elements[i] = 1; cp = get_next_item(cp); } cp = active_numbers; while(*cp) { sscanf(cp,"%d",&i); if((i >= 0) && (i < s->dim)) v->elements[i] = 1; cp = get_next_item(cp); } for(i=0, v->dims = 0; i < s->dim; i++) { if(v->elements[i]) v->elements[v->dims++] = i; } if(! v->dims) { /* activate all, if none were correctly specified */ for(i=0; i < s->dim; i++) v->elements[i] = i; v->dims = s->dim; } }}/*********************************************************************/void operate_wave_scrollbar(v, event) View *v; Event *event;{ int id = event_id(event); switch (id) { case MS_LEFT: case MS_MIDDLE: case MS_RIGHT: if(event_is_down(event)) { operate_scrollbar(id, event_x(event), v); } break; default: break; } file_print_x(v,event_x(event));}/*********************************************************************/generic_time_to_x(v,time) register View *v; register double time;{ register int i; register double freq, t; freq = v->sig->freq; /* "integerize" time */ i = 0.5 + ((time - v->sig->start_time) * freq); time = v->sig->start_time + ((double)i)/freq; if (time < v->start_time) time = v->start_time; /* clamp */ if (time > (t = ET(v))) time = t; return((int)(.5 + (PIX_PER_CM * ((time - v->start_time) / (*v->x_scale)))) + (*v->x_offset));} /*********************************************************************/generic_yval_to_y(v, yval) register View *v; register double yval;{ register int i; for(i=0; i < v->dims; i++) if(v->cursor_channel == v->elements[i]) { if (yval < v->start_yval) yval = v->start_yval; if (yval > v->end_yval) yval = v->end_yval; yval -= v->start_yval; i = (v->y_offset[i]) - (int) (0.5 + yval * PIX_PER_CM / (v->y_scale[i])); return i; } return(0);} /*********************************************************************/double generic_x_to_time(v,x) register View *v; register int x;{ register int i; register double time, freq, t; freq = v->sig->freq; x -= *(v->x_offset); if(x < 0) x = 0; time = v->start_time + (double)x * *(v->x_scale) / PIX_PER_CM; if (time > (t = ET(v))) time = t; i = 0.5 + ((time - v->sig->start_time) * freq); return(v->sig->start_time + ((double)i)/freq);}/*********************************************************************/double generic_y_to_yval(v, y) register View *v; int y;{ double val; register int i, chan = v->cursor_channel; for(i=0; i < v->dims; i++) if(chan == v->elements[i]) { val = (v->y_offset[i] - y) * v->y_scale[i] / PIX_PER_CM; return( (val < v->sig->smin[chan]) ? v->sig->smin[chan] : ((val > v->sig->smax[chan]) ? v->sig->smax[chan] : val)); } return(0.0);}/*********************************************************************/double nonlin_y_to_yval(v, y) View *v; int y;{ double *y_dat, u; int d, i; y_dat = v->sig->y_dat; d = v->sig->dim - 1; u = d*(*v->y_offset - y)*(*v->y_scale) / (PIX_PER_CM*(v->end_yval - v->start_yval)); if (u < 0.0) return y_dat[0]; i = u; if (i >= d) return y_dat[d]; u -= i; return y_dat[i] + u*(y_dat[i+1] - y_dat[i]);}/*********************************************************************/generic_x_to_index(v, x) View *v; int x;{ Signal *s; if(v && (s = v->sig)) { double time = (v->x_to_time)? v->x_to_time(v,x) : generic_x_to_time(v,x); return((s->utils->time_to_index)? s->utils->time_to_index(s,time) : vec_time_to_index(s,time)); } return(0);}/*********************************************************************//* Given a view v, a buffer index, ind, a crossing level val, and achannel, chan, find the nearest positive level crossing within theview. */int level_crossing_index(v, ind, val, chan) int ind, chan; View *v; double val;{ if(v) { int is, ie, i, j, k; double oldv, dv, signal_get_value(); Signal *s; s = v->sig; is = time_to_index(s,v->start_time); ie = time_to_index(s,ET(v)); if((is <= ind) && (ie >= ind)) { if(is < ind) { i = ind; } else { i = ind + 1; } oldv = signal_get_value(s, chan, i-1); for(j = -1 ; i <= ie; i++) { if(((dv = signal_get_value(s, chan, i)) >= val) && (oldv < val)) { j = i; break; } oldv = dv; } if(ie > ind) i = ind; else i = ind-1; oldv = signal_get_value(s, chan, i); for(k = -1; i > is; i--) { if(((dv = signal_get_value(s, chan, i-1)) < val) && (oldv >= val)) { k = i; break; } oldv = dv; } if(k >= 0) { if((j >= 0) && ((j-ind) < ind - k)) return(j); else return(k); } else if(j >= 0) return(j); else return(ind); } } return(ind);}/*********************************************************************//* Given a view v, view Xposition x, a crossing level val, and achannel, chan, find the time of the nearest positive level crossing within theview and return the corresponding time. */double level_crossing_time(v, x, val, chan) int x, chan; View *v; double val;{ if(v) { int newind, ind; ind = generic_x_to_index(v, x); newind = level_crossing_index(v, ind, val, chan); return(v->sig->utils->index_to_time(v->sig, newind)); } return(0.0);}/*********************************************************************/int generic_ord_to_y(v, val) register View *v; double val;{ register int chan = v->cursor_channel, i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -