Beispiel #1
0
 //@singleSection: this has to be triggered from derived classes as command execute has to be abstract
 protected void TriggerProgressChanged()
 {
     if (m_ProgressPercentage >= 0)
     {
         mView.TriggerProgressChangedEvent(ProjectView.ProjectView.ProgressBar_Command, m_ProgressPercentage);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Create the phrase detection command for list of phrases.
        /// </summary>
        public static CompositeCommand GetPhraseDetectionCommand(ProjectView.ProjectView view, List <PhraseNode> phraseNodesList,
                                                                 long threshold, double gap, double before, bool mergeFirstTwoPhrases)
        {
            CompositeCommand          command        = view.Presentation.CreateCompositeCommand(Localizer.Message("phrase_detection"));
            List <List <PhraseNode> > phrasesToMerge = new List <List <PhraseNode> >();
            int index = 0;

            if (phraseNodesList.Count > 0)
            {
                view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), 0);
            }

            for (int j = 0; j < phraseNodesList.Count; j++)
            {
                PhraseNode phrase = phraseNodesList[j];

                if (j == 0 ||
                    phraseNodesList[j].ParentAs <SectionNode>() != phraseNodesList[j - 1].ParentAs <SectionNode>())
                {
                    index = phrase.Index + 1;
                    Console.WriteLine("PH Section name " + phrase.ParentAs <SectionNode>().Label);
                }
                else
                {
                    int diff = phraseNodesList[j].Index - phraseNodesList[j - 1].Index - 1; // used -1 because the original phrase is deleted
                    index = index + diff;
                }
                System.Collections.Generic.List <PhraseNode> phrases = view.Presentation.CreatePhraseNodesFromAudioAssetList(
                    Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before));
                for (int i = 0; i < phrases.Count; ++i)
                {
                    // Copy page/heading role for the first phrase only
                    if (i == 0 || (phrase.Role_ != EmptyNode.Role.Page && phrase.Role_ != EmptyNode.Role.Heading))
                    {
                        phrases[i].CopyAttributes(phrase);
                    }
                    phrases[i].Used = phrase.Used;
                    phrases[i].TODO = phrase.TODO;
                    if (phrases[i].Role_ == EmptyNode.Role.Heading && i > 0)
                    {
                        phrases[i].Role_ = EmptyNode.Role.Plain;
                    }
                    Console.WriteLine("PH index: " + index);
                    // in following add node constructor, update selection is made false, to improve performance (19 may, 2010)
                    command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, phrases[i], phrase.ParentAs <SectionNode>(), index, false));
                    // add first 2 phrases to the list if the merge flag is true
                    if (phrases.Count >= 2 && mergeFirstTwoPhrases &&
                        phrases[0] is PhraseNode && phrases[1] is PhraseNode)
                    {
                        List <PhraseNode> mergeList = new List <PhraseNode>();
                        mergeList.Add(phrases[0]);
                        mergeList.Add(phrases[1]);
                        phrasesToMerge.Add(mergeList);
                    }

                    index++;
                }

                Commands.Node.Delete deleteCmd = new Commands.Node.Delete(view, phrase, false);
                command.ChildCommands.Insert(command.ChildCommands.Count, deleteCmd);//@singleSection: moved delete command last for improve undo selection

                if (Obi.Audio.PhraseDetection.CancelOperation)
                {
                    break;
                }

                /*
                 * // skip to next indexes if the two consequtive phrases in phrase list are not consequitive according to phrase index in the parent section
                 * if (j < phraseNodesList.Count - 1
                 *  && phrase.Index + 1 < phraseNodesList[j + 1].Index)
                 * {
                 *  EmptyNode empty = null;
                 *  for (int i = phrase.Index + 1; i < phraseNodesList[j + 1].Index; ++i)
                 *  {
                 *      empty = phrase.ParentAs<SectionNode>().PhraseChild(i);
                 *      command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.Delete(view, empty, false));
                 *      command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, empty, parent, index, false));
                 *      index++;
                 *  }
                 *  //index = index + (phraseNodesList[j + 1].Index - (phrase.Index + 1));
                 * }
                 */
                view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), (100 * j) / phraseNodesList.Count);
            }
            if (phrasesToMerge.Count > 0)
            {
                for (int i = 0; i < phrasesToMerge.Count; i++)
                {
                    List <PhraseNode>        mergeList = phrasesToMerge[i];
                    Commands.Node.MergeAudio mergeCmd  = new MergeAudio(view, mergeList[0], mergeList[1]);
                    mergeCmd.UpdateSelection = false;
                    command.ChildCommands.Insert(command.ChildCommands.Count, mergeCmd);
                }
            }
            return(command);
        }
Beispiel #3
0
        /// <summary>
        /// Create the phrase detection command.
        /// </summary>
        public static CompositeCommand GetPhraseDetectionCommand(ProjectView.ProjectView view, ObiNode node,
                                                                 long threshold, double gap, double before, bool mergeFirstTwoPhrases, ObiPresentation presentation = null)
        {
            List <PhraseNode> phraseNodesList = new List <PhraseNode> ();

            if (node is PhraseNode)
            {
                phraseNodesList.Add((PhraseNode)node);
            }
            else if (node is SectionNode)
            {
                SectionNode section = (SectionNode)node;
                for (int i = 0; i < section.PhraseChildCount; i++)
                {
                    if (section.PhraseChild(i) is PhraseNode && ((PhraseNode)section.PhraseChild(i)).Role_ != EmptyNode.Role.Silence)
                    {
                        phraseNodesList.Add((PhraseNode)section.PhraseChild(i));
                    }
                }
            }
            List <List <PhraseNode> > phrasesToMerge = new List <List <PhraseNode> >();
            CompositeCommand          command        = null;

            if (view.Presentation == null && presentation != null)
            {
                command = presentation.CreateCompositeCommand(Localizer.Message("phrase_detection"));
            }
            else
            {
                command = view.Presentation.CreateCompositeCommand(Localizer.Message("phrase_detection"));
            }

            // if phrase is selected but phrase detection node is section,select section
            if (node is SectionNode && view.GetSelectedPhraseSection != null &&
                view.GetSelectedPhraseSection == node)
            {
                command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(node, view.Selection.Control)));
            }

            ObiNode parent = node is SectionNode ? node : node.ParentAs <ObiNode> ();
            int     index  = 0;

            if (phraseNodesList.Count > 0)
            {
                view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), 0);
            }
            for (int j = 0; j < phraseNodesList.Count; j++)
            {
                PhraseNode phrase = phraseNodesList[j];

                if (j == 0)
                {
                    index = phrase.Index + 1;
                }
                System.Collections.Generic.List <PhraseNode> phrases = null;
                if (view.Presentation == null && presentation != null)
                {
                    phrases = presentation.CreatePhraseNodesFromAudioAssetList(
                        Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before));
                }
                else
                {
                    phrases = view.Presentation.CreatePhraseNodesFromAudioAssetList(
                        Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before));
                }
                for (int i = 0; i < phrases.Count; ++i)
                {
                    // Copy page/heading role for the first phrase only
                    if (i == 0 || (phrase.Role_ != EmptyNode.Role.Page && phrase.Role_ != EmptyNode.Role.Heading))
                    {
                        phrases[i].CopyAttributes(phrase);
                    }
                    phrases[i].Used = phrase.Used;
                    phrases[i].TODO = phrase.TODO;
                    if (i == 0 && phrase.TODO && (phrase as EmptyNode).CommentText != null)
                    {
                        (phrases[i] as EmptyNode).CommentText = (phrase as EmptyNode).CommentText;
                    }
                    if (phrases[i].Role_ == EmptyNode.Role.Heading && i > 0)
                    {
                        phrases[i].Role_ = EmptyNode.Role.Plain;
                    }

                    // in following add node constructor, update selection is made false, to improve performance (19 may, 2010)
                    command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, phrases[i], parent, index, false));
                    index++;
                }
                // add first 2 phrases to the list if the merge flag is true
                if (phrases.Count >= 2 && mergeFirstTwoPhrases &&
                    phrases[0] is PhraseNode && phrases [1] is PhraseNode)
                {
                    List <PhraseNode> mergeList = new List <PhraseNode>();
                    mergeList.Add(phrases[0]);
                    mergeList.Add(phrases[1]);
                    phrasesToMerge.Add(mergeList);
                }

                if (node is PhraseNode && phrases.Count > 0 && view.Selection != null)
                {
                    //command.append ( new UpdateSelection ( view, new NodeSelection ( node, view.Selection.Control ) ) );
                    command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(phrases[0], view.Selection.Control)));    //uncommenting this because unexecute for update selection can handle null unexecute now
                }
                Commands.Node.Delete deleteCmd = new Commands.Node.Delete(view, phrase, false);
                command.ChildCommands.Insert(command.ChildCommands.Count, deleteCmd);//@singleSection: moved delete command last for improve undo selection

                if (Obi.Audio.PhraseDetection.CancelOperation)
                {
                    break;
                }
                // skip to next indexes if the two consequtive phrases in phrase list are not consequitive according to phrase index in the parent section
                if (j < phraseNodesList.Count - 1 &&
                    phrase.Index + 1 < phraseNodesList[j + 1].Index)
                {
                    EmptyNode empty = null;
                    for (int i = phrase.Index + 1; i < phraseNodesList[j + 1].Index; ++i)
                    {
                        empty = phrase.ParentAs <SectionNode>().PhraseChild(i);
                        command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.Delete(view, empty, false));
                        command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, empty, parent, index, false));
                        index++;
                    }
                    //index = index + (phraseNodesList[j + 1].Index - (phrase.Index + 1));
                }
                view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), (100 * j) / phraseNodesList.Count);
            }
            if (phrasesToMerge.Count > 0)
            {
                for (int i = 0; i < phrasesToMerge.Count; i++)
                {
                    List <PhraseNode>        mergeList = phrasesToMerge[i];
                    Commands.Node.MergeAudio mergeCmd  = new MergeAudio(view, mergeList[0], mergeList[1]);
                    mergeCmd.UpdateSelection = false;
                    command.ChildCommands.Insert(command.ChildCommands.Count, mergeCmd);
                }
            }
            return(command);
        }