Audacity 3.2.0
SetLabelCommand.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2018 Audacity Team
5 License: wxwidgets
6
7 James Crook
8
9******************************************************************//*******************************************************************/
18
19
20#include "SetLabelCommand.h"
21
22#include "CommandDispatch.h"
23#include "MenuRegistry.h"
24#include "../CommonCommandFlags.h"
25#include "LoadCommands.h"
26#include "ViewInfo.h"
27#include "WaveTrack.h"
28#include "LabelTrack.h"
29#include "ProjectHistory.h"
30#include "SettingsVisitor.h"
31#include "ShuttleGui.h"
32#include "CommandContext.h"
33#include "../tracks/labeltrack/ui/LabelTrackView.h"
34
36{ XO("Set Label") };
37
39
41{
42}
43
44template<bool Const>
46 S.Define( mLabelIndex, wxT("Label"), 0, 0, 10000 );
47 S.OptionalY( bHasText ).Define( mText, wxT("Text"), wxString{"empty"} );
48 S.OptionalY( bHasT0 ).Define( mT0, wxT("Start"), 0.0, 0.0, 100000.0);
49 S.OptionalY( bHasT1 ).Define( mT1, wxT("End"), 0.0, 0.0, 100000.0);
50 S.OptionalN( bHasSelected ).Define( mbSelected, wxT("Selected"), false );
51 return true;
52};
53
55 { return VisitSettings<false>(S); }
56
58 { return VisitSettings<true>(S); }
59
61{
62 S.AddSpace(0, 5);
63
64 S.StartMultiColumn(2, wxALIGN_CENTER);
65 {
66 S.TieNumericTextBox( XXO("Label Index"), mLabelIndex );
67 }
68 S.EndMultiColumn();
69 S.StartMultiColumn(3, wxALIGN_CENTER);
70 {
71 S.Optional( bHasText ).TieTextBox( XXO("Text:"), mText );
72 S.Optional( bHasT0 ).TieNumericTextBox( XXO("Start:"), mT0 );
73 S.Optional( bHasT1 ).TieNumericTextBox( XXO("End:"), mT1 );
74 S.Optional( bHasSelected ).TieCheckBox( XXO("Selected"), mbSelected );
75 }
76 S.EndMultiColumn();
77}
78
80{
81 // \todo we have similar code for finding the nth Label, Clip, Track etc.
82 // this code could be put in subroutines/reduced.
83
84 //wxString mode = GetString(wxT("Type"));
85 AudacityProject * p = &context.project;
86 auto &tracks = TrackList::Get( *p );
87 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
88 const LabelStruct * pLabel = nullptr;
89 LabelTrack *labelTrack = nullptr;
90 auto ii = mLabelIndex;
91 if ( mLabelIndex >= 0 ) {
92 for (auto lt : tracks.Any<LabelTrack>()) {
93 const auto &labels = lt->GetLabels();
94 const auto nLabels = labels.size();
95 if( ii >= (int)nLabels )
96 ii -= nLabels;
97 else {
98 labelTrack = lt;
99 pLabel = &labels[ ii ];
100 break;
101 }
102 }
103 }
104
105 if ( !pLabel )
106 {
107 context.Error(wxT("LabelIndex was invalid."));
108 return false;
109 }
110 auto newLabel = *pLabel;
111 if( bHasText )
112 newLabel.title = mText;
113 if( bHasT0 )
114 newLabel.selectedRegion.setT0(mT0, false);
115 if( bHasT1 )
116 newLabel.selectedRegion.setT1(mT1, false);
117 if( bHasT0 || bHasT1 )
118 newLabel.selectedRegion.ensureOrdering();
119 labelTrack->SetLabel( ii, newLabel );
120
121 // Only one label can be selected.
122 if( bHasSelected ) {
123 auto &view = LabelTrackView::Get( *labelTrack );
124 if( mbSelected )
125 {
126 view.SetNavigationIndex( ii );
127 double t0 = pLabel->selectedRegion.t0();
128 double t1 = pLabel->selectedRegion.t1();
129 selectedRegion.setTimes( t0, t1);
130 }
131 else if( view.GetNavigationIndex( context.project ) == ii )
132 view.SetNavigationIndex( -1 );
133 }
134
135 labelTrack->SortLabels();
136
138 XO("Edited Label"), XO("Label"));
139
140 return true;
141}
142
143namespace {
144using namespace MenuRegistry;
145
146// Register menu items
147
149 // Note that the PLUGIN_SYMBOL must have a space between words,
150 // whereas the short-form used here must not.
151 // (So if you did write "Compare Audio" for the PLUGIN_SYMBOL name, then
152 // you would have to use "CompareAudio" here.)
153 Command( wxT("SetLabel"), XXO("Set Label..."),
155 wxT("Optional/Extra/Part2/Scriptables1")
156};
157}
wxT("CloseDown"))
AttachedItem sAttachment1
const ReservedCommandFlag & AudioIONotBusyFlag()
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
Declarations of SetLabelCommand and SetLabelCommandType classes.
const auto tracks
#define S(N)
Definition: ToChars.cpp:64
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
virtual void Error(const wxString &message) const
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A LabelStruct holds information for ONE label in a LabelTrack.
Definition: LabelTrack.h:40
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:98
static LabelTrackView & Get(LabelTrack &)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
bool Apply(const CommandContext &context) override
bool VisitSettings(SettingsVisitorBase< Const > &S)
void PopulateOrExchange(ShuttleGui &S) override
static const ComponentInterfaceSymbol Symbol
Visitor of effect or command parameters. This is a base class with lots of virtual functions that do ...
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:216
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
AUDACITY_DLL_API void OnAudacityCommand(const CommandContext &ctx)
constexpr auto Command
Definition: MenuRegistry.h:456
BuiltinCommandsModule::Registration< SetLabelCommand > reg