35#include "../KeyboardCapture.h"
39#include "../ProjectAudioManager.h"
43#include "../widgets/AButton.h"
44#include "../widgets/ASlider.h"
45#include "../tracks/ui/Scrubbing.h"
48#ifdef EXPERIMENTAL_VOICE_DETECTION
49#include "../VoiceKey.h"
50#include "../ProjectWindow.h"
68#ifdef EXPERIMENTAL_VOICE_DETECTION
87 EVT_SLIDER(TTB_SensitivitySlider, TranscriptionToolBar::OnSensitivitySlider)
89 EVT_CHOICE(TTB_KeyType, TranscriptionToolBar::SetKeyType)
96 return wxT(
"Transcription");
104#ifdef EXPERIMENTAL_VOICE_DETECTION
105 mVk = std::make_unique<VoiceKey>();
116#ifdef EXPERIMENTAL_DA
147#ifdef EXPERIMENTAL_VOICE_DETECTION
170 wxSizeEvent event(GetSize(), GetId());
171 event.SetEventObject(
this);
172 GetEventHandler()->ProcessEvent(event);
193 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall,bmpRecoloredHiliteSmall,
194 eFore, eFore, eDisabled,
204 pBar->
Add( r, 0, wxALIGN_CENTER );
211 int id,
unsigned altIdx)
214 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall,bmpRecoloredHiliteSmall,
215 eFore, eFore, eDisabled,
227 XO(
"Play at selected speed"));
234 const int SliderWidth=100;
237 XO(
"Playback Speed"),
239 wxSize(SliderWidth,25),
257#ifdef EXPERIMENTAL_VOICE_DETECTION
260#define YO( x ) Verbatim( x )
261 AddButton(
this, bmpTnStartOn, bmpTnStartOnDisabled, TTB_StartOn,
262 YO(
"Adjust left selection to next onset"));
263 AddButton(
this, bmpTnEndOn, bmpTnEndOnDisabled, TTB_EndOn,
264 YO(
"Adjust right selection to previous offset"));
265 AddButton(
this, bmpTnStartOff, bmpTnStartOffDisabled, TTB_StartOff,
266 YO(
"Adjust left selection to next offset"));
267 AddButton(
this, bmpTnEndOff, bmpTnEndOffDisabled, TTB_EndOff,
268 YO(
"Adjust right selection to previous onset"));
269 AddButton(
this, bmpTnSelectSound, bmpTnSelectSoundDisabled, TTB_SelectSound,
270 YO(
"Select region of sound around cursor"));
271 AddButton(
this, bmpTnSelectSilence, bmpTnSelectSilenceDisabled, TTB_SelectSilence,
272 YO(
"Select region of silence around cursor"));
273 AddButton(
this, bmpTnAutomateSelection, bmpTnAutomateSelectionDisabled, TTB_AutomateSelection,
274 YO(
"Automatically make labels from words"));
275 AddButton(
this, bmpTnMakeTag, bmpTnMakeTagDisabled, TTB_MakeLabel,
276 YO(
"Add label at selection"));
277 AddButton(
this, bmpTnCalibrate, bmpTnCalibrateDisabled, TTB_Calibrate,
278 YO(
"Calibrate voicekey"));
281 TTB_SensitivitySlider,
282 YO(
"Adjust Sensitivity"),
284 wxSize(SliderWidth,25),
293 YO(
"Sign Changes (Low Threshold)"),
294 YO(
"Sign Changes (High Threshold)"),
295 YO(
"Direction Changes (Low Threshold)"),
296 YO(
"Direction Changes (High Threshold)")
299 mKeyTypeChoice =
safenew wxChoice(
this, TTB_KeyType,
302 transform_container<wxArrayStringEx>( choices,
304 mKeyTypeChoice->SetName(YO(
"Key type").Translation());
305 mKeyTypeChoice->SetSelection(0);
306 Add( mKeyTypeChoice, 0, wxALIGN_CENTER );
320 bool canStopAudioStream = (!gAudioIO->IsStreamActive() ||
321 gAudioIO->IsMonitoring() ||
322 gAudioIO->GetOwningProject().get() == p );
323 bool recording = gAudioIO->GetNumCaptureChannels() > 0;
329#ifdef EXPERIMENTAL_VOICE_DETECTION
334 auto selection = !selectedRegion.
isPoint() &&
357 static const struct Entry {
365 wxT(
"PlayAtSpeedLooped"),
XO(
"Play-at-Speed"),
366 wxT(
"PlayAtSpeed"),
XO(
"Play-at-Speed Once"),
370 for (
const auto &
entry : table) {
372 {
entry.commandName,
entry.untranslatedLabel },
373 {
entry.commandName2,
entry.untranslatedLabel2 },
379#ifdef EXPERIMENTAL_VOICE_DETECTION
391 mKeyTypeChoice->SetToolTip(YO(
"Key type").Translation());
402 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
403 int keyCode = kevent->GetKeyCode();
407 || keyCode == WXK_UP || keyCode == WXK_DOWN
408 || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
420 if (event.ControlDown()) {
425 if (event.GetKeyCode() == WXK_SPACE) {
427 if (gAudioIO->IsBusy()) {
464 double start = selectedRegion.
t0();
465 double end = selectedRegion.t1();
470 if (start < t->GetStartTime()) {
476 if (ss1 >= t->GetNumSamples()) {
477 ss1 = t->GetNumSamples();
491#define TIMETRACK_MIN 0.01
492#define TIMETRACK_MAX 10.0
510 bFixedSpeedPlay =
true;
515 bFixedSpeedPlay = bFixedSpeedPlay || cutPreview;
521 std::make_unique<BoundedEnvelope>(
538 if (gAudioIO->IsBusy())
539 projectAudioManager.Stop();
543 const auto &playRegion = viewInfo.playRegion;
546 if (playRegion.GetStart() < 0)
552 options.envelope = bFixedSpeedPlay ?
mEnvelope.get() :
nullptr;
553 options.variableSpeed = !bFixedSpeedPlay;
558 projectAudioManager.PlayPlayRegion(
572 const bool looped = !cutPreview &&
573 !button->WasShiftDown();
592#ifdef EXPERIMENTAL_VOICE_DETECTION
593void TranscriptionToolBar::OnStartOn(wxCommandEvent & WXUNUSED(event))
597 if (gAudioIO->IsBusy()){
602 mVk->AdjustThreshold(GetSensitivity());
606 auto wt =
static_cast<const WaveTrack*
>(t);
614 auto newstart = mVk->OnForward(*wt, start, len);
615 double newpos = newstart.as_double() / wt->GetRate();
618 selectedRegion.
setT0( newpos );
625void TranscriptionToolBar::OnStartOff(wxCommandEvent & WXUNUSED(event))
629 if (gAudioIO->IsBusy()){
633 mVk->AdjustThreshold(GetSensitivity());
639 auto wt =
static_cast<const WaveTrack*
>(t);
647 auto newstart = mVk->OffForward(*wt, start, len);
648 double newpos = newstart.as_double() / wt->GetRate();
651 selectedRegion.
setT0( newpos );
658void TranscriptionToolBar::OnEndOn(wxCommandEvent & WXUNUSED(event))
663 if (gAudioIO->IsBusy()){
668 mVk->AdjustThreshold(GetSensitivity());
672 auto wt =
static_cast<const WaveTrack*
>(t);
682 auto newEnd = mVk->OnBackward(*wt, start + len, len);
683 double newpos = newEnd.
as_double() / wt->GetRate();
686 selectedRegion.
setT1( newpos );
695void TranscriptionToolBar::OnEndOff(wxCommandEvent & WXUNUSED(event))
700 if (gAudioIO->IsBusy()){
704 mVk->AdjustThreshold(GetSensitivity());
709 auto wt =
static_cast<const WaveTrack*
>(t);
718 auto newEnd = mVk->OffBackward(*wt, start + len, len);
719 double newpos = newEnd.
as_double() / wt->GetRate();
722 selectedRegion.
setT1( newpos );
731void TranscriptionToolBar::OnSelectSound(wxCommandEvent & WXUNUSED(event))
736 if (gAudioIO->IsBusy()){
742 mVk->AdjustThreshold(GetSensitivity());
754 double rate = wt->GetRate();
755 auto newstart = mVk->OffBackward(*wt, start, start);
757 mVk->OffForward(*wt, start + len, (
int)(tl->
GetEndTime() * rate));
762 newstart.as_double() / rate, newend.as_double() / rate );
770void TranscriptionToolBar::OnSelectSilence(wxCommandEvent & WXUNUSED(event))
775 if (gAudioIO->IsBusy()) {
780 mVk->AdjustThreshold(GetSensitivity());
791 double rate = wt->GetRate();
792 auto newstart = mVk->OnBackward(*wt, start, start);
794 mVk->OnForward(*wt, start + len, (
int)(tl->
GetEndTime() * rate));
799 newstart.as_double() / rate, newend.as_double() / rate);
810void TranscriptionToolBar::OnCalibrate(wxCommandEvent & WXUNUSED(event))
814 if (gAudioIO->IsBusy()){
825 mVk->CalibrateNoise(*wt, start, len);
826 mVk->AdjustThreshold(3);
846 wxCommandEvent dummy;
847 OnSensitivitySlider(dummy);
851#include "../LabelTrack.h"
853#include "../TrackPanel.h"
854#include "../TrackPanelAx.h"
855#include "../tracks/labeltrack/ui/LabelTrackView.h"
868 const auto pFocusedTrack = trackFocus.Get();
871 auto iter = pFocusedTrack
872 ?
tracks.Find(pFocusedTrack)
878 lt =
tracks.Add( std::make_shared<LabelTrack>() );
886 lt->SetSelected(
true);
896 trackPanel.SetFocus();
905void TranscriptionToolBar::OnAutomateSelection(wxCommandEvent & WXUNUSED(event))
911 if (gAudioIO->IsBusy())
919 mVk->AdjustThreshold(GetSensitivity());
932 double newStartPos, newEndPos;
935 int minWordSize = (int)(wt->GetRate() * .05);
939 while(len > 0 && lastlen != len)
944 auto newStart = mVk->OnForward(*wt, start, len);
951 len -= (newStart - start);
962 mVk->OffForward(*wt, newStart + minWordSize, len);
966 if(newEnd == (newStart + minWordSize))
971 len -= (newEnd - newStart);
974 newStartPos = newStart.
as_double() / wt->GetRate();
975 newEndPos = newEnd.as_double() / wt->GetRate();
988void TranscriptionToolBar::OnMakeLabel(wxCommandEvent & WXUNUSED(event))
995double TranscriptionToolBar::GetSensitivity()
997 return (
double)mSensitivity;
1000void TranscriptionToolBar::OnSensitivitySlider(wxCommandEvent & WXUNUSED(event))
1005void TranscriptionToolBar::SetKeyType(wxCommandEvent & WXUNUSED(event))
1007 int value = mKeyTypeChoice->GetSelection();
1013 mVk->SetKeyType(
true,0,0,0,0);
1016 mVk->SetKeyType(0,
true,0,0,0);
1019 mVk->SetKeyType(0,0,
true,0,0);
1022 mVk->SetKeyType(0,0,0,
true,0);
1025 mVk->SetKeyType(0,0,0,0,
true);
1080 wxT(
"ShowTranscriptionTB"),
XXO(
"Pla&y-at-Speed Toolbar")
1086#include "../CommonCommandFlags.h"
1095 tb->PlayAtSpeed(
false,
false);
1105 tb->PlayAtSpeed(
true,
false);
1115 tb->PlayAtSpeed(
false,
true);
1125 tb->ShowPlaySpeedDialog();
1135 tb->AdjustPlaySpeed(0.1f);
1145 tb->AdjustPlaySpeed(-0.1f);
1154 Menu(
wxT(
"PlayAtSpeed"),
XXO(
"&Play-at-Speed") ) };
1159 wxT(
"Optional/Extra/Part1"),
1172 Command(
wxT(
"PlayAtSpeedCutPreview"),
XXO(
"Play C&ut Preview-at-Speed"),
1174 Command(
wxT(
"SetPlaySpeed"),
XXO(
"Ad&just Playback Speed..."),
1176 Command(
wxT(
"PlaySpeedInc"),
XXO(
"&Increase Playback Speed"),
1178 Command(
wxT(
"PlaySpeedDec"),
XXO(
"&Decrease Playback Speed"),
wxEVT_COMMAND_BUTTON_CLICKED
AttachedItem sAttachment3
AttachedItem sAttachment2
const ReservedCommandFlag & CaptureNotBusyFlag()
XXO("&Cut/Copy/Paste Toolbar")
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
audacity::BasicSettings * gPrefs
std::vector< TranslatableString > TranslatableStrings
ASlider is a custom slider, allowing for a slicker look and feel.
bool ShowDialog(wxPoint pos=wxPoint(-1, -1))
void Increase(float steps)
void Decrease(float steps)
float Get(bool convert=true)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
static AudioIOBase * Get()
Track subclass holding data representing sound (as notes, or samples, or ...)
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
An explicitly nonlocalized string, not meant for the user to see.
A LabelTrack is a Track that holds labels (LabelStruct).
static LabelTrackView & Get(LabelTrack &)
int AddLabel(const SelectedRegion ®ion, const wxString &title={}, int restoreFocus=-1)
A Track that is used for Midi notes. (Somewhat old code).
bool setTimes(double t0, double t1)
bool setT1(double t, bool maySwap=true)
bool setT0(double t, bool maySwap=true)
void SetPlaySpeed(double value)
static AudioIOStartStreamOptions GetDefaultOptions(AudacityProject &project, bool newDefaults=false)
Invoke the global hook, supplying a default argument.
static ProjectAudioIO & Get(AudacityProject &project)
static ProjectAudioManager & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
static ProjectWindow & Get(AudacityProject &project)
Defines a selected portion of a project.
wxColour & Colour(int iIndex)
wxSize ImageSize(int iIndex)
void EnsureVisible(bool modifyState=false)
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
double GetEndTime() const
Return the greatest end time of the tracks, or 0 when no tracks.
auto Any() -> TrackIterRange< TrackType >
static TrackList & Get(AudacityProject &project)
auto Selected() -> TrackIterRange< TrackType >
static TrackPanel & Get(AudacityProject &project)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
A Track that contains audio waveform data.
double GetStartTime() const override
Implement WideSampleSequence.
double GetRate() const override
bool ReadBool(const wxString &key, bool defaultValue) const
Positions or offsets within audio files need a wide type.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
bool Begin(const FilePath &dataDir)
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...
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