Add API to configure plugins for non-realtime offline processing

This commit is contained in:
Robin Gareus 2024-04-20 00:51:25 +02:00
parent 598ff1cb9a
commit 2bb4a9ac4e
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
5 changed files with 33 additions and 4 deletions

View File

@ -154,6 +154,7 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
void add_slave (std::shared_ptr<Plugin>, bool);
void remove_slave (std::shared_ptr<Plugin>);
void set_non_realtime (bool);
bool write_from_ui(uint32_t index,
uint32_t protocol,
@ -226,6 +227,7 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
double _current_bpm;
double _prev_time_scale; ///< previous Port::speed_ratio
PBD::ID _insert_id;
bool _non_realtime;
std::string _plugin_state_dir;
uint32_t _bpm_control_port_index;
uint32_t _patch_port_in_index;

View File

@ -191,6 +191,9 @@ public:
void realtime_locate (bool);
void monitoring_changed ();
/* use plugin for offline processing */
virtual void set_non_realtime (bool) {}
virtual void add_slave (std::shared_ptr<Plugin>, bool realtime) {}
virtual void remove_slave (std::shared_ptr<Plugin>) {}

View File

@ -199,6 +199,7 @@ public:
}
void set_owner (ARDOUR::SessionObject* o);
void set_non_realtime (bool);
void enable_io (std::vector<bool> const&, std::vector<bool> const&);
@ -297,6 +298,7 @@ private:
bool _is_loading_state;
bool _is_processing;
int32_t _block_size;
bool _process_offline;
/* ports */
struct Param {
@ -426,6 +428,7 @@ public:
int set_block_size (pframes_t);
void set_owner (ARDOUR::SessionObject* o);
void set_non_realtime (bool);
void add_slave (std::shared_ptr<Plugin>, bool);
void remove_slave (std::shared_ptr<Plugin>);

View File

@ -453,6 +453,7 @@ LV2Plugin::LV2Plugin (AudioEngine& engine,
, _worker(NULL)
, _state_worker(NULL)
, _insert_id("0")
, _non_realtime (false)
, _bpm_control_port_index((uint32_t)-1)
, _patch_port_in_index((uint32_t)-1)
, _patch_port_out_index((uint32_t)-1)
@ -472,6 +473,7 @@ LV2Plugin::LV2Plugin (const LV2Plugin& other)
, _worker(NULL)
, _state_worker(NULL)
, _insert_id(other._insert_id)
, _non_realtime (other._non_realtime)
, _bpm_control_port_index((uint32_t)-1)
, _patch_port_in_index((uint32_t)-1)
, _patch_port_out_index((uint32_t)-1)
@ -1830,6 +1832,12 @@ LV2Plugin::remove_slave (std::shared_ptr<Plugin> p)
}
}
void
LV2Plugin::set_non_realtime (bool yn)
{
_non_realtime = yn;
}
bool
LV2Plugin::has_message_output() const
{
@ -2790,7 +2798,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
TempoMetric metric (tmap->metric_at (timepos_t (start0)));
if (_freewheel_control_port) {
*_freewheel_control_port = _session.engine().freewheeling() ? 1.f : 0.f;
*_freewheel_control_port = _non_realtime || _session.engine().freewheeling() ? 1.f : 0.f;
}
if (_bpm_control_port) {
@ -3379,7 +3387,7 @@ LV2Plugin::run(pframes_t nframes, bool sync_work)
if (_worker) {
// Execute work synchronously if we're freewheeling (export)
_worker->set_synchronous(sync_work || session().engine().freewheeling());
_worker->set_synchronous(sync_work || _non_realtime || session().engine().freewheeling());
}
// Run the plugin for this cycle

View File

@ -699,6 +699,12 @@ VST3Plugin::remove_slave (std::shared_ptr<Plugin> p)
}
}
void
VST3Plugin::set_non_realtime (bool yn)
{
_plug->set_non_realtime (yn);
}
int
VST3Plugin::connect_and_run (BufferSet& bufs,
samplepos_t start, samplepos_t end, double speed,
@ -1166,6 +1172,7 @@ VST3PI::VST3PI (std::shared_ptr<ARDOUR::VST3PluginModule> m, std::string unique_
, _is_loading_state (false)
, _is_processing (false)
, _block_size (0)
, _process_offline (false)
, _port_id_bypass (UINT32_MAX)
, _owner (0)
, _add_to_selection (false)
@ -1764,7 +1771,7 @@ VST3PI::update_processor ()
}
Vst::ProcessSetup setup;
setup.processMode = AudioEngine::instance ()->freewheeling () ? Vst::kOffline : Vst::kRealtime;
setup.processMode = _process_offline || AudioEngine::instance ()->freewheeling () ? Vst::kOffline : Vst::kRealtime;
setup.symbolicSampleSize = Vst::kSample32;
setup.maxSamplesPerBlock = _block_size;
setup.sampleRate = _context.sampleRate;
@ -1804,6 +1811,12 @@ VST3PI::set_owner (SessionObject* o)
}
}
void
VST3PI::set_non_realtime (bool yn)
{
_process_offline = yn;
}
int32
VST3PI::count_channels (Vst::MediaType media, Vst::BusDirection dir, Vst::BusType type)
{
@ -2315,7 +2328,7 @@ VST3PI::process (float** ins, float** outs, uint32_t n_samples)
Vst::ProcessData data;
data.numSamples = n_samples;
data.processMode = AudioEngine::instance ()->freewheeling () ? Vst::kOffline : Vst::kRealtime;
data.processMode = _process_offline || AudioEngine::instance ()->freewheeling () ? Vst::kOffline : Vst::kRealtime;
data.symbolicSampleSize = Vst::kSample32;
data.numInputs = _n_bus_in;
data.numOutputs = _n_bus_out;