From 597ddbfa52f9b1cb685f4bb04d582a2f29b2cda7 Mon Sep 17 00:00:00 2001 From: James Crook Date: Thu, 25 May 2017 15:45:47 +0100 Subject: [PATCH 1/2] Further speed up to showing preferences. We now don't sort the list until a view is selected. Also we create it with nodes open, rather than creating with nodes closed and then separately opening them. Instead of 3 sorts at initialisation only one happens now. AX info is only updated after a sort, so this may be 3x faster for screen reader users too. --- src/prefs/KeyConfigPrefs.cpp | 16 ++++++---- src/prefs/KeyConfigPrefs.h | 2 +- src/widgets/KeyView.cpp | 58 ++++++++++++++++++++++-------------- src/widgets/KeyView.h | 5 ++-- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index ad24b574e..b6aebb918 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -142,7 +142,9 @@ void KeyConfigPrefs::Populate() mManager = project->GetCommandManager(); - RefreshBindings(); + // For speed, don't sort here. We're just creating. + // Instead sort when we do SetView later in this function. + RefreshBindings(false); if (mViewByTree->GetValue()) { mViewType = ViewByTree; @@ -294,7 +296,7 @@ void KeyConfigPrefs::PopulateOrExchange(ShuttleGui & S) Layout(); } -void KeyConfigPrefs::RefreshBindings() +void KeyConfigPrefs::RefreshBindings(bool bSort) { wxArrayString Labels; wxArrayString Categories; @@ -316,8 +318,10 @@ void KeyConfigPrefs::RefreshBindings() Categories, Prefixes, Labels, - mKeys); - mView->ExpandAll(); + mKeys, + bSort); + //Not needed as new nodes are already shown expanded. + //mView->ExpandAll(); mNewKeys = mKeys; } @@ -351,7 +355,7 @@ void KeyConfigPrefs::OnImport(wxCommandEvent & WXUNUSED(event)) wxOK | wxCENTRE, this); } - RefreshBindings(); + RefreshBindings(true); } void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) @@ -391,7 +395,7 @@ void KeyConfigPrefs::OnDefaults(wxCommandEvent & WXUNUSED(event)) mManager->SetKeyFromIndex(i, mNewKeys[i]); } - RefreshBindings(); + RefreshBindings(true); } void KeyConfigPrefs::OnHotkeyKeyDown(wxKeyEvent & e) diff --git a/src/prefs/KeyConfigPrefs.h b/src/prefs/KeyConfigPrefs.h index 07dceb2a4..0ed56104f 100644 --- a/src/prefs/KeyConfigPrefs.h +++ b/src/prefs/KeyConfigPrefs.h @@ -46,7 +46,7 @@ public: private: void Populate(); void PopulateOrExchange(ShuttleGui & S); - void RefreshBindings(); + void RefreshBindings(bool bSort); wxString NameFromKey(const wxString & key); void SetKeyForSelected(const wxString & key); diff --git a/src/widgets/KeyView.cpp b/src/widgets/KeyView.cpp index 083a0da51..36f8ab0df 100644 --- a/src/widgets/KeyView.cpp +++ b/src/widgets/KeyView.cpp @@ -531,7 +531,9 @@ KeyView::RefreshBindings(const wxArrayString & names, const wxArrayString & categories, const wxArrayString & prefixes, const wxArrayString & labels, - const wxArrayString & keys) + const wxArrayString & keys, + bool bSort + ) { bool firsttime = mNodes.GetCount() == 0; @@ -604,6 +606,7 @@ KeyView::RefreshBindings(const wxArrayString & names, node.iscat = true; node.isparent = true; node.depth = depth++; + node.isopen = true; // Add it to the tree mNodes.Add(node); @@ -643,6 +646,7 @@ KeyView::RefreshBindings(const wxArrayString & names, node.ispfx = true; node.isparent = true; node.depth = depth++; + node.isopen = true; // Add it to the tree mNodes.Add(node); @@ -724,10 +728,10 @@ KeyView::RefreshBindings(const wxArrayString & names, UpdateHScroll(); // Refresh the view lines - RefreshLines(); + RefreshLines(bSort); - // Set the selected node if this was the first time through - if (firsttime) + // Set the selected node if we've just reprepared the list and nothing was selected. + if ((GetSelection()==wxNOT_FOUND) && bSort ) { SelectNode(LineToIndex(0)); } @@ -737,7 +741,7 @@ KeyView::RefreshBindings(const wxArrayString & names, // Refresh the list of lines within the current view // void -KeyView::RefreshLines() +KeyView::RefreshLines(bool bSort) { int cnt = (int) mNodes.GetCount(); int linecnt = 0; @@ -918,27 +922,34 @@ KeyView::RefreshLines() mLines.Add(&node); } } - //To see how many lines are being sorted (and how often). - //wxLogDebug("Sorting %i lines", mLines.GetCount()); - // Speed up the comparison function used in sorting - // by only translating this string once. - CommandTranslated = _("Command"); - - // Sort list based on type - switch (mViewType) + // Sorting is costly. If bSort is false, we do not have to sort. + // bSort false means we know that the list will be updated again before + // the user needs to see it. + if( bSort ) { - case ViewByTree: - mLines.Sort(CmpKeyNodeByTree); - break; + //To see how many lines are being sorted (and how often). + //wxLogDebug("Sorting %i lines for type %i", mLines.GetCount(), mViewType); - case ViewByName: - mLines.Sort(CmpKeyNodeByName); - break; + // Speed up the comparison function used in sorting + // by only translating this string once. + CommandTranslated = _("Command"); - case ViewByKey: - mLines.Sort(CmpKeyNodeByKey); - break; + // Sort list based on type + switch (mViewType) + { + case ViewByTree: + mLines.Sort(CmpKeyNodeByTree); + break; + + case ViewByName: + mLines.Sort(CmpKeyNodeByName); + break; + + case ViewByKey: + mLines.Sort(CmpKeyNodeByKey); + break; + } } // Now, reassign the line numbers @@ -973,7 +984,8 @@ KeyView::RefreshLines() #if wxUSE_ACCESSIBILITY // Let accessibility know that the list has changed - mAx->ListUpdated(); + if( bSort ) + mAx->ListUpdated(); #endif } diff --git a/src/widgets/KeyView.h b/src/widgets/KeyView.h index 4fc515d97..8ddb6168f 100644 --- a/src/widgets/KeyView.h +++ b/src/widgets/KeyView.h @@ -82,7 +82,8 @@ public: const wxArrayString & categories, const wxArrayString & prefixes, const wxArrayString & labels, - const wxArrayString & keys); + const wxArrayString & keys, + bool bSort); int GetSelected() const; @@ -109,7 +110,7 @@ public: private: void RecalcExtents(); void UpdateHScroll(); - void RefreshLines(); + void RefreshLines(bool bSort = true); void SelectNode(int index); From eea55f78ce2a6aff2c2bcb8b01324d9ca60783ce Mon Sep 17 00:00:00 2001 From: Steve Daulton Date: Thu, 25 May 2017 23:15:01 +0100 Subject: [PATCH 2/2] Make Nyquist debug window resizable and name window to match the effect. --- src/effects/nyquist/Nyquist.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/effects/nyquist/Nyquist.cpp b/src/effects/nyquist/Nyquist.cpp index 48d72f2d4..75a82a604 100644 --- a/src/effects/nyquist/Nyquist.cpp +++ b/src/effects/nyquist/Nyquist.cpp @@ -770,8 +770,8 @@ _("Selection too long for Nyquist code.\nMaximum allowed selection is %ld sample if (mDebug && !mRedirectOutput) { NyquistOutputDialog dlog(mUIParent, -1, - _("Nyquist"), - _("Nyquist Output: "), + mName, + _("Debug Output: "), mDebugOutput.c_str()); dlog.CentreOnParent(); dlog.ShowModal(); @@ -1175,8 +1175,7 @@ bool NyquistEffect::ProcessOne() if (rval == nyx_string) { wxMessageBox(NyquistToWxString(nyx_get_string()), - wxT("Nyquist"), - wxOK | wxCENTRE, mUIParent); + mName, wxOK | wxCENTRE, mUIParent); // True if not process type. // If not returning audio from process effect, @@ -2382,7 +2381,7 @@ NyquistOutputDialog::NyquistOutputDialog(wxWindow * parent, wxWindowID id, const wxString & title, const wxString & prompt, const wxString &message) -: wxDialogWrapper(parent, id, title) +: wxDialogWrapper{ parent, id, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER } { SetName(GetTitle()); @@ -2399,10 +2398,10 @@ NyquistOutputDialog::NyquistOutputDialog(wxWindow * parent, wxWindowID id, // TODO: use ShowInfoDialog() instead. // Beware this dialog MUST work with screen readers. - item = safenew wxTextCtrl(this, -1, message, - wxDefaultPosition, wxSize(400, 200), - wxTE_MULTILINE | wxTE_READONLY); - mainSizer->Add(item, 0, wxALIGN_LEFT | wxALL, 10); + item = new wxTextCtrl(this, -1, message, + wxDefaultPosition, wxSize(480, 250), + wxTE_MULTILINE | wxTE_READONLY); + mainSizer->Add(item, 1, wxEXPAND | wxALL, 10); { auto hSizer = std::make_unique(wxHORIZONTAL);