Use PBD::sys::operator/ instead of PBD::sys::path::operator/= in ARDOUR::SessionDirectory
[ardour.git] / libs / ardour / audio_unit.cc
index bc63018ce618e414a7afe9c615d0da6688cced7a..dfcffb8cfed2288750ab9e86c59d58a47f673efa 100644 (file)
@@ -41,15 +41,8 @@ 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;
-       
+       unit (new CAAudioUnit)
+{                      
        OSErr err = CAAudioUnit::Open (*comp, *unit);
        if (err != noErr) {
                error << _("AudioUnit: Could not convert CAComponent to CAAudioUnit") << endmsg;
@@ -71,6 +64,14 @@ AUPlugin::~AUPlugin ()
        if (comp) {
                delete comp;
        }
+       
+       if (in_list) {
+               delete in_list;
+       }
+       
+       if (out_list) {
+               delete out_list;
+       }
 }
 
 AUPluginInfo::~AUPluginInfo ()
@@ -89,13 +90,13 @@ AUPlugin::unique_id () const
 const char *
 AUPlugin::label () const
 {
-       return "";
+       return "AUPlugin label";
 }
 
 const char *
 AUPlugin::maker () const
 {
-       return "";
+       return "AUplugin maker";
 }
 
 uint32_t
@@ -107,31 +108,40 @@ AUPlugin::parameter_count () const
 float
 AUPlugin::default_value (uint32_t port)
 {
-       return 0.0;
+       // AudioUnits don't have default values.  Maybe presets though?
+       return 0;
 }
 
-jack_nframes_t
-AUPlugin::latency () const
+nframes_t
+AUPlugin::signal_latency () const
 {
-       return 0;
+       if (_user_latency) {
+               return _user_latency;
+       }
+
+       return unit->Latency ();
 }
 
 void
 AUPlugin::set_parameter (uint32_t which, float val)
 {
-       
+       unit->SetParameter (parameter_map[which].first, parameter_map[which].second, 0, val);
 }
 
 float
 AUPlugin::get_parameter (uint32_t which) const
 {
-       return 0.0;
+       float outValue = 0.0;
+       
+       unit->GetParameter(parameter_map[which].first, parameter_map[which].second, 0, outValue);
+       
+       return outValue;
 }
 
 int
 AUPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor&) const
 {
-       return -1;
+       return 0;
 }
 
 uint32_t
@@ -143,25 +153,37 @@ AUPlugin::nth_parameter (uint32_t which, bool& ok) const
 void
 AUPlugin::activate ()
 {
-       
+       unit->GlobalReset ();
 }
 
 void
 AUPlugin::deactivate ()
 {
-       
+       // not needed.  GlobalReset () takes care of it.
 }
 
 void
-AUPlugin::set_block_size (jack_nframes_t nframes)
+AUPlugin::set_block_size (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)
+AUPlugin::connect_and_run (vector<Sample*>& bufs, uint32_t maxbuf, int32_t& in, int32_t& out, nframes_t nframes, nframes_t offset)
 {
-       return -1;
+       AudioUnitRenderActionFlags flags = 0;
+       AudioTimeStamp ts;
+       
+       AudioBufferList abl;
+       abl.mNumberBuffers = 1;
+       abl.mBuffers[0].mNumberChannels = 1;
+       abl.mBuffers[0].mDataByteSize = nframes * sizeof(Sample);
+       abl.mBuffers[0].mData = &bufs[0];
+       
+       
+       unit->Render (&flags, &ts, 0, 0, &abl);
+       
+       return 0;
 }
 
 set<uint32_t>
@@ -288,40 +310,32 @@ AUPluginInfo::discover ()
 {
        PluginInfoList plugs;
 
-       int numTypes = 2;    // this magic number was retrieved from the apple AUHost example.
-
        CAComponentDescription desc;
        desc.componentFlags = 0;
        desc.componentFlagsMask = 0;
        desc.componentSubType = 0;
        desc.componentManufacturer = 0;
+       desc.componentType = kAudioUnitType_Effect;
 
-       for (int i = 0; i < numTypes; ++i) {
-               if (i == 1) {
-                       desc.componentType = kAudioUnitType_MusicEffect;
-               } else {
-                       desc.componentType = kAudioUnitType_Effect;
-               }
+       Component comp = 0;
 
-               Component comp = 0;
-
-               comp = FindNextComponent (NULL, &desc);
-               while (comp != NULL) {
-                       CAComponentDescription temp;
-                       GetComponentInfo (comp, &temp, NULL, NULL, NULL);
-                       
-                       AUPluginInfoPtr plug(new AUPluginInfo);
-                       plug->name = AUPluginInfo::get_name (temp);
-                       plug->type = PluginInfo::AudioUnit;
-                       plug->n_inputs = 0;
-                       plug->n_outputs = 0;
-                       plug->category = "AudioUnit";
-                       plug->desc = new CAComponentDescription(temp);
-
-                       plugs.push_back(plug);
-                       
-                       comp = FindNextComponent (comp, &desc);
-               }
+       comp = FindNextComponent (NULL, &desc);
+       while (comp != NULL) {
+               CAComponentDescription temp;
+               GetComponentInfo (comp, &temp, NULL, NULL, NULL);
+               
+               AUPluginInfoPtr plug(new AUPluginInfo);
+               plug->name = AUPluginInfo::get_name (temp);
+               plug->type = ARDOUR::AudioUnit;
+               plug->n_inputs = 0;
+               plug->n_outputs = 0;
+               // plug->setup_nchannels (temp);
+               plug->category = "AudioUnit";
+               plug->desc = new CAComponentDescription(temp);
+
+               plugs.push_back(plug);
+               
+               comp = FindNextComponent (comp, &desc);
        }
 
        return plugs;
@@ -367,3 +381,21 @@ AUPluginInfo::get_name (CAComponentDescription& comp_desc)
        
        return CFStringRefToStdString(itemName);
 }
+
+void
+AUPluginInfo::setup_nchannels (CAComponentDescription& comp_desc)
+{
+       CAAudioUnit unit;
+       
+       CAAudioUnit::Open (comp_desc, unit);
+       
+       if (unit.SupportsNumChannels()) {
+               n_inputs = n_outputs = 0;
+       } else {
+               AUChannelInfo cinfo;
+               size_t info_size = sizeof(cinfo);
+               OSStatus err = AudioUnitGetProperty (unit.AU(), kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
+                                             0, &cinfo, &info_size);
+       }
+}
+