From: Soeren Apel Date: Tue, 1 Aug 2017 18:58:46 +0000 (+0200) Subject: Restart min-max-based conversion if min or max change X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8e15445ccd6994348eb74b24b5324d26c9be0cce;p=pulseview.git Restart min-max-based conversion if min or max change --- diff --git a/pv/data/analog.cpp b/pv/data/analog.cpp index 854dae3e..51e7f495 100644 --- a/pv/data/analog.cpp +++ b/pv/data/analog.cpp @@ -74,5 +74,10 @@ void Analog::notify_samples_added(QObject* segment, uint64_t start_sample, samples_added(segment, start_sample, end_sample); } +void Analog::notify_min_max_changed(float min, float max) +{ + min_max_changed(min, max); +} + } // namespace data } // namespace pv diff --git a/pv/data/analog.hpp b/pv/data/analog.hpp index 30860ce1..633c6fba 100644 --- a/pv/data/analog.hpp +++ b/pv/data/analog.hpp @@ -56,12 +56,16 @@ public: void notify_samples_added(QObject* segment, uint64_t start_sample, uint64_t end_sample); + void notify_min_max_changed(float min, float max); + Q_SIGNALS: void samples_cleared(); void samples_added(QObject* segment, uint64_t start_sample, uint64_t end_sample); + void min_max_changed(float min, float max); + private: deque< shared_ptr > segments_; }; diff --git a/pv/data/analogsegment.cpp b/pv/data/analogsegment.cpp index 6dc2b915..0610a4a8 100644 --- a/pv/data/analogsegment.cpp +++ b/pv/data/analogsegment.cpp @@ -178,6 +178,7 @@ void AnalogSegment::append_payload_to_envelope_levels() e0.length = sample_count_ / EnvelopeScaleFactor; // Calculate min/max values in case we have too few samples for an envelope + const float old_min_value = min_value_, old_max_value = max_value_; if (sample_count_ < EnvelopeScaleFactor) { it = begin_raw_sample_iteration(0); for (uint64_t i = 0; i < sample_count_; i++) { @@ -257,6 +258,10 @@ void AnalogSegment::append_payload_to_envelope_levels() *dest_ptr = sub_sample; } } + + // Notify if the min or max value changed + if ((old_min_value != min_value_) || (old_max_value != max_value_)) + owner_.min_max_changed(min_value_, max_value_); } } // namespace data diff --git a/pv/data/signalbase.cpp b/pv/data/signalbase.cpp index b455111a..797bd456 100644 --- a/pv/data/signalbase.cpp +++ b/pv/data/signalbase.cpp @@ -140,6 +140,14 @@ void SignalBase::set_data(shared_ptr data) this, SLOT(on_samples_cleared())); disconnect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)), this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t))); + + if (channel_type_ == AnalogChannel) { + shared_ptr analog = analog_data(); + assert(analog); + + disconnect(analog.get(), SIGNAL(min_max_changed(float, float)), + this, SLOT(on_min_max_changed(float, float))); + } } data_ = data; @@ -149,6 +157,14 @@ void SignalBase::set_data(shared_ptr data) this, SLOT(on_samples_cleared())); connect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)), this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t))); + + if (channel_type_ == AnalogChannel) { + shared_ptr analog = analog_data(); + assert(analog); + + connect(analog.get(), SIGNAL(min_max_changed(float, float)), + this, SLOT(on_min_max_changed(float, float))); + } } } @@ -560,14 +576,23 @@ void SignalBase::on_samples_added(QObject* segment, uint64_t start_sample, samples_added(segment, start_sample, end_sample); } +void SignalBase::on_min_max_changed(float min, float max) +{ + (void)min; + (void)max; + + // Restart conversion if one is enabled and uses an automatic threshold + if ((conversion_type_ != NoConversion) && + (get_current_conversion_preset() == 0)) + start_conversion(); +} + void SignalBase::on_capture_state_changed(int state) { if (state == Session::Running) { - if (conversion_type_ != NoConversion) { - // Restart conversion - stop_conversion(); + // Restart conversion if one is enabled + if (conversion_type_ != NoConversion) start_conversion(); - } } } diff --git a/pv/data/signalbase.hpp b/pv/data/signalbase.hpp index 67b3f7c4..32085a43 100644 --- a/pv/data/signalbase.hpp +++ b/pv/data/signalbase.hpp @@ -279,6 +279,8 @@ private Q_SLOTS: void on_samples_added(QObject* segment, uint64_t start_sample, uint64_t end_sample); + void on_min_max_changed(float min, float max); + void on_capture_state_changed(int state); protected: