2#include "../CommonCommandFlags.h"
4#include "../LabelTrack.h"
9#include "../ProjectAudioManager.h"
11#include "../ProjectSettings.h"
12#include "../ProjectWindows.h"
13#include "../ProjectWindow.h"
14#include "../SelectUtilities.h"
15#include "../SoundActivatedRecord.h"
16#include "../TrackPanelAx.h"
17#include "../TrackPanel.h"
18#include "../TransportUtilities.h"
20#include "../prefs/RecordingPrefs.h"
21#include "../prefs/TracksPrefs.h"
24#include "../commands/CommandContext.h"
25#include "../commands/CommandManager.h"
26#include "../toolbars/ControlToolBar.h"
27#include "../toolbars/ToolManager.h"
53 if (gAudioIO->IsStreamActive(
57 toolbar.SetPlay(
false);
61 using namespace std::chrono;
62 std::this_thread::sleep_for(100ms);
67 if (gAudioIO->IsBusy())
82 auto lt = *trackRange.rbegin();
83 auto nLabelTrack = trackRange.
size();
85 if (nLabelTrack == 0 ) {
86 trackFocus.MessageForScreenReader(
XO(
"no label track"));
88 else if (nLabelTrack > 1) {
91 *
tracks.Find(trackFocus.Get()).Filter<LabelTrack>();
93 trackFocus.MessageForScreenReader(
94 XO(
"no label track at or below focused track"));
109 bool newDefault = projectAudioManager.Looping();
112 selectedRegion =
label->selectedRegion;
113 window.RedrawProject();
117 selectedRegion =
label->selectedRegion;
118 window.ScrollIntoView(selectedRegion.t0());
119 window.RedrawProject();
127 auto message =
XO(
"%s %d of %d")
129 trackFocus.MessageForScreenReader(message);
132 trackFocus.MessageForScreenReader(
XO(
"no labels in label track"));
140 return playRegion.
Active();
202#ifdef EXPERIMENTAL_PUNCH_AND_ROLL
208 static const auto url =
209 wxT(
"Punch_and_Roll_Record#Using_Punch_and_Roll_Record");
212 if (gAudioIO->IsBusy())
216 viewInfo.selectedRegion.collapseToT0();
217 double t1 = std::max(0.0, viewInfo.selectedRegion.t1());
222 const bool allSameRate{ selectedTracks.allSameRate };
226 "for recording must all have the same sampling rate"),
227 XO(
"Mismatched Sampling Rates"),
228 wxICON_ERROR | wxCENTRE);
237 auto recordingChannels =
240 (recordingChannels == 1)
241 ?
XO(
"Please select in a mono track.")
242 : (recordingChannels == 2)
243 ?
XO(
"Please select in a stereo track or two mono tracks.")
244 :
XO(
"Please select at least %d channels.").Format( recordingChannels );
246 XO(
"Error"), message, url);
256 const double crossFadeDuration = std::max(0.0,
264 bool error = (t1 == 0.0);
270 for (
const auto &wt :
tracks) {
271 auto rate = wt->GetRate();
274 intervals = as_const(*wt).Intervals();
279 [rate, testSample](
const auto &pInterval){
280 auto start = floor(pInterval->Start() * rate + 0.5);
281 auto end = floor(pInterval->End() * rate + 0.5);
282 auto ts = testSample.as_double();
283 return ts >= start && ts <
end;
286 auto begin = intervals.begin(),
end = intervals.end(),
287 iter = std::find_if(
begin,
end, pred(testSample));
293 iter = std::find_if(
begin,
end, pred(testSample - 10));
300 newt1 =
std::min(newt1, (*iter).get()->End() - crossFadeDuration);
305 auto message =
XO(
"Please select a time within a clip.");
313 for (
const auto &wt :
tracks) {
315 endTime = wt->GetEndTime();
316 const auto duration =
317 std::max(0.0,
std::min(crossFadeDuration, endTime - t1));
318 const size_t getLen = floor(duration * wt->GetRate());
319 std::vector<float> data(getLen);
321 float *
const samples = data.data();
323 wt->GetFloats(samples, pos, getLen);
325 crossfadeData.push_back(std::move(data));
329 for (
const auto &wt :
tracks)
331 wt->Clear(t1, wt->GetEndTime());
342 for (
auto &pTrack :
tracks)
343 if (pTrack->IsLeader())
353 options.rate = rateOfSelected;
354 options.preRoll = std::max(0.0,
356 options.pCrossfadeData = &crossfadeData;
386 if (!playRegion.Active())
397 if (!playRegion.Active())
431#ifdef EXPERIMENTAL_DA
444 gPrefs->
Read(
wxT(
"/AudioIO/SWPlaythrough"), &SWPlaythrough,
false);
450#ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
451void OnToggleAutomatedInputLevelAdjustment(
456 wxT(
"/AudioIO/AutomatedInputLevelAdjustment"), &AVEnabled,
false);
457 gPrefs->
Write(
wxT(
"/AudioIO/AutomatedInputLevelAdjustment"), !AVEnabled);
477 double pos = trackPanel.GetMostRecentXPos();
499 const auto &selectedRegion = viewInfo.selectedRegion;
501 double pos = trackPanel.GetMostRecentXPos();
505 if (fabs(pos - selectedRegion.t0()) <
506 fabs(pos - selectedRegion.t1())) {
507 t0 = t1 = selectedRegion.t0();
509 t0 = t1 = selectedRegion.t1();
545 const auto &selectedRegion = viewInfo.selectedRegion;
547 double t0 = selectedRegion.t0();
549 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
566 const auto &selectedRegion = viewInfo.selectedRegion;
568 double t0 = selectedRegion.t0();
569 double t1 = selectedRegion.t1();
571 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
575 if ( t1 - t0 > 0.0 && t1 - t0 < afterLen )
593 const auto &selectedRegion = viewInfo.selectedRegion;
595 double t0 = selectedRegion.t0();
596 double t1 = selectedRegion.t1();
598 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
602 if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen )
620 const auto &selectedRegion = viewInfo.selectedRegion;
622 double t1 = selectedRegion.t1();
624 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
642 const auto &selectedRegion = viewInfo.selectedRegion;
644 double t0 = selectedRegion.t0();
645 double t1 = selectedRegion.t1();
647 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
649 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
653 if ( t1 - t0 > 0.0 && t1 - t0 < afterLen )
672 const auto &selectedRegion = viewInfo.selectedRegion;
674 double t0 = selectedRegion.t0();
675 double t1 = selectedRegion.t1();
677 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0);
679 gPrefs->
Read(
wxT(
"/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0);
683 if ( t1 - t0 > 0.0 && t1 - t0 < beforeLen )
722 auto &viewInfo =
project.GetViewInfo();
723 auto &selectedRegion = viewInfo.selectedRegion;
726 if (gAudioIO->IsStreamActive()) {
727 selectedRegion.setT0(gAudioIO->GetStreamTime(),
false);
729 history.ModifyState(
false);
753 Command(
wxT(
"PlayStopSelect"),
XXO(
"Play/Stop and &Set Cursor"),
777 ?
XXO(
"&Append Record") :
XXO(
"Record &New Track")),
782 #ifdef EXPERIMENTAL_PUNCH_AND_ROLL
808 XXO(
"&Set Loop to Selection"),
823 Menu(
wxT(
"Options"),
XXO(
"Transport &Options"),
830 XXO(
"Enable sound a&ctivated recording"),
837 Command(
wxT(
"Overdub"),
XXO(
"Hear &other tracks during recording"),
841#ifdef EXPERIMENTAL_DA
847 Command(
wxT(
"SWPlaythrough"),
XXO(
"Enable audible input &monitoring"),
853 #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT
855 Command(
wxT(
"AutomatedInputLevelAdjustmentOnOff"),
856 XXO(
"A&utomated Recording Level Adjustment (on/off)"),
857 OnToggleAutomatedInputLevelAdjustment,
860 wxT(
"/AudioIO/AutomatedInputLevelAdjustment"),
false ) )
902 Command(
wxT(
"PlayBeforeAndAfterSelectionStart"),
903 XXO(
"Play Before a&nd After Selection Start"),
905 wxT(
"Ctrl+Shift+F5") ),
906 Command(
wxT(
"PlayBeforeAndAfterSelectionEnd"),
907 XXO(
"Play Before an&d After Selection End"),
909 wxT(
"Ctrl+Shift+F7") ),
918 wxT(
"Optional/Extra/Part1"),
927 Command(
wxT(
"MoveToPrevLabel"),
XXO(
"Move to Pre&vious Label"),
938 {
wxT(
"Optional/Extra/Part1/Select"), { OrderingHint::End, {} } },
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
BoolSetting SoundActivatedRecord
IntSetting AudioIORecordChannels
std::vector< std::vector< float > > PRCrossfadeData
Toolkit-neutral facade for basic user interface services.
AttachedItem sAttachment1
AttachedItem sAttachment2
constexpr CommandFlag AlwaysEnabledFlag
const ReservedCommandFlag & CaptureNotBusyFlag()
const ReservedCommandFlag & AudioIOBusyFlag()
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & WaveTracksExistFlag()
const ReservedCommandFlag & TrackPanelHasFocus()
XXO("&Cut/Copy/Paste Toolbar")
audacity::BasicSettings * gPrefs
std::unique_ptr< const BasicUI::WindowPlacement > ProjectFramePlacement(AudacityProject *project)
Make a WindowPlacement object suitable for project (which may be null)
const ReservedCommandFlag & CanStopAudioStreamFlag()
PropertiesOfSelected GetPropertiesOfSelected(const AudacityProject &proj)
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 ...
#define AUDIO_PRE_ROLL_KEY
#define DEFAULT_PRE_ROLL_SECONDS
#define DEFAULT_ROLL_CROSSFADE_MS
#define AUDIO_ROLL_CROSSFADE_KEY
TransportSequences MakeTransportTracks(TrackList &trackList, bool selectedOnly, bool nonWaveToo)
const TranslatableString LoopToggleText
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
static AudioIOBase * Get()
bool Toggle()
Write the negation of the previous value, and then return the current value.
size_t size() const
How many attachment pointers are in the Site.
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
static DeviceManager * Instance()
Gets the singleton instance.
A LabelStruct holds information for ONE label in a LabelTrack.
A LabelTrack is a Track that holds labels (LabelStruct).
int FindPrevLabel(const SelectedRegion ¤tSelection)
const LabelStruct * GetLabel(int index) const
int FindNextLabel(const SelectedRegion ¤tSelection)
int GetAudioIOToken() const
static AudioIOStartStreamOptions GetDefaultOptions(AudacityProject &project, bool newDefaults=false)
Invoke the global hook, supplying a default argument.
static ProjectAudioIO & Get(AudacityProject &project)
void Stop(bool stopStream=true)
static WritableSampleTrackArray ChooseExistingRecordingTracks(AudacityProject &proj, bool selectedOnly, double targetRate=RATE_NOT_SELECTED)
static ProjectAudioManager & Get(AudacityProject &project)
bool DoPlayStopSelect(bool click, bool shift)
bool DoRecord(AudacityProject &project, const TransportSequences &transportSequences, double t0, double t1, bool altAppearance, const AudioIOStartStreamOptions &options)
static ProjectHistory & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
Defines a selected portion of a project.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
Configures sound activated recording.
static TrackList & Get(AudacityProject &project)
static TrackPanel & Get(AudacityProject &project)
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
bool ReadBool(const wxString &key, bool defaultValue) const
virtual bool Read(const wxString &key, bool *value) const =0
Positions or offsets within audio files need a wide type.
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
std::shared_ptr< BaseItem > BaseItemSharedPtr
void SetPlayRegionToSelection(AudacityProject &project)
void ActivatePlayRegion(AudacityProject &project)
void OnSetRegion(AudacityProject &project, bool left, bool selection, const TranslatableString &dialogTitle)
Adjust left or right of selection or play region.
void ClearPlayRegion(AudacityProject &project)
void TogglePlayRegion(AudacityProject &project)
CommandManager::Options Options
void copy(const T *src, T *dst, int32_t n)
Options && CheckTest(const CheckFn &fn) &&
A convenience for use with range-for.
RecordableSequences captureSequences
ConstPlayableSequences playbackSequences
static void PlayPlayRegionAndWait(const CommandContext &context, const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode mode)
static bool DoStopPlaying(const CommandContext &context)
static void PlayCurrentRegionAndWait(const CommandContext &context, bool newDefault=false, bool cutpreview=false)
static void RecordAndWait(const CommandContext &context, bool altAppearance)
static void DoStartPlaying(const CommandContext &context, bool newDefault=false)