]> sigrok.org Git - pulseview.git/blobdiff - pv/data/analog.cpp
Session: Fix issue #67 by improving error handling
[pulseview.git] / pv / data / analog.cpp
index eb25629fe68fa0f5f94d165ca6f5d7a0a66e222e..da9736b53fe29210d808fbb54a86c06c64889833 100644 (file)
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <cassert>
 
-#include "analog.h"
-#include "analogsnapshot.h"
+#include "analog.hpp"
+#include "analogsegment.hpp"
 
 using std::deque;
 using std::max;
 using std::shared_ptr;
+using std::vector;
 
 namespace pv {
 namespace data {
 
 Analog::Analog() :
-       SignalData()
+       SignalData(),
+       samplerate_(1)  // Default is 1 Hz to prevent division-by-zero errors
 {
 }
 
-void Analog::push_snapshot(shared_ptr<AnalogSnapshot> &snapshot)
+void Analog::push_segment(shared_ptr<AnalogSegment> &segment)
 {
-       snapshots_.push_front(snapshot);
+       segments_.push_back(segment);
+
+       if ((samplerate_ == 1) && (segment->samplerate() > 1))
+               samplerate_ = segment->samplerate();
+
+       connect(segment.get(), SIGNAL(completed()), this, SLOT(on_segment_completed()));
 }
 
-deque< shared_ptr<AnalogSnapshot> >& Analog::get_snapshots()
+const deque< shared_ptr<AnalogSegment> >& Analog::analog_segments() const
 {
-       return snapshots_;
+       return segments_;
+}
+
+vector< shared_ptr<Segment> > Analog::segments() const
+{
+       return vector< shared_ptr<Segment> >(
+               segments_.begin(), segments_.end());
+}
+
+uint32_t Analog::get_segment_count() const
+{
+       return (uint32_t)segments_.size();
 }
 
 void Analog::clear()
 {
-       snapshots_.clear();
+       if (!segments_.empty()) {
+               segments_.clear();
+
+               samples_cleared();
+       }
+}
+
+void Analog::set_samplerate(double value)
+{
+       samplerate_ = value;
 }
 
-uint64_t Analog::get_max_sample_count() const
+double Analog::get_samplerate() const
+{
+       return samplerate_;
+}
+
+uint64_t Analog::max_sample_count() const
 {
        uint64_t l = 0;
-       for (const std::shared_ptr<AnalogSnapshot> s : snapshots_) {
+       for (const shared_ptr<AnalogSegment>& s : segments_) {
                assert(s);
                l = max(l, s->get_sample_count());
        }
        return l;
 }
 
+void Analog::notify_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
+       uint64_t end_sample)
+{
+       samples_added(segment, start_sample, end_sample);
+}
+
+void Analog::notify_min_max_changed(float min, float max)
+{
+       min_max_changed(min, max);
+}
+
+void Analog::on_segment_completed()
+{
+       segment_completed();
+}
+
 } // namespace data
 } // namespace pv