X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Faudio_unit.cc;h=89aa99bac8f5f903f98d0b81b7d63c6d72618982;hb=e0012e1b88a6a26ebaf0038f40975779480b1453;hp=6b6d7ae3176417530977cdd67760752a02979ca9;hpb=5f1ff657c2f0324fcdcd539b9775382c001b965c;p=ardour.git diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index 6b6d7ae317..89aa99bac8 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -31,7 +31,7 @@ #include "pbd/pathscanner.h" #include "pbd/locale_guard.h" -#include +#include #include #include @@ -43,6 +43,7 @@ #include "ardour/filesystem_paths.h" #include "ardour/io.h" #include "ardour/audio_unit.h" +#include "ardour/route.h" #include "ardour/session.h" #include "ardour/tempo.h" #include "ardour/utils.h" @@ -783,6 +784,10 @@ AUPlugin::set_parameter (uint32_t which, float val) return; } + if (get_parameter(which) == val) { + return; + } + const AUParameterDescriptor& d (descriptors[which]); DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("set parameter %1 in scope %2 element %3 to %4\n", d.id, d.scope, d.element, val)); unit->SetParameter (d.id, d.scope, d.element, val); @@ -809,7 +814,7 @@ AUPlugin::get_parameter (uint32_t which) const float val = 0.0; if (which < descriptors.size()) { const AUParameterDescriptor& d (descriptors[which]); - DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("get value of parameter %1 in scope %2 element %3\n", d.id, d.scope, d.element)); + // DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("get value of parameter %1 in scope %2 element %3\n", d.id, d.scope, d.element)); unit->GetParameter(d.id, d.scope, d.element, val); } return val; @@ -1019,7 +1024,8 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out) con vector >& io_configs = pinfo->cache.io_configs; - DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 has %2 IO configurations\n", name(), io_configs.size())); + DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 has %2 IO configurations, looking for %3 in, %4 out\n", + name(), io_configs.size(), in, out)); //Ardour expects the plugin to tell it the output //configuration but AU plugins can have multiple I/O @@ -1034,7 +1040,13 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out) con int32_t possible_out = i->second; if ((possible_in == audio_in) && (possible_out == audio_out)) { - DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("\tCHOSEN: in %1 out %2\n", in, out)); + DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("\tCHOSEN: %1 in %2 out to match in %3 out %4\n", + possible_in, possible_out, + in, out)); + + out.set (DataType::MIDI, 0); + out.set (DataType::AUDIO, audio_out); + return 1; } } @@ -1072,8 +1084,21 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out) con audio_out = 2; found = true; } else if (possible_out < -2) { - /* explicitly variable number of outputs, pick maximum */ - audio_out = -possible_out; + /* explicitly variable number of outputs. + + Since Ardour can handle any configuration, + we have to somehow pick a number. + + We'll use the number of inputs + to the master bus, or 2 if there + is no master bus. + */ + boost::shared_ptr master = _session.master_out(); + if (master) { + audio_out = master->input()->n_ports().n_audio(); + } else { + audio_out = 2; + } found = true; } else { /* exact number of outputs */ @@ -1136,6 +1161,7 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out) con /* request is too large */ } + if (possible_out == -1) { /* any output configuration possible, provide stereo out */ audio_out = 2; @@ -1147,8 +1173,21 @@ AUPlugin::can_support_io_configuration (const ChanCount& in, ChanCount& out) con audio_out = 2; found = true; } else if (possible_out < -2) { - /* explicitly variable number of outputs, pick maximum */ - audio_out = -possible_out; + /* explicitly variable number of outputs. + + Since Ardour can handle any configuration, + we have to somehow pick a number. + + We'll use the number of inputs + to the master bus, or 2 if there + is no master bus. + */ + boost::shared_ptr master = _session.master_out(); + if (master) { + audio_out = master->input()->n_ports().n_audio(); + } else { + audio_out = 2; + } found = true; } else { /* exact number of outputs */ @@ -1300,9 +1339,14 @@ AUPlugin::connect_and_run (BufferSet& bufs, ChanMapping in_map, ChanMapping out_ _last_nframes = nframes; } + DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 in %2 out %3 MIDI %4 bufs %5 (available %6)\n", + name(), input_channels, output_channels, _has_midi_input, + bufs.count(), bufs.available())); + /* the apparent number of buffers matches our input configuration, but we know that the bufferset has the capacity to handle our outputs. */ + assert (bufs.available() >= ChanCount (DataType::AUDIO, output_channels)); input_buffers = &bufs; @@ -1310,10 +1354,6 @@ AUPlugin::connect_and_run (BufferSet& bufs, ChanMapping in_map, ChanMapping out_ input_offset = offset; cb_offset = 0; - DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 in %2 out %3 MIDI %4 bufs %5 (available %6)\n", - name(), input_channels, output_channels, _has_midi_input, - bufs.count(), bufs.available())); - buffers->mNumberBuffers = output_channels; for (int32_t i = 0; i < output_channels; ++i) { @@ -1321,8 +1361,10 @@ AUPlugin::connect_and_run (BufferSet& bufs, ChanMapping in_map, ChanMapping out_ buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample); /* setting this to 0 indicates to the AU that it can provide buffers here if necessary. if it can process in-place, it will use the buffers provided - as input by ::render_callback() above. no documentation on what setting it - to a non-null value means. + as input by ::render_callback() above. + + a non-null values tells the plugin to render into the buffer pointed + at by the value. */ buffers->mBuffers[i].mData = 0; } @@ -1357,8 +1399,8 @@ AUPlugin::connect_and_run (BufferSet& bufs, ChanMapping in_map, ChanMapping out_ ts.mSampleTime = frames_processed; ts.mFlags = kAudioTimeStampSampleTimeValid; - // DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 render flags=%2 time=%3 nframes=%4 buffers=%5\n", - // name(), flags, frames_processed, nframes, buffers->mNumberBuffers)); + DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1 render flags=%2 time=%3 nframes=%4 buffers=%5\n", + name(), flags, frames_processed, nframes, buffers->mNumberBuffers)); if ((err = unit->Render (&flags, &ts, 0, nframes, buffers)) == noErr) { @@ -2099,7 +2141,7 @@ AUPlugin::find_presets () for (FactoryPresetMap::iterator i = factory_preset_map.begin(); i != factory_preset_map.end(); ++i) { /* XXX: dubious */ string const uri = string_compose ("%1", _presets.size ()); - _presets.insert (make_pair (uri, Plugin::PresetRecord (uri, i->first))); + _presets.insert (make_pair (uri, Plugin::PresetRecord (uri, i->first, i->second))); } #endif @@ -2155,7 +2197,7 @@ AUPluginInfo::load (Session& session) Glib::ustring AUPluginInfo::au_cache_path () { - return Glib::build_filename (ARDOUR::user_config_directory().to_string(), "au_cache"); + return Glib::build_filename (ARDOUR::user_config_directory(), "au_cache"); } PluginInfoList* @@ -2715,6 +2757,26 @@ AUPlugin::listen_to_parameter (uint32_t param_id) return -1; } + event.mEventType = kAudioUnitEvent_BeginParameterChangeGesture; + event.mArgument.mParameter.mAudioUnit = unit->AU(); + event.mArgument.mParameter.mParameterID = descriptors[param_id].id; + event.mArgument.mParameter.mScope = descriptors[param_id].scope; + event.mArgument.mParameter.mElement = descriptors[param_id].element; + + if (AUEventListenerAddEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) { + return -1; + } + + event.mEventType = kAudioUnitEvent_EndParameterChangeGesture; + event.mArgument.mParameter.mAudioUnit = unit->AU(); + event.mArgument.mParameter.mParameterID = descriptors[param_id].id; + event.mArgument.mParameter.mScope = descriptors[param_id].scope; + event.mArgument.mParameter.mElement = descriptors[param_id].element; + + if (AUEventListenerAddEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) { + return -1; + } + return 0; } @@ -2737,6 +2799,26 @@ AUPlugin::end_listen_to_parameter (uint32_t param_id) return -1; } + event.mEventType = kAudioUnitEvent_BeginParameterChangeGesture; + event.mArgument.mParameter.mAudioUnit = unit->AU(); + event.mArgument.mParameter.mParameterID = descriptors[param_id].id; + event.mArgument.mParameter.mScope = descriptors[param_id].scope; + event.mArgument.mParameter.mElement = descriptors[param_id].element; + + if (AUEventListenerRemoveEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) { + return -1; + } + + event.mEventType = kAudioUnitEvent_EndParameterChangeGesture; + event.mArgument.mParameter.mAudioUnit = unit->AU(); + event.mArgument.mParameter.mParameterID = descriptors[param_id].id; + event.mArgument.mParameter.mScope = descriptors[param_id].scope; + event.mArgument.mParameter.mElement = descriptors[param_id].element; + + if (AUEventListenerRemoveEventType (_parameter_listener, _parameter_listener_arg, &event) != noErr) { + return -1; + } + return 0; } @@ -2749,9 +2831,23 @@ AUPlugin::_parameter_change_listener (void* arg, void* src, const AudioUnitEvent void AUPlugin::parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 /*host_time*/, Float32 new_value) { - ParameterMap::iterator i = parameter_map.find (event->mArgument.mParameter.mParameterID); - - if (i != parameter_map.end()) { - ParameterChanged (i->second, new_value); - } + ParameterMap::iterator i; + + if ((i = parameter_map.find (event->mArgument.mParameter.mParameterID)) == parameter_map.end()) { + return; + } + + switch (event->mEventType) { + case kAudioUnitEvent_BeginParameterChangeGesture: + StartTouch (i->second); + break; + case kAudioUnitEvent_EndParameterChangeGesture: + EndTouch (i->second); + break; + case kAudioUnitEvent_ParameterValueChange: + ParameterChanged (i->second, new_value); + break; + default: + break; + } }