⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xlabel.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 5 页
字号:
  Label *label, *la;  Fields *fld;  Objects *ob = lf->obj;  char *c;  int edit_string = FALSE;  if(!strcmp(str,"*PRINT*")) { /* print graphic */    meth_print(ob,NULL);    return;  }  if(!strcmp(str,"*DEL*")) {	/* delete the label? */    if((la = get_nearest_label(lf,lf->time_t)) &&       remove_nearest_label(lf, lf->time_t, lf->color_t)) {      redo_display(ob);      waves_send(ob->name,"unmark",la->color,lf->time_t);    }    return;  }  if(!strcmp(str,"*UNLOAD*")) { /* remove the label file? */    rewrite_labels(lf);    destroy_labelfile(ob,lf,1);    set_display_size(ob);    redo_display(ob);    return;  }  if(!strcmp(str,"*REPLACE*")) {    insert_mode = 0;    return;  }  if(!strcmp(str,"*INSERT*")) {    insert_mode = 1;    return;  }  if(!strcmp(str,"*MOVE*")) {    insert_mode = 2;    return;  }  if(!strcmp(str,"*EDIT*"))    edit_string = TRUE;  else    edit_string = FALSE;  /* else, it is a label to be applied */  if(!edit_string && !event_shift_is_down(ev) && insert_mode) {    if(! (label = new_label(lf->time_t, lf->color_t))) {      fprintf(stderr,"Can't allocate another label structure!\n");      return;    }    if(!append_label(label,lf)) {      fprintf(stderr,"Error from append_label() in label_menu_proc()\n");      return;    }    if(!(fld = (Fields*)new_field(NULL, 1, lf->color_t, 0))) {      fprintf(stderr,"Can't get new_field() in label_menu_proc()\n");      return;    }    label->fields = fld;  }  if(edit_string || event_shift_is_down(ev) ||     (insert_mode == 0)) {	/* replace or edit nearest label */    Fields *f;    if(!(label = get_nearest_label(lf,lf->time_t)))      return;			/* nothing to replace */    fld = f = label->fields;    while(f && (f->field_id != replace_field)) {      fld = f;      f = f->next;    }    if(!f) {			/* must create missing fields */      if(!fld)	label->fields = fld = (Fields*)new_field(NULL, 1, lf->color_t, 0);      while(fld->field_id < replace_field) {	fld->next = new_field(NULL,fld->field_id + 1, lf->color_t, 0);	if(!(fld = fld->next)) {	  fprintf(stderr,"Allocation failure in label_menu_proc\n");	  return;	}      }    } else      fld = f;    if(edit_string) {      set_up_editor(ob,lf,label,fld);      return;    }    if(fld->str) free(fld->str);  }  c = malloc(strlen(str)+1);  strcpy(c,str);  fld->str = c;  lf->changed = TRUE;  if(insert_mode == 1)    if(!file_update(lf,label)) {      fprintf(stderr,"Problems doing file_update() in label_menu_proc()\n");      return;    }    else      if(!rewrite_labels(lf)) { /* Must rewrite whole file. */	fprintf(stderr,"Problems doing rewrite_labels() in label_menu_proc()\n");	return;      }  plot_labels(lf);  if(insert_mode && !event_shift_is_down(ev))    waves_send(ob->name, "mark", lf->color_t, lf->time_t);}/*********************************************************************/voiddone_proc(men, result)    Menu	men;    Xv_opaque	result;{  if(evrx || evry)    xv_set(evrw,	   WIN_MOUSE_XY, evrx, evry, 0);  evrx = evry = 0;  evrw = NULL;}/*********************************************************************/plot_labels(lf)     Labelfile *lf;{  Pixwin *pw;  Pixfont *pf;  Rect *rec;  Wobject *wob;  Objects *ob;  Labelfile *lf2;  Label *label;  Fields *f;  double end;  int x, y, n, top, bot, old_x[100], xl, yl, f_plotted;  int ystep, ymin, ymax, yspace, width, lev, oldf, yoffset;  char mes[MES_BUF_SIZE];  if(!((ob = lf->obj) && (lf2 = ob->labels)))    return(FALSE);  n = 1;  x = 1;  while((lf2 = lf2->next)) {    n++;    if(lf2 == lf) x = n;  }  wob = get_wobject(ob);  pw = canvas_pixwin(ob->canvas);  rec = (Rect*)xv_get(ob->canvas, WIN_RECT);  if(wob && wob->charts && wob->charts->first_word) {    lf->height = wob->label_size/n;    yoffset = (wob->label_loc)? rec->r_height - wob->label_size : 0;  } else {    lf->height = rec->r_height/n;    yoffset = 0;  }  top = (x-1)*lf->height + yoffset;  bot = top + lf->height + yoffset;  end = ob->start + ((ob->sec_cm * rec->r_width) /PIX_PER_CM);  if (debug_level > 1)     (void) fprintf(stderr,		   "plot_labels: n;%d x:%d height:%d top:%d bot:%d yoffset:%d\n",		   n, x, lf->height,top,bot,yoffset);     if(!doing_print_graphic)      pw_rop(pw,0,top,rec->r_width,lf->height,          PIX_SRC|PIX_COLOR(W_BACKGROUND_COLOR), NULL,0,W_BACKGROUND_COLOR);  if(lf->next)    pw_vector(pw, 0, bot-1, rec->r_width, bot-1, PIX_SRC, lf->color);  if((label=lf->first_label)){    if((pf = lf->font)) { /* set sizes */      yspace = (int)xv_get(pf,FONT_DEFAULT_CHAR_HEIGHT)*0.2;      ystep = ymin = (int)xv_get(pf,FONT_DEFAULT_CHAR_HEIGHT) + yspace;      ymax = bot - ystep;    }    else {      fprintf(stderr,"plot_labels: cannot get window font\n");      return(FALSE);    }    width = (int)xv_get(pf,FONT_DEFAULT_CHAR_WIDTH);    if (debug_level) 	(void) fprintf(stderr, "yspace = %d, ystep = %d, width = %d\n",		       yspace, ystep, width);     for(lev = 0; lev < 100; lev++) old_x[lev] = 0;    lev = 0;    y = top;    while(label) {      if((label->time >= ob->start) && (label->time <= end)) {	xl = time_to_x(ob,label->time);	f = label->fields;	*mes = 0;	x = xl - width;	oldf = 1;	f_plotted = FALSE;	while(f) {	  if(lf->active[f->field_id-1]) {	    if(f->str) x -= (strlen(f->str) * width);	    if(f_plotted)	      while(f->field_id > oldf){/* place marks for blank active fields */		if(lf->active[oldf-1]) {		  x -= width;		  strcat(mes,lf->separator);		}		oldf++;	      }	    if(f->str) {	      strcat(mes,f->str);	      f_plotted = TRUE;	      oldf = f->field_id;	    }	  }	  f = f->next;	}	y = top;	lev = 0;	while(old_x[lev] && (x <= old_x[lev])) {	  lev++;	  y += ystep;	}	x += width;	if(y > ymax) y = ymax;	old_x[lev] = xl;	yl = y + ystep;	pw_text(pw,x,yl - yspace,PIX_COLOR(TEXT_COLOR)|PIX_SRC,pf,mes);	pw_vector(pw, xl, yl, x, yl, PIX_SRC, label->color);	if(xl <= rec->r_width)	  pw_vector(pw, xl, top, xl, yl, PIX_SRC, label->color);      }      label = label->next;    }  }  return(TRUE);}/*********************************************************************/redo_display(ob)     Objects *ob;{  Label *l;  Labelfile *lf;  double end;  Rect *rec;  Pixwin *pw;  int x, n;  Wobject *w;  Chartfile *cf;    if(!(ob && ob_exists(ob))) return(FALSE);  if(! ob->canvas) {    fprintf(stderr,"Null canvas in redo_display()\n");    return(FALSE);  }  ob->oldcursor_x = -1;  ob->oldcursor_y = -1;  w = get_wobject(ob);  if(!(lf = ob->labels) && (!w || (w && !w->charts))) {    rec = (Rect*)xv_get(ob->canvas, WIN_RECT);    pw = canvas_pixwin(ob->canvas);      pw_rop(pw,0,0,rec->r_width,rec->r_height,	   PIX_SRC|PIX_COLOR(W_BACKGROUND_COLOR),NULL,0,W_BACKGROUND_COLOR);    return(TRUE);  }  while(lf) {    plot_labels(lf);    lf = lf->next;  }  if(w) {    cf = w->charts;    while(cf) {      plot_chart(cf);      cf = cf->next;    }  }  return(TRUE);}/*********************************************************************/char *meth_unload(ob, args)     Objects *ob;     char *args;{  static char file[NAMELEN],object[NAMELEN];  static Selector a0 = {"file","%s",file,NULL},                  a1 = {"name","%s",object,&a0};  Labelfile *lf, *find_labelfile();  extern Objects *objlist;  *file = *object = 0;  get_args(args,&a1);  if((ob == program)) {    if((! *object) && (objlist != program))      strcpy(object,objlist->name);    ob = (Objects*)get_receiver(object);  }  if(ob && (! *file) && ob->labels)    strcpy(file,ob->labels->label_name);  if(ob && (lf = find_labelfile(ob,file))) {      rewrite_labels(lf);      destroy_labelfile(ob,lf,1);      set_display_size(ob);      redo_display(ob);      return(Ok);    }  return(Null);}/*********************************************************************/char *meth_kill(ob, args)     Objects *ob;     char *args;{  static char file[NAMELEN],object[NAMELEN], chart[NAMELEN];  static Selector a0 = {"file","%s",file,NULL},                  a1 = {"name","%s",object,&a0},                  a2b = {"chartfile","%s",chart,&a1},                  a2 = {"chart","%s",chart,&a2b};  Labelfile *lf;  Frame fr;  Objects *o;  int got, sendit;  *file = 0;  *object = 0;  *chart = 0;  sendit = 0;  got = get_args(args,&a2);  if(ob == program) {		/* Was this a message to the program? */    if(!(got && (o = (Objects*)get_receiver(object))))      return(Null);    if(*file) { /* label file specified?*/      if((lf = (Labelfile*)get_labelfile(o,file))) {	rewrite_labels(lf);	destroy_labelfile(o,lf,1);	set_display_size(o);	redo_display(o);		xv_set(file_item, PANEL_VALUE, "", 0);	*inputname = 0;	return(Ok);      } else return(Null);    } else			/* chart file specified? */      if(kill_chartfile(chart,(o = (Objects*)get_receiver(object))))	redo_display(o);    /* If neither label or chart was specified prepare to kill entire object */      else {	ob = o;	sendit = 1;		/* send "unmark" commands to host */      }  } else {		/* The message was sent to a display object. */    /* "file" will be the name of a signal file in this case */    if(*file)	     /* label doesn't care which signames are displayed */      return(Ok);  /*(assumes that something remains in display ensemble)*/    sendit = 0;  }  /* Getting here implies that the message was sent to a display object     either implicitly or explicitly.     The whole display ensemble will be distroyed */  if((fr = (Frame)xv_get(ob->canvas, XV_OWNER))) {    Canvas    canvas = xv_get(ob->canvas, CANVAS_PAINT_CANVAS_WINDOW);    save_shared_colormap(ob->canvas);    xv_set(fr, WIN_CLIENT_DATA, NULL, 0);    xv_set(ob->canvas, WIN_CLIENT_DATA, NULL, 0);    if(canvas)      xv_set(canvas, WIN_CLIENT_DATA, NULL, 0);    kill_object(ob,sendit);    xv_set(fr, FRAME_NO_CONFIRM, TRUE, 0);    xv_destroy_safe(fr); /* causes kill_object in kill_signal_view */    xv_set(file_item, PANEL_VALUE, "", 0);    *inputname = 0;        if(is_chart()) {      xv_set(chart_item, PANEL_VALUE, "", 0);      *chartname = 0;    }        xv_set(object_item, PANEL_VALUE, "", 0);    *objectname = 0;    return(Ok);  }  return(Null);}/*********************************************************************/is_chart(){  extern Objects *program;  return(!strcmp("xchart",basename(program->name)));}/*********************************************************************/char *meth_set(ob, args)     Objects *ob;     char *args;{  get_args(args, &g4);    xv_set(object_item, PANEL_VALUE, objectname,0);  if(*objectname)    newFile(object_item,NULL);  if(is_chart()) {        xv_set(chart_item, PANEL_VALUE, chartname,0);    newFile(chart_item,NULL);    xv_set(top_word_item, PANEL_VALUE, topword,0);    newFile(top_word_item,NULL);  }  xv_set(file_item, PANEL_VALUE, inputname,0);  if(*inputname)    newFile(file_item,NULL);  xv_set(active_item, PANEL_VALUE, active,0);  newFile(active_item, NULL);    xv_set(menu_item, PANEL_VALUE, menufile,0);  newFile(menu_item,NULL);      return(Ok);}/*********************************************************************/initial_setup(){  xv_set(file_item, PANEL_VALUE, inputname,0);    xv_set(menu_item, PANEL_VALUE, menufile,0);      xv_set(object_item, PANEL_VALUE, objectname,0);  if(*objectname)    newFile(object_item,NULL);  if(is_chart()) {        xv_set(chart_item, PANEL_VALUE, chartname,0);    newFile(chart_item,NULL);    xv_set(top_word_item, PANEL_VALUE, topword,0);    newFile(top_word_item,NULL);  }  xv_set(active_item, PANEL_VALUE, active,0);  newFile(active_item, NULL);  }/*********************************************************************/char *meth_mark(ob, args)     Objects *ob;     char *args;{  static double time, rstart, rend;  static int color;  static char file[NAMELEN], label[MES_BUF_SIZE];   static Selector     a4 = {"rend", "%lf", (char*)&rend, NULL},     a3 = {"rstart", "%lf", (char*)&rstart, &a4}, /* recognize & ignore */     a2c = {"label", "#strq", label, &a3},     a2b = {"replace_field", "%d", (char*)&replace_field, &a2c},     a2 = {"time", "%lf", (char*)&time, &a2b },     a1 = {"color", "%d", (char*)&color, &a2},     a0b = {"signal", "%s", signame, &a1},     a0 = {"file", "%s", file, &a0b};  Labelfile *lf;  if(ob_exists(ob)) {    time = 0.0;    *file = 0;    *label = 0;    color = -1;      if(get_args(args, &a0) ) {      if(!(lf = get_labelfile(ob,file))) lf = ob->labels;      if((color < 0) && lf) color = lf->color;      if(*label) {	event_x(&pseudo_event) = time_to_x(lf->obj,time);	event_y(&pseudo_event) = wind_height/2;	lf->time_t = time;	lf->color_t = color;	do_labels(&pseudo_event, lf, label);	return(Ok);      } else	if(do_label_menu(lf,time,0,color,NULL, 0)) {	  return(Ok);	}    }  }     return(Null);}/*********************************************************************/cleanup(){  extern Objects *program;  Objects *obj;  Labelfile *lf;  int dumcol=1;  double dumtime = 0.0;  extern Objects *objlist;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -