Audacity 3.2.0
ChangeClipSpeedDialog.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/**********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 @file ChangeClipSpeedDialog.cpp
7
8 Dmitry Vedenko
9
10 **********************************************************************/
12
13#include <wx/button.h>
14#include <wx/textctrl.h>
15
16#include "ShuttleGui.h"
18
20 WaveTrack& waveTrack, WaveTrack::Interval& interval, wxWindow* parent)
22 parent, wxID_ANY, XO("Change Speed"), wxDefaultPosition, { 480, 250 },
23 wxDEFAULT_DIALOG_STYLE)
24 , mTrack { waveTrack }
25 , mTrackInterval { interval }
26 , mClipSpeed { 100.0 / interval.GetStretchRatio() }
27 , mOldClipSpeed { mClipSpeed }
28{
29 ShuttleGui s(this, eIsCreating);
30
31 s.StartVerticalLay();
32 {
33 PopulateOrExchange(s);
34 }
35 s.EndVerticalLay();
36
37 // TODO: Tolerance?
38 // Stretch ratio of
39 assert(mOldClipSpeed > 0.0);
40
41 Layout();
42 Fit();
43 Centre();
44
45 Bind(
46 wxEVT_CHAR_HOOK,
47 [this](auto& evt)
48 {
49 if (!IsEscapeKey(evt))
50 {
51 evt.Skip();
52 return;
53 }
54
55 EndModal(wxID_CANCEL);
56 });
57}
58
60
62{
64 s.StartVerticalLay(wxEXPAND, 1);
65 {
66 s.SetBorder(1);
67 s.StartHorizontalLay(wxEXPAND);
68 {
69 s.AddPrompt(XO("Clip speed"));
70 s.AddSpace(0, 0, 1);
71 s.Name(XO("Clip speed"))
72 .NameSuffix(Verbatim("%"))
73 .TieNumericTextBox({}, mClipSpeed, 14, true)
74 ->Bind(wxEVT_TEXT_ENTER, [this](auto&) { OnOk(); });
75
76 s.AddFixedText(Verbatim("%"));
77 }
79 }
82
83 s.StartHorizontalLay(wxEXPAND, 0);
84 {
86 {
87 s.SetBorder(2);
88 s.StartHorizontalLay(wxEXPAND, 0);
89 {
90 s.AddSpace(0, 0, 1);
91
92 s.AddButton(XXO("&Cancel"))
93 ->Bind(wxEVT_BUTTON, [this](auto&) { EndModal(wxID_CANCEL); });
94
95 s.AddSpace(4, 0, 0);
96
97 auto okBtn = s.AddButton(XXO("&Ok"));
98 okBtn->Bind(wxEVT_BUTTON, [this](auto&) { OnOk(); });
99 okBtn->SetDefault();
100 }
102 }
104 }
106}
107
109{
111 EndModal(wxID_OK);
112}
113
115{
116 {
119 }
120
121 if (mClipSpeed <= 0.0)
122 {
124 /* i18n-hint: Title of an error message shown, when invalid clip speed is set */
125 wxWidgetsWindowPlacement { this }, XO("Invalid clip speed"),
126 XO("Clip speed must be a positive value"), {});
127
128 return false;
129 }
130
132 const auto maxEndTime = nextClip != nullptr ?
133 nextClip->Start() :
134 std::numeric_limits<double>::infinity();
135
136 const auto start = mTrackInterval.Start();
137 const auto end = mTrackInterval.End();
138
139 const auto expectedEndTime =
140 start + (end - start) * mOldClipSpeed / mClipSpeed;
141
142 if (expectedEndTime >= maxEndTime)
143 {
145 wxWidgetsWindowPlacement { this }, XO("Invalid clip speed"),
146 XO("There is not enough space to stretch the clip to the selected speed"), {});
147
148 return false;
149 }
150
151 mTrackInterval.StretchRightTo(expectedEndTime);
153
154 {
157 }
158
159 return true;
160}
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
@ eIsSettingToDialog
Definition: ShuttleGui.h:39
@ eIsCreating
Definition: ShuttleGui.h:37
@ eIsGettingFromDialog
Definition: ShuttleGui.h:38
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
WaveTrack::Interval & mTrackInterval
ChangeClipSpeedDialog(WaveTrack &track, WaveTrack::Interval &interval, wxWindow *parent=nullptr)
~ChangeClipSpeedDialog() override
void PopulateOrExchange(ShuttleGui &s)
double End() const
Definition: Channel.h:42
double Start() const
Definition: Channel.h:41
void SetBorder(int Border)
Definition: ShuttleGui.h:488
wxStaticText * AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:237
void EndMultiColumn()
void EndInvisiblePanel()
wxPanel * StartInvisiblePanel(int border=0)
void StartVerticalLay(int iProp=1)
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:361
void EndHorizontalLay()
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
wxTextCtrl * TieNumericTextBox(const TranslatableString &Prompt, int &Value, const int nChars=0, bool acceptEnter=false)
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:441
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:630
ShuttleGui & NameSuffix(const TranslatableString &suffix)
Definition: ShuttleGui.h:670
wxSizerItem * AddSpace(int width, int height, int prop=0)
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:662
double GetStretchRatio() const
Definition: WaveTrack.cpp:430
void StretchRightTo(double t)
Definition: WaveTrack.cpp:265
A Track that contains audio waveform data.
Definition: WaveTrack.h:227
IntervalConstHolder GetNextInterval(const Interval &interval, PlaybackDirection searchDirection) const
Definition: WaveTrack.cpp:516
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Definition: BasicUI.h:262
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.