configurable midi audition synth
[ardour.git] / libs / ardour / auditioner.cc
index 8b030750bdcade3f6e08839053fdd594f16faee4..3e382625a0229a54b452bb070473fbadd02acef2 100644 (file)
@@ -51,6 +51,7 @@ Auditioner::Auditioner (Session& s)
        , via_monitor (false)
        , _midi_audition (false)
        , _synth_added (false)
+       , _synth_changed (false)
        , _queue_panic (false)
 {
 }
@@ -67,11 +68,11 @@ Auditioner::init ()
        }
 
        _output->add_port ("Midiaudition", this, DataType::MIDI);
-       boost::shared_ptr<Plugin> p = find_plugin (_session, "https://community.ardour.org/node/7596", ARDOUR::LV2);
-       assert(p);
-       asynth = boost::shared_ptr<Processor> (new PluginInsert (_session, p));
+
+       lookup_synth();
 
        _output->changed.connect_same_thread (*this, boost::bind (&Auditioner::output_changed, this, _1, _2));
+       Config->ParameterChanged.connect_same_thread (*this, boost::bind (&Auditioner::config_changed, this, _1));
 
        return 0;
 }
@@ -80,6 +81,35 @@ Auditioner::~Auditioner ()
 {
 }
 
+void
+Auditioner::lookup_synth ()
+{
+       string plugin_id = Config->get_midi_audition_synth_uri();
+       boost::shared_ptr<Plugin> p;
+       if (!plugin_id.empty()) {
+               p = find_plugin (_session, plugin_id, ARDOUR::LV2);
+               if (!p) {
+                       p = find_plugin (_session, "https://community.ardour.org/node/7596", ARDOUR::LV2);
+                       if (p) {
+                               warning << _("Falling back to Reasonable Synth for Midi Audition") << endmsg;
+                       } else {
+                               warning << _("No synth for midi-audition found.") << endmsg;
+                       }
+               }
+       }
+       if (p) {
+               asynth = boost::shared_ptr<Processor> (new PluginInsert (_session, p));
+       }
+}
+
+void
+Auditioner::config_changed (std::string p)
+{
+       if (p == "midi-audition-synth-uri") {
+               _synth_changed = true;
+       }
+}
+
 int
 Auditioner::connect ()
 {
@@ -379,7 +409,17 @@ Auditioner::audition_region (boost::shared_ptr<Region> region)
 
                ProcessorStreams ps;
 
-               if (!_synth_added) {
+               if (_synth_changed && _synth_added) {
+                       remove_processor(asynth);
+                       _synth_added = false;
+               }
+               if (_synth_changed && !_synth_added) {
+                       _synth_added = false;
+                       lookup_synth();
+               }
+
+
+               if (!_synth_added && asynth) {
                        int rv = add_processor_by_index(asynth, PreFader, &ps, true);
                        if (rv) {
                                error << _("Failed to load synth for MIDI-Audition.") << endmsg;
@@ -458,7 +498,9 @@ Auditioner::play_audition (framecnt_t nframes)
                _seek_complete = false;
                _seeking = false;
                _seek_frame = -1;
-               midi_diskstream()->reset_tracker();
+               if (_midi_audition && midi_diskstream()) {
+                       midi_diskstream()->reset_tracker();
+               }
        }
 
        if(!_seeking) {
@@ -551,7 +593,7 @@ Auditioner::input_streams () const
        return ChanCount ();
 }
 
-MonitorState 
+MonitorState
 Auditioner::monitoring_state () const
 {
        return MonitoringDisk;