/* ============ CDAudio_InitDevice ============ */ qboolean CDAudio_InitDevice (void) { DWORD dwReturn; MCI_OPEN_PARMS mciOpenParms; MCI_SET_PARMS mciSetParms; mciOpenParms.lpstrDeviceType = "cdaudio"; if ((dwReturn = mciSendCommandA (0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE, (DWORD)(LPVOID) &mciOpenParms))) { Con_Printf ("CDAudio_Init: MCI_OPEN failed (%i)\n", dwReturn); return false; } wDeviceID = mciOpenParms.wDeviceID; // Set the time format to track/minute/second/frame (TMSF). mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF; if ((dwReturn = mciSendCommandA (wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT, (DWORD)(LPVOID) &mciSetParms))) { Con_Printf ("MCI_SET_TIME_FORMAT failed (%i)\n", dwReturn); mciSendCommandA (wDeviceID, MCI_CLOSE, 0, 0); return false; } // JDH: store original volume CDAudio_AccessVolume (&cd_initialvol, CDDA_GETVOL); return true; }
/* ============ CDAudio_GetNumTracks ============ */ int CDAudio_GetNumTracks (void) { DWORD dwReturn; MCI_STATUS_PARMS mciStatusParms; mciStatusParms.dwItem = MCI_STATUS_READY; dwReturn = mciSendCommandA (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD)(LPVOID)&mciStatusParms); if (dwReturn) { Con_DPrintf ("CDAudio: drive ready test - get status failed\n"); return -1; } if (!mciStatusParms.dwReturn) { Con_DPrintf ("CDAudio: drive not ready\n"); return -1; } mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS; dwReturn = mciSendCommandA (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT, (DWORD)(LPVOID)&mciStatusParms); if (dwReturn) { Con_DPrintf ("CDAudio: get tracks - status failed\n"); return -1; } if (mciStatusParms.dwReturn < 1) { Con_DPrintf ("CDAudio: no music tracks\n"); return -1; } return mciStatusParms.dwReturn; }
/* ============ CDAudio_GetTrackLength ============ */ int CDAudio_GetTrackLength (byte track) { DWORD dwReturn; MCI_STATUS_PARMS mciStatusParms; mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK; mciStatusParms.dwTrack = track; dwReturn = mciSendCommandA (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD)(LPVOID)&mciStatusParms); if (dwReturn) { Con_DPrintf ("MCI_STATUS failed (%i)\n", dwReturn); return -1; } if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO) { Con_Printf ("CDAudio: track %i is not audio\n", track); return -1; } // get the length of the track to be played mciStatusParms.dwItem = MCI_STATUS_LENGTH; mciStatusParms.dwTrack = track; dwReturn = mciSendCommandA (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT, (DWORD)(LPVOID)&mciStatusParms); if (dwReturn) { Con_DPrintf ("MCI_STATUS failed (%i)\n", dwReturn); return -1; } return mciStatusParms.dwReturn; }
static void MCIWND_ToggleState(MCIWndInfo* mwi) { MCI_GENERIC_PARMS mgp; MCI_DGV_PLAY_PARMS mdply; memset(&mgp, 0, sizeof(mgp)); memset(&mdply, 0, sizeof(mdply)); switch (MCIWND_GetStatus(mwi)) { case MCI_MODE_NOT_READY: case MCI_MODE_RECORD: case MCI_MODE_SEEK: case MCI_MODE_OPEN: TRACE("Cannot do much...\n"); break; case MCI_MODE_PAUSE: mciSendCommandA(mwi->mci, MCI_RESUME, MCI_WAIT, (LPARAM)&mgp); break; case MCI_MODE_PLAY: mciSendCommandA(mwi->mci, MCI_PAUSE, MCI_WAIT, (LPARAM)&mgp); break; case MCI_MODE_STOP: mdply.dwFrom = 0L; mciSendCommandA(mwi->mci, MCI_PLAY, MCI_FROM, (LPARAM)&mdply); mwi->uTimer = SetTimer(mwi->hWnd, 0, 333, 0L); TRACE("Timer=%u\n", mwi->uTimer); break; } }
static void MCIWND_Create(HWND hWnd, LPCREATESTRUCTA cs) { MCI_DGV_OPEN_PARMSA mdopn; MCI_DGV_RECT_PARMS mdrct; MMRESULT mmr; int cx, cy; HWND hChld; MCIWndInfo* mwi = (MCIWndInfo*)cs->lpCreateParams; SetWindowLongA(hWnd, 0, (LPARAM)mwi); mwi->hWnd = hWnd; /* now open MCI player for AVI file */ memset(&mdopn, 0, sizeof(mdopn)); mdopn.lpstrElementName = mwi->lpName; mdopn.dwStyle = WS_VISIBLE|WS_CHILD; mdopn.hWndParent = hWnd; mmr = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_ELEMENT|MCI_DGV_OPEN_PARENT|MCI_DGV_OPEN_WS, (LPARAM)&mdopn); if (mmr) { MessageBoxA(GetTopWindow(hWnd), "Cannot open file", "MciWnd", MB_OK); return; } mwi->mci = mdopn.wDeviceID; /* grab AVI window size */ memset(&mdrct, 0, sizeof(mdrct)); mmr = mciSendCommandA(mwi->mci, MCI_WHERE, MCI_DGV_WHERE_DESTINATION, (LPARAM)&mdrct); if (mmr) { WARN("Cannot get window rect\n"); return; } cx = mdrct.rc.right - mdrct.rc.left; cy = mdrct.rc.bottom - mdrct.rc.top; AdjustWindowRect(&mdrct.rc, GetWindowLongA(hWnd, GWL_STYLE), FALSE); SetWindowPos(hWnd, 0, 0, 0, mdrct.rc.right - mdrct.rc.left, mdrct.rc.bottom - mdrct.rc.top + 32, SWP_NOMOVE|SWP_NOZORDER); /* adding the other elements: play/stop button, menu button, status */ hChld = CreateWindowExA(0, "BUTTON", "Play", WS_CHILD|WS_VISIBLE, 0, cy, 32, 32, hWnd, (HMENU)CTL_PLAYSTOP, GetWindowLongA(hWnd, GWL_HINSTANCE), 0L); TRACE("Get Button1: %04x\n", hChld); hChld = CreateWindowExA(0, "BUTTON", "Menu", WS_CHILD|WS_VISIBLE, 32, cy, 32, 32, hWnd, (HMENU)CTL_MENU, GetWindowLongA(hWnd, GWL_HINSTANCE), 0L); TRACE("Get Button2: %04x\n", hChld); hChld = CreateWindowExA(0, TRACKBAR_CLASSA, "", WS_CHILD|WS_VISIBLE, 64, cy, cx - 64, 32, hWnd, (HMENU)CTL_TRACKBAR, GetWindowLongA(hWnd, GWL_HINSTANCE), 0L); TRACE("Get status: %04x\n", hChld); SendMessageA(hChld, TBM_SETRANGEMIN, 0L, 0L); SendMessageA(hChld, TBM_SETRANGEMAX, 1L, MCIWND_Get(mwi, MCI_STATUS_LENGTH)); /* FIXME: no need to set it if child window */ MCIWND_SetText(mwi); }
/* ============ CDAudio_Eject ============ */ void CDAudio_Eject (void) { DWORD dwReturn; if ((dwReturn = mciSendCommandA(wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, (DWORD)NULL))) Con_DPrintf ("MCI_SET_DOOR_OPEN failed (%i)\n", dwReturn); }
/* ============ CDAudio_CloseDoor ============ */ void CDAudio_CloseDoor (void) { DWORD dwReturn; if ((dwReturn = mciSendCommandA(wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD)NULL))) Con_DPrintf ("MCI_SET_DOOR_CLOSED failed (%i)\n", dwReturn); }
static void MCIWND_Close(MCIWndInfo* mwi) { MCI_GENERIC_PARMS mgp; memset(&mgp, 0, sizeof(mgp)); mciSendCommandA(mwi->mci, MCI_CLOSE, 0, (LPARAM)&mgp); }
/* ============ CDAudio_CloseDevice ============ */ void CDAudio_CloseDevice (void) { // JDH: restore original volume CDAudio_AccessVolume (&cd_initialvol, CDDA_SETVOL); if (mciSendCommandA (wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD) NULL)) Con_DPrintf ("CDAudio_Shutdown: MCI_CLOSE failed\n"); }
////////////////////////////////////////////////////////////////////// // mciOpenFileA(LPCSTR _szStr) // open a music file. szStr: Path of the file ////////////////////////////////////////////////////////////////////// DWORD MUSIC::OpenFile(LPCSTR _szStr) { MCIERROR mciERR = ERROR_SUCCESS; MCI_OPEN_PARMSA mci_p = {0}; mci_p.lpstrElementName = _szStr; mci_p.lpstrDeviceType = NULL; mci_p.dwCallback = (DWORD_PTR)m_dwCallBack; if (m_DID != MUSIC_ERROR) Close(); mciERR = mciSendCommandA( 0, MCI_OPEN, MCI_OPEN_SHAREABLE|MCI_NOTIFY|MCI_OPEN_ELEMENT, (DWORD_PTR)&mci_p); if (mciERR != ERROR_SUCCESS) { mciERR = mciSendCommandA( 0, MCI_OPEN, MCI_NOTIFY|MCI_OPEN_ELEMENT, (DWORD_PTR)&mci_p); } if (mciERR == ERROR_SUCCESS) { m_DID = mci_p.wDeviceID; // // Set time format with milliseconds // { MCI_SET_PARMS mci_p = {0}; mci_p.dwTimeFormat = MCI_FORMAT_MILLISECONDS; //DWORD dw = mciSendCommandW( m_DID, MCI_SET, MCI_NOTIFY|MCI_SET_TIME_FORMAT, (DWORD_PTR)&mci_p); } } return mciERR; }
static DWORD MCIWND_Get(MCIWndInfo* mwi, DWORD what) { MCI_DGV_STATUS_PARMSA mdsp; memset(&mdsp, 0, sizeof(mdsp)); mdsp.dwItem = what; if (mciSendCommandA(mwi->mci, MCI_STATUS, MCI_WAIT|MCI_STATUS_ITEM, (DWORD)&mdsp)) return 0; return mdsp.dwReturn; }
/* ============ CDAudio_StopDevice ============ */ qboolean CDAudio_StopDevice (void) { DWORD dwReturn; if ((dwReturn = mciSendCommandA(wDeviceID, MCI_STOP, 0, (DWORD)NULL))) { Con_DPrintf ("MCI_STOP failed (%i)", dwReturn); return false; } return true; }
/* ============ CDAudio_PauseDevice ============ */ qboolean CDAudio_PauseDevice (void) { DWORD dwReturn; MCI_GENERIC_PARMS mciGenericParms; mciGenericParms.dwCallback = (DWORD)mainwindow; if ((dwReturn = mciSendCommandA(wDeviceID, MCI_PAUSE, 0, (DWORD)(LPVOID)&mciGenericParms))) { Con_DPrintf ("MCI_PAUSE failed (%i)", dwReturn); return false; } return true; }
static DWORD MCIWND_GetStatus(MCIWndInfo* mwi) { MCI_DGV_STATUS_PARMSA mdsp; memset(&mdsp, 0, sizeof(mdsp)); mdsp.dwItem = MCI_STATUS_MODE; if (mciSendCommandA(mwi->mci, MCI_STATUS, MCI_WAIT|MCI_STATUS_ITEM, (DWORD)&mdsp)) return MCI_MODE_NOT_READY; if (mdsp.dwReturn == MCI_MODE_STOP && mwi->uTimer) { TRACE("Killing timer\n"); KillTimer(mwi->hWnd, 0); mwi->uTimer = 0; } return mdsp.dwReturn; }
// returns S_OK if the CD player is playing, S_FALSE otherwise (blocking) HRESULT IsPlayingImpl() { MCI_STATUS_PARMS mciStatusParams; mciStatusParams.dwItem = MCI_STATUS_MODE; DWORD dwError = mciSendCommandA(m_idDevice, MCI_STATUS, MCI_STATUS_ITEM, (UINT_PTR)&mciStatusParams); if (dwError) { char cbError[256]; mciGetErrorStringA(dwError, cbError, 256); debugf("Status:Mode failed for CD Audio device: %s\n", cbError); return E_FAIL; } return (mciStatusParams.dwReturn == MCI_MODE_PLAY) ? S_OK : S_FALSE; };
BOOL capmicaudio(char *szFile, int millisecs) { UINT wDeviceID; DWORD dwReturn; MCI_OPEN_PARMSA mciOpenParms; MCI_RECORD_PARMS mciRecordParms; MCI_SAVE_PARMSA mciSaveParms; MCI_PLAY_PARMS mciPlayParms; DWORD dwMilliSeconds; dwMilliSeconds = millisecs; // Open a waveform-audio device with a new file for recording. mciOpenParms.lpstrDeviceType = "waveaudio"; mciOpenParms.lpstrElementName = ""; if (dwReturn = mciSendCommand(0, MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE, (DWORD_PTR)(LPVOID) &mciOpenParms)) { // Failed to open device; don't close it, just return error. return (dwReturn); } // The device opened successfully; get the device ID. wDeviceID = mciOpenParms.wDeviceID; mciRecordParms.dwTo = dwMilliSeconds; if (dwReturn = mciSendCommand(wDeviceID, MCI_RECORD, MCI_TO | MCI_WAIT, (DWORD)(LPVOID) &mciRecordParms)) { mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD_PTR)0 ); return (dwReturn); } // Play the recording and query user to save the file. mciPlayParms.dwFrom = 0L; // Save the recording to a file. Wait for // the operation to complete before continuing. mciSaveParms.lpfilename = szFile; if (dwReturn = mciSendCommandA(wDeviceID, MCI_SAVE, MCI_SAVE_FILE | MCI_WAIT, (DWORD_PTR)(LPVOID) &mciSaveParms)) { mciSendCommand(wDeviceID, MCI_CLOSE, 0, (DWORD_PTR)0 ); return (dwReturn); } return (0L); }
/* ============ CDAudio_PlayTrack ============ */ qboolean CDAudio_PlayTrack (byte track, int length) { DWORD dwReturn; MCI_PLAY_PARMS mciPlayParms; mciPlayParms.dwFrom = MCI_MAKE_TMSF(track, 0, 0, 0); mciPlayParms.dwTo = (length << 8) | track; mciPlayParms.dwCallback = (DWORD)mainwindow; dwReturn = mciSendCommandA (wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO, (DWORD)(LPVOID)&mciPlayParms); if (dwReturn) { Con_DPrintf ("CDAudio: MCI_PLAY failed (%i)\n", dwReturn); return false; } return true; }
/* ============ CDAudio_ResumeDevice ============ */ qboolean CDAudio_ResumeDevice (void) { DWORD dwReturn; MCI_PLAY_PARMS mciPlayParms; mciPlayParms.dwFrom = MCI_MAKE_TMSF(playTrack, 0, 0, 0); mciPlayParms.dwTo = MCI_MAKE_TMSF(playTrack + 1, 0, 0, 0); mciPlayParms.dwCallback = (DWORD)mainwindow; dwReturn = mciSendCommandA (wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY, (DWORD)(LPVOID)&mciPlayParms); if (dwReturn) { Con_DPrintf ("CDAudio: MCI_PLAY failed (%i)\n", dwReturn); return false; } return true; }