Audacity  3.0.3
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ProjectAudioManager Class Referencefinal

#include <ProjectAudioManager.h>

Inheritance diagram for ProjectAudioManager:
[legend]
Collaboration diagram for ProjectAudioManager:
[legend]

Public Member Functions

 ProjectAudioManager (AudacityProject &project)
 
 ProjectAudioManager (const ProjectAudioManager &) PROHIBITED
 
ProjectAudioManageroperator= (const ProjectAudioManager &) PROHIBITED
 
 ~ProjectAudioManager () override
 
bool IsTimerRecordCancelled ()
 
void SetTimerRecordCancelled ()
 
void ResetTimerRecordCancelled ()
 
bool Paused () const
 
bool Playing () const
 
bool Recording () const
 
bool Stopping () const
 
bool Appending () const
 
bool Looping () const
 
bool Cutting () const
 
bool CanStopAudioStream () const
 
void OnRecord (bool altAppearance)
 
bool DoRecord (AudacityProject &project, const TransportTracks &transportTracks, double t0, double t1, bool altAppearance, const AudioIOStartStreamOptions &options)
 
int PlayPlayRegion (const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode playMode, bool backwards=false, bool playWhiteSpace=false)
 
void PlayCurrentRegion (bool looped=false, bool cutpreview=false)
 
void OnPause ()
 
void Pause ()
 
void Stop (bool stopStream=true)
 
void StopIfPaused ()
 
bool DoPlayStopSelect (bool click, bool shift)
 
void DoPlayStopSelect ()
 
PlayMode GetLastPlayMode () const
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 
- Public Member Functions inherited from AudioIOListener
 AudioIOListener ()
 
virtual ~AudioIOListener ()
 

Static Public Member Functions

static ProjectAudioManagerGet (AudacityProject &project)
 
static const ProjectAudioManagerGet (const AudacityProject &project)
 
static WaveTrackArray ChooseExistingRecordingTracks (AudacityProject &proj, bool selectedOnly, double targetRate=RATE_NOT_SELECTED)
 
static bool UseDuplex ()
 
static TransportTracks GetAllPlaybackTracks (TrackList &trackList, bool selectedOnly, bool useMidi=false)
 

Private Member Functions

void SetPaused (bool value)
 
void SetAppending (bool value)
 
void SetLooping (bool value)
 
void SetCutting (bool value)
 
void SetStopping (bool value)
 
void SetupCutPreviewTracks (double playStart, double cutStart, double cutEnd, double playEnd)
 
void ClearCutPreviewTracks ()
 
void CancelRecording ()
 
void OnAudioIORate (int rate) override
 
void OnAudioIOStartRecording () override
 
void OnAudioIOStopRecording () override
 
void OnAudioIONewBlocks (const WaveTrackArray *tracks) override
 
void OnCommitRecording () override
 
void OnSoundActivationThreshold () override
 
void OnCheckpointFailure (wxCommandEvent &evt)
 

Static Private Member Functions

static std::pair< TranslatableStrings, unsigned > StatusWidthFunction (const AudacityProject &project, StatusBarField field)
 

Private Attributes

AudacityProjectmProject
 
std::shared_ptr< TrackListmCutPreviewTracks
 
PlayMode mLastPlayMode { PlayMode::normalPlay }
 
bool mTimerRecordCanceled { false }
 
bool mPaused { false }
 
bool mAppending { false }
 
bool mLooping { false }
 
bool mCutting { false }
 
bool mStopping { false }
 
int mDisplayedRate { 0 }
 

Detailed Description

Definition at line 41 of file ProjectAudioManager.h.

Constructor & Destructor Documentation

◆ ProjectAudioManager() [1/2]

ProjectAudioManager::ProjectAudioManager ( AudacityProject project)
explicit

Definition at line 63 of file ProjectAudioManager.cpp.

64  : mProject{ project }
65 {
67  registerStatusWidthFunction{ StatusWidthFunction };
68  project.Bind( EVT_CHECKPOINT_FAILURE,
70 }

◆ ProjectAudioManager() [2/2]

ProjectAudioManager::ProjectAudioManager ( const ProjectAudioManager )

◆ ~ProjectAudioManager()

ProjectAudioManager::~ProjectAudioManager ( )
overridedefault

Member Function Documentation

◆ Appending()

bool ProjectAudioManager::Appending ( ) const
inline

Definition at line 80 of file ProjectAudioManager.h.

80 { return mAppending; }

References mAppending.

◆ CancelRecording()

void ProjectAudioManager::CancelRecording ( )
private

Definition at line 841 of file ProjectAudioManager.cpp.

842 {
843  const auto project = &mProject;
844  TrackList::Get( *project ).ClearPendingTracks();
845 }

References TrackList::ClearPendingTracks(), TrackList::Get(), and mProject.

Referenced by DoRecord().

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

◆ CanStopAudioStream()

bool ProjectAudioManager::CanStopAudioStream ( ) const

Definition at line 985 of file ProjectAudioManager.cpp.

986 {
987  auto gAudioIO = AudioIO::Get();
988  return (!gAudioIO->IsStreamActive() ||
989  gAudioIO->IsMonitoring() ||
990  gAudioIO->GetOwningProject() == &mProject );
991 }

References AudioIO::Get(), and mProject.

Referenced by Playing(), and Recording().

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

◆ ChooseExistingRecordingTracks()

WaveTrackArray ProjectAudioManager::ChooseExistingRecordingTracks ( AudacityProject proj,
bool  selectedOnly,
double  targetRate = RATE_NOT_SELECTED 
)
static

Definition at line 388 of file ProjectAudioManager.cpp.

390 {
391  auto p = &proj;
392  size_t recordingChannels =
393  std::max(0L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2));
394  bool strictRules = (recordingChannels <= 2);
395 
396  // Iterate over all wave tracks, or over selected wave tracks only.
397  // If target rate was specified, ignore all tracks with other rates.
398  //
399  // In the usual cases of one or two recording channels, seek a first-fit
400  // unbroken sub-sequence for which the total number of channels matches the
401  // required number exactly. Never drop inputs or fill only some channels
402  // of a track.
403  //
404  // In case of more than two recording channels, choose tracks only among the
405  // selected. Simply take the earliest wave tracks, until the number of
406  // channels is enough. If there are fewer channels than inputs, but at least
407  // one channel, then some of the input channels will be dropped.
408  //
409  // Resulting tracks may be non-consecutive within the list of all tracks
410  // (there may be non-wave tracks between, or non-selected tracks when
411  // considering selected tracks only.)
412 
413  if (!strictRules && !selectedOnly)
414  return {};
415 
416  auto &trackList = TrackList::Get( *p );
417  std::vector<unsigned> channelCounts;
418  WaveTrackArray candidates;
419  const auto range = trackList.Leaders<WaveTrack>();
420  for ( auto candidate : selectedOnly ? range + &Track::IsSelected : range ) {
421  if (targetRate != RATE_NOT_SELECTED && candidate->GetRate() != targetRate)
422  continue;
423 
424  // count channels in this track
425  const auto channels = TrackList::Channels( candidate );
426  unsigned nChannels = channels.size();
427 
428  if (strictRules && nChannels > recordingChannels) {
429  // The recording would under-fill this track's channels
430  // Can't use any partial accumulated results
431  // either. Keep looking.
432  candidates.clear();
433  channelCounts.clear();
434  continue;
435  }
436  else {
437  // Might use this but may have to discard some of the accumulated
438  while(strictRules &&
439  nChannels + candidates.size() > recordingChannels) {
440  auto nOldChannels = channelCounts[0];
441  wxASSERT(nOldChannels > 0);
442  channelCounts.erase(channelCounts.begin());
443  candidates.erase(candidates.begin(),
444  candidates.begin() + nOldChannels);
445  }
446  channelCounts.push_back(nChannels);
447  for ( auto channel : channels ) {
448  candidates.push_back(channel->SharedPointer<WaveTrack>());
449  if(candidates.size() == recordingChannels)
450  // Done!
451  return candidates;
452  }
453  }
454  }
455 
456  if (!strictRules && !candidates.empty())
457  // good enough
458  return candidates;
459 
460  // If the loop didn't exit early, we could not find enough channels
461  return {};
462 }

References TrackList::Channels(), TrackList::Get(), gPrefs, Track::IsSelected(), and RATE_NOT_SELECTED.

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

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

◆ ClearCutPreviewTracks()

void ProjectAudioManager::ClearCutPreviewTracks ( )
private

Definition at line 834 of file ProjectAudioManager.cpp.

835 {
836  if (mCutPreviewTracks)
837  mCutPreviewTracks->Clear();
838  mCutPreviewTracks.reset();
839 }

References mCutPreviewTracks.

Referenced by SetupCutPreviewTracks(), and Stop().

Here is the caller graph for this function:

◆ Cutting()

bool ProjectAudioManager::Cutting ( ) const
inline

Definition at line 82 of file ProjectAudioManager.h.

82 { return mCutting; }

References mCutting.

◆ DoPlayStopSelect() [1/2]

void ProjectAudioManager::DoPlayStopSelect ( )

Definition at line 1127 of file ProjectAudioManager.cpp.

1128 {
1129  auto gAudioIO = AudioIO::Get();
1130  if (DoPlayStopSelect(false, false))
1131  Stop();
1132  else if (!gAudioIO->IsBusy()) {
1133  //Otherwise, start playing (assuming audio I/O isn't busy)
1134 
1135  // Will automatically set mLastPlayMode
1136  PlayCurrentRegion(false);
1137  }
1138 }

References AudioIO::Get(), PlayCurrentRegion(), and Stop().

Here is the call graph for this function:

◆ DoPlayStopSelect() [2/2]

bool ProjectAudioManager::DoPlayStopSelect ( bool  click,
bool  shift 
)

Definition at line 1071 of file ProjectAudioManager.cpp.

1072 {
1073  auto &project = mProject;
1074  auto &scrubber = Scrubber::Get( project );
1075  auto token = ProjectAudioIO::Get( project ).GetAudioIOToken();
1076  auto &viewInfo = ViewInfo::Get( project );
1077  auto &selection = viewInfo.selectedRegion;
1078  auto gAudioIO = AudioIOBase::Get();
1079 
1080  //If busy, stop playing, make sure everything is unpaused.
1081  if (scrubber.HasMark() ||
1082  gAudioIO->IsStreamActive(token)) {
1083  // change the selection
1084  auto time = gAudioIO->GetStreamTime();
1085  // Test WasSpeedPlaying(), not IsSpeedPlaying()
1086  // as we could be stopped now. Similarly WasKeyboardScrubbing().
1087  if (click && (scrubber.WasSpeedPlaying() || scrubber.WasKeyboardScrubbing()))
1088  {
1089  ;// don't change the selection.
1090  }
1091  else if (shift && click) {
1092  // Change the region selection, as if by shift-click at the play head
1093  auto t0 = selection.t0(), t1 = selection.t1();
1094  if (time < t0)
1095  // Grow selection
1096  t0 = time;
1097  else if (time > t1)
1098  // Grow selection
1099  t1 = time;
1100  else {
1101  // Shrink selection, changing the nearer boundary
1102  if (fabs(t0 - time) < fabs(t1 - time))
1103  t0 = time;
1104  else
1105  t1 = time;
1106  }
1107  selection.setTimes(t0, t1);
1108  }
1109  else if (click){
1110  // avoid a point at negative time.
1111  time = wxMax( time, 0 );
1112  // Set a point selection, as if by a click at the play head
1113  selection.setTimes(time, time);
1114  } else
1115  // How stop and set cursor always worked
1116  // -- change t0, collapsing to point only if t1 was greater
1117  selection.setT0(time, false);
1118 
1119  ProjectHistory::Get( project ).ModifyState(false); // without bWantsAutoSave
1120  return true;
1121  }
1122  return false;
1123 }

References AudioIOBase::Get(), ProjectAudioIO::Get(), ProjectHistory::Get(), Scrubber::Get(), ViewInfo::Get(), ProjectAudioIO::GetAudioIOToken(), ProjectHistory::ModifyState(), and mProject.

Referenced by TransportActions::Handler::OnPlayStopSelect().

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

◆ DoRecord()

bool ProjectAudioManager::DoRecord ( AudacityProject project,
const TransportTracks transportTracks,
double  t0,
double  t1,
bool  altAppearance,
const AudioIOStartStreamOptions options 
)

Definition at line 575 of file ProjectAudioManager.cpp.

580 {
581  auto &projectAudioManager = *this;
582 
583  CommandFlag flags = AlwaysEnabledFlag; // 0 means recalc flags.
584 
585  // NB: The call may have the side effect of changing flags.
586  bool allowed = MenuManager::Get(project).TryToMakeActionAllowed(
587  flags,
589 
590  if (!allowed)
591  return false;
592  // ...end of code from CommandHandler.
593 
594  auto gAudioIO = AudioIO::Get();
595  if (gAudioIO->IsBusy())
596  return false;
597 
598  projectAudioManager.SetAppending( !altAppearance );
599 
600  bool success = false;
601 
602  auto transportTracks = tracks;
603 
604  // Will replace any given capture tracks with temporaries
605  transportTracks.captureTracks.clear();
606 
607  const auto p = &project;
608 
609  bool appendRecord = !tracks.captureTracks.empty();
610 
611  {
612  if (appendRecord) {
613  // Append recording:
614  // Pad selected/all wave tracks to make them all the same length
615  for (const auto &wt : tracks.captureTracks)
616  {
617  auto endTime = wt->GetEndTime();
618 
619  // If the track was chosen for recording and playback both,
620  // remember the original in preroll tracks, before making the
621  // pending replacement.
622  bool prerollTrack = make_iterator_range(transportTracks.playbackTracks).contains(wt);
623  if (prerollTrack)
624  transportTracks.prerollTracks.push_back(wt);
625 
626  // A function that copies all the non-sample data between
627  // wave tracks; in case the track recorded to changes scale
628  // type (for instance), during the recording.
629  auto updater = [](Track &d, const Track &s){
630  auto &dst = static_cast<WaveTrack&>(d);
631  auto &src = static_cast<const WaveTrack&>(s);
632  dst.Reinit(src);
633  };
634 
635  // Get a copy of the track to be appended, to be pushed into
636  // undo history only later.
637  auto pending = std::static_pointer_cast<WaveTrack>(
639  updater, wt.get() ) );
640 
641  // End of current track is before or at recording start time.
642  // Less than or equal, not just less than, to ensure a clip boundary.
643  // when append recording.
644  if (endTime <= t0) {
645 
646  // Pad the recording track with silence, up to the
647  // maximum time.
648  auto newTrack = pending->EmptyCopy();
649  newTrack->InsertSilence(0.0, t0 - endTime);
650  newTrack->Flush();
651  pending->Clear(endTime, t0);
652  pending->Paste(endTime, newTrack.get());
653  }
654  transportTracks.captureTracks.push_back(pending);
655  }
657  }
658 
659  if( transportTracks.captureTracks.empty() )
660  { // recording to NEW track(s).
661  bool recordingNameCustom, useTrackNumber, useDateStamp, useTimeStamp;
662  wxString defaultTrackName, defaultRecordingTrackName;
663 
664  // Count the tracks.
665  auto &trackList = TrackList::Get( *p );
666  auto numTracks = trackList.Leaders< const WaveTrack >().size();
667 
668  auto recordingChannels = std::max(1L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2));
669 
670  gPrefs->Read(wxT("/GUI/TrackNames/RecordingNameCustom"), &recordingNameCustom, false);
671  gPrefs->Read(wxT("/GUI/TrackNames/TrackNumber"), &useTrackNumber, false);
672  gPrefs->Read(wxT("/GUI/TrackNames/DateStamp"), &useDateStamp, false);
673  gPrefs->Read(wxT("/GUI/TrackNames/TimeStamp"), &useTimeStamp, false);
675  gPrefs->Read(wxT("/GUI/TrackNames/RecodingTrackName"), &defaultRecordingTrackName, defaultTrackName);
676 
677  wxString baseTrackName = recordingNameCustom? defaultRecordingTrackName : defaultTrackName;
678 
679  Track *first {};
680  for (int c = 0; c < recordingChannels; c++) {
681  auto newTrack = WaveTrackFactory::Get( *p ).NewWaveTrack();
682  if (!first)
683  first = newTrack.get();
684 
685  // Quantize bounds to the rate of the new track.
686  if (c == 0) {
687  if (t0 < DBL_MAX)
688  t0 = newTrack->LongSamplesToTime(newTrack->TimeToLongSamples(t0));
689  if (t1 < DBL_MAX)
690  t1 = newTrack->LongSamplesToTime(newTrack->TimeToLongSamples(t1));
691  }
692 
693  newTrack->SetOffset(t0);
694  wxString nameSuffix = wxString(wxT(""));
695 
696  if (useTrackNumber) {
697  nameSuffix += wxString::Format(wxT("%d"), 1 + (int) numTracks + c);
698  }
699 
700  if (useDateStamp) {
701  if (!nameSuffix.empty()) {
702  nameSuffix += wxT("_");
703  }
704  nameSuffix += wxDateTime::Now().FormatISODate();
705  }
706 
707  if (useTimeStamp) {
708  if (!nameSuffix.empty()) {
709  nameSuffix += wxT("_");
710  }
711  nameSuffix += wxDateTime::Now().FormatISOTime();
712  }
713 
714  // ISO standard would be nice, but ":" is unsafe for file name.
715  nameSuffix.Replace(wxT(":"), wxT("-"));
716 
717  if (baseTrackName.empty()) {
718  newTrack->SetName(nameSuffix);
719  }
720  else if (nameSuffix.empty()) {
721  newTrack->SetName(baseTrackName);
722  }
723  else {
724  newTrack->SetName(baseTrackName + wxT("_") + nameSuffix);
725  }
726 
727  TrackList::Get( *p ).RegisterPendingNewTrack( newTrack );
728 
729  if ((recordingChannels > 2) &&
731  TrackView::Get( *newTrack ).SetMinimized(true);
732  }
733 
734  transportTracks.captureTracks.push_back(newTrack);
735  }
736  TrackList::Get( *p ).GroupChannels(*first, recordingChannels);
737  // Bug 1548. First of new tracks needs the focus.
738  TrackFocus::Get(*p).Set(first);
739  if (TrackList::Get(*p).back())
740  TrackList::Get(*p).back()->EnsureVisible();
741  }
742 
743  //Automated Input Level Adjustment Initialization
744  #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
745  gAudioIO->AILAInitialize();
746  #endif
747 
748  int token = gAudioIO->StartStream(transportTracks, t0, t1, options);
749 
750  success = (token != 0);
751 
752  if (success) {
754  }
755  else {
756  CancelRecording();
757 
758  // Show error message if stream could not be opened
759  auto msg = XO("Error opening recording device.\nError code: %s")
760  .Format( gAudioIO->LastPaErrorString() );
762  XO("Error"), msg, wxT("Error_opening_sound_device"));
763  }
764  }
765 
766  return success;
767 }

References AlwaysEnabledFlag, AudioIONotBusyFlag(), CancelRecording(), CanStopAudioStreamFlag(), TransportTracks::captureTracks, AudioIO::Get(), TrackFocus::Get(), MenuManager::Get(), ProjectAudioIO::Get(), ProjectSettings::Get(), TrackList::Get(), WaveTrackFactory::Get(), TrackView::Get(), TracksPrefs::GetDefaultAudioTrackNamePreference(), GetProjectFrame(), ProjectSettings::GetTracksFitVerticallyZoomed(), gPrefs, TrackList::GroupChannels(), make_iterator_range(), mProject, WaveTrackFactory::NewWaveTrack(), TrackList::RegisterPendingChangedTrack(), TrackList::RegisterPendingNewTrack(), WaveTrack::Reinit(), ProjectAudioIO::SetAudioIOToken(), TrackView::SetMinimized(), ShowErrorDialog(), MenuManager::TryToMakeActionAllowed(), TrackList::UpdatePendingTracks(), and XO.

Referenced by OnRecord().

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

◆ Get() [1/2]

ProjectAudioManager & ProjectAudioManager::Get ( AudacityProject project)
static

Definition at line 51 of file ProjectAudioManager.cpp.

52 {
53  return project.AttachedObjects::Get< ProjectAudioManager >(
55 }

References sProjectAudioManagerKey.

Referenced by AdornedRulerPanel::ScrubbingHandle::Cancel(), CanStopAudioStreamFlag(), AdornedRulerPanel::ClearPlayRegion(), AdornedRulerPanel::QPHandle::Click(), CloseButtonHandle::CommitChanges(), DefaultPlayOptions(), DefaultSpeedPlayOptions(), MacroCommands::DoAudacityCommand(), EffectUI::DoEffect(), anonymous_namespace{TransportMenus.cpp}::DoMoveToLabel(), anonymous_namespace{TransportMenus.cpp}::DoStartPlaying(), anonymous_namespace{TransportMenus.cpp}::DoStopPlaying(), ControlToolBar::EnableDisableButtons(), Get(), Scrubber::MarkScrubStart(), ProjectManager::New(), ProjectManager::OnCloseWindow(), ControlToolBar::OnFF(), ControlToolBar::OnIdle(), AudacityApp::OnKeyDown(), ControlToolBar::OnKeyEvent(), TransportActions::Handler::OnPause(), ControlToolBar::OnPause(), EffectUIHost::OnPlay(), ControlToolBar::OnPlay(), TransportActions::Handler::OnPlayStopSelect(), ControlToolBar::OnRecord(), ControlToolBar::OnRewind(), TransportActions::Handler::OnStop(), ControlToolBar::OnStop(), MixerBoard::OnTimer(), PlayIndicatorOverlay::OnTimer(), TrackPanel::OnTimer(), TransportActions::Handler::OnTimerRecord(), TranscriptionToolBar::PlayAtSpeed(), anonymous_namespace{TransportMenus.cpp}::PlayCurrentRegionAndWait(), ControlToolBar::PlayDefault(), anonymous_namespace{TransportMenus.cpp}::PlayPlayRegionAndWait(), anonymous_namespace{TransportMenus.cpp}::RecordAndWait(), TimerRecordDialog::RunWaitDialog(), AdornedRulerPanel::StartQPPlay(), ControlToolBar::StateForStatusBar(), and StatusWidthFunction().

Here is the caller graph for this function:

◆ Get() [2/2]

const ProjectAudioManager & ProjectAudioManager::Get ( const AudacityProject project)
static

Definition at line 57 of file ProjectAudioManager.cpp.

59 {
60  return Get( const_cast< AudacityProject & >( project ) );
61 }

References Get().

Here is the call graph for this function:

◆ GetAllPlaybackTracks()

TransportTracks ProjectAudioManager::GetAllPlaybackTracks ( TrackList trackList,
bool  selectedOnly,
bool  useMidi = false 
)
static

Definition at line 1039 of file ProjectAudioManager.cpp.

1041 {
1042  TransportTracks result;
1043  {
1044  auto range = trackList.Any< WaveTrack >()
1045  + (selectedOnly ? &Track::IsSelected : &Track::Any );
1046  for (auto pTrack: range)
1047  result.playbackTracks.push_back(
1048  pTrack->SharedPointer< WaveTrack >() );
1049  }
1050 #ifdef EXPERIMENTAL_MIDI_OUT
1051  if (useMidi) {
1052  auto range = trackList.Any< const NoteTrack >() +
1053  (selectedOnly ? &Track::IsSelected : &Track::Any );
1054  for (auto pTrack: range)
1055  result.midiTracks.push_back(
1056  pTrack->SharedPointer< const NoteTrack >() );
1057  }
1058 #else
1059  WXUNUSED(useMidi);
1060 #endif
1061  return result;
1062 }

References TrackList::Any(), Track::Any(), Track::IsSelected(), and TransportTracks::playbackTracks.

Referenced by OnRecord(), PlayPlayRegion(), and Effect::Preview().

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

◆ GetLastPlayMode()

PlayMode ProjectAudioManager::GetLastPlayMode ( ) const
inline

Definition at line 119 of file ProjectAudioManager.h.

119 { return mLastPlayMode; }

References mLastPlayMode.

Referenced by MixerBoard::OnTimer(), and PlayIndicatorOverlay::OnTimer().

Here is the caller graph for this function:

◆ IsTimerRecordCancelled()

bool ProjectAudioManager::IsTimerRecordCancelled ( )
inline

Definition at line 65 of file ProjectAudioManager.h.

65 { return mTimerRecordCanceled; }

References mTimerRecordCanceled.

Referenced by OnAudioIOStopRecording().

Here is the caller graph for this function:

◆ Looping()

bool ProjectAudioManager::Looping ( ) const
inline

Definition at line 81 of file ProjectAudioManager.h.

81 { return mLooping; }

References mLooping.

◆ OnAudioIONewBlocks()

void ProjectAudioManager::OnAudioIONewBlocks ( const WaveTrackArray tracks)
overrideprivatevirtual

Implements AudioIOListener.

Definition at line 936 of file ProjectAudioManager.cpp.

937 {
938  auto &project = mProject;
939  auto &projectFileIO = ProjectFileIO::Get( project );
940  projectFileIO.AutoSave(true);
941 }

References ProjectFileIO::Get(), and mProject.

Here is the call graph for this function:

◆ OnAudioIORate()

void ProjectAudioManager::OnAudioIORate ( int  rate)
overrideprivatevirtual

Implements AudioIOListener.

Definition at line 847 of file ProjectAudioManager.cpp.

848 {
849  auto &project = mProject;
850 
851  mDisplayedRate = rate;
852 
853  auto display = FormatRate( rate );
854 
855  ProjectStatus::Get( project ).Set( display, rateStatusBarField );
856 }

References FormatRate(), ProjectStatus::Get(), mDisplayedRate, mProject, rateStatusBarField, and ProjectStatus::Set().

Here is the call graph for this function:

◆ OnAudioIOStartRecording()

void ProjectAudioManager::OnAudioIOStartRecording ( )
overrideprivatevirtual

Implements AudioIOListener.

Definition at line 858 of file ProjectAudioManager.cpp.

859 {
860  // Auto-save was done here before, but it is unnecessary, provided there
861  // are sufficient autosaves when pushing or modifying undo states.
862 }

◆ OnAudioIOStopRecording()

void ProjectAudioManager::OnAudioIOStopRecording ( )
overrideprivatevirtual

Implements AudioIOListener.

Definition at line 865 of file ProjectAudioManager.cpp.

866 {
867  auto &project = mProject;
868  auto &projectAudioIO = ProjectAudioIO::Get( project );
869  auto &projectFileIO = ProjectFileIO::Get( project );
870  auto &window = GetProjectFrame( project );
871 
872  // Only push state if we were capturing and not monitoring
873  if (projectAudioIO.GetAudioIOToken() > 0)
874  {
875  auto &history = ProjectHistory::Get( project );
876 
877  if (IsTimerRecordCancelled()) {
878  // discard recording
879  history.RollbackState();
880  // Reset timer record
882  }
883  else {
884  // Add to history
885  // We want this to have No-fail-guarantee if we get here from exception
886  // handling of recording, and that means we rely on the last autosave
887  // successfully committed to the database, not risking a failure
888  history.PushState(XO("Recorded Audio"), XO("Record"),
890 
891  // Now, we may add a label track to give information about
892  // dropouts. We allow failure of this.
893  auto &tracks = TrackList::Get( project );
894  auto gAudioIO = AudioIO::Get();
895  auto &intervals = gAudioIO->LostCaptureIntervals();
896  if (intervals.size()) {
897  // Make a track with labels for recording errors
898  auto uTrack = std::make_shared<LabelTrack>();
899  auto pTrack = uTrack.get();
900  tracks.Add( uTrack );
901  /* i18n-hint: A name given to a track, appearing as its menu button.
902  The translation should be short or else it will not display well.
903  At most, about 11 Latin characters.
904  Dropout is a loss of a short sequence of audio sample data from the
905  recording */
906  pTrack->SetName(_("Dropouts"));
907  long counter = 1;
908  for (auto &interval : intervals)
909  pTrack->AddLabel(
910  SelectedRegion{ interval.first,
911  interval.first + interval.second },
912  wxString::Format(wxT("%ld"), counter++));
913 
914  history.ModifyState( true ); // this might fail and throw
915 
916  // CallAfter so that we avoid any problems of yielding
917  // to the event loop while still inside the timer callback,
918  // entering StopStream() recursively
919  wxTheApp->CallAfter( [&] {
920  ShowWarningDialog(&window, wxT("DropoutDetected"), XO("\
921 Recorded audio was lost at the labeled locations. Possible causes:\n\
922 \n\
923 Other applications are competing with Audacity for processor time\n\
924 \n\
925 You are saving directly to a slow external storage device\n\
926 "
927  ),
928  false,
929  XXO("Turn off dropout detection"));
930  });
931  }
932  }
933  }
934 }

References _, AudioIO::Get(), ProjectAudioIO::Get(), ProjectFileIO::Get(), ProjectHistory::Get(), TrackList::Get(), GetProjectFrame(), IsTimerRecordCancelled(), mProject, NOAUTOSAVE, ResetTimerRecordCancelled(), ShowWarningDialog(), XO, and XXO.

Here is the call graph for this function:

◆ OnCheckpointFailure()

void ProjectAudioManager::OnCheckpointFailure ( wxCommandEvent &  evt)
private

Definition at line 958 of file ProjectAudioManager.cpp.

959 {
960  evt.Skip();
961  Stop();
962 }

References Stop().

Here is the call graph for this function:

◆ OnCommitRecording()

void ProjectAudioManager::OnCommitRecording ( )
overrideprivatevirtual

Implements AudioIOListener.

Definition at line 943 of file ProjectAudioManager.cpp.

944 {
945  const auto project = &mProject;
946  TrackList::Get( *project ).ApplyPendingTracks();
947 }

References TrackList::ApplyPendingTracks(), TrackList::Get(), and mProject.

Here is the call graph for this function:

◆ OnPause()

void ProjectAudioManager::OnPause ( )

Definition at line 769 of file ProjectAudioManager.cpp.

770 {
771  auto &projectAudioManager = *this;
772  bool canStop = projectAudioManager.CanStopAudioStream();
773 
774  if ( !canStop ) {
775  return;
776  }
777 
778  bool paused = !projectAudioManager.Paused();
779  projectAudioManager.SetPaused( paused );
780 
781  auto gAudioIO = AudioIO::Get();
782 
783 #ifdef EXPERIMENTAL_SCRUBBING_SUPPORT
784 
785  auto project = &mProject;
786  auto &scrubber = Scrubber::Get( *project );
787 
788  // Bug 1494 - Pausing a seek or scrub should just STOP as
789  // it is confusing to be in a paused scrub state.
790  bool bStopInstead = paused &&
791  gAudioIO->IsScrubbing() &&
792  !scrubber.IsSpeedPlaying() &&
793  !scrubber.IsKeyboardScrubbing();
794 
795  if (bStopInstead) {
796  Stop();
797  return;
798  }
799 
800  if (gAudioIO->IsScrubbing())
801  scrubber.Pause(paused);
802  else
803 #endif
804  {
805  gAudioIO->SetPaused(paused);
806  }
807 }

References AudioIO::Get(), Scrubber::Get(), mProject, and Stop().

Referenced by AdornedRulerPanel::QPHandle::Click(), TransportActions::Handler::OnPause(), ControlToolBar::OnPause(), and Pause().

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

◆ OnRecord()

void ProjectAudioManager::OnRecord ( bool  altAppearance)
Exception safety guarantee:
Strong – For state of current project's tracks

Definition at line 465 of file ProjectAudioManager.cpp.

466 {
467  bool bPreferNewTrack;
468  gPrefs->Read("/GUI/PreferNewTrackRecord", &bPreferNewTrack, false);
469  const bool appendRecord = (altAppearance == bPreferNewTrack);
470 
471  // Code from CommandHandler start...
473 
474  if (p) {
475  const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
476  double t0 = selectedRegion.t0();
477  double t1 = selectedRegion.t1();
478  // When no time selection, recording duration is 'unlimited'.
479  if (t1 == t0)
480  t1 = DBL_MAX;
481 
482  auto options = DefaultPlayOptions(*p);
483  WaveTrackArray existingTracks;
484 
485  // Checking the selected tracks: counting them and
486  // making sure they all have the same rate
487  const auto selectedTracks{ GetPropertiesOfSelected(*p) };
488  const int rateOfSelected{ selectedTracks.rateOfSelected };
489  const int numberOfSelected{ selectedTracks.numberOfSelected };
490  const bool allSameRate{ selectedTracks.allSameRate };
491 
492  if (!allSameRate) {
493  AudacityMessageBox(XO("The tracks selected "
494  "for recording must all have the same sampling rate"),
495  XO("Mismatched Sampling Rates"),
496  wxICON_ERROR | wxCENTRE);
497 
498  return;
499  }
500 
501  if (appendRecord) {
502  const auto trackRange = TrackList::Get( *p ).Any< const WaveTrack >();
503 
504  // Try to find wave tracks to record into. (If any are selected,
505  // try to choose only from them; else if wave tracks exist, may record into any.)
506  existingTracks = ChooseExistingRecordingTracks(*p, true, rateOfSelected);
507  if (!existingTracks.empty()) {
508  t0 = std::max(t0,
509  (trackRange + &Track::IsSelected).max(&Track::GetEndTime));
510  }
511  else {
512  if (numberOfSelected > 0 && rateOfSelected != options.rate) {
514  "Too few tracks are selected for recording at this sample rate.\n"
515  "(Audacity requires two channels at the same sample rate for\n"
516  "each stereo track)"),
517  XO("Too Few Compatible Tracks Selected"),
518  wxICON_ERROR | wxCENTRE);
519 
520  return;
521  }
522 
523  existingTracks = ChooseExistingRecordingTracks(*p, false, options.rate);
524  t0 = std::max( t0, trackRange.max( &Track::GetEndTime ) );
525  // If suitable tracks still not found, will record into NEW ones,
526  // but the choice of t0 does not depend on that.
527  }
528 
529  // Whether we decided on NEW tracks or not:
530  if (t1 <= selectedRegion.t0() && selectedRegion.t1() > selectedRegion.t0()) {
531  t1 = selectedRegion.t1(); // record within the selection
532  }
533  else {
534  t1 = DBL_MAX; // record for a long, long time
535  }
536  }
537 
538  TransportTracks transportTracks;
539  if (UseDuplex()) {
540  // Remove recording tracks from the list of tracks for duplex ("overdub")
541  // playback.
542  /* TODO: set up stereo tracks if that is how the user has set up
543  * their preferences, and choose sample format based on prefs */
544  transportTracks = GetAllPlaybackTracks(TrackList::Get( *p ), false, true);
545  for (const auto &wt : existingTracks) {
546  auto end = transportTracks.playbackTracks.end();
547  auto it = std::find(transportTracks.playbackTracks.begin(), end, wt);
548  if (it != end)
549  transportTracks.playbackTracks.erase(it);
550  }
551  }
552 
553  transportTracks.captureTracks = existingTracks;
554 
555  if (rateOfSelected != RATE_NOT_SELECTED)
556  options.rate = rateOfSelected;
557 
558  DoRecord(*p, transportTracks, t0, t1, altAppearance, options);
559  }
560 }

References TrackList::Any(), AudacityMessageBox(), TransportTracks::captureTracks, ChooseExistingRecordingTracks(), DefaultPlayOptions(), DoRecord(), TrackList::Get(), ViewInfo::Get(), GetAllPlaybackTracks(), Track::GetEndTime(), GetPropertiesOfSelected(), gPrefs, Track::IsSelected(), mProject, TransportTracks::playbackTracks, RATE_NOT_SELECTED, PropertiesOfSelected::rateOfSelected, ViewInfo::selectedRegion, NotifyingSelectedRegion::t0(), UseDuplex(), and XO.

Referenced by ControlToolBar::OnRecord(), and TimerRecordDialog::RunWaitDialog().

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

◆ OnSoundActivationThreshold()

void ProjectAudioManager::OnSoundActivationThreshold ( )
overrideprivatevirtual

Implements AudioIOListener.

Definition at line 949 of file ProjectAudioManager.cpp.

950 {
951  auto &project = mProject;
952  auto gAudioIO = AudioIO::Get();
953  if ( gAudioIO && &project == gAudioIO->GetOwningProject() ) {
954  wxTheApp->CallAfter( [this]{ Pause(); } );
955  }
956 }

References AudioIO::Get(), mProject, and Pause().

Here is the call graph for this function:

◆ operator=()

ProjectAudioManager& ProjectAudioManager::operator= ( const ProjectAudioManager )

◆ Pause()

void ProjectAudioManager::Pause ( )

Definition at line 374 of file ProjectAudioManager.cpp.

375 {
376  auto &projectAudioManager = *this;
377  bool canStop = projectAudioManager.CanStopAudioStream();
378 
379  if ( !canStop ) {
380  auto gAudioIO = AudioIO::Get();
381  gAudioIO->SetPaused(!gAudioIO->IsPaused());
382  }
383  else {
384  OnPause();
385  }
386 }

References AudioIO::Get(), and OnPause().

Referenced by OnSoundActivationThreshold().

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

◆ Paused()

bool ProjectAudioManager::Paused ( ) const
inline

Definition at line 69 of file ProjectAudioManager.h.

69 { return mPaused; }

References mPaused.

◆ PlayCurrentRegion()

void ProjectAudioManager::PlayCurrentRegion ( bool  looped = false,
bool  cutpreview = false 
)

Definition at line 280 of file ProjectAudioManager.cpp.

282 {
283  auto &projectAudioManager = *this;
284  bool canStop = projectAudioManager.CanStopAudioStream();
285 
286  if ( !canStop )
287  return;
288 
290 
291  {
292 
293  const auto &playRegion = ViewInfo::Get( *p ).playRegion;
294 
295  auto options = DefaultPlayOptions( *p );
296  options.playLooped = looped;
297  if (cutpreview)
298  options.envelope = nullptr;
299  auto mode =
300  cutpreview ? PlayMode::cutPreviewPlay
301  : options.playLooped ? PlayMode::loopedPlay
303  PlayPlayRegion(SelectedRegion(playRegion.GetStart(), playRegion.GetEnd()),
304  options,
305  mode);
306  }
307 }

References cutPreviewPlay, DefaultPlayOptions(), ViewInfo::Get(), loopedPlay, mProject, normalPlay, AudioIOStartStreamOptions::playLooped, PlayPlayRegion(), and ViewInfo::playRegion.

Referenced by DoPlayStopSelect(), and ControlToolBar::PlayDefault().

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

◆ Playing()

bool ProjectAudioManager::Playing ( ) const

Definition at line 964 of file ProjectAudioManager.cpp.

965 {
966  auto gAudioIO = AudioIO::Get();
967  return
968  gAudioIO->IsBusy() &&
969  CanStopAudioStream() &&
970  // ... and not merely monitoring
971  !gAudioIO->IsMonitoring() &&
972  // ... and not punch-and-roll recording
973  gAudioIO->GetNumCaptureChannels() == 0;
974 }

References CanStopAudioStream(), and AudioIO::Get().

Here is the call graph for this function:

◆ PlayPlayRegion()

int ProjectAudioManager::PlayPlayRegion ( const SelectedRegion selectedRegion,
const AudioIOStartStreamOptions options,
PlayMode  mode,
bool  backwards = false,
bool  playWhiteSpace = false 
)
Exception safety guarantee:
Strong – For state of mCutPreviewTracks

Definition at line 100 of file ProjectAudioManager.cpp.

105 {
106  auto &projectAudioManager = *this;
107  bool canStop = projectAudioManager.CanStopAudioStream();
108 
109  if ( !canStop )
110  return -1;
111 
112  bool useMidi = true;
113 
114  // Remove these lines to experiment with scrubbing/seeking of note tracks
115  if (options.pScrubbingOptions)
116  useMidi = false;
117 
118  // Uncomment this for laughs!
119  // backwards = true;
120 
121  double t0 = selectedRegion.t0();
122  double t1 = selectedRegion.t1();
123  // SelectedRegion guarantees t0 <= t1, so we need another boolean argument
124  // to indicate backwards play.
125  const bool looped = options.playLooped;
126 
127  if (backwards)
128  std::swap(t0, t1);
129 
130  projectAudioManager.SetLooping( mode == PlayMode::loopedPlay );
131  projectAudioManager.SetCutting( mode == PlayMode::cutPreviewPlay );
132 
133  bool success = false;
134 
135  auto gAudioIO = AudioIO::Get();
136  if (gAudioIO->IsBusy())
137  return -1;
138 
139  const bool cutpreview = mode == PlayMode::cutPreviewPlay;
140  if (cutpreview && t0==t1)
141  return -1; /* msmeyer: makes no sense */
142 
144 
145  auto &tracks = TrackList::Get( *p );
146 
147  mLastPlayMode = mode;
148 
149  bool hasaudio;
150  if (useMidi)
151  hasaudio = ! tracks.Any<PlayableTrack>().empty();
152  else
153  hasaudio = ! tracks.Any<WaveTrack>().empty();
154 
155  double latestEnd = (playWhiteSpace)? t1 : tracks.GetEndTime();
156 
157  if (!hasaudio)
158  return -1; // No need to continue without audio tracks
159 
160 #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR)
161  double init_seek = 0.0;
162 #endif
163 
164  double loop_offset = 0.0;
165 
166  if (t1 == t0) {
167  if (looped) {
168  const auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
169  // play selection if there is one, otherwise
170  // set start of play region to project start,
171  // and loop the project from current play position.
172 
173  if ((t0 > selectedRegion.t0()) && (t0 < selectedRegion.t1())) {
174  t0 = selectedRegion.t0();
175  t1 = selectedRegion.t1();
176  }
177  else {
178  // loop the entire project
179  // Bug2347, loop playback from cursor position instead of project start
180  loop_offset = t0 - tracks.GetStartTime();
181  t0 = tracks.GetStartTime();
182  t1 = tracks.GetEndTime();
183  }
184  } else {
185  // move t0 to valid range
186  if (t0 < 0) {
187  t0 = tracks.GetStartTime();
188  }
189  else if (t0 > tracks.GetEndTime()) {
190  t0 = tracks.GetEndTime();
191  }
192 #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR)
193  else {
194  init_seek = t0; //AC: init_seek is where playback will 'start'
195  t0 = tracks.GetStartTime();
196  }
197 #endif
198  }
199  t1 = tracks.GetEndTime();
200  }
201  else {
202  // maybe t1 < t0, with backwards scrubbing for instance
203  if (backwards)
204  std::swap(t0, t1);
205 
206  t0 = std::max(0.0, std::min(t0, latestEnd));
207  t1 = std::max(0.0, std::min(t1, latestEnd));
208 
209  if (backwards)
210  std::swap(t0, t1);
211  }
212 
213  int token = -1;
214 
215  if (t1 != t0) {
216  if (cutpreview) {
217  const double tless = std::min(t0, t1);
218  const double tgreater = std::max(t0, t1);
219  double beforeLen, afterLen;
220  gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
221  gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
222  double tcp0 = tless-beforeLen;
223  double diff = tgreater - tless;
224  double tcp1 = (tgreater+afterLen) - diff;
225  SetupCutPreviewTracks(tcp0, tless, tgreater, tcp1);
226  if (backwards)
227  std::swap(tcp0, tcp1);
228  if (mCutPreviewTracks)
229  {
230  AudioIOStartStreamOptions myOptions = options;
231  myOptions.cutPreviewGapStart = t0;
232  myOptions.cutPreviewGapLen = t1 - t0;
233  token = gAudioIO->StartStream(
234  GetAllPlaybackTracks(*mCutPreviewTracks, false, useMidi),
235  tcp0, tcp1, myOptions);
236  }
237  else
238  // Cannot create cut preview tracks, clean up and exit
239  return -1;
240  }
241  else {
242  token = gAudioIO->StartStream(
243  GetAllPlaybackTracks( tracks, false, useMidi ),
244  t0, t1, options);
245  }
246  if (token != 0) {
247  success = true;
249  if (loop_offset != 0.0) {
250  // Bug 2347
251  gAudioIO->SeekStream(loop_offset);
252  }
253 #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR )
254  //AC: If init_seek was set, now's the time to make it happen.
255  gAudioIO->SeekStream(init_seek);
256 #endif
257  }
258  else {
259  // Bug1627 (part of it):
260  // infinite error spew when trying to start scrub:
261  // Problem was that the error dialog yields to events,
262  // causing recursion to this function in the scrub timer
263  // handler! Easy fix, just delay the user alert instead.
264  auto &window = GetProjectFrame( mProject );
265  window.CallAfter( [&]{
266  // Show error message if stream could not be opened
267  ShowErrorDialog(&window, XO("Error"),
268  XO("Error opening sound device.\nTry changing the audio host, playback device and the project sample rate."),
269  wxT("Error_opening_sound_device"));
270  });
271  }
272  }
273 
274  if (!success)
275  return -1;
276 
277  return token;
278 }

References AudioIOStartStreamOptions::cutPreviewGapLen, AudioIOStartStreamOptions::cutPreviewGapStart, cutPreviewPlay, AudioIO::Get(), ProjectAudioIO::Get(), TrackList::Get(), ViewInfo::Get(), GetAllPlaybackTracks(), GetProjectFrame(), gPrefs, loopedPlay, mCutPreviewTracks, min(), mLastPlayMode, mProject, AudioIOStartStreamOptions::playLooped, ViewInfo::selectedRegion, ProjectAudioIO::SetAudioIOToken(), SetupCutPreviewTracks(), ShowErrorDialog(), anonymous_namespace{NoteTrack.cpp}::swap(), SelectedRegion::t0(), SelectedRegion::t1(), and XO.

Referenced by PlayCurrentRegion().

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

◆ Recording()

bool ProjectAudioManager::Recording ( ) const

Definition at line 976 of file ProjectAudioManager.cpp.

977 {
978  auto gAudioIO = AudioIO::Get();
979  return
980  gAudioIO->IsBusy() &&
981  CanStopAudioStream() &&
982  gAudioIO->GetNumCaptureChannels() > 0;
983 }

References CanStopAudioStream(), and AudioIO::Get().

Here is the call graph for this function:

◆ ResetTimerRecordCancelled()

void ProjectAudioManager::ResetTimerRecordCancelled ( )
inline

Definition at line 67 of file ProjectAudioManager.h.

67 { mTimerRecordCanceled = false; }

References mTimerRecordCanceled.

Referenced by OnAudioIOStopRecording().

Here is the caller graph for this function:

◆ SetAppending()

void ProjectAudioManager::SetAppending ( bool  value)
inlineprivate

Definition at line 123 of file ProjectAudioManager.h.

123 { mAppending = value; }

References mAppending.

◆ SetCutting()

void ProjectAudioManager::SetCutting ( bool  value)
inlineprivate

Definition at line 125 of file ProjectAudioManager.h.

125 { mCutting = value; }

References mCutting.

◆ SetLooping()

void ProjectAudioManager::SetLooping ( bool  value)
inlineprivate

Definition at line 124 of file ProjectAudioManager.h.

124 { mLooping = value; }

References mLooping.

◆ SetPaused()

void ProjectAudioManager::SetPaused ( bool  value)
inlineprivate

Definition at line 122 of file ProjectAudioManager.h.

122 { mPaused = value; }

References mPaused.

◆ SetStopping()

void ProjectAudioManager::SetStopping ( bool  value)
inlineprivate

Definition at line 126 of file ProjectAudioManager.h.

126 { mStopping = value; }

References mStopping.

◆ SetTimerRecordCancelled()

void ProjectAudioManager::SetTimerRecordCancelled ( )
inline

Definition at line 66 of file ProjectAudioManager.h.

66 { mTimerRecordCanceled = true; }

References mTimerRecordCanceled.

Referenced by TransportActions::Handler::OnTimerRecord().

Here is the caller graph for this function:

◆ SetupCutPreviewTracks()

void ProjectAudioManager::SetupCutPreviewTracks ( double  playStart,
double  cutStart,
double  cutEnd,
double  playEnd 
)
private
Exception safety guarantee:
Strong – For state of mCutPreviewTracks

Definition at line 810 of file ProjectAudioManager.cpp.

813 {
816  {
817  auto trackRange = TrackList::Get( *p ).Selected< const PlayableTrack >();
818  if( !trackRange.empty() ) {
819  auto cutPreviewTracks = TrackList::Create( nullptr );
820  for (const auto track1 : trackRange) {
821  // Duplicate and change tracks
822  // Clear has a very small chance of throwing
823 
824  auto newTrack = track1->Duplicate();
825  newTrack->Clear(cutStart, cutEnd);
826  cutPreviewTracks->Add( newTrack );
827  }
828  // use No-throw-guarantee:
829  mCutPreviewTracks = cutPreviewTracks;
830  }
831  }
832 }

References ClearCutPreviewTracks(), TrackList::Create(), TrackList::Get(), mCutPreviewTracks, mProject, and TrackList::Selected().

Referenced by PlayPlayRegion().

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

◆ StatusWidthFunction()

auto ProjectAudioManager::StatusWidthFunction ( const AudacityProject project,
StatusBarField  field 
)
staticprivate

Definition at line 84 of file ProjectAudioManager.cpp.

87 {
88  if ( field == rateStatusBarField ) {
89  auto &audioManager = ProjectAudioManager::Get( project );
90  int rate = audioManager.mDisplayedRate;
91  return {
92  { { FormatRate( rate ) } },
93  50
94  };
95  }
96  return {};
97 }

References field, FormatRate(), Get(), and rateStatusBarField.

Here is the call graph for this function:

◆ Stop()

void ProjectAudioManager::Stop ( bool  stopStream = true)

Definition at line 309 of file ProjectAudioManager.cpp.

310 {
311  AudacityProject *project = &mProject;
312  auto &projectAudioManager = *this;
313  bool canStop = projectAudioManager.CanStopAudioStream();
314 
315  if ( !canStop )
316  return;
317 
318  if(project) {
319  // Let scrubbing code do some appearance change
320  auto &scrubber = Scrubber::Get( *project );
321  scrubber.StopScrubbing();
322  }
323 
324  auto gAudioIO = AudioIO::Get();
325 
326  auto cleanup = finally( [&]{
327  projectAudioManager.SetStopping( false );
328  } );
329 
330  if (stopStream && gAudioIO->IsBusy()) {
331  // flag that we are stopping
332  projectAudioManager.SetStopping( true );
333  // Allow UI to update for that
334  while( wxTheApp->ProcessIdle() )
335  ;
336  }
337 
338  if(stopStream)
339  gAudioIO->StopStream();
340 
341  projectAudioManager.SetLooping( false );
342  projectAudioManager.SetCutting( false );
343 
344  #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
345  gAudioIO->AILADisable();
346  #endif
347 
348  projectAudioManager.SetPaused( false );
349  //Make sure you tell gAudioIO to unpause
350  gAudioIO->SetPaused( false );
351 
353 
354  // So that we continue monitoring after playing or recording.
355  // also clean the MeterQueues
356  if( project ) {
357  auto &projectAudioIO = ProjectAudioIO::Get( *project );
358  auto meter = projectAudioIO.GetPlaybackMeter();
359  if( meter ) {
360  meter->Clear();
361  }
362 
363  meter = projectAudioIO.GetCaptureMeter();
364  if( meter ) {
365  meter->Clear();
366  }
367  }
368 
369  const auto toolbar = ToolManager::Get( *project ).GetToolBar(ScrubbingBarID);
370  if (toolbar)
371  toolbar->EnableDisableButtons();
372 }

References ClearCutPreviewTracks(), ToolBar::EnableDisableButtons(), AudioIO::Get(), ProjectAudioIO::Get(), ToolManager::Get(), Scrubber::Get(), ToolManager::GetToolBar(), mProject, and ScrubbingBarID.

Referenced by AdornedRulerPanel::ScrubbingHandle::Cancel(), AdornedRulerPanel::ClearPlayRegion(), MacroCommands::DoAudacityCommand(), EffectUI::DoEffect(), DoPlayStopSelect(), OnCheckpointFailure(), ProjectManager::OnCloseWindow(), AudacityApp::OnKeyDown(), OnPause(), TransportActions::Handler::OnStop(), TimerRecordDialog::RunWaitDialog(), and StopIfPaused().

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

◆ StopIfPaused()

void ProjectAudioManager::StopIfPaused ( )

Definition at line 1065 of file ProjectAudioManager.cpp.

1066 {
1067  if( AudioIOBase::Get()->IsPaused() )
1068  Stop();
1069 }

References AudioIOBase::Get(), and Stop().

Referenced by CloseButtonHandle::CommitChanges(), ControlToolBar::OnFF(), and ControlToolBar::OnRewind().

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

◆ Stopping()

bool ProjectAudioManager::Stopping ( ) const
inline

Definition at line 77 of file ProjectAudioManager.h.

77 { return mStopping; }

References mStopping.

◆ UseDuplex()

bool ProjectAudioManager::UseDuplex ( )
static

Definition at line 562 of file ProjectAudioManager.cpp.

563 {
564  bool duplex;
565  gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex,
566 #ifdef EXPERIMENTAL_DA
567  false
568 #else
569  true
570 #endif
571  );
572  return duplex;
573 }

References gPrefs.

Referenced by OnRecord().

Here is the caller graph for this function:

Member Data Documentation

◆ mAppending

bool ProjectAudioManager::mAppending { false }
private

Definition at line 155 of file ProjectAudioManager.h.

Referenced by Appending(), and SetAppending().

◆ mCutPreviewTracks

std::shared_ptr<TrackList> ProjectAudioManager::mCutPreviewTracks
private

◆ mCutting

bool ProjectAudioManager::mCutting { false }
private

Definition at line 157 of file ProjectAudioManager.h.

Referenced by Cutting(), and SetCutting().

◆ mDisplayedRate

int ProjectAudioManager::mDisplayedRate { 0 }
private

Definition at line 160 of file ProjectAudioManager.h.

Referenced by OnAudioIORate().

◆ mLastPlayMode

PlayMode ProjectAudioManager::mLastPlayMode { PlayMode::normalPlay }
private

Definition at line 149 of file ProjectAudioManager.h.

Referenced by GetLastPlayMode(), and PlayPlayRegion().

◆ mLooping

bool ProjectAudioManager::mLooping { false }
private

Definition at line 156 of file ProjectAudioManager.h.

Referenced by Looping(), and SetLooping().

◆ mPaused

bool ProjectAudioManager::mPaused { false }
private

Definition at line 154 of file ProjectAudioManager.h.

Referenced by Paused(), and SetPaused().

◆ mProject

AudacityProject& ProjectAudioManager::mProject
private

◆ mStopping

bool ProjectAudioManager::mStopping { false }
private

Definition at line 158 of file ProjectAudioManager.h.

Referenced by SetStopping(), and Stopping().

◆ mTimerRecordCanceled

bool ProjectAudioManager::mTimerRecordCanceled { false }
private

The documentation for this class was generated from the following files:
ProjectAudioManager::mLooping
bool mLooping
Definition: ProjectAudioManager.h:156
WaveTrackArray
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:62
PlayMode::cutPreviewPlay
@ cutPreviewPlay
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:123
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:162
field
#define field(n, t)
Definition: ImportAUP.cpp:165
TransportTracks::playbackTracks
WaveTrackArray playbackTracks
Definition: AudioIO.h:92
ProjectAudioIO::GetAudioIOToken
int GetAudioIOToken() const
Definition: ProjectAudioIO.cpp:42
CanStopAudioStreamFlag
const ReservedCommandFlag & CanStopAudioStreamFlag()
Definition: ProjectAudioManager.cpp:994
WaveTrackFactory::Get
static WaveTrackFactory & Get(AudacityProject &project)
Definition: WaveTrack.cpp:2786
Scrubber::Get
static Scrubber & Get(AudacityProject &project)
Definition: Scrubbing.cpp:198
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:68
make_iterator_range
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:625
ProjectAudioManager::Get
static ProjectAudioManager & Get(AudacityProject &project)
Definition: ProjectAudioManager.cpp:51
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
TrackView::SetMinimized
void SetMinimized(bool minimized)
Definition: TrackView.cpp:77
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:67
Track::GetEndTime
virtual double GetEndTime() const =0
SelectedRegion::t1
double t1() const
Definition: SelectedRegion.h:95
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: AudacityMessageBox.h:20
TransportTracks::captureTracks
WaveTrackArray captureTracks
Definition: AudioIO.h:93
ProjectAudioManager::DoPlayStopSelect
void DoPlayStopSelect()
Definition: ProjectAudioManager.cpp:1127
ProjectAudioManager::PlayCurrentRegion
void PlayCurrentRegion(bool looped=false, bool cutpreview=false)
Definition: ProjectAudioManager.cpp:280
ProjectAudioManager::Pause
void Pause()
Definition: ProjectAudioManager.cpp:374
DefaultPlayOptions
AudioIOStartStreamOptions DefaultPlayOptions(AudacityProject &project)
Definition: ProjectAudioManager.cpp:1003
ViewInfo::playRegion
PlayRegion playRegion
Definition: ViewInfo.h:200
ShowWarningDialog
int ShowWarningDialog(wxWindow *parent, const wxString &internalDialogName, const TranslatableString &message, bool showCancelButton, const TranslatableString &footer)
Definition: Warning.cpp:93
AudioIONotBusyFlag
const ReservedCommandFlag & AudioIONotBusyFlag()
Definition: CommonCommandFlags.cpp:127
sProjectAudioManagerKey
static AudacityProject::AttachedObjects::RegisteredFactory sProjectAudioManagerKey
Definition: ProjectAudioManager.cpp:45
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1467
ProjectAudioManager::ChooseExistingRecordingTracks
static WaveTrackArray ChooseExistingRecordingTracks(AudacityProject &proj, bool selectedOnly, double targetRate=RATE_NOT_SELECTED)
Definition: ProjectAudioManager.cpp:388
ProjectAudioManager::mDisplayedRate
int mDisplayedRate
Definition: ProjectAudioManager.h:160
ToolManager::Get
static ToolManager & Get(AudacityProject &project)
Definition: ToolManager.cpp:355
ProjectAudioManager::OnCheckpointFailure
void OnCheckpointFailure(wxCommandEvent &evt)
Definition: ProjectAudioManager.cpp:958
ToolBar::EnableDisableButtons
virtual void EnableDisableButtons()=0
XO
#define XO(s)
Definition: Internat.h:32
ProjectFileIO::Get
static ProjectFileIO & Get(AudacityProject &project)
Definition: ProjectFileIO.cpp:267
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:39
ProjectAudioManager::CancelRecording
void CancelRecording()
Definition: ProjectAudioManager.cpp:841
Track::Any
bool Any() const
Definition: Track.cpp:361
AlwaysEnabledFlag
constexpr CommandFlag AlwaysEnabledFlag
Definition: CommandFlag.h:35
CommandFlag
std::bitset< NCommandFlags > CommandFlag
Definition: CommandFlag.h:31
ProjectAudioIO::Get
static ProjectAudioIO & Get(AudacityProject &project)
Definition: ProjectAudioIO.cpp:23
TracksPrefs::GetDefaultAudioTrackNamePreference
static wxString GetDefaultAudioTrackNamePreference()
Definition: TracksPrefs.cpp:422
AudioIOStartStreamOptions::playLooped
bool playLooped
Definition: AudioIOBase.h:94
ProjectAudioManager::mLastPlayMode
PlayMode mLastPlayMode
Definition: ProjectAudioManager.h:149
WaveTrack::Reinit
void Reinit(const WaveTrack &orig)
Definition: WaveTrack.cpp:163
ProjectAudioManager::ResetTimerRecordCancelled
void ResetTimerRecordCancelled()
Definition: ProjectAudioManager.h:67
PlayMode::normalPlay
@ normalPlay
TrackList::RegisterPendingChangedTrack
std::shared_ptr< Track > RegisterPendingChangedTrack(Updater updater, Track *src)
Definition: Track.cpp:1032
ProjectAudioManager::CanStopAudioStream
bool CanStopAudioStream() const
Definition: ProjectAudioManager.cpp:985
UndoPush::NOAUTOSAVE
@ NOAUTOSAVE
ProjectAudioManager::IsTimerRecordCancelled
bool IsTimerRecordCancelled()
Definition: ProjectAudioManager.h:65
ProjectStatus::Set
void Set(const TranslatableString &msg, StatusBarField field=mainStatusBarField)
Definition: ProjectStatus.cpp:65
ViewInfo::selectedRegion
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:199
XXO
#define XXO(s)
Definition: Internat.h:45
ToolManager::GetToolBar
ToolBar * GetToolBar(int type) const
Definition: ToolManager.cpp:1028
TrackList::ClearPendingTracks
void ClearPendingTracks(ListOfTracks *pAdded=nullptr)
Definition: Track.cpp:1078
GetProjectFrame
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
Definition: Project.cpp:186
ScrubbingBarID
@ ScrubbingBarID
Definition: ToolBar.h:76
ProjectAudioManager::mTimerRecordCanceled
bool mTimerRecordCanceled
Definition: ProjectAudioManager.h:152
rateStatusBarField
@ rateStatusBarField
Definition: ProjectStatus.h:27
ProjectAudioManager::UseDuplex
static bool UseDuplex()
Definition: ProjectAudioManager.cpp:562
Track::IsSelected
bool IsSelected() const
Definition: Track.cpp:364
AudioIOBase::Get
static AudioIOBase * Get()
Definition: AudioIOBase.cpp:94
TrackFocus::Get
Track * Get()
Definition: TrackPanelAx.cpp:755
AudioIOStartStreamOptions
struct holding stream options, including a pointer to the time warp info and AudioIOListener and whet...
Definition: AudioIOBase.h:76
anonymous_namespace{NoteTrack.cpp}::swap
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:733
ProjectAudioManager::mAppending
bool mAppending
Definition: ProjectAudioManager.h:155
TrackList::RegisterPendingNewTrack
void RegisterPendingNewTrack(const std::shared_ptr< Track > &pTrack)
Definition: Track.cpp:1054
ProjectAudioManager::Stop
void Stop(bool stopStream=true)
Definition: ProjectAudioManager.cpp:309
PlayableTrack
AudioTrack subclass that can also be audibly replayed by the program.
Definition: Track.h:837
MenuManager::TryToMakeActionAllowed
bool TryToMakeActionAllowed(CommandFlag &flags, CommandFlag flagsRqd)
Definition: Menus.cpp:711
TransportTracks
Definition: AudioIO.h:91
ProjectAudioManager::mPaused
bool mPaused
Definition: ProjectAudioManager.h:154
ProjectAudioManager::mCutPreviewTracks
std::shared_ptr< TrackList > mCutPreviewTracks
Definition: ProjectAudioManager.h:147
ProjectAudioManager::PlayPlayRegion
int PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode playMode, bool backwards=false, bool playWhiteSpace=false)
Definition: ProjectAudioManager.cpp:100
TrackList::UpdatePendingTracks
void UpdatePendingTracks()
Definition: Track.cpp:1060
ShowErrorDialog
void ShowErrorDialog(wxWindow *parent, const TranslatableString &dlogTitle, const TranslatableString &message, const wxString &helpPage, const bool Close, const wxString &log)
Displays an error dialog with a button that offers help.
Definition: ErrorDialog.cpp:148
ProjectAudioIO::SetAudioIOToken
void SetAudioIOToken(int token)
Definition: ProjectAudioIO.cpp:47
min
int min(int a, int b)
Definition: CompareAudioCommand.cpp:106
RATE_NOT_SELECTED
constexpr int RATE_NOT_SELECTED
Definition: ProjectAudioManager.h:20
SelectedRegion::t0
double t0() const
Definition: SelectedRegion.h:94
TrackList::GroupChannels
void GroupChannels(Track &track, size_t groupSize, bool resetChannels=true)
Define a group of channels starting at the given track.
Definition: Track.cpp:707
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:495
ProjectAudioManager::SetupCutPreviewTracks
void SetupCutPreviewTracks(double playStart, double cutStart, double cutEnd, double playEnd)
Definition: ProjectAudioManager.cpp:810
TrackList::ApplyPendingTracks
bool ApplyPendingTracks()
Definition: Track.cpp:1119
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:238
ProjectAudioManager::mProject
AudacityProject & mProject
Definition: ProjectAudioManager.h:145
AudioIOStartStreamOptions::cutPreviewGapStart
double cutPreviewGapStart
Definition: AudioIOBase.h:95
_
#define _(s)
Definition: Internat.h:76
ProjectAudioManager::ClearCutPreviewTracks
void ClearCutPreviewTracks()
Definition: ProjectAudioManager.cpp:834
ProjectSettings::GetTracksFitVerticallyZoomed
bool GetTracksFitVerticallyZoomed() const
Definition: ProjectSettings.h:69
ProjectAudioManager::mCutting
bool mCutting
Definition: ProjectAudioManager.h:157
ProjectStatus::Get
static ProjectStatus & Get(AudacityProject &project)
Definition: ProjectStatus.cpp:23
ProjectStatus::RegisteredStatusWidthFunction
Definition: ProjectStatus.h:61
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
AudioIOStartStreamOptions::cutPreviewGapLen
double cutPreviewGapLen
Definition: AudioIOBase.h:96
ProjectAudioManager
Definition: ProjectAudioManager.h:45
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
TrackList::Create
static std::shared_ptr< TrackList > Create(AudacityProject *pOwner)
Definition: Track.cpp:512
ProjectAudioManager::GetAllPlaybackTracks
static TransportTracks GetAllPlaybackTracks(TrackList &trackList, bool selectedOnly, bool useMidi=false)
Definition: ProjectAudioManager.cpp:1039
NotifyingSelectedRegion::t0
double t0() const
Definition: ViewInfo.h:45
ProjectAudioManager::DoRecord
bool DoRecord(AudacityProject &project, const TransportTracks &transportTracks, double t0, double t1, bool altAppearance, const AudioIOStartStreamOptions &options)
Definition: ProjectAudioManager.cpp:575
GetPropertiesOfSelected
PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
Definition: ProjectAudioManager.cpp:1156
TrackList::Any
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1354
AudioIO::Get
static AudioIO * Get()
Definition: AudioIO.cpp:505
PlayMode::loopedPlay
@ loopedPlay
TrackList::Selected
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1371
TransportTracks::prerollTracks
WaveTrackConstArray prerollTracks
Definition: AudioIO.h:99
ProjectAudioManager::mStopping
bool mStopping
Definition: ProjectAudioManager.h:158
WaveTrackFactory::NewWaveTrack
std::shared_ptr< WaveTrack > NewWaveTrack(sampleFormat format=(sampleFormat) 0, double rate=0)
Definition: WaveTrack.cpp:85
PropertiesOfSelected::rateOfSelected
int rateOfSelected
Definition: ProjectAudioManager.h:172
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
NoteTrack
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:66
ProjectAudioManager::StatusWidthFunction
static std::pair< TranslatableStrings, unsigned > StatusWidthFunction(const AudacityProject &project, StatusBarField field)
Definition: ProjectAudioManager.cpp:84
FormatRate
static TranslatableString FormatRate(int rate)
Definition: ProjectAudioManager.cpp:74
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:38
ProjectAudioManager::OnPause
void OnPause()
Definition: ProjectAudioManager.cpp:769