diff --git a/libs/ardour/ardour/monitor_return.h b/libs/ardour/ardour/monitor_return.h new file mode 100644 index 0000000000..bea1461fb9 --- /dev/null +++ b/libs/ardour/ardour/monitor_return.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 Robin Gareus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __ardour_monitor_return_h__ +#define __ardour_monitor_return_h__ + +#include "ardour/internal_return.h" + +namespace ARDOUR { + +class AudioPort; + +class LIBARDOUR_API MonitorReturn : public InternalReturn +{ +public: + MonitorReturn (Session&); + ~MonitorReturn (); + + void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool); + +protected: + XMLNode& state (); + + uint32_t _nch; + gain_t _gain; +}; + +} // namespace ARDOUR + +#endif diff --git a/libs/ardour/monitor_return.cc b/libs/ardour/monitor_return.cc new file mode 100644 index 0000000000..c2831d0316 --- /dev/null +++ b/libs/ardour/monitor_return.cc @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2021 Robin Gareus + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include + +#include "ardour/audio_port.h" +#include "ardour/audioengine.h" +#include "ardour/monitor_return.h" +#include "ardour/session.h" + +using namespace ARDOUR; + +MonitorReturn::MonitorReturn (Session& s) + : InternalReturn (s, "Monitor Return") + , _nch (0) + , _gain (1.f) +{ +#if 0 + MonitorPort& mp (AudioEngine::instance()->monitor_port ()); + mp->enable (); +#endif +} + +MonitorReturn::~MonitorReturn () +{ + MonitorPort& mp (AudioEngine::instance()->monitor_port ()); + mp.clear_ports (true); +} + +void +MonitorReturn::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool result_required) +{ + InternalReturn::run (bufs, start_sample, end_sample, speed, nframes, result_required); + + MonitorPort& mp (AudioEngine::instance()->monitor_port ()); + + if (mp.silent ()) { + return; + } + + uint32_t nch = bufs.count().n_audio (); + if (_nch != nch) { + _nch = _nch; + _gain = nch > 0 ? (1.f / sqrtf (nch)) : 1.f; + } + + const AudioBuffer& bb (mp.get_audio_buffer (nframes)); + for (BufferSet::iterator b = bufs.begin (DataType::AUDIO); b != bufs.end (DataType::AUDIO); ++b) { + AudioBuffer* ab = dynamic_cast (&(*b)); + ab->accumulate_with_gain_from (bb, nframes, _gain); + } +} + +XMLNode& +MonitorReturn::state () +{ + XMLNode& node (InternalReturn::state ()); + node.set_property ("type", "monreturn"); + return node; +} diff --git a/libs/ardour/wscript b/libs/ardour/wscript index a973593b15..03f21b7881 100644 --- a/libs/ardour/wscript +++ b/libs/ardour/wscript @@ -151,6 +151,7 @@ libardour_sources = [ 'monitor_control.cc', 'monitor_port.cc', 'monitor_processor.cc', + 'monitor_return.cc', 'mp3fileimportable.cc', 'mp3filesource.cc', 'mtc_slave.cc',