Audacity  3.0.3
Public Member Functions | Private Attributes | List of all members
AudioUnitEffectImportDialog Class Referencefinal
Inheritance diagram for AudioUnitEffectImportDialog:
[legend]
Collaboration diagram for AudioUnitEffectImportDialog:
[legend]

Public Member Functions

 AudioUnitEffectImportDialog (wxWindow *parent, AudioUnitEffect *effect)
 
virtual ~AudioUnitEffectImportDialog ()
 
void PopulateOrExchange (ShuttleGui &S)
 
bool HasPresets ()
 
TranslatableString Import (const wxString &path, const wxString &name)
 
void OnOk (wxCommandEvent &evt)
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Attributes

wxWindow * mParent
 
AudioUnitEffectmEffect
 
wxListCtrl * mList
 

Detailed Description

Definition at line 633 of file AudioUnitEffect.cpp.

Constructor & Destructor Documentation

◆ AudioUnitEffectImportDialog()

AudioUnitEffectImportDialog::AudioUnitEffectImportDialog ( wxWindow *  parent,
AudioUnitEffect effect 
)

Definition at line 658 of file AudioUnitEffect.cpp.

659 : wxDialogWrapper(parent, wxID_ANY, XO("Import Audio Unit Presets"))
660 {
661  mEffect = effect;
662 
663  ShuttleGui S(this, eIsCreating);
665 }

References eIsCreating.

◆ ~AudioUnitEffectImportDialog()

AudioUnitEffectImportDialog::~AudioUnitEffectImportDialog ( )
virtual

Definition at line 667 of file AudioUnitEffect.cpp.

668 {
669 }

Member Function Documentation

◆ HasPresets()

bool AudioUnitEffectImportDialog::HasPresets ( )

Definition at line 741 of file AudioUnitEffect.cpp.

742 {
743  return mList->GetItemCount() > 0;
744 }

References mList.

◆ Import()

TranslatableString AudioUnitEffectImportDialog::Import ( const wxString &  path,
const wxString &  name 
)

Definition at line 746 of file AudioUnitEffect.cpp.

748 {
749  // Generate the path
750  wxString fullPath;
751  fullPath.Printf(wxT("%s/%s.aupreset"),
752  path,
753  name);
754 
755  // Open the preset
756  wxFFile f(fullPath, wxT("r"));
757  if (!f.IsOpened())
758  {
759  return XO("Couldn't open \"%s\"").Format(fullPath);
760  }
761 
762  // Load it into the buffer
763  size_t len = f.Length();
764  wxMemoryBuffer buf(len);
765  if (f.Read(buf.GetData(), len) != len || f.Error())
766  {
767  return XO("Unable to read the preset from \"%s\"").Format(fullPath);
768  }
769 
770  wxString parms = wxBase64Encode(buf.GetData(), len);
771  if (parms.IsEmpty())
772  {
773  return XO("Failed to encode preset from \"%s\"").Format(fullPath);
774  }
775 
776  // And write it to the config
777  wxString group = mEffect->mHost->GetUserPresetsGroup(name);
778  if (!mEffect->mHost->SetPrivateConfig(group, PRESET_KEY, parms))
779  {
780  return XO("Unable to store preset in config file");
781  }
782 
783  return {};
784 }

References EffectHostInterface::GetUserPresetsGroup(), mEffect, AudioUnitEffect::mHost, name, PRESET_KEY, ConfigClientInterface::SetPrivateConfig(), and XO.

Referenced by OnOk().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnOk()

void AudioUnitEffectImportDialog::OnOk ( wxCommandEvent &  evt)

Definition at line 786 of file AudioUnitEffect.cpp.

787 {
788  evt.Skip();
789 
790  // Import all selected presets
791  long sel = -1;
792  while ((sel = mList->GetNextItem(sel, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) >= 0)
793  {
794  wxListItem item;
795  item.SetId(sel);
796  item.SetColumn(1);
797  item.SetMask(wxLIST_MASK_TEXT);
798  mList->GetItem(item);
799 
800  wxString path = item.GetText();
801  wxString name = mList->GetItemText(sel);
802  auto msg = Import(path, name);
803 
804  if (!msg.empty())
805  {
807  XO("Could not import \"%s\" preset\n\n%s").Format(name, msg),
808  XO("Import Audio Unit Presets"),
809  wxOK | wxCENTRE,
810  this);
811  return;
812  }
813  }
814 
815  EndModal(wxID_OK);
816 }

References AudacityMessageBox(), Import(), mList, name, and XO.

Here is the call graph for this function:

◆ PopulateOrExchange()

void AudioUnitEffectImportDialog::PopulateOrExchange ( ShuttleGui S)

Definition at line 671 of file AudioUnitEffect.cpp.

672 {
673  S.SetBorder(5);
674  S.StartHorizontalLay(wxEXPAND, 1);
675  {
676  S.StartVerticalLay(true);
677  {
678  S.StartStatic(XO("Presets (may select multiple)"));
679  {
680  mList = S.Style(wxLC_REPORT | wxLC_HRULES | wxLC_VRULES |
681  wxLC_NO_SORT_HEADER)
682  .AddListControlReportMode({ XO("Preset"), XO("Location") });
683  }
684  S.EndStatic();
685  }
686  S.EndVerticalLay();
687  }
688  S.EndHorizontalLay();
689 
690  S.AddStandardButtons();
691 
692  FilePaths presets;
693  wxFileName fn;
694 
695  // Generate the local domain path
696  wxString path;
697  path.Printf(wxT("%s/%s/%s"),
699  mEffect->mVendor,
700  mEffect->mName);
701  fn = path;
702  fn.Normalize();
703 
704  // Get all presets in the local domain for this effect
705  wxDir::GetAllFiles(fn.GetFullPath(), &presets, wxT("*.aupreset"));
706 
707  // Generate the user domain path
708  path.Printf(wxT("%s/%s/%s"),
710  mEffect->mVendor,
711  mEffect->mName);
712  fn = path;
713  fn.Normalize();
714 
715  // Get all presets in the user domain for this effect
716  wxDir::GetAllFiles(fn.GetFullPath(), &presets, wxT("*.aupreset"));
717 
718  presets.Sort();
719 
720  for (size_t i = 0, cnt = presets.size(); i < cnt; i++)
721  {
722  fn = presets[i];
723  mList->InsertItem(i, fn.GetName());
724  mList->SetItem(i, 1, fn.GetPath());
725  }
726 
727  mList->SetColumnWidth(0, wxLIST_AUTOSIZE);
728  mList->SetColumnWidth(1, wxLIST_AUTOSIZE);
729 
730  // Set the list size...with a little extra for good measure
731  wxSize sz = mList->GetBestSize();
732  sz.x += 5;
733  sz.y += 5;
734  mList->SetMinSize(sz);
735 
736  Layout();
737  Fit();
738  Center();
739 }

References ShuttleGuiBase::AddListControlReportMode(), ShuttleGui::AddStandardButtons(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndStatic(), ShuttleGuiBase::EndVerticalLay(), fn, mEffect, mList, AudioUnitEffect::mName, AudioUnitEffect::mVendor, PRESET_LOCAL_PATH, PRESET_USER_PATH, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartStatic(), ShuttleGuiBase::StartVerticalLay(), ShuttleGui::Style(), and XO.

Here is the call graph for this function:

Member Data Documentation

◆ mEffect

AudioUnitEffect* AudioUnitEffectImportDialog::mEffect
private

Definition at line 647 of file AudioUnitEffect.cpp.

Referenced by Import(), and PopulateOrExchange().

◆ mList

wxListCtrl* AudioUnitEffectImportDialog::mList
private

Definition at line 649 of file AudioUnitEffect.cpp.

Referenced by HasPresets(), OnOk(), and PopulateOrExchange().

◆ mParent

wxWindow* AudioUnitEffectImportDialog::mParent
private

Definition at line 646 of file AudioUnitEffect.cpp.


The documentation for this class was generated from the following file:
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
AudacityMessageBox
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Definition: AudacityMessageBox.cpp:17
fn
static const auto fn
Definition: WaveformView.cpp:1108
AudioUnitEffectImportDialog::mList
wxListCtrl * mList
Definition: AudioUnitEffect.cpp:649
Format
Abstract base class used in importing a file.
XO
#define XO(s)
Definition: Internat.h:31
wxArrayStringEx
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
Definition: wxArrayStringEx.h:18
AudioUnitEffectImportDialog::Import
TranslatableString Import(const wxString &path, const wxString &name)
Definition: AudioUnitEffect.cpp:746
AudioUnitEffectImportDialog::PopulateOrExchange
void PopulateOrExchange(ShuttleGui &S)
Definition: AudioUnitEffect.cpp:671
ShuttleGui::Style
ShuttleGui & Style(long iStyle)
Definition: ShuttleGui.h:727
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
PRESET_LOCAL_PATH
#define PRESET_LOCAL_PATH
Definition: AudioUnitEffect.cpp:70
AudioUnitEffect::mHost
EffectHostInterface * mHost
Definition: AudioUnitEffect.h:189
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
PRESET_USER_PATH
#define PRESET_USER_PATH
Definition: AudioUnitEffect.cpp:71
PRESET_KEY
#define PRESET_KEY
Definition: AudioUnitEffect.cpp:67
name
const TranslatableString name
Definition: Distortion.cpp:98
ShuttleGuiBase::StartStatic
wxStaticBox * StartStatic(const TranslatableString &Str, int iProp=0)
Definition: ShuttleGui.cpp:893
EffectHostInterface::GetUserPresetsGroup
virtual RegistryPath GetUserPresetsGroup(const RegistryPath &name)=0
ConfigClientInterface::SetPrivateConfig
virtual bool SetPrivateConfig(const RegistryPath &group, const RegistryPath &key, const wxString &value)=0
ShuttleGuiBase::AddListControlReportMode
wxListCtrl * AddListControlReportMode(std::initializer_list< const ListControlColumn > columns={}, long listControlStyles=0)
Definition: ShuttleGui.cpp:802
AudioUnitEffectImportDialog::mEffect
AudioUnitEffect * mEffect
Definition: AudioUnitEffect.cpp:647
wxDialogWrapper::wxDialogWrapper
wxDialogWrapper()
Definition: wxPanelWrapper.h:84
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2444
AudioUnitEffect::mVendor
wxString mVendor
Definition: AudioUnitEffect.h:181
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
ShuttleGuiBase::EndStatic
void EndStatic()
Definition: ShuttleGui.cpp:922
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
AudioUnitEffect::mName
wxString mName
Definition: AudioUnitEffect.h:180