diff options
-rw-r--r-- | gtk2_ardour/au_pluginui.h | 5 | ||||
-rw-r--r-- | gtk2_ardour/au_pluginui.mm | 27 | ||||
-rw-r--r-- | libs/ardour/ardour/audio_unit.h | 6 | ||||
-rw-r--r-- | libs/ardour/audio_unit.cc | 71 | ||||
-rw-r--r-- | libs/ardour/coreaudiosource.cc | 2 |
5 files changed, 54 insertions, 57 deletions
diff --git a/gtk2_ardour/au_pluginui.h b/gtk2_ardour/au_pluginui.h index 94883cbadf..cb4b88ee39 100644 --- a/gtk2_ardour/au_pluginui.h +++ b/gtk2_ardour/au_pluginui.h @@ -67,11 +67,6 @@ class AUPluginUI : public PlugUIBase, public Gtk::VBox OSStatus carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event); -#ifdef PARAMETER_LISTENING - 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); -#endif - private: boost::shared_ptr<ARDOUR::AUPlugin> au; int prefheight; diff --git a/gtk2_ardour/au_pluginui.mm b/gtk2_ardour/au_pluginui.mm index bdc1dd33b4..a704dcd148 100644 --- a/gtk2_ardour/au_pluginui.mm +++ b/gtk2_ardour/au_pluginui.mm @@ -121,18 +121,6 @@ AUPluginUI::AUPluginUI (boost::shared_ptr<PluginInsert> insert) throw failed_constructor (); } -#ifdef PARAMETER_LISTENING - if (au->create_parameter_listener (AUPluginUI::_parameter_change_listener, this, 0.05) == 0) { - cerr << "Registered parameter listener for " << insert->name() << endl; - set<uint32_t> params = au->automatable (); - for (set<uint32_t>::iterator p = params.begin(); p != params.end(); ++p) { - cerr << "Listen to " << *p << " result = " << au->listen_to_parameter (*p) << endl; - } - } else { - cerr << "Could not registered parameter listener for " << insert->name() << endl; - } -#endif - /* stuff some stuff into the top of the window */ HBox* smaller_hbox = manage (new HBox); @@ -699,18 +687,3 @@ AUPluginUI::on_focus_out_event (GdkEventFocus* ev) return false; } -#ifdef PARAMETER_LISTENING - -void -AUPluginUI::_parameter_change_listener (void* arg, void* src, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value) -{ - ((AUPluginUI*) arg)->parameter_change_listener (arg, src, event, host_time, new_value); -} - -void -AUPluginUI::parameter_change_listener (void* /*arg*/, void* /*src*/, const AudioUnitEvent* event, UInt64 host_time, Float32 new_value) -{ - cerr << insert->name() << "Parameter " << event->mArgument.mParameter.mParameterID << " changed to " << new_value << endl; -} - -#endif 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<std::pair<uint32_t, uint32_t> > parameter_map; uint32_t current_maxbuf; nframes_t current_offset; nframes_t cb_offset; vector<Sample*>* current_buffers; nframes_t frames_processed; + typedef std::map<uint32_t, uint32_t> ParameterMap; + ParameterMap parameter_map; std::vector<AUParameterDescriptor> 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<AUPlugin> 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<uint32_t,uint32_t> (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'; |