1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-21 16:11:11 +01:00

Scrubbing.cpp does not depend on TranscriptionToolBar...

... Freeing the latter from cycles, and also VoiceKey.

As with ToolsToolBar, use low-level ProjectSettings as the chalkboard for
sending a message.
This commit is contained in:
Paul Licameli
2019-06-14 00:14:13 -04:00
parent 1884eb8619
commit 352380d58f
5 changed files with 27 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ Paul Licameli split from AudacityProject.h
#ifndef __AUDACITY_PROJECT_SETTINGS__
#define __AUDACITY_PROJECT_SETTINGS__
#include <atomic>
#include <wx/event.h> // to declare custom event type
#include "ClientData.h" // to inherit
@@ -88,6 +89,12 @@ public:
void SetTool(int tool) { mCurrentTool = tool; }
int GetTool() const { return mCurrentTool; }
// Speed play
double GetPlaySpeed() const {
return mPlaySpeed.load( std::memory_order_relaxed ); }
void SetPlaySpeed( double value ) {
mPlaySpeed.store( value, std::memory_order_relaxed ); }
// Selection Format
void SetSelectionFormat(const NumericFormatSymbol & format);
@@ -121,6 +128,10 @@ private:
double mRate;
// This is atomic because scrubber may read it in a separate thread from
// the main
std::atomic<double> mPlaySpeed{};
sampleFormat mDefaultFormat;
int mSnapTo;

View File

@@ -90,7 +90,7 @@ WaveTrack::WaveTrack(const std::shared_ptr<DirManager> &projDirManager, sampleFo
PlayableTrack(projDirManager)
{
{
const auto settings = ProjectSettings::Get( *GetActiveProject() );
const auto &settings = ProjectSettings::Get( *GetActiveProject() );
if (format == (sampleFormat)0)
{
format = settings.GetDefaultFormat();

View File

@@ -40,6 +40,7 @@
#include "../KeyboardCapture.h"
#include "../Project.h"
#include "../ProjectAudioManager.h"
#include "../ProjectSettings.h"
#include "../Envelope.h"
#include "../ViewInfo.h"
#include "../WaveTrack.h"
@@ -98,7 +99,7 @@ TranscriptionToolBar::TranscriptionToolBar( AudacityProject &project )
: ToolBar( project,
TranscriptionBarID, _("Play-at-Speed"), wxT("Transcription"), true )
{
mPlaySpeed = 1.0 * 100.0;
SetPlaySpeed( 1.0 * 100.0 );
#ifdef EXPERIMENTAL_VOICE_DETECTION
mVk = std::make_unique<VoiceKey>();
#endif
@@ -146,7 +147,7 @@ void TranscriptionToolBar::Create(wxWindow * parent)
//JKC: Set speed this way is better, as we don't
//then stop Audio if it is playing, so we can be playing
//audio and open a second project.
mPlaySpeed = (mPlaySpeedSlider->Get()) * 100;
SetPlaySpeed( (mPlaySpeedSlider->Get()) * 100 );
// Simulate a size event to set initial placement/size
wxSizeEvent event(GetSize(), GetId());
@@ -154,6 +155,12 @@ void TranscriptionToolBar::Create(wxWindow * parent)
GetEventHandler()->ProcessEvent(event);
}
void TranscriptionToolBar::SetPlaySpeed( double value )
{
mPlaySpeed = value;
ProjectSettings::Get( mProject ).SetPlaySpeed( GetPlaySpeed() );
}
/// This is a convenience function that allows for button creation in
/// MakeButtons() with fewer arguments
/// Very similar to code in ControlToolBar...
@@ -551,7 +558,7 @@ void TranscriptionToolBar::OnPlaySpeed(wxCommandEvent & WXUNUSED(event))
void TranscriptionToolBar::OnSpeedSlider(wxCommandEvent& WXUNUSED(event))
{
mPlaySpeed = (mPlaySpeedSlider->Get()) * 100;
SetPlaySpeed( (mPlaySpeedSlider->Get()) * 100 );
RegenerateTooltips();
// If IO is busy, abort immediately

View File

@@ -121,7 +121,7 @@ class TranscriptionToolBar final : public ToolBar {
private:
void InitializeTranscriptionToolBar();
void SetPlaySpeed( double value );
static AButton *AddButton(
TranscriptionToolBar *pBar,
teBmps eFore, teBmps eDisabled,

View File

@@ -21,6 +21,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Project.h"
#include "../../ProjectAudioIO.h"
#include "../../ProjectAudioManager.h"
#include "../../ProjectSettings.h"
#include "../../TrackPanel.h"
#include "../../ViewInfo.h"
#include "../../prefs/PlaybackPrefs.h"
@@ -28,12 +29,8 @@ Paul Licameli split from TrackPanel.cpp
#include "../../toolbars/ControlToolBar.h"
#include "../../toolbars/ScrubbingToolBar.h"
#include "../../toolbars/ToolManager.h"
#include "../../toolbars/TranscriptionToolBar.h"
#undef USE_TRANSCRIPTION_TOOLBAR
#ifdef USE_TRANSCRIPTION_TOOLBAR
#include "../../toolbars/TranscriptionToolBar.h"
#endif
#include <algorithm>
@@ -397,7 +394,7 @@ bool Scrubber::MaybeStartScrubbing(wxCoord xx)
// Take the starting speed limit from the transcription toolbar,
// but it may be varied during the scrub.
mMaxSpeed = mOptions.maxSpeed =
TranscriptionToolBar::Get( *mProject ).GetPlaySpeed();
ProjectSettings::Get( *mProject ).GetPlaySpeed();
}
#else
// That idea seems unpopular... just make it one for move-scrub,
@@ -560,10 +557,8 @@ void Scrubber::ContinueScrubbingPoll()
// default speed of 1.3 set, so that we can hear there is a problem
// when playAtSpeedTB not found.
double speed = 1.3;
const auto playAtSpeedTB = &TranscriptionToolBar::Get( *mProject );
if (playAtSpeedTB) {
speed = playAtSpeedTB->GetPlaySpeed();
}
const auto &settings = ProjectSettings::Get( *mProject );
speed = settings.GetPlaySpeed();
mOptions.minSpeed = speed -0.01;
mOptions.maxSpeed = speed +0.01;
mOptions.adjustStart = false;