Audacity  3.2.0
Classes | Namespaces | Functions | Variables
ProjectAudioManager.cpp File Reference
#include "ProjectAudioManager.h"
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/statusbr.h>
#include <algorithm>
#include "AudioIO.h"
#include "BasicUI.h"
#include "CommonCommandFlags.h"
#include "Menus.h"
#include "Meter.h"
#include "Mix.h"
#include "Project.h"
#include "ProjectAudioIO.h"
#include "ProjectFileIO.h"
#include "ProjectHistory.h"
#include "ProjectRate.h"
#include "ProjectSettings.h"
#include "ProjectStatus.h"
#include "ProjectWindows.h"
#include "ScrubState.h"
#include "TrackPanelAx.h"
#include "UndoManager.h"
#include "ViewInfo.h"
#include "WaveTrack.h"
#include "toolbars/ToolManager.h"
#include "prefs/TracksPrefs.h"
#include "tracks/ui/Scrubbing.h"
#include "tracks/ui/TrackView.h"
#include "widgets/MeterPanelBase.h"
#include "widgets/AudacityMessageBox.h"
Include dependency graph for ProjectAudioManager.cpp:

Go to the source code of this file.

Classes

class  anonymous_namespace{ProjectAudioManager.cpp}::CutPreviewPlaybackPolicy
 

Namespaces

 anonymous_namespace{ProjectAudioManager.cpp}
 

Functions

 wxDEFINE_EVENT (EVT_RECORDING_DROPOUT, RecordingDropoutEvent)
 
static TranslatableString FormatRate (int rate)
 
const ReservedCommandFlagCanStopAudioStreamFlag ()
 
AudioIOStartStreamOptions DefaultPlayOptions (AudacityProject &project, bool newDefault)
 
AudioIOStartStreamOptions DefaultSpeedPlayOptions (AudacityProject &project)
 
PropertiesOfSelected GetPropertiesOfSelected (const AudacityProject &proj)
 

Variables

static AudacityProject::AttachedObjects::RegisteredFactory sProjectAudioManagerKey
 
static RegisteredMenuItemEnabler stopIfPaused
 

Function Documentation

◆ CanStopAudioStreamFlag()

const ReservedCommandFlag& CanStopAudioStreamFlag ( )

Definition at line 1135 of file ProjectAudioManager.cpp.

1135  { static ReservedCommandFlag flag{
1136  [](const AudacityProject &project){
1137  auto &projectAudioManager = ProjectAudioManager::Get( project );
1138  bool canStop = projectAudioManager.CanStopAudioStream();
1139  return canStop;
1140  }
1141  }; return flag; }

References flag, and ProjectAudioManager::Get().

Referenced by anonymous_namespace{SelectMenus.cpp}::CursorMenu(), ProjectAudioManager::DoRecord(), anonymous_namespace{TransportMenus.cpp}::ExtraTransportMenu(), and anonymous_namespace{TransportMenus.cpp}::TransportMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultPlayOptions()

AudioIOStartStreamOptions DefaultPlayOptions ( AudacityProject project,
bool  newDefault 
)
Parameters
newDefault"new" default playback policy adjusts to changes of the looping region, "old" default plays once straight

Definition at line 1144 of file ProjectAudioManager.cpp.

1145 {
1146  auto &projectAudioIO = ProjectAudioIO::Get( project );
1147  AudioIOStartStreamOptions options { project.shared_from_this(),
1148  ProjectRate::Get( project ).GetRate() };
1149  options.captureMeter = projectAudioIO.GetCaptureMeter();
1150  options.playbackMeter = projectAudioIO.GetPlaybackMeter();
1151  options.envelope = Mixer::WarpOptions::DefaultWarp::Call(TrackList::Get(project));
1152  options.listener = ProjectAudioManager::Get( project ).shared_from_this();
1153 
1154  bool loopEnabled = ViewInfo::Get(project).playRegion.Active();
1155  options.loopEnabled = loopEnabled;
1156 
1157  if (newDefault) {
1158  const double trackEndTime = TrackList::Get(project).GetEndTime();
1159  const double loopEndTime = ViewInfo::Get(project).playRegion.GetEnd();
1160  options.policyFactory = [&project, trackEndTime, loopEndTime](
1161  const AudioIOStartStreamOptions &options)
1162  -> std::unique_ptr<PlaybackPolicy>
1163  {
1164  return std::make_unique<NewDefaultPlaybackPolicy>( project,
1165  trackEndTime, loopEndTime,
1166  options.loopEnabled, options.variableSpeed);
1167  };
1168 
1169  // Start play from left edge of selection
1170  options.pStartTime.emplace(ViewInfo::Get(project).selectedRegion.t0());
1171  }
1172 
1173  return options;
1174 }

References PlayRegion::Active(), GlobalHook< Tag, Signature, Options >::Call(), ProjectRate::Get(), ViewInfo::Get(), TrackList::Get(), ProjectAudioIO::Get(), ProjectAudioManager::Get(), PlayRegion::GetEnd(), TrackList::GetEndTime(), ProjectRate::GetRate(), and ViewInfo::playRegion.

Referenced by DefaultSpeedPlayOptions(), EffectUIHost::OnPlay(), TransportActions::Handler::OnPlayAfterSelectionEnd(), TransportActions::Handler::OnPlayAfterSelectionStart(), TransportActions::Handler::OnPlayBeforeAndAfterSelectionEnd(), TransportActions::Handler::OnPlayBeforeAndAfterSelectionStart(), TransportActions::Handler::OnPlayBeforeSelectionEnd(), TransportActions::Handler::OnPlayBeforeSelectionStart(), TransportActions::Handler::OnPlayOneSecond(), TransportActions::Handler::OnPlayToSelection(), ProjectAudioManager::OnRecord(), TranscriptionToolBar::PlayAtSpeed(), ProjectAudioManager::PlayCurrentRegion(), Effect::Preview(), MeterPanel::StartMonitoring(), and AdornedRulerPanel::StartQPPlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultSpeedPlayOptions()

AudioIOStartStreamOptions DefaultSpeedPlayOptions ( AudacityProject project)

Definition at line 1177 of file ProjectAudioManager.cpp.

1178 {
1179  auto result = DefaultPlayOptions( project );
1180  auto gAudioIO = AudioIO::Get();
1181  auto PlayAtSpeedRate = gAudioIO->GetBestRate(
1182  false, //not capturing
1183  true, //is playing
1184  ProjectRate::Get( project ).GetRate() //suggested rate
1185  );
1186  result.rate = PlayAtSpeedRate;
1187  return result;
1188 }

References DefaultPlayOptions(), AudioIO::Get(), ProjectRate::Get(), and anonymous_namespace{TimeTrack.cpp}::GetRate().

Here is the call graph for this function:

◆ FormatRate()

static TranslatableString FormatRate ( int  rate)
static

Definition at line 78 of file ProjectAudioManager.cpp.

79 {
80  if (rate > 0) {
81  return XO("Actual Rate: %d").Format( rate );
82  }
83  else
84  // clear the status field
85  return {};
86 }

References XO.

Referenced by ProjectAudioManager::OnAudioIORate(), and ProjectAudioManager::StatusWidthFunction().

Here is the caller graph for this function:

◆ GetPropertiesOfSelected()

PropertiesOfSelected GetPropertiesOfSelected ( const AudacityProject proj)

Definition at line 1308 of file ProjectAudioManager.cpp.

1309 {
1310  double rateOfSelection{ RATE_NOT_SELECTED };
1311 
1312  PropertiesOfSelected result;
1313  result.allSameRate = true;
1314 
1315  const auto selectedTracks{
1316  TrackList::Get(proj).Selected< const WaveTrack >() };
1317 
1318  for (const auto & track : selectedTracks)
1319  {
1320  if (rateOfSelection != RATE_NOT_SELECTED &&
1321  track->GetRate() != rateOfSelection)
1322  result.allSameRate = false;
1323  else if (rateOfSelection == RATE_NOT_SELECTED)
1324  rateOfSelection = track->GetRate();
1325  }
1326 
1327  result.numberOfSelected = selectedTracks.size();
1328  result.rateOfSelected = rateOfSelection;
1329 
1330  return result;
1331 }

References PropertiesOfSelected::allSameRate, TrackList::Get(), PropertiesOfSelected::numberOfSelected, RATE_NOT_SELECTED, PropertiesOfSelected::rateOfSelected, and TrackList::Selected().

Referenced by ProjectAudioManager::OnRecord(), and TransportActions::Handler::OnTimerRecord().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wxDEFINE_EVENT()

wxDEFINE_EVENT ( EVT_RECORDING_DROPOUT  ,
RecordingDropoutEvent   
)

Variable Documentation

◆ sProjectAudioManagerKey

Initial value:
{
[]( AudacityProject &project ) {
return std::make_shared< ProjectAudioManager >( project );
}
}

Definition at line 49 of file ProjectAudioManager.cpp.

Referenced by ProjectAudioManager::Get().

◆ stopIfPaused

RegisteredMenuItemEnabler stopIfPaused
static
Initial value:
{{
[]{ return PausedFlag(); },
[]{ return AudioIONotBusyFlag(); },
[]( const AudacityProject &project ){
return MenuManager::Get( project ).mStopIfWasPaused; },
[]( AudacityProject &project, CommandFlag ){
}
}}

Definition at line 1294 of file ProjectAudioManager.cpp.

PropertiesOfSelected::allSameRate
bool allSameRate
Definition: ProjectAudioManager.h:200
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
PropertiesOfSelected::numberOfSelected
int numberOfSelected
Definition: ProjectAudioManager.h:202
PlayRegion::GetEnd
double GetEnd() const
Definition: ViewInfo.h:133
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
ProjectAudioManager::Get
static ProjectAudioManager & Get(AudacityProject &project)
Definition: ProjectAudioManager.cpp:55
flag
static std::once_flag flag
Definition: WaveformView.cpp:1133
ViewInfo::playRegion
PlayRegion playRegion
Definition: ViewInfo.h:216
ProjectRate::Get
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
AudioIONotBusyFlag
const ReservedCommandFlag & AudioIONotBusyFlag()
Definition: CommonCommandFlags.cpp:128
ReservedCommandFlag
Definition: CommandFlag.h:89
DefaultPlayOptions
AudioIOStartStreamOptions DefaultPlayOptions(AudacityProject &project, bool newDefault)
Definition: ProjectAudioManager.cpp:1144
XO
#define XO(s)
Definition: Internat.h:31
CommandFlag
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:31
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:24
TrackList::GetEndTime
double GetEndTime() const
Definition: Track.cpp:897
PropertiesOfSelected
Definition: ProjectAudioManager.h:199
anonymous_namespace{TimeTrack.cpp}::GetRate
double GetRate()
Definition: TimeTrack.cpp:192
AudioIOStartStreamOptions
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:43
PausedFlag
const ReservedCommandFlag & PausedFlag()
Definition: CommonCommandFlags.cpp:306
ProjectRate::GetRate
double GetRate() const
Definition: ProjectRate.cpp:53
RATE_NOT_SELECTED
constexpr int RATE_NOT_SELECTED
Definition: ProjectAudioManager.h:21
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:377
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:70
GlobalHook::Call
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
Definition: GlobalVariable.h:155
ProjectAudioManager::StopIfPaused
void StopIfPaused()
Definition: ProjectAudioManager.cpp:1217
PlayRegion::Active
bool Active() const
Definition: ViewInfo.h:122
AudioIO::Get
static AudioIO * Get()
Definition: AudioIO.cpp:140
TrackList::Selected
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1396
MenuManager::mStopIfWasPaused
bool mStopIfWasPaused
Definition: Menus.h:123
PropertiesOfSelected::rateOfSelected
int rateOfSelected
Definition: ProjectAudioManager.h:201