From 8087bad9a03fb49af833b91685dd255090635cbb Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 31 Aug 2021 22:35:14 -0600 Subject: [PATCH] triggerbox: create regions and sources using factories, and restore region in set_state() --- libs/ardour/triggerbox.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 68a272c194..c294315ac0 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -19,6 +19,7 @@ #include "ardour/region_factory.h" #include "ardour/session.h" #include "ardour/session_object.h" +#include "ardour/source_factory.h" #include "ardour/sndfilesource.h" #include "ardour/triggerbox.h" @@ -116,6 +117,16 @@ Trigger::set_state (const XMLNode& node, int version) node.get_property (X_("name"), _name); node.get_property (X_("index"), _index); + PBD::ID rid; + + node.get_property (X_("region"), rid); + + boost::shared_ptr r = RegionFactory::region_by_id (rid); + + if (r) { + set_region (r); + } + return 0; } @@ -360,6 +371,10 @@ AudioTrigger::set_state (const XMLNode& node, int version) { timepos_t t; + if (!Trigger::set_state (node, version)) { + return -1; + } + node.get_property (X_("start"), t); _start_offset = t.samples(); @@ -772,7 +787,12 @@ TriggerBox::set_from_path (size_t slot, std::string const & path) SourceList src_list; for (uint16_t n = 0; n < info.channels; ++n) { - boost::shared_ptr source (new SndFileSource (_session, path, n, Source::Flag (0))); + boost::shared_ptr source (SourceFactory::createExternal (DataType::AUDIO, _session, path, n, Source::Flag (0), true)); + if (!source) { + error << string_compose (_("Cannot create source from %1"), path) << endmsg; + src_list.clear (); + return -1; + } src_list.push_back (source); } @@ -784,7 +804,7 @@ TriggerBox::set_from_path (size_t slot, std::string const & path) plist.add (Properties::layer, 0); plist.add (Properties::layering_index, 0); - boost::shared_ptr the_region (RegionFactory::create (src_list, plist, false)); + boost::shared_ptr the_region (RegionFactory::create (src_list, plist, true)); all_triggers[slot]->set_region (the_region);