1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-23 15:50:05 +02:00

enum PlayMode tells whether there's cut preview; out of Project.h

This commit is contained in:
Paul Licameli 2019-01-19 11:41:11 -05:00
parent 0bd9bb3b90
commit dccb716f39
11 changed files with 61 additions and 58 deletions

View File

@ -1587,18 +1587,17 @@ void AdornedRulerPanel::StartQPPlay(bool looped, bool cutPreview)
else else
options.timeTrack = NULL; options.timeTrack = NULL;
ControlToolBar::PlayAppearance appearance = auto mode =
cutPreview ? ControlToolBar::PlayAppearance::CutPreview cutPreview ? PlayMode::cutPreviewPlay
: options.playLooped ? ControlToolBar::PlayAppearance::Looped : options.playLooped ? PlayMode::loopedPlay
: ControlToolBar::PlayAppearance::Straight; : PlayMode::normalPlay;
mPlayRegionStart = start; mPlayRegionStart = start;
mPlayRegionEnd = end; mPlayRegionEnd = end;
Refresh(); Refresh();
ctb->PlayPlayRegion((SelectedRegion(start, end)), ctb->PlayPlayRegion((SelectedRegion(start, end)),
options, PlayMode::normalPlay, options, mode,
appearance,
false, false,
true); true);

View File

@ -5371,7 +5371,7 @@ void AudioIoCallback::SendVuOutputMeterData(
//MixerBoard* pMixerBoard = mOwningProject->GetMixerBoard(); //MixerBoard* pMixerBoard = mOwningProject->GetMixerBoard();
//if (pMixerBoard) //if (pMixerBoard)
// pMixerBoard->UpdateMeters(GetStreamTime(), // pMixerBoard->UpdateMeters(GetStreamTime(),
// (pProj->mLastPlayMode == loopedPlay)); // (pProj->GetControlToolBar()->GetLastPlayMode() == loopedPlay));
} }
mUpdatingMeters = false; mUpdatingMeters = false;
} }

View File

@ -54,6 +54,7 @@
#endif #endif
#include "commands/CommandManager.h" #include "commands/CommandManager.h"
#include "toolbars/ControlToolBar.h"
// class MixerTrackSlider // class MixerTrackSlider
@ -1344,8 +1345,11 @@ void MixerBoard::OnTimer(wxCommandEvent &event)
// audacityAudioCallback where it calls gAudioIO->mOutputMeter->UpdateDisplay(). // audacityAudioCallback where it calls gAudioIO->mOutputMeter->UpdateDisplay().
if (mProject->IsAudioActive()) if (mProject->IsAudioActive())
{ {
UpdateMeters(gAudioIO->GetStreamTime(), UpdateMeters(
(mProject->mLastPlayMode == PlayMode::loopedPlay)); gAudioIO->GetStreamTime(),
(mProject->GetControlToolBar()->GetLastPlayMode()
== PlayMode::loopedPlay)
);
} }
// Let other listeners get the notification // Let other listeners get the notification

View File

@ -116,12 +116,6 @@ using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >;
extern AProjectArray gAudacityProjects; extern AProjectArray gAudacityProjects;
enum class PlayMode : int {
normalPlay,
oneSecondPlay, // Disables auto-scrolling
loopedPlay // Disables auto-scrolling
};
enum StatusBarField { enum StatusBarField {
stateStatusBarField = 1, stateStatusBarField = 1,
mainStatusBarField = 2, mainStatusBarField = 2,
@ -524,7 +518,6 @@ public:
void WriteXMLHeader(XMLWriter &xmlFile) const; void WriteXMLHeader(XMLWriter &xmlFile) const;
PlayMode mLastPlayMode{ PlayMode::normalPlay };
ViewInfo mViewInfo; ViewInfo mViewInfo;
// Audio IO callback methods // Audio IO callback methods

View File

@ -3529,9 +3529,10 @@ void EffectUIHost::OnPlay(wxCommandEvent & WXUNUSED(evt))
mPlayPos = mRegion.t1(); mPlayPos = mRegion.t1();
} }
mProject->GetControlToolBar()->PlayPlayRegion mProject->GetControlToolBar()->PlayPlayRegion(
(SelectedRegion(mPlayPos, mRegion.t1()), SelectedRegion(mPlayPos, mRegion.t1()),
mProject->GetDefaultPlayOptions(), PlayMode::normalPlay); mProject->GetDefaultPlayOptions(),
PlayMode::normalPlay );
} }
} }

View File

@ -707,8 +707,8 @@ void OnPlayOneSecond(const CommandContext &context)
auto options = project.GetDefaultPlayOptions(); auto options = project.GetDefaultPlayOptions();
double pos = trackPanel->GetMostRecentXPos(); double pos = trackPanel->GetMostRecentXPos();
controlToolBar->PlayPlayRegion controlToolBar->PlayPlayRegion(
(SelectedRegion(pos - 0.5, pos + 0.5), options, SelectedRegion(pos - 0.5, pos + 0.5), options,
PlayMode::oneSecondPlay); PlayMode::oneSecondPlay);
} }
@ -759,8 +759,8 @@ void OnPlayToSelection(const CommandContext &context)
auto controlToolBar = project.GetControlToolBar(); auto controlToolBar = project.GetControlToolBar();
auto playOptions = project.GetDefaultPlayOptions(); auto playOptions = project.GetDefaultPlayOptions();
controlToolBar->PlayPlayRegion controlToolBar->PlayPlayRegion(
(SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay); SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay);
} }
// The next 4 functions provide a limited version of the // The next 4 functions provide a limited version of the

View File

@ -537,7 +537,6 @@ bool ControlToolBar::IsRecordDown() const
int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
const AudioIOStartStreamOptions &options, const AudioIOStartStreamOptions &options,
PlayMode mode, PlayMode mode,
PlayAppearance appearance, /* = PlayOption::Straight */
bool backwards, /* = false */ bool backwards, /* = false */
bool playWhiteSpace /* = false */) bool playWhiteSpace /* = false */)
// STRONG-GUARANTEE (for state of mCutPreviewTracks) // STRONG-GUARANTEE (for state of mCutPreviewTracks)
@ -563,7 +562,18 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (backwards) if (backwards)
std::swap(t0, t1); std::swap(t0, t1);
{
PlayAppearance appearance;
switch( mode ) {
case PlayMode::cutPreviewPlay:
appearance = PlayAppearance::CutPreview; break;
case PlayMode::loopedPlay:
appearance = PlayAppearance::Looped; break;
default:
appearance = PlayAppearance::Straight; break;
}
SetPlay(true, appearance); SetPlay(true, appearance);
}
bool success = false; bool success = false;
auto cleanup = finally( [&] { auto cleanup = finally( [&] {
@ -577,7 +587,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (gAudioIO->IsBusy()) if (gAudioIO->IsBusy())
return -1; return -1;
const bool cutpreview = appearance == PlayAppearance::CutPreview; const bool cutpreview = mode == PlayMode::cutPreviewPlay;
if (cutpreview && t0==t1) if (cutpreview && t0==t1)
return -1; /* msmeyer: makes no sense */ return -1; /* msmeyer: makes no sense */
@ -589,7 +599,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (!t) if (!t)
return -1; // Should never happen, but... return -1; // Should never happen, but...
p->mLastPlayMode = mode; mLastPlayMode = mode;
bool hasaudio; bool hasaudio;
if (useMidi) if (useMidi)
@ -744,14 +754,13 @@ void ControlToolBar::PlayCurrentRegion(bool looped /* = false */,
options.playLooped = looped; options.playLooped = looped;
if (cutpreview) if (cutpreview)
options.timeTrack = NULL; options.timeTrack = NULL;
ControlToolBar::PlayAppearance appearance = auto mode =
cutpreview ? ControlToolBar::PlayAppearance::CutPreview cutpreview ? PlayMode::cutPreviewPlay
: looped ? ControlToolBar::PlayAppearance::Looped : options.playLooped ? PlayMode::loopedPlay
: ControlToolBar::PlayAppearance::Straight; : PlayMode::normalPlay;
PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd), PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd),
options, options,
(looped ? PlayMode::loopedPlay : PlayMode::normalPlay), mode);
appearance);
} }
} }

View File

@ -33,8 +33,12 @@ class TimeTrack;
struct AudioIOStartStreamOptions; struct AudioIOStartStreamOptions;
class SelectedRegion; class SelectedRegion;
// Defined in Project.h enum class PlayMode : int {
enum class PlayMode : int; normalPlay,
oneSecondPlay, // Disables auto-scrolling
loopedPlay, // Disables auto-scrolling
cutPreviewPlay
};
class WaveTrack; class WaveTrack;
using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >; using WaveTrackArray = std::vector < std::shared_ptr < WaveTrack > >;
@ -100,7 +104,6 @@ class ControlToolBar final : public ToolBar {
int PlayPlayRegion(const SelectedRegion &selectedRegion, int PlayPlayRegion(const SelectedRegion &selectedRegion,
const AudioIOStartStreamOptions &options, const AudioIOStartStreamOptions &options,
PlayMode playMode, PlayMode playMode,
PlayAppearance appearance = PlayAppearance::Straight,
bool backwards = false, bool backwards = false,
// Allow t0 and t1 to be beyond end of tracks // Allow t0 and t1 to be beyond end of tracks
bool playWhiteSpace = false); bool playWhiteSpace = false);
@ -133,6 +136,8 @@ class ControlToolBar final : public ToolBar {
// Cancel the addition of temporary recording tracks into the project // Cancel the addition of temporary recording tracks into the project
void CancelRecording(); void CancelRecording();
PlayMode GetLastPlayMode() const { return mLastPlayMode; }
private: private:
static AButton *MakeButton( static AButton *MakeButton(
@ -192,6 +197,8 @@ class ControlToolBar final : public ToolBar {
wxString mStateRecord; wxString mStateRecord;
wxString mStatePause; wxString mStatePause;
PlayMode mLastPlayMode{ PlayMode::normalPlay };
public: public:
DECLARE_CLASS(ControlToolBar) DECLARE_CLASS(ControlToolBar)

View File

@ -483,18 +483,15 @@ void TranscriptionToolBar::PlayAtSpeed(bool looped, bool cutPreview)
AudioIOStartStreamOptions options(p->GetDefaultPlayOptions()); AudioIOStartStreamOptions options(p->GetDefaultPlayOptions());
options.playLooped = looped; options.playLooped = looped;
// No need to set cutPreview options. // No need to set cutPreview options.
// Due to a rather hacky approach, the appearance is used
// to signal use of cutpreview to code below.
options.timeTrack = mTimeTrack.get(); options.timeTrack = mTimeTrack.get();
ControlToolBar::PlayAppearance appearance = auto mode =
cutPreview ? ControlToolBar::PlayAppearance::CutPreview cutPreview ? PlayMode::cutPreviewPlay
: looped ? ControlToolBar::PlayAppearance::Looped : options.playLooped ? PlayMode::loopedPlay
: ControlToolBar::PlayAppearance::Straight; : PlayMode::normalPlay;
p->GetControlToolBar()->PlayPlayRegion p->GetControlToolBar()->PlayPlayRegion
(SelectedRegion(playRegionStart, playRegionEnd), (SelectedRegion(playRegionStart, playRegionEnd),
options, options,
PlayMode::normalPlay, mode);
appearance);
} }
else else
{ {

View File

@ -17,6 +17,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Project.h" #include "../../Project.h"
#include "../../TrackPanel.h" #include "../../TrackPanel.h"
#include "Scrubbing.h" #include "Scrubbing.h"
#include "../../toolbars/ControlToolBar.h"
#include <wx/dc.h> #include <wx/dc.h>
@ -176,9 +177,10 @@ void PlayIndicatorOverlay::OnTimer(wxCommandEvent &event)
playPos >= 0 && !onScreen ) { playPos >= 0 && !onScreen ) {
// msmeyer: But only if not playing looped or in one-second mode // msmeyer: But only if not playing looped or in one-second mode
// PRL: and not scrolling with play/record head fixed // PRL: and not scrolling with play/record head fixed
auto mode = mProject->GetControlToolBar()->GetLastPlayMode();
if (!pinned && if (!pinned &&
mProject->mLastPlayMode != PlayMode::loopedPlay && mode != PlayMode::loopedPlay &&
mProject->mLastPlayMode != PlayMode::oneSecondPlay && mode != PlayMode::oneSecondPlay &&
!gAudioIO->IsPaused()) !gAudioIO->IsPaused())
{ {
auto newPos = playPos; auto newPos = playPos;

View File

@ -394,13 +394,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
#endif #endif
std::max(0.0, MinStutter); std::max(0.0, MinStutter);
ControlToolBar::PlayAppearance appearance =
// commented out to fix Bug 1241
// mSeeking
// ? ControlToolBar::PlayAppearance::Seek
// : ControlToolBar::PlayAppearance::Scrub;
ControlToolBar::PlayAppearance::Straight;
// const bool cutPreview = false;
const bool backwards = time1 < time0; const bool backwards = time1 < time0;
#ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
static const double maxScrubSpeedBase = static const double maxScrubSpeedBase =
@ -421,7 +414,7 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
mScrubToken = mScrubToken =
ctb->PlayPlayRegion(SelectedRegion(time0, time1), options, ctb->PlayPlayRegion(SelectedRegion(time0, time1), options,
PlayMode::normalPlay, appearance, backwards); PlayMode::normalPlay, backwards);
if (mScrubToken <= 0) { if (mScrubToken <= 0) {
// Bug1627 (part of it): // Bug1627 (part of it):
// infinite error spew when trying to start scrub: // infinite error spew when trying to start scrub:
@ -485,8 +478,6 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1)
mOptions.adjustStart = false; mOptions.adjustStart = false;
mOptions.isPlayingAtSpeed = true; mOptions.isPlayingAtSpeed = true;
ControlToolBar::PlayAppearance appearance = ControlToolBar::PlayAppearance::Straight;
const bool backwards = time1 < time0; const bool backwards = time1 < time0;
#ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL #ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
static const double maxScrubSpeedBase = static const double maxScrubSpeedBase =
@ -510,7 +501,7 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1)
mScrubToken = mScrubToken =
// Reduce time by 'stopTolerance' fudge factor, so that the Play will stop. // Reduce time by 'stopTolerance' fudge factor, so that the Play will stop.
ctb->PlayPlayRegion(SelectedRegion(time0, time1-stopTolerance), options, ctb->PlayPlayRegion(SelectedRegion(time0, time1-stopTolerance), options,
PlayMode::normalPlay, appearance, backwards); PlayMode::normalPlay, backwards);
if (mScrubToken >= 0) { if (mScrubToken >= 0) {
mLastScrubPosition = 0; mLastScrubPosition = 0;