]> sigrok.org Git - pulseview.git/commitdiff
Refactoring: move samplerate algo from View to Session
authorSoeren Apel <redacted>
Wed, 4 Nov 2015 15:41:34 +0000 (16:41 +0100)
committerSoeren Apel <redacted>
Wed, 4 Nov 2015 16:56:17 +0000 (17:56 +0100)
pv/mainwindow.cpp
pv/session.cpp
pv/session.hpp
pv/view/view.cpp

index 195c460a1de90f3aea20b3fb4af9745a6a34103b..0184ef0937c2fd6029cbd0899c8d6719ed3899db 100644 (file)
@@ -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<pv::data::SignalData> d : session_.get_data()) {
-               assert(d);
-               const vector< shared_ptr<pv::data::Segment> > segments =
-                       d->segments();
-               for (const shared_ptr<pv::data::Segment> &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();
 
index e6fb52fd7dd0d589342ed877ee573cbb572a4755..07405fe4ba79de4a0003c9d08070ed47406c23a0 100644 (file)
@@ -222,6 +222,25 @@ set< shared_ptr<data::SignalData> > Session::get_data() const
        return data;
 }
 
+double Session::get_samplerate() const
+{
+       double samplerate = 0.0;
+
+       for (const shared_ptr<pv::data::SignalData> d : get_data()) {
+               assert(d);
+               const vector< shared_ptr<pv::data::Segment> > segments =
+                       d->segments();
+               for (const shared_ptr<pv::data::Segment> &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<view::Signal> > Session::signals() const
 {
        shared_lock<shared_mutex> lock(signals_mutex_);
index 2eb4f630fd3be357161272f3b1ae60028390ce1b..0a8f018cbc1216a898d63d0393f80236cca486f7 100644 (file)
@@ -114,6 +114,8 @@ public:
 
        std::set< std::shared_ptr<data::SignalData> > get_data() const;
 
+       double get_samplerate() const;
+
        const std::unordered_set< std::shared_ptr<view::Signal> >
                signals() const;
 
index 99a28e4d7ee187b805490699ace737428cc31e1f..7de1c792c06fa9880eee2d295e4cc8fc9672ef19 100644 (file)
@@ -349,24 +349,12 @@ void View::zoom_one_to_one()
        if (visible_data.empty())
                return;
 
-       double samplerate = 0.0;
-       for (const shared_ptr<SignalData> d : visible_data) {
-               assert(d);
-               const vector< shared_ptr<Segment> > segments =
-                       d->segments();
-               for (const shared_ptr<Segment> &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)