Exemple #1
0
        private void OnAudioRecordingFinished_(object sender, AudioRecorder.AudioRecordingFinishEventArgs e)
        {
            if (!Settings.Default.Audio_DisableSingleWavFileRecord)
            {
                if (m_RecordAndContinue_StopSingleFileRecord)
                {
                    m_RecordAndContinue_StopSingleFileRecord = false;
                    return;
                }
            }

            if (m_InterruptRecording)
            {
                m_RecordAndContinue  = false;
                m_InterruptRecording = false;
                checkAndAddDeferredRecordingDataItems();

                if (IsMonitoringAlways)
                {
                    CommandStartMonitor.Execute();
                }
                return;
            }

            if (!String.IsNullOrEmpty(e.RecordedFilePath))
            {
                registerRecordedAudioFileForDeferredAddition(e.RecordedFilePath);

                ////m_RecordAndContinue &&
                ////!Settings.Default.Audio_EnableSkippability
                //if (m_RecordAndContinue)
                //{

                //}
                //else
                //{
                //    openFile(e.RecordedFilePath, true, true, State.Audio.PcmFormatRecordingMonitoring);
                //}
            }

            if (m_RecordAndContinue)
            {
                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                {
#if DEBUG
                    DebugFix.Assert(IsRecording);
#endif
                }

                IsAutoPlay = false;

                Tuple <TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.GetTreeNodeSelection();
                TreeNode treeNode = treeNodeSelection.Item2 ?? treeNodeSelection.Item1;
                if (treeNode != null)
                {
                    //TreeNode next = electNextRecordableNode(treeNode);
tryNext:
                    //TreeNode nested;
                    //TreeNode next = TreeNode.GetNextTreeNodeWithNoSignificantTextOnlySiblings(false, treeNode, out nested);
                    TreeNode next = TreeNode.NavigatePreviousNextSignificantText(false, treeNode);
                    if (next != null)
                    {
                        TreeNode math = next.GetFirstAncestorWithXmlElement("math");
                        if (math != null)
                        {
                            next = math;
                        }
                        else
                        {
                            TreeNode svg = next.GetFirstAncestorWithXmlElement("svg");
                            if (svg != null)
                            {
                                next = svg;
                            }
                            else
                            {
                                TreeNode candidate = m_UrakawaSession.AdjustTextSyncGranularity(next, treeNode);
                                if (candidate != null)
                                {
                                    next = candidate;
                                }
                            }
                        }


                        if (Settings.Default.Audio_EnableSkippability && m_UrakawaSession.isTreeNodeSkippable(next))
                        {
                            treeNode = next;
                            goto tryNext;
                        }

                        m_StateToRestore = null;

                        m_UrakawaSession.PerformTreeNodeSelection(next, false, null); //nested);
                        State.Selection.ClearSelection();

                        //must appear after tree node selection!!!
                        m_RecordAndContinue = false;

                        if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                        {
                            //RaisePropertyChanged(() => State.Audio.PcmFormatRecordingMonitoring);

                            //if (EventAggregator != null)
                            //{
                            //    EventAggregator.GetEvent<StatusBarMessageUpdateEvent>().Publish(Tobi_Plugin_AudioPane_Lang.Recording);
                            //}
                            //PCMFormatInfo pcmFormatInfo = State.Audio.GetCurrentPcmFormat();
                            OnStateChanged_Recorder(null,
                                                    new AudioRecorder.StateChangedEventArgs(AudioRecorder.State.Stopped));
                        }
                        else
                        {
                            State.Audio.PcmFormatRecordingMonitoring = null;
                        }

                        Tuple <TreeNode, TreeNode> treeNodeSelectionNew = m_UrakawaSession.GetTreeNodeSelection();
                        TreeNode treeNodeNew = treeNodeSelectionNew.Item2 ?? treeNodeSelectionNew.Item1;
                        if (treeNodeNew != null)
                        {
                            //#if DEBUG
                            //                    DebugFix.Assert(treeNodeNew == next);
                            //#endif //DEBUG

                            if (treeNodeNew.GetManagedAudioMedia() == null &&
                                treeNodeNew.GetFirstDescendantWithManagedAudio() == null)
                            {
                                if (IsWaveFormLoading && View != null)
                                {
                                    View.CancelWaveFormLoad(true);
                                }

                                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                                {
                                    // NOOP
                                }
                                else
                                {
                                    CommandStartRecord.Execute();
                                }
                                return;
                            }
                            else
                            {
                                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                                {
                                    m_RecordAndContinue_StopSingleFileRecord = true;
                                    CommandStopRecord.Execute();
                                }

                                if (m_DeferredRecordingDataItems != null)
                                {
                                    checkAndAddDeferredRecordingDataItems();

                                    if (IsWaveFormLoading && View != null)
                                    {
                                        View.CancelWaveFormLoad(true);
                                    }

                                    m_UrakawaSession.PerformTreeNodeSelection(treeNodeSelectionNew.Item1, false, treeNodeSelectionNew.Item2);
                                }
                                //CommandPlay.Execute();

                                if (Settings.Default.Audio_Record_OverwriteFollowingAudio)
                                {
                                    CommandSelectAll.Execute();
                                    CommandStartRecord.Execute();
                                }
                            }
                        }
                        else
                        {
#if DEBUG
                            Debugger.Break();
#endif
                        }

                        if (IsMonitoringAlways && !IsMonitoring)
                        {
                            CommandStartMonitor.Execute();
                        }
                        return;
                    }
                }

                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                {
                    m_RecordAndContinue_StopSingleFileRecord = true;
                    CommandStopRecord.Execute();
                }
            }

            m_RecordAndContinue = false;
            checkAndAddDeferredRecordingDataItems();
            State.Audio.PcmFormatRecordingMonitoring = null;

            if (IsMonitoringAlways && !IsMonitoring)
            {
                CommandStartMonitor.Execute();
            }
        }
        private void CommandGenTTS_Execute()
        {
            string text;
            Dictionary <string, string> ttsVoiceMap = readTTSVoicesMapping(out text);

            bool cancelled = false;

            m_UrakawaSession.AutoSave_OFF();

            m_UrakawaSession.DocumentProject.Presentations.Get(0).UndoRedoManager.StartTransaction(Tobi_Plugin_AudioPane_Lang.GeneratingTTSAudio, Tobi_Plugin_AudioPane_Lang.CmdAudioGenTTS_LongDesc, COMMAND_TRANSATION_ID__AUDIO_TTS);
            try
            {
                CommandSelectAll.Execute();
                CommandDeleteAudioSelection.Execute();
                CommandRefresh.Execute();

                m_TTSGen = true;

                var converter = new AudioTTSGeneratorAutoAdvance(this, ttsVoiceMap);

                bool error = m_ShellView.RunModalCancellableProgressTask(true,
                                                                         Tobi_Plugin_AudioPane_Lang.GeneratingTTSAudio,
                                                                         converter,
                                                                         () =>
                {
                    Logger.Log(@"Audio TTS CANCELLED", Category.Debug, Priority.Medium);
                    cancelled = true;
                },
                                                                         () =>
                {
                    Logger.Log(@"Audio TTS DONE", Category.Debug, Priority.Medium);
                    cancelled = false;
                });

                if (cancelled)
                {
                    //DebugFix.Assert(!result);
                }

                if (converter.RequestCancellation) // Exception, not user-triggered
                {
                    cancelled = true;
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Debugger.Break();
#endif
                cancelled = true;
            }
            finally
            {
                m_TTSGen = false;
                m_UrakawaSession.AutoSave_ON();

                if (cancelled)
                {
                    m_UrakawaSession.DocumentProject.Presentations.Get(0).UndoRedoManager.CancelTransaction();

                    //TODO: waveform not refreshed !!

                    //m_LastSetPlayBytePosition = -1;

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

                    ////RefreshWaveFormChunkMarkersForCurrentSubTreeNode(false);

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

                    //if (AudioPlaybackStreamKeepAlive)
                    //{
                    //    ensurePlaybackStreamIsDead();
                    //}
                    //if (m_CurrentAudioStreamProvider() != null)
                    //{
                    //    m_StateToRestore = null;
                    //    CommandRefresh.Execute();
                    //}
                }
                else
                {
                    m_UrakawaSession.DocumentProject.Presentations.Get(0).UndoRedoManager.EndTransaction();
                }
            }
        }
Exemple #3
0
        //#endif

        private void initializeCommands_Recorder()
        {
            Stopwatch stopWatchRecorder = null;

            CommandStopRecordAndContinue = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStopRecordAndContinue_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStopRecordAndContinue_LongDesc,
                null,                                    // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("start-here"), //weather-clear-night -- emblem-symbolic-link
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStopRecordAndContinue", Category.Debug, Priority.Medium);

                if (stopWatchRecorder != null)
                {
                    stopWatchRecorder.Stop();
                    if (stopWatchRecorder.ElapsedMilliseconds <= 100)
                    {
                        Console.WriteLine("stopWatchRecorder.ElapsedMilliseconds<=100, skipping stop record");
                        stopWatchRecorder.Start();
                        return;
                    }
                    Console.WriteLine("stopWatchRecorder.ElapsedMilliseconds, elapsed record :" + stopWatchRecorder.ElapsedMilliseconds);
                }
                stopWatchRecorder = null;

                IsAutoPlay           = false;
                m_RecordAndContinue  = true;
                m_InterruptRecording = false;

                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                {
                    m_RecordAndContinue_StopBytePos = (long)m_Recorder.CurrentDurationBytePosition_BufferLookAhead;
                    OnAudioRecordingFinished(null,
                                             new AudioRecorder.AudioRecordingFinishEventArgs(
                                                 m_Recorder.RecordedFilePath));
                }
                else
                {
                    m_Recorder.StopRecording();

                    if (EventAggregator != null)
                    {
                        EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(Tobi_Plugin_AudioPane_Lang.RecordingStopped);
                    }
                }
                //ENABLE_SINGLE_RECORD_FILE
            },
                () =>
            {
                //Tuple<TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.GetTreeNodeSelection();

                return(!IsWaveFormLoading && IsRecording &&
                       m_UrakawaSession.DocumentProject != null);
            },
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StopRecordAndContinue));

            m_ShellView.RegisterRichCommand(CommandStopRecordAndContinue);
            //
            CommandStopRecord = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStopRecord_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStopRecord_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-playback-stop"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStopRecord", Category.Debug, Priority.Medium);

                if (stopWatchRecorder != null)
                {
                    stopWatchRecorder.Stop();
                    if (stopWatchRecorder.ElapsedMilliseconds <= 50)
                    {
                        Console.WriteLine("stopWatchRecorder.ElapsedMilliseconds<=50, skipping stop record");
                        stopWatchRecorder.Start();
                        return;
                    }
                    Console.WriteLine("stopWatchRecorder.ElapsedMilliseconds, elapsed record :" + stopWatchRecorder.ElapsedMilliseconds);
                }
                stopWatchRecorder = null;

                m_RecordAndContinue = false;
                m_Recorder.StopRecording();

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

                if (IsMonitoringAlways)
                {
                    CommandStartMonitor.Execute();
                }
            },
                () => !IsWaveFormLoading && IsRecording,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StartStopRecord));

            m_ShellView.RegisterRichCommand(CommandStopRecord);
            //
            CommandStartRecord = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStartRecord_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStartRecord_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-record"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStartRecord", Category.Debug, Priority.Medium);

                m_RecordAndContinue_StopBytePos = -1;

                if (stopWatchRecorder != null)
                {
                    Console.WriteLine("stopWatchRecorder != null, skipping start record");
                    return;
                }

                if (IsMonitoring)
                {
                    CommandStopMonitor.Execute();
                }

                IsAutoPlay = false;

                bool allowPlayPreview = false;

                m_punchInRecordOverSelection = false;
                if (IsPlaying)     // Punch-in recording
                {
                    SetRecordAfterPlayOverwriteSelection(-1);

                    m_punchInRecordOverSelection = true;

                    CommandPause.Execute();

                    CommandSelectRight.Execute();
                }
                else if (Settings.Default.Audio_Record_OverwriteFollowingAudio &&
                         !IsSelectionSet)
                {
                    SetRecordAfterPlayOverwriteSelection(-1);

                    m_punchInRecordOverSelection = true;

                    if (PlayBytePosition >= 0)
                    {
                        allowPlayPreview = true;

                        CommandSelectRight.Execute();
                    }
                    else
                    {
                        CommandSelectAll.Execute();
                    }
                }

                if (IsWaveFormLoading && View != null)
                {
                    View.CancelWaveFormLoad(true);
                }

                m_RecordAndContinue = false;

                if (m_UrakawaSession.DocumentProject == null)
                {
                    SetRecordAfterPlayOverwriteSelection(-1);

                    State.ResetAll();

                    State.Audio.PcmFormatRecordingMonitoring = new PCMFormatInfo();
                }
                else
                {
                    Tuple <TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.GetTreeNodeSelection();
                    if (treeNodeSelection.Item1 == null)
                    {
                        SetRecordAfterPlayOverwriteSelection(-1);

                        return;
                    }

                    if (!m_punchInRecordOverSelection || allowPlayPreview)     // let's check auto punch in/out based on audio selection
                    {
                        var bytesForRequiredOffsetTime =
                            m_UrakawaSession.DocumentProject.Presentations.Get(0).MediaDataManager.DefaultPCMFormat.
                            Data.ConvertTimeToBytes(150 * AudioLibPCMFormat.TIME_UNIT);
                        if (State.Selection.SelectionBeginBytePosition > 0 &&
                            PlayBytePosition >= 0 &&
                            PlayBytePosition < State.Selection.SelectionBeginBytePosition - bytesForRequiredOffsetTime)
                        {
                            AudioPlayer_PlayFromTo(PlayBytePosition, State.Selection.SelectionBeginBytePosition);
                            SetRecordAfterPlayOverwriteSelection(State.Selection.SelectionBeginBytePosition);
                            return;
                        }
                        else if (Settings.Default.Audio_EnablePlayPreviewBeforeRecord && m_RecordAfterPlayOverwriteSelection < 0 && PlayBytePosition > 0)
                        {
                            var playbackStartBytePos =
                                m_UrakawaSession.DocumentProject.Presentations.Get(0).MediaDataManager.DefaultPCMFormat.
                                Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_PlayPreviewTimeStep * 2 * AudioLibPCMFormat.TIME_UNIT);
                            playbackStartBytePos = PlayBytePosition - playbackStartBytePos;
                            if (playbackStartBytePos < 0)
                            {
                                playbackStartBytePos = 0;
                            }

                            SetRecordAfterPlayOverwriteSelection(State.Selection.SelectionBeginBytePosition > 0 ? State.Selection.SelectionBeginBytePosition : PlayBytePosition);
                            AudioPlayer_PlayFromTo(playbackStartBytePos, PlayBytePosition);
                            return;
                        }

                        SetRecordAfterPlayOverwriteSelection(-1);
                    }

                    DebugFix.Assert(m_UrakawaSession.DocumentProject.Presentations.Get(0).MediaDataManager.EnforceSinglePCMFormat);
                    State.Audio.PcmFormatRecordingMonitoring = m_UrakawaSession.DocumentProject.Presentations.Get(0).MediaDataManager.DefaultPCMFormat;
                }

                OnSettingsPropertyChanged(this, new PropertyChangedEventArgs(GetMemberName(() => Settings.Default.Audio_InputDevice)));

                stopWatchRecorder = Stopwatch.StartNew();
                m_Recorder.StartRecording(State.Audio.PcmFormatRecordingMonitoring.Copy().Data);

                RaisePropertyChanged(() => State.Audio.PcmFormatRecordingMonitoring);

                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(Tobi_Plugin_AudioPane_Lang.Recording);
                }
            },
                () =>
            {
                return((!IsMonitoring || IsMonitoringAlways) &&
                       !IsRecording &&
                       !IsWaveFormLoading &&  //!IsPlaying &&
                       canDeleteInsertReplaceAudio());
            },
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StartStopRecord));

            m_ShellView.RegisterRichCommand(CommandStartRecord);

            //
            //
            CommandStopMonitor = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStopMonitor_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStopMonitor_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-playback-stop"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStopMonitor", Category.Debug, Priority.Medium);

                m_Recorder.StopRecording();

                //AudioCues.PlayTockTock();

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

                State.Audio.PcmFormatRecordingMonitoring = null;
            },
                () => !IsWaveFormLoading &&
                IsMonitoring,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StartStopMonitor));

            m_ShellView.RegisterRichCommand(CommandStopMonitor);
            //

            CommandStartMonitor = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStartMonitor_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStartMonitor_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("audio-input-microphone"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStartMonitor", Category.Debug, Priority.Medium);

                m_RecordAndContinue_StopBytePos = -1;     // to avoid display of m_RecordAndContinue time stamp

                IsAutoPlay = false;

                if (m_UrakawaSession.DocumentProject == null)
                {
                    State.ResetAll();

                    State.Audio.PcmFormatRecordingMonitoring = new PCMFormatInfo();

                    //m_PcmFormatOfAudioToInsert = IsAudioLoaded ? State.Audio.PcmFormat : new PCMFormatInfo();
                    //m_Recorder.InputDevice.Capture.Caps.Format44KhzMono16Bit
                }
                else
                {
                    DebugFix.Assert(m_UrakawaSession.DocumentProject.Presentations.Get(0).MediaDataManager.EnforceSinglePCMFormat);
                    State.Audio.PcmFormatRecordingMonitoring = m_UrakawaSession.DocumentProject.Presentations.Get(0).MediaDataManager.DefaultPCMFormat;
                }

                OnSettingsPropertyChanged(this, new PropertyChangedEventArgs(GetMemberName(() => Settings.Default.Audio_InputDevice)));

                //AudioCues.PlayTock();

                m_Recorder.StartMonitoring(State.Audio.PcmFormatRecordingMonitoring.Copy().Data);

                RaisePropertyChanged(() => State.Audio.PcmFormatRecordingMonitoring);

                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(Tobi_Plugin_AudioPane_Lang.Monitoring);
                }
            },
                () => !IsWaveFormLoading &&
                !IsPlaying &&
                !IsRecording &&
                !IsMonitoring,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StartStopMonitor));

            m_ShellView.RegisterRichCommand(CommandStartMonitor);
            //

            CommandTogglePlayPreviewBeforeRecord = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioTogglePlayPreviewBeforeRecord_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioTogglePlayPreviewBeforeRecord_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadGnomeGionIcon("Gion_music-player"),
                () =>
            {
                Settings.Default.Audio_EnablePlayPreviewBeforeRecord =
                    !Settings.Default.Audio_EnablePlayPreviewBeforeRecord;

                RaisePropertyChanged(() => RecordPlayPreviewString);

                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(RecordPlayPreviewString
                                                                                     //Tobi_Plugin_AudioPane_Lang.AudioRecordPlayPreview + (Settings.Default.Audio_EnablePlayPreviewBeforeRecord ? " [ON]" : " [OFF]")
                                                                                     );
                }
            },
                () => true,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_TogglePlayPreviewBeforeRecord));

            m_ShellView.RegisterRichCommand(CommandTogglePlayPreviewBeforeRecord);
            //
            CommandToggleRecordOverwrite = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioToggleRecordOverwrite_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioToggleRecordOverwrite_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                null, //m_ShellView.LoadGnomeGionIcon("Gion_music-player"),
                () =>
            {
                Settings.Default.Audio_Record_OverwriteFollowingAudio =
                    !Settings.Default.Audio_Record_OverwriteFollowingAudio;

                RaisePropertyChanged(() => RecordOverwriteString);

                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(RecordOverwriteString
                                                                                     //Tobi_Plugin_AudioPane_Lang.AudioRecordOverwrite + (Settings.Default.Audio_Record_OverwriteFollowingAudio ? " [ON]" : " [OFF]")
                                                                                     );
                }
            },
                () => true,
                Settings_KeyGestures.Default,
                null //PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_TogglePlayPreviewBeforeRecord)
                );

            m_ShellView.RegisterRichCommand(CommandToggleRecordOverwrite);
            //
            CommandToggleSelectAfterRecord = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioToggleSelectAfterRecord_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioToggleSelectAfterRecord_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                null, //m_ShellView.LoadGnomeGionIcon("Gion_music-player"),
                () =>
            {
                Settings.Default.Audio_DisableAfterRecordSelection =
                    !Settings.Default.Audio_DisableAfterRecordSelection;

                RaisePropertyChanged(() => SelectAfterRecordString);

                if (EventAggregator != null)
                {
                    EventAggregator.GetEvent <StatusBarMessageUpdateEvent>().Publish(SelectAfterRecordString
                                                                                     //Tobi_Plugin_AudioPane_Lang.AudioSelectAfterRecord + (Settings.Default.Audio_DisableSelectAfterRecord ? " [OFF]" : " [ON]")
                                                                                     );
                }
            },
                () => true,
                Settings_KeyGestures.Default,
                null //PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_TogglePlayPreviewBeforeRecord)
                );

            m_ShellView.RegisterRichCommand(CommandToggleSelectAfterRecord);
        }
Exemple #4
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);
            //
        }