From d3b2f9e498ec9548f5d33a3b0016d31d18377813 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 7 Apr 2011 15:41:36 +0000 Subject: make AUPlugin emit ParameterChanged() whenever it is notified of a parameter change event by the AU git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@9323 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/audio_unit.h | 6 +++- libs/ardour/audio_unit.cc | 71 ++++++++++++++++++++++++++++------------- libs/ardour/coreaudiosource.cc | 2 +- 3 files changed, 54 insertions(+), 25 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/audio_unit.h b/libs/ardour/ardour/audio_unit.h index 7d2624ac5a..cc1604f725 100644 --- a/libs/ardour/ardour/audio_unit.h +++ b/libs/ardour/ardour/audio_unit.h @@ -187,13 +187,14 @@ class AUPlugin : public ARDOUR::Plugin int set_stream_format (int scope, uint32_t cnt, AudioStreamBasicDescription&); void discover_parameters (); - std::vector > parameter_map; uint32_t current_maxbuf; nframes_t current_offset; nframes_t cb_offset; vector* current_buffers; nframes_t frames_processed; + typedef std::map ParameterMap; + ParameterMap parameter_map; std::vector descriptors; AUEventListenerRef _parameter_listener; void * _parameter_listener_arg; @@ -203,6 +204,9 @@ class AUPlugin : public ARDOUR::Plugin bool last_transport_rolling; float last_transport_speed; + + static void _parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value); + void parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value); }; typedef boost::shared_ptr AUPluginPtr; diff --git a/libs/ardour/audio_unit.cc b/libs/ardour/audio_unit.cc index d3f9378498..ed107a0840 100644 --- a/libs/ardour/audio_unit.cc +++ b/libs/ardour/audio_unit.cc @@ -508,6 +508,8 @@ AUPlugin::init () discover_factory_presets (); Plugin::setup_controls (); + + create_parameter_listener (AUPlugin::_parameter_change_listener, this, 0.05); } void @@ -620,14 +622,13 @@ AUPlugin::discover_parameters () descriptors.push_back (d); - if (d.automatable) { - unit->addPropertyListen (d.id); - } + uint32_t last_param = descriptors.size() - 1; + parameter_map.insert (pair (d.id, last_param)); + listen_to_parameter (last_param); } } } - static unsigned int four_ints_to_four_byte_literal (unsigned char n[4]) { @@ -771,24 +772,34 @@ AUPlugin::latency () const void AUPlugin::set_parameter (uint32_t which, float val) { - if (which < descriptors.size()) { - const AUParameterDescriptor& d (descriptors[which]); - TRACE_API ("set parameter %d in scope %d element %d to %f\n", d.id, d.scope, d.element, val); - unit->SetParameter (d.id, d.scope, d.element, val); + if (which >= descriptors.size()) { + return; + } - /* tell the world what we did */ + const AUParameterDescriptor& d (descriptors[which]); + TRACE_API ("set parameter %d in scope %d element %d to %f\n", d.id, d.scope, d.element, val); + unit->SetParameter (d.id, d.scope, d.element, val); + + /* tell the world what we did */ + + AudioUnitEvent theEvent; + + theEvent.mEventType = kAudioUnitEvent_ParameterValueChange; + theEvent.mArgument.mParameter.mAudioUnit = unit->AU(); + theEvent.mArgument.mParameter.mParameterID = d.id; + theEvent.mArgument.mParameter.mScope = d.scope; + theEvent.mArgument.mParameter.mElement = d.element; + + TRACE_API ("notify about parameter change\n"); - AudioUnitEvent theEvent; - - theEvent.mEventType = kAudioUnitEvent_ParameterValueChange; - theEvent.mArgument.mParameter.mAudioUnit = unit->AU(); - theEvent.mArgument.mParameter.mParameterID = d.id; - theEvent.mArgument.mParameter.mScope = d.scope; - theEvent.mArgument.mParameter.mElement = d.element; + /* use the AU Event API to notify about the change. Our own listener will + end up "emitting" ParameterChanged, and this way ParameterChanged is + used whether the change to the parameter comes from this function + or within the plugin or anywhere else, since they should all notify + via AUEventListenerNotify(). + */ - TRACE_API ("notify about parameter change\n"); - AUEventListenerNotify (NULL, NULL, &theEvent); - } + AUEventListenerNotify (NULL, NULL, &theEvent); } float @@ -2478,11 +2489,10 @@ AUPluginInfo::stringify_descriptor (const CAComponentDescription& desc) return s.str(); } - int AUPlugin::create_parameter_listener (AUEventListenerProc cb, void* arg, float interval_secs) { - CFRunLoopRef run_loop = (CFRunLoopRef)GetCFRunLoopFromEventLoop(GetCurrentEventLoop()); + CFRunLoopRef run_loop = (CFRunLoopRef) GetCFRunLoopFromEventLoop(GetCurrentEventLoop()); CFStringRef loop_mode = kCFRunLoopDefaultMode; if (AUEventListenerCreate (cb, arg, run_loop, loop_mode, interval_secs, interval_secs, &_parameter_listener) != noErr) { @@ -2499,7 +2509,7 @@ AUPlugin::listen_to_parameter (uint32_t param_id) { AudioUnitEvent event; - if (param_id >= descriptors.size()) { + if (!_parameter_listener || param_id >= descriptors.size()) { return -2; } @@ -2521,7 +2531,7 @@ AUPlugin::end_listen_to_parameter (uint32_t param_id) { AudioUnitEvent event; - if (param_id >= descriptors.size()) { + if (!_parameter_listener || param_id >= descriptors.size()) { return -2; } @@ -2538,3 +2548,18 @@ AUPlugin::end_listen_to_parameter (uint32_t param_id) return 0; } +void +AUPlugin::_parameter_change_listener (void* arg, void* src, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value) +{ + ((AUPlugin*) arg)->parameter_change_listener (arg, src, event, host_time, new_value); +} + +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); + } +} diff --git a/libs/ardour/coreaudiosource.cc b/libs/ardour/coreaudiosource.cc index 62a7a18ba7..5a3c542521 100644 --- a/libs/ardour/coreaudiosource.cc +++ b/libs/ardour/coreaudiosource.cc @@ -267,7 +267,7 @@ CoreAudioSource::get_soundfile_info (string path, SoundFileInfo& _info, string& } char buf[32]; - snprintf (buf, sizeof (buf), " %" PRIu32 " bit", absd.mBitsPerChannel); + snprintf (buf, sizeof (buf), " %" PRIu32 " bit", (uint32_t) absd.mBitsPerChannel); _info.format_name += buf; _info.format_name += '\n'; -- cgit v1.2.3