Start of AudioUnit work. COREAUDIO=y is a little destable for now.
authorTaybin Rutkin <taybin@taybin.com>
Mon, 31 Jul 2006 22:05:28 +0000 (22:05 +0000)
committerTaybin Rutkin <taybin@taybin.com>
Mon, 31 Jul 2006 22:05:28 +0000 (22:05 +0000)
git-svn-id: svn://localhost/ardour2/trunk@724 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/plugin_selector.cc
gtk2_ardour/plugin_selector.h
gtk2_ardour/sfdb_ui.cc
libs/ardour/SConscript
libs/ardour/ardour/audio_unit.h [new file with mode: 0644]
libs/ardour/ardour/plugin_manager.h
libs/ardour/ardour/utils.h
libs/ardour/audio_unit.cc [new file with mode: 0644]
libs/ardour/audiofilesource.cc
libs/ardour/plugin_manager.cc
libs/ardour/utils.cc

index a762a0b186ac282e527d7379fcb25669790380af..db63c285f18802336a3d61068f6530e805c546e1 100644 (file)
@@ -196,6 +196,10 @@ PluginSelector::input_refiller ()
 #ifdef VST_SUPPORT
        vmodel->clear();
 #endif
+
+#ifdef HAVE_COREAUDIO
+       aumodel->clear();
+#endif
        // Insert into GTK list
        for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
                snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
@@ -242,7 +246,40 @@ PluginSelector::vst_refiller ()
        }
        vmodel->set_sort_column (0, Gtk::SORT_ASCENDING);
 }
-#endif
+#endif //VST_SUPPORT
+
+#ifdef HAVE_COREAUDIO
+
+void
+PluginSelector::_au_refiller (void *arg)
+{
+       ((PluginSelector *) arg)->au_refiller ();
+}
+
+void
+PluginSelector::au_refiller ()
+{
+       guint row;
+//     list<PluginInfo *> &plugs = manager->au_plugin_info ();
+       list<PluginInfo *> &plugs;
+       list<PluginInfo *>::iterator i;
+       char ibuf[16], obuf[16];
+       
+       // Insert into GTK list
+       for (row = 0, i=plugs.begin(); i != plugs.end(); ++i, ++row) {
+
+               snprintf (ibuf, sizeof(ibuf)-1, "%d", (*i)->n_inputs);
+               snprintf (obuf, sizeof(obuf)-1, "%d", (*i)->n_outputs);         
+               
+               Gtk::TreeModel::Row newrow = *(amodel->append());
+               newrow[acols.name] = (*i)->name.c_str();
+               newrow[acols.ins] = ibuf;
+               newrow[acols.outs] = obuf;
+               newrow[acols.plugin] = *i;
+       }
+       amodel->set_sort_column (0, Gtk::SORT_ASCENDING);
+}
+#endif //HAVE_COREAUDIO
 
 void
 PluginSelector::use_plugin (PluginInfo* pi)
@@ -263,29 +300,44 @@ PluginSelector::use_plugin (PluginInfo* pi)
 void
 PluginSelector::btn_add_clicked()
 {
-       bool vst = notebook.get_current_page(); // 0 = LADSPA, 1 = VST
+       // 0 = LADSPA, 1 = VST, 2 = AU
+       unsigned int page = notebook.get_current_page(); 
        std::string name;
        ARDOUR::PluginInfo *pi;
        Gtk::TreeModel::Row newrow = *(amodel->append());
        
-       if (vst) {
+       Gtk::TreeModel::Row row;
+
+       switch (page) {
+               case 0:
+                       row = *(ladspa_display.get_selection()->get_selected());
+                       name = row[lcols.name];
+                       pi = row[lcols.plugin];
+                       added_plugins.push_back (row[lcols.plugin]);
+                       break;
+               case 1:
 #ifdef VST_SUPPORT
-               Gtk::TreeModel::Row row = *(vst_display.get_selection()->get_selected());
-               name = row[vcols.name];
-               pi = row[vcols.plugin];
-               added_plugins.push_back (row[vcols.plugin]);
+                       row = *(vst_display.get_selection()->get_selected());
+                       name = row[vcols.name];
+                       pi = row[vcols.plugin];
+                       added_plugins.push_back (row[vcols.plugin]);
 #endif
-       } else {
-               Gtk::TreeModel::Row row = *(ladspa_display.get_selection()->get_selected());
-               name = row[lcols.name];
-               pi = row[lcols.plugin];
-               added_plugins.push_back (row[lcols.plugin]);
+                       break;
+               case 2:
+#ifdef HAVE_COREAUDIO
+                       row = *(au_display.get_selection()->get_selected());
+                       name = row[aucols.name];
+                       pi = row[aucols.plugin];
+                       added_plugins.push_back (row[aucols.plugin]);
+#endif
+                       break;
        }
+
        newrow[acols.text] = name;
        newrow[acols.plugin] = pi;
 
        if (!amodel->children().empty()) {
-         set_response_sensitive (RESPONSE_APPLY, true);
+               set_response_sensitive (RESPONSE_APPLY, true);
        }
 }
 
@@ -313,6 +365,9 @@ PluginSelector::btn_update_clicked()
 #ifdef VST_SUPPORT
        vst_refiller ();
 #endif 
+#ifdef HAVE_COREAUDIO
+//     au_refiller ();
+#endif
 }
 
 #ifdef VST_SUPPORT
@@ -327,6 +382,18 @@ PluginSelector::vst_display_selection_changed()
 }
 #endif
 
+#ifdef HAVE_COREAUDIO
+void
+PluginSelector::vst_display_selection_changed()
+{
+  if (au_display.get_selection()->count_selected_rows() != 0) {
+    btn_add->set_sensitive (true);
+  } else {
+    btn_add->set_sensitive (false);
+  }
+}
+#endif
+
 void
 PluginSelector::ladspa_display_selection_changed()
 {
index 220de74871f501b9669d1effc6ae092f23d2bcef..25cba998dfa5910b0a1234ee03f2c04646c939f5 100644 (file)
@@ -104,7 +104,30 @@ class PluginSelector : public ArdourDialog
        static void _vst_refiller (void *);
        void vst_refiller ();
        void vst_display_selection_changed();
-#endif 
+#endif // VST_SUPPORT
+
+#ifdef HAVE_COREAUDIO
+       // page 3
+       struct AUColumns : public Gtk::TreeModel::ColumnRecord {
+               AUColumns () {
+                       add (name);
+                       add (ins);
+                       add (outs);
+                       add (plugin);
+               }
+               Gtk::TreeModelColumn<std::string> name;
+               Gtk::TreeModelColumn<std::string> ins;
+               Gtk::TreeModelColumn<std::string> outs;
+               Gtk::TreeModelColumn<ARDOUR::PluginInfo *> plugin;
+       };
+       AUColumns aucols;
+       Glib::RefPtr<Gtk::ListStore> aumodel;
+       Glib::RefPtr<Gtk::TreeSelection> auselection;
+       Gtk::TreeView au_display;
+       static void _au_refiller (void *);
+       void au_refiller ();
+       void au_display_selection_changed();
+#endif //HAVE_COREAUDIO
 
        ARDOUR::PluginInfo* i_selected_plug;
 
@@ -130,3 +153,4 @@ class PluginSelector : public ArdourDialog
 };
 
 #endif // __ardour_plugin_selector_h__
+
index 4948525b15bc04979ecc90f4004a2d0690bfc74a..d9ded04d2b063a934e85ef6a25dfc6994c472223 100644 (file)
@@ -98,7 +98,7 @@ SoundFileBox::SoundFileBox ()
        remove_field_btn.signal_clicked().connect
                        (mem_fun (*this, &SoundFileBox::remove_field_clicked));
        
-       Gtk::CellRendererText* cell(static_cast<Gtk::CellRendererText*>(field_view.get_column_cell_renderer(1)));
+       Gtk::CellRendererText* cell(dynamic_cast<Gtk::CellRendererText*>(field_view.get_column_cell_renderer(1)));
        cell->signal_edited().connect (mem_fun (*this, &SoundFileBox::field_edited));
 
        field_view.get_selection()->signal_changed().connect (mem_fun (*this, &SoundFileBox::field_selected));
index bca0a83d1eeac15e3de05f19cb8a59abdbc4578d..1c3092135382f54ac46c8c88fffe2269835bd595 100644 (file)
@@ -97,7 +97,7 @@ arch_specific_objects = [ ]
 
 osc_files = [ 'osc.cc' ]
 vst_files = [ 'vst_plugin.cc', 'session_vst.cc' ]
-coreaudio_files = [ 'coreaudiosource.cc' ]
+coreaudio_files = [ 'audio_unit.cc', 'coreaudiosource.cc' ]
 extra_sources = [ ]
 
 if ardour['VST']:
diff --git a/libs/ardour/ardour/audio_unit.h b/libs/ardour/ardour/audio_unit.h
new file mode 100644 (file)
index 0000000..88d311b
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+    Copyright (C) 2006 Paul Davis 
+       Written by Taybin Rutkin
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __ardour_audio_unit_h__
+#define __ardour_audio_unit_h__
+
+#include <ardour/plugin.h>
+
+namespace ARDOUR {
+
+class AudioUnit : public ARDOUR::Plugin
+{
+       
+};
+
+} // namespace ARDOUR
+
+#endif // __ardour_audio_unit_h__
\ No newline at end of file
index cc9a04738e6d704f3478e8cdfd0aa8184432726d..ca378dee98ffda8c5a4e398fdb7d16670bc47f9a 100644 (file)
@@ -23,6 +23,8 @@ class PluginManager {
 
        std::list<PluginInfo*> &vst_plugin_info () { return _vst_plugin_info; }
        std::list<PluginInfo*> &ladspa_plugin_info () { return _ladspa_plugin_info; }
+       std::list<PluginInfo*> &au_plugin_info () { return _au_plugin_info; }
+
        void refresh ();
 
        int add_ladspa_directory (std::string dirpath);
@@ -36,6 +38,7 @@ class PluginManager {
        ARDOUR::AudioEngine&   _engine;
        std::list<PluginInfo*> _vst_plugin_info;
        std::list<PluginInfo*> _ladspa_plugin_info;
+       std::list<PluginInfo*> _au_plugin_info;
        std::map<uint32_t, std::string> rdf_type;
 
        std::string ladspa_path;
@@ -55,6 +58,8 @@ class PluginManager {
        int ladspa_discover_from_path (std::string path);
        int ladspa_discover (std::string path);
 
+       int au_discover ();
+
        std::string get_ladspa_category (uint32_t id);
 
        static PluginManager* _manager; // singleton
@@ -63,3 +68,4 @@ class PluginManager {
 } /* namespace ARDOUR */
 
 #endif /* __ardour_plugin_manager_h__ */
+
index ad471085b5b225a7886e34e80c3ca736233be4fc..ee4482d26061cf8c880862cd7ea4c7b7c7d31b58 100644 (file)
 #include <string>
 #include <cmath>
 
+#ifdef HAVE_COREAUDIO
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
 #include "ardour.h"
 
 class XMLNode;
@@ -53,4 +57,8 @@ int touch_file(std::string path);
 std::string region_name_from_path (std::string path);
 std::string path_expand (std::string);
 
+#ifdef HAVE_COREAUDIO
+std::string CFStringRefToStdString(CFStringRef stringRef);
+#endif // HAVE_COREAUDIO
+
 #endif /* __ardour_utils_h__ */
diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc
new file mode 100644 (file)
index 0000000..5d7e7ae
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+    Copyright (C) 2006 Paul Davis 
+       Written by Taybin Rutkin
+       
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
index 29736a8677698a0495e074d737039cfb18fa82d2..d3d870865f4d911025743294717a15a7adf296ef 100644 (file)
@@ -238,25 +238,6 @@ AudioFileSource::create (const string& idstr, Flag flags)
 
 #endif // HAVE_COREAUDIO
 
-#ifdef HAVE_COREAUDIO
-std::string 
-CFStringRefToStdString(CFStringRef stringRef)
-{
-       CFIndex size = 
-               CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , 
-               kCFStringEncodingASCII);
-           char *buf = new char[size];
-       
-       std::string result;
-
-       if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
-           result = buf;
-       }
-       delete [] buf;
-       return result;
-}
-#endif // HAVE_COREAUDIO
-
 bool
 AudioFileSource::get_soundfile_info (string path, SoundFileInfo& _info, string& error_msg)
 {
index c8787a7d34522274e9b67ae7ef9465d4ee58483f..4be9b194688fa0865d58c0bc306b51f800f0746f 100644 (file)
@@ -27,7 +27,7 @@
 #include <fst.h>
 #include <pbd/basename.h>
 #include <string.h>
-#endif
+#endif // VST_SUPPORT
 
 #include <pbd/pathscanner.h>
 
 #include <pbd/error.h>
 #include <pbd/stl_delete.h>
 
+#ifdef HAVE_COREAUDIO
+#include <CoreServices/CoreServices.h>
+#include <AudioUnit/AudioUnit.h>
+#endif // HAVE_COREAUDIO
+
 #include "i18n.h"
 
 using namespace ARDOUR;
@@ -95,7 +100,11 @@ PluginManager::refresh ()
        if (Config->get_use_vst()) {
                vst_refresh ();
        }
-#endif
+#endif // VST_SUPPORT
+
+#ifdef HAVE_COREAUDIO
+       au_discover ();
+#endif // HAVE_COREAUDIO
 }
 
 void
@@ -302,10 +311,10 @@ PluginManager::load (Session& session, PluginInfo *info)
                        } else {
                                error << _("You asked ardour to not use any VST plugins") << endmsg;
                        }
-#else
+#else // !VST_SUPPORT
                        error << _("This version of ardour has no support for VST plugins") << endmsg;
                        return boost::shared_ptr<Plugin> ((Plugin*) 0);
-#endif                 
+#endif // !VST_SUPPORT
                                
                } else {
 
@@ -342,12 +351,15 @@ ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::T
                unique_id = 0; // VST plugins don't have a unique id.
                break;
        case PluginInfo::AudioUnit:
+               plugs = &mgr->au_plugin_info();
+               unique_id = 0;
+               break;
        default:
                return boost::shared_ptr<Plugin> ((Plugin *) 0);
        }
 
        for (i = plugs->begin(); i != plugs->end(); ++i) {
-               if ((name == ""     || (*i)->name == name) &&
+               if ((name == "" || (*i)->name == name) &&
                        (unique_id == 0 || (*i)->unique_id == unique_id)) {     
                        return mgr->load (session, *i);
                }
@@ -489,4 +501,102 @@ PluginManager::vst_discover (string path)
        return 0;
 }
 
-#endif
+#endif // VST_SUPPORT
+
+#ifdef HAVE_COREAUDIO
+
+int
+PluginManager::au_discover ()
+{
+       int mNumUnits = 0;
+       int numTypes = 2;    // this magic number was retrieved from the apple AUHost example.
+
+       ComponentDescription desc;
+       desc.componentFlags = 0;
+       desc.componentFlagsMask = 0;
+       desc.componentSubType = 0;
+       desc.componentManufacturer = 0;
+
+       for (int i = 0; i < numTypes; ++i) {
+               if (i == 1) {
+                       desc.componentType = kAudioUnitType_MusicEffect;
+               } else {
+                       desc.componentType = kAudioUnitType_Effect;
+               }
+
+               int n = CountComponents (&desc);
+
+               mNumUnits += n;
+       }
+       cout << "Number of AU plugins: " << mNumUnits << endl;
+
+       ComponentDescription* mCompDescs = new ComponentDescription[mNumUnits];
+
+       int n = 0;
+       for (int i = 0; i < numTypes; ++i)
+       {
+               if (i == 1) {
+                       desc.componentType = kAudioUnitType_MusicEffect;
+               } else {
+                       desc.componentType = kAudioUnitType_Effect;
+               }
+               
+               Component comp = 0;
+
+               comp = FindNextComponent (NULL, &desc);
+               while (comp != NULL) {
+                       ComponentDescription temp;
+                       GetComponentInfo (comp, &temp, NULL, NULL, NULL);
+                       mCompDescs[n++] = temp;
+                       comp = FindNextComponent (comp, &desc);
+               }
+       }
+
+       for (int i = 0; i < mNumUnits; ++i) {
+
+               // the following large block is just for determining the name of the plugin.
+               CFStringRef itemName = NULL;
+               // Marc Poirier -style item name
+               Component auComponent = FindNextComponent (0, &(mCompDescs[i]));
+               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());
+                                       }
+                               }
+                               DisposeHandle(nameHandle);
+                       }
+               }
+               
+               // if Marc-style fails, do the original way
+               if (itemName == NULL) {
+                       CFStringRef compTypeString = UTCreateStringForOSType(mCompDescs[i].componentType);
+                       CFStringRef compSubTypeString = UTCreateStringForOSType(mCompDescs[i].componentSubType);
+                       CFStringRef compManufacturerString = UTCreateStringForOSType(mCompDescs[i].componentManufacturer);
+                       
+                       itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"), 
+                               compTypeString, compManufacturerString, compSubTypeString);
+
+                       if (compTypeString != NULL)
+                               CFRelease(compTypeString);
+                       if (compSubTypeString != NULL)
+                               CFRelease(compSubTypeString);
+                       if (compManufacturerString != NULL)
+                               CFRelease(compManufacturerString);
+               }
+               string realname = CFStringRefToStdString(itemName);
+               cout << realname << endl;       
+       }
+
+       delete[] mCompDescs;
+
+       return 0;
+}
+
+#endif // HAVE_COREAUDIO
+
index f02163902865a76c412556250a2c71e78282fe48..a7da7a914e3ad196e9401b3438303cf33a991b87 100644 (file)
@@ -253,3 +253,21 @@ path_expand (string path)
 #endif
 }
 
+#ifdef HAVE_COREAUDIO
+string 
+CFStringRefToStdString(CFStringRef stringRef)
+{
+       CFIndex size = 
+               CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , 
+               kCFStringEncodingASCII);
+           char *buf = new char[size];
+       
+       std::string result;
+
+       if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingASCII)) {
+           result = buf;
+       }
+       delete [] buf;
+       return result;
+}
+#endif // HAVE_COREAUDIO