Пример #1
0
        private void PlayPreviewLeftRight(bool left)
        {
            Logger.Log(String.Format("AudioPaneViewModel.CommandPlayPreview ({0})",
                                     (left ? "before" : "after")), Category.Debug, Priority.Medium);

            CommandPause.Execute();

            long from = 0;
            long to   = 0;

            if (left)
            {
                from = Math.Max(0, PlayBytePosition - State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_PlayPreviewTimeStep * 2 * AudioLibPCMFormat.TIME_UNIT));
                to   = PlayBytePosition;
            }
            else
            {
                from = PlayBytePosition;
                to   = Math.Min(State.Audio.DataLength, PlayBytePosition + State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_PlayPreviewTimeStep * 2 * AudioLibPCMFormat.TIME_UNIT));
            }

            if (from == to)
            {
                return;
            }

            //if (verifyBeginEndPlayerValues(byteLeft, byteRight))
            //{
            //}
            AudioPlayer_PlayFromTo(from, to);

            State.Audio.EndOffsetOfPlayStream = left ? to : from;

            //DebugFix.Assert(State.Audio.EndOffsetOfPlayStream == (left ? to : from));
        }
Пример #2
0
        private void registerRecordedAudioFileForDeferredAddition(string filePath)
        {
            CommandPause.Execute();

            Tuple <TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.GetTreeNodeSelection();

            var data = new DeferredRecordingData
            {
                RecordedFilePath           = filePath,
                TreeNode1                  = treeNodeSelection.Item1,
                TreeNode2                  = treeNodeSelection.Item2,
                PlayBytePosition           = PlayBytePosition,
                SelectionBeginBytePosition = State.Selection.SelectionBeginBytePosition,
                SelectionEndBytePosition   = State.Selection.SelectionEndBytePosition,
            };

            if (!Settings.Default.Audio_DisableSingleWavFileRecord)
            {
                data.RecordAndContinue_StopBytePos = m_RecordAndContinue ? m_RecordAndContinue_StopBytePos : -1;
            }

            if (m_DeferredRecordingDataItems == null)
            {
                m_DeferredRecordingDataItems = new List <DeferredRecordingData>();
            }
            m_DeferredRecordingDataItems.Add(data);
        }
Пример #3
0
        public void AudioPlayer_LoadAndPlayFromFile(string path)
        {
            Logger.Log("AudioPaneViewModel.AudioPlayer_LoadAndPlayFromFile", Category.Debug, Priority.Medium);

            CommandPause.Execute();
            //if (m_Player.CurrentState != AudioPlayer.State.NotReady
            //    && !IsStopped)
            //{
            //    //m_Player.Stop();
            //}

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

            if (AudioPlaybackStreamKeepAlive)
            {
                ensurePlaybackStreamIsDead();
            }

            State.ResetAll();

            m_LastSetPlayBytePosition = 0;
            //IsWaveFormLoading = false;

            State.FilePath = path;

            m_CurrentAudioStreamProvider = m_AudioStreamProvider_File;

            if (m_CurrentAudioStreamProvider() == null)
            {
                State.ResetAll();

                m_LastSetPlayBytePosition = -1;
                //IsWaveFormLoading = false;
                return;
            }

            if (View != null)
            {
                View.RefreshUI_PeakMeterBlackout(true);
                //View.ResetPeakLines();
            }

            PeakOverloadCountCh1 = 0;
            PeakOverloadCountCh2 = 0;

            //#if DEBUG
            //            Logger.Log("CALLING AudioPlayer_LoadWaveForm (loadAndPlay) FILE", Category.Debug, Priority.Medium);
            //#endif
            AudioPlayer_LoadWaveForm(false);
        }
Пример #4
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();
        }
Пример #5
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);
        }
Пример #6
0
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        Command result;

        JObject jo = JObject.Load(reader);

        if (!Enum.TryParse((string)jo["Type"], out Command.Type commandType))
        {
            Debug.LogError($"CommandType {jo["Type"]} not recognized in {jo}");
            return(new CommandNone());
        }

        switch (commandType)
        {
        case (Command.Type.Break):
            result = new CommandBreak();
            break;

        case (Command.Type.Call):
            result = new CommandCall();
            break;

        case (Command.Type.Conditional):
            result = new CommandConditional();
            break;

        case (Command.Type.Consume):
            result = new CommandConsume();
            break;

        case (Command.Type.Continue):
            result = new CommandContinue();
            break;

        case (Command.Type.Debug):
            result = new CommandDebug();
            break;

        case (Command.Type.Dialog):
            result = new CommandDialog();
            break;

        case (Command.Type.Dialogue):
            result = new CommandDialogue();
            break;

        case (Command.Type.Event):
            result = new CommandEvent();
            break;

        case (Command.Type.EventEnd):
            result = new CommandEventEnd();
            break;

        case (Command.Type.Flush):
            result = new CommandFlush();
            break;

        case (Command.Type.GotoLocation):
            result = new CommandGotoLocation();
            break;

        case (Command.Type.Interrupt):
            result = new CommandInterrupt();
            break;

        case (Command.Type.ItemAdd):
            result = new CommandItemAdd();
            break;

        case (Command.Type.ItemRemove):
            result = new CommandItemRemove();
            break;

        case (Command.Type.NoteAdd):
            result = new CommandNoteAdd();
            break;

        case (Command.Type.NoteRemove):
            result = new CommandNoteRemove();
            break;

        case (Command.Type.Outfit):
            result = new CommandOutfit();
            break;

        case (Command.Type.OutfitManage):
            result = new CommandOutfitManage();
            break;

        case (Command.Type.Pause):
            result = new CommandPause();
            break;

        case (Command.Type.Services):
            result = new CommandServices();
            break;

        case (Command.Type.Set):
            result = new CommandSet();
            break;

        case (Command.Type.Shop):
            result = new CommandShop();
            break;

        case (Command.Type.Sleep):
            result = new CommandSleep();
            break;

        case (Command.Type.TimePass):
            result = new CommandTimePass();
            break;

        case (Command.Type.None):
        default:
            result = new CommandNone();
            break;
        }

        serializer.Populate(jo.CreateReader(), result);

        return(result);

        /*if (reader.TokenType == JsonToken.Null)
         *  return new CText();
         *
         * if (reader.TokenType == JsonToken.StartObject)
         * {
         *  //https://stackoverflow.com/questions/35586987/json-net-custom-serialization-with-jsonconverter-how-to-get-the-default-beha
         *  existingValue = existingValue ?? serializer.ContractResolver.ResolveContract(objectType).DefaultCreator();
         *  serializer.Populate(reader, existingValue);
         *  return existingValue;
         * }
         *
         * if (reader.TokenType == JsonToken.String)
         *  return new CText((string)reader.Value);
         *
         */
        //throw new JsonSerializationException();
    }
Пример #7
0
 public void ProccessData(JObject dataPairs)
 {
     if (dataPairs.ContainsKey("changeDirection"))
     {
         map.changeSnakeDirection(int.Parse(dataPairs["snakeId"].ToString()), Map.getDirection(dataPairs["changeDirection"].ToString()));
     }
     else if (dataPairs.ContainsKey("serverAddress"))
     {
         AddMessage($"Connected to server {dataPairs["serverAddress"]}");
         map.snakeId = int.Parse(dataPairs["snakeId"].ToString());
     }
     else if (dataPairs.ContainsKey("powerUp"))
     {
         map.addFood(int.Parse(dataPairs["powerUp"]["x"].ToString()),
                     int.Parse(dataPairs["powerUp"]["y"].ToString()),
                     bool.Parse(dataPairs["powerUp"]["isBuff"].ToString()),
                     (Objects.PowerUps.PowerUpType) int.Parse(dataPairs["powerUp"]["powerUpType"].ToString()), int.Parse(dataPairs["powerUp"]["random"].ToString()));
     }
     else if (dataPairs.ContainsKey("message"))
     {
         AddMessage(dataPairs["message"].ToString());
     }
     else if (dataPairs.ContainsKey("gameStart"))
     {
         form.gameStart();
     }
     else if (dataPairs.ContainsKey("syncSnakes"))
     {
         map.Snakes = System.Text.Json.JsonSerializer.Deserialize <List <SnakeBody> >(dataPairs["syncSnakes"].ToString());
         map.Scores = new List <Score>();
         for (int i = 0; i < map.Snakes.Count; i++)
         {
             map.Scores.Add(new Score(i, 0));
         }
     }
     else if (dataPairs.ContainsKey("pauseGame"))
     {
         Command command = new CommandPause(map);
         Invoker invoker = new Invoker();
         invoker.SetCommand(command);
         if (map.gameState is Started)
         {
             invoker.ExecuteCommand();
         }
         else
         {
             invoker.Undo();
         }
     }
     else if (dataPairs.ContainsKey("saveState"))
     {
         map.SaveSnakesState();
     }
     else if (dataPairs.ContainsKey("restoreState"))
     {
         map.RestoreSnakesState();
     }
     else if (dataPairs.ContainsKey("sayCommand"))
     {
         AddMessage(dataPairs["sayCommand"].ToString());
     }
 }
Пример #8
0
        private void initializeCommands_Navigation()
        {
            CommandGotoBegining = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoBegin_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoBegin_LongDesc,
                null,    // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-first"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandGotoBegining", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                if (PlayBytePosition == 0)
                {
                    AudioCues.PlayBeep();
                }
                else
                {
                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = 0;
                }
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GotoBegin));

            m_ShellView.RegisterRichCommand(CommandGotoBegining);
            //
            CommandGotoEnd = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoEnd_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioGotoEnd_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("go-last"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandGotoEnd", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                if (PlayBytePosition == State.Audio.DataLength)
                {
                    AudioCues.PlayBeep();
                }
                else
                {
                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = State.Audio.DataLength;
                }
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GotoEnd));

            m_ShellView.RegisterRichCommand(CommandGotoEnd);
            //
            CommandStepBack = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepBack_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepBack_LongDesc,
                null,  // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-skip-backward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStepBack", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long bytesLeftPrevious = -1;

                State.Audio.FindInPlayStreamMarkersAndDo(PlayBytePosition,
                                                         (bytesLeft, bytesRight, markerTreeNode, index)
                                                         =>
                {
                    if (bytesLeftPrevious == -1)
                    {
                        if (IsAutoPlay)
                        {
                            State.Selection.ClearSelection();
                        }

                        PlayBytePosition = bytesLeft;
                        AudioCues.PlayBeep();
                        return(-1);
                    }

                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = bytesLeftPrevious;

                    return(-1);
                }
                                                         ,
                                                         (bytesToMatch_, bytesLeft, bytesRight, markerTreeNode)
                                                         =>
                {
                    bytesLeftPrevious = bytesLeft;
                    return(bytesToMatch_);
                }
                                                         );
            },
                () => !IsWaveFormLoading &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways) &&
                State.Audio.HasContent && State.Audio.PlayStreamMarkers != null && State.Audio.PlayStreamMarkers.Count > 1,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StepBack));

            m_ShellView.RegisterRichCommand(CommandStepBack);
            //
            CommandStepForward = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepForward_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioStepForward_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-skip-forward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandStepForward", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long bytesRight;
                long bytesLeft;
                int index;
                TreeNode subTreeNode;
                bool match = State.Audio.FindInPlayStreamMarkers(PlayBytePosition, out subTreeNode, out index, out bytesLeft, out bytesRight);

                if (match)
                {
                    if (index == State.Audio.PlayStreamMarkers.Count - 1)
                    {
                        AudioCues.PlayBeep();
                        return;
                    }

                    if (IsAutoPlay)
                    {
                        State.Selection.ClearSelection();
                    }

                    PlayBytePosition = bytesRight;
                }
                else
                {
                    Debug.Fail("audio chunk not found ??");

                    AudioCues.PlayBeep();
                }
            },
                () => CommandStepBack.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_StepForward));

            m_ShellView.RegisterRichCommand(CommandStepForward);
            //
            CommandFastForward = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForward_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForward_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-forward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandFastForward", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newBytesPosition = PlayBytePosition + State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStep * AudioLibPCMFormat.TIME_UNIT);
                if (newBytesPosition > State.Audio.DataLength)
                {
                    newBytesPosition = State.Audio.DataLength;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newBytesPosition;
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                (!IsMonitoring || IsMonitoringAlways) &&
                !IsRecording,
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoForward));

            m_ShellView.RegisterRichCommand(CommandFastForward);
            //
            CommandRewind = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewind_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewind_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-backward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandRewind", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newTimeBytePosition = PlayBytePosition - State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStep * AudioLibPCMFormat.TIME_UNIT);
                if (newTimeBytePosition < 0)
                {
                    newTimeBytePosition = 0;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newTimeBytePosition;
            },
                () => !IsWaveFormLoading &&
                State.Audio.HasContent &&
                !IsRecording &&
                (!IsMonitoring || IsMonitoringAlways),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoBack));

            m_ShellView.RegisterRichCommand(CommandRewind);
            //
            CommandFastForwardX = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForwardX_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioFastForwardX_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-forward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandFastForwardX", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newBytesPosition = PlayBytePosition + State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStepX * AudioLibPCMFormat.TIME_UNIT);
                if (newBytesPosition > State.Audio.DataLength)
                {
                    newBytesPosition = State.Audio.DataLength;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newBytesPosition;
            },
                () => CommandFastForward.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoForwardX));

            m_ShellView.RegisterRichCommand(CommandFastForwardX);
            //
            CommandRewindX = new RichDelegateCommand(
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewindX_ShortDesc,
                Tobi_Plugin_AudioPane_Lang.CmdAudioRewindX_LongDesc,
                null, // KeyGesture obtained from settings (see last parameters below)
                m_ShellView.LoadTangoIcon("media-seek-backward"),
                () =>
            {
                Logger.Log("AudioPaneViewModel.CommandRewindX", Category.Debug, Priority.Medium);

                CommandPause.Execute();

                long newTimeBytePosition = PlayBytePosition - State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes((long)Settings.Default.AudioWaveForm_JumpTimeStepX * AudioLibPCMFormat.TIME_UNIT);
                if (newTimeBytePosition < 0)
                {
                    newTimeBytePosition = 0;
                    AudioCues.PlayBeep();
                }

                if (IsAutoPlay)
                {
                    State.Selection.ClearSelection();
                }

                PlayBytePosition = newTimeBytePosition;
            },
                () => CommandRewind.CanExecute(),
                Settings_KeyGestures.Default,
                PropertyChangedNotifyBase.GetMemberName(() => Settings_KeyGestures.Default.Keyboard_Audio_GoBackX));

            m_ShellView.RegisterRichCommand(CommandRewindX);
        }
Пример #9
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);
            //
        }
Пример #10
0
        /// <summary>
        /// If player exists and is playing, then pause. Otherwise if paused or stopped, then plays.
        /// </summary>
        //public void AudioPlayer_TogglePlayPause()
        //{
        //    //Logger.Log("AudioPaneViewModel.AudioPlayer_TogglePlayPause", Category.Debug, Priority.Medium);

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

        //    if (m_Player.CurrentState == AudioPlayer.State.Playing)
        //    {
        //        m_Player.Pause();

        //        bool wasAutoPlay = IsAutoPlay;
        //        if (wasAutoPlay) IsAutoPlay = false;
        //        LastPlayHeadTime = m_Player.CurrentTime;
        //        if (wasAutoPlay) IsAutoPlay = true;
        //    }
        //    else if (m_Player.CurrentState == AudioPlayer.State.Paused || m_Player.CurrentState == AudioPlayer.State.Stopped)
        //    {
        //        m_Player.Resume();
        //    }
        //}

        /// <summary>
        /// If player exists, resumes or start playing at the given byte offset in the audio stream,
        /// and ends playback at the specified offset.
        /// </summary>
        /// <param name="bytesStart"></param>
        /// <param name="bytesEnd"></param>
        public void AudioPlayer_PlayFromTo(long bytesStart, long bytesEnd)
        {
            //Logger.Log("AudioPaneViewModel.AudioPlayer_PlayFromTo", Category.Debug, Priority.Medium);

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

            State.Audio.EndOffsetOfPlayStream = State.Audio.DataLength;

            //if (m_Player.CurrentState == AudioPlayer.State.Paused)
            //{
            //    m_Player.Stop();
            //}

            if (bytesEnd < 0)
            {
                if (IsPlaying)
                {
                    CommandPause.Execute();
                    //m_Player.Stop();
                }

                if (IsStopped)
                {
                    if (m_CurrentAudioStreamProvider() == null)
                    {
                        return;
                    }
                    // else: the stream is now open

                    State.Audio.EndOffsetOfPlayStream = State.Audio.DataLength;

                    OnSettingsPropertyChanged(this, new PropertyChangedEventArgs(GetMemberName(() => Settings.Default.Audio_OutputDevice)));
                    m_Player.PlayBytes(m_CurrentAudioStreamProvider,
                                       State.Audio.DataLength,
                                       State.Audio.PcmFormat.Copy().Data,
                                       bytesStart,
                                       -1
                                       );
                }
                //else if (m_Player.CurrentState == AudioPlayer.State.Playing)
                //{
                //    m_Player.CurrentTime = State.Audio.ConvertBytesToMilliseconds(bytesStart);
                //}
            }
            else
            {
                State.Audio.EndOffsetOfPlayStream = bytesEnd;

                CommandPause.Execute();
                //if (IsPlaying)
                //{
                //    //m_Player.Stop();
                //}

                if (m_CurrentAudioStreamProvider() == null)
                {
                    return;
                }
                // else: the stream is now open

                OnSettingsPropertyChanged(this, new PropertyChangedEventArgs(GetMemberName(() => Settings.Default.Audio_OutputDevice)));
                m_Player.PlayBytes(m_CurrentAudioStreamProvider,
                                   State.Audio.DataLength,
                                   State.Audio.PcmFormat.Copy().Data,
                                   bytesStart,
                                   bytesEnd
                                   );
            }

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

            //AudioPlayer_UpdateWaveFormPlayHead(); rounding problems between player.currentTime and playheadtime => let's let the vumeter callback do the refresh.
        }
Пример #11
0
        //        private DispatcherTimer m_WaveFormLoadTimer;

        //        private static readonly Object LOCK = new Object();

        //        private void StartWaveFormLoadTimer(long delayMilliseconds)
        //        {
        //            if (IsWaveFormLoading)
        //            {
        //                return;
        //            }

        //            lock (LOCK)
        //            {
        //                if (false && View != null)
        //                {
        //                    View.ShowHideWaveFormLoadingMessage(true);
        //                }
        //                if (delayMilliseconds == 0)
        //                {
        ////#if DEBUG
        ////                    Logger.Log("CALLING AudioPlayer_LoadWaveForm (StartWaveFormLoadTimer)", Category.Debug, Priority.Medium);
        ////#endif
        //                    AudioPlayer_LoadWaveForm(false);
        //                    return;
        //                }
        //                if (m_WaveFormLoadTimer == null)
        //                {
        //                    m_WaveFormLoadTimer = new DispatcherTimer(DispatcherPriority.Normal);
        //                    m_WaveFormLoadTimer.Tick += OnWaveFormLoadTimerTick;
        //                    // ReSharper disable ConvertIfStatementToConditionalTernaryExpression
        //                    if (delayMilliseconds == 0)
        //                    // ReSharper restore ConvertIfStatementToConditionalTernaryExpression
        //                    {
        //                        m_WaveFormLoadTimer.Interval = TimeSpan.FromMilliseconds(0);
        //                        //TODO: does this work ?? (immediate dispatch)
        //                    }
        //                    else
        //                    {
        //                        m_WaveFormLoadTimer.Interval = TimeSpan.FromMilliseconds(delayMilliseconds);
        //                    }
        //                }
        //                else if (m_WaveFormLoadTimer.IsEnabled)
        //                {
        //                    //Logger.Log("m_WaveFormLoadTimer.Stop()", Category.Debug, Priority.Medium);

        //                    m_WaveFormLoadTimer.Stop();
        //                }

        //                //Logger.Log("m_WaveFormLoadTimer.Start()", Category.Debug, Priority.Medium);

        //                m_WaveFormLoadTimer.Start();
        //            }
        //        }

        //        private void OnWaveFormLoadTimerTick(object sender, EventArgs e)
        //        {
        //            if (!TheDispatcher.CheckAccess())
        //            {
        //#if DEBUG
        //                Debugger.Break();
        //#endif
        //                TheDispatcher.Invoke(DispatcherPriority.Normal, (Action<object, EventArgs>)OnWaveFormLoadTimerTick, sender, e);
        //                return;
        //            }

        //            m_WaveFormLoadTimer.Stop();

        //            if (IsWaveFormLoading)
        //            {
        //                return;
        //            }
        ////#if DEBUG
        ////            Logger.Log("CALLING AudioPlayer_LoadWaveForm (OnWaveFormLoadTimerTick)", Category.Debug, Priority.Medium);
        ////#endif
        //            AudioPlayer_LoadWaveForm(false);
        //        }

        public void AudioPlayer_LoadWaveForm(bool onlyUpdateTiles)
        {
            //Logger.Log("AudioPaneViewModel.AudioPlayer_LoadWaveForm", Category.Debug, Priority.Medium);
            Tuple <TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.GetTreeNodeSelection();

            if (String.IsNullOrEmpty(State.FilePath) && treeNodeSelection.Item1 == null)
            {
                if (View != null)
                {
                    View.ShowHideWaveFormLoadingMessage(false);
                }
                return;
            }

            bool wasPlaying = IsPlaying;

            //#if DEBUG
            //            Logger.Log("AudioPlayer_LoadWaveForm (calling PAUSE)", Category.Debug, Priority.Medium);
            //#endif

            if (!onlyUpdateTiles)
            {
                CommandPause.Execute();
            }

            //#if DEBUG
            //            Logger.Log("AudioPlayer_LoadWaveForm (called PAUSE)", Category.Debug, Priority.Medium);
            //#endif

            //if (wasPlaying)
            //{
            //    //m_Player.Pause();
            //    //m_Player.Stop();
            //}

            if (m_CurrentAudioStreamProvider() == null)
            {
                if (View != null)
                {
                    View.ShowHideWaveFormLoadingMessage(false);
                }
                return;
            }
            // else: the stream is now open

            //if (!onlyUpdateTiles)
            //{
            //    State.Selection.ClearSelection();
            //}

            if (View != null)
            {
                //View.RefreshCanvasWidth();

                if (false && !onlyUpdateTiles)
                {
                    View.ShowHideWaveFormLoadingMessage(true);
                }

                View.RefreshUI_LoadWaveForm(wasPlaying, onlyUpdateTiles);
            }
            else
            {
#if DEBUG
                Debugger.Break();
#endif
                AudioPlayer_PlayAfterWaveFormLoaded(wasPlaying);
            }
        }