📄 xmarks.c
字号:
/* Copyright (c) 1995 Entropic Research Laboratory, Inc. *//* * This material contains unpublished, proprietary software of * Entropic Research Laboratory, Inc. Any reproduction, distribution, * or publication of this work must be authorized in writing by Entropic * Research Laboratory, Inc., and must bear the notice: * * "Copyright (c) 1987-1990 AT&T, Inc. * "Copyright (c) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-1993 Entropic Research Laboratory, Inc. * All rights reserved" * * The copyright notice above does not evidence any actual or intended * publication of this source code. * * Written by: Mark Liberman, Mark Beutnagel, AT&T Bell Laboratories * Checked by: * Revised by: Rodney Johnson, Entropic Research Laboratory * (convert to XView) * David Talkin (update attachment IPC) * Alan Parker (ditto) * * ``xwaves'' attachment for marking speech files * This version, based on "nmark" allows insertion of new markers. */static char *sccs_id = "@(#)xmarks.c 1.16 9/28/98 ERL/ATT";#include <esps/esps.h>#include <xview/cursor.h>#include <xview/cms.h>#include <xview/xview.h>#ifdef LINUX#include <xview/panel.h>#endif#include <esps/exview.h>#include <wave_colors.h>#include <w_lengths.h>#include <marker.h> #define SYNTAX USAGE("xmarks [-w wave_pro] [-n<waves or other host program>] [-c<registry name of host>] ");int debug_level = 0;int command_paused = 0;extern char ok[], null[]; /* in message.c */int use_dsp32, da_location = 0; /*referenced in globals.c*/double image_clip = 7.0, image_range = 40.0;Frame base_frame = XV_NULL;Frame daddy = XV_NULL;Panel panel = XV_NULL;Canvas labelsw = XV_NULL;Pixwin *labelpw;char *host = "waves", *thisprog = "xmarks";#if !defined(hpux) && !defined(DS3100) && !defined(DEC_ALPHA)char *malloc();#endifXv_Font fonts[3];char *font_styles[] = {FONT_STYLE_BOLD, FONT_STYLE_NORMAL, FONT_STYLE_BOLD};int font_sizes[] = {10, 24, 24};extern char *Version;/*char *font_names[] = { "/usr/lib/vfont/delegate.b.12", "/usr/lib/vfont/delegate.i.12", "/usr/lib/vfont/delegate.r.12" };*//*char *font_names[] = { "/usr/lib/fonts/fixedwidthfonts/cour.b.10", "/usr/lib/fonts/fixedwidthfonts/cour.r.24", "/usr/lib/fonts/fixedwidthfonts/cour.b.24" };*/Sentence *sentence=NULL;Marker *current_m = NULL;int insert_before = 1; /* insert where? 1=before 0=after */Rect *label_rect = NULL;FILE *infd = NULL; /* for reading in markers *//* Panel_setting read_font(), get_string(); */Marker *first_free_marker();void prompt_for_label();extern char *registry_name;/* Panel_item quit_item; */void quit_proc();Objects base_obj, file_obj; /* program object and file object */Notify_value iocatcher(); /* gets input while in window loop */static double sec_cm, start;static int width, height, loc_x, loc_y;static double m_time, rstart, rend;static char name[NAMELEN], file[NAMELEN], sigfile[NAMELEN];static int color;static Selector a9 = {"sec/cm", "%lf", (char*)&sec_cm, NULL}, a8 = {"start", "%lf", (char*)&start, &a9}, a7 = {"width", "%d", (char*)&width, &a8}, a6 = {"height", "%d", (char*)&height, &a7}, a5 = {"loc_y", "%d", (char*)&loc_y, &a6}, a4 = {"loc_x", "%d", (char*)&loc_x, &a5}, b1 = {"time", "%lf", (char*)&m_time, &a4}, b2 = {"name", "%s", name, &b1}, b3a = {"file", "%s", file, &b2}, b3b = {"signal", "%s", sigfile, &b2}, b3 = {"rstart", "%lf", (char*)&rstart, &b3b}, b4 = {"rend", "%lf", (char*)&rend, &b3};/* These are needed by the inter-process communications stuff. *//*********************************************************************/char *get_receiver_name(ob) Objects *ob;{ return(ob->name);}/*********************************************************************/char *get_methods(ob) Objects *ob;{ extern Methods base_methods, file_methods; if (ob)return((char *)(ob->methods)); return((char*)&base_methods);}/*********************************************************************/char *get_receiver(str) char *str;{ Objects *ob; static char name[NAMELEN]; extern Objects base_obj; ob = &base_obj; if (str && strlen(str)) { sscanf(str, "%s", name); while (ob) { if (ob->name && (! strcmp(ob->name, name))) { return((char*)ob); } ob = ob->next; } } return(NULL);}/*********************************************************************/init_object(o) Objects *o;{ if(o) { o->name[0] = 0; o->canvas = NULL; o->methods = NULL; o->next = NULL; o->pcanvas = NULL; o->x_off = 0; o->xloc = 0; o->yloc = SCREEN_HEIGHT; o->width = SCREEN_WIDTH; o->height = 100; o->color = 0; o->sec_cm = .02; o->start = 0.0; o->cursor = 0.0; o->time = 0.0; }}/*********************************************************************/char *generate_startup_command(registry_name) char *registry_name;{ static char com[MES_BUF_SIZE]; sprintf(com,"add_op name %s op #send function %s registry %s command _name mark signal _file time _cursor_time", basename(thisprog), thisprog, registry_name); return(com);}/*********************************************************************/extern int fullscreendebug; /* an xview global hack to prevent grabs *//*********************************************************************/main(ac, av) int ac; char **av;{ int i; extern Objects base_obj, file_obj; extern Methods base_methods; char mess[MES_BUF_SIZE]; extern char *optarg, *wave_pro; extern int attachment, /* Is this program an attachment? */ optind; extern Methods file_methods; int rem_args; /* no. of args after getopt processing */ int ch; /* option letter read by getopt */ char *server_name = "xwaves"; extern Display *X_Display; extern Window comm_window; init_object(&file_obj); fullscreendebug=1; /* this global inhibits some server grabs that cause problems on the SGI */ thisprog = av[0]; while ((ch = getopt(ac, av, "w:n:c:")) != EOF) switch (ch) { case 'n': host = optarg; break; case 'w': wave_pro = optarg; break; case 'c': server_name = optarg; break; default: SYNTAX if(debug_level) for(ch = 0; ch < ac; ch++) fprintf(stderr,"%s ",av[ch]); fprintf(stderr,"\n"); exit(-1); } xv_init(XV_INIT_ARGC_PTR_ARGV, &ac, av, 0); attachment = TRUE; get_globals(); get_color_depth(); setup_colormap();/* initialize fonts */ for (i = 0; i < 3 ; i++) { fonts[i] = (Xv_Font) xv_find(XV_NULL, FONT, FONT_FAMILY, FONT_FAMILY_DEFAULT_FIXEDWIDTH, FONT_STYLE, font_styles[i], FONT_SIZE, font_sizes[i], 0); if (fonts[i] == XV_NULL){ fprintf(stderr, "can't open font %d\n", i); kill_proc(); } }/* set up window stuff */ daddy = base_frame = xv_create(XV_NULL, FRAME, XV_X, 160, XV_Y, 0, XV_WIDTH, 980, FRAME_ARGS, ac, av, XV_LABEL, "marker", 0); /* set up communications with the host (xwaves) */ if (!setup_attach_comm(base_frame, server_name, "xmarks")) { fprintf(stderr, "Failed to setup ipc communications\n"); exit(0); } sprintf(mess, "Marker %s (%s)", Version, registry_name); xv_set(base_frame, XV_LABEL, mess, NULL); send_start_command(generate_startup_command(registry_name)); set_blowup_op(); create_panel_subwindow(); create_label_subwindow(); exv_attach_icon(base_frame, ERL_NOBORD_ICON, "xmarks", TRANSPARENT); window_fit(base_frame);/* set up object */ base_obj.next = &file_obj; file_obj.next = NULL; base_obj.canvas = file_obj.canvas = labelsw; base_obj.pcanvas = file_obj.pcanvas = NULL; base_obj.methods = &base_methods; file_obj.methods = &file_methods; strcpy(base_obj.name, av[0]); xv_main_loop(base_frame); exit(0);}/*********************************************************************/set_blowup_op(){ char mess[MES_BUF_SIZE]; sprintf(mess,"set blowup_op %s",basename(thisprog)); mess_write(mess);}/*********************************************************************/voidquit_proc(){ print_markers(sentence, stdout); cleanup(); kill_proc();}/*********************************************************************/kill_proc(){ char mess[MES_BUF_SIZE]; sprintf(mess,"%s disconnect function %s\n",host,thisprog); terminal_message(mess); terminate_communication(registry_name); exit(0);}/*********************************************************************/create_panel_subwindow(){ void quit_proc(), next_word_proc(), last_word_proc(), next_mark_proc(), last_mark_proc(), insert_where_proc(), change_label_proc(), insert_label_proc(), un_set_proc(), delete_proc(); panel = xv_create(base_frame, PANEL, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Quit", PANEL_NOTIFY_PROC, quit_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "NextWord", PANEL_NOTIFY_PROC, next_word_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "LastWord", PANEL_NOTIFY_PROC, last_word_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "NextMark", PANEL_NOTIFY_PROC, next_mark_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "LastMark", PANEL_NOTIFY_PROC, last_mark_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "ChangeMark", PANEL_NOTIFY_PROC, change_label_proc, 0); (void) xv_create(panel, PANEL_CYCLE, PANEL_DISPLAY_LEVEL, PANEL_CURRENT, PANEL_LABEL_STRING, "Where?", PANEL_CHOICE_STRINGS, "after", "before", 0, PANEL_VALUE, insert_before, PANEL_NOTIFY_PROC, insert_where_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "AddMark", PANEL_NOTIFY_PROC, insert_label_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "UnSet", PANEL_NOTIFY_PROC, un_set_proc, 0); (void) xv_create(panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Delete", PANEL_NOTIFY_PROC, delete_proc, 0); window_fit_height(panel);}/*********************************************************************/create_label_subwindow(){ labelsw = xv_create(base_frame, CANVAS, WIN_BELOW, panel, XV_HEIGHT, 120, 0); window_fit(labelsw); labelpw = canvas_pixwin(labelsw);}/*********************************************************************/voidnext_word_proc(){ Word *w; if(current_m && (w = current_m->word)) { if (w->right != NULL && w->right->first != NULL){ current_m = w->right->first; show_markers(&labelsw, sentence, current_m, fonts); } }}/*********************************************************************/voidlast_word_proc(){ Word *w; if(current_m && (w = current_m->word)) { if (w->left != NULL && w->left->first != NULL){ current_m = w->left->first; show_markers(&labelsw, sentence, current_m, fonts); } }}/*********************************************************************/voidnext_mark_proc(){ Marker *m; if(current_m && (m = current_m->right)) { current_m = m; show_markers(&labelsw, sentence, current_m, fonts); }}/*********************************************************************/voidlast_mark_proc(){ Marker *m; if(current_m && (m = current_m->left)) { current_m = m; show_markers(&labelsw, sentence, current_m, fonts); }}/*********************************************************************/voidinsert_where_proc(item) /* insert before or after? */ Panel_item item;{ insert_before = (int) xv_get(item, PANEL_VALUE);}/*********************************************************************/voidchange_label(p) char *p;{ (void) xv_get(fonts[1], FONT_STRING_DIMS, current_m->label, ¤t_m->bound); show_markers(&labelsw, sentence, current_m, fonts);}/*********************************************************************/voidchange_label_proc(item) /* change label of current marker */ Panel_item item;{ int x, y; Rect rect; frame_get_rect(base_frame, &rect); x = rect.r_left + 250; y = rect.r_top - 35; prompt_for_label(current_m, x, y, change_label);}/*********************************************************************/voidinsert_label(p) char *p;{ Marker *m = (Marker *) p; if (insert_before){ insert_marker(current_m->left, m, current_m); m->word = current_m->word; if (m->word->first==current_m) m->word->first=m; } else{ insert_marker(current_m, m, current_m->right); m->word = current_m->word; if (m->word->last==current_m) m->word->last=m; } (void) xv_get(fonts[1], FONT_STRING_DIMS, m->label, &m->bound); if (insert_before) current_m=m; show_markers(&labelsw, sentence, current_m, fonts);}/*********************************************************************/voidinsert_label_proc(item) /* insert a new marker label */ Panel_item item;{ Marker *m = get_marker(); int x, y; Rect rect; frame_get_rect(base_frame, &rect); x = rect.r_left + 250; y = rect.r_top - 35; if (m) prompt_for_label(m, x, y, insert_label);}/*********************************************************************/voidun_set_proc(){ sendtc(&file_obj, "unmark", current_m->time, MARKER_COLOR); current_m->time = -1.; replot(&file_obj);}/*********************************************************************/voiddelete_proc(){ Marker *delete_marker(); sendtc(&file_obj, "unmark", current_m->time, MARKER_COLOR); current_m = delete_marker(current_m); show_markers(&labelsw, sentence, current_m, fonts);}#define MY_SPACE 15/*********************************************************************/show_markers(sw, s, m, fonts) Canvas *sw; Sentence *s; Marker *m; Xv_Font *fonts;{ Rect *m_rect, n_rect; Pixwin *pw; register int xval, yval, sum, count, fval, total_width; register Word *current_w; register Marker *mptr, *start_mark; if (s == NULL) return; if (m == NULL) return; pw = canvas_pixwin(*sw); m_rect = (Rect *) xv_get(*sw, WIN_RECT, 0); n_rect = *m_rect; n_rect.r_top -= 30; n_rect.r_height += 30; erase(pw, &n_rect); xval = m_rect->r_width/2 - s->bound.width/2; if (xval < 0) xval = 0; yval = m_rect->r_top; pw_text(pw, xval, yval, PIX_SRC, fonts[0], s->text); current_w = m->word; xval = m_rect->r_width/2 - current_w->bound.width/2; yval += 30; pw_text(pw, xval, yval, PIX_SRC, fonts[1], current_w->spelling); sum = count = 0; for (mptr = current_w->first; mptr && mptr->left != current_w->last; mptr = mptr->right) { sum += mptr->bound.width; count++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -