File: Selection.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (115 lines) | stat: -rw-r--r-- 3,606 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/***************************************************************************
             Selection.h - Simple class for a selection
                             -------------------
    begin                : Sun May 06 2001
    copyright            : (C) 2000 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef SELECTION_H
#define SELECTION_H

#include "config.h"
#include "libkwave_export.h"

#include <QtGlobal>
#include <QObject>

#include "libkwave/Sample.h"

namespace Kwave
{

    class LIBKWAVE_EXPORT Selection: public QObject
    {
        Q_OBJECT
    public:
        /**
         * constructor.
         * @param offset index of the first item
         * @param length number of items
         */
        Selection(sample_index_t offset, sample_index_t length);

        /** copy constructor */
        Selection(const Selection &other);

        /** Destructor */
        ~Selection() override;

        /**
         * Sets a new offset and length.
         * @param offset index of the first item
         * @param length number of items
         */
        void select(sample_index_t offset, sample_index_t length);

        /** Clears the selection (0 samples at offset 0) */
        inline void clear() {
            select(0, 0);
        }

        /** Returns the index of the first selected item. */
        inline sample_index_t offset() const {
            return m_offset;
        }

        /** Returns the number of selected items. */
        inline sample_index_t length() const {
            return m_length;
        }

        /** Equal to offset(). */
        inline sample_index_t first() const {
            return offset();
        }

        /** Returns the index of the last selected item. */
        inline sample_index_t last() const {
            return m_offset + (m_length ? (m_length-1) : 0);
        }

        /** compare operator */
        bool operator == (const Selection &other) const {
            return ((m_offset == other.offset()) &&
                    (m_length == other.length()));
        }

        /** Assignment operator */
        Selection & operator = (const Selection &source) {
            m_offset = source.offset();
            m_length = source.length();
            return *this;
        }

    signals:

        /**
         * Emits a change in the selected range.
         * @param offset index of the first selected items
         * @param length number of selected items
         */
        void changed(sample_index_t offset, sample_index_t length);

    private:
        /** index of the first selected item */
        sample_index_t m_offset;

        /** number of items */
        sample_index_t m_length;
    };
}

#endif /* SELECTION_H */

//***************************************************************************
//***************************************************************************