15#include "../AnalysisTracks.h"
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"
38#include "../../LabelTrack.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;
301 for (
auto leader :
inputTracks()->Leaders<const WaveTrack>()) {
303 auto rate = (*channelGroup.first++) ->
GetRate();
304 for(
auto channel : channelGroup) {
305 if (rate != channel->GetRate())
312"Sorry, Vamp Plug-ins cannot be run on stereo tracks where the individual channels of the track do not match.") );
327 Vamp::HostExt::PluginLoader *loader = Vamp::HostExt::PluginLoader::getInstance();
328 mPlugin.reset(loader->loadPlugin(
mKey,
mRate, Vamp::HostExt::PluginLoader::ADAPT_ALL));
332 XO(
"Sorry, failed to load Vamp Plug-in."));
348 bool multiple =
false;
349 unsigned prevTrackChannels = 0;
360 std::vector<std::shared_ptr<AddedAnalysisTrack>> addedTracks;
362 for (
auto leader :
inputTracks()->Leaders<const WaveTrack>())
365 auto left = *channelGroup.first++;
367 unsigned channels = 1;
371 channelGroup.
size() ? *channelGroup.first++ :
nullptr;
381 size_t step =
mPlugin->getPreferredStepSize();
382 size_t block =
mPlugin->getPreferredBlockSize();
384 bool initialiseRequired =
true;
403 if (prevTrackChannels > 0)
409 if (prevTrackChannels == channels)
412 initialiseRequired =
false;
421 if (initialiseRequired)
423 if (!
mPlugin->initialise(channels, step, block))
426 XO(
"Sorry, Vamp Plug-in failed to initialize."));
434 ? wxString::Format(
_(
"%s: %s"), left->GetName(), effectName )
437 LabelTrack *ltrack = addedTracks.back()->get();
441 auto originalLen = len;
451 left->GetFloats(data[0].get(), pos, request);
456 right->
GetFloats(data[1].get(), pos, request);
461 for (
unsigned int c = 0; c < channels; ++c)
463 for (
decltype(block) i = request; i < block; ++i)
472 Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime(
473 long( pos.as_long_long() ),
477 Vamp::Plugin::FeatureSet features =
mPlugin->process(
478 reinterpret_cast< float**
>( data.get() ), timestamp);
495 (pos - start).as_double() /
496 originalLen.as_double() ))
504 (pos - start).as_double() /
505 originalLen.as_double() ))
512 Vamp::Plugin::FeatureSet features =
mPlugin->getRemainingFeatures();
515 prevTrackChannels = channels;
519 for (
auto &addedTrack : addedTracks)
520 addedTrack->Commit();
530 Vamp::Plugin::ProgramList programs =
mPlugin->getPrograms();
543 wxScrolledWindow *scroller =
S.Style(wxVSCROLL | wxTAB_TRAVERSAL)
546 S.StartStatic(
XO(
"Plugin Settings"));
548 S.StartMultiColumn(5, wxEXPAND);
552 if (!programs.empty())
554 S.AddPrompt(
XXO(
"Program"));
558 .MinSize( { -1, -1 } )
559 .Position(wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL)
563 for (
const auto &program : programs)
565 Verbatim(wxString::FromUTF8(program.c_str())));
576 for (
size_t p = 0; p < count; p++)
578 wxString tip = wxString::FromUTF8(
mParameters[p].description.c_str());
579 wxString unit = wxString::FromUTF8(
mParameters[p].unit.c_str());
592 labelText +=
wxT(
" (") + unit +
wxT(
")");
606 .Position(wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL)
622 for (
size_t i = 0, cnt =
mParameters[p].valueNames.size(); i < cnt; i++)
624 wxString choice = wxString::FromUTF8(
mParameters[p].valueNames[i].c_str());
625 if (
size_t(value -
mParameters[p].minValue + 0.5) == i)
629 choices.push_back(
Verbatim( choice ) );
635 .Position(wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL)
636 .MinSize( { -1, -1 } )
637 .AddChoice( {}, choices, selected );
652 .Position(wxALIGN_CENTER_VERTICAL | wxALL)
653 .Validator<FloatingPointValidator<float>>(
656 ? NumValidatorStyle::THREE_TRAILING_ZEROES
658 ? NumValidatorStyle::TWO_TRAILING_ZEROES
659 : NumValidatorStyle::ONE_TRAILING_ZERO),
661 .AddTextBox( {},
wxT(
""), 12);
669 .Style(wxSL_HORIZONTAL)
670 .MinSize( { 150, -1 } )
671 .AddSlider( {}, 0, 1000, 0);
684 scroller->SetScrollRate(0, 20);
714 Vamp::Plugin::FeatureSet &features)
716 for (Vamp::Plugin::FeatureList::iterator fli = features[
mOutput].
begin();
717 fli != features[
mOutput].end(); ++fli)
719 Vamp::RealTime ftime0 = fli->timestamp;
720 double ltime0 = ftime0.sec + (double(ftime0.nsec) / 1000000000.0);
722 Vamp::RealTime ftime1 = ftime0;
723 if (fli->hasDuration) ftime1 = ftime0 + fli->duration;
724 double ltime1 = ftime1.sec + (double(ftime1.nsec) / 1000000000.0);
727 if (
label == wxString())
729 if (fli->values.empty())
735 label = wxString::Format(
LAT1CTOWX(
"%.3f"), *fli->values.begin());
745 for (
size_t p = 0, cnt =
mParameters.size(); p < cnt; p++)
765 mFields[p]->GetValidator()->TransferToWindow();
769 float range = upper - lower;
777 value = (int)((value - lower) / qs + 0.5) * qs + lower;
781 mSliders[p]->SetValue((
int)(((value - lower) / range) * 1000.0 + 0.5));
800 Vamp::Plugin::ProgramList programs =
mPlugin->getPrograms();
801 mPlugin->selectProgram(programs[evt.GetInt()]);
815 float range = upper - lower;
816 float val = (evt.GetInt() / 1000.0) * range;
824 val = (int)(val / qs + 0.5) * qs;
831 mFields[p]->GetValidator()->TransferToWindow();
840 mFields[p]->GetValidator()->TransferFromWindow();
844 float range = upper - lower;
853 val = (int)((val - lower) / qs + 0.5) * qs + lower;
859 mSliders[p]->SetValue((
int)(((val - lower) / range) * 1000.0 + 0.5));
std::shared_ptr< AddedAnalysisTrack > AddAnalysisTrack(Effect &effect, const wxString &name)
static const AudacityProject::AttachedObjects::RegisteredFactory key
const TranslatableString 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)
size_t size() const
How many attachment pointers are in the Site.
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
bool TrackProgress(int whichTrack, double frac, const TranslatableString &={}) const
void GetBounds(const WaveTrack &track, const WaveTrack *pRight, sampleCount *start, sampleCount *len)
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)
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Defines a selected portion of a project.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
static auto Channels(TrackType *pTrack) -> 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.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
double GetRate(const Track &track)
Externalized state of a plug-in.