1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 16:19:43 +02:00

Remove CommandContext::GetProject() ...

... which called ::GetActiveProject(), but one purpose of the CommandContext
class was to eliminate many uses of that global function, because a
CommandContext must always be constructed from a reference to a project
(which was always in fact the active one), then passed around to where it is
needed!

Also, just use the project member directly -- because CommandContext was
intended as just a P.O.D (plain-old-data) structure.

This also eliminates a dependency of CommandContext.cpp on Project.cpp.

This is not enough by itself to break any dependency cycles.
This commit is contained in:
Paul Licameli 2019-05-11 16:19:43 -04:00
parent 1c0453106d
commit 9eb9104859
16 changed files with 86 additions and 90 deletions

View File

@ -95,7 +95,7 @@ class ScreenFrame final : public wxFrame
wxStatusBar *mStatus;
std::unique_ptr<ScreenshotCommand> mCommand;
CommandContext mContext;
const CommandContext mContext;
DECLARE_EVENT_TABLE()
};
@ -469,7 +469,7 @@ void ScreenFrame::PopulateOrExchange(ShuttleGui & S)
CentreOnParent();
}
SetIcon(mContext.GetProject()->GetIcon());
SetIcon(mContext.project.GetIcon());
}
bool ScreenFrame::ProcessEvent(wxEvent & e)
@ -564,8 +564,8 @@ void ScreenFrame::SizeMainWindow(int w, int h)
{
int top = 20;
mContext.GetProject()->Maximize(false);
mContext.GetProject()->SetSize(16, 16 + top, w, h);
mContext.project.Maximize(false);
mContext.project.SetSize(16, 16 + top, w, h);
//Bug383 - Toolbar Resets not wanted.
//mContext.GetProject()->GetToolManager()->Reset();
}
@ -669,9 +669,9 @@ void ScreenFrame::OnCaptureSomething(wxCommandEvent & event)
void ScreenFrame::TimeZoom(double seconds)
{
int width, height;
mContext.GetProject()->GetClientSize(&width, &height);
mContext.GetProject()->mViewInfo.SetZoom((0.75 * width) / seconds);
mContext.GetProject()->RedrawProject();
mContext.project.GetClientSize(&width, &height);
mContext.project.mViewInfo.SetZoom((0.75 * width) / seconds);
mContext.project.RedrawProject();
}
void ScreenFrame::OnOneSec(wxCommandEvent & WXUNUSED(event))
@ -708,7 +708,7 @@ void ScreenFrame::SizeTracks(int h)
// If there should be more-than-stereo tracks, this makes
// each channel as high as for a stereo channel
auto tracks = mContext.GetProject()->GetTracks();
auto tracks = mContext.project.GetTracks();
for (auto t : tracks->Leaders<WaveTrack>()) {
auto channels = TrackList::Channels(t);
auto nChannels = channels.size();
@ -716,15 +716,15 @@ void ScreenFrame::SizeTracks(int h)
for (auto channel : channels)
channel->SetHeight(height);
}
mContext.GetProject()->RedrawProject();
mContext.project.RedrawProject();
}
void ScreenFrame::OnShortTracks(wxCommandEvent & WXUNUSED(event))
{
for (auto t : mContext.GetProject()->GetTracks()->Any<WaveTrack>())
for (auto t : mContext.project.GetTracks()->Any<WaveTrack>())
t->SetHeight(t->GetMinimizedHeight());
mContext.GetProject()->RedrawProject();
mContext.project.RedrawProject();
}
void ScreenFrame::OnMedTracks(wxCommandEvent & WXUNUSED(event))

View File

@ -65,7 +65,7 @@ public:
ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target);
bool Apply() override;
bool Apply(const CommandContext &context) override;// Error to use this.
std::unique_ptr<CommandContext> mCtx;
std::unique_ptr<const CommandContext> mCtx;
};

View File

@ -24,6 +24,8 @@ messaging from a command back to its invoker.
#include "CommandContext.h"
#include <map>
#include <wx/app.h>
#include <wx/log.h>
#include <wx/string.h>
#include <wx/variant.h>
#include <wx/arrstr.h>
@ -32,8 +34,6 @@ messaging from a command back to its invoker.
#include "CommandTargets.h"
#include "CommandDirectory.h"
#include "../Project.h"
CommandContext::CommandContext(
AudacityProject &p
, const wxEvent *e
@ -92,9 +92,6 @@ void CommandContext::Progress( double d ) const
AudacityApp * CommandContext::GetApp() const
{ return (AudacityApp *) wxTheApp;}
AudacityProject *CommandContext::GetProject() const
{ return GetActiveProject();}
void CommandContext::StartArray() const
{
if( pOutput )

View File

@ -56,6 +56,5 @@ public:
int index;
CommandParameter parameter;
AudacityApp *GetApp() const;
AudacityProject *GetProject() const;
};
#endif

View File

@ -59,5 +59,5 @@ void CommandHandler::OnReceiveCommand(AppCommandEvent &event)
wxUnusedVar(result);
// Redraw the project
mCurrentContext->GetProject()->RedrawProject();
mCurrentContext->project.RedrawProject();
}

View File

@ -25,7 +25,7 @@ class CommandContext;
class CommandHandler
{
private:
std::unique_ptr<CommandContext> mCurrentContext;
std::unique_ptr<const CommandContext> mCurrentContext;
public:
CommandHandler();

View File

@ -107,7 +107,7 @@ inline int min(int a, int b)
bool CompareAudioCommand::Apply(const CommandContext & context)
{
if (!GetSelection(context, *context.GetProject()))
if (!GetSelection(context, context.project))
{
return false;
}

View File

@ -90,7 +90,7 @@ bool DragCommand::Apply(const CommandContext & context)
if( !bHasToY )
mToY = 10;
wxWindow * pWin = context.GetProject();
wxWindow * pWin = &context.project;
wxWindow * pWin1 = nullptr;
wxMouseEvent Evt( wxEVT_MOTION );
Evt.m_x = mFromX;

View File

@ -121,7 +121,7 @@ bool GetInfoCommand::Apply(const CommandContext &context)
if( mFormat == kLisp )
{
CommandContext LispyContext(
*(context.GetProject()),
context.project,
std::make_unique<LispifiedCommandOutputTargets>( *context.pOutput.get() )
);
return ApplyInner( LispyContext );
@ -130,7 +130,7 @@ bool GetInfoCommand::Apply(const CommandContext &context)
if( mFormat == kBrief )
{
CommandContext BriefContext(
*(context.GetProject()),
context.project,
std::make_unique<BriefCommandOutputTargets>( *context.pOutput.get() )
);
return ApplyInner( BriefContext );
@ -159,7 +159,7 @@ bool GetInfoCommand::ApplyInner(const CommandContext &context)
bool GetInfoCommand::SendMenus(const CommandContext &context)
{
wxMenuBar * pBar = context.GetProject()->GetMenuBar();
wxMenuBar * pBar = context.project.GetMenuBar();
if(!pBar ){
wxLogDebug("No menus");
return false;
@ -418,10 +418,10 @@ wxSpinCtrl * ShuttleGuiGetDefinition::TieSpinCtrl(
bool GetInfoCommand::SendPreferences(const CommandContext &context)
{
context.StartArray();
GlobalPrefsDialog dialog( context.GetProject() );
GlobalPrefsDialog dialog( &context.project );
// wxCommandEvent Evt;
//dialog.Show();
wxWindow * pWin = context.GetProject();
wxWindow * pWin = &context.project;
ShuttleGuiGetDefinition S(pWin, *((context.pOutput)->mStatusTarget) );
dialog.ShuttleAll( S );
context.EndArray();
@ -454,7 +454,7 @@ bool GetInfoCommand::SendCommands(const CommandContext &context, int flags )
bool GetInfoCommand::SendBoxes(const CommandContext &context)
{
//context.Status("Boxes");
wxWindow * pWin = context.GetProject();
wxWindow * pWin = &context.project;
context.StartArray();
wxRect R = pWin->GetScreenRect();
@ -483,11 +483,11 @@ bool GetInfoCommand::SendBoxes(const CommandContext &context)
bool GetInfoCommand::SendTracks(const CommandContext & context)
{
TrackList *projTracks = context.GetProject()->GetTracks();
TrackList *projTracks = context.project.GetTracks();
context.StartArray();
for (auto trk : projTracks->Leaders())
{
TrackPanel *panel = context.GetProject()->GetTrackPanel();
TrackPanel *panel = context.project.GetTrackPanel();
Track * fTrack = panel->GetFocusedTrack();
context.StartStruct();
@ -530,7 +530,7 @@ bool GetInfoCommand::SendTracks(const CommandContext & context)
bool GetInfoCommand::SendClips(const CommandContext &context)
{
TrackList *tracks = context.GetProject()->GetTracks();
TrackList *tracks = context.project.GetTracks();
int i=0;
context.StartArray();
for (auto waveTrack : tracks->Leaders<WaveTrack>()) {
@ -552,7 +552,7 @@ bool GetInfoCommand::SendClips(const CommandContext &context)
bool GetInfoCommand::SendEnvelopes(const CommandContext &context)
{
TrackList *tracks = context.GetProject()->GetTracks();
TrackList *tracks = context.project.GetTracks();
int i=0;
int j=0;
context.StartArray();
@ -589,7 +589,7 @@ bool GetInfoCommand::SendEnvelopes(const CommandContext &context)
bool GetInfoCommand::SendLabels(const CommandContext &context)
{
TrackList *tracks = context.GetProject()->GetTracks();
TrackList *tracks = context.project.GetTracks();
int i=0;
context.StartArray();
for (auto t : tracks->Leaders()) {
@ -640,7 +640,7 @@ void GetInfoCommand::ExploreMenu( const CommandContext &context, wxMenu * pMenu,
if( !pMenu )
return;
CommandManager * pMan = context.GetProject()->GetCommandManager();
CommandManager * pMan = context.project.GetCommandManager();
wxMenuItemList list = pMenu->GetMenuItems();
size_t lcnt = list.size();
@ -714,7 +714,7 @@ void GetInfoCommand::ExploreAdornments( const CommandContext &context,
void GetInfoCommand::ExploreTrackPanel( const CommandContext &context,
wxPoint P, wxWindow * pWin, int WXUNUSED(Id), int depth )
{
AudacityProject * pProj = context.GetProject();
AudacityProject * pProj = &context.project;
TrackPanel * pTP = pProj->GetTrackPanel();
wxRect trackRect = pWin->GetRect();

View File

@ -40,7 +40,7 @@ void ImportCommand::PopulateOrExchange(ShuttleGui & S)
}
bool ImportCommand::Apply(const CommandContext & context){
return context.GetProject()->Import(mFileName);
return context.project.Import(mFileName);
}
@ -66,8 +66,8 @@ void ExportCommand::PopulateOrExchange(ShuttleGui & S)
bool ExportCommand::Apply(const CommandContext & context)
{
double t0, t1;
t0 = context.GetProject()->mViewInfo.selectedRegion.t0();
t1 = context.GetProject()->mViewInfo.selectedRegion.t1();
t0 = context.project.mViewInfo.selectedRegion.t0();
t1 = context.project.mViewInfo.selectedRegion.t1();
// Find the extension and check it's valid
int splitAt = mFileName.Find(wxUniChar('.'), true);
@ -80,7 +80,7 @@ bool ExportCommand::Apply(const CommandContext & context)
Exporter exporter;
bool exportSuccess = exporter.Process(context.GetProject(),
bool exportSuccess = exporter.Process(&context.project,
std::max(0, mnChannels),
extension, mFileName,
true, t0, t1);

View File

@ -44,17 +44,17 @@ void OpenProjectCommand::PopulateOrExchange(ShuttleGui & S)
bool OpenProjectCommand::Apply(const CommandContext & context){
auto oldFileName = context.GetProject()->GetFileName();
auto oldFileName = context.project.GetFileName();
if(mFileName.empty())
{
auto project = context.GetProject();
auto project = &context.project;
AudacityProject::OpenFiles(project);
}
else
{
context.GetProject()->OpenFile(mFileName, mbAddToHistory);
context.project.OpenFile(mFileName, mbAddToHistory);
}
const auto &newFileName = context.GetProject()->GetFileName();
const auto &newFileName = context.project.GetFileName();
// Because Open does not return a success or failure, we have to guess
// at this point, based on whether the project file name has
@ -85,7 +85,7 @@ void SaveProjectCommand::PopulateOrExchange(ShuttleGui & S)
bool SaveProjectCommand::Apply(const CommandContext &context)
{
if(mFileName.empty())
return context.GetProject()->SaveAs(mbCompress);
return context.project.SaveAs(mbCompress);
else
return context.GetProject()->SaveAs(mFileName,mbCompress,mbAddToHistory);
return context.project.SaveAs(mFileName,mbCompress,mbAddToHistory);
}

View File

@ -594,7 +594,7 @@ void ScreenshotCommand::CaptureScriptables(
void ScreenshotCommand::CaptureCommands(
const CommandContext & context, const wxArrayStringEx & Commands ){
AudacityProject * pProject = context.GetProject();
AudacityProject * pProject = &context.project;
CommandManager * pMan = pProject->GetCommandManager();
wxString Str;
// Yucky static variables. Is there a better way? The problem is that we need the
@ -807,16 +807,16 @@ bool ScreenshotCommand::Apply(const CommandContext & context)
GetDerivedParams();
//Don't reset the toolbars to a known state.
//We will be capturing variations of them.
//context.GetProject()->GetToolManager()->Reset();
//context.project.GetToolManager()->Reset();
wxTopLevelWindow *w = GetFrontWindow(context.GetProject());
wxTopLevelWindow *w = GetFrontWindow(&context.project);
if (!w)
return false;
TrackPanel *panel = context.GetProject()->GetTrackPanel();
TrackPanel *panel = context.project.GetTrackPanel();
AdornedRulerPanel *ruler = panel->mRuler;
int nTracks = context.GetProject()->GetTracks()->size();
int nTracks = context.project.GetTracks()->size();
int x1,y1,x2,y2;
w->ClientToScreen(&x1, &y1);
@ -826,47 +826,47 @@ bool ScreenshotCommand::Apply(const CommandContext & context)
switch (mCaptureMode) {
case kwindow:
return Capture(context, WindowFileName( context.GetProject(), w ) , w, GetWindowRect(w));
return Capture(context, WindowFileName( &context.project, w ) , w, GetWindowRect(w));
case kfullwindow:
case kwindowplus:
return Capture(context, WindowFileName( context.GetProject(), w ) , w, GetFullWindowRect(w));
return Capture(context, WindowFileName( &context.project, w ) , w, GetFullWindowRect(w));
case kfullscreen:
return Capture(context, mFileName, w,GetScreenRect());
case ktoolbars:
return CaptureDock(context, context.GetProject()->GetToolManager()->GetTopDock(), mFileName);
return CaptureDock(context, context.project.GetToolManager()->GetTopDock(), mFileName);
case kscriptables:
CaptureScriptables(context, context.GetProject(), mFileName);
CaptureScriptables(context, &context.project, mFileName);
break;
case keffects:
CaptureEffects(context, context.GetProject(), mFileName);
CaptureEffects(context, &context.project, mFileName);
break;
case kpreferences:
CapturePreferences(context, context.GetProject(), mFileName);
CapturePreferences(context, &context.project, mFileName);
break;
case kselectionbar:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), SelectionBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), SelectionBarID, mFileName);
case kspectralselection:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), SpectralSelectionBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), SpectralSelectionBarID, mFileName);
case ktools:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), ToolsBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), ToolsBarID, mFileName);
case ktransport:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), TransportBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), TransportBarID, mFileName);
case kmixer:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), MixerBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), MixerBarID, mFileName);
case kmeter:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), MeterBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), MeterBarID, mFileName);
case krecordmeter:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), RecordMeterBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), RecordMeterBarID, mFileName);
case kplaymeter:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), PlayMeterBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), PlayMeterBarID, mFileName);
case kedit:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), EditBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), EditBarID, mFileName);
case kdevice:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), DeviceBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), DeviceBarID, mFileName);
case ktranscription:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), TranscriptionBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), TranscriptionBarID, mFileName);
case kscrub:
return CaptureToolbar(context, context.GetProject()->GetToolManager(), ScrubbingBarID, mFileName);
return CaptureToolbar(context, context.project.GetToolManager(), ScrubbingBarID, mFileName);
case ktrackpanel:
return Capture(context, mFileName, panel, GetPanelRect(panel));
case kruler:
@ -874,9 +874,9 @@ bool ScreenshotCommand::Apply(const CommandContext & context)
case ktracks:
return Capture(context, mFileName, panel, GetTracksRect(panel));
case kfirsttrack:
return Capture(context, mFileName, panel, GetTrackRect( context.GetProject(), panel, 0 ) );
return Capture(context, mFileName, panel, GetTrackRect( &context.project, panel, 0 ) );
case ksecondtrack:
return Capture(context, mFileName, panel, GetTrackRect( context.GetProject(), panel, 1 ) );
return Capture(context, mFileName, panel, GetTrackRect( &context.project, panel, 1 ) );
case ktracksplus:
{ wxRect r = GetTracksRect(panel);
r.SetTop( r.GetTop() - ruler->GetRulerHeight() );
@ -884,36 +884,36 @@ bool ScreenshotCommand::Apply(const CommandContext & context)
return Capture(context, mFileName, panel, r);
}
case kfirsttrackplus:
{ wxRect r = GetTrackRect(context.GetProject(), panel, 0 );
{ wxRect r = GetTrackRect(&context.project, panel, 0 );
r.SetTop( r.GetTop() - ruler->GetRulerHeight() );
r.SetHeight( r.GetHeight() + ruler->GetRulerHeight() );
return Capture(context, mFileName, panel, r );
}
case kfirsttwotracks:
{ wxRect r = GetTrackRect( context.GetProject(), panel, 0 );
r = r.Union( GetTrackRect( context.GetProject(), panel, 1 ));
{ wxRect r = GetTrackRect( &context.project, panel, 0 );
r = r.Union( GetTrackRect( &context.project, panel, 1 ));
return Capture(context, mFileName, panel, r );
}
case kfirstthreetracks:
{ wxRect r = GetTrackRect( context.GetProject(), panel, 0 );
r = r.Union( GetTrackRect( context.GetProject(), panel, 2 ));
{ wxRect r = GetTrackRect( &context.project, panel, 0 );
r = r.Union( GetTrackRect( &context.project, panel, 2 ));
return Capture(context, mFileName, panel, r );
}
case kfirstfourtracks:
{ wxRect r = GetTrackRect( context.GetProject(), panel, 0 );
r = r.Union( GetTrackRect( context.GetProject(), panel, 3 ));
{ wxRect r = GetTrackRect( &context.project, panel, 0 );
r = r.Union( GetTrackRect( &context.project, panel, 3 ));
return Capture(context, mFileName, panel, r );
}
case kalltracks:
{ wxRect r = GetTrackRect( context.GetProject(), panel, 0 );
r = r.Union( GetTrackRect( context.GetProject(), panel, nTracks-1 ));
{ wxRect r = GetTrackRect( &context.project, panel, 0 );
r = r.Union( GetTrackRect( &context.project, panel, nTracks-1 ));
return Capture(context, mFileName, panel, r );
}
case kalltracksplus:
{ wxRect r = GetTrackRect( context.GetProject(), panel, 0 );
{ wxRect r = GetTrackRect( &context.project, panel, 0 );
r.SetTop( r.GetTop() - ruler->GetRulerHeight() );
r.SetHeight( r.GetHeight() + ruler->GetRulerHeight() );
r = r.Union( GetTrackRect( context.GetProject(), panel, nTracks-1 ));
r = r.Union( GetTrackRect( &context.project, panel, nTracks-1 ));
return Capture(context, mFileName, panel, r );
}
default:

View File

@ -85,7 +85,7 @@ void SelectTimeCommand::PopulateOrExchange(ShuttleGui & S)
bool SelectTimeCommand::Apply(const CommandContext & context){
// Many commands need focus on track panel.
// No harm in setting it with a scripted select.
context.GetProject()->GetTrackPanel()->SetFocus();
context.project.GetTrackPanel()->SetFocus();
if( !bHasT0 && !bHasT1 )
return true;
@ -97,7 +97,7 @@ bool SelectTimeCommand::Apply(const CommandContext & context){
if( !bHasRelativeSpec )
mRelativeTo = 0;
AudacityProject * p = context.GetProject();
AudacityProject * p = &context.project;
double end = p->GetTracks()->GetEndTime();
double t0;
double t1;
@ -164,7 +164,7 @@ bool SelectFrequenciesCommand::Apply(const CommandContext & context){
if( !bHasBottom )
mBottom = 0.0;
context.GetProject()->SSBL_ModifySpectralSelection(
context.project.SSBL_ModifySpectralSelection(
mBottom, mTop, false);// false for not done.
return true;
}
@ -214,7 +214,7 @@ bool SelectTracksCommand::Apply(const CommandContext &context)
// Used to invalidate cached selection and tracks.
Effect::IncEffectCounter();
int index = 0;
TrackList *tracks = context.GetProject()->GetTracks();
TrackList *tracks = context.project.GetTracks();
// Defaults if no value...
if( !bHasNumTracks )

View File

@ -66,8 +66,8 @@ bool SetLabelCommand::Apply(const CommandContext & context)
// this code could be put in subroutines/reduced.
//wxString mode = GetString(wxT("Type"));
AudacityProject * p = context.GetProject();
TrackList *tracks = context.GetProject()->GetTracks();
AudacityProject * p = &context.project;
TrackList *tracks = context.project.GetTracks();
LabelStruct * pLabel = NULL;
int i=0;
int nn=0;

View File

@ -66,7 +66,7 @@ void SetProjectCommand::PopulateOrExchange(ShuttleGui & S)
bool SetProjectCommand::Apply(const CommandContext & context)
{
AudacityProject * pProj = context.GetProject();
AudacityProject * pProj = &context.project;
if( bHasName )
pProj->SetLabel(mName);

View File

@ -94,7 +94,7 @@ bool SetTrackBase::Apply(const CommandContext & context )
{
long i = 0;// track counter
long j = 0;// channel counter
auto tracks = context.GetProject()->GetTracks();
auto tracks = context.project.GetTracks();
for ( auto t : tracks->Leaders() )
{
auto channels = TrackList::Channels(t);
@ -163,7 +163,7 @@ bool SetTrackStatusCommand::ApplyInner(const CommandContext & context, Track * t
if( !bIsSecondChannel ){
if( bHasFocused )
{
TrackPanel *panel = context.GetProject()->GetTrackPanel();
TrackPanel *panel = context.project.GetTrackPanel();
if( bFocused)
panel->SetFocusedTrack( t );
else if( t== panel->GetFocusedTrack() )