File: LabelList.cpp

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 (111 lines) | stat: -rw-r--r-- 3,760 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
/***************************************************************************
          LabelList.cpp  -  list of labels
                             -------------------
    begin                : Sat Aug 05 2006
    copyright            : (C) 2006 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "config.h"

#include <algorithm>

#include "libkwave/LabelList.h"
#include "libkwave/MetaData.h"
#include "libkwave/MetaDataList.h"
#include "libkwave/Sample.h"

//***************************************************************************
Kwave::LabelList::LabelList()
    :QList<Kwave::Label>()
{
}

//***************************************************************************
Kwave::LabelList::LabelList(const Kwave::MetaDataList &meta_data_list)
    :QList<Kwave::Label>()
{
    if (!meta_data_list.isEmpty()) {
        // get a list sorted by position
        QList<Kwave::MetaData> list =
            meta_data_list.selectByType(
                Kwave::Label::metaDataType()).toSortedList();

        if (!list.isEmpty()) {
            // append a label for each meta data object
            foreach (const Kwave::MetaData &meta_data, list)
                append(Kwave::Label(meta_data));
        }

        sort();
    }
}

//***************************************************************************
Kwave::LabelList::~LabelList()
{
}

//***************************************************************************
static bool compare_labels(Kwave::Label a, Kwave::Label b)
{
    return (a < b);
}

//***************************************************************************
void Kwave::LabelList::sort()
{
    if (!isEmpty())
        std::sort(begin(), end(), compare_labels);
}

//***************************************************************************
Kwave::MetaDataList Kwave::LabelList::toMetaDataList() const
{
    Kwave::MetaDataList list;
    foreach (const Kwave::Label &label, *this)
        list.add(label);
    return list;
}

//***************************************************************************
sample_index_t Kwave::LabelList::nextLabelLeft(sample_index_t from)
{
    sample_index_t best  = 0;
    bool           found = false;
    if (!isEmpty()) {
        foreach (const Kwave::Label &label, *this) {
            sample_index_t lp = label.pos();
            if (lp >= from) break;
            best  = lp;
            found = true;
        }
    }
    return (found) ? best : 0;
}

//***************************************************************************
sample_index_t Kwave::LabelList::nextLabelRight(sample_index_t from)
{
    if (!isEmpty()) {
        foreach (const Kwave::Label &label, *this) {
            sample_index_t lp = label.pos();
            if (lp  > from)
                return lp; // found the first label after "from"
        }
    }
    // nothing found: return "infinite"
    return SAMPLE_INDEX_MAX;
}

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