From: Soeren Apel Date: Tue, 5 May 2020 16:21:46 +0000 (+0200) Subject: Add SignalBase::clear_sample_data() and local samplerate values X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=464f05d59f205225eff1cb435f9ae11716dbe9de;p=pulseview.git Add SignalBase::clear_sample_data() and local samplerate values --- diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index f8fe473d..57d09502 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -31,7 +31,8 @@ namespace pv { namespace data { Analog::Analog() : - SignalData() + SignalData(), + samplerate_(1) // Default is 1 Hz to prevent division-by-zero errors { } @@ -63,12 +64,14 @@ void Analog::clear() samples_cleared(); } -double Analog::get_samplerate() const +void Analog::set_samplerate(double value) { - if (segments_.empty()) - return 1.0; + samplerate_ = value; +} - return segments_.front()->samplerate(); +double Analog::get_samplerate() const +{ + return samplerate_; } uint64_t Analog::max_sample_count() const diff --git a/pv/data/analog.hpp b/pv/data/analog.hpp index c0b9a013..026d8046 100644 --- a/pv/data/analog.hpp +++ b/pv/data/analog.hpp @@ -53,6 +53,8 @@ public: void clear(); + void set_samplerate(double value); + double get_samplerate() const; uint64_t max_sample_count() const; @@ -71,6 +73,7 @@ Q_SIGNALS: void min_max_changed(float min, float max); private: + double samplerate_; deque< shared_ptr > segments_; }; diff --git a/pv/data/logic.cpp b/pv/data/logic.cpp index 516060a0..7aefbf5f 100644 --- a/pv/data/logic.cpp +++ b/pv/data/logic.cpp @@ -32,6 +32,7 @@ namespace data { Logic::Logic(unsigned int num_channels) : SignalData(), + samplerate_(1), // Default is 1 Hz to prevent division-by-zero errors num_channels_(num_channels) { assert(num_channels_ > 0); @@ -69,12 +70,14 @@ void Logic::clear() samples_cleared(); } -double Logic::get_samplerate() const +void Logic::set_samplerate(double value) { - if (segments_.empty()) - return 1.0; + samplerate_ = value; +} - return segments_.front()->samplerate(); +double Logic::get_samplerate() const +{ + return samplerate_; } uint64_t Logic::max_sample_count() const diff --git a/pv/data/logic.hpp b/pv/data/logic.hpp index e0fb7dd1..18622c1e 100644 --- a/pv/data/logic.hpp +++ b/pv/data/logic.hpp @@ -54,6 +54,8 @@ public: void clear(); + void set_samplerate(double value); + double get_samplerate() const; uint64_t max_sample_count() const; @@ -68,6 +70,7 @@ Q_SIGNALS: uint64_t end_sample); private: + double samplerate_; const unsigned int num_channels_; deque< shared_ptr > segments_; }; diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index fde99e2b..d09615c8 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -185,6 +185,15 @@ void SignalBase::set_data(shared_ptr data) } } +void SignalBase::clear_sample_data() +{ + if (analog_data()) + analog_data()->clear(); + + if (logic_data()) + logic_data()->clear(); +} + shared_ptr SignalBase::analog_data() const { shared_ptr result = nullptr; diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 6decf26e..d6f11d82 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -171,6 +171,11 @@ public: */ void set_data(shared_ptr data); + /** + * Clears all sample data and removes all associated segments. + */ + void clear_sample_data(); + /** * Get the internal data as analog data object in case of analog type. */ diff --git a/pv/data/signaldata.hpp b/pv/data/signaldata.hpp index 5168fee8..6d2283ab 100644 --- a/pv/data/signaldata.hpp +++ b/pv/data/signaldata.hpp @@ -51,6 +51,8 @@ public: virtual uint64_t max_sample_count() const = 0; + virtual void set_samplerate(double value) = 0; + virtual double get_samplerate() const = 0; };