16#ifdef EXPERIMENTAL_BRUSH_TOOL
23#include <wx/checkbox.h>
27#include <wx/imaglist.h>
29#include <wx/listctrl.h>
30#include <wx/settings.h>
31#include <wx/spinctrl.h>
32#include <wx/statline.h>
33#include <wx/stattext.h>
34#include <wx/textctrl.h>
37#include "../images/Arrow.xpm"
38#include "../images/Empty9x16.xpm"
68 ID_BRUSH_BUTTON = 10000,
72 ID_CHECKBOX_OVERTONES,
100 void DoUpdateDisplay();
101 void UpdateControls(
bool active );
103 bool Show(
bool show =
true )
override;
112 void OnApply(wxCommandEvent &event);
113 void OnBrushButton(wxCommandEvent &event);
114 void OnBrushSizeSlider(wxCommandEvent &event);
115 void OnCheckSmartSelection(wxCommandEvent &event);
116 void OnCheckOvertones(wxCommandEvent &event);
119 void UpdatePrefs()
override;
123 , mClipboardSubscription
126 wxToggleButton *mBrushButton =
nullptr;
127 bool mAudioIOBusy {
false };
130 void DoToolChanged();
132 DECLARE_EVENT_TABLE()
135class AUDACITY_DLL_API SpectralDataDialogWorker final
139 ~SpectralDataDialogWorker();
142 void OnIdle(wxIdleEvent &evt);
146 unsigned mPrevNViews = 0;
150 EVT_TOGGLEBUTTON(ID_BRUSH_BUTTON, SpectralDataDialog::OnBrushButton)
151 #ifdef SMART_CHECKBOX
152 EVT_CHECKBOX(ID_CHECKBOX_SMART, SpectralDataDialog::OnCheckSmartSelection)
154 EVT_CHECKBOX(ID_CHECKBOX_OVERTONES, SpectralDataDialog::OnCheckOvertones)
156 EVT_SLIDER(ID_SLIDER_BRUSH_SIZE, SpectralDataDialog::OnBrushSizeSlider)
159#define Title XO("Spectral Data Control Panel")
164 wxDefaultPosition, wxDefaultSize,
165 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
176 ->
Subscribe(*
this, &SpectralDataDialog::OnAudioIO);
179 .
Subscribe(*
this, &::SpectralDataDialog::UpdateDisplayForClipboard);
182 .
Subscribe(*
this, &SpectralDataDialog::UpdateDisplay);
187static const AttachedWindows::RegisteredFactory
key{
193static wxToggleButton *MakeButton(wxWindow *pParent)
195 auto button =
safenew wxBitmapToggleButton{
198 button->SetName(
XO(
"Brush Tool").Translation());
204 mBrushButton = MakeButton(
this);
206 S.StartVerticalLay(
true);
209 S.AddVariableText(
XO(
"Spectral Brush"));
210 S.AddWindow(mBrushButton, wxALIGN_LEFT);
212 S.AddVariableText(
XO(
"Brush radius"));
213 S.Id(ID_SLIDER_BRUSH_SIZE)
214 .Style(wxSL_HORIZONTAL)
215 .Name(
XO(
"Custom brush size"))
216 .AddSlider( {}, 5, 10, 1);
218 S.AddWindow(
safenew wxStaticLine{
S.GetParent() });
220 S.Id(ID_CHECKBOX_OVERTONES)
222 XXO(
"Auto-select overtones (beta)"),
226 S.Id(ID_CHECKBOX_SMART)
227 .AddCheckBox(
XXO(
"Enable smart selection"),
false);
231 XO(
"Select the fundamental frequency\n"
232 "and release the mouse"));
239 SetMinSize(GetSize());
245 mAudioIOBusy = ev.
on;
255 switch (message.
type) {
268void SpectralDataDialog::DoUpdateDisplay()
274void SpectralDataDialog::UpdateControls(
bool active )
277 mBrushButton->SetValue(active);
287 if ( show && !IsShown())
289 if ( IsShown() && !show && IsBrushToolActive(mProject) )
296void SpectralDataDialog::DoUpdate()
306void SpectralDataDialog::UpdatePrefs()
308 bool shown = IsShown();
326void SpectralDataDialog::OnBrushButton(wxCommandEvent &event) {
327 if (mBrushButton->GetValue())
331 mBrushButton->SetValue(
true);
336 return std::make_shared< SpectralDataDialogWorker >(
project );
340AttachedWindows::RegisteredFactory sSpectralDataDialogKey{
370 .
Subscribe(*
this, &SpectralDataDialogWorker::OnToolChanged);
371 wxTheApp->Bind(wxEVT_IDLE, &SpectralDataDialogWorker::OnIdle,
this);
374SpectralDataDialogWorker::~SpectralDataDialogWorker()
376 wxTheApp->Unbind(wxEVT_IDLE, &SpectralDataDialogWorker::OnIdle,
this);
384 pDialog && pDialog->IsShown())
385 pDialog->DoToolChanged();
388 using Type = std::underlying_type_t<
decltype(ToolCodes::brushTool)>;
389 constexpr auto value =
static_cast<Type>(ToolCodes::brushTool);
392 if (projectSettings.GetTool() == value) {
394 if (oldValue + 1 == value)
396 wxTheApp->CallAfter([&]{ projectSettings.SetTool(
401 wxTheApp->CallAfter([&]{ projectSettings.SetTool(
405 wxTheApp->CallAfter([&]{ projectSettings.SetTool(oldValue); });
411static bool HasVisibleSpectralView(
WaveTrack *wt)
415 const auto range = waveChannelViewPtr->GetSubViews();
416 return std::any_of( range.begin(), range.end(),
417 [](
const auto &pair){
418 return dynamic_cast<SpectrumView*>(pair.second.get()); } );
426 return std::count_if( range.begin(), range.end(), HasVisibleSpectralView );
429void SpectralDataDialogWorker::OnIdle(wxIdleEvent &evt)
432 auto nViews = CountVisibleSpectralViews(mProject);
433 if (nViews > mPrevNViews) {
440 else if (nViews == 0 && mPrevNViews > 0) {
446 mPrevNViews = nViews;
449void SpectralDataDialog::DoToolChanged()
451 UpdateControls( IsBrushToolActive(mProject) );
454void SpectralDataDialog::OnBrushSizeSlider(wxCommandEvent &event) {
456 projectSettings.SetBrushRadius(event.GetInt());
459void SpectralDataDialog::OnCheckSmartSelection(wxCommandEvent &event){
460 int isSelected =
event.GetInt();
461 wxASSERT(isSelected == 0 || isSelected == 1);
463 projectSettings.SetSmartSelection(isSelected);
466void SpectralDataDialog::OnCheckOvertones(wxCommandEvent &event){
467 int isSelected =
event.GetInt();
468 wxASSERT(isSelected == 0 || isSelected == 1);
470 projectSettings.SetOvertones(isSelected);
471#ifndef SMART_CHECKBOX
473 OnCheckSmartSelection(event);
482 dialog.Show( !dialog.IsShown() );
487 wxT(
"View/Other/Toolbars/Toolbars/Other"),
489 XXO(
"Spectra&l Selection Panel"),
490 OnSpectralEditingPanel,
496 return pDialog && pDialog->IsShown();
Utility ClientData::Site to register hooks into a host class that attach client data.
constexpr CommandFlag AlwaysEnabledFlag
XXO("&Cut/Copy/Paste Toolbar")
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
accessors for certain important windows associated with each project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
static ChannelView & Get(Channel &channel)
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Subclass * Find(const RegisteredFactory &key)
Get a (bare) pointer to an attachment, or null, down-cast it to Subclass *; will not create on demand...
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
static CommandManager & Get(AudacityProject &project)
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
A move-only handle representing a connection to a Publisher.
A listener notified of changes in preferences.
static ProjectSettings & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Provides UI for spectral editing and parameters adjustments.
wxBitmap & Bitmap(int iIndex)
auto Any() -> TrackIterRange< TrackType >
static TrackList & Get(AudacityProject &project)
Maintain a non-persistent list of states of the project, to support undo and redo commands.
static UndoManager & Get(AudacityProject &project)
A Track that contains audio waveform data.
auto GetChannel(size_t iChannel)
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)
void OnCloseWindow(wxCloseEvent &e)
enum AudioIOEvent::Type type
A convenient default parameter for class template Site.
Message is sent during idle time by the global clipboard.
enum ProjectSettingsEvent::Type type
Type of message published by UndoManager.
@ Purge
Undo or redo states eliminated.
enum UndoRedoMessage::Type type