#ifndef __ardour_audio_unit_h__
#define __ardour_audio_unit_h__
+#include <stdint.h>
+
#include <list>
+#include <set>
+#include <string>
+#include <vector>
#include <ardour/plugin.h>
#include <boost/shared_ptr.hpp>
-struct ComponentDescription;
+class CAComponent;
+class CAAudioUnit;
+class CAComponentDescription;
namespace ARDOUR {
-class CAAudioUnit;
+class AudioEngine;
+class Session;
class AUPlugin : public ARDOUR::Plugin
{
public:
- AUPlugin (AudioEngine& engine, Session& session) : Plugin(engine, session) {};
- virtual ~AUPlugin () {};
+ AUPlugin (AudioEngine& engine, Session& session, CAComponent* comp);
+ virtual ~AUPlugin ();
uint32_t unique_id () const;
const char * label () const;
void store_state (ARDOUR::PluginState&);
void restore_state (ARDOUR::PluginState&);
string describe_parameter (uint32_t);
- string state_node_name () const;
+ string state_node_name () const { return "audiounit"; }
void print_parameter (uint32_t, char*, uint32_t len) const;
bool parameter_is_audio (uint32_t) const;
bool parameter_is_input (uint32_t) const;
bool parameter_is_output (uint32_t) const;
+ XMLNode& get_state();
+ int set_state(const XMLNode& node);
+
bool save_preset (string name);
bool load_preset (const string preset_label);
std::vector<std::string> get_presets ();
bool has_editor () const;
private:
- boost::shared_ptr<CAAudioUnit> unit;
+ CAComponent* comp;
+ CAAudioUnit* unit;
};
class AUPluginInfo : public PluginInfo {
- public:
- typedef boost::shared_ptr<ComponentDescription> CompDescPtr;
-
+ public:
AUPluginInfo () { };
- ~AUPluginInfo () { };
+ ~AUPluginInfo ();
- CompDescPtr desc;
+ CAComponentDescription* desc;
static PluginInfoList discover ();
PluginPtr load (Session& session);
private:
- static std::string get_name (ComponentDescription&);
+ static std::string get_name (CAComponentDescription&);
};
typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
*/
+#include <pbd/transmitter.h>
+#include <pbd/xml++.h>
+
+#include <ardour/audioengine.h>
#include <ardour/audio_unit.h>
+#include <ardour/session.h>
#include <ardour/utils.h>
+#include <appleutility/CAAudioUnit.h>
+
#include <CoreServices/CoreServices.h>
#include <AudioUnit/AudioUnit.h>
+#include "i18n.h"
+
+using namespace std;
+using namespace PBD;
using namespace ARDOUR;
-PluginPtr
-AUPluginInfo::load (Session& session)
+AUPlugin::AUPlugin (AudioEngine& engine, Session& session, CAComponent* _comp)
+ :
+ Plugin (engine, session),
+ comp (_comp),
+ unit (0)
+{
+ if (!unit->IsValid()) {
+ error << _("AudioUnit: Not a proper AudioUnit plugin") << endmsg;
+ throw failed_constructor ();
+ }
+
+ unit = new CAAudioUnit;
+
+ OSErr err = CAAudioUnit::Open (*comp, *unit);
+ if (err != noErr) {
+ error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
+ delete unit;
+ delete comp;
+ throw failed_constructor ();
+ }
+
+ unit->Initialize ();
+}
+
+AUPlugin::~AUPlugin ()
+{
+ if (unit) {
+ unit->Uninitialize ();
+ delete unit;
+ }
+
+ if (comp) {
+ delete comp;
+ }
+}
+
+AUPluginInfo::~AUPluginInfo ()
+{
+ if (desc) {
+ delete desc;
+ }
+}
+
+uint32_t
+AUPlugin::unique_id () const
+{
+ return 0;
+}
+
+const char *
+AUPlugin::label () const
+{
+ return "";
+}
+
+const char *
+AUPlugin::maker () const
+{
+ return "";
+}
+
+uint32_t
+AUPlugin::parameter_count () const
+{
+ return 0;
+}
+
+float
+AUPlugin::default_value (uint32_t port)
+{
+ return 0.0;
+}
+
+jack_nframes_t
+AUPlugin::latency () const
+{
+ return 0;
+}
+
+void
+AUPlugin::set_parameter (uint32_t which, float val)
+{
+
+}
+
+float
+AUPlugin::get_parameter (uint32_t which) const
+{
+ return 0.0;
+}
+
+int
+AUPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const
+{
+ return -1;
+}
+
+uint32_t
+AUPlugin::nth_parameter (uint32_t which, bool& ok) const
+{
+ return 0;
+}
+
+void
+AUPlugin::activate ()
{
- return PluginPtr((AUPlugin*)0);
}
+void
+AUPlugin::deactivate ()
+{
+
+}
+
+void
+AUPlugin::set_block_size (jack_nframes_t nframes)
+{
+
+}
+
+int
+AUPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, jack_nframes_t nframes, jack_nframes_t offset)
+{
+ return -1;
+}
+
+set<uint32_t>
+AUPlugin::automatable() const
+{
+ set<uint32_t> automates;
+
+ return automates;
+}
+
+void
+AUPlugin::store_state (ARDOUR::PluginState&)
+{
+
+}
+
+void
+AUPlugin::restore_state (ARDOUR::PluginState&)
+{
+
+}
+
+string
+AUPlugin::describe_parameter (uint32_t)
+{
+ return "";
+}
+
+void
+AUPlugin::print_parameter (uint32_t, char*, uint32_t len) const
+{
+
+}
+
+bool
+AUPlugin::parameter_is_audio (uint32_t) const
+{
+ return false;
+}
+
+bool
+AUPlugin::parameter_is_control (uint32_t) const
+{
+ return false;
+}
+
+bool
+AUPlugin::parameter_is_input (uint32_t) const
+{
+ return false;
+}
+
+bool
+AUPlugin::parameter_is_output (uint32_t) const
+{
+ return false;
+}
+
+XMLNode&
+AUPlugin::get_state()
+{
+ XMLNode* root = new XMLNode (state_node_name());
+
+ return *root;
+}
+
+int
+AUPlugin::set_state(const XMLNode& node)
+{
+ return -1;
+}
+
+bool
+AUPlugin::save_preset (string name)
+{
+ return false;
+}
+
+bool
+AUPlugin::load_preset (const string preset_label)
+{
+ return false;
+}
+
+vector<string>
+AUPlugin::get_presets ()
+{
+ vector<string> presets;
+
+ return presets;
+}
+
+bool
+AUPlugin::has_editor () const
+{
+ return false;
+}
+
+PluginPtr
+AUPluginInfo::load (Session& session)
+{
+ try {
+ PluginPtr plugin;
+
+ CAComponent* comp = new CAComponent(*desc);
+
+ if (!comp->IsValid()) {
+ error << ("AudioUnit: not a valid Component") << endmsg;
+ } else {
+ plugin.reset (new AUPlugin (session.engine(), session, comp));
+ }
+
+ plugin->set_info(PluginInfoPtr(new AUPluginInfo(*this)));
+ return plugin;
+ }
+
+ catch (failed_constructor &err) {
+ return PluginPtr ((Plugin*) 0);
+ }
+}
PluginInfoList
AUPluginInfo::discover ()
int numTypes = 2; // this magic number was retrieved from the apple AUHost example.
- ComponentDescription desc;
+ CAComponentDescription desc;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
desc.componentSubType = 0;
comp = FindNextComponent (NULL, &desc);
while (comp != NULL) {
- ComponentDescription temp;
+ CAComponentDescription temp;
GetComponentInfo (comp, &temp, NULL, NULL, NULL);
AUPluginInfoPtr plug(new AUPluginInfo);
plug->n_inputs = 0;
plug->n_outputs = 0;
plug->category = "AudioUnit";
- plug->desc = CompDescPtr(new ComponentDescription(temp));
+ plug->desc = new CAComponentDescription(temp);
plugs.push_back(plug);
return plugs;
}
-std::string
-AUPluginInfo::get_name (ComponentDescription& comp_desc)
-{
- CFStringRef itemName = NULL;
- // Marc Poirier -style item name
- Component auComponent = FindNextComponent (0, &comp_desc);
- if (auComponent != NULL) {
- ComponentDescription dummydesc;
- Handle nameHandle = NewHandle(sizeof(void*));
- if (nameHandle != NULL) {
- OSErr err = GetComponentInfo(auComponent, &dummydesc, nameHandle, NULL, NULL);
- if (err == noErr) {
- ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
- if (nameString != NULL) {
- itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
- }
+string
+AUPluginInfo::get_name (CAComponentDescription& comp_desc)
+{
+ CFStringRef itemName = NULL;
+ // Marc Poirier -style item name
+ CAComponent auComponent (comp_desc);
+ if (auComponent.IsValid()) {
+ CAComponentDescription dummydesc;
+ Handle nameHandle = NewHandle(sizeof(void*));
+ if (nameHandle != NULL) {
+ OSErr err = GetComponentInfo(auComponent.Comp(), &dummydesc, nameHandle, NULL, NULL);
+ if (err == noErr) {
+ ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
+ if (nameString != NULL) {
+ itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
}
- DisposeHandle(nameHandle);
}
+ DisposeHandle(nameHandle);
}
-
- // if Marc-style fails, do the original way
- if (itemName == NULL) {
- CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
- CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
- CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
-
- itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
- compTypeString, compManufacturerString, compSubTypeString);
-
- if (compTypeString != NULL)
- CFRelease(compTypeString);
- if (compSubTypeString != NULL)
- CFRelease(compSubTypeString);
- if (compManufacturerString != NULL)
- CFRelease(compManufacturerString);
- }
-
- return CFStringRefToStdString(itemName);
+ }
+
+ // if Marc-style fails, do the original way
+ if (itemName == NULL) {
+ CFStringRef compTypeString = UTCreateStringForOSType(comp_desc.componentType);
+ CFStringRef compSubTypeString = UTCreateStringForOSType(comp_desc.componentSubType);
+ CFStringRef compManufacturerString = UTCreateStringForOSType(comp_desc.componentManufacturer);
+
+ itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"),
+ compTypeString, compManufacturerString, compSubTypeString);
+
+ if (compTypeString != NULL)
+ CFRelease(compTypeString);
+ if (compSubTypeString != NULL)
+ CFRelease(compSubTypeString);
+ if (compManufacturerString != NULL)
+ CFRelease(compManufacturerString);
+ }
+
+ return CFStringRefToStdString(itemName);
}