kwave  18.07.70
LabelList.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  LabelList.cpp - list of labels
3  -------------------
4  begin : Sat Aug 05 2006
5  copyright : (C) 2006 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <algorithm>
21 
22 #include "libkwave/LabelList.h"
23 #include "libkwave/MetaData.h"
24 #include "libkwave/MetaDataList.h"
25 #include "libkwave/Sample.h"
26 
27 //***************************************************************************
29  :QList<Kwave::Label>()
30 {
31 }
32 
33 //***************************************************************************
35  :QList<Kwave::Label>()
36 {
37  if (!meta_data_list.isEmpty()) {
38  // get a list sorted by position
39  QList<Kwave::MetaData> list =
41 
42  if (!list.isEmpty()) {
43  // append a label for each meta data object
44  foreach (const Kwave::MetaData &meta_data, list)
45  append(Kwave::Label(meta_data));
46  }
47 
48  sort();
49  }
50 }
51 
52 //***************************************************************************
54 {
55 }
56 
57 //***************************************************************************
59 {
60  return (a < b);
61 }
62 
63 //***************************************************************************
65 {
66  if (!isEmpty())
67  std::sort(begin(), end(), compare_labels);
68 }
69 
70 //***************************************************************************
72 {
74  foreach (const Kwave::Label &label, *this)
75  list.add(label);
76  return list;
77 }
78 
79 //***************************************************************************
81 {
82  sample_index_t best = 0;
83  bool found = false;
84  if (!isEmpty()) {
85  foreach (const Kwave::Label &label, *this) {
86  sample_index_t lp = label.pos();
87  if (lp >= from) break;
88  best = lp;
89  found = true;
90  }
91  }
92  return (found) ? best : 0;
93 }
94 
95 //***************************************************************************
97 {
98  if (!isEmpty()) {
99  foreach (const Kwave::Label &label, *this) {
100  sample_index_t lp = label.pos();
101  if (lp > from)
102  return lp; // found the first label after "from"
103  }
104  }
105  // nothing found: return "infinite"
106  return SAMPLE_INDEX_MAX;
107 }
108 
109 //***************************************************************************
110 //***************************************************************************
Definition: App.h:33
sample_index_t nextLabelRight(sample_index_t from)
Definition: LabelList.cpp:96
static bool compare_labels(Kwave::Label a, Kwave::Label b)
Definition: LabelList.cpp:58
virtual sample_index_t pos() const
Definition: Label.cpp:56
quint64 sample_index_t
Definition: Sample.h:28
virtual void add(const MetaData &metadata)
static QString metaDataType()
Definition: Label.h:59
virtual MetaDataList selectByType(const QString &type) const
sample_index_t nextLabelLeft(sample_index_t from)
Definition: LabelList.cpp:80
virtual ~LabelList()
Definition: LabelList.cpp:53
Kwave::MetaDataList toMetaDataList() const
Definition: LabelList.cpp:71
virtual QList< Kwave::MetaData > toSortedList() const
virtual void sort()
Definition: LabelList.cpp:64
#define SAMPLE_INDEX_MAX
Definition: Sample.h:31