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"
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>();
141#ifdef EXPERIMENTAL_VOICE_DETECTION
164 wxSizeEvent event(GetSize(), GetId());
165 event.SetEventObject(
this);
166 GetEventHandler()->ProcessEvent(event);
187 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall,bmpRecoloredHiliteSmall,
188 eFore, eFore, eDisabled,
198 pBar->
Add( r, 0, wxALIGN_CENTER );
205 int id,
unsigned altIdx)
208 bmpRecoloredUpSmall, bmpRecoloredDownSmall, bmpRecoloredUpHiliteSmall,bmpRecoloredHiliteSmall,
209 eFore, eFore, eDisabled,
221 XO(
"Play at selected speed"));
228 const int SliderWidth=100;
231 XO(
"Playback Speed"),
233 wxSize(SliderWidth,25),
251#ifdef EXPERIMENTAL_VOICE_DETECTION
254#define YO( x ) Verbatim( x )
255 AddButton(
this, bmpTnStartOn, bmpTnStartOnDisabled, TTB_StartOn,
256 YO(
"Adjust left selection to next onset"));
257 AddButton(
this, bmpTnEndOn, bmpTnEndOnDisabled, TTB_EndOn,
258 YO(
"Adjust right selection to previous offset"));
259 AddButton(
this, bmpTnStartOff, bmpTnStartOffDisabled, TTB_StartOff,
260 YO(
"Adjust left selection to next offset"));
261 AddButton(
this, bmpTnEndOff, bmpTnEndOffDisabled, TTB_EndOff,
262 YO(
"Adjust right selection to previous onset"));
263 AddButton(
this, bmpTnSelectSound, bmpTnSelectSoundDisabled, TTB_SelectSound,
264 YO(
"Select region of sound around cursor"));
265 AddButton(
this, bmpTnSelectSilence, bmpTnSelectSilenceDisabled, TTB_SelectSilence,
266 YO(
"Select region of silence around cursor"));
267 AddButton(
this, bmpTnAutomateSelection, bmpTnAutomateSelectionDisabled, TTB_AutomateSelection,
268 YO(
"Automatically make labels from words"));
269 AddButton(
this, bmpTnMakeTag, bmpTnMakeTagDisabled, TTB_MakeLabel,
270 YO(
"Add label at selection"));
271 AddButton(
this, bmpTnCalibrate, bmpTnCalibrateDisabled, TTB_Calibrate,
272 YO(
"Calibrate voicekey"));
275 TTB_SensitivitySlider,
276 YO(
"Adjust Sensitivity"),
278 wxSize(SliderWidth,25),
287 YO(
"Sign Changes (Low Threshold)"),
288 YO(
"Sign Changes (High Threshold)"),
289 YO(
"Direction Changes (Low Threshold)"),
290 YO(
"Direction Changes (High Threshold)")
293 mKeyTypeChoice =
safenew wxChoice(
this, TTB_KeyType,
296 transform_container<wxArrayStringEx>( choices,
298 mKeyTypeChoice->SetName(YO(
"Key type").Translation());
299 mKeyTypeChoice->SetSelection(0);
300 Add( mKeyTypeChoice, 0, wxALIGN_CENTER );
314 bool canStopAudioStream = (!gAudioIO->IsStreamActive() ||
315 gAudioIO->IsMonitoring() ||
316 gAudioIO->GetOwningProject().get() == p );
317 bool recording = gAudioIO->GetNumCaptureChannels() > 0;
323#ifdef EXPERIMENTAL_VOICE_DETECTION
328 auto selection = !selectedRegion.
isPoint() &&
351 static const struct Entry {
359 wxT(
"PlayAtSpeedLooped"),
XO(
"Play-at-Speed"),
360 wxT(
"PlayAtSpeed"),
XO(
"Play-at-Speed Once"),
364 for (
const auto &
entry : table) {
366 {
entry.commandName,
entry.untranslatedLabel },
367 {
entry.commandName2,
entry.untranslatedLabel2 },
373#ifdef EXPERIMENTAL_VOICE_DETECTION
385 mKeyTypeChoice->SetToolTip(YO(
"Key type").Translation());
396 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
397 int keyCode = kevent->GetKeyCode();
401 || keyCode == WXK_UP || keyCode == WXK_DOWN
402 || keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN)) {
414 if (event.ControlDown()) {
419 if (event.GetKeyCode() == WXK_SPACE) {
421 if (gAudioIO->IsBusy()) {
458 double start = selectedRegion.
t0();
459 double end = selectedRegion.t1();
464 if (start < t->GetStartTime()) {
470 if (ss1 >= t->GetNumSamples()) {
471 ss1 = t->GetNumSamples();
485#define TIMETRACK_MIN 0.01
486#define TIMETRACK_MAX 10.0
504 bFixedSpeedPlay =
true;
509 bFixedSpeedPlay = bFixedSpeedPlay || cutPreview;
515 std::make_unique<BoundedEnvelope>(
532 if (gAudioIO->IsBusy())
533 projectAudioManager.Stop();
537 const auto &playRegion = viewInfo.playRegion;
540 if (playRegion.GetStart() < 0)
546 options.envelope = bFixedSpeedPlay ?
mEnvelope.get() :
nullptr;
547 options.variableSpeed = !bFixedSpeedPlay;
552 projectAudioManager.PlayPlayRegion(
566 const bool looped = !cutPreview &&
567 !button->WasShiftDown();
586#ifdef EXPERIMENTAL_VOICE_DETECTION
587void TranscriptionToolBar::OnStartOn(wxCommandEvent & WXUNUSED(event))
591 if (gAudioIO->IsBusy()){
596 mVk->AdjustThreshold(GetSensitivity());
600 auto wt =
static_cast<const WaveTrack*
>(t);
608 auto newstart = mVk->OnForward(*wt, start, len);
609 double newpos = newstart.as_double() / wt->GetRate();
612 selectedRegion.
setT0( newpos );
619void TranscriptionToolBar::OnStartOff(wxCommandEvent & WXUNUSED(event))
623 if (gAudioIO->IsBusy()){
627 mVk->AdjustThreshold(GetSensitivity());
633 auto wt =
static_cast<const WaveTrack*
>(t);
641 auto newstart = mVk->OffForward(*wt, start, len);
642 double newpos = newstart.as_double() / wt->GetRate();
645 selectedRegion.
setT0( newpos );
652void TranscriptionToolBar::OnEndOn(wxCommandEvent & WXUNUSED(event))
657 if (gAudioIO->IsBusy()){
662 mVk->AdjustThreshold(GetSensitivity());
666 auto wt =
static_cast<const WaveTrack*
>(t);
676 auto newEnd = mVk->OnBackward(*wt, start + len, len);
677 double newpos = newEnd.
as_double() / wt->GetRate();
680 selectedRegion.
setT1( newpos );
689void TranscriptionToolBar::OnEndOff(wxCommandEvent & WXUNUSED(event))
694 if (gAudioIO->IsBusy()){
698 mVk->AdjustThreshold(GetSensitivity());
703 auto wt =
static_cast<const WaveTrack*
>(t);
712 auto newEnd = mVk->OffBackward(*wt, start + len, len);
713 double newpos = newEnd.
as_double() / wt->GetRate();
716 selectedRegion.
setT1( newpos );
725void TranscriptionToolBar::OnSelectSound(wxCommandEvent & WXUNUSED(event))
730 if (gAudioIO->IsBusy()){
736 mVk->AdjustThreshold(GetSensitivity());
748 double rate = wt->GetRate();
749 auto newstart = mVk->OffBackward(*wt, start, start);
751 mVk->OffForward(*wt, start + len, (
int)(tl->
GetEndTime() * rate));
756 newstart.as_double() / rate, newend.as_double() / rate );
764void TranscriptionToolBar::OnSelectSilence(wxCommandEvent & WXUNUSED(event))
769 if (gAudioIO->IsBusy()) {
774 mVk->AdjustThreshold(GetSensitivity());
785 double rate = wt->GetRate();
786 auto newstart = mVk->OnBackward(*wt, start, start);
788 mVk->OnForward(*wt, start + len, (
int)(tl->
GetEndTime() * rate));
793 newstart.as_double() / rate, newend.as_double() / rate);
804void TranscriptionToolBar::OnCalibrate(wxCommandEvent & WXUNUSED(event))
808 if (gAudioIO->IsBusy()){
819 mVk->CalibrateNoise(*wt, start, len);
820 mVk->AdjustThreshold(3);
840 wxCommandEvent dummy;
841 OnSensitivitySlider(dummy);
847#include "../TrackPanel.h"
849#include "../tracks/labeltrack/ui/LabelTrackView.h"
862 const auto pFocusedTrack = trackFocus.Get();
865 auto iter = pFocusedTrack
866 ?
tracks.Find(pFocusedTrack)
872 lt =
tracks.Add( std::make_shared<LabelTrack>() );
880 lt->SetSelected(
true);
890 trackPanel.SetFocus();
899void TranscriptionToolBar::OnAutomateSelection(wxCommandEvent & WXUNUSED(event))
905 if (gAudioIO->IsBusy())
913 mVk->AdjustThreshold(GetSensitivity());
926 double newStartPos, newEndPos;
929 int minWordSize = (int)(wt->GetRate() * .05);
933 while(len > 0 && lastlen != len)
938 auto newStart = mVk->OnForward(*wt, start, len);
945 len -= (newStart - start);
956 mVk->OffForward(*wt, newStart + minWordSize, len);
960 if(newEnd == (newStart + minWordSize))
965 len -= (newEnd - newStart);
968 newStartPos = newStart.
as_double() / wt->GetRate();
969 newEndPos = newEnd.as_double() / wt->GetRate();
982void TranscriptionToolBar::OnMakeLabel(wxCommandEvent & WXUNUSED(event))
989double TranscriptionToolBar::GetSensitivity()
991 return (
double)mSensitivity;
994void TranscriptionToolBar::OnSensitivitySlider(wxCommandEvent & WXUNUSED(event))
999void TranscriptionToolBar::SetKeyType(wxCommandEvent & WXUNUSED(event))
1001 int value = mKeyTypeChoice->GetSelection();
1007 mVk->SetKeyType(
true,0,0,0,0);
1010 mVk->SetKeyType(0,
true,0,0,0);
1013 mVk->SetKeyType(0,0,
true,0,0);
1016 mVk->SetKeyType(0,0,0,
true,0);
1019 mVk->SetKeyType(0,0,0,0,
true);
1074 wxT(
"ShowTranscriptionTB"),
XXO(
"Pla&y-at-Speed Toolbar")
1080#include "../CommonCommandFlags.h"
1089 tb->PlayAtSpeed(
false,
false);
1099 tb->PlayAtSpeed(
true,
false);
1109 tb->PlayAtSpeed(
false,
true);
1119 tb->ShowPlaySpeedDialog();
1129 tb->AdjustPlaySpeed(0.1f);
1139 tb->AdjustPlaySpeed(-0.1f);
1147 static auto menu = std::shared_ptr{
1148 Menu(
wxT(
"PlayAtSpeed"),
XXO(
"&Play-at-Speed") ) };
1153 wxT(
"Optional/Extra/Part1")
1158 static auto items = std::shared_ptr{
1165 Command(
wxT(
"PlayAtSpeedCutPreview"),
XXO(
"Play C&ut Preview-at-Speed"),
1167 Command(
wxT(
"SetPlaySpeed"),
XXO(
"Ad&just Playback Speed..."),
1169 Command(
wxT(
"PlaySpeedInc"),
XXO(
"&Increase Playback Speed"),
1171 Command(
wxT(
"PlaySpeedDec"),
XXO(
"&Decrease Playback Speed"),
wxEVT_COMMAND_BUTTON_CLICKED
AttachedItem sAttachment3
AttachedItem sAttachment2
const ReservedCommandFlag & CaptureNotBusyFlag()
XXO("&Cut/Copy/Paste Toolbar")
static ProjectFileIORegistry::AttributeWriterEntry entry
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)
Generates classes whose instances register items at construction.
Defines a selected portion of a project.
wxColour & Colour(int iIndex)
wxSize ImageSize(int iIndex)
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)
static Viewport & 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...
std::unique_ptr< detail::IndirectItem< Item > > Indirect(const std::shared_ptr< Item > &ptr)
A convenience function.
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept