Selection.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_SELECTION_H
17 #define SV_SELECTION_H
18 
19 #include <cstddef>
20 #include <set>
21 
22 #include "XmlExportable.h"
23 #include "BaseTypes.h"
24 
40 class Selection
41 {
42 public:
43  Selection();
44  Selection(sv_frame_t startFrame, sv_frame_t endFrame);
45  Selection(const Selection &);
46  Selection &operator=(const Selection &);
47  virtual ~Selection();
48 
49  bool isEmpty() const;
50  sv_frame_t getStartFrame() const;
51  sv_frame_t getEndFrame() const;
52  sv_frame_t getDuration() const { return getEndFrame() - getStartFrame(); }
53  bool contains(sv_frame_t frame) const;
54 
55  bool operator<(const Selection &) const;
56  bool operator==(const Selection &) const;
57 
58 protected:
61 };
62 
64 {
65 public:
67  virtual ~MultiSelection();
68 
69  typedef std::set<Selection> SelectionList;
70 
71  const SelectionList &getSelections() const;
72  void setSelection(const Selection &selection);
73  void addSelection(const Selection &selection);
74  void removeSelection(const Selection &selection);
75  void clearSelections();
76 
77  void getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const;
78 
85  Selection getContainingSelection(sv_frame_t frame,
86  bool defaultToFollowing) const;
87 
88  void toXml(QTextStream &stream, QString indent = "",
89  QString extraAttributes = "") const override;
90 
91  // Debug only, not interop
92  QString toString() const;
93 
94 protected:
95  SelectionList m_selections;
96 };
97 
98 
99 #endif
sv_frame_t getEndFrame() const
Definition: Selection.cpp:69
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
A selection object simply represents a range in time, via start and end frame.
Definition: Selection.h:40
sv_frame_t m_endFrame
Definition: Selection.h:60
bool operator==(const Selection &) const
Definition: Selection.cpp:93
bool isEmpty() const
Definition: Selection.cpp:57
SelectionList m_selections
Definition: Selection.h:95
sv_frame_t m_startFrame
Definition: Selection.h:59
std::set< Selection > SelectionList
Definition: Selection.h:69
bool contains(sv_frame_t frame) const
Definition: Selection.cpp:75
sv_frame_t getDuration() const
Definition: Selection.h:52
Selection & operator=(const Selection &)
Definition: Selection.cpp:43
sv_frame_t getStartFrame() const
Definition: Selection.cpp:63
virtual ~Selection()
Definition: Selection.cpp:52
bool operator<(const Selection &) const
Definition: Selection.cpp:81