MCP: make v-pot press work; work ongoing on general keybindings
[ardour.git] / libs / ardour / audio_unit.cc
index 5e15d9b48e872082cb7d8e598b197c63c49da26e..6b6d7ae3176417530977cdd67760752a02979ca9 100644 (file)
@@ -54,6 +54,9 @@
 #include <CoreServices/CoreServices.h>
 #include <AudioUnit/AudioUnit.h>
 #include <AudioToolbox/AudioUnitUtilities.h>
+#ifdef WITH_CARBON
+#include <Carbon/Carbon.h>
+#endif
 
 #include "i18n.h"
 
@@ -483,7 +486,7 @@ AUPlugin::init ()
                DEBUG_TRACE (DEBUG::AudioUnits, "set render callback in input scope\n");
                if ((err = unit->SetProperty (kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
                                              0, (void*) &renderCallbackInfo, sizeof(renderCallbackInfo))) != 0) {
-                       cerr << "cannot install render callback (err = " << err << ')' << endl;
+                       error << string_compose (_("cannot install render callback (err = %1)"), err) << endmsg;
                        throw failed_constructor();
                }
        }
@@ -680,7 +683,6 @@ AUPlugin::maybe_fix_broken_au_id (const std::string& id)
 
                                /* too close to the end for \xNN parsing: treat as literal characters */
 
-                               cerr << "Parse " << cstr << " as a literal \\" << endl;
                                nascent[in] = *cstr;
                                ++cstr;
                                ++in;
@@ -699,7 +701,6 @@ AUPlugin::maybe_fix_broken_au_id (const std::string& id)
                                } else {
 
                                        /* treat as literal characters */
-                                       cerr << "Parse " << cstr << " as a literal \\" << endl;
                                        nascent[in] = *cstr;
                                        ++cstr;
                                        ++in;
@@ -886,7 +887,7 @@ AUPlugin::set_block_size (pframes_t nframes)
        DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("set MaximumFramesPerSlice in global scope to %1\n", numFrames));
        if ((err = unit->SetProperty (kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
                                      0, &numFrames, sizeof (numFrames))) != noErr) {
-               cerr << "cannot set max frames (err = " << err << ')' << endl;
+               error << string_compose (_("AU: cannot set max frames (err = %1)"), err) << endmsg;
                return -1;
        }
 
@@ -1315,7 +1316,7 @@ AUPlugin::connect_and_run (BufferSet& bufs, ChanMapping in_map, ChanMapping out_
 
        buffers->mNumberBuffers = output_channels;
 
-       for (uint32_t i = 0; i < output_channels; ++i) {
+       for (int32_t i = 0; i < output_channels; ++i) {
                buffers->mBuffers[i].mNumberChannels = 1;
                buffers->mBuffers[i].mDataByteSize = nframes * sizeof (Sample);
                /* setting this to 0 indicates to the AU that it can provide buffers here
@@ -1390,7 +1391,7 @@ AUPlugin::connect_and_run (BufferSet& bufs, ChanMapping in_map, ChanMapping out_
                return 0;
        }
 
-       cerr << name() << " render status " << err << endl;
+       error << string_compose (_("AU: render error for %1, status = %2"), name(), err) << endmsg;
        return -1;
 }
 
@@ -1413,11 +1414,11 @@ AUPlugin::get_beat_and_tempo_callback (Float64* outCurrentBeat,
 
        Timecode::BBT_Time bbt;
        TempoMetric metric = tmap.metric_at (_session.transport_frame() + input_offset);
-       tmap.bbt_time_with_metric (_session.transport_frame() + input_offset, bbt, metric);
+       tmap.bbt_time (_session.transport_frame() + input_offset, bbt);
 
        if (outCurrentBeat) {
                float beat;
-               beat = metric.meter().beats_per_bar() * bbt.bars;
+               beat = metric.meter().divisions_per_bar() * bbt.bars;
                beat += bbt.beats;
                beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
                *outCurrentBeat = beat;
@@ -1452,7 +1453,7 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
 
        Timecode::BBT_Time bbt;
        TempoMetric metric = tmap.metric_at (_session.transport_frame() + input_offset);
-       tmap.bbt_time_with_metric (_session.transport_frame() + input_offset, bbt, metric);
+       tmap.bbt_time (_session.transport_frame() + input_offset, bbt);
 
        if (outDeltaSampleOffsetToNextBeat) {
                if (bbt.ticks == 0) {
@@ -1461,12 +1462,12 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
                } else {
                        *outDeltaSampleOffsetToNextBeat = (UInt32) 
                                floor (((Timecode::BBT_Time::ticks_per_beat - bbt.ticks)/Timecode::BBT_Time::ticks_per_beat) * // fraction of a beat to next beat
-                                      metric.tempo().frames_per_beat(_session.frame_rate(), metric.meter())); // frames per beat
+                                      metric.tempo().frames_per_beat (_session.frame_rate())); // frames per beat
                }
        }
 
        if (outTimeSig_Numerator) {
-               *outTimeSig_Numerator = (UInt32) lrintf (metric.meter().beats_per_bar());
+               *outTimeSig_Numerator = (UInt32) lrintf (metric.meter().divisions_per_bar());
        }
        if (outTimeSig_Denominator) {
                *outTimeSig_Denominator = (UInt32) lrintf (metric.meter().note_divisor());
@@ -1476,12 +1477,12 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
 
                /* beat for the start of the bar.
                   1|1|0 -> 1
-                  2|1|0 -> 1 + beats_per_bar
-                  3|1|0 -> 1 + (2 * beats_per_bar)
+                  2|1|0 -> 1 + divisions_per_bar
+                  3|1|0 -> 1 + (2 * divisions_per_bar)
                   etc.
                */
 
-               *outCurrentMeasureDownBeat = 1 + metric.meter().beats_per_bar() * (bbt.bars - 1);
+               *outCurrentMeasureDownBeat = 1 + metric.meter().divisions_per_bar() * (bbt.bars - 1);
        }
 
        return noErr;
@@ -1547,10 +1548,10 @@ AUPlugin::get_transport_state_callback (Boolean*  outIsPlaying,
 
                                if (outCycleStartBeat) {
                                        TempoMetric metric = tmap.metric_at (loc->start() + input_offset);
-                                       _session.tempo_map().bbt_time_with_metric (loc->start(), bbt, metric);
+                                       _session.tempo_map().bbt_time (loc->start(), bbt);
 
                                        float beat;
-                                       beat = metric.meter().beats_per_bar() * bbt.bars;
+                                       beat = metric.meter().divisions_per_bar() * bbt.bars;
                                        beat += bbt.beats;
                                        beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
 
@@ -1559,10 +1560,10 @@ AUPlugin::get_transport_state_callback (Boolean*  outIsPlaying,
 
                                if (outCycleEndBeat) {
                                        TempoMetric metric = tmap.metric_at (loc->end() + input_offset);
-                                       _session.tempo_map().bbt_time_with_metric (loc->end(), bbt, metric);
+                                       _session.tempo_map().bbt_time (loc->end(), bbt);
 
                                        float beat;
-                                       beat = metric.meter().beats_per_bar() * bbt.bars;
+                                       beat = metric.meter().divisions_per_bar() * bbt.bars;
                                        beat += bbt.beats;
                                        beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
 
@@ -2679,7 +2680,11 @@ AUPlugin::set_info (PluginInfoPtr info)
 int
 AUPlugin::create_parameter_listener (AUEventListenerProc cb, void* arg, float interval_secs)
 {
+#ifdef WITH_CARBON
        CFRunLoopRef run_loop = (CFRunLoopRef) GetCFRunLoopFromEventLoop(GetCurrentEventLoop()); 
+#else
+       CFRunLoopRef run_loop = CFRunLoopGetCurrent();
+#endif
        CFStringRef  loop_mode = kCFRunLoopDefaultMode;
 
        if (AUEventListenerCreate (cb, arg, run_loop, loop_mode, interval_secs, interval_secs, &_parameter_listener) != noErr) {
@@ -2742,7 +2747,7 @@ 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)
+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);