annotate base/Selection.h @ 1879:652c5360e682

Ensure transforms are populated before instantiateDefaultPluginFor runs - otherwise if we have prior knowledge of a transform id, we can find ourselves trying to instantiate it before the plugin factory has heard of it and e.g. knows which server to use
author Chris Cannam
date Thu, 25 Jun 2020 12:20:06 +0100
parents 796ae7eecced
children
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
cannam@1452 16 #ifndef SV_SELECTION_H
cannam@1452 17 #define SV_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@1038 23 #include "BaseTypes.h"
Chris@46 24
Chris@925 25 /**
Chris@925 26 * A selection object simply represents a range in time, via start and
Chris@925 27 * end frame.
Chris@925 28 *
Chris@925 29 * The end frame is the index of the frame just *after* the end of the
Chris@925 30 * selection. For example a selection of length 10 frames starting at
Chris@925 31 * time 0 will have start frame 0 and end frame 10. This will be
Chris@925 32 * contiguous with (rather than overlapping with) a selection that
Chris@925 33 * starts at frame 10.
Chris@925 34 *
Chris@925 35 * Any selection with equal start and end frames is empty,
Chris@925 36 * representing "no selection". All empty selections are equal under
Chris@925 37 * the comparison operators. The default constructor makes an empty
Chris@925 38 * selection with start and end frames equal to zero.
Chris@925 39 */
Chris@8 40 class Selection
Chris@8 41 {
Chris@8 42 public:
Chris@8 43 Selection();
Chris@1038 44 Selection(sv_frame_t startFrame, sv_frame_t endFrame);
Chris@8 45 Selection(const Selection &);
Chris@8 46 Selection &operator=(const Selection &);
Chris@8 47 virtual ~Selection();
Chris@8 48
Chris@8 49 bool isEmpty() const;
Chris@1038 50 sv_frame_t getStartFrame() const;
Chris@1038 51 sv_frame_t getEndFrame() const;
Chris@1645 52 sv_frame_t getDuration() const { return getEndFrame() - getStartFrame(); }
Chris@1038 53 bool contains(sv_frame_t frame) const;
Chris@8 54
Chris@8 55 bool operator<(const Selection &) const;
Chris@8 56 bool operator==(const Selection &) const;
Chris@8 57
Chris@8 58 protected:
Chris@1038 59 sv_frame_t m_startFrame;
Chris@1038 60 sv_frame_t m_endFrame;
Chris@8 61 };
Chris@8 62
Chris@46 63 class MultiSelection : public XmlExportable
Chris@24 64 {
Chris@24 65 public:
Chris@24 66 MultiSelection();
Chris@24 67 virtual ~MultiSelection();
Chris@24 68
Chris@24 69 typedef std::set<Selection> SelectionList;
Chris@24 70
Chris@24 71 const SelectionList &getSelections() const;
Chris@24 72 void setSelection(const Selection &selection);
Chris@24 73 void addSelection(const Selection &selection);
Chris@24 74 void removeSelection(const Selection &selection);
Chris@24 75 void clearSelections();
Chris@24 76
Chris@1038 77 void getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const;
Chris@1811 78
Chris@24 79 /**
Chris@24 80 * Return the selection that contains a given frame.
Chris@24 81 * If defaultToFollowing is true, and if the frame is not in a
Chris@24 82 * selected area, return the next selection after the given frame.
Chris@24 83 * Return the empty selection if no appropriate selection is found.
Chris@24 84 */
Chris@1811 85 Selection getContainingSelection(sv_frame_t frame,
Chris@1811 86 bool defaultToFollowing) const;
Chris@24 87
Chris@1580 88 void toXml(QTextStream &stream, QString indent = "",
Chris@1811 89 QString extraAttributes = "") const override;
Chris@46 90
Chris@1811 91 // Debug only, not interop
Chris@1811 92 QString toString() const;
Chris@1811 93
Chris@24 94 protected:
Chris@24 95 SelectionList m_selections;
Chris@24 96 };
Chris@24 97
Chris@24 98
Chris@8 99 #endif