35#include "../AudioIO.h"
37#include "../KeyboardCapture.h"
40#include "../ProjectAudioIO.h"
41#include "../ProjectAudioManager.h"
44#include "../WaveTrack.h"
45#include "../widgets/AButton.h"
46#include "../widgets/ASlider.h"
47#include "../tracks/ui/Scrubbing.h"
50#ifdef EXPERIMENTAL_VOICE_DETECTION
51#include "../VoiceKey.h"
52#include "../ProjectWindow.h"
70#ifdef EXPERIMENTAL_VOICE_DETECTION
89 EVT_SLIDER(TTB_SensitivitySlider, TranscriptionToolBar::OnSensitivitySlider)
91 EVT_CHOICE(TTB_KeyType, TranscriptionToolBar::SetKeyType)
102#ifdef EXPERIMENTAL_VOICE_DETECTION
103 mVk = std::make_unique<VoiceKey>();
129#ifdef EXPERIMENTAL_VOICE_DETECTION
152 wxSizeEvent event(GetSize(), GetId());
153 event.SetEventObject(
this);
154 GetEventHandler()->ProcessEvent(event);
175 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall,bmpRecoloredHiliteSmall,
176 eFore, eFore, eDisabled,
186 pBar->
Add( r, 0, wxALIGN_CENTER );
193 int id,
unsigned altIdx)
196 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall,bmpRecoloredHiliteSmall,
197 eFore, eFore, eDisabled,
209 XO(
"Play at selected speed"));
216 const int SliderWidth=100;
219 XO(
"Playback Speed"),
221 wxSize(SliderWidth,25),
239#ifdef EXPERIMENTAL_VOICE_DETECTION
242#define YO( x ) Verbatim( x )
243 AddButton(
this, bmpTnStartOn, bmpTnStartOnDisabled, TTB_StartOn,
244 YO(
"Adjust left selection to next onset"));
245 AddButton(
this, bmpTnEndOn, bmpTnEndOnDisabled, TTB_EndOn,
246 YO(
"Adjust right selection to previous offset"));
247 AddButton(
this, bmpTnStartOff, bmpTnStartOffDisabled, TTB_StartOff,
248 YO(
"Adjust left selection to next offset"));
249 AddButton(
this, bmpTnEndOff, bmpTnEndOffDisabled, TTB_EndOff,
250 YO(
"Adjust right selection to previous onset"));
251 AddButton(
this, bmpTnSelectSound, bmpTnSelectSoundDisabled, TTB_SelectSound,
252 YO(
"Select region of sound around cursor"));
253 AddButton(
this, bmpTnSelectSilence, bmpTnSelectSilenceDisabled, TTB_SelectSilence,
254 YO(
"Select region of silence around cursor"));
255 AddButton(
this, bmpTnAutomateSelection, bmpTnAutomateSelectionDisabled, TTB_AutomateSelection,
256 YO(
"Automatically make labels from words"));
257 AddButton(
this, bmpTnMakeTag, bmpTnMakeTagDisabled, TTB_MakeLabel,
258 YO(
"Add label at selection"));
259 AddButton(
this, bmpTnCalibrate, bmpTnCalibrateDisabled, TTB_Calibrate,
260 YO(
"Calibrate voicekey"));
263 TTB_SensitivitySlider,
264 YO(
"Adjust Sensitivity"),
266 wxSize(SliderWidth,25),
275 YO(
"Sign Changes (Low Threshold)"),
276 YO(
"Sign Changes (High Threshold)"),
277 YO(
"Direction Changes (Low Threshold)"),
278 YO(
"Direction Changes (High Threshold)")
281 mKeyTypeChoice =
safenew wxChoice(
this, TTB_KeyType,
284 transform_container<wxArrayStringEx>( choices,
286 mKeyTypeChoice->SetName(YO(
"Key type").Translation());
287 mKeyTypeChoice->SetSelection(0);
288 Add( mKeyTypeChoice, 0, wxALIGN_CENTER );
302 bool canStopAudioStream = (!gAudioIO->IsStreamActive() ||
303 gAudioIO->IsMonitoring() ||
304 gAudioIO->GetOwningProject().get() == p );
305 bool recording = gAudioIO->GetNumCaptureChannels() > 0;
309 SetEnabled( canStopAudioStream && tracks && !recording );
311#ifdef EXPERIMENTAL_VOICE_DETECTION
316 auto selection = !selectedRegion.
isPoint() &&
339 static const struct Entry {
347 wxT(
"PlayAtSpeedLooped"),
XO(
"Play-at-Speed"),
348 wxT(
"PlayAtSpeed"),
XO(
"Play-at-Speed Once"),
352 for (
const auto &
entry : table) {
354 {
entry.commandName,
entry.untranslatedLabel },
355 {
entry.commandName2,
entry.untranslatedLabel2 },
361#ifdef EXPERIMENTAL_VOICE_DETECTION
373 mKeyTypeChoice->SetToolTip(YO(
"Key type").Translation());
384 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
385 int keyCode = kevent->GetKeyCode();
388 if (FindFocus() ==
mPlaySpeedSlider && (keyCode == WXK_LEFT || keyCode == WXK_RIGHT
389 || keyCode == WXK_UP || keyCode == WXK_DOWN
390 || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
402 if (event.ControlDown()) {
407 if (event.GetKeyCode() == WXK_SPACE) {
409 if (gAudioIO->IsBusy()) {
446 double start = selectedRegion.
t0();
447 double end = selectedRegion.t1();
452 if (start < t->GetOffset()) {
458 if (ss1 >= t->GetNumSamples()) {
459 ss1 = t->GetNumSamples();
473#define TIMETRACK_MIN 0.01
474#define TIMETRACK_MAX 10.0
489 bool bFixedSpeedPlay = !
gPrefs->ReadBool(wxT(
"/AudioIO/VariSpeedPlay"),
true);
492 bFixedSpeedPlay =
true;
497 bFixedSpeedPlay = bFixedSpeedPlay || cutPreview;
503 std::make_unique<BoundedEnvelope>(
520 if (gAudioIO->IsBusy())
521 projectAudioManager.Stop();
525 const auto &playRegion = viewInfo.playRegion;
528 if (playRegion.GetStart() < 0)
534 options.envelope = bFixedSpeedPlay ?
mEnvelope.get() :
nullptr;
535 options.variableSpeed = !bFixedSpeedPlay;
540 projectAudioManager.PlayPlayRegion(
554 const bool looped = !cutPreview &&
555 !button->WasShiftDown();
574#ifdef EXPERIMENTAL_VOICE_DETECTION
575void TranscriptionToolBar::OnStartOn(wxCommandEvent & WXUNUSED(event))
579 if (gAudioIO->IsBusy()){
584 mVk->AdjustThreshold(GetSensitivity());
588 auto wt =
static_cast<const WaveTrack*
>(t);
596 auto newstart = mVk->OnForward(*wt, start, len);
597 double newpos = newstart.as_double() / wt->GetRate();
600 selectedRegion.
setT0( newpos );
607void TranscriptionToolBar::OnStartOff(wxCommandEvent & WXUNUSED(event))
611 if (gAudioIO->IsBusy()){
615 mVk->AdjustThreshold(GetSensitivity());
621 auto wt =
static_cast<const WaveTrack*
>(t);
629 auto newstart = mVk->OffForward(*wt, start, len);
630 double newpos = newstart.as_double() / wt->GetRate();
633 selectedRegion.
setT0( newpos );
640void TranscriptionToolBar::OnEndOn(wxCommandEvent & WXUNUSED(event))
645 if (gAudioIO->IsBusy()){
650 mVk->AdjustThreshold(GetSensitivity());
654 auto wt =
static_cast<const WaveTrack*
>(t);
664 auto newEnd = mVk->OnBackward(*wt, start + len, len);
665 double newpos = newEnd.
as_double() / wt->GetRate();
668 selectedRegion.
setT1( newpos );
677void TranscriptionToolBar::OnEndOff(wxCommandEvent & WXUNUSED(event))
682 if (gAudioIO->IsBusy()){
686 mVk->AdjustThreshold(GetSensitivity());
691 auto wt =
static_cast<const WaveTrack*
>(t);
700 auto newEnd = mVk->OffBackward(*wt, start + len, len);
701 double newpos = newEnd.
as_double() / wt->GetRate();
704 selectedRegion.
setT1( newpos );
713void TranscriptionToolBar::OnSelectSound(wxCommandEvent & WXUNUSED(event))
718 if (gAudioIO->IsBusy()){
724 mVk->AdjustThreshold(GetSensitivity());
736 double rate = wt->GetRate();
737 auto newstart = mVk->OffBackward(*wt, start, start);
739 mVk->OffForward(*wt, start + len, (
int)(tl->
GetEndTime() * rate));
744 newstart.as_double() / rate, newend.as_double() / rate );
752void TranscriptionToolBar::OnSelectSilence(wxCommandEvent & WXUNUSED(event))
757 if (gAudioIO->IsBusy()){
762 mVk->AdjustThreshold(GetSensitivity());
773 double rate = wt->GetRate();
774 auto newstart = mVk->OnBackward(*wt, start, start);
776 mVk->OnForward(*wt, start + len, (
int)(tl->
GetEndTime() * rate));
781 newstart.as_double() / rate, newend.as_double() / rate);
792void TranscriptionToolBar::OnCalibrate(wxCommandEvent & WXUNUSED(event))
796 if (gAudioIO->IsBusy()){
807 mVk->CalibrateNoise(*wt, start, len);
808 mVk->AdjustThreshold(3);
828 wxCommandEvent dummy;
829 OnSensitivitySlider(dummy);
833#include "../LabelTrack.h"
835#include "../TrackPanel.h"
836#include "../TrackPanelAx.h"
837#include "../tracks/labeltrack/ui/LabelTrackView.h"
850 const auto pFocusedTrack = trackFocus.Get();
853 auto iter = pFocusedTrack
854 ? tracks.Find(pFocusedTrack)
855 : tracks.Any().begin();
860 lt = tracks.Add( std::make_shared<LabelTrack>() );
871 int focusTrackNumber = -1;
881 trackPanel.SetFocus();
890void TranscriptionToolBar::OnAutomateSelection(wxCommandEvent & WXUNUSED(event))
896 if (gAudioIO->IsBusy())
904 mVk->AdjustThreshold(GetSensitivity());
917 double newStartPos, newEndPos;
920 int minWordSize = (int)(wt->GetRate() * .05);
924 while(len > 0 && lastlen != len)
929 auto newStart = mVk->OnForward(*wt, start, len);
936 len -= (newStart - start);
947 mVk->OffForward(*wt, newStart + minWordSize, len);
951 if(newEnd == (newStart + minWordSize))
956 len -= (newEnd - newStart);
959 newStartPos = newStart.
as_double() / wt->GetRate();
960 newEndPos = newEnd.as_double() / wt->GetRate();
973void TranscriptionToolBar::OnMakeLabel(wxCommandEvent & WXUNUSED(event))
980double TranscriptionToolBar::GetSensitivity()
982 return (
double)mSensitivity;
985void TranscriptionToolBar::OnSensitivitySlider(wxCommandEvent & WXUNUSED(event))
990void TranscriptionToolBar::SetKeyType(wxCommandEvent & WXUNUSED(event))
992 int value = mKeyTypeChoice->GetSelection();
998 mVk->SetKeyType(
true,0,0,0,0);
1001 mVk->SetKeyType(0,
true,0,0,0);
1004 mVk->SetKeyType(0,0,
true,0,0);
1007 mVk->SetKeyType(0,0,0,
true,0);
1010 mVk->SetKeyType(0,0,0,0,
true);
wxEVT_COMMAND_BUTTON_CLICKED
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
AudioIOStartStreamOptions DefaultPlayOptions(AudacityProject &project, bool newDefault)
static ProjectFileIORegistry::AttributeWriterEntry entry
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 ...)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A LabelTrack is a Track that holds labels (LabelStruct).
void SetSelected(bool s) override
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 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)
void RedrawProject(const bool bForceWaveTracks=false)
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
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 GetOffset() const override
double GetRate() const override
Positions or offsets within audio files need a wide type.
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, if Traits<Type>::iterated_type is defined.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for, if Traits<Type>::iterated_type is defined.