mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 23:05:04 +01:00
Break out API to create readables from files
This commit is contained in:
parent
34c4602e61
commit
56c1fa0c90
4 changed files with 80 additions and 34 deletions
|
|
@ -25,11 +25,15 @@
|
||||||
|
|
||||||
namespace ARDOUR {
|
namespace ARDOUR {
|
||||||
|
|
||||||
|
class Session;
|
||||||
|
|
||||||
class LIBARDOUR_API Readable {
|
class LIBARDOUR_API Readable {
|
||||||
public:
|
public:
|
||||||
Readable () {}
|
|
||||||
virtual ~Readable() {}
|
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 read (Sample*, samplepos_t pos, samplecnt_t cnt, int channel) const = 0;
|
||||||
virtual samplecnt_t readable_length() const = 0;
|
virtual samplecnt_t readable_length() const = 0;
|
||||||
virtual uint32_t n_channels () const = 0;
|
virtual uint32_t n_channels () const = 0;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include "ardour/audioengine.h"
|
#include "ardour/audioengine.h"
|
||||||
#include "ardour/audiofilesource.h"
|
#include "ardour/audiofilesource.h"
|
||||||
#include "ardour/convolver.h"
|
#include "ardour/convolver.h"
|
||||||
|
#include "ardour/readable.h"
|
||||||
#include "ardour/session.h"
|
#include "ardour/session.h"
|
||||||
#include "ardour/srcfilesource.h"
|
#include "ardour/srcfilesource.h"
|
||||||
#include "ardour/source_factory.h"
|
#include "ardour/source_factory.h"
|
||||||
|
|
@ -48,44 +49,18 @@ Convolver::Convolver (
|
||||||
, _offset (0)
|
, _offset (0)
|
||||||
, _configured (false)
|
, _configured (false)
|
||||||
{
|
{
|
||||||
ARDOUR::SoundFileInfo sf_info;
|
_readables = Readable::load (_session, path);
|
||||||
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 ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_readables.empty ()) {
|
if (_readables.empty ()) {
|
||||||
PBD::error << string_compose (_("Convolver: IR \"%1\" no usable audio-channels sound."), path) << endmsg;
|
PBD::error << string_compose (_("Convolver: IR \"%1\" no usable audio-channels sound."), path) << endmsg;
|
||||||
throw failed_constructor ();
|
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));
|
AudioEngine::instance ()->BufferSizeChanged.connect_same_thread (*this, boost::bind (&Convolver::reconfigure, this));
|
||||||
|
|
||||||
reconfigure ();
|
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',
|
'progress.cc',
|
||||||
'quantize.cc',
|
'quantize.cc',
|
||||||
'rc_configuration.cc',
|
'rc_configuration.cc',
|
||||||
|
'readable.cc',
|
||||||
'readonly_control.cc',
|
'readonly_control.cc',
|
||||||
'raw_midi_parser.cc',
|
'raw_midi_parser.cc',
|
||||||
'recent_sessions.cc',
|
'recent_sessions.cc',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue