summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/ardour/readable.h8
-rw-r--r--libs/ardour/convolver.cc35
-rw-r--r--libs/ardour/readable.cc66
-rw-r--r--libs/ardour/wscript1
4 files changed, 78 insertions, 32 deletions
diff --git a/libs/ardour/ardour/readable.h b/libs/ardour/ardour/readable.h
index 0463b2fce4..ada47776cf 100644
--- a/libs/ardour/ardour/readable.h
+++ b/libs/ardour/ardour/readable.h
@@ -25,11 +25,15 @@
namespace ARDOUR {
+class Session;
+
class LIBARDOUR_API Readable {
- public:
- Readable () {}
+public:
virtual ~Readable() {}
+ static std::vector<boost::shared_ptr<Readable> >
+ load (Session&, std::string const&);
+
virtual samplecnt_t read (Sample*, samplepos_t pos, samplecnt_t cnt, int channel) const = 0;
virtual samplecnt_t readable_length() const = 0;
virtual uint32_t n_channels () const = 0;
diff --git a/libs/ardour/convolver.cc b/libs/ardour/convolver.cc
index b556c212b3..2b00f0894e 100644
--- a/libs/ardour/convolver.cc
+++ b/libs/ardour/convolver.cc
@@ -24,6 +24,7 @@
#include "ardour/audioengine.h"
#include "ardour/audiofilesource.h"
#include "ardour/convolver.h"
+#include "ardour/readable.h"
#include "ardour/session.h"
#include "ardour/srcfilesource.h"
#include "ardour/source_factory.h"
@@ -48,44 +49,18 @@ Convolver::Convolver (
, _offset (0)
, _configured (false)
{
- ARDOUR::SoundFileInfo sf_info;
- std::string error_msg;
+ _readables = Readable::load (_session, path);
- if (!AudioFileSource::get_soundfile_info (path, sf_info, error_msg)) {
- PBD::error << string_compose(_("Convolver: cannot open IR \"%1\": %2"), path, error_msg) << endmsg;
+ if (_readables.empty ()) {
+ PBD::error << string_compose (_("Convolver: IR \"%1\" no usable audio-channels sound."), path) << endmsg;
throw failed_constructor ();
}
- if (sf_info.length > 0x1000000 /*2^24*/) {
+ if (_readables[0]->readable_length () > 0x1000000 /*2^24*/) {
PBD::error << string_compose(_("Convolver: IR \"%1\" file too long."), path) << endmsg;
throw failed_constructor ();
}
- for (unsigned int n = 0; n < sf_info.channels; ++n) {
- try {
- boost::shared_ptr<AudioFileSource> afs;
- afs = boost::dynamic_pointer_cast<AudioFileSource> (
- SourceFactory::createExternal (DataType::AUDIO, _session,
- path, n,
- Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
-
- if (afs->sample_rate() != _session.nominal_sample_rate()) {
- boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(_session, afs, ARDOUR::SrcBest));
- _readables.push_back(sfs);
- } else {
- _readables.push_back (afs);
- }
- } catch (failed_constructor& err) {
- PBD::error << string_compose(_("Convolver: Could not open IR \"%1\"."), path) << endmsg;
- throw failed_constructor ();
- }
- }
-
- if (_readables.empty ()) {
- PBD::error << string_compose (_("Convolver: IR \"%1\" no usable audio-channels sound."), path) << endmsg;
- throw failed_constructor ();
- }
-
AudioEngine::instance ()->BufferSizeChanged.connect_same_thread (*this, boost::bind (&Convolver::reconfigure, this));
reconfigure ();
diff --git a/libs/ardour/readable.cc b/libs/ardour/readable.cc
new file mode 100644
index 0000000000..0390a0169d
--- /dev/null
+++ b/libs/ardour/readable.cc
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2020 Robin Gareus <robin@gareus.org>
+ *
+ * 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 <vector>
+
+#include "pbd/error.h"
+
+#include "ardour/audiofilesource.h"
+#include "ardour/readable.h"
+#include "ardour/session.h"
+#include "ardour/srcfilesource.h"
+#include "ardour/source_factory.h"
+
+#include "pbd/i18n.h"
+
+using namespace ARDOUR;
+
+std::vector<boost::shared_ptr<Readable> >
+Readable::load (Session& session, std::string const& path)
+{
+ std::vector<boost::shared_ptr<Readable> > readables;
+
+ ARDOUR::SoundFileInfo sf_info;
+ std::string error_msg;
+
+ if (!AudioFileSource::get_soundfile_info (path, sf_info, error_msg)) {
+ PBD::error << string_compose(_("Cannot open File \"%1\": %2"), path, error_msg) << endmsg;
+ throw failed_constructor ();
+ }
+
+ for (unsigned int n = 0; n < sf_info.channels; ++n) {
+ try {
+ boost::shared_ptr<AudioFileSource> afs;
+ afs = boost::dynamic_pointer_cast<AudioFileSource> (
+ SourceFactory::createExternal (DataType::AUDIO, session,
+ path, n,
+ Source::Flag (ARDOUR::AudioFileSource::NoPeakFile), false));
+
+ if (afs->sample_rate() != session.nominal_sample_rate()) {
+ boost::shared_ptr<SrcFileSource> sfs (new SrcFileSource(session, afs, ARDOUR::SrcBest));
+ readables.push_back(sfs);
+ } else {
+ readables.push_back (afs);
+ }
+ } catch (failed_constructor& err) {
+ PBD::error << string_compose(_("Could not read file \"%1\"."), path) << endmsg;
+ throw failed_constructor ();
+ }
+ }
+ return readables;
+}
diff --git a/libs/ardour/wscript b/libs/ardour/wscript
index 9de7953d09..8d6090d956 100644
--- a/libs/ardour/wscript
+++ b/libs/ardour/wscript
@@ -181,6 +181,7 @@ libardour_sources = [
'progress.cc',
'quantize.cc',
'rc_configuration.cc',
+ 'readable.cc',
'readonly_control.cc',
'raw_midi_parser.cc',
'recent_sessions.cc',