summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2008-05-13 18:54:21 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2008-05-13 18:54:21 +0000
commit49f73b561b4117131e2d2da001d9dd133846ef62 (patch)
treefee231c7b72c7c2a8a2637140c118115961862d4 /libs
parent65ddc52f4975179054902b3df8ea2b8b043d1513 (diff)
initial code for AU I/O config discovery (i hate you apple!)
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3346 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/appleutility/CAAudioUnit.cpp40
-rw-r--r--libs/ardour/ardour/audio_unit.h11
-rw-r--r--libs/ardour/audio_unit.cc104
3 files changed, 151 insertions, 4 deletions
diff --git a/libs/appleutility/CAAudioUnit.cpp b/libs/appleutility/CAAudioUnit.cpp
index 9244877d29..3d8a98476a 100644
--- a/libs/appleutility/CAAudioUnit.cpp
+++ b/libs/appleutility/CAAudioUnit.cpp
@@ -328,6 +328,46 @@ bool CAAudioUnit::CanDo ( int inChannelsIn,
return ValidateChannelPair (inChannelsIn, inChannelsOut, info.mChanInfo, (dataSize / sizeof (AUChannelInfo)));
}
+int CAAudioUnit::GetChannelInfo (AUChannelInfo** chaninfo, uint32_t& cnt)
+{
+ // this is the default assumption of an audio effect unit
+ Boolean* isWritable = 0;
+ UInt32 dataSize = 0;
+ // lets see if the unit has any channel restrictions
+ OSStatus result = AudioUnitGetPropertyInfo (AU(),
+ kAudioUnitProperty_SupportedNumChannels,
+ kAudioUnitScope_Global, 0,
+ &dataSize, isWritable); //don't care if this is writable
+
+ // if this property is NOT implemented an FX unit
+ // is expected to deal with same channel valance in and out
+
+ if (result)
+ {
+ if (Comp().Desc().IsEffect())
+ {
+ return 1;
+ }
+ else
+ {
+ // the au should either really tell us about this
+ // or we will assume the worst
+ return -1;
+ }
+ }
+
+ *chaninfo = (AUChannelInfo*) malloc (dataSize);
+ cnt = dataSize / sizeof (AUChannelInfo);
+
+ result = GetProperty (kAudioUnitProperty_SupportedNumChannels,
+ kAudioUnitScope_Global, 0,
+ *chaninfo, &dataSize);
+
+ if (result) { return -1; }
+ return 0;
+}
+
+
bool CAAudioUnit::ValidateChannelPair (int inChannelsIn,
int inChannelsOut,
const AUChannelInfo * info,
diff --git a/libs/ardour/ardour/audio_unit.h b/libs/ardour/ardour/audio_unit.h
index e5f6053c5b..98bda912f7 100644
--- a/libs/ardour/ardour/audio_unit.h
+++ b/libs/ardour/ardour/audio_unit.h
@@ -145,6 +145,10 @@ class AUPlugin : public ARDOUR::Plugin
typedef boost::shared_ptr<AUPlugin> AUPluginPtr;
+struct AUPluginCachedInfo {
+ std::vector<std::pair<int,int> > io_configs;
+};
+
class AUPluginInfo : public PluginInfo {
public:
AUPluginInfo (boost::shared_ptr<CAComponentDescription>);
@@ -162,6 +166,13 @@ class AUPluginInfo : public PluginInfo {
static void discover_music (PluginInfoList&);
static void discover_fx (PluginInfoList&);
static void discover_by_description (PluginInfoList&, CAComponentDescription&);
+
+ static std::map<std::string,AUPluginCachedInfo> cached_info;
+
+ static bool cached_io_configuration (std::string, CAComponentDescription&, AUPluginCachedInfo&);
+ static void add_cached_info (AUPluginCachedInfo&);
+ static void save_cached_info ();
+ static int load_cached_info ();
};
typedef boost::shared_ptr<AUPluginInfo> AUPluginInfoPtr;
diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc
index 74c9c23505..2e38f86be1 100644
--- a/libs/ardour/audio_unit.cc
+++ b/libs/ardour/audio_unit.cc
@@ -395,6 +395,23 @@ AUPlugin::_set_block_size (nframes_t nframes)
int32_t
AUPlugin::can_support_input_configuration (int32_t in)
{
+#ifdef NEWSTUFF
+ CAChannelHelper ch_in;
+ CAChannelHelper ch_out;
+
+ ch_in.nNumEls = input_elements;
+
+ for (uint32_t n = 0; n < input_elements; ++n) {
+ ch_in.mChans[n] = in;
+ }
+
+ /* don't check output */
+
+ ch_out.nNumEls = 0;
+
+ return unit->CanDo (ch_in, ch_out);
+
+#endif
streamFormat.mChannelsPerFrame = in;
/* apple says that for non-interleaved data, these
values always refer to a single channel.
@@ -834,11 +851,21 @@ AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescrip
info->type = ARDOUR::AudioUnit;
info->unique_id = stringify_descriptor (*info->descriptor);
-
- /* mark the plugin as having flexible i/o */
- info->n_inputs = -1;
- info->n_outputs = -1;
+ AUPluginCachedInfo cinfo;
+
+ if (cached_io_configuration (info->unique_id(), *info->descriptor, cinfo)) {
+
+ info->n_inputs = cinfo->in;
+ info->n_outputs = cinfo->out;
+
+ } else {
+
+ /* mark the plugin as having flexible i/o */
+
+ info->n_inputs = -1;
+ info->n_outputs = -1;
+ }
plugs.push_back (info);
@@ -846,6 +873,75 @@ AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescrip
}
}
+bool
+AUPluginInfo::cached_io_configuration (std::string unique_id, CAComponentDescriptor& descriptor, AUPluginCachedInfo& cinfo)
+{
+ CachedInfoMap::iterator cim = cached_info.find (unique_id);
+
+ if (cim != cached_info.end()) {
+ cinfo = *cim;
+ return true;
+ }
+
+ CAComponent comp (descriptor);
+ CAAudioUnit unit (comp);
+ AUChannelInfo* channel_info;
+ uint32_t cnt;
+ int ret;
+
+
+ if ((ret = unit.GetChannelInfo (&channel_info, cnt)) < 0) {
+ return false;
+ }
+
+ if (ret > 0) {
+ /* no explicit info available */
+
+ cinfo.io_configs.push_back (pair<int,int> (-1, -1));
+
+ } else {
+
+ /* store each configuration */
+
+ for (uint32_t n = 0; n < cnt; ++n) {
+ cinfo.io_configs.push_back (pair<int,int> (channel_info[n].inChannels,
+ channel_info[n].outChannels));
+ }
+
+ free (channel_info);
+ }
+
+
+ add_cached_info (unique_id, cinfo);
+ save_cached_info ();
+
+ return true;
+}
+
+void
+AUPluginInfo::add_cached_info (std::string id, AUPluginCachedInfo& cinfo)
+{
+ cached_info[id] = cinfo;
+}
+
+void
+AUPluginInfo::save_cached_info ()
+{
+ for (map<string,AUPluginCachedInfo>::iterator i = cached_info.begin(); i != cached_info.end(); ++i) {
+ cerr << i->first << ' ';
+ for (vector<pair<int, int> >::iterator j = i->second.io_configs.begin(); j != i->second.io_configs.end(); ++j) {
+ cerr << j->first << ' ' << j->second;
+ }
+ cerr << endl;
+ }
+}
+
+void
+AUPluginInfo::load_cached_info ()
+{
+
+}
+
void
AUPluginInfo::get_names (CAComponentDescription& comp_desc, std::string& name, Glib::ustring& maker)
{