summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2011-04-07 15:41:36 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2011-04-07 15:41:36 +0000
commitd3b2f9e498ec9548f5d33a3b0016d31d18377813 (patch)
treee2bb27d2d342a071b9c7927722c82b6feb56eff4 /libs
parent04b3f11979da485fd9d682ede0c6c601b3b8f24e (diff)
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
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/audio_unit.h6
-rw-r--r--libs/ardour/audio_unit.cc71
-rw-r--r--libs/ardour/coreaudiosource.cc2
3 files changed, 54 insertions, 25 deletions
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';