30#include <wx/checkbox.h>
32#include <wx/spinctrl.h>
33#include <wx/textctrl.h>
50 std::shared_ptr<WaveTrack>
track;
51 std::shared_ptr<WaveTrack::Interval>
clip;
57 const auto pos =
event.event.GetPosition();
59 const auto t = viewInfo.PositionToTime(pos.x, event.
rect.GetX());
63 const auto trackRect = trackPanel.FindTrackRect(leader);
64 if (!trackRect.Contains(pos))
66 auto [
begin,
end] = leader->Intervals();
70 if (clip->WithinPlayRegion(t))
71 return HitClip { std::static_pointer_cast<WaveTrack>(
72 leader->SharedPointer()),
93 while (shift.cents <= -100)
98 while (shift.cents >= 100)
104 const auto onlySemitonesChanged = [](
int oldCents,
int newCents) {
109 return oldCents / 100 != newCents / 100;
110 }(oldCents, newCents);
112 if (onlySemitonesChanged && shift.cents > 0 && shift.semis < 0)
113 return { shift.semis + 1, shift.cents - 100 };
114 else if (onlySemitonesChanged && shift.cents < 0 && shift.semis > 0)
115 return { shift.semis - 1, shift.cents + 100 };
124 const auto cents = shift.
semis * 100 + shift.
cents;
134 return { totalShift / 100, totalShift % 100 };
137static const AttachedWindows::RegisteredFactory
key {
158 auto* pPanel = attachedWindows.Find(
key);
161 pPanel->wxWindow::Destroy();
162 attachedWindows.Assign(
key,
nullptr);
169 { 480, 250 }, wxDEFAULT_DIALOG_STYLE)
173 , mTitle { GetTitle() }
175 Bind(wxEVT_CLOSE_WINDOW, [
this](
const auto&) {
Show(
false); });
177 Bind(wxEVT_CHAR_HOOK, [
this](wxKeyEvent& event) {
178 if (event.GetKeyCode() == WXK_ESCAPE)
186 mAudioIOSubscription =
192 case AudioIOEvent::CAPTURE:
193 case AudioIOEvent::PLAYBACK:
194 if (const auto child = wxDialog::FindWindowById(speedCtrlId))
195 child->Enable(!event.on);
197 case AudioIOEvent::MONITOR:
198 case AudioIOEvent::PAUSE:
211 if (!target.has_value() || target->clip ==
mLeftClip.lock())
213 Retarget(target->track, target->clip);
217 const std::shared_ptr<WaveTrack>& track,
221 wxDialog::SetTitle(
mTitle +
" - " + clip->GetName());
222 const auto leftClip = clip;
224 leftClip->Observer::Publisher<WaveClipDtorCalled>::Subscribe(
227 leftClip->Observer::Publisher<CentShiftChange>::Subscribe(
234 leftClip->Observer::Publisher<StretchRatioChange>::Subscribe(
242 mClipSpeed = 100.0 / leftClip->GetStretchRatio();
269 const std::optional<PitchAndSpeedDialogGroup>& group)
274 wxWindow::FindWindowById(
304 semiSpin->Bind(wxEVT_SPINCTRL, [
this, semiSpin](
const auto&) {
321 if (prevSemis < 0 && mShift.semis > 0)
323 else if (prevSemis > 0 && mShift.semis < 0)
329 const auto centSpin =
331 centSpin->Bind(wxEVT_SPINCTRL, [
this, centSpin](
const auto&) {
351 wxSize(60, -1),
XO(
"&speed %: "),
mClipSpeed, 1000.0, 1.0);
352#if wxUSE_ACCESSIBILITY
355 const auto playbackOngoing =
357 txtCtrl->Enable(!playbackOngoing);
359 wxEVT_SPINCTRL, [
this, txtCtrl](wxCommandEvent& event) {
365 *target->track, *target->clip);
381 ->Bind(wxEVT_CHECKBOX, [
this](
auto&) {
384 target->clip->SetPitchAndSpeedPreset(
400 const auto wasExactlySelected =
404 *target->track, *target->clip, 100 /
mClipSpeed))
407 if (wasExactlySelected)
428std::optional<PitchAndSpeedDialog::StrongTarget>
431 if (
const auto track =
mTrack.lock())
432 if (
const auto leftClip =
mLeftClip.lock())
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
accessors for certain important windows associated with each project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
virtual double GetPlayEndTime() const =0
virtual double GetPlayStartTime() const =0
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Observer::Subscription mClipSpeedChangeSubscription
static PitchAndSpeedDialog & Get(AudacityProject &project)
void TryRetarget(const TrackPanelMouseEvent &event)
std::optional< StrongTarget > LockTarget()
Observer::Subscription mClipDeletedSubscription
void UpdateHistory(const TranslatableString &desc)
static void Destroy(AudacityProject &project)
bool Show(bool show) override
std::weak_ptr< WaveClip > mLeftClip
bool mOldFormantPreservation
AudacityProject & mProject
PitchAndSpeedDialog & Retarget(const std::shared_ptr< WaveTrack > &track, const WaveTrack::IntervalHolder &wideClip)
std::weak_ptr< WaveTrack > mTrack
PitchAndSpeedDialog(AudacityProject &project)
void PopulateOrExchange(ShuttleGui &s)
Observer::Subscription mClipCentShiftChangeSubscription
bool mFormantPreservation
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
void SetBorder(int Border)
wxCheckBox * TieCheckBox(const TranslatableString &Prompt, bool &Var)
wxSpinCtrl * TieSpinCtrl(const TranslatableString &Prompt, int &Value, const int max, const int min=0)
SpinControl * TieSpinControl(const wxSize &size, const TranslatableString &Prompt, double &Value, const double max, const double min=0)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
wxSizerItem * AddSpace(int width, int height, int prop=0)
ShuttleGui & Name(const TranslatableString &name)
static constexpr auto MaxCents
static constexpr auto MinCents
static TrackList & Get(AudacityProject &project)
static TrackPanel & Get(AudacityProject &project)
void RefreshTrack(Track *trk, bool refreshbacking=true)
Holds a msgid for the translation catalog; may also bind format arguments.
static ViewInfo & Get(AudacityProject &project)
This allows multiple clips to be a part of one WaveTrack.
int GetCentShift() const override
std::shared_ptr< Interval > IntervalHolder
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)
WAVE_TRACK_API bool SetClipStretchRatio(const WaveTrack &track, WaveTrack::Interval &interval, double stretchRatio)
void SelectClip(AudacityProject &project, const WaveTrack::Interval &clip)
WAVE_TRACK_API void ExpandClipTillNextOne(const WaveTrack &track, WaveTrack::Interval &interval)
const TranslatableString desc
constexpr auto semitoneCtrlId
constexpr auto speedCtrlId
void ClampPitchShift(PitchAndSpeedDialog::PitchShift &shift)
static const AttachedWindows::RegisteredFactory key
std::optional< HitClip > GetHitClip(AudacityProject &project, const TrackPanelMouseEvent &event)
bool IsExactlySelected(AudacityProject &project, const ClipTimes &clip)
PitchAndSpeedDialog::PitchShift GetClipShift(const WaveClip &clip)
PitchAndSpeedDialog::PitchShift ToSemitonesAndCents(int oldCents, int newCents)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept
enum AudioIOEvent::Type type
AudacityProject * pProject
Message sent when the project window is closed.
std::shared_ptr< WaveTrack > track
std::shared_ptr< WaveTrack::Interval > clip