Skip to content
Merged
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
61 changes: 56 additions & 5 deletions src/detail/auv2/parameter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,68 @@
namespace Clap::AUv2
{

Parameter::Parameter(clap_param_info_t &clap_param)
Parameter::Parameter(const clap_plugin_t* plugin, const clap_plugin_params_t* clap_param_ext,
const clap_param_info_t& clap_param)
{
_info = clap_param;
_cfstring = CFStringCreateWithCString(NULL, _info.name, kCFStringEncodingUTF8);
updateInfo(plugin, clap_param_ext, clap_param);
}

void Parameter::resetInfo(const clap_param_info_t &i)
void Parameter::updateInfo(const clap_plugin_t* plugin, const clap_plugin_params_t* clap_param_ext,
const clap_param_info_t& i)
{
if (_cfstring)
{
CFRelease(_cfstring);
}
_info = i;
CFRelease(_cfstring);
_cfstring = CFStringCreateWithCString(NULL, _info.name, kCFStringEncodingUTF8);

const auto& info = _info;
AudioUnitParameterOptions flags = 0;

flags |= kAudioUnitParameterFlag_Global;

if (!(info.flags & CLAP_PARAM_IS_AUTOMATABLE)) flags |= kAudioUnitParameterFlag_NonRealTime;
if (!(info.flags & CLAP_PARAM_IS_HIDDEN))
{
if (info.flags & CLAP_PARAM_IS_READONLY)
flags |= kAudioUnitParameterFlag_IsReadable;
else
flags |= kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable;
}
if (info.flags & CLAP_PARAM_IS_STEPPED)
{
if (info.max_value - info.min_value == 1)
{
flags |= kAudioUnitParameterUnit_Boolean;
}
// flags |= kAudioUnitParameterUnit_Indexed; // probably need to add the lists then
}
if (info.max_value - info.min_value > 100)
{
flags |= kAudioUnitParameterFlag_IsHighResolution;
}

// checking if the parameter supports the conversion of its value to text

// we can't get the value since we are not in the audio thread
// auto guarantee_mainthread = _plugin->AlwaysMainThread();

{
char buf[200];
if (clap_param_ext->value_to_text(plugin, info.id, info.default_value, buf, sizeof(buf)))
{
flags |= kAudioUnitParameterFlag_HasName;
}
}

/*
* The CFString() used from the param can reset which releases it. So add a ref count
* and ask the param to release it too
*/
flags |= kAudioUnitParameterFlag_HasCFNameString | kAudioUnitParameterFlag_CFNameRelease;

_flags = flags;
}
Parameter::~Parameter()
{
Expand Down
13 changes: 10 additions & 3 deletions src/detail/auv2/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace Clap::AUv2
class Parameter
{
public:
Parameter(clap_param_info_t& clap_param);
Parameter(const clap_plugin_t* plugin, const clap_plugin_params_t* clap_param_ext,
const clap_param_info_t& clap_param);
~Parameter();
const clap_param_info_t& info() const
{
Expand All @@ -44,12 +45,18 @@ class Parameter
{
return _cfstring;
}
AudioUnitParameterOptions AudioUnitFlags() const
{
return _flags;
}

void resetInfo(const clap_param_info_t& i);
void updateInfo(const clap_plugin_t* plugin, const clap_plugin_params_t* clap_param_ext,
const clap_param_info_t& i);

private:
clap_param_info_t _info;
CFStringRef _cfstring;
CFStringRef _cfstring = nullptr;
AudioUnitParameterOptions _flags;
};

} // namespace Clap::AUv2
14 changes: 7 additions & 7 deletions src/detail/auv2/wrappedview.asinclude.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (id)initWithAUv2:(free_audio::auv2_wrapper::ui_connection *)cont preferredSize

ui = *cont;
canary = 0xbeebbeeb;

if (ui._registerWindow)
{
ui._registerWindow((clap_window_t *)self, &canary);
Expand Down Expand Up @@ -148,20 +148,20 @@ - (void)doIdle
{
// auto gui = ui._plugin->_ext._gui;
}
- (void) viewDidMoveToWindow
- (void)viewDidMoveToWindow
{
if ( [self window] == nil )
if ([self window] == nil)
{
LOGINFO("[clap-wrapper] - view removed from a window");
if (idleTimer)
{
CFRunLoopTimerInvalidate(idleTimer);
idleTimer = 0;
}
if ( canary )
if (canary)
{
ui._destroyWindow();

assert(canary == 0);
}
}
Expand All @@ -175,7 +175,7 @@ - (void)dealloc
{
CFRunLoopTimerInvalidate(idleTimer);
}
if ( canary )
if (canary)
{
LOGINFO("[clap-wrapper] the host did not call viewDidMoveWindow with a nil window");
ui._destroyWindow();
Expand All @@ -185,7 +185,7 @@ - (void)dealloc
- (void)setFrame:(NSRect)newSize
{
[super setFrame:newSize];
if ( canary )
if (canary)
{
auto gui = ui._plugin->_ext._gui;
gui->set_scale(ui._plugin->_plugin, 1.0);
Expand Down
53 changes: 5 additions & 48 deletions src/wrapasauv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,12 @@ void WrapAsAUV2::setupParameters(const clap_plugin_t* plugin, const clap_plugin_
{
// creating the mapping object and insert it into the tree
// this will also create Clumps if necessary
_parametertree[paraminfo.id] = std::make_unique<Clap::AUv2::Parameter>(paraminfo);
_parametertree[paraminfo.id] =
std::make_unique<Clap::AUv2::Parameter>(_plugin->_plugin, p, paraminfo);
}
else
{
piter->second->resetInfo(paraminfo);
piter->second->updateInfo(_plugin->_plugin, p, paraminfo);
}
Globals()->SetParameter(paraminfo.id, result);
}
Expand Down Expand Up @@ -443,57 +444,13 @@ OSStatus WrapAsAUV2::GetParameterInfo(AudioUnitScope inScope, AudioUnitParameter
// const uint64_t stdflag = kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable;
if (inScope == kAudioUnitScope_Global)
{
AudioUnitParameterOptions flags = 0;
auto pi = _parametertree.find(inParameterID);
if (pi != _parametertree.end())
{
auto f = pi->second.get();
const auto info = f->info();
const auto& info = f->info();

flags |= kAudioUnitParameterFlag_Global;

if (!(info.flags & CLAP_PARAM_IS_AUTOMATABLE)) flags |= kAudioUnitParameterFlag_NonRealTime;
if (!(info.flags & CLAP_PARAM_IS_HIDDEN))
{
if (info.flags & CLAP_PARAM_IS_READONLY)
flags |= kAudioUnitParameterFlag_IsReadable;
else
flags |= kAudioUnitParameterFlag_IsReadable | kAudioUnitParameterFlag_IsWritable;
}
if (info.flags & CLAP_PARAM_IS_STEPPED)
{
if (info.max_value - info.min_value == 1)
{
flags |= kAudioUnitParameterUnit_Boolean;
}
// flags |= kAudioUnitParameterUnit_Indexed; // probably need to add the lists then
}
if (info.max_value - info.min_value > 100)
{
flags |= kAudioUnitParameterFlag_IsHighResolution;
}

// checking if the parameter supports the conversion of its value to text

// we can't get the value since we are not in the audio thread
auto guarantee_mainthread = _plugin->AlwaysMainThread();
double value;
if (_plugin->_ext._params->get_value(_plugin->_plugin, info.id, &value))
{
char buf[200];
if (_plugin->_ext._params->value_to_text(_plugin->_plugin, info.id, value, buf, sizeof(buf)))
{
flags |= kAudioUnitParameterFlag_HasName;
}
}

/*
* The CFString() used from the param can reset which releases it. So add a ref count
* and ask the param to release it too
*/
flags |= kAudioUnitParameterFlag_HasCFNameString | kAudioUnitParameterFlag_CFNameRelease;

outParameterInfo.flags = flags;
outParameterInfo.flags = f->AudioUnitFlags();

// according to the documentation, the name field should be zeroed. In fact, AULab does display anything then.
// strcpy(outParameterInfo.name, info.name);
Expand Down
Loading