static void CD_f (void) { char *command; int ret; int n; if (Cmd_Argc() < 2) return; command = Cmd_Argv (1); if (Q_strcasecmp(command, "on") == 0) { enabled = true; return; } if (Q_strcasecmp(command, "off") == 0) { if (playing) CDAudio_Stop(); enabled = false; return; } if (Q_strcasecmp(command, "reset") == 0) { enabled = true; if (playing) CDAudio_Stop(); for (n = 0; n < 100; n++) remap[n] = n; CDAudio_GetAudioDiskInfo(); return; } if (Q_strcasecmp(command, "remap") == 0) { ret = Cmd_Argc() - 2; if (ret <= 0) { for (n = 1; n < 100; n++) if (remap[n] != n) Con_Printf(" %u -> %u\n", n, remap[n]); return; } for (n = 1; n <= ret; n++) remap[n] = Q_atoi(Cmd_Argv (n+1)); return; } if (Q_strcasecmp(command, "close") == 0) { CDAudio_CloseDoor(); return; } if (!cdValid) { CDAudio_GetAudioDiskInfo(); if (!cdValid) { Con_Printf("No CD in player.\n"); return; } } if (Q_strcasecmp(command, "play") == 0) { CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false); return; } if (Q_strcasecmp(command, "loop") == 0) { CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true); return; } if (Q_strcasecmp(command, "stop") == 0) { CDAudio_Stop(); return; } if (Q_strcasecmp(command, "pause") == 0) { CDAudio_Pause(); return; } if (Q_strcasecmp(command, "resume") == 0) { CDAudio_Resume(); return; } if (Q_strcasecmp(command, "eject") == 0) { if (playing) CDAudio_Stop(); CDAudio_Eject(); cdValid = false; return; } if (Q_strcasecmp(command, "info") == 0) { Con_Printf("%u tracks\n", maxTrack); if (playing) Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack); else if (wasPlaying) Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack); Con_Printf("Volume is %f\n", cdvolume); return; } }
static void CD_f (void) { const char *command; #ifdef MAXTRACKS int ret; int n; #endif command = Cmd_Argv (1); if (strcasecmp(command, "remap") != 0) Host_StartVideo(); if (strcasecmp(command, "on") == 0) { enabled = true; return; } if (strcasecmp(command, "off") == 0) { CDAudio_Stop(); enabled = false; return; } if (strcasecmp(command, "reset") == 0) { enabled = true; CDAudio_Stop(); #ifdef MAXTRACKS for (n = 0; n < MAXTRACKS; n++) *remap[n] = 0; // empty string, that is, unremapped #endif CDAudio_GetAudioDiskInfo(); return; } if (strcasecmp(command, "rescan") == 0) { CDAudio_Shutdown(); CDAudio_Startup(); return; } if (strcasecmp(command, "remap") == 0) { #ifdef MAXTRACKS ret = Cmd_Argc() - 2; if (ret <= 0) { for (n = 1; n < MAXTRACKS; n++) if (*remap[n]) Con_Printf(" %u -> %s\n", n, remap[n]); return; } for (n = 1; n <= ret; n++) strlcpy(remap[n], Cmd_Argv (n+1), sizeof(*remap)); #endif return; } if (strcasecmp(command, "close") == 0) { CDAudio_CloseDoor(); return; } if (strcasecmp(command, "play") == 0) { if (music_playlist_index.integer >= 0) return; CDAudio_Play_byName(Cmd_Argv (2), false, true, 0); return; } if (strcasecmp(command, "loop") == 0) { if (music_playlist_index.integer >= 0) return; CDAudio_Play_byName(Cmd_Argv (2), true, true, 0); return; } if (strcasecmp(command, "stop") == 0) { if (music_playlist_index.integer >= 0) return; CDAudio_Stop(); return; } if (strcasecmp(command, "pause") == 0) { if (music_playlist_index.integer >= 0) return; CDAudio_Pause(); return; } if (strcasecmp(command, "resume") == 0) { if (music_playlist_index.integer >= 0) return; CDAudio_Resume(); return; } if (strcasecmp(command, "eject") == 0) { if (faketrack == -1) CDAudio_Stop(); CDAudio_Eject(); cdValid = false; return; } if (strcasecmp(command, "info") == 0) { CDAudio_GetAudioDiskInfo (); if (cdValid) Con_Printf("%u tracks on CD.\n", maxTrack); else Con_Print ("No CD in player.\n"); if (cdPlaying) Con_Printf("Currently %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack); else if (wasPlaying) Con_Printf("Paused %s track %u\n", cdPlayLooping ? "looping" : "playing", cdPlayTrack); if (cdvolume >= 0) Con_Printf("Volume is %f\n", cdvolume); else Con_Printf("Can't get CD volume\n"); return; } Con_Printf("CD commands:\n"); Con_Printf("cd on - enables CD audio system\n"); Con_Printf("cd off - stops and disables CD audio system\n"); Con_Printf("cd reset - resets CD audio system (clears track remapping and re-reads disc information)\n"); Con_Printf("cd rescan - rescans disks in drives (to use another disc)\n"); Con_Printf("cd remap <remap1> [remap2] [remap3] [...] - chooses (possibly emulated) CD tracks to play when a map asks for a particular track, this has many uses\n"); Con_Printf("cd close - closes CD tray\n"); Con_Printf("cd eject - stops playing music and opens CD tray to allow you to change disc\n"); Con_Printf("cd play <tracknumber> - plays selected track in remapping table\n"); Con_Printf("cd loop <tracknumber> - plays and repeats selected track in remapping table\n"); Con_Printf("cd stop - stops playing current CD track\n"); Con_Printf("cd pause - pauses CD playback\n"); Con_Printf("cd resume - unpauses CD playback\n"); Con_Printf("cd info - prints basic disc information (number of tracks, currently playing track, volume level)\n"); }
static int CDAudio_GetAudioDiskInfo(void) { #if defined(__FreeBSD__) struct ioc_toc_header tochdr; #else struct cdrom_tochdr tochdr; #endif cdValid = false; #if defined(__FreeBSD__) if ( ioctl(cdfile, CDIOREADTOCHEADER, &tochdr) == -1 ) { Com_DPrintf("ioctl cdioreadtocheader failed\n"); #else if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 ) { Com_DPrintf("ioctl cdromreadtochdr failed\n"); #endif return -1; } #if defined(__FreeBSD__) if (tochdr.starting_track < 1) #else if (tochdr.cdth_trk0 < 1) #endif { Com_DPrintf("CDAudio: no music tracks\n"); return -1; } cdValid = true; #if defined(__FreeBSD__) maxTrack = tochdr.ending_track; #else maxTrack = tochdr.cdth_trk1; #endif return 0; } void CDAudio_Play(int track, qboolean looping) { #if defined(__FreeBSD__) struct ioc_read_toc_entry entry; struct cd_toc_entry toc_buffer; struct ioc_play_track ti; #else struct cdrom_tocentry entry; struct cdrom_ti ti; #endif if (cdfile == -1 || !enabled) return; if (!cdValid) { CDAudio_GetAudioDiskInfo(); if (!cdValid) return; } track = remap[track]; if (track < 1 || track > maxTrack) { Com_DPrintf("CDAudio: Bad track number %u.\n", track); return; } #if defined(__FreeBSD__) #define CDROM_DATA_TRACK 4 bzero((char *)&toc_buffer, sizeof(toc_buffer)); entry.data_len = sizeof(toc_buffer); entry.data = &toc_buffer; // don't try to play a non-audio track entry.starting_track = track; entry.address_format = CD_MSF_FORMAT; if ( ioctl(cdfile, CDIOREADTOCENTRYS, &entry) == -1 ) { Com_DPrintf("ioctl cdromreadtocentry failed\n"); return; } if (toc_buffer.control == CDROM_DATA_TRACK) #else // don't try to play a non-audio track entry.cdte_track = track; entry.cdte_format = CDROM_LBA; if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 ) { Com_DPrintf("ioctl cdromreadtocentry failed\n"); return; } if (entry.cdte_ctrl == CDROM_DATA_TRACK) #endif { Com_Printf("CDAudio: track %i is not audio\n", track); return; } if (playing) { if (playTrack == track) return; CDAudio_Stop(); } #if defined(__FreeBSD__) ti.start_track = track; ti.end_track = track; ti.start_index = 1; ti.end_index = 99; #else ti.cdti_trk0 = track; ti.cdti_trk1 = track; ti.cdti_ind0 = 0; ti.cdti_ind1 = 0; #endif #if defined(__FreeBSD__) if ( ioctl(cdfile, CDIOCPLAYTRACKS, &ti) == -1 ) #else if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 ) #endif { Com_DPrintf("ioctl cdromplaytrkind failed\n"); return; } #if defined(__FreeBSD__) if ( ioctl(cdfile, CDIOCRESUME) == -1 ) #else if ( ioctl(cdfile, CDROMRESUME) == -1 ) #endif Com_DPrintf("ioctl cdromresume failed\n"); playLooping = looping; playTrack = track; playing = true; if (cd_volume->value == 0.0) CDAudio_Pause (); } void CDAudio_Stop(void) { if (cdfile == -1 || !enabled) return; if (!playing) return; #if defined(__FreeBSD__) if ( ioctl(cdfile, CDIOCSTOP) == -1 ) Com_DPrintf("ioctl cdiocstop failed (%d)\n", errno); #else if ( ioctl(cdfile, CDROMSTOP) == -1 ) Com_DPrintf("ioctl cdromstop failed (%d)\n", errno); #endif wasPlaying = false; playing = false; } void CDAudio_Pause(void) { if (cdfile == -1 || !enabled) return; if (!playing) return; #if defined(__FreeBSD__) if ( ioctl(cdfile, CDIOCPAUSE) == -1 ) Com_DPrintf("ioctl cdiocpause failed\n"); #else if ( ioctl(cdfile, CDROMPAUSE) == -1 ) Com_DPrintf("ioctl cdrompause failed\n"); #endif wasPlaying = playing; playing = false; } void CDAudio_Resume(void) { if (cdfile == -1 || !enabled) return; if (!cdValid) return; if (!wasPlaying) return; #if defined(__FreeBSD__) if ( ioctl(cdfile, CDIOCRESUME) == -1 ) Com_DPrintf("ioctl cdiocresume failed\n"); #else if ( ioctl(cdfile, CDROMRESUME) == -1 ) Com_DPrintf("ioctl cdromresume failed\n"); #endif playing = true; } static void CD_f (void) { char *command; int ret; int n; if (Cmd_Argc() < 2) return; command = Cmd_Argv (1); if (Q_stricmp(command, "on") == 0) { enabled = true; return; } if (Q_stricmp(command, "off") == 0) { if (playing) CDAudio_Stop(); enabled = false; return; } if (Q_stricmp(command, "reset") == 0) { enabled = true; if (playing) CDAudio_Stop(); for (n = 0; n < 100; n++) remap[n] = n; CDAudio_GetAudioDiskInfo(); return; } if (Q_stricmp(command, "remap") == 0) { ret = Cmd_Argc() - 2; if (ret <= 0) { for (n = 1; n < 100; n++) if (remap[n] != n) Com_Printf(" %u -> %u\n", n, remap[n]); return; } for (n = 1; n <= ret; n++) remap[n] = atoi(Cmd_Argv (n+1)); return; } if (Q_stricmp(command, "close") == 0) { CDAudio_CloseDoor(); return; } if (!cdValid) { CDAudio_GetAudioDiskInfo(); if (!cdValid) { Com_Printf("No CD in player.\n"); return; } } if (Q_stricmp(command, "play") == 0) { CDAudio_Play((byte)atoi(Cmd_Argv (2)), false); return; } if (Q_stricmp(command, "loop") == 0) { CDAudio_Play((byte)atoi(Cmd_Argv (2)), true); return; } if (Q_stricmp(command, "stop") == 0) { CDAudio_Stop(); return; } if (Q_stricmp(command, "pause") == 0) { CDAudio_Pause(); return; } if (Q_stricmp(command, "resume") == 0) { CDAudio_Resume(); return; } if (Q_stricmp(command, "eject") == 0) { if (playing) CDAudio_Stop(); CDAudio_Eject(); cdValid = false; return; } if (Q_stricmp(command, "info") == 0) { Com_Printf("%u tracks\n", maxTrack); if (playing) Com_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack); else if (wasPlaying) Com_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack); Com_Printf("Volume is %f\n", cdvolume); return; } }
static void CD_f (void) { char *command; int ret; int n; if (Cmd_Argc() < 2) { Con_Printf("CD parameters:\n on\n off\n reset\n remap\n eject\n close\n play\n loop\n pause\n resume\n stop\n info\n"); // Manoel Kasimier return; } command = Cmd_Argv (1); if (Q_strcasecmp(command, "on") == 0) { Cvar_SetValue("cd_enabled", 1); // Manoel Kasimier - CD player in menu return; } if (Q_strcasecmp(command, "off") == 0) { if (playing) CDAudio_Stop(); Cvar_SetValue("cd_enabled", 0); // Manoel Kasimier - CD player in menu return; } if (Q_strcasecmp(command, "reset") == 0) { /* // Manoel Kasimier - Windows XP fix if (playing) CDAudio_Stop(); for (n = 0; n < 100; n++) remap[n] = n; CDAudio_GetAudioDiskInfo(); */ // Manoel Kasimier - Windows XP fix - begin CDAudio_Shutdown(); CDAudio_Init(); // Manoel Kasimier - Windows XP fix - end return; } if (Q_strcasecmp(command, "remap") == 0) { ret = Cmd_Argc() - 2; if (ret <= 0) { for (n = 1; n < 100; n++) if (remap[n] != n) Con_Printf(" %u -> %u\n", n, remap[n]); return; } for (n = 1; n <= ret; n++) remap[n] = Q_atoi(Cmd_Argv (n+1)); return; } // Manoel Kasimier - moved the "eject" command here so empty drives can be ejected if (Q_strcasecmp(command, "eject") == 0) { if (playing) CDAudio_Stop(); CDAudio_Eject(); cdValid = false; maxTrack = 0; // Manoel Kasimier - CD player in menu return; } if (Q_strcasecmp(command, "close") == 0) { CDAudio_CloseDoor(); Cbuf_AddText ("wait;cd reset\n", "cd reset"); // Manoel Kasimier - CD player in menu - auto-update CD status after closing drive door return; } if (Q_strcasecmp(command, "info") == 0) { // Manoel Kasimier - begin if (!maxTrack) Con_Printf("No CD in player.\n"); else { Con_Printf("%u tracks\n", maxTrack); if (!cdValid) Con_Printf("No audio tracks on disc\n"); else // List valid tracks { Con_Printf("Audio tracks on disc:\n"); for (n=1; n<=99; n++) if (audioTrack[n]) { if (!audioTrack[n+1]) // end of sequence, or isolated track Con_Printf(" %2i\n", n); else if (!audioTrack[n-1]) // beginning of sequence Con_Printf(" %2i -", n); } if (cd_enabled.value) { // Manoel Kasimier - end if (playing) Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack); else if (wasPlaying) Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack); // Manoel Kasimier - begin } } } if (!cd_enabled.value) Con_Printf("CD audio is off\n"); // Manoel Kasimier - end Con_Printf("Volume is %.1f\n", cdvolume); // Manoel Kasimier - edited return; } if (!cdValid) { CDAudio_GetAudioDiskInfo(); if (!cdValid) { // Manoel Kasimier - begin if (maxTrack) Con_Printf("No audio tracks on disc\n"); else // Manoel Kasimier - end Con_Printf("No CD in player.\n"); return; } } if (Q_strcasecmp(command, "play") == 0) { CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false); return; } if (Q_strcasecmp(command, "loop") == 0) { CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true); return; } if (Q_strcasecmp(command, "stop") == 0) { CDAudio_Stop(); return; } if (Q_strcasecmp(command, "pause") == 0) { CDAudio_Pause(); return; } if (Q_strcasecmp(command, "resume") == 0) { CDAudio_Resume(); return; } Con_Printf("CD parameters:\n on\n off\n reset\n remap\n eject\n close\n play\n loop\n pause\n resume\n stop\n info\n"); // Manoel Kasimier - absent/unrecognized parameter }