/*------------------------------------------------------------------ ---------------------------------- open dialog to browse sound files ------------------------------------------------------------------*/ BOOL BrowseSoundFile(HWND hDlg, const wchar_t* deffile, wchar_t fname[MAX_PATH]) { wchar_t filter[1024], mmfileexts[1024]; DWORD index; filter[0]=filter[1]='\0'; str0cat(filter, MyString(IDS_MMFILE)); GetMMFileExts(mmfileexts); str0cat(filter, mmfileexts); str0cat(filter, MyString(IDS_ALLFILE)); str0cat(filter, L"*.*"); if(!deffile[0] || IsMMFile(deffile)) index = 1; else index = 2; if(SelectMyFile(hDlg, filter, index, deffile, fname)) { if(!wcsncmp(fname,api.root,api.root_len)) { // make relative to waves/ if possible if(!wcsncmp(fname+api.root_len, L"\\waves\\", 7)) { memmove(fname, fname+api.root_len+7, ((wcslen(fname)-api.root_len-7+1) * sizeof fname[0])); } } return 1; } return 0; }
/*------------------------------------------------------------------ ---------------------------------- open dialog to browse sound files ------------------------------------------------------------------*/ BOOL BrowseSoundFile(HWND hDlg, const char* deffile, char* fname) { char filter[1024], mmfileexts[1024]; char ftitle[MAX_PATH], initdir[MAX_PATH]; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); // Initialize OPENFILENAME ofn.lStructSize = sizeof(ofn); filter[0]=filter[1]='\0'; str0cat(filter, MyString(IDS_MMFILE)); GetMMFileExts(mmfileexts); str0cat(filter, mmfileexts); str0cat(filter, MyString(IDS_ALLFILE)); str0cat(filter, "*.*"); if(!deffile[0] || IsMMFile(deffile)) ofn.nFilterIndex = 1; else ofn.nFilterIndex = 2; memcpy(initdir, api.root, api.root_len+1); if(deffile[0]) { WIN32_FIND_DATA fd; HANDLE hfind; hfind = FindFirstFile(deffile, &fd); if(hfind != INVALID_HANDLE_VALUE) { FindClose(hfind); strncpy_s(initdir,sizeof(initdir),deffile,_TRUNCATE); del_title(initdir); } } *fname = '\0'; ofn.hwndOwner = hDlg; ofn.hInstance = NULL; ofn.lpstrFilter = filter; ofn.lpstrFile = fname; ofn.nMaxFile = MAX_PATH; ofn.lpstrFileTitle = ftitle; ofn.nMaxFileTitle = MAX_PATH; ofn.lpstrInitialDir = initdir; ofn.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) { size_t tlen=api.root_len; if(!strncmp(fname,api.root,tlen)) { // make relative to waves/ if possible if(!strncmp(fname+tlen,"\\waves\\",7)) { memmove(fname,fname+tlen+7,strlen(fname)-tlen-6); } } return 1; } return 0; }
//=================================================* // ------------------------ Play Selected Alarm File //===================================================* BOOL PlayFile(HWND hwnd, const char* fname, DWORD dwLoops) { char file[MAX_PATH]; if(!fname[0] || fname[0]=='<') return FALSE; if(fname[0]!='/' && fname[0]!='\\' && fname[1]!=':' // no abs path &&(fname[0]!='.' || (fname[1]!='/' && fname[1]!='\\' && (fname[1]!='.' || (fname[2]!='/' && fname[2]!='\\'))))) // no relative path (strict relative) { // do it relative to "waves/" char app[MAX_PATH]; const size_t tlen=api.root_len; const size_t len=strlen(fname)+1; // incl. terminating null if(len<MAX_PATH-tlen-7){ memcpy(file, api.root, tlen); // absolute path is at least required by .pcb / PlayNoSoundThread (not for .wav) memcpy(file+tlen, "\\waves\\", 7); memcpy(file+tlen+7, fname, len); if(api.GetFileAndOption(file, app, NULL) == 0){ fname = file; } } } if(ext_cmp(fname, "wav") == 0) { if(m_bMCIPlaying) return FALSE; return PlayWave(hwnd, fname, dwLoops); } if(ext_cmp(fname, "pcb") == 0) { if(m_bMCIPlaying) return FALSE; PlayNoSoundThread(hwnd, fname, dwLoops); return TRUE; } else if(IsMMFile(fname)) { char command[MIN_BUFF+MAX_PATH]; if(m_bMCIPlaying) return FALSE; strcpy(command, "open \""); strcat(command, fname); strcat(command, "\" alias myfile"); if(mciSendString(command, NULL, 0, NULL) == 0) { strcpy(command, "set myfile time format "); if(strcasecmp(fname, "cdaudio") == 0 || ext_cmp(fname, "cda") == 0) { strcat(command, "tmsf"); m_bTrack = TRUE; } else { strcat(command, "milliseconds"); m_bTrack = FALSE; } mciSendString(command, NULL, 0, NULL); m_nTrack = -1; if(ext_cmp(fname, "cda") == 0) { const char* p; p = fname; m_nTrack = 0; while(*p) { if('0' <= *p && *p <= '9') m_nTrack = m_nTrack * 10 + *p - '0'; p++; } } if(PlayMCI(hwnd, m_nTrack) == 0) { m_bMCIPlaying = TRUE; m_countPlay = dwLoops; } else mciSendString("close myfile", NULL, 0, NULL); } return m_bMCIPlaying; } else api.ExecFile(fname,hwnd); return FALSE; }