Beispiel #1
0
 public MPAiUser(string name, string code, VoiceType voiceType, bool admin, bool originalAdmin)
 {
     if (!admin && originalAdmin)
     {
         throw new ArgumentException("Cannot create a user who is not an admin but is an original admin.");
     }
     userName           = name;
     passWord           = code;
     Voice              = voiceType;
     this.isAdmin       = admin;
     this.originalAdmin = originalAdmin;
 }
Beispiel #2
0
        /// <summary>
        /// Method called by the button to show the  plot.
        /// If there is already a  plot running, it is brought into the foreground.
        /// If not, a new process is created.
        ///
        /// requestedPlotType determines if RunPlot runs a Vowel or Formant Plot.
        /// requestedVoiceType determines if we use heratage/ modern and masculine/feminine for the plots.
        /// </summary>
        public static void RunPlot(PlotType?requestedPlotType, VoiceType requestedVoiceType)
        {
            exitRequest = false;
            plotType    = requestedPlotType;
            voiceType   = requestedVoiceType;

            var deviceEnum = new MMDeviceEnumerator();
            var devices    = deviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToList();

            if (devices.Count == 0)
            {
                if (plotType == PlotType.VOWEL_PLOT)
                {
                    MPAiMessageBoxFactory.Show("No recording device detected.\nVowel Plot requires a working microphone to function correctly.\nPlease plug in Microphone, or update Drivers.");
                }
                else if (plotType == PlotType.FORMANT_PLOT)
                {
                    MPAiMessageBoxFactory.Show("No recording device detected.\nFormant Plot requires a working microphone to function correctly.\nPlease plug in Microphone or update Drivers.");
                }

                MPAiSoundMainMenu menu = new MPAiSoundMainMenu();
                menu.Show();
            }
            else
            {
                foreach (var process in Process.GetProcessesByName("MPAiVowelRunner"))
                {
                    process.Kill();
                    process.WaitForExit();
                    process.Dispose();
                }
                foreach (var process in Process.GetProcessesByName("MPAiPlotRunner"))
                {
                    process.Kill();
                    process.WaitForExit();
                    process.Dispose();
                }
                if (PlotStarted(GetPlotTitle()) == 1)
                {
                    StartPlot();
                }
                else
                {
                    ShowPlot(GetPlotTitle());
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Returns the display name for a voice type; this should be used when displaying voice type to the user.
 /// </summary>
 /// <param name="voiceType"></param>
 /// <returns></returns>
 public static string getDisplayNameFromVoiceType(VoiceType voiceType)
 {
     if (voiceType.Gender.Equals(GenderType.MASCULINE) && voiceType.Language.Equals(LanguageType.NATIVE))
     {
         return("Masculine, Kaumatua Māori");
     }
     else if (voiceType.Gender.Equals(GenderType.FEMININE) && voiceType.Language.Equals(LanguageType.NATIVE))
     {
         return("Feminine, Kuia Māori");
     }
     else if (voiceType.Gender.Equals(GenderType.MASCULINE) && voiceType.Language.Equals(LanguageType.MODERN))
     {
         return("Masculine, Modern Māori");
     }
     else if (voiceType.Gender.Equals(GenderType.FEMININE) && voiceType.Language.Equals(LanguageType.MODERN))
     {
         return("Feminine, Modern Māori");
     }
     return("No Voice Type");
 }
Beispiel #4
0
        /// <summary>
        /// Returns the appropriate string for the inputted VoiceType. This string is used for writing settings and
        /// underlying uses of voicetype; use GetDisplayName for displaying to user.
        /// </summary>
        /// <param name="voiceString">The enum to convert into a string.</param>
        public static string getStringFromVoiceType(VoiceType voiceType)
        {
            if (voiceType.Gender.Equals(GenderType.MASCULINE) && voiceType.Language.Equals(LanguageType.NATIVE))
            {
                return("MASCULINE_NATIVE");
            }
            else if (voiceType.Gender.Equals(GenderType.FEMININE) && voiceType.Language.Equals(LanguageType.NATIVE))
            {
                return("FEMININE_NATIVE");
            }
            else if (voiceType.Gender.Equals(GenderType.MASCULINE) && voiceType.Language.Equals(LanguageType.MODERN))
            {
                return("MASCULINE_MODERN");
            }
            else if (voiceType.Gender.Equals(GenderType.FEMININE) && voiceType.Language.Equals(LanguageType.MODERN))
            {
                return("FEMININE_MODERN");
            }

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// Writes all users to the settings file, and creates it if it does not already exist.
        /// </summary>
        public static void WriteSettings()
        {
            Int32 n = allUsers.Count;

            try
            {
                using (FileStream fs = new FileStream(GetSettingFilePath(), FileMode.Create))
                {
                    using (BinaryWriter writer = new BinaryWriter(fs))
                    {
                        writer.Write(n);
                        if (!(n == 0))
                        {
                            foreach (MPAiUser user in allUsers)
                            {
                                writer.Write(user.getName());
                                writer.Write(user.getCode());
                                writer.Write(VoiceType.getStringFromVoiceType(user.Voice));
                                writer.Write(user.IsAdmin);
                                writer.Write(user.OriginalAdmin);
                            }
                            if (CurrentUser == null)    // If there is a current user, store it.
                            {
                                writer.Write((Int32)(-1));
                            }
                            else
                            {
                                writer.Write((Int32)(allUsers.FindIndex(CurrentUser.Equals)));
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Opens the settings file and populates the allUsers field with the data found there.
        /// Also restores the last user to access the system to current user status.
        /// </summary>
        public static void ReadSettings()
        {
            try
            {
                using (FileStream fs = new FileStream(GetSettingFilePath(), FileMode.OpenOrCreate, FileAccess.Read))
                {
                    using (BinaryReader reader = new BinaryReader(fs))
                    {
                        if (new FileInfo(GetSettingFilePath()).Length != 0) // If the file wasn't just created
                        {
                            int n = reader.ReadInt32();
                            for (int i = 0; i < n; i++)
                            {
                                allUsers.Add(new MPAiUser(reader.ReadString(), reader.ReadString(), VoiceType.getVoiceTypeFromString(reader.ReadString()), reader.ReadBoolean(), reader.ReadBoolean()));
                            }
                            // restore the last used user, if there was one.

                            int index = reader.ReadInt32();
                            if (index >= 0 && index < allUsers.Count)
                            {
                                currentUser = allUsers[index];
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Beispiel #7
0
 public MPAiUser(string name, string code, VoiceType voiceType, bool admin) :
     this(name, code, voiceType, admin, false)
 {
 }
Beispiel #8
0
 /// <summary>
 /// Constructor for the MPAiUser class.
 /// </summary>
 /// <param name="name">The new user's username</param>
 /// <param name="code">The new user's password</param>
 public MPAiUser(string name, string code, VoiceType voiceType) :
     this(name, code, voiceType, false)
 {
 }