Use XMLNode::get/set_property API in ARDOUR::SoloControl class
[ardour.git] / libs / ardour / audio_unit.cc
index 85bfc51a6da5dc66977f44d16de343e39a730c14..5d0b600e59372e299687110b1dfeecbc321e456d 100644 (file)
@@ -606,7 +606,7 @@ AUPlugin::init ()
        DEBUG_TRACE (DEBUG::AudioUnits, "count output elements\n");
        unit->GetElementCount (kAudioUnitScope_Output, output_elements);
 
-       cb_offsets = (framecnt_t*) calloc (input_elements, sizeof(uint32_t));
+       cb_offsets = (framecnt_t*) calloc (input_elements, sizeof(framecnt_t));
        bus_inputs = (uint32_t*) calloc (input_elements, sizeof(uint32_t));
        bus_outputs = (uint32_t*) calloc (output_elements, sizeof(uint32_t));
 
@@ -1686,7 +1686,7 @@ AUPlugin::connect_and_run (BufferSet& bufs,
                        /* one MIDI port/buffer only */
                        MidiBuffer& m = bufs.get_midi (i);
                        for (MidiBuffer::iterator i = m.begin(); i != m.end(); ++i) {
-                               Evoral::MIDIEvent<framepos_t> ev (*i);
+                               Evoral::Event<framepos_t> ev (*i);
                                if (ev.is_channel_event()) {
                                        const uint8_t* b = ev.buffer();
                                        DEBUG_TRACE (DEBUG::AudioUnits, string_compose ("%1: MIDI event %2\n", name(), ev));
@@ -1803,29 +1803,12 @@ AUPlugin::get_beat_and_tempo_callback (Float64* outCurrentBeat,
 
        DEBUG_TRACE (DEBUG::AudioUnits, "AU calls ardour beat&tempo callback\n");
 
-       /* more than 1 meter or more than 1 tempo means that a simplistic computation
-          (and interpretation) of a beat position will be incorrect. So refuse to
-          offer the value.
-       */
-
-       if (tmap.n_tempos() > 1 || tmap.n_meters() > 1) {
-               return kAudioUnitErr_CannotDoInCurrentContext;
-       }
-
-       TempoMetric metric = tmap.metric_at (transport_frame + input_offset);
-       Timecode::BBT_Time bbt = _session.tempo_map().bbt_at_frame (transport_frame + input_offset);
-
        if (outCurrentBeat) {
-               const double ppq_scaling = metric.meter().note_divisor() / 4.0;
-               float beat;
-               beat = metric.meter().divisions_per_bar() * (bbt.bars - 1);
-               beat += (bbt.beats - 1);
-               beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
-               *outCurrentBeat = beat * ppq_scaling;
+               *outCurrentBeat = tmap.quarter_note_at_frame (transport_frame + input_offset);
        }
 
        if (outCurrentTempo) {
-               *outCurrentTempo = floor (session->tempo_map().tempo_at_frame (transport_frame + input_offset).beats_per_minute());
+               *outCurrentTempo = tmap.tempo_at_frame (transport_frame + input_offset).quarter_notes_per_minute();
        }
 
        return noErr;
@@ -1842,15 +1825,6 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
 
        DEBUG_TRACE (DEBUG::AudioUnits, "AU calls ardour music time location callback\n");
 
-       /* more than 1 meter or more than 1 tempo means that a simplistic computation
-          (and interpretation) of a beat position will be incorrect. So refuse to
-          offer the value.
-       */
-
-       if (tmap.n_tempos() > 1 || tmap.n_meters() > 1) {
-               return kAudioUnitErr_CannotDoInCurrentContext;
-       }
-
        TempoMetric metric = tmap.metric_at (transport_frame + input_offset);
        Timecode::BBT_Time bbt = _session.tempo_map().bbt_at_frame (transport_frame + input_offset);
 
@@ -1859,8 +1833,10 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
                        /* on the beat */
                        *outDeltaSampleOffsetToNextBeat = 0;
                } else {
-                       double const beat_frac_to_next = (Timecode::BBT_Time::ticks_per_beat - bbt.ticks) / Timecode::BBT_Time::ticks_per_beat;
-                       *outDeltaSampleOffsetToNextBeat = tmap.frame_at_beat (tmap.beat_at_frame (transport_frame + input_offset) + beat_frac_to_next);
+                       double const next_beat = ceil (tmap.quarter_note_at_frame (transport_frame + input_offset));
+                       framepos_t const next_beat_frame = tmap.frame_at_quarter_note (next_beat);
+
+                       *outDeltaSampleOffsetToNextBeat = next_beat_frame - (transport_frame + input_offset);
                }
        }
 
@@ -1879,8 +1855,10 @@ AUPlugin::get_musical_time_location_callback (UInt32*   outDeltaSampleOffsetToNe
                   3|1|0 -> 1 + (2 * divisions_per_bar)
                   etc.
                */
+               bbt.beats = 1;
+               bbt.ticks = 0;
 
-               *outCurrentMeasureDownBeat = 1 + metric.meter().divisions_per_bar() * (bbt.bars - 1);
+               *outCurrentMeasureDownBeat = tmap.quarter_note_at_bbt (bbt);
        }
 
        return noErr;
@@ -1933,38 +1911,14 @@ AUPlugin::get_transport_state_callback (Boolean*  outIsPlaying,
 
                                TempoMap& tmap (_session.tempo_map());
 
-                               /* more than 1 meter means that a simplistic computation (and interpretation) of
-                                  a beat position will be incorrect. so refuse to offer the value.
-                               */
-
-                               if (tmap.n_meters() > 1) {
-                                       return kAudioUnitErr_CannotDoInCurrentContext;
-                               }
-
                                Timecode::BBT_Time bbt;
 
                                if (outCycleStartBeat) {
-                                       TempoMetric metric = tmap.metric_at (loc->start() + input_offset);
-                                       bbt = _session.tempo_map().bbt_at_frame (loc->start() + input_offset);
-
-                                       float beat;
-                                       beat = metric.meter().divisions_per_bar() * bbt.bars;
-                                       beat += bbt.beats;
-                                       beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
-
-                                       *outCycleStartBeat = beat;
+                                       *outCycleStartBeat = tmap.quarter_note_at_frame (loc->start() + input_offset);
                                }
 
                                if (outCycleEndBeat) {
-                                       TempoMetric metric = tmap.metric_at (loc->end() + input_offset);
-                                       bbt = _session.tempo_map().bbt_at_frame (loc->end() + input_offset);
-
-                                       float beat;
-                                       beat = metric.meter().divisions_per_bar() * bbt.bars;
-                                       beat += bbt.beats;
-                                       beat += bbt.ticks / Timecode::BBT_Time::ticks_per_beat;
-
-                                       *outCycleEndBeat = beat;
+                                       *outCycleEndBeat = tmap.quarter_note_at_frame (loc->end() + input_offset);
                                }
                        }
                }
@@ -2004,6 +1958,8 @@ AUPlugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
                        break;
        }
 
+       std::string busname;
+
        if (dt == DataType::AUDIO) {
                if (input) {
                        uint32_t pid = id;
@@ -2012,6 +1968,7 @@ AUPlugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
                                        id = pid;
                                        ss << _bus_name_in[bus];
                                        ss << " / Bus " << (1 + bus);
+                                       busname = _bus_name_in[bus];
                                        break;
                                }
                                pid -= bus_inputs[bus];
@@ -2024,6 +1981,7 @@ AUPlugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
                                        id = pid;
                                        ss << _bus_name_out[bus];
                                        ss << " / Bus " << (1 + bus);
+                                       busname = _bus_name_out[bus];
                                        break;
                                }
                                pid -= bus_outputs[bus];
@@ -2040,6 +1998,10 @@ AUPlugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
        ss << (id + 1);
 
        Plugin::IOPortDescription iod (ss.str());
+       if (!busname.empty()) {
+               iod.group_name = busname;
+               iod.group_channel = id;
+       }
        return iod;
 }
 
@@ -2596,8 +2558,10 @@ AUPlugin::find_presets ()
        /* add factory 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 ());
+               /* XXX: dubious -- deleting & re-adding a preset -> same URI
+                * good that we don't support deleting AU presets :)
+                */
+               string const uri = PBD::to_string<uint32_t> (_presets.size ());
                _presets.insert (make_pair (uri, Plugin::PresetRecord (uri, i->first, false)));
                DEBUG_TRACE (DEBUG::AudioUnits, string_compose("AU Adding Factory Preset: %1 > %2\n", i->first, i->second));
        }
@@ -2937,24 +2901,24 @@ AUPluginInfo::discover_by_description (PluginInfoList& plugs, CAComponentDescrip
                        continue;
 
                case kAudioUnitType_Output:
-                       info->category = _("AudioUnit Outputs");
+                       info->category = _("AudioUnit Output");
                        break;
                case kAudioUnitType_MusicDevice:
-                       info->category = _("AudioUnit Instruments");
+                       info->category = _("Instrument");
                        has_midi_in = true;
                        break;
                case kAudioUnitType_MusicEffect:
-                       info->category = _("AudioUnit MusicEffects");
+                       info->category = _("Music Effect");
                        has_midi_in = true;
                        break;
                case kAudioUnitType_Effect:
-                       info->category = _("AudioUnit Effects");
+                       info->category = _("Effect");
                        break;
                case kAudioUnitType_Mixer:
-                       info->category = _("AudioUnit Mixers");
+                       info->category = _("Mixer");
                        break;
                case kAudioUnitType_Generator:
-                       info->category = _("AudioUnit Generators");
+                       info->category = _("Generator");
                        break;
                default:
                        info->category = _("AudioUnit (Unknown)");
@@ -3159,22 +3123,19 @@ AUPluginInfo::save_cached_info ()
        XMLNode* node;
 
        node = new XMLNode (X_("AudioUnitPluginCache"));
-       node->add_property( "version", AU_CACHE_VERSION );
+       node->set_property( "version", AU_CACHE_VERSION );
 
        for (map<string,AUPluginCachedInfo>::iterator i = cached_info.begin(); i != cached_info.end(); ++i) {
                XMLNode* parent = new XMLNode (X_("plugin"));
-               parent->add_property ("id", i->first);
+               parent->set_property ("id", i->first);
                node->add_child_nocopy (*parent);
 
                for (vector<pair<int, int> >::iterator j = i->second.io_configs.begin(); j != i->second.io_configs.end(); ++j) {
 
                        XMLNode* child = new XMLNode (X_("io"));
-                       char buf[32];
 
-                       snprintf (buf, sizeof (buf), "%d", j->first);
-                       child->add_property (X_("in"), buf);
-                       snprintf (buf, sizeof (buf), "%d", j->second);
-                       child->add_property (X_("out"), buf);
+                       child->set_property (X_("in"), j->first);
+                       child->set_property (X_("out"), j->second);
                        parent->add_child_nocopy (*child);
                }
 
@@ -3231,13 +3192,12 @@ AUPluginInfo::load_cached_info ()
 
                        const XMLNode* gchild;
                        const XMLNodeList gchildren = child->children();
-                       XMLProperty const * prop = child->property (X_("id"));
 
-                       if (!prop) {
+                       string id;
+                       if (!child->get_property (X_("id"), id)) {
                                continue;
                        }
 
-                       string id = prop->value();
                        string fixed;
                        string version;
 
@@ -3267,16 +3227,10 @@ AUPluginInfo::load_cached_info ()
 
                                if (gchild->name() == X_("io")) {
 
-                                       int in;
-                                       int out;
-                                       XMLProperty const * iprop;
-                                       XMLProperty const * oprop;
-
-                                       if (((iprop = gchild->property (X_("in"))) != 0) &&
-                                           ((oprop = gchild->property (X_("out"))) != 0)) {
-                                               in = atoi (iprop->value());
-                                               out = atoi (oprop->value());
+                                       int32_t in;
+                                       int32_t out;
 
+                                       if (gchild->get_property (X_("in"), in) && gchild->get_property (X_("out"), out)) {
                                                cinfo.io_configs.push_back (pair<int,int> (in, out));
                                        }
                                }