📄 xoverlays.c
字号:
int x, y, i, j; double time, tinc; POLE **po; Pixwin *pw; Signal *s; struct rect *rect; int color; if(v && (vh = (View*)v->extra) && (s = v->sig)) { if(((s->type & SPECIAL_SIGNALS) == SIG_LPC_POLES) && (po = (POLE**)s->data) && (s->buff_size > 0)) { pw = canvas_pixwin(v->canvas); rect = (struct rect*)xv_get(v->canvas, WIN_RECT); if(vh->overlay_as_number) color = FOREGROUND_COLOR; else color = YA1_COLOR; for(tinc = 1.0/s->freq, i=0; i < s->buff_size; i++) { if(((time = (tinc*i)+BUF_START_TIME(s)) >= vh->start_time) && (time <= ET(vh))) { if (vh->overlay_as_number) { for(j=0,x=o_time_to_x(vh,time) + o_xoff; j < po[i]->npoles; j++) { y = vh->yval_to_y(vh,po[i]->freq[j]) + o_yoff; pw_ttext(pw, x, y, PIX_SRC|PIX_COLOR(color), def_font, "*"); } } else { x = o_time_to_x(vh, time); for(j = 0; j < po[i]->npoles; j++) { y = vh->yval_to_y(vh, po[i]->freq[j]); pw_write(pw, x + o_off, y + o_off, o_siz, o_siz, PIX_SRC|PIX_COLOR(color), NULL, 0, 0); } } } } return(TRUE); } else show_notice(1,"Apparently bogus SIG_LPC_POLES in overlay_poles"); } else show_notice(1,"Bad argument(s) to overlay_poles"); return(FALSE);}/****************************************************************************/pole_cursor(v) View *v;{ return(TRUE);}/****************************************************************************/pole_print(v) View *v;{ int i,j,k; POLE **po; View *vh = (View*)v->extra; double time, freq, amin, tm; char tmp[100]; /* Frame frm; */ Pixwin *pw; time = vh->cursor_time; if (time < vh->start_time) time = vh->start_time; if (time > (tm = ET(vh))) time = tm; freq = vh->cursor_yval; if (freq < vh->start_yval) freq = vh->start_yval; if (freq > vh->end_yval) freq = vh->end_yval; po = (POLE**)v->sig->data; i = time_to_index(v->sig, time); if(po && po[i] && po[i]->npoles) { for(amin=1.0e8,j=0,k=0; j < po[i]->npoles; j++) { if((tm = fabs(po[i]->freq[j] - freq)) < amin) { amin = tm; k = j; } } sprintf(tmp,"pF:%5.0f pB:%5.0f",po[i]->freq[k],po[i]->band[k]); /* pw = (Pixwin*)xv_get(v->canvas, WIN_PIXWIN); */ pw = canvas_pixwin(v->canvas); pw_text(pw, 0, P_F_Y_LOC, PIX_SRC|PIX_COLOR(YA1_COLOR), def_font, tmp); }} /*********************************************************************/Signal *find_host_signal(ob,name) Object *ob; char *name;{ Signal *s; if(ob && name && (s = ob->signals)) { while(s) { if(!strcmp(expand_name(NULL,name),s->name) && s->views) return(s); s = s->others; } } return(NULL);}/****************************************************************************/View *setup_overlay(object,name,onname) char *name, *object, *onname;{ Object *o, *find_object(); Signal *s, *so, *get_any_signal(), *find_signal(); extern int read_poles(); double mpexc_buf_start(), mpexc_buf_end(); if(name && *name) { if(!(o = find_object(object))) object = objectname; if((o = find_object(object))) { if(!(s = find_host_signal(o,onname))) { s = o->signals; /* If no "onname" can be found, default to either the most recent spectrogram or the most recently loaded signal. */ for ( ; s->others; s = s->others ) { if ((!s->views) || (s->views && (s->views->extra_type == VIEW_OVERLAY))) continue; /* (no valid view to overlay onto) */ if ((s->type & SPECIAL_SIGNALS) == SIG_SPECTROGRAM ) break; } } if(s) { if((so=get_any_signal(expand_name(NULL,name),0.0,0.0,NULL))) { switch(so->type & SPECIAL_SIGNALS) { case SIG_GENERAL: if (!IS_GENERIC(so->type)) { sprintf(notice_msg, "Specified overlay signal type %x not supported", so->type); show_notice(1,notice_msg); free_signal(so); return(NULL); } if (so->utils->read_data(so, s->start_time, s->end_time - s->start_time)) { /* use SIG_END_TIME()? */ close_sig_file(so); return setup_general_overlay(so, s->views); } else { show_notice(1,"Problems reading general signal in setup_overlay"); return(NULL); } case SIG_LPC_POLES: so->utils->read_data = read_poles; if(so->utils->read_data(so,s->start_time, s->end_time - s->start_time)) { /* should use SIG_END_TIME() */ close_sig_file(so); return(setup_pole_overlay(so,s->views)); } else { show_notice(1,"Problems reading poles in setup_overlay"); return(NULL); } default: if(((s->type & SPECIAL_SIGNALS) != SIG_SPECTROGRAM ) && IS_GENERIC(s->type)) return(setup_general_overlay(so,s->views)); if(((s->type & SPECIAL_SIGNALS) == SIG_SPECTROGRAM ) && ((so->type & VECTOR_SIGNALS) != P_DOUBLES)) { sprintf(notice_msg, "Specified overlay signal type %x not supported",so->type); show_notice(1,notice_msg); free_signal(so); return(NULL); } /* else fall through and try to overlay */ case SIG_FORMANTS: if(so->utils->read_data(so,s->start_time, s->end_time - s->start_time)) { /* should use SIG_END_TIME() */ close_sig_file(so); return(setup_formant_overlay(so,s->views)); } else { show_notice(1,"Problems reading formants in setup_overlay"); return(NULL); } } } else { sprintf(notice_msg,"Can't get signal %s in setup_overlay",name); show_notice(1,notice_msg); return(NULL); } } sprintf(notice_msg, "Object %s has no views on which to overlay",objectname); show_notice(1,notice_msg); } else { sprintf(notice_msg, "Object %s doesn't exist, or has no views",objectname); show_notice(1,notice_msg); } } return(NULL);} /****************************************************************************/View *setup_general_overlay(s, v) Signal *s; /* signal to overlay */ View *v; /* usually the view of the "host" signal */{ Object *o; Signal *sh; View *vo, *vh; Rect *rec; extern int YA1_COLOR; int overlays, i; if((vh = v) && (sh = v->sig) && (o = (Object*)sh->obj) && v->canvas) { s->others = o->signals; o->signals = s; s->obj = (caddr_t)o; if((vo = new_waves_view(s, v->canvas))) { rec = (Rect*)xv_get(v->canvas,WIN_RECT); vo->width = rec->r_width; vo->height = rec->r_height; vo->extra = (caddr_t)v; vo->extra_type = VIEW_OVERLAY; vo->cursor_plot = dummy_cursor; vo->reticle_plot = NULL; vo->x_print = general_overlay_print; vo->y_print = NULL; vo->time_to_x = generic_time_to_x; vo->x_to_time = generic_x_to_time; vo->yval_to_y = generic_yval_to_y; vo->y_to_yval = generic_y_to_yval; vo->xy_to_chan = overlay_xy_to_chan; if(isa_spectrogram_view(vh)) { vo->data_plot = overlay_spectrograms; } else { if(IS_TAGGED_FEA(s)) { int tag_time_to_x(), tag_plot_waves(); double tag_x_to_time(); vo->data_plot = tag_plot_waves; vo->time_to_x = tag_time_to_x; vo->x_to_time = tag_x_to_time; } else { vo->data_plot = overlay_general; } } overlays = 0; while(v->next) { v = v->next; /* put new view at end of list */ if(v->extra_type & VIEW_OVERLAY) v->overlay_n = overlays++; } vh->overlay_n = overlays; vo->overlay_n = overlays; for(i=0; i < s->dim; i++) vo->colors[i] = YA1_COLOR + overlays + 1; { double start, size; start = vh->start_time; size = ET(vh) - vh->start_time; get_view_segment(vo,&start,&size); } if(vh->plotted) { /* do overlay now if host plot is visible */ vo->data_plot(vo); vo->cursor_plot(vo); vo->x_print(vo); } vo->next = v->next; v->next = vo; /* (redisplay is done in list order) */ return(vo); } else show_notice(1,"Can't make new_waves_view in setup_general_overlay"); } else { show_notice(1,"Bad argument(s) to setup_general_overlay"); } return(NULL);}/****************************************************************************//* The overlay is implemented by sharing the canvas of the "host" signal view.Things like display offsets, scale factors, come from host by dereferencingoverlaying_view->extra in the context of VIEW_OVERLAY. overlaying_view->sigrefers to the overlaying signal. The overlaying signal does not referenceANY views directly (s->views == NULL). */View *setup_formant_overlay(s,v) Signal *s; /* the formant signal */ View *v; /* the "host" view */{ Object *o; Signal *sh; View *vo; Rect *rec; if((sh = v->sig) && (o = (Object*)sh->obj) && v->canvas) { int overlays; View *vh = v; s->others = o->signals; o->signals = s; s->obj = (caddr_t)o; if((vo = new_waves_view(s, v->canvas))) { rec = (Rect*)xv_get(v->canvas,WIN_RECT); vo->width = rec->r_width; vo->height = rec->r_height; vo->extra = (caddr_t)v; vo->extra_type = VIEW_OVERLAY; vo->data_plot = overlay_formants; vo->cursor_plot = formant_cursor; vo->reticle_plot = NULL; vo->x_print = formant_print; vo->y_print = NULL; vo->time_to_x = generic_time_to_x; vo->x_to_time = generic_x_to_time; vo->yval_to_y = generic_yval_to_y; vo->y_to_yval = generic_y_to_yval; vo->xy_to_chan = overlay_xy_to_chan; vo->dims = s->dim/2; if(v->plotted) { /* do overlay now if host plot is visible */ vo->data_plot(vo); vo->cursor_plot(vo); vo->x_print(vo); } overlays = 0; while(v->next) { v = v->next; /* put new view at end of list */ if(v->extra_type & VIEW_OVERLAY) v->overlay_n = overlays++; } vh->overlay_n = overlays; vo->overlay_n = overlays; vo->next = v->next; v->next = vo; /* (redisplay is done in list order) */ return(vo); } else show_notice(1,"Can't make new_waves_view in setup_formant_overlay"); } else show_notice(1,"Bad argument(s) to setup_formant_overlay"); return(NULL);}/****************************************************************************/View *setup_pole_overlay(s,v) Signal *s; /* the POLE signal */ View *v; /* the "host" view */{ Object *o; Signal *sh; Rect *rec; View *vo; if((sh = v->sig) && (o = (Object*)sh->obj) && v->canvas) { s->others = o->signals; o->signals = s; s->obj = (caddr_t)o; if((vo = new_waves_view(s, v->canvas))) { rec = (Rect*)xv_get(v->canvas,WIN_RECT); vo->width = rec->r_width; vo->height = rec->r_height; vo->extra = (caddr_t)v; vo->extra_type = VIEW_OVERLAY; vo->data_plot = overlay_poles; vo->cursor_plot = pole_cursor; vo->reticle_plot = NULL; vo->x_print = pole_print; vo->y_print = NULL; vo->time_to_x = generic_time_to_x; vo->x_to_time = generic_x_to_time; vo->yval_to_y = generic_yval_to_y; vo->y_to_yval = generic_y_to_yval; if(v->plotted) { /* do overlay now if host plot is visible */ vo->data_plot(vo); vo->cursor_plot(vo); vo->x_print(vo); } while(v->next) v = v->next; /* put new view at end of list */ vo->next = v->next; v->next = vo; /* (redisplay is done in list order) */ return(vo); } else show_notice(1,"Can't make new_waves_view in setup_pole_overlay"); } else show_notice(1,"Bad argument(s) to setup_pole_overlay"); return(NULL);}/*********************************************************************/o_time_to_x(v,time) register View *v; register double time;{ return((int)(.5 + (PIX_PER_CM * ((time - v->start_time) / *(v->x_scale)))) + *(v->x_offset));}/*******************************************************************/static finish_overlay_edit(sf, vh, event, active) Signal *sf; View *vh; Event *event; int active;{ int id; if (event_is_up(event) && ((id = event_id(event)) != LOC_WINENTER) && (id != LOC_WINEXIT) && (id != LOC_MOVE)) { if((active >= 0) && vh->redraw_on_release) redoit(vh->canvas); else if(vh->cursor_plot) vh->cursor_plot(vh, CURSOR_COLOR); /* Optionally, save the signal after each edit. */ if(sf && vh->rewrite_after_edit && (sf->file_size == sf->buff_size)) { if(sf->file == SIG_NEW) put_waves_signal(sf); else put_signal(sf); } return(TRUE); } else return(FALSE);}/****************************************************************************//* Scan view list for this canvas looking for LPC_POLE and FORMANTS file overlays. If both of these are found, check the state of the FORMANTS file descriptor. If it is not SIG_NEW, change the name of the FORMANTS file (append "2" or something) and change s->file to SIG_NEW. Get the cursor time, index and frequency coordinates. If the button was just depressed (event_down and !LOC_DRAG) determine which formant the cursor is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -