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
16#include "SelectUtilities.h"
17#include "TrackFocus.h"
18#include "Viewport.h"
19#include "WaveTrack.h"
20#include "CommandContext.h"
21#include "MenuRegistry.h"
22#include "QualitySettings.h"
23
24namespace {
25using namespace MenuRegistry;
26
27void OnNewWaveTrack(const CommandContext &context)
28{
29 auto &project = context.project;
30 auto &tracks = TrackList::Get( project );
31 auto &trackFactory = WaveTrackFactory::Get( project );
32
33 auto defaultFormat = QualitySettings::SampleFormatChoice();
34
35 auto rate = ProjectRate::Get(project).GetRate();
36
37 auto track = trackFactory.Create(defaultFormat, rate);
38 track->SetName(tracks.MakeUniqueTrackName(WaveTrack::GetDefaultAudioTrackNamePreference()));
39 tracks.Add(track);
41
42 track->SetSelected(true);
43
45 .PushState(XO("Created new audio track"), XO("New Track"));
46
47 TrackFocus::Get(project).Set(track.get());
49}
50
51void OnNewStereoTrack(const CommandContext &context)
52{
53 auto &project = context.project;
54 auto &tracks = TrackList::Get( project );
55 auto &trackFactory = WaveTrackFactory::Get( project );
56
57 auto defaultFormat = QualitySettings::SampleFormatChoice();
58 auto rate = ProjectRate::Get(project).GetRate();
59
61
62 tracks.Add(trackFactory.Create(2, defaultFormat, rate));
63 auto &newTrack = **tracks.rbegin();
64 newTrack.SetSelected(true);
65 newTrack.SetName(tracks.MakeUniqueTrackName(WaveTrack::GetDefaultAudioTrackNamePreference()));
66
68 .PushState(XO("Created new stereo audio track"), XO("New Track"));
69
70 TrackFocus::Get(project).Set(&newTrack);
72}
73
75 Items( "",
76 Command( wxT("NewMonoTrack"), XXO("&Mono Track"), OnNewWaveTrack,
77 AudioIONotBusyFlag(), wxT("Ctrl+Shift+N") ),
78 Command( wxT("NewStereoTrack"), XXO("&Stereo Track"),
80 ),
81 wxT("Tracks/Add/Add")
82};
83
84}
wxT("CloseDown"))
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
an object holding per-project preferred sample rate
const auto tracks
const auto project
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
Generates classes whose instances register items at construction.
Definition: Registry.h:388
Track * Get()
Definition: TrackFocus.cpp:156
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
void ShowTrack(const Track &track)
Definition: Viewport.cpp:460
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:3376
static wxString GetDefaultAudioTrackNamePreference()
Definition: WaveTrack.cpp:373
constexpr auto Items
Definition: MenuRegistry.h:427
constexpr auto Command
Definition: MenuRegistry.h:456
PROJECT_RATE_API sampleFormat SampleFormatChoice()
void SelectNone(AudacityProject &project)
void OnNewWaveTrack(const CommandContext &context)
void OnNewStereoTrack(const CommandContext &context)