I recently purchased a new car and, obviously, it has been a long time since I had that experience. So it was a surprise to learn that you can no longer expect a car to have a CD player. Fortunately the car does have a USB port into which can be inserted a USB drive loaded with music files in various formats to be played through the car's audio system. I already had a large collection of music in MP3 format, having digitized my large vinyl record collection a few years ago; plus I also had a decent library of music I have downloaded over the years from various Internet sources. So after determining the structure I needed to load the music files into on the USB drive so that they would play and display correctly on the car's audio system, the OCD programmer in me turned to how I wanted to maintain the collection, which obviously would need to be updated from time to time.
First I created a directory on my desktop computer and assembled an initial collection of MP3 files that I wanted to have available in my car, including the contents of the CDs that I had in my old car. I already had some experience putting together collections of music files on CDs and USB drives, so I knew that I needed to have a mechanism to load the files in the order I wanted them to play in the car. Simply copying the directories to the USB drive with the Linux cp command (or dragging them over from a graphical file manager) would result in the files being loaded in alphabetical order; and they would play back in that order. Some of the directories of music contained digitized contents of a specific vinyl record, so I knew the order that the tracks were arranged in on the original vinyl and I wanted to maintain that order. Some directories were music I had downloaded from the Internet for a particular artist, and those I just wanted to load (and play) in a random order. So from those requirements, I had the design specification for the program I needed to write.
The parent directory of the music collection contains a file - folderlist.txt - which is a plain text file in which each line names a sub-directory from which music is to be loaded onto the USB drive. Each of the subdirectories contains a group of MP3 files related to a particular artist, or a similar grouping criteria. Those subdirectories that came from an actual vinyl (or CD) album also contain a file - playorder.txt - which is a plain text file in which each line names a file in the subdirectory containing music. When a subdirectory is processed, if there is a playorder.txt file, that is used to load the individual music files in the order they occur in the file. If there is not a playorder.txt file present, all the music files in the subdirectory are loaded in random order.
I had not gotten far in building the program until I realized I would be requiring occasional updates to the USB drive. I would need to add new subdirectories of music or replace subdirectories where I had added new tracks. From the start I had set up a fairly large collection of music to carry in the car, and it took some time for the program to cycle through the collection on my desktop computer and load it onto a newly formatted USB drive. So I added the function to specify a single subdirectory name on the command line to process, rather than process the entire collection each time I ran the program to update the USB drive. I also decided I wanted to remove and replace any existing directory on the USB drive before copying the contents from my desktop computer. And I wanted to remove any directory on the USB drive if there was not a corresponding directory in the folderlist.txt file; I set that up as an embedded, separate COBOL subprogram.
I have been very pleased with the way this program evolved, and it did evolve over a few weeks. And since I designed it as a well structured program, it was never difficult to add new functionality. Obviously I am working on a Linux desktop, but it should be relatively easy for anyone to modify it to work on a Windows system and also to use music formats other than mp3. So I have decided to add it to my little collection of programs here for anyone to use as they wish.
To install the source program, and compile it, execute the bash script: loadUSBMusicsetup [md5: 6cb502a374857770992fd1949f725f79]. Right click and save the script in the location where you want the source program to reside, then execute it. It will create a file containing the source program, then execute the GnuCOBOL compiler to compile it. The GnuCOBOL compiler must be installed prior to executing the bash script. You will need to modify the program to set proper Source and Target directories for your environment, and possibly to modify the extension for the type of audio files you intend to process.
This page was last updated on July 27, 2019.