コード例 #1
0
ファイル: YalvViewModel.cs プロジェクト: Dirkster99/YalvLib
 private void RefreshCommandsCanExecute(object sender, LogFileLoader.ResultEvent resultEvent)
 {
     _fileLoader.LoadResultEvent -= RefreshCommandsCanExecute;
     _fileLoader = null;
     ManageRepositoriesViewModel.IsLoading = false;
     CommandRefresh.CanExecute(null);
     CommandDelete.CanExecute(null);
     LogEntryRows.FilterYalvView.CanExecute(null);
     RaisePropertyChanged("HasData");
 }
コード例 #2
0
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //Application.Current.UpdateContentWindows(this);
            $"{Title} Loading...".INFO();

            CommandRefresh.Hide();
            CommandFilter.Hide();

            if (Content is BrowerPage)
            {
                CommandPageRead.Show();
                CommandRefreshThumb.ToolTip = "Refresh";
                PreftchingProgress.Hide();
            }
            else
                CommandPageRead.Hide();

            if (Content is IllustDetailPage ||
                Content is IllustImageViewerPage ||
                Content is SearchResultPage ||
                Content is HistoryPage)
            {
                CommandRefresh.Show();
                if (!(Content is IllustImageViewerPage))
                {
                    CommandRefreshThumb.Show();
                    PreftchingProgress.Show();
                    CommandFilter.Show();
                }
            }

            if (Content is BatchProcessPage)
            {
                LeftWindowCommands.Hide();
                RightWindowCommands.Hide();
                ShowMinButton = true;
                ShowMaxRestoreButton = false;
                ResizeMode = ResizeMode.CanMinimize;
            }

            if (Application.Current.DropBoxExists() == null)
                CommandDropbox.IsChecked = false;
            else
                CommandDropbox.IsChecked = true;

            this.AdjustWindowPos();

            Commands.SaveOpenedWindows.Execute(null);
        }
コード例 #3
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();
        }
コード例 #4
0
        private void UndoRedoManagerChanged_RestoreAudioTreeNodeSelectionState(TreeNode targetNode1, TreeNode targetNode2, long byteStart, long byteDur, bool done, bool deselectAndPosEnd)
        {
            if (targetNode1 == null || targetNode2 != null && !targetNode2.IsDescendantOf(targetNode1))
            {
#if DEBUG
                Debugger.Break();
#endif
                return;
            }

            m_LastSetPlayBytePosition = -1;

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

            //RefreshWaveFormChunkMarkersForCurrentSubTreeNode(false);


            long byteOffset = 0;

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

            bool waveFormNeedsForcedRefresh = treeNodeSelection.Item1 == targetNode1;
            if (waveFormNeedsForcedRefresh)
            {
                if (View != null)
                {
                    View.ResetAll();
                }

                if (AudioPlaybackStreamKeepAlive)
                {
                    ensurePlaybackStreamIsDead();
                }
                m_CurrentAudioStreamProvider();

                byteOffset = computeByteOffset(targetNode1, targetNode2);

                treeNodeSelection = m_UrakawaSession.PerformTreeNodeSelection(targetNode1, false, targetNode2);
            }
            else
            {
                m_StateToRestore = new StateToRestore
                {
                    SelectionBeginBytePosition = -1,
                    SelectionEndBytePosition   = -1,
                    PlayHeadBytePosition       = -1
                };

                treeNodeSelection = m_UrakawaSession.PerformTreeNodeSelection(targetNode1, false, targetNode2);

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

                if (treeNodeSelection.Item1 == targetNode1)
                {
                    byteOffset = computeByteOffset(targetNode1, targetNode2);
                    //treeNodeSelection.Item2 == targetNode2
                }
            }

            if (treeNodeSelection.Item1 != targetNode1)
            {
#if DEBUG
                Debugger.Break();
#endif
                m_StateToRestore = new StateToRestore
                {
                    SelectionBeginBytePosition = -1,
                    SelectionEndBytePosition   = -1,
                    PlayHeadBytePosition       = 0
                };

                CommandRefresh.Execute();

                return;
            }

            if (treeNodeSelection.Item2 != targetNode2)
            {
#if DEBUG
                Debugger.Break();
#endif
            }

            long begin = byteOffset + byteStart;
            if (deselectAndPosEnd)
            {
                m_StateToRestore = new StateToRestore
                {
                    SelectionBeginBytePosition = -1,
                    SelectionEndBytePosition   = -1,
                    PlayHeadBytePosition       = byteDur + begin
                };
            }
            else if (done)
            {
                m_StateToRestore = new StateToRestore
                {
                    SelectionBeginBytePosition = begin,
                    SelectionEndBytePosition   = byteDur + begin,
                    PlayHeadBytePosition       = begin
                };
            }
            else
            {
                m_StateToRestore = new StateToRestore
                {
                    SelectionBeginBytePosition = -1,
                    SelectionEndBytePosition   = -1,
                    PlayHeadBytePosition       = begin
                };
            }

            CommandRefresh.Execute();
        }
コード例 #5
0
        private void checkAndAddDeferredRecordingDataItems()
        {
            if (m_DeferredRecordingDataItems == null)
            {
                return;
            }

            IsAutoPlay = false;

            bool needsRefresh = false;

            bool skipDrawing = Settings.Default.AudioWaveForm_DisableDraw;

            Settings.Default.AudioWaveForm_DisableDraw = true;


            //#if !DISABLE_SINGLE_RECORD_FILE
            string            previousRecordedFile    = null;
            FileDataProvider  currentFileDataProvider = null;
            AudioLibPCMFormat currentPcmFormat        = null;
            long currentPcmDataLength = -1;
            long previousBytePosEnd   = 0;

            //#endif


            foreach (var deferredRecordingDataItem in m_DeferredRecordingDataItems)
            {
                Tuple <TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.PerformTreeNodeSelection(deferredRecordingDataItem.TreeNode1, false, deferredRecordingDataItem.TreeNode2);
                if (treeNodeSelection.Item1 != deferredRecordingDataItem.TreeNode1 ||
                    treeNodeSelection.Item2 != deferredRecordingDataItem.TreeNode2)
                {
#if DEBUG
                    Debugger.Break();
#endif
                    continue;
                }

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

                if (deferredRecordingDataItem.PlayBytePosition >= 0)
                {
                    PlayBytePosition = deferredRecordingDataItem.PlayBytePosition;
                }
                else
                {
                    m_LastSetPlayBytePosition = deferredRecordingDataItem.PlayBytePosition;
                }

                if (PlayBytePosition != deferredRecordingDataItem.PlayBytePosition)
                {
#if DEBUG
                    Debugger.Break();
#endif
                    continue;
                }

                if (deferredRecordingDataItem.SelectionBeginBytePosition >= 0 &&
                    deferredRecordingDataItem.SelectionEndBytePosition > 0)
                {
                    State.Selection.SetSelectionBytes(deferredRecordingDataItem.SelectionBeginBytePosition, deferredRecordingDataItem.SelectionEndBytePosition);
                }
                else
                {
                    State.Selection.ClearSelection();
                }

                if (State.Selection.SelectionBeginBytePosition != deferredRecordingDataItem.SelectionBeginBytePosition ||
                    State.Selection.SelectionEndBytePosition != deferredRecordingDataItem.SelectionEndBytePosition)
                {
#if DEBUG
                    Debugger.Break();
#endif
                    continue;
                }

                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                {
                    TreeNode treeNode = deferredRecordingDataItem.TreeNode1 ?? deferredRecordingDataItem.TreeNode2;

                    if (string.IsNullOrEmpty(previousRecordedFile) ||
                        previousRecordedFile != deferredRecordingDataItem.RecordedFilePath)
                    {
                        PCMFormatInfo pcmInfo = State.Audio.PcmFormatRecordingMonitoring;
                        currentPcmFormat = (pcmInfo != null ? pcmInfo.Copy().Data : null);
                        if (currentPcmFormat == null)
                        {
                            Stream fileStream = File.Open(deferredRecordingDataItem.RecordedFilePath, FileMode.Open, FileAccess.Read,
                                                          FileShare.Read);
                            try
                            {
                                uint dataLength;
                                currentPcmFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);

                                currentPcmDataLength = dataLength;
                            }
                            finally
                            {
                                fileStream.Close();
                            }
                        }

                        currentFileDataProvider =
                            (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                        currentFileDataProvider.InitByMovingExistingFile(deferredRecordingDataItem.RecordedFilePath);
                        if (File.Exists(deferredRecordingDataItem.RecordedFilePath))
                        //check exist just in case file adopted by DataProviderManager
                        {
                            File.Delete(deferredRecordingDataItem.RecordedFilePath);
                        }
                    }

                    //Time duration = new Time(currentPcmFormat.ConvertBytesToTime(currentPcmDataLength));

                    if (previousBytePosEnd < 0)
                    {
                        previousBytePosEnd = 0;
                    }
                    long bytePosEnd = deferredRecordingDataItem.RecordAndContinue_StopBytePos;

                    openFile(treeNode, currentFileDataProvider, previousBytePosEnd, bytePosEnd, currentPcmFormat, currentPcmDataLength);
                }
                else
                {
                    openFile(deferredRecordingDataItem.RecordedFilePath, true, true,
                             State.Audio.PcmFormatRecordingMonitoring);
                }

                needsRefresh = true;

                //m_viewModel.CommandRefresh.Execute();
                //if (m_viewModel.View != null)
                //{
                //    m_viewModel.View.CancelWaveFormLoad(true);
                //}

                if (!Settings.Default.Audio_DisableSingleWavFileRecord)
                {
                    previousRecordedFile = deferredRecordingDataItem.RecordedFilePath;
                    previousBytePosEnd   = deferredRecordingDataItem.RecordAndContinue_StopBytePos;
                }
            }

            m_DeferredRecordingDataItems = null;

            Settings.Default.AudioWaveForm_DisableDraw = skipDrawing;

            if (needsRefresh)
            {
                CommandRefresh.Execute();
            }
        }
コード例 #6
0
        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();
                }
            }
        }