mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-08 22:55:44 +01:00
more rhythm ferret/transient detection/split region stuff, maybe it works now
git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@2969 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
9dde869179
commit
315dd3d770
12 changed files with 163 additions and 125 deletions
|
|
@ -1012,6 +1012,7 @@ if env['SYSLIBS']:
|
|||
'libs/midi++2',
|
||||
'libs/ardour',
|
||||
'libs/vamp-sdk',
|
||||
'libs/vamp-plugins/',
|
||||
# these are unconditionally included but have
|
||||
# tests internally to avoid compilation etc
|
||||
# if VST is not set
|
||||
|
|
@ -1077,6 +1078,7 @@ else:
|
|||
'libs/midi++2',
|
||||
'libs/ardour',
|
||||
'libs/vamp-sdk',
|
||||
'libs/vamp-plugins/',
|
||||
# these are unconditionally included but have
|
||||
# tests internally to avoid compilation etc
|
||||
# if VST is not set
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ cd `dirname "$0"`/..
|
|||
|
||||
export ARDOUR_PATH=gtk2_ardour/icons:gtk2_ardour/pixmaps:gtk2_ardour:.
|
||||
export GTK_PATH=libs/clearlooks
|
||||
export VAMP_PATH=libs/vamp-sdk:$VAMP_PATH
|
||||
export VAMP_PATH=libs/vamp-plugins:$VAMP_PATH
|
||||
|
||||
export LD_LIBRARY_PATH=libs/vamp-sdk:libs/surfaces/control_protocol:libs/ardour:libs/midi++2:libs/pbd:libs/rubberband:libs/soundtouch:libs/gtkmm2ext:libs/sigc++2:libs/glibmm2:libs/gtkmm2/atk:libs/gtkmm2/pango:libs/gtkmm2/gdk:libs/gtkmm2/gtk:libs/libgnomecanvasmm:libs/libsndfile:libs/appleutility:$LD_LIBRARY_PATH
|
||||
|
||||
|
|
|
|||
|
|
@ -959,6 +959,8 @@ class Editor : public PublicEditor
|
|||
void split_region ();
|
||||
void split_region_at (nframes_t);
|
||||
void split_regions_at (nframes_t, RegionSelection&);
|
||||
void split_region_at_transients ();
|
||||
void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, std::vector<nframes64_t>&);
|
||||
void crop_region_to_selection ();
|
||||
void crop_region_to (nframes_t start, nframes_t end);
|
||||
void set_sync_point (nframes64_t, const RegionSelection&);
|
||||
|
|
@ -984,7 +986,6 @@ class Editor : public PublicEditor
|
|||
void normalize_region ();
|
||||
void denormalize_region ();
|
||||
void adjust_region_scale_amplitude (bool up);
|
||||
void split_region_at_transients ();
|
||||
|
||||
void use_region_as_bar ();
|
||||
void use_range_as_bar ();
|
||||
|
|
|
|||
|
|
@ -5019,7 +5019,7 @@ Editor::define_one_bar (nframes64_t start, nframes64_t end)
|
|||
void
|
||||
Editor::split_region_at_transients ()
|
||||
{
|
||||
list<nframes64_t> transients;
|
||||
vector<nframes64_t> positions;
|
||||
|
||||
if (!session) {
|
||||
return;
|
||||
|
|
@ -5031,7 +5031,7 @@ Editor::split_region_at_transients ()
|
|||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
session->begin_reversible_command (_("split regions"));
|
||||
|
||||
for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ) {
|
||||
|
||||
|
|
@ -5040,52 +5040,90 @@ Editor::split_region_at_transients ()
|
|||
tmp = i;
|
||||
++tmp;
|
||||
|
||||
cerr << "working on " << (*i)->get_item_name() << endl;
|
||||
|
||||
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> ((*i)->region());
|
||||
|
||||
if (!ar) {
|
||||
continue;
|
||||
if (ar && (ar->get_transients (positions) == 0)) {
|
||||
split_region_at_points ((*i)->region(), positions);
|
||||
positions.clear ();
|
||||
}
|
||||
|
||||
boost::shared_ptr<Playlist> pl = ar->playlist();
|
||||
|
||||
if (!pl) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cerr << "getting transients\n";
|
||||
|
||||
ar->get_transients (transients);
|
||||
nframes64_t start = ar->start();
|
||||
nframes64_t pos = ar->position();
|
||||
|
||||
pl->freeze ();
|
||||
pl->remove_region (ar);
|
||||
|
||||
cerr << "creating new regions from " << transients.size() << " transients\n";
|
||||
|
||||
for (list<nframes64_t>::iterator x = transients.begin(); x != transients.end(); ++x) {
|
||||
|
||||
nframes_t len = (*x) - start;
|
||||
|
||||
string new_name;
|
||||
|
||||
if (session->region_name (new_name, ar->name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pl->add_region (RegionFactory::create (ar->get_sources(), start, len, new_name), pos);
|
||||
|
||||
start = (*x);
|
||||
pos += len;
|
||||
}
|
||||
|
||||
pl->thaw ();
|
||||
|
||||
transients.clear ();
|
||||
|
||||
i = tmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
session->commit_reversible_command ();
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
Editor::split_region_at_points (boost::shared_ptr<Region> r, vector<nframes64_t>& positions)
|
||||
{
|
||||
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (r);
|
||||
|
||||
if (!ar) {
|
||||
return;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Playlist> pl = ar->playlist();
|
||||
|
||||
if (!pl) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (positions.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
vector<nframes64_t>::const_iterator x;
|
||||
|
||||
nframes64_t pos = ar->position();
|
||||
|
||||
XMLNode& before (pl->get_state());
|
||||
|
||||
x = positions.begin();
|
||||
|
||||
while (x != positions.end()) {
|
||||
if ((*x) > pos) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == positions.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pl->freeze ();
|
||||
pl->remove_region (ar);
|
||||
|
||||
do {
|
||||
|
||||
/* file start = original start + how far we from the initial position ?
|
||||
*/
|
||||
|
||||
nframes64_t file_start = ar->start() + (pos - ar->position());
|
||||
|
||||
/* length = next position - current position
|
||||
*/
|
||||
|
||||
nframes64_t len = (*x) - pos;
|
||||
|
||||
string new_name;
|
||||
|
||||
if (session->region_name (new_name, ar->name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pl->add_region (RegionFactory::create (ar->get_sources(), file_start, len, new_name), pos);
|
||||
|
||||
pos += len;
|
||||
|
||||
++x;
|
||||
|
||||
} while (x != positions.end() && (*x) < ar->last_frame());
|
||||
|
||||
pl->thaw ();
|
||||
|
||||
XMLNode& after (pl->get_state());
|
||||
|
||||
session->add_command (new MementoCommand<Playlist>(*pl, &before, &after));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ class PublicEditor : public Gtk::Window, public PBD::StatefulThingWithGoingAway
|
|||
virtual void restore_editing_space() = 0;
|
||||
virtual nframes64_t get_preferred_edit_position (bool ignore_playhead = false) = 0;
|
||||
virtual void toggle_meter_updating() = 0;
|
||||
virtual void split_region_at_points (boost::shared_ptr<ARDOUR::Region>, std::vector<nframes64_t>&) = 0;
|
||||
|
||||
sigc::signal<void> ZoomFocusChanged;
|
||||
sigc::signal<void> ZoomChanged;
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ RhythmFerret::run_percussion_onset_analysis (boost::shared_ptr<Readable> readabl
|
|||
t.set_threshold (detection_threshold_adjustment.get_value());
|
||||
t.set_sensitivity (sensitivity_adjustment.get_value());
|
||||
|
||||
if (t.run ("", readable, i, these_results)) {
|
||||
if (t.run ("", readable.get(), i, these_results)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -289,83 +289,13 @@ RhythmFerret::do_split_action ()
|
|||
|
||||
(*i)->get_time_axis_view().hide_temporary_lines ();
|
||||
|
||||
do_region_split ((*i), current_results);
|
||||
editor.split_region_at_points ((*i)->region(), current_results);
|
||||
|
||||
/* i is invalid at this point */
|
||||
|
||||
i = tmp;
|
||||
}
|
||||
|
||||
session->commit_reversible_command ();
|
||||
}
|
||||
|
||||
void
|
||||
RhythmFerret::do_region_split (RegionView* rv, const vector<nframes64_t>& positions)
|
||||
{
|
||||
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> (rv->region());
|
||||
|
||||
if (!ar) {
|
||||
return;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Playlist> pl = ar->playlist();
|
||||
|
||||
if (!pl) {
|
||||
return;
|
||||
}
|
||||
|
||||
vector<nframes64_t>::const_iterator x;
|
||||
|
||||
nframes64_t pos = ar->position();
|
||||
|
||||
XMLNode& before (pl->get_state());
|
||||
|
||||
x = positions.begin();
|
||||
|
||||
while (x != positions.end()) {
|
||||
if ((*x) > pos) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (x == positions.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pl->freeze ();
|
||||
pl->remove_region (ar);
|
||||
|
||||
do {
|
||||
|
||||
/* file start = original start + how far we from the initial position ?
|
||||
*/
|
||||
|
||||
nframes64_t file_start = ar->start() + (pos - ar->position());
|
||||
|
||||
/* length = next position - current position
|
||||
*/
|
||||
|
||||
nframes64_t len = (*x) - pos;
|
||||
|
||||
string new_name;
|
||||
|
||||
if (session->region_name (new_name, ar->name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pl->add_region (RegionFactory::create (ar->get_sources(), file_start, len, new_name), pos);
|
||||
|
||||
pos += len;
|
||||
|
||||
++x;
|
||||
|
||||
} while (x != positions.end() && (*x) < ar->last_frame());
|
||||
|
||||
pl->thaw ();
|
||||
|
||||
XMLNode& after (pl->get_state());
|
||||
|
||||
session->add_command (new MementoCommand<Playlist>(*pl, &before, &after));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class AudioAnalyser {
|
|||
|
||||
/* analysis object should provide a run method
|
||||
that accepts a path to write the results to (optionally empty)
|
||||
a boost::shared_ptr<Readable> to read data from
|
||||
a Readable* to read data from
|
||||
and a reference to a type-specific container to return the
|
||||
results.
|
||||
*/
|
||||
|
|
@ -59,7 +59,7 @@ class AudioAnalyser {
|
|||
nframes64_t stepsize;
|
||||
|
||||
int initialize_plugin (AnalysisPluginKey name, float sample_rate);
|
||||
int analyse (const std::string& path, boost::shared_ptr<Readable>, uint32_t channel);
|
||||
int analyse (const std::string& path, Readable*, uint32_t channel);
|
||||
|
||||
/* instances of an analysis object will have this method called
|
||||
whenever there are results to process. if out is non-null,
|
||||
|
|
|
|||
|
|
@ -148,6 +148,8 @@ class AudioRegion : public Region
|
|||
|
||||
void set_playlist (boost::weak_ptr<Playlist>);
|
||||
|
||||
int get_transients (std::vector<nframes64_t>&);
|
||||
|
||||
private:
|
||||
friend class RegionFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class TransientDetector : public AudioAnalyser
|
|||
float get_threshold () const;
|
||||
float get_sensitivity () const;
|
||||
|
||||
int run (const std::string& path, boost::shared_ptr<Readable>, uint32_t channel, std::vector<nframes64_t>& results);
|
||||
int run (const std::string& path, Readable*, uint32_t channel, std::vector<nframes64_t>& results);
|
||||
|
||||
protected:
|
||||
std::vector<nframes64_t>* current_results;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ AudioAnalyser::initialize_plugin (AnalysisPluginKey key, float sr)
|
|||
plugin = loader->loadPlugin (key, sr, PluginLoader::ADAPT_ALL);
|
||||
|
||||
if (!plugin) {
|
||||
error << string_compose (_("VAMP Plugin \"%1\" could not be loaded"), key) << endmsg;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ AudioAnalyser::reset ()
|
|||
}
|
||||
|
||||
int
|
||||
AudioAnalyser::analyse (const string& path, boost::shared_ptr<Readable> src, uint32_t channel)
|
||||
AudioAnalyser::analyse (const string& path, Readable* src, uint32_t channel)
|
||||
{
|
||||
ofstream ofile;
|
||||
Plugin::FeatureSet onsets;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
#include <ardour/audiofilter.h>
|
||||
#include <ardour/audiofilesource.h>
|
||||
#include <ardour/region_factory.h>
|
||||
#include <ardour/transient_detector.h>
|
||||
|
||||
#include "i18n.h"
|
||||
#include <locale.h>
|
||||
|
|
@ -1502,6 +1503,68 @@ AudioRegion::set_playlist (boost::weak_ptr<Playlist> wpl)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
AudioRegion::get_transients (vector<nframes64_t>& results)
|
||||
{
|
||||
if (!playlist()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
TransientDetector t (playlist()->session().frame_rate());
|
||||
bool existing_results = !results.empty();
|
||||
|
||||
for (uint32_t i = 0; i < n_channels(); ++i) {
|
||||
|
||||
vector<nframes64_t> these_results;
|
||||
|
||||
t.reset ();
|
||||
|
||||
if (t.run ("", this, i, these_results)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* translate all transients to give absolute position */
|
||||
|
||||
for (vector<nframes64_t>::iterator i = these_results.begin(); i != these_results.end(); ++i) {
|
||||
(*i) += _position;
|
||||
}
|
||||
|
||||
/* merge */
|
||||
|
||||
results.insert (results.end(), these_results.begin(), these_results.end());
|
||||
}
|
||||
|
||||
if (!results.empty() && (existing_results || n_channels() > 1)) {
|
||||
|
||||
/* now resort to bring transients from different channels together */
|
||||
|
||||
sort (results.begin(), results.end());
|
||||
|
||||
/* remove duplicates or other things that are too close */
|
||||
|
||||
vector<nframes64_t>::iterator i = results.begin();
|
||||
nframes64_t curr = (*i);
|
||||
|
||||
/* XXX force a 3msec gap - use a config variable */
|
||||
|
||||
nframes64_t gap_frames = (nframes64_t) floor (3.0 * (playlist()->session().frame_rate() / 1000.0));
|
||||
|
||||
++i;
|
||||
|
||||
while (i != results.end()) {
|
||||
if (((*i) == curr) || (((*i) - curr) < gap_frames)) {
|
||||
i = results.erase (i);
|
||||
} else {
|
||||
++i;
|
||||
curr = *i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
int region_read_peaks_from_c (void *arg, uint32_t npeaks, uint32_t start, uint32_t cnt, intptr_t data, uint32_t n_chan, double samples_per_unit)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using namespace ARDOUR;
|
|||
using namespace std;
|
||||
|
||||
TransientDetector::TransientDetector (float sr)
|
||||
: AudioAnalyser (sr, X_("ardour-vamp-plugins:percussiononsets"))
|
||||
: AudioAnalyser (sr, X_("libardourvampplugins:percussiononsets"))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ TransientDetector::~TransientDetector()
|
|||
}
|
||||
|
||||
int
|
||||
TransientDetector::run (const std::string& path, boost::shared_ptr<Readable> src, uint32_t channel, vector<nframes64_t>& results)
|
||||
TransientDetector::run (const std::string& path, Readable* src, uint32_t channel, vector<nframes64_t>& results)
|
||||
{
|
||||
current_results = &results;
|
||||
int ret = analyse (path, src, channel);
|
||||
|
|
@ -37,7 +37,7 @@ TransientDetector::use_features (Plugin::FeatureSet& features, ostream* out)
|
|||
(*out) << (*f).timestamp.toString() << endl;
|
||||
}
|
||||
|
||||
current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, sample_rate));
|
||||
current_results->push_back (RealTime::realTime2Frame ((*f).timestamp, (nframes_t) floor(sample_rate)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue