From: Soeren Apel Date: Wed, 4 Nov 2015 15:41:34 +0000 (+0100) Subject: Refactoring: move samplerate algo from View to Session X-Git-Tag: pulseview-0.3.0~55 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=2220e94218298b208041c5e828595d9e1b842c88;p=pulseview.git Refactoring: move samplerate algo from View to Session --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 195c460a..0184ef09 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -666,20 +666,6 @@ void MainWindow::save_selection_to_file() // Stop any currently running capture session session_.stop_capture(); - // Get sample rate - double samplerate = 0.0; - - for (const shared_ptr d : session_.get_data()) { - assert(d); - const vector< shared_ptr > segments = - d->segments(); - for (const shared_ptr &s : segments) - samplerate = std::max(samplerate, s->samplerate()); - } - - if (samplerate == 0.0) - samplerate = 1; - // Verify that the cursors are active and fetch their values if (!view_->cursors()->enabled()) { show_session_error(tr("Missing Cursors"), tr("You need to set the " \ @@ -688,6 +674,8 @@ void MainWindow::save_selection_to_file() return; } + const double samplerate = session_.get_samplerate(); + const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); diff --git a/pv/session.cpp b/pv/session.cpp index e6fb52fd..07405fe4 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -222,6 +222,25 @@ set< shared_ptr > Session::get_data() const return data; } +double Session::get_samplerate() const +{ + double samplerate = 0.0; + + for (const shared_ptr d : get_data()) { + assert(d); + const vector< shared_ptr > segments = + d->segments(); + for (const shared_ptr &s : segments) + samplerate = std::max(samplerate, s->samplerate()); + } + + // If there is no sample rate given we use samples as unit + if (samplerate == 0.0) + samplerate = 1.0; + + return samplerate; +} + const unordered_set< shared_ptr > Session::signals() const { shared_lock lock(signals_mutex_); diff --git a/pv/session.hpp b/pv/session.hpp index 2eb4f630..0a8f018c 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -114,6 +114,8 @@ public: std::set< std::shared_ptr > get_data() const; + double get_samplerate() const; + const std::unordered_set< std::shared_ptr > signals() const; diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 99a28e4d..7de1c792 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -349,24 +349,12 @@ void View::zoom_one_to_one() if (visible_data.empty()) return; - double samplerate = 0.0; - for (const shared_ptr d : visible_data) { - assert(d); - const vector< shared_ptr > segments = - d->segments(); - for (const shared_ptr &s : segments) - samplerate = max(samplerate, s->samplerate()); - } - - if (samplerate == 0.0) - return; - assert(viewport_); const int w = viewport_->width(); if (w <= 0) return; - set_zoom(1.0 / samplerate, w / 2); + set_zoom(1.0 / session_.get_samplerate(), w / 2); } void View::set_scale_offset(double scale, const Timestamp& offset)