Skip to content

Commit

Permalink
Fix track searching and number of tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuanx committed Mar 11, 2023
1 parent c2aefcf commit df76e6c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ogg-winmm also provides separate volume control for CDDA/MIDI/WAVE, which has be
1. Rip the audio tracks from the CD and encode them to ogg files, following naming convention:
> **Track02.ogg, Track03.ogg, Track04.ogg, ...**
Note the file names can not contain any whitespace.
Note the file names can not contain any whitespace, and the track numbers must be contiguous without gap in the middle.

Also note the numbering usually starts from 02 since on mixed mode CDs the first track is a data track.

Expand Down Expand Up @@ -42,6 +42,10 @@ NOTE: It actually can also work on Win95/98 if you follow the extra procedure be

# Revisions:

v.2023.03.11
- Allow more than 1 data track before audio track.
- Fix total track number.

v.2023.02.28
- Improve time range precision from second to millisecond.
- Add compatibility support for Win95/98.
Expand Down
24 changes: 13 additions & 11 deletions ogg-winmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
strcat(music_path, "\\MUSIC");

dprintf("ogg-winmm music directory is %s\n", music_path);
dprintf("ogg-winmm searching tracks...\n");

memset(tracks, 0, sizeof(tracks));
unsigned int position = 0;
Expand All @@ -164,20 +163,21 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
if (tracks[i].length) {
dprintf("Track %02u: %02u:%02u:%03u @ %u ms\n", i, tracks[i].length / 60000, tracks[i].length / 1000 % 60, tracks[i].length % 1000, tracks[i].position);
if (!firstTrack) firstTrack = i;
numTracks = lastTrack = i;
lastTrack = i;
numTracks++;
position += tracks[i].length;
} else {
tracks[i].path[0] = '\0';
}

if (i != 1 && !tracks[i].length) break;
if (numTracks && !tracks[i].length) break;
}
dprintf("Emulating total of %d CD tracks.\n", numTracks);

if (numTracks) {
event = CreateEvent(NULL, FALSE, FALSE, NULL);
player = CreateThread(NULL, 0, player_main, NULL, 0, &thread);
dprintf("Created thread 0x%X\n\n", player);
dprintf("Creating thread 0x%X\n\n", player);
}
} else if (fdwReason == DLL_PROCESS_DETACH) {
#ifdef _DEBUG
Expand Down Expand Up @@ -263,10 +263,7 @@ MCIERROR WINAPI fake_mciSendCommandA(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR
case MCI_PLAY:
{
dprintf(" MCI_PLAY\n");
if (mode == MCI_MODE_PLAY) {
dprintf(" already playing\n");
break;
} else if (mode == MCI_MODE_PAUSE) {
if (mode == MCI_MODE_PAUSE) {
dprintf(" resume instead of new play\n");
mode = MCI_MODE_PLAY;
plr_resume();
Expand Down Expand Up @@ -349,6 +346,11 @@ MCIERROR WINAPI fake_mciSendCommandA(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR
}
} else if ((info.first && (fdwCommand & MCI_FROM)) || (info.last && (fdwCommand & MCI_TO))) {
if (event) {
if (mode != MCI_MODE_STOP) {
command = MCI_STOP;
plr_stop();
while (mode != MCI_MODE_STOP) Sleep(1);
}
command = MCI_PLAY;
SetEvent(event);
}
Expand Down Expand Up @@ -487,7 +489,7 @@ MCIERROR WINAPI fake_mciSendCommandA(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR
break;
case MCI_STATUS_NUMBER_OF_TRACKS:
dprintf(" MCI_STATUS_NUMBER_OF_TRACKS\n");
parms->dwReturn = numTracks;
parms->dwReturn = lastTrack; // including data tracks
break;
case MCI_STATUS_MODE:
dprintf(" MCI_STATUS_MODE\n");
Expand Down Expand Up @@ -668,8 +670,8 @@ MCIERROR WINAPI fake_mciSendStringA(LPCSTR cmd, LPSTR ret, UINT cchReturn, HANDL
if (strstr(cmdbuf, cmp_str)){
if (strstr(cmdbuf, "number of tracks"))
{
dprintf(" Returning number of tracks (%d)\n", numTracks);
sprintf(ret, "%d", numTracks);
dprintf(" Returning number of tracks (%d)\n", lastTrack);
sprintf(ret, "%u", lastTrack); // including data tracks
return 0;
}
int track = 0;
Expand Down
4 changes: 2 additions & 2 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void plr_stop()
if (plr_ev) {
SetEvent(plr_ev);
while (plr_bsy) {
Sleep(0);
Sleep(1);
}
}
}
Expand Down Expand Up @@ -192,7 +192,7 @@ int plr_pump()
WAVEHDR *hdr = &plr_hdr[plr_que];
if (waveOutPrepareHeader(plr_hw, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR || waveOutWrite(plr_hw, hdr, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
SetEvent(plr_ev);
Sleep(0);
Sleep(1);
break;
}
plr_sta[plr_que] = 0;
Expand Down

0 comments on commit df76e6c

Please sign in to comment.