( Index )
Month

Brief Information about the Sept 2001 CSIG Meeting

CopyRand - Copies MP3 and standard files --- 32 bit

3rd Tuesday of the month. 7:30PM - C/C++ Group, SPRS

Sample Output

Welcome to the C++ Users Group. This group is a "Special Interest Group" of the ACGNJ devoted to discussing programming languages in general and C, C++, and C++ for Windows programming in particular. Each month a small but hopefully useful program (complete with source code) is presented for discussion.

"COPYRAND" is a 32 bit command box program that copies a randomly selected group of files. If desired, it can also copy MP3 files based on music time.

Here's the situation: I've got hundreds of MP3 files that I've converted from my CD's and that I've downloaded from the Internet. I wanted to make (burn) a CDROM with a randomly selected assortment of those files. At first I created a utility to just randomly copy files from one place to another. This was not enough because you can never know how many files will fit on a CD. The solution was to enhance the program with enough knowledge to decipher the music times from the MP3 data file. Now you can issue a command to copy only 74 minutes of music. (Or 80 minutes, or whatever.)

This program will demonstrate some of the inner workings of the MP3 data format as well as normal 32 bit console programming. It works under Windows 95, 98, 98se, ME, NT, 2000, and XP.

At the meeting on Tuesday night we will be discussing the utility and the source code.


SAMPLE CODE
===========
for (i=k=t=0; i<nSource && i<nOutput; i++)
    {
    j = index.next();
    if (goalTime)
        {
        char activity[5] = "\\-/-";
        fprintf(stderr,"Searching ... %c\r",activity[i%4]);
        t = MP3Time(name[j]) + 2;               // allow 2 second gap.
        if ((t + accumTime) > goalTime) continue;
        if (t < 10) continue;
        printf("  Adding %2d:%02d for a total of %2d:%02d\n",
                                        t/60,t%60,(t+accumTime)/60,(t+accumTime)%60);
        }
    _splitpath( name[j], drive, dir, fname, ext );
    strcpy(target,absDest);
    if (target[strlen(target)-1] != '\\') strcat(target,"\\");
    strcat(target,fname);
    strcat(target,ext);

    printf("%-5d%s      ", k+1, addDots(name[j]));

    if (listFlg) {
        accumTime += t;
        puts("\n");
        continue;
        }

        if (isWin98())          // it’s Win95, 98, 98se, ME, etc.
            {
            if (CopyFile(name[j],target, false))
                { 
                puts("OK\n"); ++k; accumTime += t;
                }
            else
                {
                puts("Error");   PrintError(name[j]);
                }
            }
        else            // it’s WinNT, 2000, XP, etc.
            {
            if (CopyFileEx(
                    name[j],
                    target,
                    isWin98() ? NULL : dots,
                    NULL,   // to be passed to the callback function 
                    NULL,   // flag that can be used to cancel the operation 
                    0 ))      
                    { 
                    puts("OK\n"); ++k; accumTime += t;
                    }
            else
                    {
                    puts("Error");   PrintError(name[j]);
                    }
            }
        ClearReadOnly(target);
    }
fprintf(stderr,"                                        \n");
printf(" %d file(s) processed, %d successfully.\n",i,k);
if (goalTime) printf(" Accumulated time = %d:%02d\n",accumTime/60,accumTime%60);

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page