Ejemplo n.º 1
0
        /// <summary>
        /// Plays or pauses the audio, depending on the VLC player's current state.
        /// </summary>
        private void playAudio()
        {
            using (MPAiModel DBModel = MPAiModel.InitializeDBModel())
            {
                Word    wd  = wordsList[currentRecordingIndex];
                Speaker spk = UserManagement.CurrentUser.Speaker;  // Get the speaker from user settings.
                Console.WriteLine(UserManagement.CurrentUser.Speaker.Name + " " + VoiceType.getDisplayNameFromVoiceType(UserManagement.CurrentUser.Voice));
                Recording rd = DBModel.Recording.Local.Where(x => x.WordId == wd.WordId && x.SpeakerId == spk.SpeakerId).SingleOrDefault();

                if (rd != null)
                {
                    ICollection <SingleFile> audios = rd.Audios;
                    if (audios == null || audios.Count == 0)
                    {
                        throw new Exception("No audio recording!");
                    }
                    SingleFile sf = audios.PickNext();
                    filePath = Path.Combine(sf.Address, sf.Name);

                    asyncPlay();
                    playButton.ImageIndex = 3;
                }
                else
                {
                    MPAiMessageBoxFactory.Show(invalidRecordingString);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateWordComboBox()
        {
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;
                    UserManagement.CurrentUser.setSpeakerFromVoiceType();

                    List <Word> view = DBModel.Word.Where(x => (
                                                              x.Category.Name.Equals(((Category)categoryComboBox.SelectedItem).Name) &&
                                                              x.Recordings.Any(y => y.Speaker.SpeakerId == UserManagement.CurrentUser.Speaker.SpeakerId)
                                                              )).ToList();

                    view.Sort(new VowelComparer());
                    WordComboBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    WordComboBox.DisplayMember = "Name";
                }
            }
            catch (Exception exp)
            {
                MPAiMessageBoxFactory.Show(dataLinkErrorText);
                Console.WriteLine(exp);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the categories from the database.
        /// </summary>
        private void populateCategoryComboBox()
        {
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;

                    List <Category> view = DBModel.Category.ToList();
                    view.Reverse();
                    categoryComboBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    categoryComboBox.DisplayMember = "Name";
                }
            }
            catch (Exception exp)
            {
                MPAiMessageBoxFactory.Show(dataLinkErrorText);
                Console.WriteLine(exp);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateBoxes()
        {
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;
                    Console.WriteLine(VoiceType.getDisplayNameFromVoiceType(current.Voice));

                    List <Word> view = DBModel.Word.Where(x => (
                                                              x.Category.Name.Equals("Word") &&
                                                              x.Recordings.Any(y => y.Speaker.SpeakerId == current.Speaker.SpeakerId)
                                                              )).ToList();

                    view.Sort(new VowelComparer());
                    WordComboBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    WordComboBox.DisplayMember = "Name";
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Ejemplo n.º 5
0
        public static bool IsFileNameCorrect(string fileName)
        {
            string[] parts = fileName.Split('-');

            MPAiModel DBModel = MPAiModel.InitializeDBModel();

            if (parts.Length < 4)
            {
                Console.WriteLine("Not enough Dashes");
                return(false);
            }

            if (!DBModel.IsSpeakerString(parts[0]))
            {
                Console.WriteLine("Speaker invalid");

                return(false);
            }

            if (!DBModel.IsCategoryString(parts[1]))
            {
                return(false);
            }

            if (!DBModel.IsWordString(parts[2]))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateBoxes()
        {
            // Stop playback and clear the boxes, to prevent errors.
            asyncStop();
            VowelComboBox.Items.Clear();
            soundListCurrentListBox.Items.Clear();
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;

                    List <Recording> videoView = DBModel.Recording.Where(x => (
                                                                             (x.Word.Category.Name.Equals("vowel")) &&        // If the category is vowel, and
                                                                             (current.Speaker.Name.Equals(x.Speaker.Name)) && // The speaker's gender matches the current user's gender, and
                                                                             ((x.Video != null) ||                            // There is a video of that speaker, or
                                                                              (x.VocalTract != null))                         // The recording has a vocaltract attached. (They are gender neutral, albeit with a male voice.)
                                                                             )).ToList();

                    wordsList = videoView;   // Take this action before display names are changed

                    // Lists of Recording objects, but only their name needs to be displayed to the user.
                    soundListAllListBox.DisplayMember     = "Name";
                    VowelComboBox.DisplayMember           = "Name";
                    soundListCurrentListBox.DisplayMember = "Name";

                    // Set the values in all the lists used by the program.
                    foreach (Recording rd in videoView)
                    {
                        // Adjust the display names of the recordings in the list, so they are human readable.
                        if (rd.Video != null)
                        {
                            rd.Name = DBModel.Word.SingleOrDefault(x => x.WordId == rd.WordId).Name + videoText;
                        }
                        else if (rd.VocalTract != null)
                        {
                            rd.Name = DBModel.Word.SingleOrDefault(x => x.WordId == rd.WordId).Name + vocalText;
                        }
                        soundListCurrentListBox.Items.Add(rd);
                        VowelComboBox.Items.Add(rd);
                    }

                    soundListAllListBox.DataSource = new BindingSource()
                    {
                        DataSource = videoView
                    };

                    selectItemInComboBox();
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Fills the database list box with all recordings in the database. Also used to refresh the list box.
 /// Can't be called in a using block
 /// </summary>
 private void populateListBox()
 {
     using (MPAiModel DBModel = new MPAiModel())
     {
         // Add all local database files to the list.
         List <SingleFile> view = DBModel.SingleFile.Where(x => x.Audio != null).ToList();
         onDBListBox.DataSource    = view;
         onDBListBox.DisplayMember = "Name";
     }
 }
Ejemplo n.º 8
0
 private MPAiModel InitializeDBModel(MPAiModel DBModel)
 {
     DBModel.Database.Initialize(false);
     DBModel.Recording.Load();
     DBModel.Speaker.Load();
     DBModel.Category.Load();
     DBModel.Word.Load();
     DBModel.SingleFile.Load();
     return(DBModel);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the words from the database.
        /// </summary>
        private void populateBoxes()
        {
            // Stop playback and clear the boxes, to prevent errors.
            asyncStop();
            WordComboBox.Items.Clear();
            soundListCurrentListBox.Items.Clear();
            try
            {
                // Create new database context.
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DBModel.Database.Initialize(false); // Added for safety; if the database has not been initialised, initialise it.

                    MPAiUser current = UserManagement.CurrentUser;

                    List <Word> view = DBModel.Word.Where(x => (
                                                              x.Category.Name.Equals("Word") &&
                                                              x.Recordings.Any(y => y.Speaker.SpeakerId == current.Speaker.SpeakerId) // Until the Menubar is finished, this won't work. Comment this line out to test.
                                                              )).ToList();

                    // Can't sort a control's Items field, so we sort a list and add values.
                    view.Sort(new VowelComparer());

                    // Lists of Word objects, but only their name needs to be displayed to the user.
                    soundListAllListBox.DisplayMember     = "Name";
                    WordComboBox.DisplayMember            = "Name";
                    soundListCurrentListBox.DisplayMember = "Name";

                    // Set the values in all the lists used by the program.
                    soundListAllListBox.DataSource = new BindingSource()
                    {
                        DataSource = view
                    };
                    foreach (Word wd in view)
                    {
                        soundListCurrentListBox.Items.Add(wd);
                        WordComboBox.Items.Add(wd);
                    }
                    wordsList = view;

                    selectItemInComboBox();
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Connects this program to the maintained database, and loads all relevant files.
 /// </summary>
 private void InitializeDB()
 {
     try
     {
         MPAiModel DBModel = new MPAiModel();
         DBModel.Database.Initialize(false);
         DBModel.Recording.Load();
         DBModel.Speaker.Load();
         DBModel.Category.Load();
         DBModel.Word.Load();
         DBModel.SingleFile.Load();
     }
     catch (Exception exp)
     {
         MPAiMessageBoxFactory.Show(exp.StackTrace, "Database linking error!");
         Console.WriteLine(exp.StackTrace);
     }
 }
Ejemplo n.º 11
0
        public void setSpeakerFromVoiceType()
        {
            using (MPAiModel DBModel = new MPAiModel())
            {
                InitializeDBModel(DBModel);

                if (voiceType.Gender.Equals(GenderType.MASCULINE) && voiceType.Language.Equals(LanguageType.NATIVE))
                {
                    speaker = DBModel.Speaker.Local.Where(x => x.SpeakerId == 2).SingleOrDefault();
                }
                else if (voiceType.Gender.Equals(GenderType.FEMININE) && voiceType.Language.Equals(LanguageType.NATIVE))
                {
                    speaker = DBModel.Speaker.Local.Where(x => x.SpeakerId == 1).SingleOrDefault();
                }
                else if (voiceType.Gender.Equals(GenderType.MASCULINE) && voiceType.Language.Equals(LanguageType.MODERN))
                {
                    speaker = DBModel.Speaker.Local.Where(x => x.SpeakerId == 4).SingleOrDefault();
                }
                else if (voiceType.Gender.Equals(GenderType.FEMININE) && voiceType.Language.Equals(LanguageType.MODERN))
                {
                    speaker = DBModel.Speaker.Local.Where(x => x.SpeakerId == 3).SingleOrDefault();
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Plays or pauses the video, depending on the VLC player's current state.
        /// </summary>
        private void playVideo()
        {
            using (MPAiModel DBModel = new MPAiModel())
            {
                // The word list only holds proxy objects, as it's context has closed. A database query is needed to get it's recordings.
                Recording rd  = DBModel.Recording.Find(wordsList[currentRecordingIndex].RecordingId);
                Speaker   spk = UserManagement.CurrentUser.Speaker; // Get the speaker from user settings.

                if (rd != null)                                     // If the recording exists
                {
                    SingleFile sf = null;
                    if (rd.Video != null)
                    {
                        sf = rd.Video;
                    }
                    else if (rd.VocalTract != null)
                    {
                        sf = rd.VocalTract;
                    }
                    if (sf == null)
                    {
                        asyncStop();
                        MPAiMessageBoxFactory.Show(noVideoString);
                        return;
                    }
                    filePath = Path.Combine(sf.Address, sf.Name);

                    asyncPlay();
                    playButton.ImageIndex = 3;
                }
                else
                {
                    MPAiMessageBoxFactory.Show(invalidRecordingString);
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Adds the selected items in the local list box to the database.
        /// </summary>
        /// <param name="sender">Automatically generated by Visual Studio.</param>
        /// <param name="e">Automatically generated by Visual Studio.</param>
        private void toDBButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (MPAiModel DBModel = new MPAiModel())
                {
                    DialogResult renameAction = MPAiMessageBoxFactory.Show(renamewarningText,
                                                                           warningText, MPAiMessageBoxButtons.OKCancel);
                    // If the user selected cancel, don't take any action.
                    if (renameAction.Equals(DialogResult.Cancel))
                    {
                        return;
                    }
                    foreach (FileInfo item in mediaLocalListBox.SelectedItems)  // For each selected item...
                    {
                        FileInfo workingFile = item;

                        // Need to rename file.
                        // If the user wanted to rename them themselves, take the same action as in SpeechRecognitionTest - automatically bring up rename.

                        if (!NameParser.IsFileNameCorrect(workingFile.Name))
                        {
                            // Back up the file to a temporary folder.
                            File.Copy(workingFile.FullName, Path.Combine(AppDataPath.Temp, "Rename_Backup"));

                            //Open the rename dialog
                            RenameFileDialog renameDialog = new RenameFileDialog(workingFile.FullName, true);
                            if (renameDialog.ShowDialog(this).Equals(DialogResult.OK))
                            {
                                // The old file has been changed to this.
                                FileInfo renamedFile = renameDialog.RenamedFile;
                                // Restore the old file, with old name intact, from the backup.
                                File.Move(Path.Combine(AppDataPath.Temp, "Rename_Backup"), workingFile.FullName);
                                // Continue the process with the new file name.
                                workingFile = renamedFile;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        // If the file follows convention (i.e. parts.length == 4), do nothing.

                        NameParser parser = new NameParser();
                        parser.FullName = workingFile.FullName;          // Put the name into the parser
                        // Set the parser address to the audio or video folder as appropriate.
                        if (parser.MediaFormat == "audio")
                        {
                            parser.Address = DirectoryManagement.AudioFolder;
                        }
                        else if (parser.MediaFormat == "video")
                        {
                            parser.Address = DirectoryManagement.VideoFolder;
                        }
                        // Get the file and add it to the database context.
                        DBModel.AddOrUpdateRecordingFile(parser.SingleFile);
                        // Copy the existing local file into the audio/video folder if it wasn't already there.
                        string existingFile = workingFile.FullName;
                        string newFile      = Path.Combine(parser.Address, workingFile.Name);
                        if (!existingFile.Equals(newFile))
                        {
                            File.Copy(existingFile, newFile, true);
                        }
                        DBModel.SaveChanges();
                    }
                }
                populateListBox();
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.StackTrace);
                MPAiMessageBoxFactory.Show(exp.StackTrace);
            }
            finally
            {
                File.Delete(Path.Combine(AppDataPath.Temp, "Rename_Backup"));
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Removes the selected items in the database list box from the database and the recordings folder.
        /// </summary>
        /// <param name="sender">Automatically generated by Visual Studio.</param>
        /// <param name="e">Automatically generated by Visual Studio.</param>
        private void toLocalButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (MPAiModel DBModel = new MPAiModel())
                {
                    // Creating a copy of the list box selected items to iterate through
                    List <SingleFile> selectedItemsCopy = new List <SingleFile>();
                    List <SingleFile> allItems          = DBModel.SingleFile.ToList(); // Avoid n+1 selects problem in the next for loop.
                    foreach (SingleFile sf in onDBListBox.SelectedItems)
                    {
                        SingleFile toAdd = allItems.Find(x => x.SingleFileId == sf.SingleFileId);
                        selectedItemsCopy.Add(toAdd);
                    }

                    // For each item in the database list box...
                    foreach (SingleFile sf in selectedItemsCopy)
                    {
                        Recording  rd    = null;
                        NameParser paser = new NameParser();
                        paser.FullName = sf.Name;       // Add the file to the Parser
                        // Use the parser to create the model objects.
                        if (paser.MediaFormat == "audio")
                        {
                            rd = sf.Audio;
                        }
                        else if (paser.MediaFormat == "video")
                        {
                            rd = sf.Video;
                        }
                        Speaker  spk          = rd.Speaker;
                        Word     word         = rd.Word;
                        Category cty          = word.Category;
                        string   existingFile = Path.Combine(sf.Address, sf.Name);
                        File.Delete(existingFile);      // Delete it,
                        DBModel.SingleFile.Remove(sf);  // And remove it from the database.

                        // If the deleted file was:
                        if (rd.Audios.Count == 0 && rd.Video == null)   // The last file attached to a recording, then delete the recording.
                        {
                            DBModel.Recording.Remove(rd);
                        }
                        if (spk.Recordings.Count == 0)                  // The last recording attached to a speaker, then delete the speaker.
                        {
                            DBModel.Speaker.Remove(spk);
                        }
                        if (word.Recordings.Count == 0)                 // The last recording attached to a word, then delete the word.
                        {
                            DBModel.Word.Remove(word);
                        }
                        if (cty.Words.Count == 0)                       // The last word attached to a category, then delete the category.
                        {
                            DBModel.Category.Remove(cty);
                        }
                        DBModel.SaveChanges();
                    }
                }
                populateListBox();
            }
            catch (Exception exp)
            {
                MPAiMessageBoxFactory.Show(exp.Message, deleteFailedText);
            }
        }