#!/bin/csh ############################################################### # This script watches for CD insertion. When one is inserted, # it does the things the musicbox should do: # Kills any currently-playing song # If the CD is already in the catalog # Tell the user we recognize it # Start playing the CD from the hard drive # Eject the CD # Otherwise # Start ripping the songs to the directory # Ask the user where the songs should end up # Start playing the songs from temporary directory ############################################################## set device = '/dev/cdrom' # Start out in the right place. cd `musicbox_cds_directory.txt` ############################################################## # Media and existence checking # Say that we have no disc to start with, so we'll go if # there is one in the drive when we start. set had_disc_before = 0 while ( 1 ) # Find out the ID of the disc that is in the CD device. # Make sure that it is valid. set discid = `musicbox_get_disc_id.txt` # XXX We should check the drive itself to see if there # is a disc in it, rather than relying on this error # value. # If we don't have a disc, wait for a second, # and then go back and look again. if ( 0 != $status) then sleep 1 set had_disc_before = 0 continue endif # If we had a disc before, don't do anything because # it is probably still the same one. We need to wait # for the user to remove it (or a job to finish and # eject it). if ( 1 == $had_disc_before ) then sleep 1 continue; endif set had_disc_before = 1 # We have an inserted disc, so stop any currently-playing songs. musicbox_kill_playing_jobs.txt # See if we've already loaded this disc. If so, then # play it off the disc drive and eject the disc. set id_dir = `musicbox_cds_directory.txt`/by_id set newdir = "$id_dir"/"$discid" if ( -e "$newdir" ) then musicbox_interrupt_to_say.txt recognized_cd.wav # If this disc has not yet been cataloged, # then ask the user where the songs should end # up. set link = `musicbox_is_cd_linked.txt "$discid"` set is_one = `echo -n $link | wc -c` if ( 0 == $is_one) then musicbox_interrupt_to_say.txt uncataloged_cd.wav ( musicbox_play.txt "$newdir" >& /dev/null )& else musicbox_interrupt_to_say.txt `musicbox_say_directory_name "$link"` ( musicbox_play.txt "$link" >& /dev/null )& endif eject else # Delete any files in the temporary WAV playback # directory and then re-create the directory set playdir = /tmp/musicbox_wavplaydir \rm -rf "$playdir" mkdir "$playdir" # Put an ID file into the temporary play directory # that holds the ID of the disk that is playing, so # that the keyboard control program can know where # to link it in. echo "$discid" > "$playdir"/ID # Start ripping the songs to the directory in the background # and also have them go into the temporary play directory mkdir "$newdir" ( time musicbox_import_cd.txt "$id_dir" "$playdir"; eject >& /dev/null )& # Give it time to get ahead of us... sleep 3 # Ask the user where the songs should end up musicbox_interrupt_to_say.txt new_cd.wav # Start playing the songs from the play directory ( musicbox_play.txt "$playdir" >& /dev/null )& endif end