10#define CDEBUG(...) Ase::debug ("clap", __VA_ARGS__)
11#define CDEBUG_ENABLED() Ase::debug_key_enabled ("clap")
17 ClapDeviceImplP device_;
18 clap_id param_id = CLAP_INVALID_ID;
20 String ident_, label_, module_;
21 double min_value = NAN, max_value = NAN, default_value = NAN;
27 double get_min ()
const override {
return min_value; }
28 double get_max ()
const override {
return max_value; }
29 double get_step ()
const override {
return is_stepped() ? 1 : 0; }
31 bool is_stepped ()
const {
return strstr (
hints().c_str(),
":stepped:"); }
36 param_id = info.param_id;
40 module_ = info.module;
41 min_value = info.min_value;
42 max_value = info.max_value;
43 default_value = info.default_value;
49 const bool down = ma < mi;
53 for (
double d = mi; down ? d > ma : d < ma; d += down ? -1 : +1) {
60 get_metadata ()
const override
63 md.
push_back (
"hints=" + ClapParamInfo::hints_from_param_info_flags (flags));
73 return (value - mi) / (ma - mi);
79 const double value = v * (ma - mi) + mi;
86 device_->handle_->param_get_value (param_id, &txt);
92 return device_->handle_->param_set_value (param_id, vstr);
97 return Value (device_->handle_->param_get_value (param_id));
102 return device_->handle_->param_set_value (param_id, val.
as_double());
107ClapDeviceImpl::ClapDeviceImpl (ClapPluginHandleP claphandle) :
111 paramschange_ = on_event (
"params:change", [
this] (
const Event &event) {
112 proc_params_change (event);
115 handle_->_set_parent (
this);
118ClapDeviceImpl::~ClapDeviceImpl()
121 handle_->_set_parent (
nullptr);
128ClapDeviceImpl::get_device_path ()
131 NativeDevice *parent =
dynamic_cast<NativeDevice*
> (this->
_parent());
132 for (Device *dev =
this; parent; dev = parent, parent =
dynamic_cast<NativeDevice*
> (dev->_parent()))
134 ssize_t index = Aux::index_of (parent->get_devices(),
135 [dev] (
const DeviceP &e) { return dev == &*e; });
142 if (project && track)
143 s =
string_format (
"t%ud%s", project->track_index (*track), s);
153 handle_->save_state (xs, get_device_path());
154 if (xs.
in_load() && handle_ && !handle_->clap_activated())
155 handle_->load_state (xs);
161 return clap_device_info (handle_->descriptor);
168 ClapDeviceImplP selfp = shared_ptr_cast<ClapDeviceImpl> (
this);
169 PropertyS properties;
172 auto aseprop = handle_->param_get_property (pinfo.param_id);
174 properties.push_back (aseprop);
178 handle_->param_set_property (prop->param_id, prop);
179 properties.push_back (prop);
186ClapDeviceImpl::proc_params_change (
const Event &event)
189 handle_->params_changed();
196 ClapDeviceImplP selfp = shared_ptr_cast<ClapDeviceImpl> (
this);
198 if (!parent && handle_)
200 handle_->destroy_gui();
201 handle_->clap_deactivate();
210 handle_->clap_activate();
216 if (handle_->gui_visible())
218 else if (handle_->supports_gui())
225 return handle_->supports_gui();
231 return handle_->gui_visible();
235ClapDeviceImpl::list_clap_plugins ()
237 static DeviceInfoS devs;
242 if (!descriptor->version.empty())
243 title = title +
" " + descriptor->version;
244 if (!descriptor->vendor.empty())
245 title = title +
" - " + descriptor->vendor;
246 devs.
push_back (clap_device_info (*descriptor));
254 return handle_->audio_processor();
258ClapDeviceImpl::_set_event_source (AudioProcessorP esource)
270ClapDeviceImpl::clap_version ()
272 const String clapversion =
string_format (
"%u.%u.%u", CLAP_VERSION.major, CLAP_VERSION.minor, CLAP_VERSION.revision);
277ClapDeviceImpl::access_clap_handle (DeviceP device)
279 ClapDeviceImpl *clapdevice =
dynamic_cast<ClapDeviceImpl*
> (&*device);
280 return clapdevice ? clapdevice->handle_ :
nullptr;
284ClapDeviceImpl::create_clap_device (AudioEngine &engine,
const String &clapuri)
288 ClapPluginDescriptor *descriptor =
nullptr;
289 for (ClapPluginDescriptor *desc : ClapPluginDescriptor::collect_descriptors())
290 if (clapid == desc->id) {
296 auto make_clap_device = [&descriptor] (
const String &aseid, AudioProcessor::StaticInfo static_info, AudioProcessorP aproc) -> DeviceP {
297 ClapPluginHandleP handlep = ClapPluginHandle::make_clap_handle (*descriptor, aproc);
298 return ClapDeviceImpl::make_shared (handlep);
300 DeviceP devicep = AudioProcessor::registry_create (ClapPluginHandle::audio_processor_type(), engine, make_clap_device);
301 ClapDeviceImplP clapdevicep = shared_ptr_cast<ClapDeviceImpl> (devicep);
void _disconnect_remove() override
Disconnect the device and remove all object references.
DeviceInfo device_info() override
Describe this Device type.
PropertyS access_properties() override
Retrieve handles for all properties.
void gui_toggle() override
Toggle GUI display.
void _activate() override
Add AudioProcessor to the Engine and start processing.
bool gui_visible() override
Is GUI currently visible.
AudioProcessorP _audio_processor() const override
Retrieve the corresponding AudioProcessor.
void _set_parent(GadgetImpl *parent) override
Assign parent container.
bool gui_supported() override
Has GUI display facilities.
void serialize(WritNode &xs) override
Serialize members and childern.
void _set_parent(GadgetImpl *parent) override
Assign parent container.
Track * _track() const
Find Track in parent ancestry.
Implementation type for classes with Event subscription.
Base type for classes that have a Property.
GadgetImpl * _parent() const override
Retrieve parent container.
ProjectImpl * _project() const
Find Project in parent ancestry.
A Property allows querying, setting and monitoring of an object property.
String hints() const
Hints for parameter handling (metadata).
virtual void serialize(WritNode &xs)=0
Serialize members and childern.
One entry in a Writ serialization document.
bool in_load() const
Return true during deserialization.
bool in_save() const
Return true during serialization.
#define assert_return(expr,...)
Return from the current function if expr is unmet and issue an assertion warning.
#define return_unless(cond,...)
Return silently if cond does not evaluate to true with return value ...
The Anklang C++ API namespace.
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
String string_join(const String &junctor, const StringS &strvec)
String parameter_guess_nick(const String ¶meter_label)
Create a few letter nick name from a multi word parameter label.
String string_from_int(int64 value)
Convert a 64bit signed integer into a string.
std::string String
Convenience alias for std::string.
bool string_startswith(const String &string, const String &fragment)
Returns whether string starts with fragment.
String get_text() const override
Get the current property value, converted to a text String.
bool is_numeric() const override
Whether the property settings can be represented as a floating point number.
Value get_value() const override
Get the native property value.
bool set_normalized(double v) override
Set the normalized property value as double.
ChoiceS choices() const override
Enumerate choices for choosable properties.
bool set_text(String vstr) override
Set the current property value as a text String.
double get_min() const override
Get the minimum property value, converted to double.
bool set_value(const Value &val) override
Set the native property value.
String nick() const override
Abbreviated user interface name, usually not more than 6 characters.
String label() const override
Preferred user interface name.
String ident() const override
Unique name (per owner) of this Property.
double get_max() const override
Get the maximum property value, converted to double.
double get_normalized() const override
Get the normalized property value, converted to double.
double get_step() const override
Get the property value stepping, converted to double.
String unit() const override
Units of the values within range.
void reset() override
Assign default as normalized property value.
Structure for callback based notifications.
Value type used to interface with various property types.
double as_double() const
Convert Value to double or return 0.