From 56d5c7c713a8a170d9181111952c5fb792d879f6 Mon Sep 17 00:00:00 2001 From: Taybin Rutkin Date: Thu, 3 Aug 2006 21:19:34 +0000 Subject: [PATCH] Start using libappleutility More AudioUnit work git-svn-id: svn://localhost/ardour2/trunk@753 d708f5d6-7413-0410-9779-e7cbd77b26cf --- SConstruct | 9 +- gtk2_ardour/SConscript | 1 + gtk2_ardour/ardev_common.sh | 2 +- libs/ardour/SConscript | 3 + libs/ardour/ardour/audio_unit.h | 34 ++-- libs/ardour/ardour/plugin.h | 3 +- libs/ardour/audio_unit.cc | 333 ++++++++++++++++++++++++++++---- libs/ardour/plugin.cc | 42 ++++ libs/ardour/plugin_manager.cc | 44 +---- 9 files changed, 372 insertions(+), 99 deletions(-) diff --git a/SConstruct b/SConstruct index 91754b33a7..e93aad96a8 100644 --- a/SConstruct +++ b/SConstruct @@ -540,6 +540,10 @@ if env['SYSLIBS']: # libraries['flowcanvas'] = LibraryInfo(LIBS='flowcanvas', LIBPATH='#/libs/flowcanvas', CPPPATH='#libs/flowcanvas') libraries['soundtouch'] = LibraryInfo() libraries['soundtouch'].ParseConfig ('pkg-config --cflags --libs libSoundTouch') + + libraries['appleutility'] = LibraryInfo(LIBS='libappleutility', + LIBPATH='#libs/appleutility', + CPPPATH='#libs/appleutility') coredirs = [ 'templates' @@ -596,7 +600,10 @@ else: # libraries['libglademm'] = LibraryInfo(LIBS='libglademm', # LIBPATH='#libs/libglademm', # CPPPATH='#libs/libglademm') - + libraries['appleutility'] = LibraryInfo(LIBS='libappleutility', + LIBPATH='#libs/appleutility', + CPPPATH='#libs/appleutility') + coredirs = [ 'libs/soundtouch', 'templates' diff --git a/gtk2_ardour/SConscript b/gtk2_ardour/SConscript index d72e47843a..d004c9c4c6 100644 --- a/gtk2_ardour/SConscript +++ b/gtk2_ardour/SConscript @@ -59,6 +59,7 @@ if gtkardour['FFT_ANALYSIS']: if gtkardour['COREAUDIO']: gtkardour.Append(CCFLAGS='-DHAVE_COREAUDIO') + gtkardour.Merge([libraries['appleutility']]) skipped_files=Split(""" connection_editor.cc diff --git a/gtk2_ardour/ardev_common.sh b/gtk2_ardour/ardev_common.sh index ce3b1935c5..bf644f3e84 100755 --- a/gtk2_ardour/ardev_common.sh +++ b/gtk2_ardour/ardev_common.sh @@ -2,7 +2,7 @@ export ARDOUR_PATH=./glade:./pixmaps:. -export LD_LIBRARY_PATH=../libs/surfaces/control_protocol:../libs/ardour:../libs/midi++2:../libs/pbd:../libs/soundtouch:../libs/gtkmm2ext:../libs/sigc++2:../libs/glibmm2:../libs/gtkmm2/atk:../libs/gtkmm2/pango:../libs/gtkmm2/gdk:../libs/gtkmm2/gtk:../libs/libgnomecanvasmm:../libs/libsndfile:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=../libs/surfaces/control_protocol:../libs/ardour:../libs/midi++2:../libs/pbd:../libs/soundtouch:../libs/gtkmm2ext:../libs/sigc++2:../libs/glibmm2:../libs/gtkmm2/atk:../libs/gtkmm2/pango:../libs/gtkmm2/gdk:../libs/gtkmm2/gtk:../libs/libgnomecanvasmm:../libs/libsndfile:../libs/appleutility:$LD_LIBRARY_PATH # DYLD_LIBRARY_PATH is for darwin. export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript index 303f021f42..0c76699aef 100644 --- a/libs/ardour/SConscript +++ b/libs/ardour/SConscript @@ -209,6 +209,9 @@ ardour.Merge ([ if ardour['LIBLO']: ardour.Merge ([ libraries['lo'] ]) +if ardour['COREAUDIO']: + ardour.Merge ([ libraries['appleutility'] ]) + ardour.VersionBuild(['version.cc', 'ardour/version.h'], 'SConscript') def SharedAsmObjectEmitter(target, source, env): diff --git a/libs/ardour/ardour/audio_unit.h b/libs/ardour/ardour/audio_unit.h index 0d64e38ffc..f437ae053a 100644 --- a/libs/ardour/ardour/audio_unit.h +++ b/libs/ardour/ardour/audio_unit.h @@ -21,23 +21,31 @@ #ifndef __ardour_audio_unit_h__ #define __ardour_audio_unit_h__ +#include + #include +#include +#include +#include #include #include -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; @@ -60,7 +68,7 @@ class AUPlugin : public ARDOUR::Plugin 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; @@ -68,6 +76,9 @@ class AUPlugin : public ARDOUR::Plugin 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 get_presets (); @@ -75,23 +86,22 @@ class AUPlugin : public ARDOUR::Plugin bool has_editor () const; private: - boost::shared_ptr unit; + CAComponent* comp; + CAAudioUnit* unit; }; class AUPluginInfo : public PluginInfo { - public: - typedef boost::shared_ptr 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 AUPluginInfoPtr; diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index c0c8663244..6b11a975ca 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -187,8 +187,7 @@ class Plugin : public Stateful, public sigc::trackable vector controls; }; -/* this is actually defined in plugin_manager.cc */ -boost::shared_ptr find_plugin(ARDOUR::Session&, string name, long unique_id, PluginInfo::Type); +PluginPtr find_plugin(ARDOUR::Session&, string name, long unique_id, PluginInfo::Type); } // namespace ARDOUR diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index 1c6f9699dc..bc63018ce6 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -18,21 +18,270 @@ */ +#include +#include + +#include #include +#include #include +#include + #include #include +#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& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, jack_nframes_t nframes, jack_nframes_t offset) +{ + return -1; +} + +set +AUPlugin::automatable() const +{ + set 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 +AUPlugin::get_presets () +{ + vector 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 () @@ -41,7 +290,7 @@ 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; @@ -58,7 +307,7 @@ AUPluginInfo::discover () comp = FindNextComponent (NULL, &desc); while (comp != NULL) { - ComponentDescription temp; + CAComponentDescription temp; GetComponentInfo (comp, &temp, NULL, NULL, NULL); AUPluginInfoPtr plug(new AUPluginInfo); @@ -67,7 +316,7 @@ AUPluginInfo::discover () 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); @@ -78,43 +327,43 @@ AUPluginInfo::discover () 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); } diff --git a/libs/ardour/plugin.cc b/libs/ardour/plugin.cc index 6763e7f508..8ea95b8903 100644 --- a/libs/ardour/plugin.cc +++ b/libs/ardour/plugin.cc @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include @@ -240,3 +242,43 @@ Plugin::save_preset (string name, string domain) return true; } + +PluginPtr +ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::Type type) +{ + PluginManager *mgr = PluginManager::the_manager(); + PluginInfoList plugs; + + switch (type) { + case PluginInfo::LADSPA: + plugs = mgr->ladspa_plugin_info(); + break; + +#ifdef VST_SUPPORT + case PluginInfo::VST: + plugs = mgr->vst_plugin_info(); + unique_id = 0; // VST plugins don't have a unique id. + break; +#endif + +#ifdef HAVE_COREAUDIO + case PluginInfo::AudioUnit: + plugs = AUPluginInfo::discover (); + unique_id = 0; // Neither do AU. + break; +#endif + + default: + return PluginPtr ((Plugin *) 0); + } + + PluginInfoList::iterator i; + for (i = plugs.begin(); i != plugs.end(); ++i) { + if ((name == "" || (*i)->name == name) && + (unique_id == 0 || (*i)->unique_id == unique_id)) { + return (*i)->load (session); + } + } + + return PluginPtr ((Plugin*) 0); +} diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index 5225b18fc4..096696aca5 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -36,8 +36,10 @@ #include #include #include + +#ifdef VST_SUPPORT #include -#include +#endif #include #include @@ -275,46 +277,6 @@ PluginManager::ladspa_discover (string path) return 0; } -PluginPtr -ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::Type type) -{ - PluginManager *mgr = PluginManager::the_manager(); - PluginInfoList plugs; - - switch (type) { - case PluginInfo::LADSPA: - plugs = mgr->ladspa_plugin_info(); - break; - -#ifdef VST_SUPPORT - case PluginInfo::VST: - plugs = mgr->vst_plugin_info(); - unique_id = 0; // VST plugins don't have a unique id. - break; -#endif - -#ifdef HAVE_COREAUDIO - case PluginInfo::AudioUnit: - plugs = AUPluginInfo::discover (); - unique_id = 0; // Neither do AU. - break; -#endif - - default: - return PluginPtr ((Plugin *) 0); - } - - PluginInfoList::iterator i; - for (i = plugs.begin(); i != plugs.end(); ++i) { - if ((name == "" || (*i)->name == name) && - (unique_id == 0 || (*i)->unique_id == unique_id)) { - return (*i)->load (session); - } - } - - return PluginPtr ((Plugin*) 0); -} - string PluginManager::get_ladspa_category (uint32_t plugin_id) { -- 2.30.2