Esempio n. 1
0
 public void queueClip(QueuedMessage queuedMessage, PearlsOfWisdom.PearlType pearlType, double pearlMessageProbability)
 {
     if (queuedMessage.canBePlayed)
     {
         lock (queuedClips)
         {
             if (queuedClips.Contains(queuedMessage.messageName))
             {
                 Console.WriteLine("Clip for event " + queuedMessage.messageName + " is already queued, ignoring");
                 return;
             }
             else
             {
                 PearlsOfWisdom.PearlMessagePosition pearlPosition = PearlsOfWisdom.PearlMessagePosition.NONE;
                 if (pearlType != PearlsOfWisdom.PearlType.NONE && checkPearlOfWisdomValid(pearlType))
                 {
                     pearlPosition = pearlsOfWisdom.getMessagePosition(pearlMessageProbability);
                 }
                 if (pearlPosition == PearlsOfWisdom.PearlMessagePosition.BEFORE)
                 {
                     QueuedMessage pearlQueuedMessage = new QueuedMessage(queuedMessage.abstractEvent);
                     pearlQueuedMessage.dueTime = queuedMessage.dueTime;
                     queuedClips.Add(PearlsOfWisdom.getMessageFolder(pearlType), pearlQueuedMessage);
                 }
                 queuedClips.Add(queuedMessage.messageName, queuedMessage);
                 if (pearlPosition == PearlsOfWisdom.PearlMessagePosition.AFTER)
                 {
                     QueuedMessage pearlQueuedMessage = new QueuedMessage(queuedMessage.abstractEvent);
                     pearlQueuedMessage.dueTime = queuedMessage.dueTime;
                     queuedClips.Add(PearlsOfWisdom.getMessageFolder(pearlType), pearlQueuedMessage);
                 }
             }
         }
     }
 }
Esempio n. 2
0
 // checks that another pearl isn't already queued. If one of the same type is already
 // in the queue this method just returns false. If a conflicting pearl is in the queue
 // this method removes it and returns false, so we don't end up with, for example,
 // a 'keep it up' message in a block that contains a 'your lap times are worsening' message
 private Boolean checkPearlOfWisdomValid(PearlsOfWisdom.PearlType newPearlType)
 {
     Boolean isValid = true;
     if (queuedClips != null && queuedClips.Count > 0)
     {
         List<String> pearlsToPurge = new List<string>();
         foreach (String eventName in queuedClips.Keys)
         {
             if (clipIsPearlOfWisdom(eventName))
             {
                 Console.WriteLine("There's already a pearl in the queue, can't add another");
                 isValid = false;
                 if (eventName != PearlsOfWisdom.getMessageFolder(newPearlType))
                 {
                     pearlsToPurge.Add(eventName);
                 }
             }
         }
         foreach (String pearlToPurge in pearlsToPurge)
         {
             queuedClips.Remove(pearlToPurge);
             Console.WriteLine("Queue contains a pearl " + pearlToPurge + " which conflicts with " + newPearlType);
         }
     }
     return isValid;
 }
Esempio n. 3
0
        public void initialise()
        {
            if (soundFolderName.Length > 3 && (soundFolderName.Substring(1, 2) == @":\" || soundFolderName.Substring(1, 2) == @":/"))
            {
                soundFilesPath = soundFolderName;
            }
            else
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    soundFilesPath = Path.Combine(Path.GetDirectoryName(
                                            System.Reflection.Assembly.GetEntryAssembly().Location), @"..\", @"..\", soundFolderName);
                }
                else
                {
                    soundFilesPath = Path.Combine(Path.GetDirectoryName(
                                            System.Reflection.Assembly.GetEntryAssembly().Location), soundFolderName);
                }
            }

            voiceFolderPath = Path.Combine(soundFilesPath, "voice");
            fxFolderPath = Path.Combine(soundFilesPath, "fx");
            driverNamesFolderPath = Path.Combine(soundFilesPath, "driver_names");
            backgroundFilesPath = Path.Combine(soundFilesPath, "background_sounds");
            Console.WriteLine("Voice dir full path = " + voiceFolderPath);
            Console.WriteLine("FX dir full path = " + fxFolderPath);
            Console.WriteLine("driver names full path = " + driverNamesFolderPath);
            Console.WriteLine("Background sound dir full path = " + backgroundFilesPath);
            DirectoryInfo soundDirectory = new DirectoryInfo(soundFilesPath);
            if (!soundDirectory.Exists)
            {
                Console.WriteLine("Unable to find sound directory " + soundDirectory.FullName);
                return;
            }
            float soundPackVersion = getSoundPackVersion(soundDirectory);
            if (soundPackVersion == -1 || soundPackVersion == 0)
            {
                Console.WriteLine("Unable to get sound pack version - expected a file called version_info with a single line containing a version number, e.g. 2.0");
            }
            else if (soundPackVersion < minimumSoundPackVersion)
            {
                Console.WriteLine("The sound pack version in use is " + soundPackVersion + " but this version of the app requires version "
                    + minimumSoundPackVersion + " or greater.");
                Console.WriteLine("You must update your sound pack to run this application");
                return;
            }
            else
            {
                Console.WriteLine("Minimum sound pack version = " + minimumSoundPackVersion + " using sound pack version " + soundPackVersion);
            }
            pearlsOfWisdom = new PearlsOfWisdom();
            int soundsCount = 0;
            try
            {
                DirectoryInfo fxSoundDirectory = new DirectoryInfo(fxFolderPath);
                if (!fxSoundDirectory.Exists)
                {
                    Console.WriteLine("Unable to find fx directory " + fxSoundDirectory.FullName);
                    return;
                }
                FileInfo[] bleepFiles = fxSoundDirectory.GetFiles();
                String alternate_prefix = useAlternateBeeps ? "alternate_" : "";
                foreach (FileInfo bleepFile in bleepFiles)
                {
                    if (bleepFile.Name.EndsWith(".wav"))
                    {
                        if (bleepFile.Name.StartsWith(alternate_prefix + "start"))
                        {
                            enableStartBleep = true;
                            openAndCacheClip("start_bleep", bleepFile.FullName);
                        }
                        else if (bleepFile.Name.StartsWith(alternate_prefix + "end"))
                        {
                            enableEndBleep = true;
                            openAndCacheClip("end_bleep", bleepFile.FullName);
                        }
                        else if (bleepFile.Name.StartsWith(alternate_prefix + "short_start"))
                        {
                            enableEndBleep = true;
                            openAndCacheClip("short_start_bleep", bleepFile.FullName);
                        }
                        else if (bleepFile.Name.StartsWith("listen_start"))
                        {
                            openAndCacheClip("listen_start_sound", bleepFile.FullName);
                        }
                    }
                }
                DirectoryInfo voiceSoundDirectory = new DirectoryInfo(voiceFolderPath);
                if (!voiceSoundDirectory.Exists)
                {
                    Console.WriteLine("Unable to find voice directory " + voiceSoundDirectory.FullName);
                    return;
                }
                DirectoryInfo[] eventFolders = voiceSoundDirectory.GetDirectories();
                foreach (DirectoryInfo eventFolder in eventFolders)
                {
                    try
                    {
                        //Console.WriteLine("Got event folder " + eventFolder.Name);
                        DirectoryInfo[] eventDetailFolders = eventFolder.GetDirectories();
                        foreach (DirectoryInfo eventDetailFolder in eventDetailFolders)
                        {
                            //Console.WriteLine("Got event detail subfolder " + eventDetailFolder.Name);
                            String fullEventName = eventFolder + "/" + eventDetailFolder;
                            try
                            {
                                FileInfo[] soundFiles = eventDetailFolder.GetFiles();
                                foreach (FileInfo soundFile in soundFiles)
                                {
                                    if (soundFile.Name.EndsWith(".wav") && (sweary || !soundFile.Name.StartsWith("sweary")))
                                    {
                                        //Console.WriteLine("Got sound file " + soundFile.FullName);
                                        soundsCount++;
                                        openAndCacheClip(eventFolder + "/" + eventDetailFolder, soundFile.FullName);
                                        if (!enabledSounds.Contains(fullEventName))
                                        {
                                            enabledSounds.Add(fullEventName);
                                        }
                                    }
                                }
                                if (!enabledSounds.Contains(fullEventName))
                                {
                                    Console.WriteLine("Event " + fullEventName + " has no sound files");
                                }
                            }
                            catch (DirectoryNotFoundException)
                            {
                                Console.WriteLine("Event subfolder " + fullEventName + " not found");
                            }
                        }
                    }
                    catch (DirectoryNotFoundException)
                    {
                        Console.WriteLine("Unable to find events folder");
                    }
                }
                Console.WriteLine("Cached " + soundsCount + " clips");
                initialised = true;
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("Unable to find sounds directory - path: " + soundFolderName);
            }
        }