Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tempo support #172

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pedalboard/ExternalPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ template <typename ExternalPluginType> class ExternalPlugin : public Plugin {
channelPointers[i] = outputBlock.getChannelPointer(i);
}


// Depending on the bus layout, we may have to pass extra buffers to the
// plugin that we don't use. Use vector here to ensure the memory is
// freed via RAII.
Expand Down Expand Up @@ -994,11 +995,12 @@ inline void init_external_plugins(py::module &m) {
"(i.e.: if you're running Linux but trying to open a VST that does not "
"support Linux, this will fail).")
.def(py::init([](std::string &pathToPluginFile,
std::optional<std::string> pluginName) {
std::optional<std::string> pluginName,
std::optional<int> tempoBpm) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to decide if tempoBpm can be optional or not; in your Python code below, you pass a default value of 120 BPM. Making tempoBpm an std::optional here means that it could be None as well; it sounds like it should be mandatory argument with a default value, rather than an optional type.

return std::make_unique<ExternalPlugin<juce::VST3PluginFormat>>(
pathToPluginFile, pluginName);
pathToPluginFile, pluginName, tempoBpm);
}),
py::arg("path_to_plugin_file"), py::arg("plugin_name") = py::none())
py::arg("path_to_plugin_file"), py::arg("plugin_name") = py::none(), py::arg("tempo_bpm") = 120)
.def("__repr__",
[](ExternalPlugin<juce::VST3PluginFormat> &plugin) {
std::ostringstream ss;
Expand Down Expand Up @@ -1043,6 +1045,10 @@ inline void init_external_plugins(py::module &m) {
"Show the UI of this plugin as a native window. This method will "
"block until the window is closed or a KeyboardInterrupt is "
"received.");
.def_property(
"tempo", &ExternalPlugin<juce::VST3PluginFormat>::getBpm,
&ExternalPlugin<juce::VST3PluginFormat>::setBpm,
"The value of the tempo/bpm")
#endif

#if JUCE_PLUGINHOST_AU && JUCE_MAC
Expand Down Expand Up @@ -1110,4 +1116,4 @@ inline void init_external_plugins(py::module &m) {
#endif
}

} // namespace Pedalboard
} // namespace Pedalboard
6 changes: 6 additions & 0 deletions pedalboard/pedalboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ def __set_initial_parameter_values__(
)
setattr(self, key, value)

def __set_extra_functions__(self, tempo_bpm: int = 120):
tempo_bpm = self.tempo_bpm

Comment on lines +568 to +570
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't do anything: tempo_bpm is just a local variable. I think you probably want to pass tempo_bpm through as a parameter into _VST3Plugin.__init__(self, path_to_plugin_file, plugin_name) on line 682 instead.

@property
def parameters(self) -> Dict[str, AudioProcessorParameter]:
# Return a read-only version of this dictionary,
Expand Down Expand Up @@ -668,6 +671,7 @@ def __init__(
path_to_plugin_file: str,
parameter_values: Dict[str, Union[str, int, float, bool]] = {},
plugin_name: Optional[str] = None,
tempo_bpm: int = 120,
):
if not isinstance(parameter_values, dict):
raise TypeError(
Expand Down Expand Up @@ -728,6 +732,7 @@ def load_plugin(
path_to_plugin_file: str,
parameter_values: Dict[str, Union[str, int, float, bool]] = {},
plugin_name: Union[str, None] = None,
tempo_bpm: int = 120,
) -> ExternalPlugin:
"""
Load an audio plugin.
Expand Down Expand Up @@ -774,6 +779,7 @@ def load_plugin(
path_to_plugin_file=path_to_plugin_file,
parameter_values=parameter_values,
plugin_name=plugin_name,
tempo_bpm=tempo_bpm
)
except ImportError as e:
exceptions.append(e)
Expand Down