Skip to content

Commit

Permalink
Refactor handling of user-selectable plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeoliphant committed Jul 16, 2024
1 parent f06a5b2 commit 762e265
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Dependencies/stompbox
2 changes: 2 additions & 0 deletions StompboxPlugin/UnmanagedAudioPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public virtual void SetUnmanagedWrapper(PluginWrapper unmanagedWrapper)
if (String.IsNullOrEmpty(Name))
Name = unmanagedWrapper.GetName();

IsUserSelectable = unmanagedWrapper.GetIsUserSelectable();

string backgroundColor = unmanagedWrapper.GetBackgroundColor();

if (!string.IsNullOrEmpty(backgroundColor))
Expand Down
20 changes: 3 additions & 17 deletions StompboxShared/Interface/PluginInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,7 @@ public void RemovePlugin(IAudioPlugin plugin)

void AddPlugin()
{
List<IAudioPlugin> plugins = new List<IAudioPlugin>();

foreach (string pluginName in StompboxClient.Instance.GetAllPluginNames())
{
plugins.Add(StompboxClient.Instance.GetPluginDefinition(pluginName));
}

Layout.Current.ShowPopup(new PluginFlipList(plugins)
Layout.Current.ShowPopup(new PluginFlipList(StompboxClient.Instance.GetAllUserPluginDefinitions())
{
DesiredWidth = Layout.Current.Bounds.Width,
DesiredHeight = 260,
Expand All @@ -175,7 +168,7 @@ public class PluginFlipList : FlipList, IPopup
public Action<string> SelectAction { get; set; }
public Action CloseAction { get; set; }

public PluginFlipList(List<IAudioPlugin> plugins)
public PluginFlipList(IEnumerable<IAudioPlugin> plugins)
: base(230)
{
HorizontalAlignment = EHorizontalAlignment.Center;
Expand Down Expand Up @@ -820,14 +813,7 @@ protected override void AddControls(Dock dock)
Text = "Swap Plugin",
AfterCloseAction = delegate
{
List<IAudioPlugin> plugins = new List<IAudioPlugin>();

foreach (string pluginName in StompboxClient.Instance.GetAllPluginNames())
{
plugins.Add(StompboxClient.Instance.GetPluginDefinition(pluginName));
}

Layout.Current.ShowPopup(new PluginFlipList(plugins)
Layout.Current.ShowPopup(new PluginFlipList(StompboxClient.Instance.GetAllUserPluginDefinitions())
{
DesiredWidth = Layout.Current.Bounds.Width,
DesiredHeight = 260,
Expand Down
13 changes: 0 additions & 13 deletions StompboxShared/PluginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,13 @@ namespace Stompbox
{
public class PluginFactory
{
public List<String> PluginIDs { get; private set; }
Dictionary<string, IAudioPlugin> loadedPlugins = new Dictionary<string, IAudioPlugin>();

StompboxClient StompboxClient;

public PluginFactory(StompboxClient StompboxClient)
{
this.StompboxClient = StompboxClient;

PluginIDs = new List<string>();
}

public void SetPlugins(IEnumerable<string> pluginIDs)
{
PluginIDs.Clear();

foreach (string pluginID in pluginIDs)
{
PluginIDs.Add(pluginID);
}
}

public void ClearPlugins()
Expand Down
23 changes: 19 additions & 4 deletions StompboxShared/StompboxClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ public StompboxClient(bool inClientMode)
processorWrapper = new PluginProcessorWrapper(PluginPath, true);
processorWrapper.SetMidiCallback(HandleMidi);

PluginFactory.SetPlugins(processorWrapper.GetAllPlugins());

UpdateProgram();
#endif
}
Expand Down Expand Up @@ -250,8 +248,6 @@ public void UpdateProgram()
}
else
{
PluginFactory.SetPlugins(protocolClient.PluginNames);

SendCommand("Dump Program");
}
}
Expand Down Expand Up @@ -283,6 +279,25 @@ public IEnumerable<String> GetAllPluginNames()
#endif
}

public IEnumerable<IAudioPlugin> GetAllPluginDefinitions()
{
foreach (string name in GetAllPluginNames())
{
yield return GetPluginDefinition(name);
}
}

public IEnumerable<IAudioPlugin> GetAllUserPluginDefinitions()
{
foreach (string name in GetAllPluginNames())
{
IAudioPlugin plugin = GetPluginDefinition(name);

if (plugin.IsUserSelectable)
yield return plugin;
}
}

public IAudioPlugin GetPluginDefinition(string pluginName)
{
if (InClientMode)
Expand Down
2 changes: 1 addition & 1 deletion UnmanagedBridge/PluginWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace UnmanagedPlugins

array<System::String^>^ GetAllPlugins()
{
std::list<std::string> pluginList = processor->GetPluginFactory()->GetUserPlugins();
std::list<std::string> pluginList = processor->GetPluginFactory()->GetAllPlugins();

array<System::String^>^ plugins = gcnew array<System::String^>(pluginList.size());

Expand Down

0 comments on commit 762e265

Please sign in to comment.