📄 hslab.c
字号:
/* DoEditLabel: change the label string */Boolean DoEditLabel(void){ HTime t; LLink p; LabId labid; char sbuf[LAB_BUF_LEN], *prompt = "New label: "; if (llist==NULL) return FALSE; PrintMsg(&io_Win, "Select label to edit..."); if (!GetWavePtrPos()){ PrintMsg(&io_Win, "Edit label aborted."); return FALSE; } t = Point2Sample(&waveWin, thisWpos); if ((p = GetLabT(llist, (long) t))==NULL){ PrintMsg(&io_Win, "Selected frame not labelled"); return FALSE; } labid = p->labid; strcpy(sbuf, prompt); strcat(sbuf, labid->name); if (!GetString(&io_Win, sbuf, strlen(prompt), MAX_LAB_LEN)){ PrintMsg(&io_Win, "Edit label aborted."); return FALSE; } RecordOp(CHANGE_OP, p); p->labid = GetLabId(sbuf + strlen(prompt), TRUE); PlotLabWin(); PrintMsg(&io_Win, NULL); labsModified = TRUE; return TRUE;}/* DoSelectlabel: use the boundaries of a chosen label to create a marked region */Boolean DoSelectLabel(void){ LLink p; HTime t, st, en; if (llist==NULL) return FALSE; PrintMsg(&io_Win, "Choose label to select as marked region..."); if (!GetWavePtrPos()){ PrintMsg(&io_Win, "Select label aborted."); return FALSE; } t = Point2Sample(&waveWin, thisWpos); if ((p = GetLabT(llist, (long) t))==NULL){ PrintMsg(&io_Win, "Selected frame not labelled."); return FALSE; } /* unmark any marked regions */ if (regnMarked) InvertRegion(&waveWin, markA, markB); st = p->start; if (st < sStart) st = sStart; en = p->end; if (en >= sEnd) en = sEnd - 1; markA = (int) (waveWin.x + (st - sStart)/samplesPt); markB = (int) (waveWin.x + (en - sStart)/samplesPt); InvertRegion(&waveWin, markA, markB); PrintMsg(&io_Win, NULL); return TRUE;}/* DoLabel: label a marked region or the waveform visible on the screen */Boolean DoLabel(Boolean useLabStr){ HTime st, en; char sbuf[LAB_BUF_LEN], *prompt = "Lab name: "; LabId labid; strcpy(sbuf, prompt); if (regnMarked) { /* if region marked already then use markA and markB */ st = Point2Sample(&waveWin, markA); en = Point2Sample(&waveWin, markB); } else { st = sStart; en = sEnd - 1; } if (MaxTimesLabelled(llist, (long) st, (long) en)==TIMES_LABELLED){ PrintMsg(&io_Win, "Area contains frames already labelled twice."); return FALSE; } if (useLabStr) labid = GetLabId(labstr, TRUE); else { if (!GetString(&io_Win, sbuf, strlen(prompt), MAX_LAB_LEN)){ PrintMsg(&io_Win, "Labelling aborted."); return FALSE; } labid = GetLabId(sbuf + strlen(prompt), TRUE); } RecordOp(CREATE_OP, CreateLabObj(llist, labid, (long) st, (long) en)); PlotLabWin(); labsModified = TRUE; if (incLab) IncLabStr(); return TRUE;}/* DoAdjustLabel: adjust the boundary of a selected label */Boolean DoAdjustLabel(void){ LLink p; Label q, qq; Boolean isStart; HTime t, nt, *bp; char sbuf[SLEN]; if (llist==NULL) return FALSE; PrintMsg(&io_Win, "Select boundary to adjust..."); if (!GetWavePtrPos()){ PrintMsg(&io_Win, "Adjust boundary aborted"); return FALSE; } t = Point2Sample(&waveWin, thisWpos); if ((p = GetLabDistance(llist, (long) t, sStart, sEnd, &isStart))==NULL){ PrintMsg(&io_Win, "Selected frame not labelled or boundary not on-screen."); return FALSE; } q = qq = *p; strcpy(sbuf, "Select new boundary position for ["); strcat(sbuf, q.labid->name); if (isStart){ bp = &(q.start); strcat(sbuf, " : start]"); } else { bp = &(q.end); strcat(sbuf, " : end]"); } /* get the new boundary position */ PrintMsg(&io_Win, sbuf); if (!GetWavePtrPos()){ PrintMsg(&io_Win, "Adjust boundary aborted"); return FALSE; } nt = Point2Sample(&waveWin, thisWpos); if (nt >= T) nt = T-1; if (nt < 0) nt = 0; *bp = nt; if (MaxTimesLabelled(llist, sStart, sEnd) > TIMES_LABELLED){ PrintMsg(&io_Win, "Boundary change will make some frames labelled more than twice."); *p = qq; return FALSE; } RecordOp(CHANGE_OP, p); *p = q; PlotLabWin(); PrintMsg(&io_Win, NULL); labsModified = TRUE; return TRUE;}/* DoAbout: display information about author, version, etc. */void DoAbout(void){ int width = MAX_GREYS; PrintMsg(&io_Win, HSLAB_INFO); PlotGStripes(io_Win.x + io_Win.w - width, io_Win.y + 1, width, io_Win.h - 1);}/* DoSave: save the changes into a HTK-format label file */void DoSave(void){ char sbuf[SLEN], fnbuf[SLEN], *prompt = "Save label file: "; LabList *ll; LLink p; if (!labsModified){ PrintMsg(&io_Win, "No changes need to be saved."); return; } for (ll=trans->head; ll!=NULL; ll=ll->next) if (CountLabs(ll)!=0) break; if (ll==NULL) { PrintMsg(&io_Win, "No labels found."); return; } strcpy(sbuf, prompt); strcat(sbuf, labfn); if (!GetString(&io_Win, sbuf, strlen(prompt), MAX_LAB_LEN)){ PrintMsg(&io_Win, "Save file aborted."); return; } strcpy(fnbuf, sbuf + strlen(prompt)); if (!FileExists(fnbuf, "w")){ PrintMsg(&io_Win, "File I/O error."); return; } strcpy(labfn, fnbuf); for (ll=trans->head; ll!=NULL; ll=ll->next) for (p=ll->head->succ; p->succ!=NULL; p=p->succ) { p->start *= sampPeriod; p->end *= sampPeriod; } if(LSave(labfn, trans, ofmt)<SUCCESS) HError(1514, "DoSave: Could not save label file %s", labfn); PrintMsg(&io_Win, "Label file saved."); labsModified = FALSE; PlotFileWin();}/* CheckForSave: check to see if changes have to be saved */void CheckForSave(void){ char sbuf[255], *prompt = "Save label file (Y/N): ", c; Boolean is0; if (!labsModified) return; do { strcpy(sbuf, prompt); do is0 = !GetString(&io_Win, sbuf, strlen(prompt), MAX_LAB_LEN); while (is0); c = sbuf[strlen(prompt)]; } while ((c!='y') && (c!='Y') && (c!='n') && (c!='N')); if ((c=='y') || (c=='Y')) DoSave();} /* DoLoad: load a new waveform/label files */Boolean DoLoad(void){ char sbuf[SLEN], fnbuf[SLEN], *prompt = "Load waveform file: "; CheckForSave(); strcpy(sbuf, prompt); if (NextArg()==STRINGARG) strcat(sbuf, GetStrArg()); else strcat(sbuf, "st"); if (!GetString(&io_Win, sbuf, strlen(prompt), MAX_LAB_LEN)){ PrintMsg(&io_Win, "Load file aborted."); return FALSE; } strcpy(fnbuf, sbuf + strlen(prompt)); if (!FileExists(fnbuf, "r")){ PrintMsg(&io_Win, "File not found."); return FALSE; } strcpy(spfn, fnbuf); LoadFiles(); hRedrawWindow(); return TRUE;}/* PlayLabel: play region for clicked on label */void PlayLabel(int x){ HTime t; LLink p; t = Point2Sample(&waveWin, x); if ((p = GetLabT(llist, (long) t))==NULL) return; Playback(wave, (long) p->start, (long) p->end, playVol, (int) scValues[scIndex], &newData);}/* ------------------------- Initialisation ------------------------------- *//* CreateButtons: create and initialise all buttons */void CreateButtons(void){ int btn_area_w; int btn_area_h; int btn_area_x; int btn_area_y; int x, y, w; char cmdstr[256]; HButton *btn; btn_area_w = (int) (WIDTH *BTN_AREA_W); btn_area_h = (int) (HEIGHT*BTN_AREA_H); btn_area_x = (int) (0.0 + (float) WIDTH *BTN_AREA_X); btn_area_y = (int) (0.0 + (float) HEIGHT*BTN_AREA_Y); btn_w = (int) ((float) btn_area_w/(BTN_PER_ROW + (BTN_PER_ROW + 1.0)*BTN_H_SPC)); btn_h = (int) ((float) btn_area_h/(BTN_PER_COL + (BTN_PER_COL + 1.0)*BTN_V_SPC)); btn_h_spc = (int) (btn_w*BTN_H_SPC); btn_v_spc = (int) (btn_h*BTN_V_SPC); x = btn_area_x + btn_h_spc; y = btn_area_y + btn_v_spc; btnList = CreateHButton(NULL,BT_LOAD,x,y,btn_w,btn_h,"Load",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_SAVE,x,y,btn_w,btn_h,"Save",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_ABOUT,x,y,btn_w,btn_h,"About",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_QUIT,x,y,btn_w,btn_h,"Quit",BLACK,LIGHT_GREY,NULL); x += 3*(btn_w + btn_h_spc); w = 2*btn_w + btn_h_spc; spcl_btn=CreateHButton(btnList,BT_SPCL,x,y,w,btn_h,spcl_str,BLACK,LIGHT_GREY,NULL); if (!CommandSet(HSLabCmd, cmdstr)) spcl_btn->active = FALSE; x += w + btn_h_spc; vol_btn = CreateHButton(btnList,BT_PLAY_VOL,x,y,btn_w,btn_h,volStr,BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; scale_btn = CreateHButton(btnList,BT_SCALE,x,y,btn_w,btn_h,scString[scIndex],BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; /* start the second row of buttons */ x = btn_area_x + btn_h_spc; y += btn_h + btn_v_spc; CreateHButton(btnList,BT_MARK,x,y,btn_w,btn_h,"Mark",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_UNMARK,x,y,btn_w,btn_h,"Unmark",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_SCRLL,x,y,btn_w,btn_h,"<--",BLACK,LIGHT_GREY,DoScrollLeft); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_SCRLR,x,y,btn_w,btn_h,"-->",BLACK,LIGHT_GREY,DoScrollRight); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_ZOOM_IN,x,y,btn_w,btn_h,"Z.In",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_ZOOM_OUT,x,y,btn_w,btn_h,"Z.Out",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_RESTORE,x,y,btn_w,btn_h,"Restore",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_PLAY,x,y,btn_w,btn_h,"play",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_REC,x,y,btn_w,btn_h,"rec",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; btn = CreateHButton(btnList,BT_PAUSE,x,y,btn_w,btn_h,"pause",BLACK,LIGHT_GREY,NULL); btn->active = FALSE; /* start the third row of buttons - labelling functions */ x = btn_area_x + btn_h_spc; y += btn_h + btn_v_spc; CreateHButton(btnList,BT_LABEL,x,y,btn_w,btn_h,"Label",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_LABELAS,x,y,btn_w,btn_h,"Labelas",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_LDELETE,x,y,btn_w,btn_h,"Delete",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_LEDIT,x,y,btn_w,btn_h,"Edit",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_LSELECT,x,y,btn_w,btn_h,"Select",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_ADJUST,x,y,btn_w,btn_h,"Adjust",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; lev_btn = CreateHButton(btnList,BT_LABSET,x,y,btn_w,btn_h,levStr,BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_NEWSET,x,y,btn_w,btn_h,"New",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; CreateHButton(btnList,BT_UNDO,x,y,btn_w,btn_h,"Undo",BLACK,LIGHT_GREY,NULL); x += btn_w + btn_h_spc; w = 3*btn_w + 2*btn_h_spc; labstr_btn = CreateHButton(btnList,BT_LABSTR,x,y,btn_w,btn_h,labstr,BLACK,LIGHT_GREY,NULL);}/* CreateSubWindows: Create the various sub-windows */void CreateSubWindows(void){ CreateButtons(); InitRectWin(&fileWin, 0.01, 0.01, 0.98, 0.05, 1, BLACK, WHITE); InitRectWin(&waveWin, 0.01, 0.06, 0.98, 0.50, 1, BLACK, WHITE); InitRectWin(&labWin1, 0.01, 0.56, 0.98, 0.10, 1, BLACK, LIGHT_GREY); InitRectWin(&io_Win, 0.01, 0.68, 0.98, 0.05, 1, BLACK, LIGHT_GREY);}/* SetConfParms: set conf parms relevant to HSLab */void SetConfParms(void){ int i; nParm = GetConfig("HSLAB", TRUE, cParm, MAXGLOBS); if (nParm>0) { if (GetConfInt(cParm,nParm,"TRACE",&i)) trace = i; }}/* Initialise: initialise everything */void Initialise(void){ SetConfParms(); CreateHeap(&tmpStack, "tmpStack", MSTAK, 1, 1.2, 512, 4096); CreateHeap(&wavStack, "wavStack", MSTAK, 1, 1.2, 512, 4096); CreateHeap(&tmpCHeap, "tmpCHeap", CHEAP, 1, 0.0, 0, 0); CreateHeap(&labStack, "labStack", MSTAK, 1, 1.2, 4096, 8192); CreateHeap(&audStack, "audStack", MSTAK, 1, 4, REC_BUF_SIZE, LONG_MAX); MakeXGraf(WINNAME, INIT_XPOS, INIT_YPOS, WIDTH, HEIGHT, 4); /* init volume setting */ playVol = (VOLUME_STEPS*2 / 3); sprintf(volStr, "Vol %d", playVol); /* set alternative transcription */ labSet = 0; FIXLABSTR; CreateSubWindows(); plotBuf = (int *) New(&tmpCHeap, 2*waveWin.w*sizeof(int));}/* -------------------- Main command loop -------------------- *//* DecodeCommands: decode the button commands */void DecodeCommands(void){ HEventRec hev; BtnId btn_id; WinKind wkind; do { hev = HGetEvent(FALSE, NULL); switch (hev.event) { case HMOUSEDOWN : wkind = GetWinKind(hev); PrintMsg(&io_Win, NULL); switch (wkind) { case WAVE_WIN: MouseMark(hev.x, &markA, &markB); break; case LAB_WIN: PlayLabel(hev.x); break; case IO_WIN: break; default: btn_id = (BtnId) TrackButtons(btnList, hev); switch(btn_id) { case BT_ZOOM_IN : DoZoomIn(); break; case BT_ZOOM_OUT : DoZoomOut(); break; case BT_RESTORE : DoRestore(); break; case BT_SCRLL : DoScrollLeft(); break; case BT_SCRLR : DoScrollRight();break; case BT_PLAY : DoPlay(); break; case BT_REC : DoRecord(data); break; case BT_PLAY_VOL : DoIncVolume(); break; case BT_SCALE : DoIncScale(); break; case BT_MARK : DoMark(&markA, &markB); break; case BT_UNMARK : DoUnMark(markA, markB); break; case BT_LABSTR : DoChangeLabStr(); break; case BT_LDELETE : DoDelLab(); break; case BT_LEDIT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -