annotate base/Selection.h @ 957:df83865d886f

Fix accidental declaration of section as bool rather than int (definitely a bug but what did it cause? see #1051, we need units here) (from coverity scan)
author Chris Cannam
date Wed, 03 Sep 2014 09:46:28 +0100
parents d03b3d956358
children cc27f35aa75c
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@8 2
Chris@8 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@8 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@8 14 */
Chris@8 15
Chris@8 16 #ifndef _SELECTION_H_
Chris@8 17 #define _SELECTION_H_
Chris@8 18
Chris@8 19 #include <cstddef>
Chris@24 20 #include <set>
Chris@8 21
Chris@46 22 #include "XmlExportable.h"
Chris@46 23
Chris@925 24 /**
Chris@925 25 * A selection object simply represents a range in time, via start and
Chris@925 26 * end frame.
Chris@925 27 *
Chris@925 28 * The end frame is the index of the frame just *after* the end of the
Chris@925 29 * selection. For example a selection of length 10 frames starting at
Chris@925 30 * time 0 will have start frame 0 and end frame 10. This will be
Chris@925 31 * contiguous with (rather than overlapping with) a selection that
Chris@925 32 * starts at frame 10.
Chris@925 33 *
Chris@925 34 * Any selection with equal start and end frames is empty,
Chris@925 35 * representing "no selection". All empty selections are equal under
Chris@925 36 * the comparison operators. The default constructor makes an empty
Chris@925 37 * selection with start and end frames equal to zero.
Chris@925 38 */
Chris@8 39 class Selection
Chris@8 40 {
Chris@8 41 public:
Chris@8 42 Selection();
Chris@928 43 Selection(int startFrame, int endFrame);
Chris@8 44 Selection(const Selection &);
Chris@8 45 Selection &operator=(const Selection &);
Chris@8 46 virtual ~Selection();
Chris@8 47
Chris@8 48 bool isEmpty() const;
Chris@928 49 int getStartFrame() const;
Chris@928 50 int getEndFrame() const;
Chris@928 51 bool contains(int frame) const;
Chris@8 52
Chris@8 53 bool operator<(const Selection &) const;
Chris@8 54 bool operator==(const Selection &) const;
Chris@8 55
Chris@8 56 protected:
Chris@928 57 int m_startFrame;
Chris@928 58 int m_endFrame;
Chris@8 59 };
Chris@8 60
Chris@46 61 class MultiSelection : public XmlExportable
Chris@24 62 {
Chris@24 63 public:
Chris@24 64 MultiSelection();
Chris@24 65 virtual ~MultiSelection();
Chris@24 66
Chris@24 67 typedef std::set<Selection> SelectionList;
Chris@24 68
Chris@24 69 const SelectionList &getSelections() const;
Chris@24 70 void setSelection(const Selection &selection);
Chris@24 71 void addSelection(const Selection &selection);
Chris@24 72 void removeSelection(const Selection &selection);
Chris@24 73 void clearSelections();
Chris@24 74
Chris@928 75 void getExtents(int &startFrame, int &endFrame) const;
Chris@300 76
Chris@24 77 /**
Chris@24 78 * Return the selection that contains a given frame.
Chris@24 79 * If defaultToFollowing is true, and if the frame is not in a
Chris@24 80 * selected area, return the next selection after the given frame.
Chris@24 81 * Return the empty selection if no appropriate selection is found.
Chris@24 82 */
Chris@928 83 Selection getContainingSelection(int frame, bool defaultToFollowing) const;
Chris@24 84
Chris@314 85 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@314 86 QString extraAttributes = "") const;
Chris@46 87
Chris@24 88 protected:
Chris@24 89 SelectionList m_selections;
Chris@24 90 };
Chris@24 91
Chris@24 92
Chris@8 93 #endif