Audacity 3.2.0
WaveTrackMenuItems.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5@file WaveTrackMenuItems.cpp
6@brief Injects menu items using WaveTrack but not the views of it
7
8Paul Licameli split from TrackMenus.cpp
9
10**********************************************************************/
11
12#include "CommonCommandFlags.h"
13#include "ProjectHistory.h"
14#include "ProjectRate.h"
15#include "ProjectWindow.h"
16#include "SelectUtilities.h"
17#include "TrackPanelAx.h"
18#include "WaveTrack.h"
19#include "../../../../commands/CommandContext.h"
20#include "../../../../commands/CommandManager.h"
21#include "QualitySettings.h"
22
23namespace {
24using namespace MenuTable;
25
27void OnNewWaveTrack(const CommandContext &context)
28{
29 auto &project = context.project;
30 auto &tracks = TrackList::Get( project );
31 auto &trackFactory = WaveTrackFactory::Get( project );
32 auto &window = ProjectWindow::Get( project );
33
34 auto defaultFormat = QualitySettings::SampleFormatChoice();
35
36 auto rate = ProjectRate::Get(project).GetRate();
37
38 auto track = trackFactory.Create(defaultFormat, rate);
39 track->SetName(tracks.MakeUniqueTrackName(WaveTrack::GetDefaultAudioTrackNamePreference()));
40 tracks.Add(track);
42
43 track->SetSelected(true);
44
45 ProjectHistory::Get( project )
46 .PushState(XO("Created new audio track"), XO("New Track"));
47
48 TrackFocus::Get(project).Set(track.get());
49 track->EnsureVisible();
50}
51
52void OnNewStereoTrack(const CommandContext &context)
53{
54 auto &project = context.project;
55 auto &tracks = TrackList::Get( project );
56 auto &trackFactory = WaveTrackFactory::Get( project );
57 auto &window = ProjectWindow::Get( project );
58
59 auto defaultFormat = QualitySettings::SampleFormatChoice();
60 auto rate = ProjectRate::Get(project).GetRate();
61
63
64 auto left = trackFactory.Create(defaultFormat, rate);
65 left->SetName(tracks.MakeUniqueTrackName(WaveTrack::GetDefaultAudioTrackNamePreference()));
66 tracks.Add(left);
67 left->SetSelected(true);
68
69 auto right = trackFactory.Create(defaultFormat, rate);
70 right->SetName(left->GetName());
71 tracks.Add(right);
72 right->SetSelected(true);
73
74 tracks.MakeMultiChannelTrack(*left, 2, true);
75
76 ProjectHistory::Get( project )
77 .PushState(XO("Created new stereo audio track"), XO("New Track"));
78
79 TrackFocus::Get(project).Set(left.get());
80 left->EnsureVisible();
81}
82
83};
84
86 // Handler is not stateful. Doesn't need a factory registered with
87 // AudacityProject.
88 static Handler instance;
89 return instance;
90}
91
92#define FN(X) (&Handler :: X)
93AttachedItem sAttachment{ wxT("Tracks/Add/Add"),
95 Items( "",
96 Command( wxT("NewMonoTrack"), XXO("&Mono Track"), FN(OnNewWaveTrack),
97 AudioIONotBusyFlag(), wxT("Ctrl+Shift+N") ),
98 Command( wxT("NewStereoTrack"), XXO("&Stereo Track"),
99 FN(OnNewStereoTrack), AudioIONotBusyFlag() )
100 ) )
101};
102#undef FN
103
104}
wxEvtHandler CommandHandlerObject
const ReservedCommandFlag & AudioIONotBusyFlag()
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
an object holding per-project preferred sample rate
#define FN(X)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
static ProjectWindow & Get(AudacityProject &project)
Track * Get()
void EnsureVisible(bool modifyState=false)
Definition: Track.cpp:98
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:467
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2800
static wxString GetDefaultAudioTrackNamePreference()
Definition: WaveTrack.cpp:100
std::unique_ptr< MenuItems > Items(const Identifier &internalName, Args &&... args)
std::unique_ptr< CommandItem > Command(const CommandID &name, const TranslatableString &label_in, void(Handler::*pmf)(const CommandContext &), CommandFlag flags, const CommandManager::Options &options={}, CommandHandlerFinder finder=FinderScope::DefaultFinder())
PROJECT_RATE_API sampleFormat SampleFormatChoice()
void SelectNone(AudacityProject &project)
CommandHandlerObject & findCommandHandler(AudacityProject &)
void OnNewWaveTrack(const CommandContext &context)
void OnNewStereoTrack(const CommandContext &context)