Skip to content

Commit

Permalink
(Source List) Clean up the natural_position implementation (libardour…
Browse files Browse the repository at this point in the history
… part).
  • Loading branch information
BenLoftis committed Aug 1, 2019
1 parent 77950c3 commit edde5d6
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 74 deletions.
2 changes: 1 addition & 1 deletion libs/ardour/analyser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Analyser::work ()

boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource> (src);

if (afs && afs->length(afs->timeline_position())) {
if (afs && afs->length(afs->natural_position())) {
Glib::Threads::Mutex::Lock lm (analysis_active_lock);
analyse_audio_file_source (afs);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/ardour/audiofilesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class LIBARDOUR_API AudioFileSource : public AudioSource, public FileSource {

int init (const std::string& idstr, bool must_exist);

virtual void set_header_timeline_position () = 0;
virtual void set_header_natural_position () = 0;
virtual void handle_header_position_change () {}

int move_dependents_to_trash();
Expand Down
1 change: 0 additions & 1 deletion libs/ardour/ardour/caimportable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class LIBARDOUR_API CAImportableSource : public ImportableSource {
samplecnt_t length() const;
samplecnt_t samplerate() const;
void seek (samplepos_t pos);
samplepos_t natural_position() const { return 0; }
bool clamped_at_unity () const { return false; }

protected:
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/ardour/coreaudiosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LIBARDOUR_API CoreAudioSource : public AudioFileSource {
uint32_t channel_count () const { return n_channels; }

int flush_header () {return 0;};
void set_header_timeline_position () {};
void set_header_natural_position () {};
bool clamped_at_unity () const { return false; }

void flush () {}
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/ardour/silentfilesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class LIBARDOUR_API SilentFileSource : public AudioFileSource {

samplecnt_t write_unlocked (Sample */*dst*/, samplecnt_t /*cnt*/) { return 0; }

void set_header_timeline_position () {}
void set_header_natural_position () {}

int read_peaks_with_fpp (PeakData *peaks, samplecnt_t npeaks, samplepos_t /*start*/, samplecnt_t /*cnt*/,
double /*samples_per_pixel*/, samplecnt_t /*fpp*/) const {
Expand Down
6 changes: 3 additions & 3 deletions libs/ardour/ardour/sndfileimportable.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class LIBARDOUR_API SndFileImportableSource : public ImportableSource {
uint32_t channels() const;
samplecnt_t length() const;
samplecnt_t samplerate() const;
void seek (samplepos_t pos);
samplepos_t natural_position() const;
bool clamped_at_unity () const;
void seek (samplepos_t pos);
bool clamped_at_unity () const;
samplepos_t natural_position () const;

protected:
SF_INFO sf_info;
Expand Down
6 changes: 2 additions & 4 deletions libs/ardour/ardour/sndfilesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
int flush_header ();
void flush ();

samplepos_t natural_position () const;

samplepos_t last_capture_start_sample() const;
void mark_capture_start (samplepos_t);
void mark_capture_end ();
Expand All @@ -81,7 +79,7 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
void close ();

void set_path (const std::string& p);
void set_header_timeline_position ();
void set_header_natural_position ();

samplecnt_t read_unlocked (Sample *dst, samplepos_t start, samplecnt_t cnt) const;
samplecnt_t write_unlocked (Sample *dst, samplecnt_t cnt);
Expand Down Expand Up @@ -111,7 +109,7 @@ class LIBARDOUR_API SndFileSource : public AudioFileSource {
Sample* xfade_buf;

samplecnt_t crossfade (Sample* data, samplecnt_t cnt, int dir);
void set_timeline_position (samplepos_t);
void set_natural_position (samplepos_t);
samplecnt_t destructive_write_unlocked (Sample *dst, samplecnt_t cnt);
samplecnt_t nondestructive_write_unlocked (Sample *dst, samplecnt_t cnt);
void handle_header_position_change ();
Expand Down
10 changes: 5 additions & 5 deletions libs/ardour/ardour/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class LIBARDOUR_API Source : public SessionObject,
void set_take_id (std::string id) { _take_id =id; }
const std::string& take_id () const { return _take_id; }

virtual samplepos_t natural_position() const { return 0; }

void mark_for_remove();

virtual void mark_streaming_write_started (const Lock& lock) {}
Expand Down Expand Up @@ -104,8 +102,9 @@ class LIBARDOUR_API Source : public SessionObject,
std::string get_transients_path() const;
int load_transients (const std::string&);

samplepos_t timeline_position() const { return _timeline_position; }
virtual void set_timeline_position (samplepos_t pos);
virtual samplepos_t natural_position() const { return _natural_position; }
virtual void set_natural_position (samplepos_t pos);
bool have_natural_position() const { return _have_natural_position; }

void set_allow_remove_if_empty (bool yn);

Expand All @@ -129,7 +128,8 @@ class LIBARDOUR_API Source : public SessionObject,
Flag _flags;
time_t _timestamp;
std::string _take_id;
samplepos_t _timeline_position;
samplepos_t _natural_position;
samplepos_t _have_natural_position;
bool _analysed;
mutable Glib::Threads::Mutex _lock;
mutable Glib::Threads::Mutex _analysis_lock;
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/ardour/srcfilesource.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class LIBARDOUR_API SrcFileSource : public AudioFileSource {
int update_header (samplepos_t /*when*/, struct tm&, time_t) { return 0; }
int flush_header () { return 0; }
void flush () { }
void set_header_timeline_position () {};
void set_header_natural_position () {};
void set_length (samplecnt_t /*len*/) {};

float sample_rate () const { return _session.nominal_sample_rate(); }
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/audio_track.cc
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ AudioTrack::freeze_me (InterThreadInfo& itt)
PropertyList plist;

plist.add (Properties::start, 0);
plist.add (Properties::length, srcs[0]->length(srcs[0]->timeline_position()));
plist.add (Properties::length, srcs[0]->length(srcs[0]->natural_position()));
plist.add (Properties::name, region_name);
plist.add (Properties::whole_file, true);

Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/audioregion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ AudioRegion::master_read_at (Sample *buf, Sample* /*mixdown_buffer*/, float* /*g

assert (cnt >= 0);
return read_from_sources (
_master_sources, _master_sources.front()->length (_master_sources.front()->timeline_position()),
_master_sources, _master_sources.front()->length (_master_sources.front()->natural_position()),
buf, position, cnt, chan_n
);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/ardour/audiosource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ AudioSource::initialize_peakfile (const string& audio_path, const bool in_sessio

/* we found it in the peaks dir, so check it out */

if (statbuf.st_size == 0 || (statbuf.st_size < (off_t) ((length(_timeline_position) / _FPP) * sizeof (PeakData)))) {
if (statbuf.st_size == 0 || (statbuf.st_size < (off_t) ((length(_natural_position) / _FPP) * sizeof (PeakData)))) {
DEBUG_TRACE(DEBUG::Peaks, string_compose("Peakfile %1 is empty\n", _peakpath));
_peaks_built = false;
} else {
Expand Down Expand Up @@ -1066,7 +1066,7 @@ samplecnt_t
AudioSource::available_peaks (double zoom_factor) const
{
if (zoom_factor < _FPP) {
return length(_timeline_position); // peak data will come from the audio file
return length(_natural_position); // peak data will come from the audio file
}

/* peak data comes from peakfile, but the filesize might not represent
Expand Down
13 changes: 8 additions & 5 deletions libs/ardour/disk_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void
DiskWriter::non_realtime_locate (samplepos_t position)
{
if (_midi_write_source) {
_midi_write_source->set_timeline_position (position);
_midi_write_source->set_natural_position (position);
}

DiskIOProcessor::non_realtime_locate (position);
Expand Down Expand Up @@ -1219,9 +1219,7 @@ DiskWriter::transport_stopped_wallclock (struct tm& when, time_t twhen, bool abo
char buf[128];
strftime (buf, sizeof(buf), "%F %H.%M.%S", &when);
as->set_take_id ( buf );

Source::SourcePropertyChanged(as);


if (Config->get_auto_analyse_audio()) {
Analyser::queue_source_for_analysis (as, true);
}
Expand All @@ -1232,6 +1230,11 @@ DiskWriter::transport_stopped_wallclock (struct tm& when, time_t twhen, bool abo
if (_midi_write_source) {
midi_srcs.push_back (_midi_write_source);
}

(*chan)->write_source->stamp (twhen);

/* "re-announce the source to the world */
Source::SourcePropertyChanged ((*chan)->write_source);
}


Expand Down Expand Up @@ -1261,7 +1264,7 @@ DiskWriter::transport_stopped_wallclock (struct tm& when, time_t twhen, bool abo

midi_srcs.push_back (_midi_write_source);

_midi_write_source->set_timeline_position (capture_info.front()->start);
_midi_write_source->set_natural_position (capture_info.front()->start);
_midi_write_source->set_captured_for (_name);

char buf[128];
Expand Down
2 changes: 0 additions & 2 deletions libs/ardour/file_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ FileSource::removable () const
int
FileSource::init (const string& pathstr, bool must_exist)
{
_timeline_position = 0;

if (Stateful::loading_state_version < 3000) {
if (!find_2X (_session, _type, pathstr, must_exist, _file_is_new, _channel, _path)) {
throw MissingSource (pathstr, _type);
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Filter::finish (boost::shared_ptr<Region> region, SourceList& nsrcs, string regi

boost::shared_ptr<SMFSource> smfs = boost::dynamic_pointer_cast<SMFSource>(*si);
if (smfs) {
smfs->set_timeline_position (region->position());
smfs->set_natural_position (region->position());
smfs->flush ();
}

Expand Down
4 changes: 2 additions & 2 deletions libs/ardour/import.cc
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static bool
create_mono_sources_for_writing (const vector<string>& new_paths,
Session& sess, uint32_t samplerate,
vector<boost::shared_ptr<Source> >& newfiles,
samplepos_t timeline_position)
samplepos_t natural_position)
{
for (vector<string>::const_iterator i = new_paths.begin(); i != new_paths.end(); ++i) {

Expand Down Expand Up @@ -212,7 +212,7 @@ create_mono_sources_for_writing (const vector<string>& new_paths,

boost::shared_ptr<AudioFileSource> afs;
if ((afs = boost::dynamic_pointer_cast<AudioFileSource>(source)) != 0) {
afs->set_timeline_position(timeline_position);
afs->set_natural_position (natural_position);
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/luabindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ LuaBindings::common (lua_State* L)
.addFunction ("writable", &Source::writable)
.addFunction ("has_been_analysed", &Source::has_been_analysed)
.addFunction ("can_be_analysed", &Source::can_be_analysed)
.addFunction ("timeline_position", &Source::timeline_position)
.addFunction ("timeline_position", &Source::natural_position) /* duplicate */
.addFunction ("use_count", &Source::use_count)
.addFunction ("used", &Source::used)
.addFunction ("ancestor_name", &Source::ancestor_name)
Expand Down
4 changes: 2 additions & 2 deletions libs/ardour/midi_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ MidiSource::mark_write_starting_now (samplecnt_t position,
because it is not RT-safe.
*/

set_timeline_position(position);
set_natural_position (position);
_capture_length = capture_length;
_capture_loop_length = loop_length;

Expand Down Expand Up @@ -417,7 +417,7 @@ MidiSource::write_to (const Lock& lock, boost::shared_ptr<MidiSource> newsrc, Te
{
Lock newsrc_lock (newsrc->mutex ());

newsrc->set_timeline_position (_timeline_position);
newsrc->set_natural_position (_natural_position);
newsrc->copy_interpolation_from (this);
newsrc->copy_automation_state_from (this);

Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/region_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ RegionFactory::create (boost::shared_ptr<Region> region, const SourceList& srcs,

if ((other = boost::dynamic_pointer_cast<AudioRegion>(region)) != 0) {

// XXX use me in caller where plist is setup, this is start i think srcs.front()->length (srcs.front()->timeline_position())
// XXX use me in caller where plist is setup, this is start i think srcs.front()->length (srcs.front()->natural_position())

ret = boost::shared_ptr<Region> (new AudioRegion (other, srcs));

Expand Down
4 changes: 2 additions & 2 deletions libs/ardour/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6274,7 +6274,7 @@ Session::write_one_track (Track& track, samplepos_t start, samplepos_t end,
if (!endpoint || for_export) {
ev.set_time(ev.time() - position);
}
ms->append_event_samples(lock, ev, ms->timeline_position());
ms->append_event_samples(lock, ev, ms->natural_position());
}
}
}
Expand Down Expand Up @@ -6328,7 +6328,7 @@ Session::write_one_track (Track& track, samplepos_t start, samplepos_t end,
PropertyList plist;

plist.add (Properties::start, 0);
plist.add (Properties::length, srcs.front()->length(srcs.front()->timeline_position()));
plist.add (Properties::length, srcs.front()->length(srcs.front()->natural_position()));
plist.add (Properties::name, region_name_from_path (srcs.front()->name(), true));

result = RegionFactory::create (srcs, plist);
Expand Down
2 changes: 1 addition & 1 deletion libs/ardour/session_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@ Session::cleanup_sources (CleanupReport& rep)
* capture files.
*/

if (!i->second->used() && (i->second->length(i->second->timeline_position()) > 0)) {
if (!i->second->used() && (i->second->length(i->second->natural_position()) > 0)) {
dead_sources.push_back (i->second);
i->second->drop_references ();
}
Expand Down
Loading

0 comments on commit edde5d6

Please sign in to comment.