Exemple #1
0
        public void OnUndoRedoManagerChanged(UndoRedoManagerEventArgs eventt, bool done, Command command, bool isTransactionEndEvent, bool isNoTransactionOrTrailingEdge)
        {
            if (!TheDispatcher.CheckAccess())
            {
#if DEBUG
                Debugger.Break();
#endif

#if NET40x
                TheDispatcher.Invoke(DispatcherPriority.Normal,
                                     (Action <UndoRedoManagerEventArgs, bool, Command, bool, bool>)OnUndoRedoManagerChanged,
                                     eventt, done, command, isTransactionEndEvent, isNoTransactionOrTrailingEdge);
#else
                TheDispatcher.Invoke(DispatcherPriority.Normal,
                                     (Action)(() => OnUndoRedoManagerChanged(eventt, done, command, isTransactionEndEvent, isNoTransactionOrTrailingEdge))
                                     );
#endif
                return;
            }

            if (m_TTSGen)
            {
                return;
            }

            //if (isTransactionEndEvent)
            //{
            //    return;
            //}

            if (isNoTransactionOrTrailingEdge)
            {
                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(Tobi_Plugin_AudioPane_Lang.Ready);
                }
            }

            if (command is CompositeCommand)
            {
#if DEBUG
                Debugger.Break();
#endif
            }
            else if (command is TreeNodeChangeTextCommand)
            {
                if (!isTransactionEndEvent)
                {
                    var cmd = (TreeNodeChangeTextCommand)command;

                    Tuple <TreeNode, TreeNode> selection = m_UrakawaSession.GetTreeNodeSelection();
                    if (selection.Item1 != null)
                    {
                        if (cmd.TreeNode == selection.Item1 ||
                            (cmd.TreeNode.IsDescendantOf(selection.Item1)))
                        {
                            if (State.Audio.HasContent && State.Audio.PlayStreamMarkers != null)
                            {
                                if (true
                                    //State.Audio.PlayStreamMarkers.Count <= Settings.Default.AudioWaveForm_TextCacheRenderThreshold
                                    )
                                {
                                    if (View != null)
                                    {
                                        View.InvalidateWaveFormOverlay();
                                    }
                                }
                                else
                                {
                                    CommandRefresh.Execute();
                                }
                            }
                        }
                    }
                }

                return;
            }

            if (!(command is TextNodeStructureEditCommand) && !(command is AudioEditCommand))
            {
                return;
            }

            if (!isTransactionEndEvent)
            {
                if (View != null)
                {
                    View.CancelWaveFormLoad(false);
                }
                InterruptAudioPlayerRecorder();

                if (View != null)
                {
                    View.CancelWaveFormLoad(true);
                }
                CommandPause.Execute();


                updateTotalDuration(command, done);
            }

            if (command is TextNodeStructureEditCommand)
            {
                if (isNoTransactionOrTrailingEdge)
                {
                    // TODO: this is currently brute-force => refresh waveform correctly, depending on modified tree fragment (remove / insert)

                    if (View != null)
                    {
                        View.ResetAll();
                    }

                    if (AudioPlaybackStreamKeepAlive)
                    {
                        ensurePlaybackStreamIsDead();
                    }

                    State.ResetAll();

                    m_LastSetPlayBytePosition = -1;

                    m_StateToRestore = null;

                    //if (View != null)
                    //{
                    //    View.InvalidateWaveFormOverlay();
                    //}

                    //CommandRefresh.Execute();

                    var sel = m_UrakawaSession.GetTreeNodeSelection();
                    //m_UrakawaSession.PerformTreeNodeSelection(sel.Item1, sel.Item2)
                    var selOld = new Tuple <TreeNode, TreeNode>(null, null);
                    OnTreeNodeSelectionChanged(new Tuple <Tuple <TreeNode, TreeNode>, Tuple <TreeNode, TreeNode> >(selOld, sel));
                }

                return;
            }
            else if (command is AudioEditCommand)
            {
                if (!isTransactionEndEvent ||
                    isNoTransactionOrTrailingEdge && command.IsInTransaction() && command.TopTransactionId() == AudioPaneViewModel.COMMAND_TRANSATION_ID__AUDIO_TTS)
                {
                    OnUndoRedoManagerChanged_AudioEditCommand(eventt, done, (AudioEditCommand)command, isTransactionEndEvent, isNoTransactionOrTrailingEdge);
                }

                if (isNoTransactionOrTrailingEdge)
                {
                    if (m_OnUndoRedoManagerChanged_targetNode1 != null && m_OnUndoRedoManagerChanged_byteStart >= 0 && (!m_OnUndoRedoManagerChanged_done || m_OnUndoRedoManagerChanged_byteDur > 0))
                    {
                        bool deselectAndPosEnd = Settings.Default.Audio_DisableAfterRecordSelection &&
                                                 m_DeferredRecordingDataItems != null && // hack to detect actual recording operation, rather than REDO
                                                 m_OnUndoRedoManagerChanged_done && m_OnUndoRedoManagerChanged_wasInitByAdd;
                        UndoRedoManagerChanged_RestoreAudioTreeNodeSelectionState(m_OnUndoRedoManagerChanged_targetNode1, m_OnUndoRedoManagerChanged_targetNode2, m_OnUndoRedoManagerChanged_byteStart, m_OnUndoRedoManagerChanged_byteDur, m_OnUndoRedoManagerChanged_done, deselectAndPosEnd);

                        if (command.IsInTransaction() && command.TopTransactionId() == AudioPaneViewModel.COMMAND_TRANSATION_ID__AUDIO_SPLIT_SHIFT)
                        {
                            CommandClearSelection.Execute();
                        }

                        m_OnUndoRedoManagerChanged_targetNode1     = null;
                        m_OnUndoRedoManagerChanged_targetNode2     = null;
                        m_OnUndoRedoManagerChanged_byteStart       = -1;
                        m_OnUndoRedoManagerChanged_byteDur         = 0;
                        m_OnUndoRedoManagerChanged_done            = false;
                        m_OnUndoRedoManagerChanged_wasInitByRemove = false;
                        m_OnUndoRedoManagerChanged_wasInitByAdd    = false;
                    }
                    else
                    {
#if DEBUG
                        Debugger.Break();
#endif
                    }
                }

                return;
            }


#if DEBUG
            Debugger.Break();
#endif

            if (View != null)
            {
                View.ResetAll();
            }

            m_LastSetPlayBytePosition = 0;

            m_StateToRestore = null;

            if (AudioPlaybackStreamKeepAlive)
            {
                ensurePlaybackStreamIsDead();
            }

            CommandRefresh.Execute();
        }
Exemple #2
0
        private void initializeCommands_Selection()
        {
            CommandSelectPreviousChunk = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectPreviousChunk_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectPreviousChunk_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-previous"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectPreviousChunk", Category.Debug, Priority.Medium);

                CommandStepBack.Execute();

                SelectChunk(PlayBytePosition);
            },
                () => CommandStepBack.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectPreviousChunk));

            m_ShellView.RegisterRichCommand(CommandSelectPreviousChunk);
            //
            CommandSelectNextChunk = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectNextChunk_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectNextChunk_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-next"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectNextChunk", Category.Debug, Priority.Medium);

                CommandStepForward.Execute();

                SelectChunk(PlayBytePosition);
            },
                () => CommandStepForward.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectNextChunk));

            m_ShellView.RegisterRichCommand(CommandSelectNextChunk);
            //
            //
            CommandEndSelection = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioEndSelection_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioEndSelection_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                ScalableGreyableImageProvider.ConvertIconFormat((DrawingImage)Application.Current.FindResource("Horizon_Image_Right1")),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandEndSelection", Category.Debug, Priority.Medium);

                if (m_SelectionBeginTmpBytePosition < 0)
                {
                    return;
                }

                CommandPause.Execute();

                long begin = m_SelectionBeginTmpBytePosition;
                long end   = PlayBytePosition;

                AudioCues.PlayTockTock();

                if (begin == end)
                {
                    CommandClearSelection.Execute();
                    return;
                }

                if (begin > end)
                {
                    long tmp = begin;
                    begin    = end;
                    end      = tmp;
                }

                State.Selection.SetSelectionBytes(begin, end);

                if (IsAutoPlay)
                {
                    CommandPlay.Execute();
                }

                //if (IsAutoPlay)
                //{
                //    //if (!State.Audio.HasContent)
                //    //{
                //    //    return;
                //    //}

                //    //IsAutoPlay = false;
                //    //LastPlayHeadTime = begin;
                //    //IsAutoPlay = true;

                //    //long bytesFrom = State.Audio.ConvertMillisecondsToBytes(begin);
                //    //long bytesTo = State.Audio.ConvertMillisecondsToBytes(end);

                //    //AudioPlayer_PlayFromTo(bytesFrom, bytesTo);
                //}
            },
                () => CommandSelectAll.CanExecute()
                //CanManipulateWaveForm
                // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                // && State.Audio.HasContent
                && m_SelectionBeginTmpBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_EndSelection));

            m_ShellView.RegisterRichCommand(CommandEndSelection);
            //
            CommandBeginSelection = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioBeginSelection_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioBeginSelection_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                ScalableGreyableImageProvider.ConvertIconFormat((DrawingImage)Application.Current.FindResource("Horizon_Image_Left1")),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandBeginSelection", Category.Debug, Priority.Medium);

                //CommandPause.Execute();
                CommandClearSelection.Execute();

                m_SelectionBeginTmpBytePosition = PlayBytePosition;

                AudioCues.PlayTock();
            },
                () => CommandSelectLeft.CanExecute(),
                //CommandSelectAll.CanExecute()
                //         //CanManipulateWaveForm
                //         ////&& !IsWaveFormLoading && !IsRecording && !IsMonitorin
                //         //&& State.Audio.HasContent,
                //         && PlayBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_BeginSelection));

            m_ShellView.RegisterRichCommand(CommandBeginSelection);
            //
            CommandSelectLeft = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectLeft_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectLeft_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("format-indent-less"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectLeft", Category.Debug, Priority.Medium);

                if (PlayBytePosition <= 0)
                {
                    AudioCues.PlayBeep();
                    return;
                }

                State.Selection.SetSelectionBytes(0, PlayBytePosition);

                PlayBytePosition = State.Selection.SelectionEndBytePosition;

                //AudioCues.PlayTock();
            },
                () => CommandSelectAll.CanExecute()
                //CanManipulateWaveForm
                // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                // && State.Audio.HasContent
                && PlayBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectLeft));

            m_ShellView.RegisterRichCommand(CommandSelectLeft);
            //
            CommandSelectRight = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectRight_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioSelectRight_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("format-indent-more"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectRight", Category.Debug, Priority.Medium);

                if (PlayBytePosition >= State.Audio.DataLength)
                {
                    AudioCues.PlayBeep();
                    return;
                }

                State.Selection.SetSelectionBytes(PlayBytePosition, State.Audio.DataLength);
                //AudioCues.PlayTock();
            },
                () => CommandSelectLeft.CanExecute(),
                //CanManipulateWaveForm
                // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                // && State.Audio.HasContent && PlayBytePosition >= 0,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectRight));

            m_ShellView.RegisterRichCommand(CommandSelectRight);
            //
            CommandSelectAll = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdSelectAll_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdSelectAll_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("view-fullscreen"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandSelectAll", Category.Debug, Priority.Medium);

                //if (!State.Audio.HasContent)
                //{
                //    if (View != null)
                //    {
                //        View.SelectAll();
                //    }
                //    return;
                //}

                State.Selection.SetSelectionBytes(0, State.Audio.DataLength);

                //AudioCues.PlayTockTock();
            },
                () => CanManipulateWaveForm
                //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                && State.Audio.HasContent,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_SelectAll));

            m_ShellView.RegisterRichCommand(CommandSelectAll);
            //
            CommandClearSelection = new RichDelegateCommand(Tobi_Plugin_AudioPane_Lang.CmdAudioClearSelection_ShortDesc,
                                                            Tobi_Plugin_AudioPane_Lang.CmdAudioClearSelection_LongDesc,
                                                            null, // KeyGesture obtained from settings (see last parameters below)
                                                            m_ShellView.LoadTangoIcon("edit-clear"),
                                                            () =>
            {
                //Logger.Log("AudioPaneViewModel.CommandClearSelection", Category.Debug, Priority.Medium);

                State.Selection.ClearSelection();
            },
                                                            () => CommandSelectAll.CanExecute()
                                                            //CanManipulateWaveForm
                                                            // //&& !IsWaveFormLoading && !IsRecording && !IsMonitoring
                                                            // && State.Audio.HasContent
                                                            && IsSelectionSet,
                                                            Settings_KeyGestures.Default,
                                                            PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_ClearSelection));

            m_ShellView.RegisterRichCommand(CommandClearSelection);
            //
        }