mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
Fewer uses of ::GetActiveProject()...
... where we have a window, ascend the chain of parent pointers instead to find the project window.
This commit is contained in:
parent
9029eee5bd
commit
275797bbb4
@ -20,7 +20,8 @@
|
|||||||
#include <wx/mimetype.h>
|
#include <wx/mimetype.h>
|
||||||
|
|
||||||
#include "AudioIO.h"
|
#include "AudioIO.h"
|
||||||
#include "Project.h" // for GetActiveProject
|
#include "Project.h"
|
||||||
|
#include "ProjectWindowBase.h"
|
||||||
#include "LabelTrack.h"
|
#include "LabelTrack.h"
|
||||||
#include "commands/CommandManager.h"
|
#include "commands/CommandManager.h"
|
||||||
#include "UndoManager.h"
|
#include "UndoManager.h"
|
||||||
@ -57,7 +58,7 @@ void HighlightTextCtrl::OnMouseEvent(wxMouseEvent& event)
|
|||||||
if (nNewSyl != nCurSyl)
|
if (nNewSyl != nCurSyl)
|
||||||
{
|
{
|
||||||
Syllable* pCurSyl = mLyricsPanel->GetSyllable(nNewSyl);
|
Syllable* pCurSyl = mLyricsPanel->GetSyllable(nNewSyl);
|
||||||
AudacityProject* pProj = GetActiveProject();
|
auto pProj = FindProjectFromWindow( this );
|
||||||
auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
|
auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
|
||||||
selectedRegion.setT0( pCurSyl->t );
|
selectedRegion.setT0( pCurSyl->t );
|
||||||
|
|
||||||
@ -440,7 +441,7 @@ void LyricsPanel::Update(double t)
|
|||||||
{
|
{
|
||||||
// TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive().
|
// TrackPanel::OnTimer passes gAudioIO->GetStreamTime(), which is -DBL_MAX if !IsStreamActive().
|
||||||
// In that case, use the selection start time.
|
// In that case, use the selection start time.
|
||||||
AudacityProject* pProj = GetActiveProject();
|
auto pProj = FindProjectFromWindow( this );
|
||||||
const auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
|
const auto &selectedRegion = ViewInfo::Get( *pProj ).selectedRegion;
|
||||||
mT = selectedRegion.t0();
|
mT = selectedRegion.t0();
|
||||||
}
|
}
|
||||||
@ -529,7 +530,7 @@ void LyricsPanel::OnShow(wxShowEvent &e)
|
|||||||
|
|
||||||
void LyricsPanel::OnKeyEvent(wxKeyEvent & event)
|
void LyricsPanel::OnKeyEvent(wxKeyEvent & event)
|
||||||
{
|
{
|
||||||
AudacityProject *project = GetActiveProject();
|
auto project = FindProjectFromWindow( this );
|
||||||
auto &commandManager = CommandManager::Get( *project );
|
auto &commandManager = CommandManager::Get( *project );
|
||||||
commandManager.FilterKeyEvent(project, event, true);
|
commandManager.FilterKeyEvent(project, event, true);
|
||||||
event.Skip();
|
event.Skip();
|
||||||
|
@ -24,3 +24,26 @@ ProjectWindowBase::ProjectWindowBase(wxWindow * parent, wxWindowID id,
|
|||||||
ProjectWindowBase::~ProjectWindowBase()
|
ProjectWindowBase::~ProjectWindowBase()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
ProjectWindowBase *FindProjectWindow( wxWindow *pWindow )
|
||||||
|
{
|
||||||
|
while ( pWindow && pWindow->GetParent() )
|
||||||
|
pWindow = pWindow->GetParent();
|
||||||
|
return dynamic_cast< ProjectWindowBase* >( pWindow );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
AudacityProject *FindProjectFromWindow( wxWindow *pWindow )
|
||||||
|
{
|
||||||
|
auto pProjectWindow = FindProjectWindow( pWindow );
|
||||||
|
return pProjectWindow ? &pProjectWindow->GetProject() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const AudacityProject *FindProjectFromWindow( const wxWindow *pWindow )
|
||||||
|
{
|
||||||
|
return FindProjectFromWindow( const_cast< wxWindow* >( pWindow ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -33,5 +33,8 @@ protected:
|
|||||||
AudacityProject &mProject;
|
AudacityProject &mProject;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AudacityProject *FindProjectFromWindow( wxWindow *pWindow );
|
||||||
|
const AudacityProject *FindProjectFromWindow( const wxWindow *pWindow );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "../ProjectSettings.h"
|
#include "../ProjectSettings.h"
|
||||||
|
#include "../ProjectWindowBase.h"
|
||||||
#include "../ShuttleGui.h"
|
#include "../ShuttleGui.h"
|
||||||
#include "../FileNames.h"
|
#include "../FileNames.h"
|
||||||
#include "../ViewInfo.h"
|
#include "../ViewInfo.h"
|
||||||
@ -52,7 +53,7 @@ bool ContrastDialog::GetDB(float &dB)
|
|||||||
// For stereo tracks: sqrt((mean(L)+mean(R))/2)
|
// For stereo tracks: sqrt((mean(L)+mean(R))/2)
|
||||||
double meanSq = 0.0;
|
double meanSq = 0.0;
|
||||||
|
|
||||||
AudacityProject *p = GetActiveProject();
|
auto p = FindProjectFromWindow( this );
|
||||||
auto range =
|
auto range =
|
||||||
TrackList::Get( *p ).SelectedLeaders< const WaveTrack >();
|
TrackList::Get( *p ).SelectedLeaders< const WaveTrack >();
|
||||||
auto numberSelectedTracks = range.size();
|
auto numberSelectedTracks = range.size();
|
||||||
@ -132,7 +133,7 @@ bool ContrastDialog::GetDB(float &dB)
|
|||||||
|
|
||||||
void ContrastDialog::SetStartAndEndTime()
|
void ContrastDialog::SetStartAndEndTime()
|
||||||
{
|
{
|
||||||
AudacityProject *p = GetActiveProject();
|
auto p = FindProjectFromWindow( this );
|
||||||
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
||||||
mT0 = selectedRegion.t0();
|
mT0 = selectedRegion.t0();
|
||||||
mT1 = selectedRegion.t1();
|
mT1 = selectedRegion.t1();
|
||||||
@ -211,7 +212,7 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
|
|||||||
wxTextValidator vld(wxFILTER_NUMERIC);
|
wxTextValidator vld(wxFILTER_NUMERIC);
|
||||||
wxString number;
|
wxString number;
|
||||||
|
|
||||||
AudacityProject *p = GetActiveProject();
|
auto p = FindProjectFromWindow( this );
|
||||||
const auto &settings = ProjectSettings::Get( *p );
|
const auto &settings = ProjectSettings::Get( *p );
|
||||||
mProjectRate = settings.GetRate();
|
mProjectRate = settings.GetRate();
|
||||||
|
|
||||||
@ -374,7 +375,7 @@ void ContrastDialog::OnClose(wxCommandEvent & WXUNUSED(event))
|
|||||||
|
|
||||||
void ContrastDialog::OnGetForeground(wxCommandEvent & /*event*/)
|
void ContrastDialog::OnGetForeground(wxCommandEvent & /*event*/)
|
||||||
{
|
{
|
||||||
AudacityProject *p = GetActiveProject();
|
auto p = FindProjectFromWindow( this );
|
||||||
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
||||||
|
|
||||||
if( TrackList::Get( *p ).Selected< const WaveTrack >() ) {
|
if( TrackList::Get( *p ).Selected< const WaveTrack >() ) {
|
||||||
@ -390,7 +391,7 @@ void ContrastDialog::OnGetForeground(wxCommandEvent & /*event*/)
|
|||||||
|
|
||||||
void ContrastDialog::OnGetBackground(wxCommandEvent & /*event*/)
|
void ContrastDialog::OnGetBackground(wxCommandEvent & /*event*/)
|
||||||
{
|
{
|
||||||
AudacityProject *p = GetActiveProject();
|
auto p = FindProjectFromWindow( this );
|
||||||
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
|
||||||
|
|
||||||
if( TrackList::Get( *p ).Selected< const WaveTrack >() ) {
|
if( TrackList::Get( *p ).Selected< const WaveTrack >() ) {
|
||||||
@ -528,7 +529,7 @@ void ContrastDialog::results()
|
|||||||
void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
|
void ContrastDialog::OnExport(wxCommandEvent & WXUNUSED(event))
|
||||||
{
|
{
|
||||||
// TODO: Handle silence checks better (-infinity dB)
|
// TODO: Handle silence checks better (-infinity dB)
|
||||||
AudacityProject * project = GetActiveProject();
|
auto project = FindProjectFromWindow( this );
|
||||||
wxString fName = wxT("contrast.txt");
|
wxString fName = wxT("contrast.txt");
|
||||||
|
|
||||||
fName = FileNames::SelectFile(FileNames::Operation::Export,
|
fName = FileNames::SelectFile(FileNames::Operation::Export,
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
//This is needed for tooltips
|
//This is needed for tooltips
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "../ProjectStatus.h"
|
#include "../ProjectStatus.h"
|
||||||
|
#include "../ProjectWindowBase.h"
|
||||||
#include <wx/tooltip.h>
|
#include <wx/tooltip.h>
|
||||||
|
|
||||||
#if wxUSE_ACCESSIBILITY
|
#if wxUSE_ACCESSIBILITY
|
||||||
@ -502,7 +503,9 @@ void AButton::OnMouseEvent(wxMouseEvent & event)
|
|||||||
if (mCursorIsInWindow)
|
if (mCursorIsInWindow)
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
else {
|
else {
|
||||||
ProjectStatus::Get( *GetActiveProject() ).Set({});
|
auto pProject = FindProjectFromWindow( this );
|
||||||
|
if (pProject)
|
||||||
|
ProjectStatus::Get( *pProject ).Set({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -519,7 +522,9 @@ void AButton::UpdateStatus()
|
|||||||
auto tipText = Verbatim( pTip->GetTip() );
|
auto tipText = Verbatim( pTip->GetTip() );
|
||||||
if (!mEnabled)
|
if (!mEnabled)
|
||||||
tipText.Join( XO("(disabled)"), " " );
|
tipText.Join( XO("(disabled)"), " " );
|
||||||
ProjectStatus::Get( *GetActiveProject() ).Set(tipText);
|
auto pProject = FindProjectFromWindow( this );
|
||||||
|
if (pProject)
|
||||||
|
ProjectStatus::Get( *pProject ).Set( tipText );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ or ASlider.
|
|||||||
#include "../ImageManipulation.h"
|
#include "../ImageManipulation.h"
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "../ProjectStatus.h"
|
#include "../ProjectStatus.h"
|
||||||
|
#include "../ProjectWindowBase.h"
|
||||||
#include "../ShuttleGui.h"
|
#include "../ShuttleGui.h"
|
||||||
|
|
||||||
#include "../AllThemeResources.h"
|
#include "../AllThemeResources.h"
|
||||||
@ -1094,7 +1095,9 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
|
|||||||
{
|
{
|
||||||
// Display the tooltip in the status bar
|
// Display the tooltip in the status bar
|
||||||
auto tip = GetTip(mCurrentValue);
|
auto tip = GetTip(mCurrentValue);
|
||||||
ProjectStatus::Get( *GetActiveProject() ).Set(tip);
|
auto pProject = FindProjectFromWindow( mParent );
|
||||||
|
if (pProject)
|
||||||
|
ProjectStatus::Get( *pProject ).Set( tip );
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
else if (event.Leaving())
|
else if (event.Leaving())
|
||||||
@ -1103,7 +1106,9 @@ void LWSlider::OnMouseEvent(wxMouseEvent & event)
|
|||||||
{
|
{
|
||||||
ShowTip(false);
|
ShowTip(false);
|
||||||
}
|
}
|
||||||
ProjectStatus::Get( *GetActiveProject() ).Set({});
|
auto pProject = FindProjectFromWindow( mParent );
|
||||||
|
if (pProject)
|
||||||
|
ProjectStatus::Get( *pProject ).Set({});
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user