16#include "../EffectEditor.h" 
   18#include <vamp-hostsdk/Plugin.h> 
   19#include <vamp-hostsdk/PluginChannelAdapter.h> 
   20#include <vamp-hostsdk/PluginInputDomainAdapter.h> 
   23#include <wx/checkbox.h> 
   25#include <wx/combobox.h> 
   27#include <wx/statbox.h> 
   28#include <wx/stattext.h> 
   29#include <wx/textctrl.h> 
   30#include <wx/scrolwin.h> 
   31#include <wx/version.h> 
   35#include "../../widgets/valnum.h" 
   67:  mPlugin(
std::move(plugin)),
 
   70   mHasParameters(hasParameters),
 
   73   mKey = mPath.BeforeFirst(
wxT(
'/')).ToUTF8();
 
   74   mName = mPath.AfterFirst(
wxT(
'/'));
 
   97   return { wxString::FromUTF8(
mPlugin->getMaker().c_str()) };
 
  102   return wxString::Format(
wxT(
"%d"), 
mPlugin->getPluginVersion());
 
  108      wxString::FromUTF8(
mPlugin->getCopyright().c_str()) );
 
  137   return mPlugin->getMaxChannelCount();
 
  143   for (
size_t p = 0, paramCount = 
mParameters.size(); p < paramCount; p++)
 
  145      wxString 
key = wxString::FromUTF8(
mParameters[p].identifier.c_str());
 
  155         bool val = value > 0.5;
 
  157         parms.Write(
key, val);
 
  163         std::vector<EnumValueSymbol> choices;
 
  166         for (
size_t i = 0, choiceCount = 
mParameters[p].valueNames.size(); i < choiceCount; i++)
 
  168            wxString choice = wxString::FromUTF8(
mParameters[p].valueNames[i].c_str());
 
  169            if (
size_t(value - 
mParameters[p].minValue + 0.5) == i)
 
  173            choices.push_back(choice);
 
  176         parms.
WriteEnum(
key, val, choices.data(), choices.size());
 
  180         parms.Write(
key, value);
 
  191   for (
size_t p = 0, paramCount = 
mParameters.size(); p < paramCount; p++)
 
  193      wxString 
key = wxString::FromUTF8(
mParameters[p].identifier.c_str());
 
  205         good = parms.Read(
key, &val);
 
  211         std::vector<EnumValueSymbol> choices;
 
  214         for (
size_t i = 0, choiceCount = 
mParameters[p].valueNames.size(); i < choiceCount; i++)
 
  216            wxString choice = wxString::FromUTF8(
mParameters[p].valueNames[i].c_str());
 
  217            choices.push_back(choice);
 
  220         good = parms.
ReadEnum(
key, &val, choices.data(), choices.size()) && val != wxNOT_FOUND;
 
  226         good = parms.Read(
key, &val) && val >= lower && val <= upper;
 
  236   for (
size_t p = 0, paramCount = 
mParameters.size(); p < paramCount; p++)
 
  238      wxString 
key = wxString::FromUTF8(
mParameters[p].identifier.c_str());
 
  249         parms.Read(
key, &val);
 
  257         std::vector<EnumValueSymbol> choices;
 
  260         for (
size_t i = 0, choiceCount = 
mParameters[p].valueNames.size(); i < choiceCount; i++)
 
  262            wxString choice = wxString::FromUTF8(
mParameters[p].valueNames[i].c_str());
 
  263            choices.push_back(choice);
 
  266         parms.
ReadEnum(
key, &val, choices.data(), choices.size());
 
  274         parms.Read(
key, &val);
 
  282               val = (int)((val - lower) / qs + 0.5) * qs + lower;
 
  307   Vamp::HostExt::PluginLoader *loader = Vamp::HostExt::PluginLoader::getInstance();
 
  308   mPlugin.reset(loader->loadPlugin(
mKey, 
mRate, Vamp::HostExt::PluginLoader::ADAPT_ALL));
 
  312         XO(
"Sorry, failed to load Vamp Plug-in."));
 
  328   bool multiple = 
false;
 
  329   unsigned prevTrackChannels = 0;
 
  340   std::vector<std::shared_ptr<AddedAnalysisTrack>> addedTracks;
 
  342   for (
auto pTrack : 
inputTracks()->Any<const WaveTrack>())
 
  344      auto channelGroup = pTrack->Channels();
 
  345      auto left = *channelGroup.first++;
 
  347      unsigned channels = 1;
 
  351         channelGroup.size() ? *channelGroup.first++ : 
nullptr;
 
  361      size_t step = 
mPlugin->getPreferredStepSize();
 
  362      size_t block = 
mPlugin->getPreferredBlockSize();
 
  364      bool initialiseRequired = 
true;
 
  383      if (prevTrackChannels > 0)
 
  389         if (prevTrackChannels == channels)
 
  392            initialiseRequired = 
false;
 
  401      if (initialiseRequired)
 
  403         if (!
mPlugin->initialise(channels, step, block))
 
  406               XO(
"Sorry, Vamp Plug-in failed to initialize."));
 
  414         ? wxString::Format( 
_(
"%s: %s"), pTrack->GetName(), effectName )
 
  417      LabelTrack *ltrack = addedTracks.back()->get();
 
  421      auto originalLen = len;
 
  430            left->GetFloats(data[0].get(), pos, request);
 
  433            right->GetFloats(data[1].get(), pos, request);
 
  437            for (
unsigned int c = 0; c < channels; ++c)
 
  439               for (
decltype(block) i = request; i < block; ++i)
 
  448         Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime(
 
  449            long( pos.as_long_long() ),
 
  453         Vamp::Plugin::FeatureSet features = 
mPlugin->process(
 
  454            reinterpret_cast< float** 
>( data.get() ), timestamp);
 
  471                  (pos - start).as_double() /
 
  472                  originalLen.as_double() ))
 
  480                  (pos - start).as_double() /
 
  481                  originalLen.as_double() ))
 
  488      Vamp::Plugin::FeatureSet features = 
mPlugin->getRemainingFeatures();
 
  491      prevTrackChannels = channels;
 
  495   for (
auto &addedTrack : addedTracks)
 
  496      addedTrack->Commit();
 
  506   Vamp::Plugin::ProgramList programs = 
mPlugin->getPrograms();
 
  519   wxScrolledWindow *scroller = 
S.Style(wxVSCROLL | wxTAB_TRAVERSAL)
 
  522      S.StartStatic(
XO(
"Plugin Settings"));
 
  524         S.StartMultiColumn(5, wxEXPAND);
 
  528            if (!programs.empty())
 
  530               S.AddPrompt(
XXO(
"Program"));
 
  534                  .MinSize( { -1, -1 } )
 
  535                  .Position(wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL)
 
  539                        for (
const auto &program : programs)
 
  541                              Verbatim(wxString::FromUTF8(program.c_str())));
 
  552            for (
size_t p = 0; p < count; p++)
 
  554               wxString tip = wxString::FromUTF8(
mParameters[p].description.c_str());
 
  555               wxString unit = wxString::FromUTF8(
mParameters[p].unit.c_str());
 
  568                  labelText += 
wxT(
" (") + unit + 
wxT(
")");
 
  582                     .Position(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL)
 
  598                  for (
size_t i = 0, cnt = 
mParameters[p].valueNames.size(); i < cnt; i++)
 
  600                     wxString choice = wxString::FromUTF8(
mParameters[p].valueNames[i].c_str());
 
  601                     if (
size_t(value - 
mParameters[p].minValue + 0.5) == i)
 
  605                     choices.push_back( 
Verbatim( choice ) );
 
  611                     .Position(wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL)
 
  612                     .MinSize( { -1, -1 } )
 
  613                     .AddChoice( {}, choices, selected );
 
  628                     .Position(wxALIGN_CENTER_VERTICAL | wxALL)
 
  629                     .Validator<FloatingPointValidator<float>>(
 
  632                           ? NumValidatorStyle::THREE_TRAILING_ZEROES
 
  634                              ? NumValidatorStyle::TWO_TRAILING_ZEROES
 
  635                              : NumValidatorStyle::ONE_TRAILING_ZERO),
 
  637                     .AddTextBox( {}, 
wxT(
""), 12);
 
  645                     .Style(wxSL_HORIZONTAL)
 
  646                     .MinSize( { 150, -1 } )
 
  647                     .AddSlider( {}, 0, 1000, 0);
 
  660   scroller->SetScrollRate(0, 20);
 
  690                             Vamp::Plugin::FeatureSet &features)
 
  692   for (Vamp::Plugin::FeatureList::iterator fli = features[
mOutput].
begin();
 
  693        fli != features[
mOutput].end(); ++fli)
 
  695      Vamp::RealTime ftime0 = fli->timestamp;
 
  696      double ltime0 = ftime0.sec + (double(ftime0.nsec) / 1000000000.0);
 
  698      Vamp::RealTime ftime1 = ftime0;
 
  699      if (fli->hasDuration) ftime1 = ftime0 + fli->duration;
 
  700      double ltime1 = ftime1.sec + (double(ftime1.nsec) / 1000000000.0);
 
  703      if (
label == wxString())
 
  705         if (fli->values.empty())
 
  711            label = wxString::Format(
LAT1CTOWX(
"%.3f"), *fli->values.begin());
 
  721   for (
size_t p = 0, cnt = 
mParameters.size(); p < cnt; p++)
 
  741         mFields[p]->GetValidator()->TransferToWindow();
 
  745         float range = upper - lower;
 
  753               value = (int)((value - lower) / qs + 0.5) * qs + lower;
 
  757         mSliders[p]->SetValue((
int)(((value - lower) / range) * 1000.0 + 0.5));
 
  776      Vamp::Plugin::ProgramList programs = 
mPlugin->getPrograms();
 
  777      mPlugin->selectProgram(programs[evt.GetInt()]);
 
  791   float range = upper - lower;
 
  792   float val = (evt.GetInt() / 1000.0) * range;
 
  800         val = (int)(val / qs + 0.5) * qs;
 
  807   mFields[p]->GetValidator()->TransferToWindow();
 
  816   mFields[p]->GetValidator()->TransferFromWindow();
 
  820   float range = upper - lower;
 
  829         val = (int)((val - lower) / qs + 0.5) * qs + lower;
 
  835   mSliders[p]->SetValue((
int)(((val - lower) / range) * 1000.0 + 0.5));
 
std::shared_ptr< AddedAnalysisTrack > AddAnalysisTrack(Effect &effect, const wxString &name)
XXO("&Cut/Copy/Paste Toolbar")
wxString PluginPath
type alias for identifying a Plugin supplied by a module, each module defining its own interpretation...
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
static Settings & settings()
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
#define VAMPEFFECTS_FAMILY
void reinit(Integral count, bool initialize=false)
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
bool WriteEnum(const wxString &key, int value, const EnumValueSymbol choices[], size_t nChoices)
bool ReadEnum(const wxString &key, int *pi, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
const wxString Translation() const
const TrackList * inputTracks() const
bool TrackGroupProgress(int whichGroup, double frac, const TranslatableString &={}) const
void GetBounds(const WaveTrack &track, sampleCount *start, sampleCount *len)
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
int GetNumWaveGroups() const
Performs effect computation.
Hold values to send to effect output meters.
static int DoMessageBox(const EffectPlugin &plugin, const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
static wxString ToDisplayString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, uses the user's locale's decimal separator.
A LabelTrack is a Track that holds labels (LabelStruct).
int AddLabel(const SelectedRegion ®ion, const wxString &title)
Defines a selected portion of a project.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
auto Any() -> TrackIterRange< TrackType >
Holds a msgid for the translation catalog; may also bind format arguments.
ArrayOf< wxCheckBox * > mToggles
void OnCheckBox(wxCommandEvent &evt)
bool IsDefault() const override
Whether the effect sorts "above the line" in the menus.
PluginPath GetPath() const override
bool TransferDataToWindow(const EffectSettings &settings) override
ComponentInterfaceSymbol GetSymbol() const override
bool TransferDataFromWindow(EffectSettings &settings) override
EffectFamilySymbol GetFamily() const override
Report identifier and user-visible name of the effect protocol.
bool IsInteractive() const override
Whether the effect needs a dialog for entry of settings.
void OnTextCtrl(wxCommandEvent &evt)
ArrayOf< wxSlider * > mSliders
EffectType GetType() const override
Type determines how it behaves.
VendorSymbol GetVendor() const override
Vamp::Plugin::ParameterList mParameters
ArrayOf< wxChoice * > mChoices
ArrayOf< wxStaticText * > mLabels
std::unique_ptr< Vamp::Plugin > mPlugin
TranslatableString GetDescription() const override
bool Process(EffectInstance &instance, EffectSettings &settings) override
ArrayOf< wxTextCtrl * > mFields
std::unique_ptr< EffectEditor > PopulateOrExchange(ShuttleGui &S, EffectInstance &instance, EffectSettingsAccess &access, const EffectOutputs *pOutputs) override
Add controls to effect panel; always succeeds.
wxWeakRef< wxWindow > mUIParent
bool SaveSettings(const EffectSettings &settings, CommandParameters &parms) const override
Store settings as keys and values.
void OnSlider(wxCommandEvent &evt)
bool LoadSettings(const CommandParameters &parms, EffectSettings &settings) const override
Restore settings from keys and values.
unsigned GetAudioInCount() const override
How many input buffers to allocate at once.
Vamp::HostExt::PluginLoader::PluginKey mKey
wxString GetVersion() const override
void OnChoice(wxCommandEvent &evt)
void AddFeatures(LabelTrack *track, Vamp::Plugin::FeatureSet &features)
A Track that contains audio waveform data.
Positions or offsets within audio files need a wide type.
double GetRate(const Track &track)
const char * begin(const char *str) noexcept
Externalized state of a plug-in.