void MAGNITUDEOBJ::load(HANDLE hFile) { char sztemp[30]; char szorder[5]; load_object_basics(this); load_property("type",P_INT,&filtertype); load_property("order",P_INT,&order); load_property("center",P_FLOAT,¢er); load_property("width",P_FLOAT,&wid); load_property("gain",P_INT,&gain); strcpy(sztemp,PASSTYPE[filtertype].init); sprintf(szorder,"%d",order); strcat(sztemp,szorder); if (lp1fbuf!=NULL) fid_run_freebuf(lp1fbuf); if (lp1filt!=NULL) fid_run_free(lp1filt); if (lp2fbuf!=NULL) fid_run_freebuf(lp2fbuf); if (lp2filt!=NULL) fid_run_free(lp2filt); lp1filt= fid_design(sztemp, PACKETSPERSECOND, (double)wid, 0, 0, 0); lp1run= fid_run_new(lp1filt, &(lp1funcp)); lp1fbuf=fid_run_newbuf(lp1run); lp2filt= fid_design(sztemp, PACKETSPERSECOND,(double)wid, 0, 0, 0); lp2run= fid_run_new(lp2filt, &(lp2funcp)); lp2fbuf=fid_run_newbuf(lp2run); }
FidlibFilter(const char *spec, int f0, int f1) { filt = fid_design((char*)spec, f0, f1, 0,0,0); run = fid_run_new(filt, &funcp); fbuf = fid_run_newbuf(run); }
MAGNITUDEOBJ::MAGNITUDEOBJ(int num) : BASE_CL() { outports = 1; inports = 1; width=65; strcpy(in_ports[0].in_name,"in"); strcpy(out_ports[0].out_name,"out"); out_ports[0].get_range=-1; out_ports[0].out_min=0; out_ports[0].out_max=100; strcpy(out_ports[0].out_dim,"uV"); lp1filt= fid_design("LpBu4", PACKETSPERSECOND, 2, 0, 0, 0); lp1run= fid_run_new(lp1filt, &(lp1funcp)); lp1fbuf=fid_run_newbuf(lp1run); lp2filt= fid_design("LpBu4", PACKETSPERSECOND, 2, 0, 0, 0); lp2run= fid_run_new(lp2filt, &(lp2funcp)); lp2fbuf=fid_run_newbuf(lp2run); filtertype=1; order=4; gain=100; center=10.0f; wid=2.0f; }
FILTEROBJ::FILTEROBJ(int num) : BASE_CL() { outports = 1; inports = 1; strcpy(in_ports[0].in_name,"in"); strcpy(out_ports[0].out_name,"out"); filtertype=3; par0=8; par1=8; par2=12; dispfrom=4; dispto=15; filt= fid_design("BpBe8", PACKETSPERSECOND, 8, 12, 0, 0); run= fid_run_new(filt, &(funcp)); fbuf=fid_run_newbuf(run); strcpy(name,"Alpha Bessel"); }
void FILTEROBJ::load(HANDLE hFile) { char sztemp[30]; char szorder[5]; load_object_basics(this); load_property("name",P_STRING,name); load_property("type",P_INT,&filtertype); load_property("order",P_INT,&par0); load_property("display-from",P_INT,&dispfrom); load_property("display-to",P_INT,&dispto); load_property("par1",P_FLOAT,&par1); load_property("par2",P_FLOAT,&par2); if (fbuf!=NULL) fid_run_freebuf(fbuf); if (filt!=NULL) fid_run_free(filt); strcpy(sztemp,FILTERTYPE[filtertype].init); wsprintf(szorder,"%d",par0); strcat(sztemp,szorder); filt=fid_design(sztemp, PACKETSPERSECOND, par1, par2, 0, 0); run= fid_run_new(filt, &(funcp)); fbuf=fid_run_newbuf(run); }
EngineFilter::EngineFilter(char * conf, int predefinedType) : iir(0), fir(0), tmp(0), ff(NULL), funcp(NULL), run(NULL) { switch(predefinedType) { case PREDEF_BP: processSample = &processSampleBp; fbuf1 = buf1; fbuf2 = buf2; break; case PREDEF_HP: processSample = &processSampleHp; fbuf1 = buf1; fbuf2 = buf2; break; case PREDEF_LP: processSample = &processSampleLp; fbuf1 = buf1; fbuf2 = buf2; break; default: ff = fid_design(conf, 44100., -1., -1., 1, NULL); qDebug() << "Filter " << conf << " Setup: 0x" << ff; run = fid_run_new(ff, &funcp); fbuf1 = fid_run_newbuf(run); fbuf2 = fid_run_newbuf(run); processSample = funcp; } int i; for(i=0; i < FILTER_BUF_SIZE; i++) buf1[i] = buf2[i] = 0; }
LRESULT CALLBACK MagnitudeDlgHandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { int t; // ,z; static int tempfilt=0,acttype=0; static int dinit=FALSE; char sztemp[30]; MAGNITUDEOBJ * st; st = (MAGNITUDEOBJ *) actobject; if ((st==NULL)||(st->type!=OB_MAGNITUDE)) return(FALSE); switch( message ) { case WM_INITDIALOG: { SCROLLINFO lpsi; SendMessage(GetDlgItem(hDlg, IDC_PASSTYPECOMBO), CB_RESETCONTENT,0,0); for (t = 0; t < PASSTYPES; t++) SendMessage( GetDlgItem(hDlg, IDC_PASSTYPECOMBO), CB_ADDSTRING, 0, (LPARAM) (LPSTR) PASSTYPE[t].tname) ; SetDlgItemText(hDlg,IDC_PASSTYPECOMBO, PASSTYPE[st->filtertype].tname); acttype=st->filtertype; SetDlgItemInt(hDlg,IDC_ORDER, st->order,0); SetDlgItemInt(hDlg,IDC_GAIN, st->gain,0); lpsi.cbSize=sizeof(SCROLLINFO); lpsi.fMask=SIF_RANGE|SIF_POS; lpsi.nMin=1; lpsi.nMax=1280; SetScrollInfo(GetDlgItem(hDlg,IDC_CENTERBAR),SB_CTL,&lpsi,TRUE); lpsi.nMin=1; lpsi.nMax=200; SetScrollInfo(GetDlgItem(hDlg,IDC_WIDTHBAR),SB_CTL,&lpsi,TRUE); SetScrollPos(GetDlgItem(hDlg,IDC_CENTERBAR), SB_CTL,(int)(st->center*10.0f),TRUE); sprintf(sztemp,"%.4f",st->center); SetDlgItemText(hDlg,IDC_CENTER, sztemp); SetScrollPos(GetDlgItem(hDlg,IDC_WIDTHBAR), SB_CTL,(int)(st->wid*10.0f),TRUE); sprintf(sztemp,"%.4f",st->wid); SetDlgItemText(hDlg,IDC_WIDTH, sztemp); } return TRUE; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); return TRUE; break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_PASSTYPECOMBO: acttype=SendMessage( GetDlgItem(hDlg, IDC_PASSTYPECOMBO), CB_GETCURSEL, 0, 0 ) ; break; case IDC_CENTER: if (HIWORD(wParam) == EN_KILLFOCUS) { GetDlgItemText(hDlg, IDC_CENTER, sztemp, 20); st->center = (float)atof(sztemp); if (st->center<0) { st->center=0; SetDlgItemText(hDlg,IDC_CENTER,"0");} if (st->center>PACKETSPERSECOND/2) { st->center=(float)(PACKETSPERSECOND/2); SetDlgItemInt(hDlg,IDC_CENTER,PACKETSPERSECOND/2,0);} // SendMessage (hDlg,WM_COMMAND,IDC_STORE,0); } break; case IDC_WIDTH: if (HIWORD(wParam) == EN_KILLFOCUS) { GetDlgItemText(hDlg, IDC_WIDTH, sztemp, 20); st->wid = (float)atof(sztemp); if (st->wid<0.0001) { st->wid=1; SetDlgItemText(hDlg,IDC_CENTER,"0.0001");} if (st->wid>PACKETSPERSECOND/2) { st->wid=(float)(PACKETSPERSECOND/2); SetDlgItemInt(hDlg,IDC_WIDTH,PACKETSPERSECOND/2,0);} // SendMessage (hDlg,WM_COMMAND,IDC_STORE,0); } break; case IDC_STORE: { char sztemp[30]; char szorder[5]; int test; test=GetDlgItemInt(hDlg,IDC_ORDER, NULL, 0); if ((test<1)||((test>10)&&(acttype==0))||((test>60)&&(acttype==1))) { SetDlgItemInt(hDlg,IDC_ORDER,st->order,0); return(TRUE); } st->filtertype=acttype; st->order=test; st->gain=GetDlgItemInt(hDlg,IDC_GAIN, NULL, 0); strcpy(sztemp,PASSTYPE[st->filtertype].init); GetDlgItemText(hDlg, IDC_ORDER, szorder, sizeof(szorder)); strcat(sztemp,szorder); st->lp1filt= fid_design(sztemp, PACKETSPERSECOND, (double)st->wid, 0, 0, 0); st->lp1run= fid_run_new(st->lp1filt, &(st->lp1funcp)); if (st->lp1fbuf!=NULL) { fid_run_freebuf(st->lp1fbuf); st->lp1fbuf=fid_run_newbuf(st->lp1run); } st->lp2filt= fid_design(sztemp, PACKETSPERSECOND,(double)st->wid, 0, 0, 0); st->lp2run= fid_run_new(st->lp2filt, &(st->lp2funcp)); if (st->lp2fbuf!=NULL) { fid_run_freebuf(st->lp2fbuf); st->lp2fbuf=fid_run_newbuf(st->lp2run); } return TRUE; } break; } return (TRUE); case WM_HSCROLL: { int nNewPos; if((nNewPos=get_scrollpos(wParam,lParam))>=0) { if (lParam == (long) GetDlgItem(hDlg,IDC_CENTERBAR)) { st->center=(float)nNewPos/10.0f; sprintf(sztemp,"%.2f",st->center); SetDlgItemText(hDlg, IDC_CENTER,sztemp); } if (lParam == (long) GetDlgItem(hDlg,IDC_WIDTHBAR)) { st->wid=(float)nNewPos/10.0f; sprintf(sztemp,"%.2f",st->wid); SetDlgItemText(hDlg, IDC_WIDTH,sztemp); } } } break; case WM_SIZE: case WM_MOVE: update_toolbox_position(hDlg); break; return(TRUE); } return FALSE; }
void update_samplingrate(int newrate) { int t,error=0; char sztemp[30],szorder[5]; for (t=0;t<GLOBAL.objects;t++) switch (objects[t]->type) { case OB_FILTER: { FILTEROBJ * st = (FILTEROBJ *) objects[t]; if (st->par1>newrate/2) { error=1; break;} if ((FILTERTYPE[st->filtertype].param==2) && (st->par2>newrate/2)) { error=1; break;} } break; case OB_MAGNITUDE: { MAGNITUDEOBJ * st = (MAGNITUDEOBJ *) objects[t]; if ((st->wid>newrate/2) ||(st->center>newrate/2)) { error=1; break;} } break; case OB_EEG: { switch (TTY.devicetype) { case DEV_IBVA: if (TTY.COMDEV!=INVALID_HANDLE_VALUE) { char str[15]; wsprintf(str,"SR %d\r",TTY.samplingrate); write_string_to_comport(str); } break; case DEV_MONOLITHEEG_P21: update_p21state(); break; } } break; } if (error) {report_error ("Cannot change Sampling Rate, please check corner frequencies of filter- or magnitude elements"); return;} PACKETSPERSECOND=newrate; for (t=0;t<GLOBAL.objects;t++) switch (objects[t]->type) { case OB_FILTER: { FILTEROBJ * st = (FILTEROBJ *) objects[t]; if (st->fbuf!=NULL) fid_run_freebuf(st->fbuf); if (st->filt!=NULL) fid_run_free(st->filt); strcpy(sztemp,FILTERTYPE[st->filtertype].init); wsprintf(szorder,"%d",st->par0); strcat(sztemp,szorder); st->filt=fid_design(sztemp, PACKETSPERSECOND, st->par1, st->par2, 0, 0); st->run= fid_run_new(st->filt, &(st->funcp)); st->fbuf=fid_run_newbuf(st->run); } break; case OB_MAGNITUDE: { MAGNITUDEOBJ * st = (MAGNITUDEOBJ *) objects[t]; strcpy(sztemp,PASSTYPE[st->filtertype].init); sprintf(szorder,"%d",st->order); strcat(sztemp,szorder); if (st->lp1fbuf!=NULL) fid_run_freebuf(st->lp1fbuf); if (st->lp1filt!=NULL) fid_run_free(st->lp1filt); if (st->lp2fbuf!=NULL) fid_run_freebuf(st->lp2fbuf); if (st->lp2filt!=NULL) fid_run_free(st->lp2filt); st->lp1filt= fid_design(sztemp, PACKETSPERSECOND, (double)st->wid, 0, 0, 0); st->lp1run= fid_run_new(st->lp1filt, &(st->lp1funcp)); st->lp1fbuf=fid_run_newbuf(st->lp1run); st->lp2filt= fid_design(sztemp, PACKETSPERSECOND,(double)st->wid, 0, 0, 0); st->lp2run= fid_run_new(st->lp2filt, &(st->lp2funcp)); st->lp2fbuf=fid_run_newbuf(st->lp2run); } } init_system_time(); get_session_length(); }
void UI_LoadMontagewindow::LoadButtonClicked() { int i, k, n, p, tmp, skip, found, signalcomps_read=0, signals_read, signal_cnt, filters_read, filter_cnt=0, ravg_filter_cnt=0, fidfilter_cnt=0, len, order=1, type=0, model=0, size=0, amp_cat[3], f_ruler_cnt=0; char *result, scratchpad[2048], str[128], *err, *filter_spec, spec_str[256]; double frequency=1.0, frequency2=2.0, ripple=1.0; struct xml_handle *xml_hdl; struct signalcompblock *newsignalcomp; if(mainwindow->files_open==1) n = 0; else n = filelist->currentRow(); if(mtg_path[0]==0) { strcpy(mtg_path, QFileDialog::getOpenFileName(0, "Load montage", QString::fromLocal8Bit(mainwindow->recent_montagedir), "Montage files (*.mtg *.MTG)").toLocal8Bit().data()); if(!strcmp(mtg_path, "")) { return; } get_directory_from_path(mainwindow->recent_montagedir, mtg_path, MAX_PATH_LENGTH); } xml_hdl = xml_get_handle(mtg_path); if(xml_hdl==NULL) { sprintf(scratchpad, "Can not open montage file:\n%s", mtg_path); QMessageBox messagewindow(QMessageBox::Critical, "Error", QString::fromLocal8Bit(scratchpad)); messagewindow.exec(); mainwindow->remove_recent_file_mtg_path(mtg_path); return; } if(strcmp(xml_hdl->elementname, PROGRAM_NAME "_montage")) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); xml_close(xml_hdl); return; } //////////////////////////////////////////// for(k=0; k<mainwindow->signalcomps; ) { if(mainwindow->signalcomp[k]->filenum==n) { if(mainwindow->spectrumdock->signalcomp == mainwindow->signalcomp[k]) { mainwindow->spectrumdock->clear(); mainwindow->spectrumdock->dock->hide(); } for(i=0; i<MAXSPECTRUMDIALOGS; i++) { p = mainwindow->signalcomp[k]->spectr_dialog[i]; if(p != 0) { delete mainwindow->spectrumdialog[p - 1]; mainwindow->spectrumdialog[p - 1] = NULL; } } for(i=0; i<MAXAVERAGECURVEDIALOGS; i++) { p = mainwindow->signalcomp[k]->avg_dialog[i]; if(p != 0) { delete mainwindow->averagecurvedialog[p - 1]; mainwindow->averagecurvedialog[p - 1] = NULL; } } if(mainwindow->signalcomp[k]->hascursor2) { /* crosshair_2_active = 0; crosshair_2_moving = 0;*/ } if(mainwindow->signalcomp[k]->hascursor1) { // crosshair_1_active = 0; // crosshair_2_active = 0; // crosshair_1_moving = 0; // crosshair_2_moving = 0; for(i=0; i<mainwindow->signalcomps; i++) { mainwindow->signalcomp[i]->hascursor2 = 0; } } for(i=0; i<mainwindow->signalcomp[k]->filter_cnt; i++) { free(mainwindow->signalcomp[k]->filter[i]); } mainwindow->signalcomp[k]->filter_cnt = 0; for(i=0; i<mainwindow->signalcomp[k]->ravg_filter_cnt; i++) { free_ravg_filter(mainwindow->signalcomp[k]->ravg_filter[i]); } mainwindow->signalcomp[k]->ravg_filter_cnt = 0; for(i=0; i<mainwindow->signalcomp[k]->fidfilter_cnt; i++) { free(mainwindow->signalcomp[k]->fidfilter[i]); fid_run_free(mainwindow->signalcomp[k]->fid_run[i]); fid_run_freebuf(mainwindow->signalcomp[k]->fidbuf[i]); fid_run_freebuf(mainwindow->signalcomp[k]->fidbuf2[i]); } mainwindow->signalcomp[k]->fidfilter_cnt = 0; if(mainwindow->signalcomp[k]->ecg_filter != NULL) { free_ecg_filter(mainwindow->signalcomp[k]->ecg_filter); mainwindow->signalcomp[k]->ecg_filter = NULL; strcpy(mainwindow->signalcomp[k]->signallabel, mainwindow->signalcomp[k]->signallabel_bu); mainwindow->signalcomp[k]->signallabellen = mainwindow->signalcomp[k]->signallabellen_bu; } free(mainwindow->signalcomp[k]); for(i=k; i<mainwindow->signalcomps - 1; i++) { mainwindow->signalcomp[i] = mainwindow->signalcomp[i + 1]; } mainwindow->signalcomps--; k = 0; } else { k++; } } //////////////////////////////////////////// while(1) { skip = 0; xml_goto_root(xml_hdl); signals_read = 0; if(xml_goto_nth_element_inside(xml_hdl, "signalcomposition", signalcomps_read)) { break; } newsignalcomp = (struct signalcompblock *)calloc(1, sizeof(struct signalcompblock)); if(newsignalcomp==NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "Internal error: Memory allocation error:\n\"new signal composition\""); messagewindow.exec(); xml_close(xml_hdl); return; } if(xml_goto_nth_element_inside(xml_hdl, "num_of_signals", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); signal_cnt = atoi(result); free(result); if((signal_cnt<1)||(signal_cnt>MAXSIGNALS)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } newsignalcomp->edfhdr = mainwindow->edfheaderlist[n]; newsignalcomp->filenum = n; newsignalcomp->num_of_signals = signal_cnt; newsignalcomp->hascursor1 = 0; newsignalcomp->hascursor2 = 0; newsignalcomp->hasoffsettracking = 0; newsignalcomp->hasgaintracking = 0; newsignalcomp->screen_offset = 0; newsignalcomp->filter_cnt = 0; newsignalcomp->ravg_filter_cnt = 0; newsignalcomp->ecg_filter = NULL; newsignalcomp->fidfilter_cnt = 0; newsignalcomp->hasruler = 0; newsignalcomp->polarity = 1; newsignalcomp->type = -1; xml_go_up(xml_hdl); if(!(xml_goto_nth_element_inside(xml_hdl, "alias", 0))) { result = xml_get_content_of_element(xml_hdl); if(result[0] != 0) { strncpy(newsignalcomp->alias, result, 16); newsignalcomp->alias[16] = 0; latin1_to_ascii(newsignalcomp->alias, 16); remove_trailing_spaces(newsignalcomp->alias); remove_leading_spaces(newsignalcomp->alias); } free(result); xml_go_up(xml_hdl); } if(xml_goto_nth_element_inside(xml_hdl, "voltpercm", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); newsignalcomp->voltpercm = atof(result); if(newsignalcomp->voltpercm==0.0) newsignalcomp->voltpercm = 0.000000001; free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "screen_offset", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); newsignalcomp->screen_offset = atof(result); free(result); xml_go_up(xml_hdl); if(!(xml_goto_nth_element_inside(xml_hdl, "polarity", 0))) { result = xml_get_content_of_element(xml_hdl); newsignalcomp->polarity = atoi(result); if(newsignalcomp->polarity != -1) { newsignalcomp->polarity = 1; } free(result); xml_go_up(xml_hdl); } if(xml_goto_nth_element_inside(xml_hdl, "color", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); newsignalcomp->color = atoi(result); if((newsignalcomp->color < 2) || (newsignalcomp->color > 18)) { newsignalcomp->color = 2; } free(result); xml_go_up(xml_hdl); if(!(xml_goto_nth_element_inside(xml_hdl, "filter_cnt", 0))) { result = xml_get_content_of_element(xml_hdl); filter_cnt = atoi(result); if(filter_cnt < 0) filter_cnt = 0; if(filter_cnt > MAXFILTERS) filter_cnt = MAXFILTERS; free(result); xml_go_up(xml_hdl); } if(!(xml_goto_nth_element_inside(xml_hdl, "ravg_filter_cnt", 0))) { result = xml_get_content_of_element(xml_hdl); ravg_filter_cnt = atoi(result); if(ravg_filter_cnt < 0) filter_cnt = 0; if(ravg_filter_cnt > MAXFILTERS) ravg_filter_cnt = MAXFILTERS; free(result); xml_go_up(xml_hdl); } if(filter_cnt) { fidfilter_cnt = 0; } else { if(!(xml_goto_nth_element_inside(xml_hdl, "fidfilter_cnt", 0))) { result = xml_get_content_of_element(xml_hdl); fidfilter_cnt = atoi(result); if(fidfilter_cnt < 0) fidfilter_cnt = 0; if(fidfilter_cnt > MAXFILTERS) fidfilter_cnt = MAXFILTERS; free(result); xml_go_up(xml_hdl); } } for(signals_read=0; signals_read<signal_cnt; signals_read++) { if(xml_goto_nth_element_inside(xml_hdl, "signal", signals_read)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(xml_goto_nth_element_inside(xml_hdl, "factor", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); newsignalcomp->factor[signals_read] = atoi(result); if(newsignalcomp->factor[signals_read] < -128) { newsignalcomp->factor[signals_read] = -128; } if(newsignalcomp->factor[signals_read] > 128) { newsignalcomp->factor[signals_read] = 128; } if(newsignalcomp->factor[signals_read] == 0) { newsignalcomp->factor[signals_read] = 1; } free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "edfindex", 0)) { if(xml_goto_nth_element_inside(xml_hdl, "label", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); remove_trailing_spaces(result); found = 0; for(i=0; i<newsignalcomp->edfhdr->edfsignals; i++) { strcpy(scratchpad, newsignalcomp->edfhdr->edfparam[i].label); remove_trailing_spaces(scratchpad); if(!strcmp(scratchpad, result)) { newsignalcomp->edfsignal[signals_read] = i; if(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[signals_read]].annotation) { found = 0; } else { found = 1; } break; } } } else { result = xml_get_content_of_element(xml_hdl); newsignalcomp->edfsignal[signals_read] = atoi(result); if((newsignalcomp->edfsignal[signals_read] < 0) || (newsignalcomp->edfsignal[signals_read] >= newsignalcomp->edfhdr->edfsignals)) { found = 0; } else { if(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[signals_read]].annotation) { found = 0; } else { found = 1; } } } free(result); if(!found) { free(newsignalcomp); skip = 1; signalcomps_read++; xml_go_up(xml_hdl); xml_go_up(xml_hdl); break; } if(signals_read) { if(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[signals_read]].smp_per_record != newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record) { free(newsignalcomp); skip = 1; signalcomps_read++; xml_go_up(xml_hdl); xml_go_up(xml_hdl); break; } } newsignalcomp->sensitivity[signals_read] = newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[signals_read]].bitvalue / (newsignalcomp->voltpercm * mainwindow->pixelsizefactor); if(!signals_read) { newsignalcomp->signallabel[0] = 0; } if(signal_cnt>1) { if(newsignalcomp->factor[signals_read]<0) { strcat(newsignalcomp->signallabel, "- "); } else { if(signals_read) { strcat(newsignalcomp->signallabel, "+ "); } } } strcpy(str, newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[signals_read]].label); strip_types_from_label(str); strcat(newsignalcomp->signallabel, str); strcat(newsignalcomp->signallabel, " "); len = strlen(newsignalcomp->signallabel); for(k=(len-1); k>0; k--) { if(newsignalcomp->signallabel[k]!=' ') break; } newsignalcomp->signallabel[k+2] = 0; newsignalcomp->file_duration = newsignalcomp->edfhdr->long_data_record_duration * newsignalcomp->edfhdr->datarecords; newsignalcomp->signallabellen = strlen(newsignalcomp->signallabel); xml_go_up(xml_hdl); xml_go_up(xml_hdl); } if(skip) continue; strcpy(newsignalcomp->physdimension, newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].physdimension); remove_trailing_spaces(newsignalcomp->physdimension); for(filters_read=0; filters_read<filter_cnt; filters_read++) { if(xml_goto_nth_element_inside(xml_hdl, "filter", filters_read)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(xml_goto_nth_element_inside(xml_hdl, "LPF", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); type = atoi(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "frequency", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); frequency = atof(result); free(result); if((type < 0) || (type > 1) || (frequency < 0.0001)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (filter values)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(frequency >= ((newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record / newsignalcomp->edfhdr->data_record_duration) / 2.0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(type == 0) { sprintf(spec_str, "HpBu1/%f", frequency); } if(type == 1) { sprintf(spec_str, "LpBu1/%f", frequency); } filter_spec = spec_str; err = fid_parse(((double)(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record)) / newsignalcomp->edfhdr->data_record_duration, &filter_spec, &newsignalcomp->fidfilter[filters_read]); if(err != NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", err); messagewindow.exec(); free(err); free(newsignalcomp); xml_close(xml_hdl); return; } newsignalcomp->fid_run[filters_read] = fid_run_new(newsignalcomp->fidfilter[filters_read], &newsignalcomp->fidfuncp[filters_read]); newsignalcomp->fidbuf[filters_read] = fid_run_newbuf(newsignalcomp->fid_run[filters_read]); newsignalcomp->fidbuf2[filters_read] = fid_run_newbuf(newsignalcomp->fid_run[filters_read]); newsignalcomp->fidfilter_freq[filters_read] = frequency; newsignalcomp->fidfilter_freq2[filters_read] = frequency * 1.12; newsignalcomp->fidfilter_ripple[filters_read] = -1.0; newsignalcomp->fidfilter_order[filters_read] = 1; newsignalcomp->fidfilter_type[filters_read] = type; newsignalcomp->fidfilter_model[filters_read] = 0; newsignalcomp->fidfilter_setup[filters_read] = 1; newsignalcomp->fidfilter_cnt = filters_read + 1; xml_go_up(xml_hdl); xml_go_up(xml_hdl); } for(filters_read=0; filters_read<ravg_filter_cnt; filters_read++) { if(xml_goto_nth_element_inside(xml_hdl, "ravg_filter", filters_read)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(xml_goto_nth_element_inside(xml_hdl, "type", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); type = atoi(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "size", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); size = atoi(result); free(result); if((type < 0) || (type > 1) || (size < 2) || (size > 10000)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (ravg_filter values)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } newsignalcomp->ravg_filter[filters_read] = create_ravg_filter(type, size); if(newsignalcomp->ravg_filter[filters_read] == NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating an ravg filter."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } newsignalcomp->ravg_filter_size[filters_read] = size; newsignalcomp->ravg_filter_type[filters_read] = type; newsignalcomp->ravg_filter_cnt = filters_read + 1; xml_go_up(xml_hdl); xml_go_up(xml_hdl); } for(filters_read=0; filters_read<fidfilter_cnt; filters_read++) { if(xml_goto_nth_element_inside(xml_hdl, "fidfilter", filters_read)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (fidfilter)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(xml_goto_nth_element_inside(xml_hdl, "type", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (type)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); type = atoi(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "model", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (model)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); model = atoi(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "frequency", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (frequency)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); frequency = atof(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "frequency2", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (frequency2)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); frequency2 = atof(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "ripple", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (ripple)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); ripple = atof(result); free(result); xml_go_up(xml_hdl); if(xml_goto_nth_element_inside(xml_hdl, "order", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (order)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); order = atoi(result); free(result); if((model < 0) || (model > 2) || (order < 1) || (order > 100) || (type < 0) || (type > 4) || (ripple < (-6.0)) || (ripple > (-0.1)) || (frequency < 0.0001) || (frequency2 < 0.0001)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file. (fidfilter values)"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(frequency >= ((newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record / newsignalcomp->edfhdr->data_record_duration) / 2.0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } if(type > 2) { if(frequency2 >= ((newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record / newsignalcomp->edfhdr->data_record_duration) / 2.0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2"); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } } if((type == 0) || (type == 1)) { if(order > 8) { order = 8; } } if(type == 0) { if(model == 0) { sprintf(spec_str, "HpBu%i/%f", order, frequency); } if(model == 1) { sprintf(spec_str, "HpCh%i/%f/%f", order, ripple, frequency); } if(model == 2) { sprintf(spec_str, "HpBe%i/%f", order, frequency); } } if(type == 1) { if(model == 0) { sprintf(spec_str, "LpBu%i/%f", order, frequency); } if(model == 1) { sprintf(spec_str, "LpCh%i/%f/%f", order, ripple, frequency); } if(model == 2) { sprintf(spec_str, "LpBe%i/%f", order, frequency); } } if(type == 2) { if(order > 100) { order = 100; } if(order < 3) { order = 3; } if(model == 0) { sprintf(spec_str, "BsRe/%i/%f", order, frequency); } } if((type == 3) || (type == 4)) { if(order < 2) { order = 2; } if(order % 2) { order++; } if(order > 16) { order = 16; } } if(type == 3) { if(model == 0) { sprintf(spec_str, "BpBu%i/%f-%f", order, frequency, frequency2); } if(model == 1) { sprintf(spec_str, "BpCh%i/%f/%f-%f", order, ripple, frequency, frequency2); } if(model == 2) { sprintf(spec_str, "BpBe%i/%f-%f", order, frequency, frequency2); } } if(type == 4) { if(model == 0) { sprintf(spec_str, "BsBu%i/%f-%f", order, frequency, frequency2); } if(model == 1) { sprintf(spec_str, "BsCh%i/%f/%f-%f", order, ripple, frequency, frequency2); } if(model == 2) { sprintf(spec_str, "BsBe%i/%f-%f", order, frequency, frequency2); } } filter_spec = spec_str; err = fid_parse(((double)(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record)) / newsignalcomp->edfhdr->data_record_duration, &filter_spec, &newsignalcomp->fidfilter[filters_read]); if(err != NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", err); messagewindow.exec(); free(err); free(newsignalcomp); xml_close(xml_hdl); return; } newsignalcomp->fid_run[filters_read] = fid_run_new(newsignalcomp->fidfilter[filters_read], &newsignalcomp->fidfuncp[filters_read]); newsignalcomp->fidbuf[filters_read] = fid_run_newbuf(newsignalcomp->fid_run[filters_read]); newsignalcomp->fidbuf2[filters_read] = fid_run_newbuf(newsignalcomp->fid_run[filters_read]); newsignalcomp->fidfilter_freq[filters_read] = frequency; newsignalcomp->fidfilter_freq2[filters_read] = frequency2; newsignalcomp->fidfilter_ripple[filters_read] = ripple; newsignalcomp->fidfilter_order[filters_read] = order; newsignalcomp->fidfilter_type[filters_read] = type; newsignalcomp->fidfilter_model[filters_read] = model; newsignalcomp->fidfilter_setup[filters_read] = 1; newsignalcomp->fidfilter_cnt = filters_read + 1; xml_go_up(xml_hdl); xml_go_up(xml_hdl); } if(!xml_goto_nth_element_inside(xml_hdl, "ecg_filter", 0)) { if(xml_goto_nth_element_inside(xml_hdl, "type", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); type = atoi(result); free(result); if(type == 1) { newsignalcomp->ecg_filter = create_ecg_filter(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record / newsignalcomp->edfhdr->data_record_duration, newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].bitvalue, mainwindow->powerlinefreq); if(newsignalcomp->ecg_filter == NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating an ECG filter."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } strcpy(newsignalcomp->signallabel_bu, newsignalcomp->signallabel); newsignalcomp->signallabellen_bu = newsignalcomp->signallabellen; strcpy(newsignalcomp->signallabel, "HR"); newsignalcomp->signallabellen = strlen(newsignalcomp->signallabel); strcpy(newsignalcomp->physdimension_bu, newsignalcomp->physdimension); strcpy(newsignalcomp->physdimension, "bpm"); } xml_go_up(xml_hdl); xml_go_up(xml_hdl); } if(newsignalcomp->ecg_filter == NULL) { if(!xml_goto_nth_element_inside(xml_hdl, "zratio_filter", 0)) { if(xml_goto_nth_element_inside(xml_hdl, "type", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); type = atoi(result); free(result); xml_go_up(xml_hdl); if(type == 1) { if(xml_goto_nth_element_inside(xml_hdl, "crossoverfreq", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); newsignalcomp->zratio_crossoverfreq = atof(result); free(result); if((newsignalcomp->zratio_crossoverfreq < 5.0) || (newsignalcomp->zratio_crossoverfreq > 9.5)) { newsignalcomp->zratio_crossoverfreq = 7.5; } newsignalcomp->zratio_filter = create_zratio_filter(newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].smp_per_record, newsignalcomp->edfhdr->long_data_record_duration, newsignalcomp->zratio_crossoverfreq, newsignalcomp->edfhdr->edfparam[newsignalcomp->edfsignal[0]].bitvalue); if(newsignalcomp->zratio_filter == NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "A memory allocation error occurred when creating a Z-ratio filter."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } strcpy(newsignalcomp->signallabel_bu, newsignalcomp->signallabel); newsignalcomp->signallabellen_bu = newsignalcomp->signallabellen; strcpy(newsignalcomp->signallabel, "Z-ratio "); strcat(newsignalcomp->signallabel, newsignalcomp->signallabel_bu); newsignalcomp->signallabellen = strlen(newsignalcomp->signallabel); strcpy(newsignalcomp->physdimension_bu, newsignalcomp->physdimension); strcpy(newsignalcomp->physdimension, ""); xml_go_up(xml_hdl); } xml_go_up(xml_hdl); } } if(f_ruler_cnt == 0) { if(!xml_goto_nth_element_inside(xml_hdl, "floating_ruler", 0)) { if(xml_goto_nth_element_inside(xml_hdl, "hasruler", 0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "There seems to be an error in this montage file."); messagewindow.exec(); free(newsignalcomp); xml_close(xml_hdl); return; } result = xml_get_content_of_element(xml_hdl); tmp = atoi(result); free(result); xml_go_up(xml_hdl); if(tmp == 1) { f_ruler_cnt = 1; mainwindow->maincurve->ruler_x_position = 200; mainwindow->maincurve->ruler_y_position = 200; mainwindow->maincurve->floating_ruler_value = 0; if(!xml_goto_nth_element_inside(xml_hdl, "ruler_x_position", 0)) { result = xml_get_content_of_element(xml_hdl); tmp = atoi(result); free(result); if((tmp >= 0) && (tmp < 5000)) { mainwindow->maincurve->ruler_x_position = tmp; } xml_go_up(xml_hdl); } if(!xml_goto_nth_element_inside(xml_hdl, "ruler_y_position", 0)) { result = xml_get_content_of_element(xml_hdl); tmp = atoi(result); free(result); if((tmp >= 0) && (tmp < 5000)) { mainwindow->maincurve->ruler_y_position = tmp; } xml_go_up(xml_hdl); } if(!xml_goto_nth_element_inside(xml_hdl, "floating_ruler_value", 0)) { result = xml_get_content_of_element(xml_hdl); tmp = atoi(result); free(result); if((tmp >= 0) && (tmp < 2)) { mainwindow->maincurve->floating_ruler_value = tmp; } xml_go_up(xml_hdl); } newsignalcomp->hasruler = 1; } xml_go_up(xml_hdl); } } mainwindow->signalcomp[mainwindow->signalcomps] = newsignalcomp; mainwindow->signalcomps++; signalcomps_read++; } xml_goto_root(xml_hdl); if(!(xml_goto_nth_element_inside(xml_hdl, "pagetime", 0))) { result = xml_get_content_of_element(xml_hdl); mainwindow->pagetime = atoll(result); if(mainwindow->pagetime < 10000LL) { mainwindow->pagetime = 10000LL; } free(result); } xml_close(xml_hdl); if(LoadMontageDialog!=NULL) LoadMontageDialog->close(); mainwindow->setMainwindowTitle(mainwindow->edfheaderlist[mainwindow->sel_viewtime]); if(mainwindow->files_open == 1) { strcpy(&mainwindow->recent_file_mtg_path[0][0], mtg_path); } for(i=0; i<3; i++) { amp_cat[i] = 0; } for(i=0; i<mainwindow->signalcomps; i++) { tmp = round_125_cat(mainwindow->signalcomp[i]->voltpercm); switch(tmp) { case 10 : amp_cat[0]++; break; case 20 : amp_cat[1]++; break; case 50 : amp_cat[2]++; break; } } mainwindow->amplitude_doubler = 10; if((amp_cat[1] > amp_cat[0]) && (amp_cat[1] >= amp_cat[2])) { mainwindow->amplitude_doubler = 20; } if((amp_cat[2] > amp_cat[0]) && (amp_cat[2] > amp_cat[1])) { mainwindow->amplitude_doubler = 50; } if(f_ruler_cnt == 1) { mainwindow->maincurve->ruler_active = 1; } mainwindow->setup_viewbuf(); }
LRESULT CALLBACK FilterboxDlgHandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { int t; // ,z; char newname[25],sztemp[30]; static int acttype; static int dinit=FALSE; static FidFilter * tempf=NULL,* newf=NULL; FILTEROBJ * st; st = (FILTEROBJ *) actobject; if ((st==NULL)||(st->type!=OB_FILTER)) return(FALSE); switch( message ) { case WM_INITDIALOG: dinit=TRUE; SendMessage(GetDlgItem(hDlg, IDC_FILTERTYPECOMBO), CB_RESETCONTENT,0,0); for (t = 0; t < FILTERTYPES; t++) SendMessage( GetDlgItem(hDlg, IDC_FILTERTYPECOMBO), CB_ADDSTRING, 0, (LPARAM) (LPSTR) FILTERTYPE[t].tname) ; SetDlgItemText(hDlg,IDC_FILTERTYPECOMBO, FILTERTYPE[st->filtertype].tname); SetDlgItemText(hDlg,IDC_FILTERNEWNAME, st->name); SetDlgItemInt(hDlg,IDC_FROMFREQ, st->dispfrom,0); SetDlgItemInt(hDlg,IDC_TOFREQ, st->dispto,0); SetDlgItemInt(hDlg,IDC_FILTERPAR0, st->par0,0); sprintf(sztemp,"%.5f",st->par1); SetDlgItemText(hDlg,IDC_FILTERPAR1, sztemp); sprintf(sztemp,"%.5f",st->par2); SetDlgItemText(hDlg,IDC_FILTERPAR2, sztemp); acttype=st->filtertype; dinit=FALSE; newf=do_filt_design(hDlg,acttype); if (newf) tempf=newf; update_filterdialog(hDlg,st->filtertype); return TRUE; case WM_CLOSE: EndDialog(hDlg, LOWORD(wParam)); return TRUE; break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_FILTERTYPECOMBO: acttype=SendMessage( GetDlgItem(hDlg, IDC_FILTERTYPECOMBO), CB_GETCURSEL, 0, 0 ) ; update_filterdialog(hDlg,acttype); case IDC_FILTERPAR0: case IDC_FILTERPAR1: case IDC_FILTERPAR2: case IDC_FROMFREQ: case IDC_TOFREQ: if (!dinit) { newf=do_filt_design(hDlg,acttype); if (newf) tempf=newf; InvalidateRect(hDlg,NULL,TRUE); } break; case IDC_FILTERSTORE: if (newf) { GetDlgItemText(hDlg, IDC_FILTERNEWNAME,newname,sizeof(newname)); st->filtertype=acttype; st->par0=GetDlgItemInt(hDlg,IDC_FILTERPAR0, NULL, 0); GetDlgItemText(hDlg,IDC_FILTERPAR1,sztemp,sizeof(sztemp)); sscanf(sztemp,"%f",&st->par1); GetDlgItemText(hDlg,IDC_FILTERPAR2,sztemp,sizeof(sztemp)); st->dispfrom=GetDlgItemInt(hDlg, IDC_FROMFREQ, NULL, 0); st->dispto=GetDlgItemInt(hDlg, IDC_TOFREQ, NULL, 0); sscanf(sztemp,"%f",&st->par2); strcpy(st->name,newname); st->filt=do_filt_design(hDlg, acttype); st->run= fid_run_new(st->filt, &(st->funcp)); if (st->fbuf!=NULL) { fid_run_freebuf(st->fbuf); st->fbuf=fid_run_newbuf(st->run); } } break; } return(TRUE); case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; RECT rect; HPEN tpen; HBRUSH tbrush; int height; int f1,f2; float fstep,val,x; hdc = BeginPaint (hDlg, &ps); GetClientRect(hDlg, &rect); tpen = CreatePen (PS_SOLID,1,0); SelectObject (hdc, tpen); tbrush = CreateSolidBrush(RGB(240,240,240)); SelectObject(hdc,tbrush); rect.top+=80; rect.bottom -= 18; height= rect.bottom-rect.top; Rectangle(hdc,rect.left,rect.top-1,rect.right,rect.bottom+20); Rectangle(hdc,rect.left,rect.top-1,rect.right,rect.bottom); Rectangle(hdc,rect.left,rect.bottom-(int)(height/1.3),rect.right,rect.bottom); DeleteObject(tbrush); DeleteObject(tpen); tpen = CreatePen (PS_SOLID,1,RGB(0,100,0)); SelectObject (hdc, tpen); f1=GetDlgItemInt(hDlg, IDC_FROMFREQ, NULL, 0); f2=GetDlgItemInt(hDlg, IDC_TOFREQ, NULL, 0); fstep=(float)(f2-f1)/(rect.right-rect.left); MoveToEx(hdc,rect.left+1,rect.bottom-(int)(height*fid_response(tempf, (float)f1/256.0)/1.3),NULL); for (t=rect.left; t<rect.right; t++) { MoveToEx(hdc,1+t,rect.bottom,NULL); LineTo(hdc,1+t,rect.bottom-(int)(height*fid_response(tempf, (((float)f1+fstep*(t-rect.left))/PACKETSPERSECOND))/1.3)); } SelectObject(hdc, DRAW.scaleFont); wsprintf(sztemp,"1.0"); ExtTextOut( hdc, rect.left+2,rect.top+(int)(height*0.2308), 0, &rect,sztemp, strlen(sztemp), NULL ) ; val=(f2-f1)/10.0f; fstep=((rect.right-25)-rect.left)/10.0f; for (t=0; t<=10; t++) { x=f1+val*t; wsprintf(sztemp,"%d.%d",(int)x,(int)(x*10)%10); ExtTextOut( hdc, rect.left+2+(int)(fstep*t),rect.bottom+2, 0, &rect,sztemp, strlen(sztemp), NULL ) ; } DeleteObject(tpen); EndPaint(hDlg, &ps ); } break; case WM_SIZE: case WM_MOVE: update_toolbox_position(hDlg); break; return(TRUE); } return FALSE; }
void UI_FilterDialog::ApplyButtonClicked() { int i, s, n, type, model, order; double frequency, frequency2, ripple; char *err; QListWidgetItem *item; QList<QListWidgetItem *> selectedlist; selectedlist = list->selectedItems(); n = selectedlist.size(); if(!n) { filterdialog->close(); return; } frequency = freqbox->value(); frequency2 = freq2box->value(); order = orderbox->value(); type = typebox->currentIndex(); model = modelbox->currentIndex(); ripple = -(ripplebox->value()); for(i=0; i<n; i++) { item = selectedlist.at(i); s = item->data(Qt::UserRole).toInt(); if((mainwindow->signalcomp[s]->filter_cnt + mainwindow->signalcomp[s]->fidfilter_cnt) > MAXFILTERS - 1) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "The maximum amount of filters per signal has been reached.\n" "Remove some filters first."); messagewindow.exec(); return; } } if(model < 3) { for(i=0; i<n; i++) { item = selectedlist.at(i); s = list->row(item); if(type < 3) { if(frequency >= ((mainwindow->signalcomp[s]->edfhdr->edfparam[mainwindow->signalcomp[s]->edfsignal[0]].smp_per_record / mainwindow->signalcomp[s]->edfhdr->data_record_duration) / 2.0)) { UI_Messagewindow errormessage("Error", "The frequency of the filter(s) must be less than: samplerate / 2"); return; } } else { if(frequency2 >= ((mainwindow->signalcomp[s]->edfhdr->edfparam[mainwindow->signalcomp[s]->edfsignal[0]].smp_per_record / mainwindow->signalcomp[s]->edfhdr->data_record_duration) / 2.0)) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "The frequency of the filter(s) must be less than: samplerate / 2"); messagewindow.exec(); return; } } } spec_str_1[0] = 0; if(type == 0) { if(model == 0) { sprintf(spec_str_1, "HpBu%i/%f", order, frequency); } if(model == 1) { sprintf(spec_str_1, "HpCh%i/%f/%f", order, ripple, frequency); } if(model == 2) { sprintf(spec_str_1, "HpBe%i/%f", order, frequency); } } if(type == 1) { if(model == 0) { sprintf(spec_str_1, "LpBu%i/%f", order, frequency); } if(model == 1) { sprintf(spec_str_1, "LpCh%i/%f/%f", order, ripple, frequency); } if(model == 2) { sprintf(spec_str_1, "LpBe%i/%f", order, frequency); } } if(type == 2) { sprintf(spec_str_1, "BsRe/%i/%f", order, frequency); } if(type == 3) { if(model == 0) { sprintf(spec_str_1, "BpBu%i/%f-%f", order, frequency, frequency2); } if(model == 1) { sprintf(spec_str_1, "BpCh%i/%f/%f-%f", order, ripple, frequency, frequency2); } if(model == 2) { sprintf(spec_str_1, "BpBe%i/%f-%f", order, frequency, frequency2); } } if(type == 4) { if(model == 0) { sprintf(spec_str_1, "BsBu%i/%f-%f", order, frequency, frequency2); } if(model == 1) { sprintf(spec_str_1, "BsCh%i/%f/%f-%f", order, ripple, frequency, frequency2); } if(model == 2) { sprintf(spec_str_1, "BsBe%i/%f-%f", order, frequency, frequency2); } } for(i=0; i<n; i++) { item = selectedlist.at(i); s = list->row(item); strcpy(spec_str_2, spec_str_1); filter_spec = spec_str_2; err = fid_parse(((double)(mainwindow->signalcomp[s]->edfhdr->edfparam[mainwindow->signalcomp[s]->edfsignal[0]].smp_per_record)) / mainwindow->signalcomp[s]->edfhdr->data_record_duration, &filter_spec, &mainwindow->signalcomp[s]->fidfilter[mainwindow->signalcomp[s]->fidfilter_cnt]); if(err != NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", err); messagewindow.exec(); free(err); filterdialog->close(); return; } mainwindow->signalcomp[s]->fid_run[mainwindow->signalcomp[s]->fidfilter_cnt] = fid_run_new(mainwindow->signalcomp[s]->fidfilter[mainwindow->signalcomp[s]->fidfilter_cnt], &mainwindow->signalcomp[s]->fidfuncp[mainwindow->signalcomp[s]->fidfilter_cnt]); mainwindow->signalcomp[s]->fidbuf[mainwindow->signalcomp[s]->fidfilter_cnt] = fid_run_newbuf(mainwindow->signalcomp[s]->fid_run[mainwindow->signalcomp[s]->fidfilter_cnt]); mainwindow->signalcomp[s]->fidbuf2[mainwindow->signalcomp[s]->fidfilter_cnt] = fid_run_newbuf(mainwindow->signalcomp[s]->fid_run[mainwindow->signalcomp[s]->fidfilter_cnt]); mainwindow->signalcomp[s]->fidfilter_freq[mainwindow->signalcomp[s]->fidfilter_cnt] = frequency; mainwindow->signalcomp[s]->fidfilter_freq2[mainwindow->signalcomp[s]->fidfilter_cnt] = frequency2; mainwindow->signalcomp[s]->fidfilter_ripple[mainwindow->signalcomp[s]->fidfilter_cnt] = ripple; mainwindow->signalcomp[s]->fidfilter_order[mainwindow->signalcomp[s]->fidfilter_cnt] = order; mainwindow->signalcomp[s]->fidfilter_model[mainwindow->signalcomp[s]->fidfilter_cnt] = model; mainwindow->signalcomp[s]->fidfilter_type[mainwindow->signalcomp[s]->fidfilter_cnt] = type; mainwindow->signalcomp[s]->fidfilter_setup[mainwindow->signalcomp[s]->fidfilter_cnt] = 1; mainwindow->signalcomp[s]->fidfilter_cnt++; } } if(model == 3) { for(i=0; i<n; i++) { item = selectedlist.at(i); s = list->row(item); mainwindow->signalcomp[s]->ravg_filter[mainwindow->signalcomp[s]->ravg_filter_cnt] = create_ravg_filter(type, order); if(mainwindow->signalcomp[s]->ravg_filter[mainwindow->signalcomp[s]->ravg_filter_cnt] == NULL) { QMessageBox messagewindow(QMessageBox::Critical, "Error", "An error occurred while creating a moving average filter."); messagewindow.exec(); filterdialog->close(); return; } mainwindow->signalcomp[s]->ravg_filter_type[mainwindow->signalcomp[s]->ravg_filter_cnt] = type; mainwindow->signalcomp[s]->ravg_filter_size[mainwindow->signalcomp[s]->ravg_filter_cnt] = order; mainwindow->signalcomp[s]->ravg_filter_setup[mainwindow->signalcomp[s]->ravg_filter_cnt] = 1; mainwindow->signalcomp[s]->ravg_filter_cnt++; } } filterdialog->close(); mainwindow->setup_viewbuf(); }