Audacity  2.3.1
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ControlToolBar Class Referencefinal

A ToolBar that has the main Transport buttons. More...

#include <ControlToolBar.h>

Inheritance diagram for ControlToolBar:
ToolBar wxPanelWrapper wxTabTraversalWrapper< wxPanel >

Public Types

enum  PlayAppearance {
  PlayAppearance::Straight, PlayAppearance::Looped, PlayAppearance::CutPreview, PlayAppearance::Scrub,
  PlayAppearance::Seek
}
 
- Public Types inherited from ToolBar
using Holder = Destroy_ptr< ToolBar >
 

Public Member Functions

 ControlToolBar ()
 Methods for ControlToolBar. More...
 
virtual ~ControlToolBar ()
 
void Create (wxWindow *parent) override
 
void UpdatePrefs () override
 
void OnKeyEvent (wxKeyEvent &event)
 
void OnRewind (wxCommandEvent &evt)
 
void OnPlay (wxCommandEvent &evt)
 
void OnStop (wxCommandEvent &evt)
 
void OnRecord (wxCommandEvent &evt)
 
bool DoRecord (AudacityProject &project, const TransportTracks &transportTracks, double t0, double t1, bool altAppearance, const AudioIOStartStreamOptions &options)
 
void OnFF (wxCommandEvent &evt)
 
void OnPause (wxCommandEvent &evt)
 
void SetPlay (bool down, PlayAppearance appearance=PlayAppearance::Straight)
 
void SetStop (bool down)
 
void SetRecord (bool down, bool altAppearance=false)
 
bool IsPauseDown () const
 
bool IsRecordDown () const
 
bool CanStopAudioStream ()
 
void PlayCurrentRegion (bool looped=false, bool cutpreview=false)
 
int PlayPlayRegion (const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode playMode, PlayAppearance appearance=PlayAppearance::Straight, bool backwards=false, bool playWhiteSpace=false)
 
void PlayDefault ()
 
void StopPlaying (bool stopStream=true)
 
void Pause ()
 
void Populate () override
 
void Repaint (wxDC *dc) override
 
void EnableDisableButtons () override
 
void ReCreateButtons () override
 
void RegenerateTooltips () override
 
int WidthForStatusBar (wxStatusBar *const)
 
void UpdateStatusBar (AudacityProject *pProject)
 
void StartScrollingIfPreferred ()
 
void StartScrolling ()
 
void StopScrolling ()
 
void CommitRecording ()
 
void CancelRecording ()
 
- Public Member Functions inherited from ToolBar
 ToolBar (int type, const wxString &label, const wxString &section, bool resizable=false)
 
virtual ~ToolBar ()
 
bool AcceptsFocus () const override
 
void SetToDefaultSize ()
 
int GetType ()
 
wxString GetTitle ()
 
wxString GetLabel ()
 
wxString GetSection ()
 
ToolDockGetDock ()
 
void SetLabel (const wxString &label) override
 
virtual void SetDocked (ToolDock *dock, bool pushed)
 
virtual bool Expose (bool show=true)
 
bool IsResizable () const
 
bool IsVisible () const
 
bool IsDocked () const
 
bool IsPositioned ()
 
void SetVisible (bool bVisible)
 
void SetPositioned ()
 
virtual int GetInitialWidth ()
 Resizable toolbars should implement these. More...
 
virtual int GetMinToolbarWidth ()
 
virtual wxSize GetDockedSize ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&...args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Static Public Member Functions

static bool IsTransportingPinned ()
 
static WaveTrackArray ChooseExistingRecordingTracks (AudacityProject &proj, bool selectedOnly)
 
static bool UseDuplex ()
 
- Static Public Member Functions inherited from ToolBar
static AButtonMakeButton (wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
 
static void MakeAlternateImages (AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size)
 
static void SetButtonToolTip (AButton &button, const TranslatedInternalString commands[], size_t nCommands)
 

Private Types

enum  {
  ID_PAUSE_BUTTON = 11000, ID_PLAY_BUTTON, ID_STOP_BUTTON, ID_FF_BUTTON,
  ID_REW_BUTTON, ID_RECORD_BUTTON, BUTTON_COUNT
}
 

Private Member Functions

void ArrangeButtons ()
 
void SetupCutPreviewTracks (double playStart, double cutStart, double cutEnd, double playEnd)
 
void ClearCutPreviewTracks ()
 
wxString StateForStatusBar ()
 

Static Private Member Functions

static AButtonMakeButton (ControlToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, bool processdownevents, const wxChar *label)
 
static void MakeAlternateImages (AButton &button, int idx, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled)
 

Private Attributes

AButtonmRewind
 
AButtonmPlay
 
AButtonmRecord
 
AButtonmPause
 
AButtonmStop
 
AButtonmFF
 
bool mPaused
 
bool mErgonomicTransportButtons
 
wxString mStrLocale
 
wxBoxSizer * mSizer
 
std::shared_ptr< TrackListmCutPreviewTracks
 
wxString mStatePlay
 
wxString mStateStop
 
wxString mStateRecord
 
wxString mStatePause
 

Static Private Attributes

static AudacityProjectmBusyProject = NULL
 

Additional Inherited Members

- Protected Member Functions inherited from ToolBar
void SetButton (bool down, AButton *button)
 
void MakeMacRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
void MakeRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
void MakeButtonBackgroundsLarge ()
 
void MakeButtonBackgroundsSmall ()
 
wxBoxSizer * GetSizer ()
 
void Add (wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
 
void Add (wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void Add (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void AddSpacer (int size=14)
 
void AddStretchSpacer (int prop=1)
 
void Detach (wxWindow *window)
 
void Detach (wxSizer *sizer)
 
void Updated ()
 
int GetResizeGrabberWidth ()
 Returns the width in pixels of the resizer element. More...
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnMouseEvents (wxMouseEvent &event)
 
- Protected Attributes inherited from ToolBar
wxString mLabel
 
wxString mSection
 
int mType
 

Detailed Description

A ToolBar that has the main Transport buttons.

In the GUI, this is referred to as "Transport Toolbar", as it corresponds to commands in the Transport menu. "Control Toolbar" is historic. This class, which is a child of Toolbar, creates the window containing the Transport (rewind/play/stop/record/ff) buttons. The window can be embedded within a normal project window, or within a ToolbarFrame that is managed by a global ToolBarStub called gControlToolBarStub.

All of the controls in this window were custom-written for Audacity - they are not native controls on any platform - however, it is intended that the images could be easily replaced to allow "skinning" or just customization to match the look and feel of each platform.

Definition at line 47 of file ControlToolBar.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
ID_PAUSE_BUTTON 
ID_PLAY_BUTTON 
ID_STOP_BUTTON 
ID_FF_BUTTON 
ID_REW_BUTTON 
ID_RECORD_BUTTON 
BUTTON_COUNT 

Definition at line 159 of file ControlToolBar.h.

Enumerator
Straight 
Looped 
CutPreview 
Scrub 
Seek 

Definition at line 82 of file ControlToolBar.h.

82  {
83  Straight, Looped, CutPreview, Scrub, Seek
84  };

Constructor & Destructor Documentation

ControlToolBar::ControlToolBar ( )

Methods for ControlToolBar.

Definition at line 105 of file ControlToolBar.cpp.

References gPrefs, and XO.

106 : ToolBar(TransportBarID, _("Transport"), wxT("Control"))
107 {
108  mPaused = false;
109 
110  gPrefs->Read(wxT("/GUI/ErgonomicTransportButtons"), &mErgonomicTransportButtons, true);
111  mStrLocale = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
112 
113  mSizer = NULL;
114 
115  /* i18n-hint: These are strings for the status bar, and indicate whether Audacity
116  is playing or recording or stopped, and whether it is paused. */
117  mStatePlay = XO("Playing");
118  mStateStop = XO("Stopped");
119  mStateRecord = XO("Recording");
120  mStatePause = XO("Paused");
121 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxString mStateRecord
#define XO(s)
Definition: Internat.h:33
wxString mStateStop
wxString mStatePause
wxString mStrLocale
wxBoxSizer * mSizer
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
ToolBar(int type, const wxString &label, const wxString &section, bool resizable=false)
Definition: ToolBar.cpp:315
bool mErgonomicTransportButtons
wxString mStatePlay
ControlToolBar::~ControlToolBar ( )
virtual

Definition at line 123 of file ControlToolBar.cpp.

124 {
125 }

Member Function Documentation

void ControlToolBar::ArrangeButtons ( )
private

Definition at line 335 of file ControlToolBar.cpp.

References ToolBar::Add(), ToolBar::Detach(), ToolBar::GetSizer(), mErgonomicTransportButtons, mFF, mPause, mPlay, mRecord, mRewind, mSizer, mStop, and safenew.

Referenced by Populate().

336 {
337  int flags = wxALIGN_CENTER | wxRIGHT;
338 
339  // (Re)allocate the button sizer
340  if( mSizer )
341  {
342  Detach( mSizer );
343  std::unique_ptr < wxSizer > {mSizer}; // DELETE it
344  }
345 
346  Add((mSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
347 
348  // Start with a little extra space
349  mSizer->Add( 5, 55 );
350 
351  // Add the buttons in order based on ergonomic setting
353  {
354  mPause->MoveBeforeInTabOrder( mRecord );
355  mPlay->MoveBeforeInTabOrder( mRecord );
356  mStop->MoveBeforeInTabOrder( mRecord );
357  mRewind->MoveBeforeInTabOrder( mRecord );
358  mFF->MoveBeforeInTabOrder( mRecord );
359 
360  mSizer->Add( mPause, 0, flags, 2 );
361  mSizer->Add( mPlay, 0, flags, 2 );
362  mSizer->Add( mStop, 0, flags, 2 );
363  mSizer->Add( mRewind, 0, flags, 2 );
364  mSizer->Add( mFF, 0, flags, 10 );
365  mSizer->Add( mRecord, 0, flags, 5 );
366  }
367  else
368  {
369  mRewind->MoveBeforeInTabOrder( mFF );
370  mPlay->MoveBeforeInTabOrder( mFF );
371  mRecord->MoveBeforeInTabOrder( mFF );
372  mPause->MoveBeforeInTabOrder( mFF );
373  mStop->MoveBeforeInTabOrder( mFF );
374 
375  mSizer->Add( mRewind, 0, flags, 2 );
376  mSizer->Add( mPlay, 0, flags, 2 );
377  mSizer->Add( mRecord, 0, flags, 2 );
378  mSizer->Add( mPause, 0, flags, 2 );
379  mSizer->Add( mStop, 0, flags, 2 );
380  mSizer->Add( mFF, 0, flags, 5 );
381  }
382 
383  // Layout the sizer
384  mSizer->Layout();
385 
386  // Layout the toolbar
387  Layout();
388 
389  // (Re)Establish the minimum size
390  SetMinSize( GetSizer()->GetMinSize() );
391 }
AButton * mRecord
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:623
AButton * mPause
void Detach(wxWindow *window)
Definition: ToolBar.cpp:697
#define safenew
Definition: Audacity.h:230
wxBoxSizer * mSizer
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:631
AButton * mRewind
bool mErgonomicTransportButtons
void ControlToolBar::CancelRecording ( )

Definition at line 1498 of file ControlToolBar.cpp.

References GetActiveProject().

Referenced by DoRecord().

1499 {
1500  const auto project = GetActiveProject();
1501  project->GetTracks()->ClearPendingTracks();
1502 }
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
bool ControlToolBar::CanStopAudioStream ( )

Definition at line 806 of file ControlToolBar.cpp.

References gAudioIO, GetActiveProject(), AudioIO::GetOwningProject(), AudioIO::IsMonitoring(), and AudioIO::IsStreamActive().

Referenced by DoRecord(), EnableDisableButtons(), OnPause(), OnPlay(), OnStop(), Pause(), PlayCurrentRegion(), PlayPlayRegion(), and StopPlaying().

807 {
808  return (!gAudioIO->IsStreamActive() ||
809  gAudioIO->IsMonitoring() ||
811 }
bool IsStreamActive() const
Returns true if the audio i/o is running at all, but not during cleanup.
Definition: AudioIO.cpp:2749
AudacityProject * GetOwningProject() const
Definition: AudioIO.h:878
bool IsMonitoring() const
Returns true if we're monitoring input (but not recording or playing actual audio) ...
Definition: AudioIO.cpp:2773
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
WaveTrackArray ControlToolBar::ChooseExistingRecordingTracks ( AudacityProject proj,
bool  selectedOnly 
)
static

Definition at line 886 of file ControlToolBar.cpp.

References TrackList::Channels(), AudacityProject::GetTracks(), gPrefs, Track::IsSelected(), and TrackList::Leaders().

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

888 {
889  auto p = &proj;
890  size_t recordingChannels =
891  std::max(0L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2));
892  bool strictRules = (recordingChannels <= 2);
893 
894  // Iterate over all wave tracks, or over selected wave tracks only.
895  //
896  // In the usual cases of one or two recording channels, seek a first-fit
897  // unbroken sub-sequence for which the total number of channels matches the
898  // required number exactly. Never drop inputs or fill only some channels
899  // of a track.
900  //
901  // In case of more than two recording channels, choose tracks only among the
902  // selected. Simply take the earliest wave tracks, until the number of
903  // channels is enough. If there are fewer channels than inputs, but at least
904  // one channel, then some of the input channels will be dropped.
905  //
906  // Resulting tracks may be non-consecutive within the list of all tracks
907  // (there may be non-wave tracks between, or non-selected tracks when
908  // considering selected tracks only.)
909 
910  if (!strictRules && !selectedOnly)
911  return {};
912 
913  auto trackList = p->GetTracks();
914  std::vector<unsigned> channelCounts;
915  WaveTrackArray candidates;
916  const auto range = trackList->Leaders<WaveTrack>();
917  for ( auto candidate : selectedOnly ? range + &Track::IsSelected : range ) {
918  // count channels in this track
919  const auto channels = TrackList::Channels( candidate );
920  unsigned nChannels = channels.size();
921 
922  if (strictRules && nChannels > recordingChannels) {
923  // The recording would under-fill this track's channels
924  // Can't use any partial accumulated results
925  // either. Keep looking.
926  candidates.clear();
927  channelCounts.clear();
928  continue;
929  }
930  else {
931  // Might use this but may have to discard some of the accumulated
932  while(strictRules &&
933  nChannels + candidates.size() > recordingChannels) {
934  auto nOldChannels = channelCounts[0];
935  wxASSERT(nOldChannels > 0);
936  channelCounts.erase(channelCounts.begin());
937  candidates.erase(candidates.begin(),
938  candidates.begin() + nOldChannels);
939  }
940  channelCounts.push_back(nChannels);
941  for ( auto channel : channels ) {
942  candidates.push_back(Track::Pointer<WaveTrack>(channel));
943  if(candidates.size() == recordingChannels)
944  // Done!
945  return candidates;
946  }
947  }
948  }
949 
950  if (!strictRules && !candidates.empty())
951  // good enough
952  return candidates;
953 
954  // If the loop didn't exit early, we could not find enough channels
955  return {};
956 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
auto Leaders() -> TrackIterRange< TrackType >
Definition: Track.h:1280
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:67
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
bool IsSelected() const
Definition: Track.cpp:442
TrackList * GetTracks()
Definition: Project.h:209
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1356
void ControlToolBar::ClearCutPreviewTracks ( )
private

Definition at line 1352 of file ControlToolBar.cpp.

References mCutPreviewTracks.

Referenced by SetupCutPreviewTracks(), and StopPlaying().

1353 {
1354  if (mCutPreviewTracks)
1355  mCutPreviewTracks->Clear();
1356  mCutPreviewTracks.reset();
1357 }
std::shared_ptr< TrackList > mCutPreviewTracks
void ControlToolBar::CommitRecording ( )

Definition at line 1492 of file ControlToolBar.cpp.

References GetActiveProject().

Referenced by AudioIO::StopStream().

1493 {
1494  const auto project = GetActiveProject();
1495  project->GetTracks()->ApplyPendingTracks();
1496 }
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void ControlToolBar::Create ( wxWindow *  parent)
overridevirtual

Reimplemented from ToolBar.

Definition at line 128 of file ControlToolBar.cpp.

References ToolBar::Create().

129 {
130  ToolBar::Create(parent);
131 }
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:445
bool ControlToolBar::DoRecord ( AudacityProject project,
const TransportTracks transportTracks,
double  t0,
double  t1,
bool  altAppearance,
const AudioIOStartStreamOptions options 
)

Definition at line 1050 of file ControlToolBar.cpp.

References _(), AlwaysEnabledFlag, AudioIONotBusyFlag, CancelRecording(), CanStopAudioStream(), CanStopAudioStreamFlag, TransportTracks::captureTracks, gAudioIO, GetActiveProject(), TracksPrefs::GetDefaultAudioTrackNamePreference(), GetMenuManager(), AudioIO::GetNumCaptureChannels(), gPrefs, AudioIO::IsBusy(), AudioIO::LastPaErrorString(), make_iterator_range(), mBusyProject, mRecord, AButton::PopUp(), AButton::PushDown(), WaveTrack::Reinit(), Track::SetOffset(), SetPlay(), SetRecord(), SetStop(), ShowErrorDialog(), StartScrollingIfPreferred(), AudioIO::StartStream(), MenuManager::TryToMakeActionAllowed(), and UpdateStatusBar().

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

1055 {
1056  CommandFlag flags = AlwaysEnabledFlag; // 0 means recalc flags.
1057 
1058  // NB: The call may have the side effect of changing flags.
1059  bool allowed = GetMenuManager(project).TryToMakeActionAllowed(
1060  project,
1061  flags,
1064 
1065  if (!allowed)
1066  return false;
1067  // ...end of code from CommandHandler.
1068 
1069  if (gAudioIO->IsBusy()) {
1071  mRecord->PopUp();
1072  else
1073  mRecord->PushDown();
1074  return false;
1075  }
1076 
1077  SetRecord(true, altAppearance);
1078 
1079  bool success = false;
1080  auto cleanup = finally([&] {
1081  if (!success) {
1082  SetPlay(false);
1083  SetStop(false);
1084  SetRecord(false);
1085  }
1086 
1087  // Success or not:
1089  });
1090 
1091  auto transportTracks = tracks;
1092 
1093  // Will replace any given capture tracks with temporaries
1094  transportTracks.captureTracks.clear();
1095 
1096  const auto p = &project;
1097 
1098  bool appendRecord = !tracks.captureTracks.empty();
1099 
1100  {
1101  if (appendRecord) {
1102  // Append recording:
1103  // Pad selected/all wave tracks to make them all the same length
1104  for (const auto &wt : tracks.captureTracks)
1105  {
1106  auto endTime = wt->GetEndTime();
1107 
1108  // If the track was chosen for recording and playback both,
1109  // remember the original in preroll tracks, before making the
1110  // pending replacement.
1111  bool prerollTrack = make_iterator_range(transportTracks.playbackTracks).contains(wt);
1112  if (prerollTrack)
1113  transportTracks.prerollTracks.push_back(wt);
1114 
1115  // A function that copies all the non-sample data between
1116  // wave tracks; in case the track recorded to changes scale
1117  // type (for instance), during the recording.
1118  auto updater = [](Track &d, const Track &s){
1119  auto &dst = static_cast<WaveTrack&>(d);
1120  auto &src = static_cast<const WaveTrack&>(s);
1121  dst.Reinit(src);
1122  };
1123 
1124  // Get a copy of the track to be appended, to be pushed into
1125  // undo history only later.
1126  auto pending = std::static_pointer_cast<WaveTrack>(
1127  p->GetTracks()->RegisterPendingChangedTrack(
1128  updater, wt.get() ) );
1129 
1130  // End of current track is before or at recording start time.
1131  // Less than or equal, not just less than, to ensure a clip boundary.
1132  // when append recording.
1133  if (endTime <= t0) {
1134 
1135  // Pad the recording track with silence, up to the
1136  // maximum time.
1137  auto newTrack = p->GetTrackFactory()->NewWaveTrack();
1138  newTrack->SetWaveColorIndex( wt->GetWaveColorIndex() );
1139  newTrack->InsertSilence(0.0, t0 - endTime);
1140  newTrack->Flush();
1141  pending->Clear(endTime, t0);
1142  pending->Paste(endTime, newTrack.get());
1143  }
1144  transportTracks.captureTracks.push_back(pending);
1145  }
1146  p->GetTracks()->UpdatePendingTracks();
1147  }
1148 
1149  if( transportTracks.captureTracks.empty() )
1150  { // recording to NEW track(s).
1151  bool recordingNameCustom, useTrackNumber, useDateStamp, useTimeStamp;
1152  wxString defaultTrackName, defaultRecordingTrackName;
1153 
1154  // Count the tracks.
1155  const auto trackList = p->GetTracks();
1156  auto numTracks = trackList->Leaders<const WaveTrack>().size();
1157 
1158  auto recordingChannels = std::max(1L, gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2));
1159 
1160  gPrefs->Read(wxT("/GUI/TrackNames/RecordingNameCustom"), &recordingNameCustom, false);
1161  gPrefs->Read(wxT("/GUI/TrackNames/TrackNumber"), &useTrackNumber, false);
1162  gPrefs->Read(wxT("/GUI/TrackNames/DateStamp"), &useDateStamp, false);
1163  gPrefs->Read(wxT("/GUI/TrackNames/TimeStamp"), &useTimeStamp, false);
1165  gPrefs->Read(wxT("/GUI/TrackNames/RecodingTrackName"), &defaultRecordingTrackName, defaultTrackName);
1166 
1167  wxString baseTrackName = recordingNameCustom? defaultRecordingTrackName : defaultTrackName;
1168 
1169  Track *first {};
1170  for (int c = 0; c < recordingChannels; c++) {
1171  std::shared_ptr<WaveTrack> newTrack{
1172  p->GetTrackFactory()->NewWaveTrack().release()
1173  };
1174  if (!first)
1175  first = newTrack.get();
1176 
1177  // Quantize bounds to the rate of the new track.
1178  if (c == 0) {
1179  if (t0 < DBL_MAX)
1180  t0 = newTrack->LongSamplesToTime(newTrack->TimeToLongSamples(t0));
1181  if (t1 < DBL_MAX)
1182  t1 = newTrack->LongSamplesToTime(newTrack->TimeToLongSamples(t1));
1183  }
1184 
1185  newTrack->SetOffset(t0);
1186  wxString nameSuffix = wxString(wxT(""));
1187 
1188  if (useTrackNumber) {
1189  nameSuffix += wxString::Format(wxT("%d"), 1 + numTracks + c);
1190  }
1191 
1192  if (useDateStamp) {
1193  if (!nameSuffix.IsEmpty()) {
1194  nameSuffix += wxT("_");
1195  }
1196  nameSuffix += wxDateTime::Now().FormatISODate();
1197  }
1198 
1199  if (useTimeStamp) {
1200  if (!nameSuffix.IsEmpty()) {
1201  nameSuffix += wxT("_");
1202  }
1203  nameSuffix += wxDateTime::Now().FormatISOTime();
1204  }
1205 
1206  // ISO standard would be nice, but ":" is unsafe for file name.
1207  nameSuffix.Replace(wxT(":"), wxT("-"));
1208 
1209  if (baseTrackName.IsEmpty()) {
1210  newTrack->SetName(nameSuffix);
1211  }
1212  else if (nameSuffix.IsEmpty()) {
1213  newTrack->SetName(baseTrackName);
1214  }
1215  else {
1216  newTrack->SetName(baseTrackName + wxT("_") + nameSuffix);
1217  }
1218 
1219  if ((recordingChannels > 2) && !(p->GetTracksFitVerticallyZoomed())) {
1220  newTrack->SetMinimized(true);
1221  }
1222 
1223  p->GetTracks()->RegisterPendingNewTrack( newTrack );
1224  transportTracks.captureTracks.push_back(newTrack);
1225  // Bug 1548. New track needs the focus.
1226  p->GetTrackPanel()->SetFocusedTrack( newTrack.get() );
1227  }
1228  p->GetTracks()->GroupChannels(*first, recordingChannels);
1229  }
1230 
1231  //Automated Input Level Adjustment Initialization
1232  #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
1233  gAudioIO->AILAInitialize();
1234  #endif
1235 
1236  int token = gAudioIO->StartStream(transportTracks, t0, t1, options);
1237 
1238  success = (token != 0);
1239 
1240  if (success) {
1241  p->SetAudioIOToken(token);
1242  mBusyProject = p;
1243 
1245  }
1246  else {
1247  CancelRecording();
1248 
1249  // Show error message if stream could not be opened
1250  wxString msg = wxString::Format(_("Error opening recording device.\nError code: %s"), gAudioIO->LastPaErrorString());
1251  ShowErrorDialog(this, _("Error"), msg, wxT("Error_opening_sound_device"));
1252  }
1253  }
1254 
1255  return success;
1256 }
int StartStream(const TransportTracks &tracks, double t0, double t1, const AudioIOStartStreamOptions &options)
Start recording or playing back audio.
Definition: AudioIO.cpp:1717
AButton * mRecord
void SetPlay(bool down, PlayAppearance appearance=PlayAppearance::Straight)
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
void PopUp()
Definition: AButton.cpp:525
WaveTrackConstArray prerollTracks
Definition: AudioIO.h:166
virtual void SetOffset(double o)
Definition: Track.h:391
void Reinit(const WaveTrack &orig)
Definition: WaveTrack.cpp:170
WaveTrackArray playbackTracks
Definition: AudioIO.h:159
static wxString GetDefaultAudioTrackNamePreference()
unsigned GetNumCaptureChannels() const
Definition: AudioIO.h:1028
bool IsBusy() const
Returns true if audio i/o is busy starting, stopping, playing, or recording.
Definition: AudioIO.cpp:2741
void ShowErrorDialog(wxWindow *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close)
Displays an error dialog with a button that offers help.
void UpdateStatusBar(AudacityProject *pProject)
wxString LastPaErrorString()
Definition: AudioIO.cpp:1666
void SetStop(bool down)
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:608
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:191
bool TryToMakeActionAllowed(AudacityProject &project, CommandFlag &flags, CommandFlag flagsRqd, CommandFlag mask)
Definition: Menus.cpp:764
MenuManager & GetMenuManager(AudacityProject &project)
Definition: Menus.cpp:58
void StartScrollingIfPreferred()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static AudacityProject * mBusyProject
CommandFlag
Definition: CommandFlag.h:16
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void PushDown()
Definition: AButton.cpp:517
void SetRecord(bool down, bool altAppearance=false)
WaveTrackArray captureTracks
Definition: AudioIO.h:160
void ControlToolBar::EnableDisableButtons ( )
overridevirtual

Implements ToolBar.

Definition at line 453 of file ControlToolBar.cpp.

References TrackList::Any(), CanStopAudioStream(), gAudioIO, GetActiveProject(), AudacityProject::GetTracks(), AudacityProject::GetTranscriptionToolBar(), AudioIO::IsBusy(), AButton::IsDown(), IsPauseDown(), mFF, mPause, mPlay, mRecord, mRewind, mStop, AButton::SetEnabled(), and TranscriptionToolBar::SetEnabled().

Referenced by ReCreateButtons(), SetPlay(), SetRecord(), and SetStop().

454 {
456 
457  bool paused = mPause->IsDown();
458  bool playing = mPlay->IsDown();
459  bool recording = mRecord->IsDown();
460  bool busy = gAudioIO->IsBusy();
461 
462  // Only interested in audio type tracks
463  bool tracks = p && p->GetTracks()->Any<AudioTrack>(); // PRL: PlayableTrack ?
464 
465  if (p) {
466  TranscriptionToolBar *const playAtSpeedTB = p->GetTranscriptionToolBar();
467  if (playAtSpeedTB)
468  playAtSpeedTB->SetEnabled(CanStopAudioStream() && tracks && !recording);
469  }
470 
471  mPlay->SetEnabled(CanStopAudioStream() && tracks && !recording);
473  CanStopAudioStream() &&
474  !(busy && !recording && !paused) &&
475  !(playing && !paused)
476  );
477  mStop->SetEnabled(CanStopAudioStream() && (playing || recording));
478  mRewind->SetEnabled(IsPauseDown() || (!playing && !recording));
479  mFF->SetEnabled(tracks && (IsPauseDown() || (!playing && !recording)));
480 
481  //auto pProject = GetActiveProject();
483 }
AButton * mRecord
bool IsDown()
Definition: AButton.h:123
AButton * mPause
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1246
bool IsBusy() const
Returns true if audio i/o is busy starting, stopping, playing, or recording.
Definition: AudioIO.cpp:2741
bool IsPauseDown() const
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
A Track that can load/save audio data to/from XML.
Definition: Track.h:754
void SetEnabled(bool state)
Definition: AButton.h:98
TranscriptionToolBar * GetTranscriptionToolBar()
Definition: Project.cpp:4889
void SetEnabled(bool enabled)
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
AButton * mRewind
TrackList * GetTracks()
Definition: Project.h:209
A kind of ToolBar used to help with analysing voice recordings.
bool ControlToolBar::IsPauseDown ( ) const

Definition at line 528 of file ControlToolBar.cpp.

References AButton::IsDown(), and mPause.

Referenced by EnableDisableButtons(), and Scrubber::OnActivateOrDeactivateApp().

529 {
530  return mPause->IsDown();
531 }
bool IsDown()
Definition: AButton.h:123
AButton * mPause
bool ControlToolBar::IsRecordDown ( ) const

Definition at line 533 of file ControlToolBar.cpp.

References AButton::IsDown(), and mRecord.

534 {
535  return mRecord->IsDown();
536 }
AButton * mRecord
bool IsDown()
Definition: AButton.h:123
bool ControlToolBar::IsTransportingPinned ( )
static

Definition at line 1417 of file ControlToolBar.cpp.

References GetActiveProject(), TracksPrefs::GetPinnedHeadPreference(), AudacityProject::GetScrubber(), and Scrubber::ShouldScrubPinned().

Referenced by AdornedRulerPanel::DoDrawIndicator(), and StartScrollingIfPreferred().

1418 {
1420  return false;
1421  const auto &scrubber = ::GetActiveProject()->GetScrubber();
1422  return
1423  !(scrubber.HasMark() &&
1424  !scrubber.WasSpeedPlaying() &&
1426 }
Scrubber & GetScrubber()
Definition: Project.h:786
static bool ShouldScrubPinned()
Definition: Scrubbing.cpp:169
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
static bool GetPinnedHeadPreference()
void ControlToolBar::MakeAlternateImages ( AButton button,
int  idx,
teBmps  eEnabledUp,
teBmps  eEnabledDown,
teBmps  eDisabled 
)
staticprivate

Definition at line 161 of file ControlToolBar.cpp.

References ThemeBase::ImageSize(), ToolBar::MakeAlternateImages(), and theTheme.

Referenced by Populate().

165 {
166  ToolBar::MakeAlternateImages(button, idx,
167  bmpRecoloredUpLarge, bmpRecoloredDownLarge, bmpRecoloredUpHiliteLarge, bmpRecoloredHiliteLarge,
168  eEnabledUp, eEnabledDown, eDisabled,
169  theTheme.ImageSize( bmpRecoloredUpLarge ));
170 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1257
static void MakeAlternateImages(AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size)
Definition: ToolBar.cpp:818
AButton * ControlToolBar::MakeButton ( ControlToolBar pBar,
teBmps  eEnabledUp,
teBmps  eEnabledDown,
teBmps  eDisabled,
int  id,
bool  processdownevents,
const wxChar *  label 
)
staticprivate

Definition at line 135 of file ControlToolBar.cpp.

References ThemeBase::ImageSize(), ToolBar::MakeButton(), AButton::SetFocusRect(), and theTheme.

Referenced by Populate().

140 {
141  AButton *r = ToolBar::MakeButton(pBar,
142  bmpRecoloredUpLarge, bmpRecoloredDownLarge, bmpRecoloredUpHiliteLarge, bmpRecoloredHiliteLarge,
143  eEnabledUp, eEnabledDown, eDisabled,
144  wxWindowID(id),
145  wxDefaultPosition, processdownevents,
146  theTheme.ImageSize( bmpRecoloredUpLarge ));
147  r->SetLabel(label);
148  enum { deflation =
149 #ifdef __WXMAC__
150  6
151 #else
152  12
153 #endif
154  };
155  r->SetFocusRect( r->GetClientRect().Deflate( deflation, deflation ) );
156 
157  return r;
158 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
void SetFocusRect(wxRect &r)
Definition: AButton.cpp:264
wxString label
Definition: Tags.cpp:733
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1257
static AButton * MakeButton(wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
Definition: ToolBar.cpp:785
A wxButton with mouse-over behaviour.
Definition: AButton.h:28
void ControlToolBar::OnFF ( wxCommandEvent &  evt)

Definition at line 1314 of file ControlToolBar.cpp.

References GetActiveProject(), mFF, AButton::PopUp(), AButton::PushDown(), AudacityProject::SkipEnd(), AudacityProject::StopIfPaused(), and AButton::WasShiftDown().

Referenced by SelectActions::Handler::OnSkipEnd().

1315 {
1316  mFF->PushDown();
1317  mFF->PopUp();
1318 
1320 
1321  if (p) {
1322  p->StopIfPaused();
1323  p->SkipEnd(mFF->WasShiftDown());
1324  }
1325 }
void PopUp()
Definition: AButton.cpp:525
bool WasShiftDown()
Definition: AButton.cpp:485
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void StopIfPaused()
Definition: Project.cpp:5742
void PushDown()
Definition: AButton.cpp:517
void SkipEnd(bool shift)
Definition: Project.cpp:4792
void ControlToolBar::OnKeyEvent ( wxKeyEvent &  event)

Definition at line 758 of file ControlToolBar.cpp.

References gAudioIO, GetActiveProject(), AudioIO::IsBusy(), AudioIO::IsStreamActive(), PlayCurrentRegion(), SetPlay(), SetStop(), and StopPlaying().

759 {
760  if (event.ControlDown() || event.AltDown()) {
761  event.Skip();
762  return;
763  }
764 
765  // Does not appear to be needed on Linux. Perhaps on some other platform?
766  // If so, "!CanStopAudioStream()" should probably apply.
767  if (event.GetKeyCode() == WXK_SPACE) {
768  if (gAudioIO->IsStreamActive(GetActiveProject()->GetAudioIOToken())) {
769  SetPlay(false);
770  SetStop(true);
771  StopPlaying();
772  }
773  else if (!gAudioIO->IsBusy()) {
774  //SetPlay(true);// Not needed as done in PlayPlayRegion
775  SetStop(false);
777  }
778  return;
779  }
780  event.Skip();
781 }
void SetPlay(bool down, PlayAppearance appearance=PlayAppearance::Straight)
void PlayCurrentRegion(bool looped=false, bool cutpreview=false)
void StopPlaying(bool stopStream=true)
bool IsStreamActive() const
Returns true if the audio i/o is running at all, but not during cleanup.
Definition: AudioIO.cpp:2749
bool IsBusy() const
Returns true if audio i/o is busy starting, stopping, playing, or recording.
Definition: AudioIO.cpp:2741
void SetStop(bool down)
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void ControlToolBar::OnPause ( wxCommandEvent &  evt)

Definition at line 1259 of file ControlToolBar.cpp.

References CanStopAudioStream(), gAudioIO, GetActiveProject(), AudacityProject::GetScrubber(), AudioIO::IsScrubbing(), Scrubber::IsSpeedPlaying(), mPause, mPaused, OnStop(), Scrubber::Pause(), AButton::PopUp(), AButton::PushDown(), AudioIO::SetPaused(), and UpdateStatusBar().

Referenced by TransportActions::DoPause(), and Pause().

1260 {
1261  if (!CanStopAudioStream()) {
1262  return;
1263  }
1264 
1265 
1266  if(mPaused)
1267  {
1268  mPause->PopUp();
1269  mPaused=false;
1270  }
1271  else
1272  {
1273  mPause->PushDown();
1274  mPaused=true;
1275  }
1276 
1277 #ifdef EXPERIMENTAL_SCRUBBING_SUPPORT
1278 
1279  // Bug 1494 - Pausing a seek or scrub should just STOP as
1280  // it is confusing to be in a paused scrub state.
1281  bool bStopInstead = mPaused &&
1282  gAudioIO->IsScrubbing() &&
1284 
1285  if (bStopInstead) {
1286  wxCommandEvent dummy;
1287  OnStop(dummy);
1288  return;
1289  }
1290 
1291  if (gAudioIO->IsScrubbing())
1293  else
1294 #endif
1295  {
1297  }
1298 
1300 }
void Pause(bool paused)
Definition: Scrubbing.cpp:816
void PopUp()
Definition: AButton.cpp:525
Scrubber & GetScrubber()
Definition: Project.h:786
AButton * mPause
bool IsSpeedPlaying() const
Definition: Scrubbing.h:98
void UpdateStatusBar(AudacityProject *pProject)
void OnStop(wxCommandEvent &evt)
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
bool IsScrubbing() const
Definition: AudioIO.h:843
void PushDown()
Definition: AButton.cpp:517
void SetPaused(bool state)
Pause and un-pause playback and recording.
Definition: AudioIO.cpp:2692
void ControlToolBar::OnPlay ( wxCommandEvent &  evt)

Definition at line 783 of file ControlToolBar.cpp.

References CanStopAudioStream(), GetActiveProject(), PlayDefault(), StopPlaying(), and UpdateStatusBar().

784 {
785  auto p = GetActiveProject();
786 
787  if (!CanStopAudioStream())
788  return;
789 
790  StopPlaying();
791 
792  if (p) p->TP_DisplaySelection();
793 
794  auto cleanup = finally( [&]{ UpdateStatusBar(p); } );
795  PlayDefault();
796 }
void StopPlaying(bool stopStream=true)
void UpdateStatusBar(AudacityProject *pProject)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void ControlToolBar::OnRecord ( wxCommandEvent &  evt)

Definition at line 958 of file ControlToolBar.cpp.

References TrackList::Any(), TransportTracks::captureTracks, ChooseExistingRecordingTracks(), DoRecord(), GetActiveProject(), GetAllPlaybackTracks(), AudacityProject::GetDefaultPlayOptions(), Track::GetEndTime(), AudacityProject::GetSel0(), AudacityProject::GetSel1(), AudacityProject::GetTracks(), gPrefs, Track::IsSelected(), mRecord, TransportTracks::playbackTracks, UseDuplex(), and AButton::WasShiftDown().

Referenced by TransportActions::DoRecord(), and TransportActions::Handler::OnRecord2ndChoice().

960 {
961  // TODO: It would be neater if Menu items and Toolbar buttons used the same code for
962  // enabling/disabling, and all fell into the same action routines.
963  // Here instead we reduplicate some logic (from CommandHandler) because it isn't
964  // normally used for buttons.
965 
966  // Code from CommandHandler start...
968  wxASSERT(p);
969  if (!p)
970  return;
971 
972  bool altAppearance = mRecord->WasShiftDown();
973  if (evt.GetInt() == 1) // used when called by keyboard shortcut. Default (0) ignored.
974  altAppearance = true;
975  if (evt.GetInt() == 2)
976  altAppearance = false;
977 
978  bool bPreferNewTrack;
979  gPrefs->Read("/GUI/PreferNewTrackRecord", &bPreferNewTrack, false);
980  const bool appendRecord = (altAppearance == bPreferNewTrack);
981 
982  if (p) {
983  double t0 = p->GetSel0();
984  double t1 = p->GetSel1();
985  // When no time selection, recording duration is 'unlimited'.
986  if (t1 == t0)
987  t1 = DBL_MAX;
988 
989  WaveTrackArray existingTracks;
990 
991  if (appendRecord) {
992  const auto trackRange = p->GetTracks()->Any< const WaveTrack >();
993 
994  // Try to find wave tracks to record into. (If any are selected,
995  // try to choose only from them; else if wave tracks exist, may record into any.)
996  existingTracks = ChooseExistingRecordingTracks(*p, true);
997  if ( !existingTracks.empty() )
998  t0 = std::max( t0,
999  ( trackRange + &Track::IsSelected ).max( &Track::GetEndTime ) );
1000  else {
1001  existingTracks = ChooseExistingRecordingTracks(*p, false);
1002  t0 = std::max( t0, trackRange.max( &Track::GetEndTime ) );
1003  // If suitable tracks still not found, will record into NEW ones,
1004  // but the choice of t0 does not depend on that.
1005  }
1006 
1007  // Whether we decided on NEW tracks or not:
1008  if (t1 <= p->GetSel0() && p->GetSel1() > p->GetSel0()) {
1009  t1 = p->GetSel1(); // record within the selection
1010  }
1011  else {
1012  t1 = DBL_MAX; // record for a long, long time
1013  }
1014  }
1015 
1016  TransportTracks transportTracks;
1017  if (UseDuplex()) {
1018  // Remove recording tracks from the list of tracks for duplex ("overdub")
1019  // playback.
1020  /* TODO: set up stereo tracks if that is how the user has set up
1021  * their preferences, and choose sample format based on prefs */
1022  transportTracks = GetAllPlaybackTracks(*p->GetTracks(), false, true);
1023  for (const auto &wt : existingTracks) {
1024  auto end = transportTracks.playbackTracks.end();
1025  auto it = std::find(transportTracks.playbackTracks.begin(), end, wt);
1026  if (it != end)
1027  transportTracks.playbackTracks.erase(it);
1028  }
1029  }
1030 
1031  transportTracks.captureTracks = existingTracks;
1033  DoRecord(*p, transportTracks, t0, t1, altAppearance, options);
1034  }
1035 }
AButton * mRecord
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
AudioIOStartStreamOptions GetDefaultPlayOptions()
Definition: Project.cpp:1365
double GetSel0() const
Definition: Project.h:221
bool WasShiftDown()
Definition: AButton.cpp:485
virtual double GetEndTime() const =0
WaveTrackArray playbackTracks
Definition: AudioIO.h:159
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1246
bool DoRecord(AudacityProject &project, const TransportTracks &transportTracks, double t0, double t1, bool altAppearance, const AudioIOStartStreamOptions &options)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
TransportTracks GetAllPlaybackTracks(TrackList &trackList, bool selectedOnly, bool useMidi)
Definition: Track.cpp:1418
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:67
struct holding stream options, including a pointer to the TimeTrack and AudioIOListener and whether t...
Definition: AudioIO.h:124
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
static WaveTrackArray ChooseExistingRecordingTracks(AudacityProject &proj, bool selectedOnly)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
bool IsSelected() const
Definition: Track.cpp:442
static bool UseDuplex()
double GetSel1() const
Definition: Project.h:222
TrackList * GetTracks()
Definition: Project.h:209
WaveTrackArray captureTracks
Definition: AudioIO.h:160
void ControlToolBar::OnRewind ( wxCommandEvent &  evt)

Definition at line 1302 of file ControlToolBar.cpp.

References GetActiveProject(), mRewind, AButton::PopUp(), AButton::PushDown(), AudacityProject::Rewind(), AudacityProject::StopIfPaused(), and AButton::WasShiftDown().

Referenced by SelectActions::Handler::OnSkipStart().

1303 {
1304  mRewind->PushDown();
1305  mRewind->PopUp();
1306 
1308  if (p) {
1309  p->StopIfPaused();
1310  p->Rewind(mRewind->WasShiftDown());
1311  }
1312 }
void PopUp()
Definition: AButton.cpp:525
bool WasShiftDown()
Definition: AButton.cpp:485
void Rewind(bool shift)
Definition: Project.cpp:4774
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void StopIfPaused()
Definition: Project.cpp:5742
AButton * mRewind
void PushDown()
Definition: AButton.cpp:517
void ControlToolBar::OnStop ( wxCommandEvent &  evt)

Definition at line 798 of file ControlToolBar.cpp.

References CanStopAudioStream(), GetActiveProject(), StopPlaying(), and UpdateStatusBar().

Referenced by AdornedRulerPanel::ScrubbingHandle::Cancel(), Scrubber::ContinueScrubbingUI(), TransportActions::DoPlayStopSelect(), TransportActions::DoStop(), AudacityProject::OnCloseWindow(), and OnPause().

799 {
800  if (CanStopAudioStream()) {
801  StopPlaying();
803  }
804 }
void StopPlaying(bool stopStream=true)
void UpdateStatusBar(AudacityProject *pProject)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void ControlToolBar::Pause ( )

Definition at line 876 of file ControlToolBar.cpp.

References CanStopAudioStream(), gAudioIO, AudioIoCallback::IsPaused(), OnPause(), and AudioIO::SetPaused().

Referenced by AudioIoCallback::CheckSoundActivatedRecordingLevel().

877 {
878  if (!CanStopAudioStream())
880  else {
881  wxCommandEvent dummy;
882  OnPause(dummy);
883  }
884 }
void OnPause(wxCommandEvent &evt)
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
bool IsPaused() const
Find out if playback / recording is currently paused.
Definition: AudioIO.cpp:2709
void SetPaused(bool state)
Pause and un-pause playback and recording.
Definition: AudioIO.cpp:2692
void ControlToolBar::PlayCurrentRegion ( bool  looped = false,
bool  cutpreview = false 
)

Definition at line 729 of file ControlToolBar.cpp.

References CanStopAudioStream(), CutPreview, GetActiveProject(), AudacityProject::GetDefaultPlayOptions(), AudacityProject::GetPlayRegion(), Looped, loopedPlay, normalPlay, AudioIOStartStreamOptions::playLooped, PlayPlayRegion(), and Straight.

Referenced by TransportActions::DoPlayStopSelect(), OnKeyEvent(), TransportActions::Handler::OnPlayCutPreview(), TransportActions::Handler::OnPlayLooped(), and PlayDefault().

731 {
732  if (!CanStopAudioStream())
733  return;
734 
736 
737  if (p)
738  {
739 
740  double playRegionStart, playRegionEnd;
741  p->GetPlayRegion(&playRegionStart, &playRegionEnd);
742 
744  options.playLooped = looped;
745  if (cutpreview)
746  options.timeTrack = NULL;
747  ControlToolBar::PlayAppearance appearance =
751  PlayPlayRegion(SelectedRegion(playRegionStart, playRegionEnd),
752  options,
754  appearance);
755  }
756 }
AudioIOStartStreamOptions GetDefaultPlayOptions()
Definition: Project.cpp:1365
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
Defines a selected portion of a project.
struct holding stream options, including a pointer to the TimeTrack and AudioIOListener and whether t...
Definition: AudioIO.h:124
int PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode playMode, PlayAppearance appearance=PlayAppearance::Straight, bool backwards=false, bool playWhiteSpace=false)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void GetPlayRegion(double *playRegionStart, double *playRegionEnd)
Definition: Project.cpp:5087
void ControlToolBar::PlayDefault ( )

Definition at line 813 of file ControlToolBar.cpp.

References mPlay, PlayCurrentRegion(), AButton::WasControlDown(), and AButton::WasShiftDown().

Referenced by OnPlay().

814 {
815  // Let control have precedence over shift
816  const bool cutPreview = mPlay->WasControlDown();
817  const bool looped = !cutPreview &&
818  mPlay->WasShiftDown();
819  PlayCurrentRegion(looped, cutPreview);
820 }
bool WasShiftDown()
Definition: AButton.cpp:485
void PlayCurrentRegion(bool looped=false, bool cutpreview=false)
bool WasControlDown()
Definition: AButton.cpp:490
int ControlToolBar::PlayPlayRegion ( const SelectedRegion selectedRegion,
const AudioIOStartStreamOptions options,
PlayMode  playMode,
PlayAppearance  appearance = PlayAppearance::Straight,
bool  backwards = false,
bool  playWhiteSpace = false 
)

Definition at line 538 of file ControlToolBar.cpp.

References _(), TrackList::Any(), CanStopAudioStream(), CutPreview, AudioIOStartStreamOptions::cutPreviewGapLen, AudioIOStartStreamOptions::cutPreviewGapStart, AdornedRulerPanel::DrawBothOverlays(), gAudioIO, GetActiveProject(), GetAllPlaybackTracks(), TrackList::GetEndTime(), AudacityProject::GetRulerPanel(), AudacityProject::GetSel0(), AudacityProject::GetSel1(), TrackList::GetStartTime(), AudacityProject::GetTracks(), gPrefs, AudioIO::IsBusy(), mBusyProject, mCutPreviewTracks, min(), AudacityProject::mLastPlayMode, AudioIOStartStreamOptions::playLooped, AudioIOStartStreamOptions::pScrubbingOptions, AudioIO::SeekStream(), AudacityProject::SetAudioIOToken(), SetPlay(), SetRecord(), SetStop(), SetupCutPreviewTracks(), ShowErrorDialog(), StartScrollingIfPreferred(), AudioIO::StartStream(), SelectedRegion::t0(), and SelectedRegion::t1().

Referenced by Scrubber::MaybeStartScrubbing(), EffectUIHost::OnPlay(), TranscriptionToolBar::PlayAtSpeed(), PlayCurrentRegion(), AdornedRulerPanel::StartQPPlay(), and Scrubber::StartSpeedPlay().

545 {
546  if (!CanStopAudioStream())
547  return -1;
548 
549  bool useMidi = true;
550 
551  // Remove these lines to experiment with scrubbing/seeking of note tracks
552  if (options.pScrubbingOptions)
553  useMidi = false;
554 
555  // Uncomment this for laughs!
556  // backwards = true;
557 
558  double t0 = selectedRegion.t0();
559  double t1 = selectedRegion.t1();
560  // SelectedRegion guarantees t0 <= t1, so we need another boolean argument
561  // to indicate backwards play.
562  const bool looped = options.playLooped;
563 
564  if (backwards)
565  std::swap(t0, t1);
566 
567  SetPlay(true, appearance);
568 
569  bool success = false;
570  auto cleanup = finally( [&] {
571  if (!success) {
572  SetPlay(false);
573  SetStop(false);
574  SetRecord(false);
575  }
576  } );
577 
578  if (gAudioIO->IsBusy())
579  return -1;
580 
581  const bool cutpreview = appearance == PlayAppearance::CutPreview;
582  if (cutpreview && t0==t1)
583  return -1; /* msmeyer: makes no sense */
584 
586  if (!p)
587  return -1; // Should never happen, but...
588 
589  TrackList *t = p->GetTracks();
590  if (!t)
591  return -1; // Should never happen, but...
592 
593  p->mLastPlayMode = mode;
594 
595  bool hasaudio;
596  if (useMidi)
597  hasaudio = ! p->GetTracks()->Any<PlayableTrack>().empty();
598  else
599  hasaudio = ! p->GetTracks()->Any<WaveTrack>().empty();
600 
601  double latestEnd = (playWhiteSpace)? t1 : t->GetEndTime();
602 
603  if (!hasaudio)
604  return -1; // No need to continue without audio tracks
605 
606 #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR)
607  double init_seek = 0.0;
608 #endif
609 
610  if (t1 == t0) {
611  if (looped) {
612  // play selection if there is one, otherwise
613  // set start of play region to project start,
614  // and loop the project from current play position.
615 
616  if ((t0 > p->GetSel0()) && (t0 < p->GetSel1())) {
617  t0 = p->GetSel0();
618  t1 = p->GetSel1();
619  }
620  else {
621  // loop the entire project
622  t0 = t->GetStartTime();
623  t1 = t->GetEndTime();
624  }
625  } else {
626  // move t0 to valid range
627  if (t0 < 0) {
628  t0 = t->GetStartTime();
629  }
630  else if (t0 > t->GetEndTime()) {
631  t0 = t->GetEndTime();
632  }
633 #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR)
634  else {
635  init_seek = t0; //AC: init_seek is where playback will 'start'
636  t0 = t->GetStartTime();
637  }
638 #endif
639  }
640  t1 = t->GetEndTime();
641  }
642  else {
643  // maybe t1 < t0, with backwards scrubbing for instance
644  if (backwards)
645  std::swap(t0, t1);
646 
647  t0 = std::max(0.0, std::min(t0, latestEnd));
648  t1 = std::max(0.0, std::min(t1, latestEnd));
649 
650  if (backwards)
651  std::swap(t0, t1);
652  }
653 
654  int token = -1;
655 
656  if (t1 != t0) {
657  if (cutpreview) {
658  const double tless = std::min(t0, t1);
659  const double tgreater = std::max(t0, t1);
660  double beforeLen, afterLen;
661  gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
662  gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
663  double tcp0 = tless-beforeLen;
664  double diff = tgreater - tless;
665  double tcp1 = (tgreater+afterLen) - diff;
666  SetupCutPreviewTracks(tcp0, tless, tgreater, tcp1);
667  if (backwards)
668  std::swap(tcp0, tcp1);
669  if (mCutPreviewTracks)
670  {
671  AudioIOStartStreamOptions myOptions = options;
672  myOptions.cutPreviewGapStart = t0;
673  myOptions.cutPreviewGapLen = t1 - t0;
674  token = gAudioIO->StartStream(
675  GetAllPlaybackTracks(*mCutPreviewTracks, false, useMidi),
676  tcp0, tcp1, myOptions);
677  }
678  else
679  // Cannot create cut preview tracks, clean up and exit
680  return -1;
681  }
682  else {
683  // Lifted the following into AudacityProject::GetDefaultPlayOptions()
684  /*
685  if (!timetrack) {
686  timetrack = t->GetTimeTrack();
687  }
688  */
689  token = gAudioIO->StartStream(
690  GetAllPlaybackTracks(*t, false, useMidi),
691  t0, t1, options);
692  }
693  if (token != 0) {
694  success = true;
695  p->SetAudioIOToken(token);
696  mBusyProject = p;
697 #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR)
698  //AC: If init_seek was set, now's the time to make it happen.
699  gAudioIO->SeekStream(init_seek);
700 #endif
701  }
702  else {
703  // Bug1627 (part of it):
704  // infinite error spew when trying to start scrub:
705  // Problem was that the error dialog yields to events,
706  // causing recursion to this function in the scrub timer
707  // handler! Easy fix, just delay the user alert instead.
708  CallAfter( [=]{
709  // Show error message if stream could not be opened
710  ShowErrorDialog(this, _("Error"),
711  _("Error opening sound device.\nTry changing the audio host, playback device and the project sample rate."),
712  wxT("Error_opening_sound_device"));
713  });
714  }
715  }
716 
717  if (!success)
718  return -1;
719 
721 
722  // Let other UI update appearance
723  if (p)
725 
726  return token;
727 }
int StartStream(const TransportTracks &tracks, double t0, double t1, const AudioIOStartStreamOptions &options)
Start recording or playing back audio.
Definition: AudioIO.cpp:1717
void SetPlay(bool down, PlayAppearance appearance=PlayAppearance::Straight)
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
double t0() const
double GetSel0() const
Definition: Project.h:221
double GetStartTime() const
Definition: Track.cpp:1226
double GetEndTime() const
Definition: Track.cpp:1231
void SetAudioIOToken(int token)
Definition: Project.cpp:1527
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1246
bool IsBusy() const
Returns true if audio i/o is busy starting, stopping, playing, or recording.
Definition: AudioIO.cpp:2741
ScrubbingOptions * pScrubbingOptions
Definition: AudioIO.h:151
double t1() const
void ShowErrorDialog(wxWindow *parent, const wxString &dlogTitle, const wxString &message, const wxString &helpPage, const bool Close)
Displays an error dialog with a button that offers help.
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
TransportTracks GetAllPlaybackTracks(TrackList &trackList, bool selectedOnly, bool useMidi)
Definition: Track.cpp:1418
void SetStop(bool down)
struct holding stream options, including a pointer to the TimeTrack and AudioIOListener and whether t...
Definition: AudioIO.h:124
AdornedRulerPanel * GetRulerPanel()
Definition: Project.cpp:1517
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
void SetupCutPreviewTracks(double playStart, double cutStart, double cutEnd, double playEnd)
int min(int a, int b)
PlayMode mLastPlayMode
Definition: Project.h:554
An AudioTrack that can be played and stopped.
Definition: Track.h:769
void StartScrollingIfPreferred()
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static AudacityProject * mBusyProject
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void SetRecord(bool down, bool altAppearance=false)
double GetSel1() const
Definition: Project.h:222
TrackList * GetTracks()
Definition: Project.h:209
void SeekStream(double seconds)
Move the playback / recording position of the current stream by the specified amount from where it is...
Definition: AudioIO.h:840
std::shared_ptr< TrackList > mCutPreviewTracks
void ControlToolBar::Populate ( )
overridevirtual

Implements ToolBar.

Definition at line 172 of file ControlToolBar.cpp.

References _(), ArrangeButtons(), ThemeBase::Colour(), AButton::FollowModifierKeys(), gPrefs, ID_FF_BUTTON, ID_PAUSE_BUTTON, ID_PLAY_BUTTON, ID_RECORD_BUTTON, ID_REW_BUTTON, ID_STOP_BUTTON, MakeAlternateImages(), MakeButton(), ToolBar::MakeButtonBackgroundsLarge(), mFF, mPause, mPlay, mRecord, mRewind, mStop, RegenerateTooltips(), and theTheme.

173 {
174  SetBackgroundColour( theTheme.Colour( clrMedium ) );
176 
177  mPause = MakeButton(this, bmpPause, bmpPause, bmpPauseDisabled,
178  ID_PAUSE_BUTTON, true, _("Pause"));
179 
180  mPlay = MakeButton(this, bmpPlay, bmpPlay, bmpPlayDisabled,
181  ID_PLAY_BUTTON, true, _("Play"));
182  MakeAlternateImages(*mPlay, 1, bmpLoop, bmpLoop, bmpLoopDisabled);
184  bmpCutPreview, bmpCutPreview, bmpCutPreviewDisabled);
186  bmpScrub, bmpScrub, bmpScrubDisabled);
188  bmpSeek, bmpSeek, bmpSeekDisabled);
190 
191  mStop = MakeButton(this, bmpStop, bmpStop, bmpStopDisabled ,
192  ID_STOP_BUTTON, false, _("Stop"));
193 
194  mRewind = MakeButton(this, bmpRewind, bmpRewind, bmpRewindDisabled,
195  ID_REW_BUTTON, false, _("Skip to Start"));
196 
197  mFF = MakeButton(this, bmpFFwd, bmpFFwd, bmpFFwdDisabled,
198  ID_FF_BUTTON, false, _("Skip to End"));
199 
200  mRecord = MakeButton(this, bmpRecord, bmpRecord, bmpRecordDisabled,
201  ID_RECORD_BUTTON, false, _("Record"));
202 
203  bool bPreferNewTrack;
204  gPrefs->Read("/GUI/PreferNewTrackRecord",&bPreferNewTrack, false);
205  if( !bPreferNewTrack )
206  MakeAlternateImages(*mRecord, 1, bmpRecordBelow, bmpRecordBelow,
207  bmpRecordBelowDisabled);
208  else
209  MakeAlternateImages(*mRecord, 1, bmpRecordBeside, bmpRecordBeside,
210  bmpRecordBesideDisabled);
211 
213 
214 #if wxUSE_TOOLTIPS
216  wxToolTip::Enable(true);
217  wxToolTip::SetDelay(1000);
218 #endif
219 
220  // Set default order and mode
221  ArrangeButtons();
222 }
AButton * mRecord
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
void MakeButtonBackgroundsLarge()
Definition: ToolBar.cpp:721
void RegenerateTooltips() override
static AButton * MakeButton(ControlToolBar *pBar, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, bool processdownevents, const wxChar *label)
AButton * mPause
void FollowModifierKeys()
Definition: AButton.cpp:258
static void MakeAlternateImages(AButton &button, int idx, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
AButton * mRewind
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void ControlToolBar::ReCreateButtons ( )
overridevirtual

Reimplemented from ToolBar.

Definition at line 393 of file ControlToolBar.cpp.

References ToolBar::Detach(), EnableDisableButtons(), AButton::IsDown(), Looped, mPause, mPlay, mRecord, mSizer, AButton::PushDown(), ToolBar::ReCreateButtons(), RegenerateTooltips(), SetPlay(), SetRecord(), Straight, and AButton::WasShiftDown().

Referenced by UpdatePrefs().

394 {
395  bool playDown = false;
396  bool playShift = false;
397  bool pauseDown = false;
398  bool recordDown = false;
399  bool recordShift = false;
400 
401  // ToolBar::ReCreateButtons() will get rid of its sizer and
402  // since we've attached our sizer to it, ours will get deleted too
403  // so clean ours up first.
404  if( mSizer )
405  {
406  playDown = mPlay->IsDown();
407  playShift = mPlay->WasShiftDown();
408  pauseDown = mPause->IsDown();
409  recordDown = mRecord->IsDown();
410  recordShift = mRecord->WasShiftDown();
411  Detach( mSizer );
412 
413  std::unique_ptr < wxSizer > {mSizer}; // DELETE it
414  mSizer = NULL;
415  }
416 
418 
419  if (playDown)
420  {
421  ControlToolBar::PlayAppearance appearance =
424  SetPlay(playDown, appearance);
425  }
426 
427  if (pauseDown)
428  {
429  mPause->PushDown();
430  }
431 
432  if (recordDown)
433  {
434  SetRecord(recordDown, recordShift);
435  }
436 
438 
440 }
AButton * mRecord
void EnableDisableButtons() override
void SetPlay(bool down, PlayAppearance appearance=PlayAppearance::Straight)
bool IsDown()
Definition: AButton.h:123
bool WasShiftDown()
Definition: AButton.cpp:485
void RegenerateTooltips() override
virtual void ReCreateButtons()
Definition: ToolBar.cpp:473
AButton * mPause
void Detach(wxWindow *window)
Definition: ToolBar.cpp:697
wxBoxSizer * mSizer
void PushDown()
Definition: AButton.cpp:517
void SetRecord(bool down, bool altAppearance=false)
void ControlToolBar::RegenerateTooltips ( )
overridevirtual

Implements ToolBar.

Definition at line 224 of file ControlToolBar.cpp.

References _(), BUTTON_COUNT, gPrefs, ID_FF_BUTTON, ID_PAUSE_BUTTON, ID_PLAY_BUTTON, ID_RECORD_BUTTON, ID_REW_BUTTON, ID_STOP_BUTTON, name, and ToolBar::SetButtonToolTip().

Referenced by Populate(), ReCreateButtons(), and UpdatePrefs().

225 {
226 #if wxUSE_TOOLTIPS
227  for (long iWinID = ID_PLAY_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
228  {
229  auto pCtrl = static_cast<AButton*>(this->FindWindow(iWinID));
230  const wxChar *name = nullptr;
231  switch (iWinID)
232  {
233  case ID_PLAY_BUTTON:
234  // Without shift
235  name = wxT("PlayStop");
236  break;
237  case ID_RECORD_BUTTON:
238  // Without shift
239  //name = wxT("Record");
240  name = wxT("Record1stChoice");
241  break;
242  case ID_PAUSE_BUTTON:
243  name = wxT("Pause");
244  break;
245  case ID_STOP_BUTTON:
246  name = wxT("Stop");
247  break;
248  case ID_FF_BUTTON:
249  name = wxT("CursProjectEnd");
250  break;
251  case ID_REW_BUTTON:
252  name = wxT("CursProjectStart");
253  break;
254  }
255  std::vector<TranslatedInternalString> commands(
256  1u, { name, pCtrl->GetLabel() } );
257 
258  // Some have a second
259  switch (iWinID)
260  {
261  case ID_PLAY_BUTTON:
262  // With shift
263  commands.push_back( { wxT("PlayLooped"), _("Loop Play") } );
264  break;
265  case ID_RECORD_BUTTON:
266  // With shift
267  { bool bPreferNewTrack;
268  gPrefs->Read("/GUI/PreferNewTrackRecord",&bPreferNewTrack, false);
269  // For the shortcut tooltip.
270  commands.push_back( {
271  wxT("Record2ndChoice"),
272  !bPreferNewTrack
273  ? _("Record New Track")
274  : _("Append Record")
275  } );
276  }
277  break;
278  case ID_PAUSE_BUTTON:
279  break;
280  case ID_STOP_BUTTON:
281  break;
282  case ID_FF_BUTTON:
283  // With shift
284  commands.push_back( {
285  wxT("SelEnd"), _("Select to End") } );
286  break;
287  case ID_REW_BUTTON:
288  // With shift
289  commands.push_back( {
290  wxT("SelStart"), _("Select to Start") } );
291  break;
292  }
293  ToolBar::SetButtonToolTip(*pCtrl, commands.data(), commands.size());
294  }
295 #endif
296 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
const wxChar * name
Definition: Distortion.cpp:94
static void SetButtonToolTip(AButton &button, const TranslatedInternalString commands[], size_t nCommands)
Definition: ToolBar.cpp:843
A wxButton with mouse-over behaviour.
Definition: AButton.h:28
void ControlToolBar::Repaint ( wxDC *  dc)
overridevirtual

Implements ToolBar.

Definition at line 442 of file ControlToolBar.cpp.

References AColor::Bevel(), and mSizer.

443 {
444 #ifndef USE_AQUA_THEME
445  wxSize s = mSizer->GetSize();
446  wxPoint p = mSizer->GetPosition();
447 
448  wxRect bevelRect( p.x, p.y, s.GetWidth() - 1, s.GetHeight() - 1 );
449  AColor::Bevel( *dc, true, bevelRect );
450 #endif
451 }
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:202
wxBoxSizer * mSizer
void ControlToolBar::SetPlay ( bool  down,
PlayAppearance  appearance = PlayAppearance::Straight 
)

Definition at line 485 of file ControlToolBar.cpp.

References CutPreview, EnableDisableButtons(), GetActiveProject(), Looped, mPlay, AButton::PopUp(), AButton::PushDown(), AButton::SetAlternateIdx(), AButton::SetControl(), AButton::SetShift(), and UpdateStatusBar().

Referenced by TransportActions::DoPlayStopSelect(), DoRecord(), Scrubber::MarkScrubStart(), OnKeyEvent(), PlayPlayRegion(), ReCreateButtons(), StopPlaying(), and Scrubber::StopScrubbing().

486 {
487  if (down) {
488  mPlay->SetShift(appearance == PlayAppearance::Looped);
490  mPlay->SetAlternateIdx(static_cast<int>(appearance));
491  mPlay->PushDown();
492  }
493  else {
494  mPlay->PopUp();
496  }
499 }
void EnableDisableButtons() override
void SetAlternateIdx(unsigned idx)
Definition: AButton.cpp:248
void PopUp()
Definition: AButton.cpp:525
void SetShift(bool shift)
Definition: AButton.cpp:546
void UpdateStatusBar(AudacityProject *pProject)
void SetControl(bool control)
Definition: AButton.cpp:551
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void PushDown()
Definition: AButton.cpp:517
void ControlToolBar::SetRecord ( bool  down,
bool  altAppearance = false 
)

Definition at line 513 of file ControlToolBar.cpp.

References EnableDisableButtons(), mRecord, AButton::PopUp(), AButton::PushDown(), and AButton::SetAlternateIdx().

Referenced by DoRecord(), PlayPlayRegion(), ReCreateButtons(), and StopPlaying().

514 {
515  if (down)
516  {
517  mRecord->SetAlternateIdx(altAppearance ? 1 : 0);
518  mRecord->PushDown();
519  }
520  else
521  {
523  mRecord->PopUp();
524  }
526 }
AButton * mRecord
void EnableDisableButtons() override
void SetAlternateIdx(unsigned idx)
Definition: AButton.cpp:248
void PopUp()
Definition: AButton.cpp:525
void PushDown()
Definition: AButton.cpp:517
void ControlToolBar::SetStop ( bool  down)

Definition at line 501 of file ControlToolBar.cpp.

References EnableDisableButtons(), mPlay, mStop, AButton::PopUp(), and AButton::PushDown().

Referenced by TransportActions::DoPlayStopSelect(), DoRecord(), OnKeyEvent(), PlayPlayRegion(), and StopPlaying().

502 {
503  if (down)
504  mStop->PushDown();
505  else {
506  if(FindFocus() == mStop)
507  mPlay->SetFocus();
508  mStop->PopUp();
509  }
511 }
void EnableDisableButtons() override
void PopUp()
Definition: AButton.cpp:525
void PushDown()
Definition: AButton.cpp:517
void ControlToolBar::SetupCutPreviewTracks ( double  playStart,
double  cutStart,
double  cutEnd,
double  playEnd 
)
private

Definition at line 1327 of file ControlToolBar.cpp.

References ClearCutPreviewTracks(), TrackList::Create(), GetActiveProject(), AudacityProject::GetTracks(), mCutPreviewTracks, and TrackList::Selected().

Referenced by PlayPlayRegion().

1331 {
1334  if (p) {
1335  auto trackRange = p->GetTracks()->Selected<const PlayableTrack>();
1336  if( !trackRange.empty() ) {
1337  auto cutPreviewTracks = TrackList::Create();
1338  for (const auto track1 : trackRange) {
1339  // Duplicate and change tracks
1340  // Clear has a very small chance of throwing
1341 
1342  auto newTrack = track1->Duplicate();
1343  newTrack->Clear(cutStart, cutEnd);
1344  cutPreviewTracks->Add(std::move(newTrack));
1345  }
1346  // use NOTHROW-GUARANTEE:
1347  mCutPreviewTracks = cutPreviewTracks;
1348  }
1349  }
1350 }
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1263
static std::shared_ptr< TrackList > Create()
Definition: Track.cpp:574
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
void ClearCutPreviewTracks()
An AudioTrack that can be played and stopped.
Definition: Track.h:769
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
TrackList * GetTracks()
Definition: Project.h:209
std::shared_ptr< TrackList > mCutPreviewTracks
void ControlToolBar::StartScrolling ( )

Definition at line 1446 of file ControlToolBar.cpp.

References gAudioIO, GetActiveProject(), AudioIO::GetNumCaptureChannels(), AudioIO::GetNumPlaybackChannels(), and gPrefs.

Referenced by StartScrollingIfPreferred().

1447 {
1449  const auto project = GetActiveProject();
1450  if (project) {
1451  auto mode = Mode::Pinned;
1452 
1453 #if 0
1454  // Enable these lines to pin the playhead right instead of center,
1455  // when recording but not overdubbing.
1456  if (gAudioIO->GetNumCaptureChannels() > 0) {
1457  // recording
1458 
1459  // Display a fixed recording head while scrolling the waves continuously.
1460  // If you overdub, you may want to anticipate some context in existing tracks,
1461  // so center the head. If not, put it rightmost to display as much wave as we can.
1462  bool duplex;
1463 #ifdef EXPERIMENTAL_DA
1464  gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, false);
1465 #else
1466  gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true);
1467 #endif
1468  if (duplex) {
1469  // See if there is really anything being overdubbed
1470  if (gAudioIO->GetNumPlaybackChannels() == 0)
1471  // No.
1472  duplex = false;
1473  }
1474 
1475  if (!duplex)
1476  mode = Mode::Right;
1477  }
1478 #endif
1479 
1480  project->GetPlaybackScroller().Activate(mode);
1481  }
1482 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
unsigned GetNumCaptureChannels() const
Definition: AudioIO.h:1028
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
unsigned GetNumPlaybackChannels() const
Definition: AudioIO.h:1027
void ControlToolBar::StartScrollingIfPreferred ( )

Definition at line 1428 of file ControlToolBar.cpp.

References AudacityProject::PlaybackScroller::Activate(), GetActiveProject(), AudacityProject::GetPlaybackScroller(), IsTransportingPinned(), AudacityProject::PlaybackScroller::Refresh, StartScrolling(), and StopScrolling().

Referenced by DoRecord(), TransportActions::DoTogglePinnedHead(), and PlayPlayRegion().

1429 {
1430  if (IsTransportingPinned())
1431  StartScrolling();
1432 #ifdef __WXMAC__
1433  else if (::GetActiveProject()->GetScrubber().HasMark()) {
1434  // PRL: cause many "unnecessary" refreshes. For reasons I don't understand,
1435  // doing this causes wheel rotation events (mapped from the double finger vertical
1436  // swipe) to be delivered more uniformly to the application, so that speed control
1437  // works better.
1440  }
1441 #endif
1442  else
1443  StopScrolling();
1444 }
PlaybackScroller & GetPlaybackScroller()
Definition: Project.h:827
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
static bool IsTransportingPinned()
wxString ControlToolBar::StateForStatusBar ( )
private

Definition at line 1385 of file ControlToolBar.cpp.

References GetActiveProject(), AButton::IsDown(), mPause, mPlay, mRecord, mStatePause, mStatePlay, mStateRecord, and mStateStop.

Referenced by UpdateStatusBar().

1386 {
1387  wxString state;
1388 
1389  auto pProject = GetActiveProject();
1390  auto scrubState =
1391  pProject ? pProject->GetScrubber().GetUntranslatedStateString() : wxString();
1392  if (!scrubState.IsEmpty())
1393  state = wxGetTranslation(scrubState);
1394  else if (mPlay->IsDown())
1395  state = wxGetTranslation(mStatePlay);
1396  else if (mRecord->IsDown())
1397  state = wxGetTranslation(mStateRecord);
1398  else
1399  state = wxGetTranslation(mStateStop);
1400 
1401  if (mPause->IsDown())
1402  {
1403  state.Append(wxT(" "));
1404  state.Append(wxGetTranslation(mStatePause));
1405  }
1406 
1407  state.Append(wxT("."));
1408 
1409  return state;
1410 }
AButton * mRecord
bool IsDown()
Definition: AButton.h:123
wxString mStateRecord
AButton * mPause
wxString mStateStop
wxString mStatePause
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
wxString mStatePlay
void ControlToolBar::StopPlaying ( bool  stopStream = true)

Definition at line 822 of file ControlToolBar.cpp.

References CanStopAudioStream(), MeterPanel::Clear(), ClearCutPreviewTracks(), ToolBar::EnableDisableButtons(), gAudioIO, GetActiveProject(), AudacityProject::GetCaptureMeter(), AudacityProject::GetPlaybackMeter(), AudacityProject::GetScrubber(), ToolManager::GetToolBar(), AudacityProject::GetToolManager(), AudacityProject::MayStartMonitoring(), mBusyProject, mPause, mPaused, mStop, AButton::PopUp(), AButton::PushDown(), ScrubbingBarID, AudioIO::SetPaused(), SetPlay(), SetRecord(), SetStop(), StopScrolling(), Scrubber::StopScrubbing(), and AudioIO::StopStream().

Referenced by AdornedRulerPanel::ClearPlayRegion(), Scrubber::DoScrub(), Scrubber::MarkScrubStart(), Scrubber::MaybeStartScrubbing(), OnKeyEvent(), OnPlay(), EffectUIHost::OnPlay(), OnStop(), TrackPanel::OnTimer(), TranscriptionToolBar::PlayAtSpeed(), AdornedRulerPanel::StartQPPlay(), and Scrubber::StartSpeedPlay().

823 {
824  StopScrolling();
825 
826  AudacityProject *project = GetActiveProject();
827 
828  if(project) {
829  // Let scrubbing code do some appearance change
830  project->GetScrubber().StopScrubbing();
831  }
832 
833  if (!CanStopAudioStream())
834  return;
835 
836  mStop->PushDown();
837 
838  SetStop(false);
839  if(stopStream)
840  gAudioIO->StopStream();
841  SetPlay(false);
842  SetRecord(false);
843 
844  #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
845  gAudioIO->AILADisable();
846  #endif
847 
848  mPause->PopUp();
849  mPaused=false;
850  //Make sure you tell gAudioIO to unpause
852 
854 
855  mBusyProject = NULL;
856  // So that we continue monitoring after playing or recording.
857  // also clean the MeterQueues
858  if( project ) {
859  project->MayStartMonitoring();
860 
861  MeterPanel *meter = project->GetPlaybackMeter();
862  if( meter ) {
863  meter->Clear();
864  }
865 
866  meter = project->GetCaptureMeter();
867  if( meter ) {
868  meter->Clear();
869  }
870  }
871 
872  const auto toolbar = project->GetToolManager()->GetToolBar(ScrubbingBarID);
873  toolbar->EnableDisableButtons();
874 }
void SetPlay(bool down, PlayAppearance appearance=PlayAppearance::Straight)
void StopStream()
Stop recording, playback or input monitoring.
Definition: AudioIO.cpp:2408
void PopUp()
Definition: AButton.cpp:525
Scrubber & GetScrubber()
Definition: Project.h:786
void Clear()
Definition: Meter.cpp:335
AButton * mPause
void MayStartMonitoring()
Definition: Project.cpp:5173
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: Meter.h:102
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
void StopScrubbing()
Definition: Scrubbing.cpp:680
void ClearCutPreviewTracks()
MeterPanel * GetCaptureMeter()
Definition: Project.cpp:4911
void SetStop(bool down)
virtual void EnableDisableButtons()=0
ToolManager * GetToolManager()
Definition: Project.h:685
static AudacityProject * mBusyProject
AudioIO * gAudioIO
Definition: AudioIO.cpp:491
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
MeterPanel * GetPlaybackMeter()
Definition: Project.cpp:4897
void PushDown()
Definition: AButton.cpp:517
void SetRecord(bool down, bool altAppearance=false)
void SetPaused(bool state)
Pause and un-pause playback and recording.
Definition: AudioIO.cpp:2692
ToolBar * GetToolBar(int type) const
void ControlToolBar::StopScrolling ( )

Definition at line 1484 of file ControlToolBar.cpp.

References GetActiveProject(), and AudacityProject::PlaybackScroller::Off.

Referenced by StartScrollingIfPreferred(), and StopPlaying().

1485 {
1486  const auto project = GetActiveProject();
1487  if(project)
1488  project->GetPlaybackScroller().Activate
1490 }
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
void ControlToolBar::UpdatePrefs ( )
overridevirtual

Reimplemented from ToolBar.

Definition at line 298 of file ControlToolBar.cpp.

References _(), gPrefs, mErgonomicTransportButtons, mStrLocale, ReCreateButtons(), RegenerateTooltips(), ToolBar::SetLabel(), ToolBar::Updated(), and ToolBar::UpdatePrefs().

299 {
300  bool updated = false;
301  bool active;
302 
303  gPrefs->Read( wxT("/GUI/ErgonomicTransportButtons"), &active, true );
304  if( mErgonomicTransportButtons != active )
305  {
307  updated = true;
308  }
309  wxString strLocale = gPrefs->Read(wxT("/Locale/Language"), wxT(""));
310  if (mStrLocale != strLocale)
311  {
312  mStrLocale = strLocale;
313  updated = true;
314  }
315 
316  if( updated )
317  {
318  ReCreateButtons(); // side effect: calls RegenerateTooltips()
319  Updated();
320  }
321  else
322  // The other reason to regenerate tooltips is if keyboard shortcuts for
323  // transport buttons changed, but that's too much work to check for, so just
324  // always do it. (Much cheaper than calling ReCreateButtons() in all cases.
326 
327 
328  // Set label to pull in language change
329  SetLabel(_("Transport"));
330 
331  // Give base class a chance
333 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
virtual void UpdatePrefs()
Definition: ToolBar.cpp:556
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:381
void RegenerateTooltips() override
void ReCreateButtons() override
wxString mStrLocale
void Updated()
Definition: ToolBar.cpp:612
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
bool mErgonomicTransportButtons
void ControlToolBar::UpdateStatusBar ( AudacityProject pProject)
bool ControlToolBar::UseDuplex ( )
static

Definition at line 1037 of file ControlToolBar.cpp.

References gPrefs.

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

1038 {
1039  bool duplex;
1040  gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex,
1041 #ifdef EXPERIMENTAL_DA
1042  false
1043 #else
1044  true
1045 #endif
1046  );
1047  return duplex;
1048 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
int ControlToolBar::WidthForStatusBar ( wxStatusBar * const  sb)

Definition at line 1360 of file ControlToolBar.cpp.

References Scrubber::GetAllUntranslatedStatusStrings(), mStatePause, mStatePlay, mStateRecord, and mStateStop.

Referenced by AudacityProject::OnAudioIORate().

1361 {
1362  int xMax = 0;
1363  const auto pauseString = wxT(" ") + wxGetTranslation(mStatePause);
1364 
1365  auto update = [&] (const wxString &state) {
1366  int x, y;
1367  sb->GetTextExtent(
1368  wxGetTranslation(state) + pauseString + wxT("."),
1369  &x, &y
1370  );
1371  xMax = std::max(x, xMax);
1372  };
1373 
1374  update(mStatePlay);
1375  update(mStateStop);
1376  update(mStateRecord);
1377 
1378  // Note that Scrubbing + Paused is not allowed.
1379  for(const auto &state : Scrubber::GetAllUntranslatedStatusStrings())
1380  update(state);
1381 
1382  return xMax + 30; // added constant needed because xMax isn't large enough for some reason, plus some space.
1383 }
wxString mStateRecord
wxString mStateStop
static std::vector< wxString > GetAllUntranslatedStatusStrings()
Definition: Scrubbing.cpp:1135
wxString mStatePause
wxString mStatePlay

Member Data Documentation

AudacityProject * ControlToolBar::mBusyProject = NULL
staticprivate

Definition at line 177 of file ControlToolBar.h.

Referenced by DoRecord(), PlayPlayRegion(), and StopPlaying().

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

Definition at line 189 of file ControlToolBar.h.

Referenced by ClearCutPreviewTracks(), PlayPlayRegion(), and SetupCutPreviewTracks().

bool ControlToolBar::mErgonomicTransportButtons
private

Definition at line 183 of file ControlToolBar.h.

Referenced by ArrangeButtons(), and UpdatePrefs().

AButton* ControlToolBar::mFF
private

Definition at line 175 of file ControlToolBar.h.

Referenced by ArrangeButtons(), EnableDisableButtons(), OnFF(), and Populate().

AButton* ControlToolBar::mPause
private
bool ControlToolBar::mPaused
private

Definition at line 180 of file ControlToolBar.h.

Referenced by OnPause(), and StopPlaying().

AButton* ControlToolBar::mPlay
private
AButton* ControlToolBar::mRecord
private
AButton* ControlToolBar::mRewind
private

Definition at line 170 of file ControlToolBar.h.

Referenced by ArrangeButtons(), EnableDisableButtons(), OnRewind(), and Populate().

wxBoxSizer* ControlToolBar::mSizer
private

Definition at line 187 of file ControlToolBar.h.

Referenced by ArrangeButtons(), ReCreateButtons(), and Repaint().

wxString ControlToolBar::mStatePause
private

Definition at line 195 of file ControlToolBar.h.

Referenced by StateForStatusBar(), and WidthForStatusBar().

wxString ControlToolBar::mStatePlay
private

Definition at line 192 of file ControlToolBar.h.

Referenced by StateForStatusBar(), and WidthForStatusBar().

wxString ControlToolBar::mStateRecord
private

Definition at line 194 of file ControlToolBar.h.

Referenced by StateForStatusBar(), and WidthForStatusBar().

wxString ControlToolBar::mStateStop
private

Definition at line 193 of file ControlToolBar.h.

Referenced by StateForStatusBar(), and WidthForStatusBar().

AButton* ControlToolBar::mStop
private
wxString ControlToolBar::mStrLocale
private

Definition at line 185 of file ControlToolBar.h.

Referenced by UpdatePrefs().


The documentation for this class was generated from the following files: