Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@8: Chris@8: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@52: This file copyright 2006 Chris Cannam. Chris@8: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@8: */ Chris@8: cannam@1452: #ifndef SV_SELECTION_H cannam@1452: #define SV_SELECTION_H Chris@8: Chris@8: #include Chris@24: #include Chris@8: Chris@46: #include "XmlExportable.h" Chris@1038: #include "BaseTypes.h" Chris@46: Chris@925: /** Chris@925: * A selection object simply represents a range in time, via start and Chris@925: * end frame. Chris@925: * Chris@925: * The end frame is the index of the frame just *after* the end of the Chris@925: * selection. For example a selection of length 10 frames starting at Chris@925: * time 0 will have start frame 0 and end frame 10. This will be Chris@925: * contiguous with (rather than overlapping with) a selection that Chris@925: * starts at frame 10. Chris@925: * Chris@925: * Any selection with equal start and end frames is empty, Chris@925: * representing "no selection". All empty selections are equal under Chris@925: * the comparison operators. The default constructor makes an empty Chris@925: * selection with start and end frames equal to zero. Chris@925: */ Chris@8: class Selection Chris@8: { Chris@8: public: Chris@8: Selection(); Chris@1038: Selection(sv_frame_t startFrame, sv_frame_t endFrame); Chris@8: Selection(const Selection &); Chris@8: Selection &operator=(const Selection &); Chris@8: virtual ~Selection(); Chris@8: Chris@8: bool isEmpty() const; Chris@1038: sv_frame_t getStartFrame() const; Chris@1038: sv_frame_t getEndFrame() const; Chris@1645: sv_frame_t getDuration() const { return getEndFrame() - getStartFrame(); } Chris@1038: bool contains(sv_frame_t frame) const; Chris@8: Chris@8: bool operator<(const Selection &) const; Chris@8: bool operator==(const Selection &) const; Chris@8: Chris@8: protected: Chris@1038: sv_frame_t m_startFrame; Chris@1038: sv_frame_t m_endFrame; Chris@8: }; Chris@8: Chris@46: class MultiSelection : public XmlExportable Chris@24: { Chris@24: public: Chris@24: MultiSelection(); Chris@24: virtual ~MultiSelection(); Chris@24: Chris@24: typedef std::set SelectionList; Chris@24: Chris@24: const SelectionList &getSelections() const; Chris@24: void setSelection(const Selection &selection); Chris@24: void addSelection(const Selection &selection); Chris@24: void removeSelection(const Selection &selection); Chris@24: void clearSelections(); Chris@24: Chris@1038: void getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const; Chris@1811: Chris@24: /** Chris@24: * Return the selection that contains a given frame. Chris@24: * If defaultToFollowing is true, and if the frame is not in a Chris@24: * selected area, return the next selection after the given frame. Chris@24: * Return the empty selection if no appropriate selection is found. Chris@24: */ Chris@1811: Selection getContainingSelection(sv_frame_t frame, Chris@1811: bool defaultToFollowing) const; Chris@24: Chris@1580: void toXml(QTextStream &stream, QString indent = "", Chris@1811: QString extraAttributes = "") const override; Chris@46: Chris@1811: // Debug only, not interop Chris@1811: QString toString() const; Chris@1811: Chris@24: protected: Chris@24: SelectionList m_selections; Chris@24: }; Chris@24: Chris@24: Chris@8: #endif