1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +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
options.timeTrack = NULL;
ControlToolBar::PlayAppearance appearance =
cutPreview ? ControlToolBar::PlayAppearance::CutPreview
: options.playLooped ? ControlToolBar::PlayAppearance::Looped
: ControlToolBar::PlayAppearance::Straight;
auto mode =
cutPreview ? PlayMode::cutPreviewPlay
: options.playLooped ? PlayMode::loopedPlay
: PlayMode::normalPlay;
mPlayRegionStart = start;
mPlayRegionEnd = end;
Refresh();
ctb->PlayPlayRegion((SelectedRegion(start, end)),
options, PlayMode::normalPlay,
appearance,
options, mode,
false,
true);

View File

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

View File

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

View File

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

View File

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

View File

@ -707,8 +707,8 @@ void OnPlayOneSecond(const CommandContext &context)
auto options = project.GetDefaultPlayOptions();
double pos = trackPanel->GetMostRecentXPos();
controlToolBar->PlayPlayRegion
(SelectedRegion(pos - 0.5, pos + 0.5), options,
controlToolBar->PlayPlayRegion(
SelectedRegion(pos - 0.5, pos + 0.5), options,
PlayMode::oneSecondPlay);
}
@ -759,8 +759,8 @@ void OnPlayToSelection(const CommandContext &context)
auto controlToolBar = project.GetControlToolBar();
auto playOptions = project.GetDefaultPlayOptions();
controlToolBar->PlayPlayRegion
(SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay);
controlToolBar->PlayPlayRegion(
SelectedRegion(t0, t1), playOptions, PlayMode::oneSecondPlay);
}
// 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,
const AudioIOStartStreamOptions &options,
PlayMode mode,
PlayAppearance appearance, /* = PlayOption::Straight */
bool backwards, /* = false */
bool playWhiteSpace /* = false */)
// STRONG-GUARANTEE (for state of mCutPreviewTracks)
@ -563,7 +562,18 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (backwards)
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);
}
bool success = false;
auto cleanup = finally( [&] {
@ -577,7 +587,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (gAudioIO->IsBusy())
return -1;
const bool cutpreview = appearance == PlayAppearance::CutPreview;
const bool cutpreview = mode == PlayMode::cutPreviewPlay;
if (cutpreview && t0==t1)
return -1; /* msmeyer: makes no sense */
@ -589,7 +599,7 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
if (!t)
return -1; // Should never happen, but...
p->mLastPlayMode = mode;
mLastPlayMode = mode;
bool hasaudio;
if (useMidi)
@ -744,14 +754,13 @@ void ControlToolBar::PlayCurrentRegion(bool looped /* = false */,
options.playLooped = looped;
if (cutpreview)
options.timeTrack = NULL;
ControlToolBar::PlayAppearance appearance =
cutpreview ? ControlToolBar::PlayAppearance::CutPreview
: looped ? ControlToolBar::PlayAppearance::Looped
: ControlToolBar::PlayAppearance::Straight;
auto mode =
cutpreview ? PlayMode::cutPreviewPlay
: options.playLooped ? PlayMode::loopedPlay
: PlayMode::normalPlay;
PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd),
options,
(looped ? PlayMode::loopedPlay : PlayMode::normalPlay),
appearance);
mode);
}
}

View File

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

View File

@ -483,18 +483,15 @@ void TranscriptionToolBar::PlayAtSpeed(bool looped, bool cutPreview)
AudioIOStartStreamOptions options(p->GetDefaultPlayOptions());
options.playLooped = looped;
// 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();
ControlToolBar::PlayAppearance appearance =
cutPreview ? ControlToolBar::PlayAppearance::CutPreview
: looped ? ControlToolBar::PlayAppearance::Looped
: ControlToolBar::PlayAppearance::Straight;
auto mode =
cutPreview ? PlayMode::cutPreviewPlay
: options.playLooped ? PlayMode::loopedPlay
: PlayMode::normalPlay;
p->GetControlToolBar()->PlayPlayRegion
(SelectedRegion(playRegionStart, playRegionEnd),
options,
PlayMode::normalPlay,
appearance);
mode);
}
else
{

View File

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

View File

@ -394,13 +394,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
#endif
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;
#ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
static const double maxScrubSpeedBase =
@ -421,7 +414,7 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
mScrubToken =
ctb->PlayPlayRegion(SelectedRegion(time0, time1), options,
PlayMode::normalPlay, appearance, backwards);
PlayMode::normalPlay, backwards);
if (mScrubToken <= 0) {
// Bug1627 (part of it):
// 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.isPlayingAtSpeed = true;
ControlToolBar::PlayAppearance appearance = ControlToolBar::PlayAppearance::Straight;
const bool backwards = time1 < time0;
#ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
static const double maxScrubSpeedBase =
@ -510,7 +501,7 @@ bool Scrubber::StartSpeedPlay(double speed, double time0, double time1)
mScrubToken =
// Reduce time by 'stopTolerance' fudge factor, so that the Play will stop.
ctb->PlayPlayRegion(SelectedRegion(time0, time1-stopTolerance), options,
PlayMode::normalPlay, appearance, backwards);
PlayMode::normalPlay, backwards);
if (mScrubToken >= 0) {
mLastScrubPosition = 0;