From 94c69b3c915c3fa8f8029e514240bca5bdb90def Mon Sep 17 00:00:00 2001 From: Sakari Bergen Date: Sat, 18 Dec 2010 19:27:04 +0000 Subject: Finally implement position aware silence adding in export (i.e. bbt times are converted to frames correctly) This will work when Session::convert_to_frames_at is fixed :) git-svn-id: svn://localhost/ardour2/branches/3.0@8295 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/export_format_dialog.cc | 4 ++-- libs/ardour/ardour/export_format_specification.h | 11 ++++----- libs/ardour/ardour/export_graph_builder.h | 2 ++ libs/ardour/ardour/types.h | 30 ++++++++++++++++++++++++ libs/ardour/export_format_specification.cc | 21 ++++------------- libs/ardour/export_graph_builder.cc | 20 ++++++++++++---- libs/ardour/export_handler.cc | 1 + libs/timecode/timecode/time.h | 7 ++++++ 8 files changed, 68 insertions(+), 28 deletions(-) diff --git a/gtk2_ardour/export_format_dialog.cc b/gtk2_ardour/export_format_dialog.cc index 5fa8333116..ceea2b1082 100644 --- a/gtk2_ardour/export_format_dialog.cc +++ b/gtk2_ardour/export_format_dialog.cc @@ -228,11 +228,11 @@ ExportFormatDialog::load_state (FormatPtr spec) trim_start_checkbox.set_active (spec->trim_beginning()); silence_start = spec->silence_beginning_time(); - silence_start_checkbox.set_active (spec->silence_beginning() > 0); + silence_start_checkbox.set_active (spec->silence_beginning_time().not_zero()); trim_end_checkbox.set_active (spec->trim_end()); silence_end = spec->silence_end_time(); - silence_end_checkbox.set_active (spec->silence_end() > 0); + silence_end_checkbox.set_active (spec->silence_end_time().not_zero()); for (Gtk::ListStore::Children::iterator it = src_quality_list->children().begin(); it != src_quality_list->children().end(); ++it) { if (it->get_value (src_quality_cols.id) == spec->src_quality()) { diff --git a/libs/ardour/ardour/export_format_specification.h b/libs/ardour/ardour/export_format_specification.h index 52ed9769a7..7afb0bc734 100644 --- a/libs/ardour/ardour/export_format_specification.h +++ b/libs/ardour/ardour/export_format_specification.h @@ -47,7 +47,7 @@ class ExportFormatSpecification : public ExportFormatBase { Time (Session & session) : AnyTime (), session (session) {} Time & operator= (AnyTime const & other); - framecnt_t get_frames (framecnt_t target_rate) const; + framecnt_t get_frames_at (framepos_t position, framecnt_t target_rate) const; /* Serialization */ @@ -123,11 +123,10 @@ class ExportFormatSpecification : public ExportFormatBase { bool tag () const { return _tag && supports_tagging; } - framecnt_t silence_beginning () const { return _silence_beginning.get_frames (sample_rate()); } - framecnt_t silence_end () const { return _silence_end.get_frames (sample_rate()); } - - framecnt_t silence_beginning (framecnt_t samplerate) const { return _silence_beginning.get_frames (samplerate); } - framecnt_t silence_end (framecnt_t samplerate) const { return _silence_end.get_frames (samplerate); } + framecnt_t silence_beginning_at (framepos_t position, framecnt_t samplerate) const + { return _silence_beginning.get_frames_at (position, samplerate); } + framecnt_t silence_end_at (framepos_t position, framecnt_t samplerate) const + { return _silence_end.get_frames_at (position, samplerate); } AnyTime silence_beginning_time () const { return _silence_beginning; } AnyTime silence_end_time () const { return _silence_end; } diff --git a/libs/ardour/ardour/export_graph_builder.h b/libs/ardour/ardour/export_graph_builder.h index 1c49eccd9d..5fb16ed448 100644 --- a/libs/ardour/ardour/export_graph_builder.h +++ b/libs/ardour/ardour/export_graph_builder.h @@ -66,6 +66,7 @@ class ExportGraphBuilder bool process_normalize (); // returns true when finished void reset (); + void set_current_timespan (boost::shared_ptr span); void add_config (FileSpec const & config); private: @@ -214,6 +215,7 @@ class ExportGraphBuilder }; Session const & session; + boost::shared_ptr timespan; // Roots for export processor trees typedef boost::ptr_list ChannelConfigList; diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index d214a67ecd..78e21d5a9d 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -227,6 +227,36 @@ namespace ARDOUR { }; AnyTime() { type = Frames; frames = 0; } + + bool operator== (AnyTime const & other) const { + if (type != other.type) { return false; } + + switch (type) { + case Timecode: + return timecode == other.timecode; + case BBT: + return bbt == other.bbt; + case Frames: + return frames == other.frames; + case Seconds: + return seconds == other.seconds; + } + } + + bool not_zero() const + { + switch (type) { + case Timecode: + return timecode.hours != 0 || timecode.minutes != 0 || + timecode.seconds != 0 || timecode.frames != 0; + case BBT: + return bbt.bars != 0 || bbt.beats != 0 || bbt.ticks != 0; + case Frames: + return frames != 0; + case Seconds: + return seconds != 0; + } + } }; struct AudioRange { diff --git a/libs/ardour/export_format_specification.cc b/libs/ardour/export_format_specification.cc index c5e63733c8..b85d060e2f 100644 --- a/libs/ardour/export_format_specification.cc +++ b/libs/ardour/export_format_specification.cc @@ -42,25 +42,14 @@ using std::string; ExportFormatSpecification::Time & ExportFormatSpecification::Time::operator= (AnyTime const & other) { - type = other.type; - timecode = other.timecode; - bbt = other.bbt; - - if (type == Frames) { - frames = other.frames; - } else { - seconds = other.seconds; - } - + static_cast(*this) = other; return *this; } framecnt_t -ExportFormatSpecification::Time::get_frames (framecnt_t target_rate) const +ExportFormatSpecification::Time::get_frames_at (framepos_t position, framecnt_t target_rate) const { - //TODO position - framecnt_t duration = session.convert_to_frames_at (0, *this); - + framecnt_t duration = session.convert_to_frames_at (position, *this); return ((double) target_rate / session.frame_rate()) * duration + 0.5; } @@ -283,14 +272,14 @@ ExportFormatSpecification::get_state () node->add_property ("enabled", trim_beginning() ? "true" : "false"); node = start->add_child ("Add"); - node->add_property ("enabled", silence_beginning() > 0 ? "true" : "false"); + node->add_property ("enabled", _silence_beginning.not_zero() ? "true" : "false"); node->add_child_nocopy (_silence_beginning.get_state()); node = end->add_child ("Trim"); node->add_property ("enabled", trim_end() ? "true" : "false"); node = end->add_child ("Add"); - node->add_property ("enabled", silence_end() > 0 ? "true" : "false"); + node->add_property ("enabled", _silence_end.not_zero() ? "true" : "false"); node->add_child_nocopy (_silence_end.get_state()); return *root; diff --git a/libs/ardour/export_graph_builder.cc b/libs/ardour/export_graph_builder.cc index 885bc9786d..c7a1efebd1 100644 --- a/libs/ardour/export_graph_builder.cc +++ b/libs/ardour/export_graph_builder.cc @@ -15,6 +15,7 @@ #include "ardour/export_channel_configuration.h" #include "ardour/export_filename.h" #include "ardour/export_format_specification.h" +#include "ardour/export_timespan.h" #include "ardour/sndfile_helpers.h" #include "pbd/filesystem.h" @@ -69,11 +70,18 @@ ExportGraphBuilder::process_normalize () void ExportGraphBuilder::reset () { + timespan.reset(); channel_configs.clear (); channels.clear (); normalizers.clear (); } +void +ExportGraphBuilder::set_current_timespan (boost::shared_ptr span) +{ + timespan = span; +} + void ExportGraphBuilder::add_config (FileSpec const & config) { @@ -391,8 +399,12 @@ ExportGraphBuilder::SilenceHandler::SilenceHandler (ExportGraphBuilder & parent, silence_trimmer.reset (new SilenceTrimmer(max_frames_in)); silence_trimmer->set_trim_beginning (config.format->trim_beginning()); silence_trimmer->set_trim_end (config.format->trim_end()); - silence_trimmer->add_silence_to_beginning (config.format->silence_beginning(sample_rate)); - silence_trimmer->add_silence_to_end (config.format->silence_end(sample_rate)); + + framecnt_t sb = config.format->silence_beginning_at (parent.timespan->get_start(), sample_rate); + framecnt_t se = config.format->silence_end_at (parent.timespan->get_end(), sample_rate); + + silence_trimmer->add_silence_to_beginning (sb); + silence_trimmer->add_silence_to_end (se); add_child (new_config); } @@ -424,8 +436,8 @@ ExportGraphBuilder::SilenceHandler::operator== (FileSpec const & other_config) c ExportFormatSpecification & other_format = *other_config.format; return (format.trim_beginning() == other_format.trim_beginning()) && (format.trim_end() == other_format.trim_end()) && - (format.silence_beginning() == other_format.silence_beginning()) && - (format.silence_end() == other_format.silence_end()); + (format.silence_beginning_time() == other_format.silence_beginning_time()) && + (format.silence_end_time() == other_format.silence_end_time()); } /* ChannelConfig */ diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc index 59a023c4d8..104894abe3 100644 --- a/libs/ardour/export_handler.cc +++ b/libs/ardour/export_handler.cc @@ -162,6 +162,7 @@ ExportHandler::start_timespan () timespan_bounds = config_map.equal_range (current_timespan); graph_builder->reset (); + graph_builder->set_current_timespan (current_timespan); for (ConfigMap::iterator it = timespan_bounds.first; it != timespan_bounds.second; ++it) { // Filenames can be shared across timespans FileSpec & spec = it->second; diff --git a/libs/timecode/timecode/time.h b/libs/timecode/timecode/time.h index cd24001807..bcb078f3f1 100644 --- a/libs/timecode/timecode/time.h +++ b/libs/timecode/timecode/time.h @@ -52,6 +52,13 @@ struct Time { subframes = 0; rate = a_rate; } + + bool operator== (const Time& other) const { + return negative == other.negative && hours == other.hours && + minutes == other.minutes && seconds == other.seconds && + frames == other.frames && subframes == other.subframes && + rate == other.rate && drop == other.drop; + } std::ostream& print (std::ostream& ostr) const { if (negative) { -- cgit v1.2.3