1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 16:49:41 +02:00

Merge branch 'master' into scrubbing

This commit is contained in:
Paul Licameli 2016-06-03 08:34:16 -04:00
commit 7e2380d496
21 changed files with 4873 additions and 5170 deletions

View File

@ -69,6 +69,8 @@ from there. Audacity will look for a file called "Pause.png".
DEFINE_IMAGE( bmpAppendRecordDisabled, wxImage( 16, 16 ), wxT("AppendRecordDisabled"));
DEFINE_IMAGE( bmpScrubDisabled, wxImage( 16, 16 ), wxT("ScrubDisabled"));
DEFINE_IMAGE( bmpScrub, wxImage( 16, 16 ), wxT("Scrub"));
DEFINE_IMAGE( bmpSeekDisabled, wxImage( 24, 16 ), wxT("SeekDisabled"));
DEFINE_IMAGE( bmpSeek, wxImage( 24, 16 ), wxT("Seek"));
SET_THEME_FLAGS( resFlagNewLine );
DEFINE_IMAGE( bmpUpButtonLarge, wxImage( 48, 48 ), wxT("UpButtonLarge"));
@ -123,6 +125,9 @@ from there. Audacity will look for a file called "Pause.png".
DEFINE_IMAGE( bmpMic, wxImage( 25, 25 ), wxT("Mic"));
DEFINE_IMAGE( bmpSpeaker, wxImage( 25, 25 ), wxT("Speaker"));
DEFINE_IMAGE( bmpPinnedPlayRecordHead, wxImage( 27, 27 ), wxT("PinnedPlayRecordHead"));
DEFINE_IMAGE( bmpUnpinnedPlayRecordHead, wxImage( 27, 27 ), wxT("UnpinnedPlayRecordHead"));
SET_THEME_FLAGS( resFlagPaired );
DEFINE_IMAGE( bmpZoomFit, wxImage( 27, 27 ), wxT("ZoomFit"));
DEFINE_IMAGE( bmpZoomFitDisabled, wxImage( 27, 27 ), wxT("ZoomFitDisabled"));

View File

@ -69,6 +69,7 @@ simplifies construction of menu items.
#include "export/Export.h"
#include "export/ExportMultiple.h"
#include "prefs/PrefsDialog.h"
#include "prefs/PlaybackPrefs.h"
#include "ShuttleGui.h"
#include "HistoryWindow.h"
#include "LyricsWindow.h"
@ -772,6 +773,11 @@ void AudacityProject::CreateMenusAndCommands()
c->AddSeparator();
c->AddCheck(wxT("PinnedHead"), _("Pinned Recording/Playback Head"),
FN(OnTogglePinnedHead), 0,
// Switching of scrolling on and off is permitted even during transport
AlwaysEnabledFlag, AlwaysEnabledFlag);
c->AddCheck(wxT("Duplex"), _("&Overdub (on/off)"), FN(OnTogglePlayRecording), 0);
c->AddCheck(wxT("SWPlaythrough"), _("So&ftware Playthrough (on/off)"), FN(OnToggleSWPlaythrough), 0);
@ -1840,6 +1846,10 @@ void AudacityProject::ModifyToolbarMenus()
gPrefs->Read(wxT("/AudioIO/AutomatedInputLevelAdjustment"),&active, false);
mCommandManager.Check(wxT("AutomatedInputLevelAdjustmentOnOff"), active);
#endif
active = PlaybackPrefs::GetPinnedHeadPreference();
mCommandManager.Check(wxT("PinnedHead"), active);
gPrefs->Read(wxT("/AudioIO/Duplex"),&active, true);
mCommandManager.Check(wxT("Duplex"), active);
gPrefs->Read(wxT("/AudioIO/SWPlaythrough"),&active, false);
@ -2360,6 +2370,27 @@ void AudacityProject::OnToggleSoundActivated()
ModifyAllProjectToolbarMenus();
}
void AudacityProject::OnTogglePinnedHead()
{
bool value = !PlaybackPrefs::GetPinnedHeadPreference();
PlaybackPrefs::SetPinnedHeadPreference(value, true);
ModifyAllProjectToolbarMenus();
// Change what happens in case transport is in progress right now
auto ctb = GetActiveProject()->GetControlToolBar();
if (ctb)
ctb->StartScrollingIfPreferred();
auto ruler = GetRulerPanel();
if (ruler)
// Update button image
ruler->UpdateButtonStates();
auto &scrubber = GetScrubber();
if (scrubber.HasStartedScrubbing())
scrubber.SetScrollScrubbing(value);
}
void AudacityProject::OnTogglePlayRecording()
{
bool Duplex;

View File

@ -313,6 +313,7 @@ void OnResetToolBars();
void OnSoundActivated();
void OnToggleSoundActivated();
void OnTogglePinnedHead();
void OnTogglePlayRecording();
void OnToggleSWPlaythrough();
#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT

View File

@ -890,7 +890,7 @@ AudacityProject::AudacityProject(wxWindow * parent, wxWindowID id,
mRuler = safenew AdornedRulerPanel( this,
wxID_ANY,
wxDefaultPosition,
wxSize( -1, AdornedRulerPanel::GetRulerHeight() ),
wxSize( -1, AdornedRulerPanel::GetRulerHeight(false) ),
&mViewInfo );
//

View File

@ -65,6 +65,7 @@ and use it for toolbar and window layouts too.
#include "Project.h"
#include "toolbars/ToolBar.h"
#include "toolbars/ToolManager.h"
#include "widgets/Ruler.h"
#include "ImageManipulation.h"
#include "Theme.h"
#include "Experimental.h"
@ -230,6 +231,7 @@ void Theme::ApplyUpdatedImages()
if( pToolBar )
pToolBar->ReCreateButtons();
}
p->GetRulerPanel()->ReCreateButtons();
}
void Theme::RegisterImages()
@ -958,27 +960,41 @@ void ThemeBase::SaveComponents()
if( (mBitmapFlags[i] & resFlagInternal)==0)
{
FileName = FileNames::ThemeComponent( mBitmapNames[i] );
if( !wxFileExists( FileName ))
if( wxFileExists( FileName ))
{
if( !mImages[i].SaveFile( FileName, wxBITMAP_TYPE_PNG ))
{
wxMessageBox(
wxString::Format(
_("Audacity could not save file:\n %s"),
FileName.c_str() ));
return;
}
n++;
++n;
break;
}
}
}
if( n==0 )
if (n > 0)
{
wxMessageBox(
wxString::Format(
_("All required files in:\n %s\nwere already present."),
FileNames::ThemeComponentsDir().c_str() ));
return;
auto result =
wxMessageBox(
wxString::Format(
_("Some required files in:\n %s\nwere already present. Overwrite?"),
FileNames::ThemeComponentsDir().c_str()),
wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT);
if(result == wxNO)
return;
}
for(i=0;i<(int)mImages.GetCount();i++)
{
if( (mBitmapFlags[i] & resFlagInternal)==0)
{
FileName = FileNames::ThemeComponent( mBitmapNames[i] );
if( !mImages[i].SaveFile( FileName, wxBITMAP_TYPE_PNG ))
{
wxMessageBox(
wxString::Format(
_("Audacity could not save file:\n %s"),
FileName.c_str() ));
return;
}
}
}
wxMessageBox(
wxString::Format(

File diff suppressed because it is too large Load Diff

View File

@ -19,13 +19,25 @@
*//********************************************************************/
#include "../Audacity.h"
#include "PlaybackPrefs.h"
#include <wx/defs.h>
#include <wx/textctrl.h>
#include "../ShuttleGui.h"
#include "../Prefs.h"
#include "PlaybackPrefs.h"
namespace {
const wxChar *PinnedHeadPreferenceKey()
{
return wxT("/AudioIO/PinnedHead");
}
bool PinnedHeadPreferenceDefault()
{
return false;
}
}
PlaybackPrefs::PlaybackPrefs(wxWindow * parent)
: PrefsPanel(parent, _("Playback"))
@ -113,6 +125,11 @@ void PlaybackPrefs::PopulateOrExchange(ShuttleGui & S)
S.EndThreeColumn();
}
S.EndStatic();
// This affects recording too, though it is in playback preferences.
S.TieCheckBox(_("Pinned playback/recording head"),
PinnedHeadPreferenceKey(),
PinnedHeadPreferenceDefault());
}
bool PlaybackPrefs::Apply()
@ -123,8 +140,21 @@ bool PlaybackPrefs::Apply()
return true;
}
bool PlaybackPrefs::GetPinnedHeadPreference()
{
return gPrefs->ReadBool(PinnedHeadPreferenceKey(), PinnedHeadPreferenceDefault());
}
void PlaybackPrefs::SetPinnedHeadPreference(bool value, bool flush)
{
gPrefs->Write(PinnedHeadPreferenceKey(), value);
if(flush)
gPrefs->Flush();
}
PrefsPanel *PlaybackPrefsFactory::Create(wxWindow *parent)
{
wxASSERT(parent); // to justify safenew
return safenew PlaybackPrefs(parent);
}

View File

@ -27,6 +27,9 @@ class PlaybackPrefs final : public PrefsPanel
virtual ~PlaybackPrefs();
bool Apply() override;
static bool GetPinnedHeadPreference();
static void SetPinnedHeadPreference(bool value, bool flush = false);
private:
void Populate();
void PopulateOrExchange(ShuttleGui & S);

View File

@ -68,6 +68,7 @@
#include "../widgets/Meter.h"
#include "../tracks/ui/Scrubbing.h"
#include "../prefs/PlaybackPrefs.h"
IMPLEMENT_CLASS(ControlToolBar, ToolBar);
@ -129,7 +130,7 @@ AButton *ControlToolBar::MakeButton(teBmps eEnabledUp, teBmps eEnabledDown, teBm
bool processdownevents,
const wxChar *label)
{
AButton *r = ToolBar::MakeButton(
AButton *r = ToolBar::MakeButton(this,
bmpRecoloredUpLarge, bmpRecoloredDownLarge, bmpRecoloredHiliteLarge,
eEnabledUp, eEnabledDown, eDisabled,
wxWindowID(id),
@ -167,6 +168,8 @@ void ControlToolBar::Populate()
bmpCutPreview, bmpCutPreview, bmpCutPreviewDisabled);
MakeAlternateImages(*mPlay, 3,
bmpScrub, bmpScrub, bmpScrubDisabled);
MakeAlternateImages(*mPlay, 4,
bmpSeek, bmpSeek, bmpSeekDisabled);
mPlay->FollowModifierKeys();
mStop = MakeButton( bmpStop, bmpStop, bmpStopDisabled ,
@ -635,15 +638,16 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
NoteTrackArray(),
#endif
tcp0, tcp1, myOptions);
} else
{
}
else {
// Cannot create cut preview tracks, clean up and exit
SetPlay(false);
SetStop(false);
SetRecord(false);
return -1;
}
} else {
}
else {
// Lifted the following into AudacityProject::GetDefaultPlayOptions()
/*
if (!timetrack) {
@ -682,6 +686,8 @@ int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion,
return -1;
}
StartScrollingIfPreferred();
// Let other UI update appearance
if (p)
p->GetRulerPanel()->HideQuickPlayIndicator();
@ -745,25 +751,17 @@ void ControlToolBar::OnKeyEvent(wxKeyEvent & event)
void ControlToolBar::OnPlay(wxCommandEvent & WXUNUSED(evt))
{
auto doubleClicked = mPlay->IsDoubleClicked();
mPlay->ClearDoubleClicked();
auto p = GetActiveProject();
if (doubleClicked)
p->GetPlaybackScroller().Activate
(AudacityProject::PlaybackScroller::Mode::Centered);
else {
if (!CanStopAudioStream())
return;
if (!CanStopAudioStream())
return;
StopPlaying();
StopPlaying();
if (p) p->TP_DisplaySelection();
if (p) p->TP_DisplaySelection();
PlayDefault();
UpdateStatusBar(p);
}
PlayDefault();
UpdateStatusBar(p);
}
void ControlToolBar::OnStop(wxCommandEvent & WXUNUSED(evt))
@ -792,11 +790,11 @@ void ControlToolBar::PlayDefault()
void ControlToolBar::StopPlaying(bool stopStream /* = true*/)
{
StopScrolling();
AudacityProject *project = GetActiveProject();
if(project) {
project->GetPlaybackScroller().Activate
(AudacityProject::PlaybackScroller::Mode::Off);
// Let scrubbing code do some appearance change
project->GetScrubber().StopScrubbing();
}
@ -853,29 +851,6 @@ void ControlToolBar::Pause()
void ControlToolBar::OnRecord(wxCommandEvent &evt)
{
auto doubleClicked = mRecord->IsDoubleClicked();
mRecord->ClearDoubleClicked();
if (doubleClicked) {
// Display a fixed recording head while scrolling the waves continuously.
// If you overdub, you may want to anticipate some context in existing tracks,
// so center the head. If not, put it rightmost to display as much wave as we can.
const auto project = GetActiveProject();
bool duplex;
gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true);
if (duplex) {
// See if there is really anything being overdubbed
if (gAudioIO->GetNumPlaybackChannels() == 0)
// No.
duplex = false;
}
using Mode = AudacityProject::PlaybackScroller::Mode;
project->GetPlaybackScroller().Activate(duplex ? Mode::Centered : Mode::Right);
return;
}
if (gAudioIO->IsBusy()) {
if (!CanStopAudioStream() || 0 == gAudioIO->GetNumCaptureChannels())
mRecord->PopUp();
@ -1092,6 +1067,8 @@ void ControlToolBar::OnRecord(wxCommandEvent &evt)
if (success) {
p->SetAudioIOToken(token);
mBusyProject = p;
StartScrollingIfPreferred();
}
else {
if (shifted) {
@ -1278,3 +1255,60 @@ void ControlToolBar::UpdateStatusBar(AudacityProject *pProject)
{
pProject->GetStatusBar()->SetStatusText(StateForStatusBar(), stateStatusBarField);
}
void ControlToolBar::StartScrollingIfPreferred()
{
if (PlaybackPrefs::GetPinnedHeadPreference())
StartScrolling();
#ifdef __WXMAC__
else if (::GetActiveProject()->GetScrubber().HasStartedScrubbing()) {
// PRL: cause many "unnecessary" refreshes. For reasons I don't understand,
// doing this causes wheel rotation events (mapped from the double finger vertical
// swipe) to be delivered more uniformly to the application, so that speed control
// works better.
::GetActiveProject()->GetPlaybackScroller().Activate
(AudacityProject::PlaybackScroller::Mode::Refresh);
}
#endif
else
StopScrolling();
}
void ControlToolBar::StartScrolling()
{
using Mode = AudacityProject::PlaybackScroller::Mode;
const auto project = GetActiveProject();
if (project) {
auto mode = Mode::Centered;
if (gAudioIO->GetNumCaptureChannels() > 0) {
// recording
// Display a fixed recording head while scrolling the waves continuously.
// If you overdub, you may want to anticipate some context in existing tracks,
// so center the head. If not, put it rightmost to display as much wave as we can.
bool duplex;
gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true);
if (duplex) {
// See if there is really anything being overdubbed
if (gAudioIO->GetNumPlaybackChannels() == 0)
// No.
duplex = false;
}
if (!duplex)
mode = Mode::Right;
}
project->GetPlaybackScroller().Activate(mode);
}
}
void ControlToolBar::StopScrolling()
{
const auto project = GetActiveProject();
if(project)
project->GetPlaybackScroller().Activate
(AudacityProject::PlaybackScroller::Mode::Off);
}

View File

@ -62,7 +62,7 @@ class ControlToolBar final : public ToolBar {
// Choice among the appearances of the play button:
enum class PlayAppearance {
Straight, Looped, CutPreview, Scrub
Straight, Looped, CutPreview, Scrub, Seek
};
//These allow buttons to be controlled externally:
@ -106,6 +106,11 @@ class ControlToolBar final : public ToolBar {
int WidthForStatusBar(wxStatusBar* const);
void UpdateStatusBar(AudacityProject *pProject);
// Starting and stopping of scrolling display
void StartScrollingIfPreferred();
void StartScrolling();
void StopScrolling();
private:
AButton *MakeButton(teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled,

View File

@ -105,7 +105,7 @@ AButton *EditToolBar::AddButton(
{
AButton *&r = mButtons[id];
r = ToolBar::MakeButton(
r = ToolBar::MakeButton(this,
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall,
eEnabledUp, eEnabledDown, eDisabled,
wxWindowID(id),

View File

@ -700,6 +700,7 @@ void ToolBar::MakeButtonBackgroundsSmall()
}
/// Makes a button and its four different state bitmaps
/// @param parent Parent window for the button.
/// @param eUp Background for when button is Up.
/// @param eDown Background for when button is Down.
/// @param eHilite Background for when button is Hilit.
@ -710,7 +711,8 @@ void ToolBar::MakeButtonBackgroundsSmall()
/// @param placement Placement position
/// @param processdownevents true iff button handles down events.
/// @param size Size of the background.
AButton * ToolBar::MakeButton(teBmps eUp,
AButton * ToolBar::MakeButton(wxWindow *parent,
teBmps eUp,
teBmps eDown,
teBmps eHilite,
teBmps eStandardUp,
@ -731,7 +733,7 @@ AButton * ToolBar::MakeButton(teBmps eUp,
wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
AButton * button =
new AButton(this, id, placement, size, *up2, *hilite2, *down2,
new AButton(parent, id, placement, size, *up2, *hilite2, *down2,
*disable2, processdownevents);
return button;

View File

@ -121,9 +121,11 @@ class ToolBar /* not final */ : public wxPanel
virtual int GetInitialWidth() { return -1; }
virtual int GetMinToolbarWidth() { return GetInitialWidth(); }
virtual wxSize GetDockedSize() { return GetMinSize(); }
protected:
AButton *MakeButton(teBmps eUp,
public:
static
AButton *MakeButton(wxWindow *parent,
teBmps eUp,
teBmps eDown,
teBmps eHilite,
teBmps eStandardUp,
@ -144,6 +146,7 @@ class ToolBar /* not final */ : public wxPanel
teBmps eDisabled,
wxSize size);
protected:
void SetButton(bool down, AButton *button);
void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);

View File

@ -156,7 +156,7 @@ void ToolsToolBar::UpdatePrefs()
AButton * ToolsToolBar::MakeTool( teBmps eTool,
int id, const wxChar *label)
{
AButton *button = ToolBar::MakeButton(
AButton *button = ToolBar::MakeButton(this,
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall,
eTool, eTool, eTool,
wxWindowID(id),

View File

@ -147,7 +147,7 @@ AButton *TranscriptionToolBar::AddButton(
{
AButton *&r = mButtons[id];
r = ToolBar::MakeButton(
r = ToolBar::MakeButton(this,
bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredHiliteSmall,
eFore, eFore, eDisabled,
wxWindowID(id),
@ -476,23 +476,11 @@ void TranscriptionToolBar::OnPlaySpeed(wxCommandEvent & WXUNUSED(event))
{
auto button = mButtons[TTB_PlaySpeed];
auto doubleClicked = button->IsDoubleClicked();
button->ClearDoubleClicked();
if (doubleClicked) {
GetActiveProject()->GetPlaybackScroller().Activate
(AudacityProject::PlaybackScroller::Mode::Centered);
// Pop up the button
SetButton(false, button);
}
else {
// Let control have precedence over shift
const bool cutPreview = mButtons[TTB_PlaySpeed]->WasControlDown();
const bool looped = !cutPreview &&
button->WasShiftDown();
PlayAtSpeed(looped, cutPreview);
}
// Let control have precedence over shift
const bool cutPreview = mButtons[TTB_PlaySpeed]->WasControlDown();
const bool looped = !cutPreview &&
button->WasShiftDown();
PlayAtSpeed(looped, cutPreview);
}
void TranscriptionToolBar::OnSpeedSlider(wxCommandEvent& WXUNUSED(event))

View File

@ -99,7 +99,7 @@ void PlayIndicatorOverlayBase::Draw(OverlayPanel &panel, wxDC &dc)
else if(auto ruler = dynamic_cast<AdornedRulerPanel*>(&panel)) {
wxASSERT(!mIsMaster);
ruler->DoDrawIndicator(&dc, mLastIndicatorX, !rec, IndicatorMediumWidth, false);
ruler->DoDrawIndicator(&dc, mLastIndicatorX, !rec, IndicatorMediumWidth, false, false);
}
else
wxASSERT(false);

View File

@ -19,6 +19,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../TrackPanelCell.h"
#include "../../TrackPanelCellIterator.h"
#include "../../commands/CommandFunctors.h"
#include "../../prefs/PlaybackPrefs.h"
#include "../../toolbars/ControlToolBar.h"
#undef USE_TRANSCRIPTION_TOOLBAR
@ -32,9 +33,6 @@ Paul Licameli split from TrackPanel.cpp
#include <wx/dc.h>
// Conditional compilation switch for making scrub menu items checkable
#define CHECKABLE_SCRUB_MENU_ITEMS
enum {
// PRL:
// Mouse must move at least this far to distinguish ctrl-drag to scrub
@ -219,37 +217,33 @@ namespace {
wxString label;
wxString status;
void (Scrubber::*memFn)(wxCommandEvent&);
bool scroll;
bool seek;
bool (Scrubber::*StatusTest)() const;
const wxString &GetStatus() const { return status; }
} menuItems[] = {
/* i18n-hint: These commands assist the user in finding a sound by ear. ...
"Scrubbing" is variable-speed playback, ...
"Seeking" is normal speed playback but with skips, ...
"Scrolling" keeps the playback position at a fixed place on screen while the waveform moves
*/
{ wxT("Scrub"), XO("&Scrub"), XO("Scrubbing"),
&Scrubber::OnScrub, false, false },
{ wxT("ScrollScrub"), XO("Sc&rolling Scrub"), XO("Scrolling Scrub"),
&Scrubber::OnScrollScrub, true, false },
&Scrubber::OnScrub, false, &Scrubber::Scrubs },
{ wxT("Seek"), XO("See&k"), XO("Seeking"),
&Scrubber::OnSeek, false, true },
&Scrubber::OnSeek, true, &Scrubber::Seeks },
{ wxT("ScrollSeek"), XO("Scro&lling Seek"), XO("Scrolling Seek"),
&Scrubber::OnScrollSeek, true, true }
{ wxT("StartScrubSeek"), XO("Star&t"), XO(""),
&Scrubber::OnStart, true, nullptr },
};
enum { nMenuItems = sizeof(menuItems) / sizeof(*menuItems) };
enum { nMenuItems = sizeof(menuItems) / sizeof(*menuItems), StartMenuItem = 2 };
inline const MenuItem &FindMenuItem(bool scroll, bool seek)
// This never finds the last item:
inline const MenuItem &FindMenuItem(bool seek)
{
return *std::find_if(menuItems, menuItems + nMenuItems,
[=](const MenuItem &item) {
return scroll == item.scroll &&
seek == item.seek;
return seek == item.seek;
}
);
}
@ -258,16 +252,13 @@ namespace {
void Scrubber::MarkScrubStart(
// Assume xx is relative to the left edge of TrackPanel!
wxCoord xx, bool smoothScrolling, bool alwaysSeeking
wxCoord xx, bool smoothScrolling
)
{
UncheckAllMenuItems();
// Don't actually start scrubbing, but collect some information
// needed for the decision to start scrubbing later when handling
// drag events.
mSmoothScrollingScrub = smoothScrolling;
mAlwaysSeeking = alwaysSeeking;
ControlToolBar * const ctb = mProject->GetControlToolBar();
@ -278,14 +269,14 @@ void Scrubber::MarkScrubStart(
// scrubber state
mProject->SetAudioIOToken(0);
ctb->SetPlay(true, ControlToolBar::PlayAppearance::Scrub);
ctb->SetPlay(true, mSeeking
? ControlToolBar::PlayAppearance::Seek
: ControlToolBar::PlayAppearance::Scrub);
ctb->UpdateStatusBar(mProject);
mScrubStartPosition = xx;
mOptions.startClockTimeMillis = ::wxGetLocalTimeMillis();
CheckMenuItem();
}
#ifdef EXPERIMENTAL_SCRUBBING_SUPPORT
@ -358,10 +349,11 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
mOptions.maxSample =
lrint(std::max(0.0, mProject->GetTracks()->GetEndTime()) * options.rate);
mOptions.minStutter =
lrint(std::max(0.0, MinStutter) * options.rate);
mDragging ? 0.0 : lrint(std::max(0.0, MinStutter) * options.rate);
ControlToolBar::PlayAppearance appearance =
ControlToolBar::PlayAppearance::Scrub;
ControlToolBar::PlayAppearance appearance = mSeeking
? ControlToolBar::PlayAppearance::Seek
: ControlToolBar::PlayAppearance::Scrub;
const bool cutPreview = false;
const bool backwards = time1 < time0;
#ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL
@ -382,7 +374,6 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
mOptions.startClockTimeMillis = ::wxGetLocalTimeMillis();
if (IsScrubbing()) {
ActivateScroller();
mPaused = false;
mLastScrubPosition = xx;
@ -475,12 +466,12 @@ void Scrubber::ContinueScrubbingUI()
{
// Show the correct status for seeking.
bool backup = mAlwaysSeeking;
mAlwaysSeeking = seek;
bool backup = mSeeking;
mSeeking = seek;
const auto ctb = mProject->GetControlToolBar();
if (ctb)
ctb->UpdateStatusBar(mProject);
mAlwaysSeeking = backup;
mSeeking = backup;
}
if (seek)
@ -505,11 +496,7 @@ void Scrubber::StopScrubbing()
mPoller->Stop();
UncheckAllMenuItems();
mScrubStartPosition = -1;
mProject->GetPlaybackScroller().Activate
(AudacityProject::PlaybackScroller::Mode::Off);
mDragging = false;
if (!IsScrubbing())
@ -779,31 +766,13 @@ Scrubber &ScrubbingOverlay::GetScrubber()
bool Scrubber::PollIsSeeking()
{
return mDragging || (mAlwaysSeeking || ::wxGetMouseState().LeftIsDown());
return mDragging || (mSeeking || ::wxGetMouseState().LeftIsDown());
}
void Scrubber::ActivateScroller()
{
using Mode = AudacityProject::PlaybackScroller::Mode;
mProject->GetPlaybackScroller().Activate(mSmoothScrollingScrub
? Mode::Centered
:
#ifdef __WXMAC__
// PRL: cause many "unnecessary" refreshes. For reasons I don't understand,
// doing this causes wheel rotation events (mapped from the double finger vertical
// swipe) to be delivered more uniformly to the application, so that spped control
// works better.
Mode::Refresh
#else
Mode::Off
#endif
);
}
void Scrubber::DoScrub(bool scroll, bool seek)
void Scrubber::DoScrub()
{
const bool wasScrubbing = IsScrubbing();
const bool match = (scroll == mSmoothScrollingScrub && seek == mAlwaysSeeking);
const bool scroll = PlaybackPrefs::GetPinnedHeadPreference();
if (!wasScrubbing) {
auto tp = mProject->GetTrackPanel();
wxCoord xx = tp->ScreenToClient(::wxGetMouseState().GetPosition()).x;
@ -814,67 +783,65 @@ void Scrubber::DoScrub(bool scroll, bool seek)
const auto offset = tp->GetLeftOffset();
xx = (std::max(offset, std::min(offset + width - 1, xx)));
MarkScrubStart(xx, scroll, seek);
MarkScrubStart(xx, scroll);
}
else if(!match) {
mSmoothScrollingScrub = scroll;
ActivateScroller();
mAlwaysSeeking = seek;
UncheckAllMenuItems();
CheckMenuItem();
}
void Scrubber::OnScrubOrSeek(bool &toToggle, bool &other)
{
toToggle = !toToggle;
if (toToggle)
other = false;
if (HasStartedScrubbing()) {
// Show the correct status.
const auto ctb = mProject->GetControlToolBar();
ctb->UpdateStatusBar(mProject);
}
else {
// This will call back to Scrubber::StopScrubbing
const auto ctb = mProject->GetControlToolBar();
ctb->StopPlaying();
}
auto ruler = mProject->GetRulerPanel();
if (ruler)
// Update button images
ruler->UpdateButtonStates();
CheckMenuItem();
}
void Scrubber::OnScrub(wxCommandEvent&)
{
DoScrub(false, false);
}
void Scrubber::OnScrollScrub(wxCommandEvent&)
{
DoScrub(true, false);
OnScrubOrSeek(mScrubbing, mSeeking);
}
void Scrubber::OnSeek(wxCommandEvent&)
{
DoScrub(false, true);
OnScrubOrSeek(mSeeking, mScrubbing);
}
void Scrubber::OnScrollSeek(wxCommandEvent&)
void Scrubber::OnStart(wxCommandEvent&)
{
DoScrub(true, true);
DoScrub();
}
enum { CMD_ID = 8000 };
BEGIN_EVENT_TABLE(Scrubber, wxEvtHandler)
EVT_MENU(CMD_ID, Scrubber::OnScrub)
EVT_MENU(CMD_ID + 1, Scrubber::OnScrollScrub)
EVT_MENU(CMD_ID + 2, Scrubber::OnSeek)
EVT_MENU(CMD_ID + 3, Scrubber::OnScrollSeek)
EVT_MENU(CMD_ID + 1, Scrubber::OnSeek)
EVT_MENU(CMD_ID + 2, Scrubber::OnStart)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(Scrubber::Forwarder, wxEvtHandler)
EVT_MOUSE_EVENTS(Scrubber::Forwarder::OnMouse)
END_EVENT_TABLE()
static_assert(nMenuItems == 4, "wrong number of items");
static_assert(nMenuItems == 3, "wrong number of items");
const wxString &Scrubber::GetUntranslatedStateString() const
{
static wxString empty;
if (HasStartedScrubbing()) {
auto &item = FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking);
auto &item = FindMenuItem(mSeeking);
return item.status;
}
else
@ -885,15 +852,19 @@ std::vector<wxString> Scrubber::GetAllUntranslatedStatusStrings()
{
using namespace std;
vector<wxString> results;
transform(menuItems, menuItems + nMenuItems, back_inserter(results),
mem_fun_ref(&MenuItem::GetStatus));
for (const auto &item : menuItems) {
const auto &status = item.GetStatus();
if (!status.empty())
results.push_back(status);
}
return move(results);
}
bool Scrubber::CanScrub() const
{
// Return the enabled state for the menu item that really launches the scrub or seek.
auto cm = mProject->GetCommandManager();
return cm->GetEnabled(menuItems[0].name);
return cm->GetEnabled(menuItems[StartMenuItem].name);
}
void Scrubber::AddMenuItems()
@ -904,15 +875,14 @@ void Scrubber::AddMenuItems()
cm->BeginSubMenu(_("Scru&bbing"));
for (const auto &item : menuItems) {
#ifdef CHECKABLE_SCRUB_MENU_ITEMS
cm->AddCheck(item.name, wxGetTranslation(item.label),
FNT(Scrubber, this, item.memFn),
false, flags, mask);
#else
cm->AddItem(item.name, wxGetTranslation(item.label),
FNT(Scrubber, this, item.memFn),
flags, mask);
#endif
if (!item.GetStatus().empty())
cm->AddCheck(item.name, wxGetTranslation(item.label),
FNT(Scrubber, this, item.memFn),
false, flags, mask);
else
cm->AddItem(item.name, wxGetTranslation(item.label),
FNT(Scrubber, this, item.memFn),
flags, mask);
}
cm->EndSubMenu();
CheckMenuItem();
@ -922,42 +892,22 @@ void Scrubber::PopulateMenu(wxMenu &menu)
{
int id = CMD_ID;
auto cm = mProject->GetCommandManager();
const MenuItem *checkedItem =
HasStartedScrubbing()
? &FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking)
: nullptr;
const MenuItem *checkedItem = &FindMenuItem(mSeeking);
for (const auto &item : menuItems) {
if (cm->GetEnabled(item.name)) {
#ifdef CHECKABLE_SCRUB_MENU_ITEMS
menu.AppendCheckItem(id, item.label);
if(&item == checkedItem)
menu.FindItem(id)->Check();
#else
menu.Append(id, item.label);
#endif
}
++id;
}
}
void Scrubber::UncheckAllMenuItems()
{
#ifdef CHECKABLE_SCRUB_MENU_ITEMS
auto cm = mProject->GetCommandManager();
for (const auto &item : menuItems)
cm->Check(item.name, false);
#endif
}
void Scrubber::CheckMenuItem()
{
#ifdef CHECKABLE_SCRUB_MENU_ITEMS
if(HasStartedScrubbing()) {
auto cm = mProject->GetCommandManager();
auto item = FindMenuItem(mSmoothScrollingScrub, mAlwaysSeeking);
cm->Check(item.name, true);
}
#endif
auto cm = mProject->GetCommandManager();
cm->Check(menuItems[0].name, mScrubbing);
cm->Check(menuItems[1].name, mSeeking);
}
#endif

View File

@ -24,7 +24,11 @@ class AudacityProject;
// Conditionally compile either a separate thead, or else use a timer in the main
// thread, to poll the mouse and update scrubbing speed and direction. The advantage of
// a thread may be immunity to choppy scrubbing in case redrawing takes too much time.
#ifdef __WXGTK__
// Unfortunately some things the thread needs to do are not thread safe
#else
#define USE_SCRUB_THREAD
#endif
// For putting an increment of work in the scrubbing queue
struct ScrubbingOptions {
@ -67,11 +71,7 @@ public:
~Scrubber();
// Assume xx is relative to the left edge of TrackPanel!
void MarkScrubStart(
wxCoord xx, bool smoothScrolling,
bool alwaysSeeking // if false, can switch seeking or scrubbing
// by mouse button state
);
void MarkScrubStart(wxCoord xx, bool smoothScrolling);
// Returns true iff the event should be considered consumed by this:
// Assume xx is relative to the left edge of TrackPanel!
@ -94,9 +94,14 @@ public:
bool IsScrollScrubbing() const // If true, implies HasStartedScrubbing()
{ return mSmoothScrollingScrub; }
void SetScrollScrubbing(bool value)
{ mSmoothScrollingScrub = value; }
bool IsAlwaysSeeking() const
{ return mAlwaysSeeking; }
bool Seeks() const
{ return mSeeking; }
bool Scrubs() const
{ return mScrubbing; }
bool ShouldDrawScrubSpeed();
double FindScrubSpeed(bool seeking, double time) const;
@ -114,12 +119,13 @@ public:
// For popup
void PopulateMenu(wxMenu &menu);
void OnScrubOrSeek(bool &toToggle, bool &other);
void OnScrub(wxCommandEvent&);
void OnScrollScrub(wxCommandEvent&);
void OnSeek(wxCommandEvent&);
void OnScrollSeek(wxCommandEvent&);
void OnStart(wxCommandEvent&);
// A string to put in the leftmost part of the status bar.
// A string to put in the leftmost part of the status bar
// when scrub or seek is in progress, or else empty.
const wxString &GetUntranslatedStateString() const;
// All possible status strings.
@ -129,10 +135,8 @@ public:
bool IsPaused() const;
private:
void ActivateScroller();
void DoScrub(bool scroll, bool seek);
void DoScrub();
void OnActivateOrDeactivateApp(wxActivateEvent & event);
void UncheckAllMenuItems();
void CheckMenuItem();
// I need this because I can't push the scrubber as an event handler
@ -155,7 +159,12 @@ private:
wxCoord mLastScrubPosition {};
bool mScrubSeekPress;
bool mSmoothScrollingScrub;
bool mAlwaysSeeking {};
// These hold the three-way choice among click-to-scrub, click-to-seek, or disabled.
// Not both true.
bool mScrubbing {};
bool mSeeking {};
bool mDragging {};
#ifdef EXPERIMENTAL_SCRUBBING_SCROLL_WHEEL

View File

@ -392,18 +392,6 @@ void AButton::OnMouseEvent(wxMouseEvent & event)
(event.m_x >= 0 && event.m_y >= 0 &&
event.m_x < clientSize.x && event.m_y < clientSize.y);
if (!mButtonIsDown)
{
// Note that CMD (or CTRL) takes precedence over Shift if both are down
// see also AButton::Listener::OnKeyUp()
if (event.CmdDown() && HasAlternateImages(2))
mAlternateIdx = 2;
else if (event.ShiftDown() && HasAlternateImages(1))
mAlternateIdx = 1;
else
mAlternateIdx = 0;
}
if (mEnabled && event.IsButton()) {
if (event.ButtonIsDown(wxMOUSE_BTN_ANY)) {
mIsClicking = true;

File diff suppressed because it is too large Load Diff

View File

@ -298,7 +298,7 @@ public:
#endif
public:
static int GetRulerHeight();
int GetRulerHeight() { return GetRulerHeight(mShowScrubbing); }
static int GetRulerHeight(bool showScrubBar);
wxRect GetInnerRect() const { return mInner; }
@ -315,39 +315,14 @@ public:
void InvalidateRuler();
void UpdatePrefs();
void ReCreateButtons();
enum class StatusChoice {
FirstButton = 0,
QuickPlayButton = FirstButton,
ScrubBarButton,
NumButtons,
LastButton = NumButtons - 1,
NoButton = -1,
EnteringQP = NumButtons,
EnteringQP,
EnteringScrubZone,
Leaving,
NoChange
};
enum class PointerState {
Out = 0, In, InArrow
};
struct CaptureState {
CaptureState() {}
CaptureState(StatusChoice s, PointerState p) : button(s), state(p) {}
StatusChoice button { StatusChoice::NoButton };
PointerState state { PointerState::Out };
};
friend inline StatusChoice &operator++ (StatusChoice &choice) {
choice = static_cast<StatusChoice>(1 + static_cast<int>(choice));
return choice;
}
friend inline StatusChoice &operator-- (StatusChoice &choice) {
choice = static_cast<StatusChoice>(-1 + static_cast<int>(choice));
return choice;
}
void RegenerateTooltips(StatusChoice choice);
@ -361,21 +336,11 @@ private:
void OnSize(wxSizeEvent &evt);
void UpdateRects();
void OnMouseEvents(wxMouseEvent &evt);
void HandleQPDoubleClick(wxMouseEvent &event, wxCoord mousePosX);
void HandleQPClick(wxMouseEvent &event, wxCoord mousePosX);
void HandleQPDrag(wxMouseEvent &event, wxCoord mousePosX);
void HandleQPRelease(wxMouseEvent &event);
void StartQPPlay(bool looped, bool cutPreview);
static inline bool IsButton(StatusChoice choice)
{
auto integer = static_cast<int>(choice);
return integer >= 0 &&
integer < static_cast<int>(StatusChoice::NumButtons);
}
static inline bool IsButton(int choice)
{ return IsButton(static_cast<StatusChoice>(choice)); }
void UpdateStatusBarAndTooltips(StatusChoice choice);
void OnCaptureLost(wxMouseCaptureLostEvent &evt);
@ -384,40 +349,18 @@ private:
void DoDrawEdge(wxDC *dc);
void DoDrawMarks(wxDC * dc, bool /*text */ );
void DoDrawSelection(wxDC * dc);
public:
void DoDrawIndicator(wxDC * dc, wxCoord xx, bool playing, int width, bool scrub);
void DoDrawIndicator(wxDC * dc, wxCoord xx, bool playing, int width, bool scrub, bool seek);
void UpdateButtonStates();
private:
QuickPlayIndicatorOverlay *GetOverlay();
void ShowOrHideQuickPlayIndicator(bool show);
void DoDrawPlayRegion(wxDC * dc);
wxRect GetButtonAreaRect(bool includeBorder = false) const;
struct ButtonStrings {
wxString label, enable, disable;
};
static const ButtonStrings PushbuttonLabels[];
static const ButtonStrings *GetPushButtonStrings(StatusChoice choice)
{
if(IsButton(choice))
return &PushbuttonLabels[static_cast<size_t>(choice)];
return nullptr;
}
wxRect GetButtonRect( StatusChoice button ) const;
PointerState InButtonRect( StatusChoice button, wxMouseEvent *pEvent ) const;
CaptureState FindButton( wxMouseEvent &mouseEvent ) const;
bool GetButtonState( StatusChoice button ) const;
void ToggleButtonState( StatusChoice button );
void ShowButtonMenu( StatusChoice button, const wxPoint *pPosition);
void DoDrawPushbutton
(wxDC *dc, StatusChoice button, bool buttonState, bool arrowState) const;
void DoDrawPushbuttons(wxDC *dc) const;
void HandlePushbuttonClick(wxMouseEvent &evt);
void HandlePushbuttonEvent(wxMouseEvent &evt);
wxFont &GetButtonFont() const;
enum class MenuChoice { QuickPlay, Scrub };
void ShowContextMenu( MenuChoice choice, const wxPoint *pPosition);
double Pos2Time(int p, bool ignoreFisheye = false);
int Time2Pos(double t, bool ignoreFisheye = false);
@ -470,20 +413,18 @@ private:
void OnAutoScroll(wxCommandEvent &evt);
void OnLockPlayRegion(wxCommandEvent &evt);
void OnToggleScrubbing(wxCommandEvent&);
void OnToggleScrubbing(/*wxCommandEvent&*/);
void OnScrub(wxCommandEvent&);
void OnSeek(wxCommandEvent&);
void OnCaptureKey(wxCommandEvent &event);
void OnKeyDown(wxKeyEvent &event);
void OnSetFocus(wxFocusEvent &);
void OnKillFocus(wxFocusEvent &);
void OnContextMenu(wxContextMenuEvent & WXUNUSED(event));
void OnTogglePinnedState(wxCommandEvent & event);
bool mPlayRegionDragsSelection;
bool mTimelineToolTip;
bool mQuickPlayEnabled;
CaptureState mCaptureState {};
enum MouseEventState {
mesNone,
mesDraggingPlayRegionStart,
@ -501,53 +442,14 @@ private:
StatusChoice mPrevZone { StatusChoice::NoChange };
struct TabState {
StatusChoice mButton { StatusChoice::FirstButton };
bool mMenu { false };
TabState() {}
TabState(StatusChoice button, bool menu)
: mButton{ button }, mMenu{ menu } {}
bool operator == (const TabState &rhs) const
{ return mButton == rhs.mButton && mMenu == rhs.mMenu; }
bool operator != (const TabState &rhs) const { return !(*this == rhs); }
TabState &operator ++ () {
if (!mMenu)
mMenu = true;
else {
mMenu = false;
if (!IsButton (++mButton))
mButton = StatusChoice::FirstButton;
}
return *this;
}
TabState &operator -- () {
if (mMenu)
mMenu = false;
else {
mMenu = true;
if (!IsButton (--mButton))
mButton = StatusChoice::LastButton;
}
return *this;
}
};
TabState mTabState;
bool mShowScrubbing { true };
mutable int mButtonFontSize { -1 };
mutable wxFont mButtonFont;
bool mDoubleClick {};
bool mShowingMenu {};
DECLARE_EVENT_TABLE()
friend QuickPlayRulerOverlay;
wxWindow *mButtons[3];
bool mNeedButtonUpdate { true };
};
#endif //define __AUDACITY_RULER__