📄 view_utils.c
字号:
/* * 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) 1993-1996 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: David Talkin * * view_utils.c * a collection of routines for manipulation of Views in "xwaves" */static char *sccs_id = "@(#)view_utils.c 1.24 8/12/98 ERL";#include <Objects.h>#include <spectrogram.h>#include <file_ext.h>#include <esps/esps.h>#include <esps/fea.h>#define WhiteSpace(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n')extern Object program;extern int debug_level;extern char time_range_prefix[], samp_range_prefix[];extern int c_range_offset; /* in globals.c */extern int s_range_offset;static Selector va11 = {"file", "%s", NULL, NULL}, va10 = {"name", "%s", NULL, &va11}, va9b = {"cursor_yval", "%lf", NULL, &va10}, va9 = {"cursor_time", "%lf", NULL, &va9b}, va8b = {"l_marker_time", "%lf", NULL, &va9}, va7b = {"r_marker_time", "%lf", NULL, &va8b}, va8 = {"t_marker_yval", "%lf", NULL, &va7b}, va7 = {"b_marker_yval", "%lf", NULL, &va8}, va6 = {"width", "%d", NULL, &va7}, va5 = {"height", "%d", NULL, &va6}, va4 = {"view_start_yval", "%lf", NULL, &va5}, va3 = {"view_end_yval", "%lf", NULL, &va4}, va2b = {"mark_reference", "#qstr", NULL, &va3}, va2a = {"find_crossing", "%d", NULL, &va2b}, va2 = {"cross_level", "%lf", NULL, &va2a}, va1 = {"view_start_time", "%lf", NULL, &va2};static char *view_get_overlays(), *view_get_is_iconized(), *view_get_cursor_samp(), *view_get_l_marker_samp(), *view_get_l_marker_samp_from_start(), *view_get_objects(), *view_get_r_marker_samp(), *view_get_win_x(), *view_get_loc_x(), *view_get_loc_y(), *view_get_sec_cm(), *view_get_val_cm(), *view_get_cursor_value(), *view_get_cursor_values(), *view_get_view_channels(), *view_get_view_end_time(), *view_get_range_samp(), *view_get_dur_samp(), *view_get_dur_time(), *view_get_f_value(), *view_get_range_time(), *view_get_range_yval(), *view_get_range_chan(), *view_get_cursor_channels(), *view_get_cursor_chan(), *view_get_cursor_label(), *view_get_bmarker_chan(), *view_get_tmarker_chan(), *view_get_operators(), *view_get_object_commands(), *view_get_waves_commands(), *view_get_settables(), *view_get_variables(), *view_get_files(), *view_get_new_files(), *view_get_cursor_element();static char *view_get_mark_range_time(), *view_get_mark_range_samp(), *view_get_r_mark_time(), *view_get_l_mark_time(), *view_get_r_mark_samp(), *view_get_l_mark_samp(), *view_get_cursor_labels();extern char *get_string_list();typedef struct activator { char *name; char *(*proc)(); struct activator *next;} Activator;static Activator vb14 = {"new_files", view_get_new_files, NULL}, vb13 = {"operators", view_get_operators, &vb14}, vb12g = {"objects", view_get_objects, &vb13}, vb12e = {"files", view_get_files, &vb12g}, vb12f = {"settables", view_get_settables, &vb12e}, vb12d = {"variables", view_get_variables, &vb12f}, vb12c = {"waves_commands", view_get_waves_commands, &vb12d}, vb12b = {"object_commands", view_get_object_commands, &vb12c}, vb12 = {"overlays", view_get_overlays, &vb12b}, vb11 = {"is_iconized", view_get_is_iconized, &vb12}, vb10 = {"cursor_samp", view_get_cursor_samp, &vb11}, vb9e = {"f_value", view_get_f_value, &vb10}, vb9d = {"dur_seconds", view_get_dur_time, &vb9e}, vb9c = {"dur_time", view_get_dur_time, &vb9d}, vb9b = {"dur_samp", view_get_dur_samp, &vb9c}, vb9 = {"l_marker_samp_from_start", view_get_l_marker_samp_from_start, &vb9b}, vb8c = {"lmsfs", view_get_l_marker_samp_from_start, &vb9}, vb8b = {"l_marker_samp", view_get_l_marker_samp, &vb8c}, vb8 = {"r_marker_samp", view_get_r_marker_samp, &vb8b}, vb7g = {"win_x", view_get_win_x, &vb8}, vb7f = {"l_mark_samp", view_get_l_mark_samp, &vb7g}, vb7e = {"r_mark_samp", view_get_r_mark_samp, &vb7f}, vb7d = {"l_mark_time", view_get_l_mark_time, &vb7e}, vb7c = {"r_mark_time", view_get_r_mark_time, &vb7d}, vb7b = {"mark_range_samp", view_get_mark_range_samp, &vb7c}, vb7a = {"mark_range_time", view_get_mark_range_time, &vb7b}, vb7 = {"loc_x", view_get_loc_x, &vb7a}, vb6 = {"loc_y", view_get_loc_y, &vb7}, vb5 = {"sec/cm", view_get_sec_cm, &vb6}, vb4 = {"val/cm", view_get_val_cm, &vb5}, vb3f= {"cursor_element", view_get_cursor_element, &vb4}, vb3e1 = {"cursor_label", view_get_cursor_label, &vb3f}, vb3e = {"cursor_labels", view_get_cursor_labels, &vb3e1}, vb3d = {"cursor_channel", view_get_cursor_chan, &vb3e}, vb3c = {"b_marker_chan", view_get_bmarker_chan, &vb3d}, vb3b = {"t_marker_chan", view_get_tmarker_chan, &vb3c}, vb3 = {"cursor_value", view_get_cursor_value, &vb3b}, vb2b = {"cursor_values", view_get_cursor_values, &vb3}, vb2 = {"cursor_channels", view_get_cursor_channels, &vb2b}, vb1e = {"range_yval", view_get_range_yval, &vb2}, vb1d = {"range_chan", view_get_range_chan, &vb1e}, vb1c = {"range_time", view_get_range_time, &vb1d}, vb1b = {"range_samp", view_get_range_samp, &vb1c}, vb1 = {"view_channels", view_get_view_channels, &vb1b}, vb0 = {"view_end_time", view_get_view_end_time, &vb1};/*************************************************************************/static double left_mark_time(s, tr) double tr; Signal *s;{ if(s) { Object *o; Marks *m; if((o = (Object*)(s->obj)) && (m = o->marks)) { if(m->time > tr) return(SIG_START_TIME(s)); while(m) { if((! m->next) || ((m->next->time > tr) && (m->time <= tr))) return(m->time); m = m->next; } } return(SIG_START_TIME(s)); } return(0.0);}/*************************************************************************/static double right_mark_time(s, tr) double tr; Signal *s;{ if(s) { Object *o; Marks *m; if((o = (Object*)(s->obj)) && (m = o->marks)) { if(m->time > tr) return(m->time); while(m && m->next) { if(((m->next->time > tr) && (m->time <= tr))) return(m->next->time); m = m->next; } } return(SIG_END_TIME(s)); } return(0.0);}/*************************************************************************/static double mark_time_reference(v) View *v;{ char *ap; if(v->mark_reference && (strlen(v->mark_reference) > 0) && strcmp("(null)", v->mark_reference) && (ap = view_get_value(v, v->mark_reference))) return(atof(ap)); else return(atof(view_get_value(v,"cursor_time")));}/*************************************************************************/static char *view_get_l_mark_time(v) View *v;{ static char rv[20]; if(v && v->sig) { sprintf(rv,"%.7f", left_mark_time(v->sig, mark_time_reference(v))); return(rv); } else return("");}/*************************************************************************/static char *view_get_mark_range_time(v) View *v;{ static char rv[40]; if(v && v->sig) { sprintf(rv,"%s%.7f:%.7f", time_range_prefix, left_mark_time(v->sig, mark_time_reference(v)), right_mark_time(v->sig, mark_time_reference(v))); return(rv); } else return("");}/*************************************************************************/static char *view_get_r_mark_time(v) View *v;{ static char rv[20]; if(v && v->sig) { sprintf(rv,"%.7f", right_mark_time(v->sig, mark_time_reference(v))); return(rv); } else return("");}/*************************************************************************/int time_to_sample(sig, time) Signal *sig; double time;{ if(sig) { if(IS_GENERIC(sig->type)) return(s_range_offset + (int)((time - sig->start_time) * sig->freq)); else { return(sig->start_samp + s_range_offset + time_to_index(sig,time)); } } else return(0);}/*************************************************************************/static char *view_get_mark_range_samp(v) View *v;{ static char rv[21]; if(v && v->sig) { sprintf(rv,"%s%d:%d", samp_range_prefix, time_to_sample(v->sig,left_mark_time(v->sig,mark_time_reference(v))), time_to_sample(v->sig,right_mark_time(v->sig,mark_time_reference(v)))); return(rv); } else return("");}/*************************************************************************/static char *view_get_dur_samp(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", (int)(0.5 + (v->sig->freq * (v->rmarker_time - v->lmarker_time)))); return(rv); } else return("");}/*************************************************************************/static char *view_get_f_value(v) View *v;{ static char rv[10]; double dur; if(v) { dur = v->rmarker_time - v->lmarker_time; if (dur > 0.0) sprintf(rv,"%8.2f", 1.0/(v->rmarker_time - v->lmarker_time)); else sprintf(rv,"--------"); return(rv); } else return("");}/*************************************************************************/static char *view_get_dur_time(v) View *v;{ static char rv[10]; if(v) { sprintf(rv,"%.7f", v->rmarker_time - v->lmarker_time); return(rv); } else return("");}/*************************************************************************/static char *view_get_r_mark_samp(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", time_to_sample(v->sig,right_mark_time(v->sig,mark_time_reference(v)))); return(rv); } else return("");}/*************************************************************************/static char *view_get_l_mark_samp(v) View *v;{ static char rv[10]; if(v && v->sig) { sprintf(rv,"%d", time_to_sample(v->sig,left_mark_time(v->sig,mark_time_reference(v)))); return(rv); } else return(""); }/*************************************************************************/char **view_get_variable_names(){ Activator *mo = &vb0; Selector *se = &va1; int no = 0; char **wopl = NULL, **sort_a_list(); while(mo) { if(mo->name && *mo->name && mo->proc) no++; mo = mo->next; } while(se) { if(se->name && *se->name) no++; se = se->next; } if(no) { wopl = (char**) malloc(sizeof(char**) * (no+1)); no = 0; mo = &vb0; while(mo) { if(mo->name && mo->name[0] && mo->proc) wopl[no++] = mo->name; mo = mo->next; } se = &va1; while(se) { if(se->name && se->name[0]) wopl[no++] = se->name; se = se->next; } wopl[no] = NULL; } return(sort_a_list(wopl));}/*************************************************************************/static Selector *view_setup_access(v) register View *v;{ if(v) { if(v->sig) { va11.dest = v->sig->name; va10.dest = ((Object*)v->sig->obj)->name; } else { va11.dest = NULL; va10.dest = NULL; } va2b.dest = v->mark_reference; va2a.dest = (char*)&(v->find_crossing); va2.dest = (char*)&(v->cross_level); va9.dest = (char*)&(v->cursor_time); va9b.dest = (char*)&(v->cursor_yval); va8b.dest = (char*)&(v->lmarker_time); va7b.dest = (char*)&(v->rmarker_time); va8.dest = (char*)&(v->tmarker_yval); va7.dest = (char*)&(v->bmarker_yval); va6.dest = (char*)&(v->width); va5.dest = (char*)&(v->height); va4.dest = (char*)&(v->start_yval); va3.dest = (char*)&(v->end_yval); va1.dest = (char*)&(v->start_time); return(&va1); } else return(NULL);}/**************************************************************/char **object_get_files(o) Object *o;{ Signal *s, *mo; if(o && (mo = s = o->signals)) { int no = 0; char **wopl = NULL, **sort_a_list(); while(mo) { if(mo->views) no++; mo = mo->others; } if(no) { wopl = (char**) malloc(sizeof(char**) * (no+1)); no = 0; while(s) { if(s->views) wopl[no++] = s->name; s = s->others; } wopl[no] = NULL; } return(sort_a_list(wopl)); } return(NULL);}/*************************************************************************/static char *view_get_files(v, str) View *v; char *str;{ extern char *pack_up_list_items(); if(v && v->sig && v->sig->obj) return(pack_up_list_items(object_get_files(v->sig->obj))); else return("");} /*************************************************************************/static char *view_get_settables(v, str) View *v; char *str;{ return(get_string_list("settables"));} /*************************************************************************/static char *view_get_objects(v, str) View *v; char *str;{ char *cp; if((cp = get_string_list("objects"))) return(cp); else return("");} /*************************************************************************/static char *view_get_variables(v, str) View *v; char *str;{ return(get_string_list("variables"));} /*************************************************************************/static char *view_get_operators(v, str) View *v; char *str;{ return(get_string_list("view"));} /*************************************************************************/static char *view_get_new_files(v, str) View *v; char *str;{ return(get_string_list("new_files"));} /*************************************************************************/static char *view_get_object_commands(v, str) View *v; char *str;{ return(get_string_list("object"));} /*************************************************************************/static char *view_get_waves_commands(v, str) View *v; char *str;{ return(get_string_list("waves"));} /*************************************************************************/Event *view_state_to_event(v) View *v;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -