Break out API to create readables from files
This commit is contained in:
parent
34c4602e61
commit
56c1fa0c90
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
if (!AudioFileSource::get_soundfile_info (path, sf_info, error_msg)) {
|
||||
PBD::error << string_compose(_("Convolver: cannot open IR \"%1\": %2"), path, error_msg) << endmsg;
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
if (sf_info.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 ();
|
||||
}
|
||||
}
|
||||
_readables = Readable::load (_session, path);
|
||||
|
||||
if (_readables.empty ()) {
|
||||
PBD::error << string_compose (_("Convolver: IR \"%1\" no usable audio-channels sound."), path) << endmsg;
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
if (_readables[0]->readable_length () > 0x1000000 /*2^24*/) {
|
||||
PBD::error << string_compose(_("Convolver: IR \"%1\" file too long."), path) << endmsg;
|
||||
throw failed_constructor ();
|
||||
}
|
||||
|
||||
AudioEngine::instance ()->BufferSizeChanged.connect_same_thread (*this, boost::bind (&Convolver::reconfigure, this));
|
||||
|
||||
reconfigure ();
|
||||
|
66
libs/ardour/readable.cc
Normal file
66
libs/ardour/readable.cc
Normal file
@ -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;
|
||||
}
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user