[3e4acc]: libkwave / LabelList.cpp Maximize Restore History

Download this file

LabelList.cpp    110 lines (94 with data), 3.4 kB

  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
/***************************************************************************
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 <QtAlgorithms>
#include "libkwave/LabelList.h"
#include "libkwave/MetaData.h"
#include "libkwave/MetaDataList.h"
#include "libkwave/Sample.h"
//***************************************************************************
LabelList::LabelList()
:QList<Label>()
{
}
//***************************************************************************
LabelList::LabelList(const Kwave::MetaDataList &meta_data_list)
:QList<Label>()
{
if (!meta_data_list.isEmpty()) {
// get a list sorted by position
QList<Kwave::MetaData> list =
meta_data_list.selectByType(Label::metaDataType()).toSortedList();
if (!list.isEmpty()) {
// append a Label for each meta data object
foreach (const Kwave::MetaData &meta_data, list)
append(Label(meta_data));
}
sort();
}
}
//***************************************************************************
LabelList::~LabelList()
{
}
//***************************************************************************
static bool compare_labels(Label a, Label b)
{
return (a < b);
}
//***************************************************************************
void LabelList::sort()
{
qSort(begin(), end(), compare_labels);
}
//***************************************************************************
Kwave::MetaDataList LabelList::toMetaDataList() const
{
Kwave::MetaDataList list;
foreach (const Label &label, *this)
list.add(label);
return list;
}
//***************************************************************************
sample_index_t LabelList::nextLabelLeft(sample_index_t from)
{
sample_index_t best = 0;
bool found = false;
if (!isEmpty()) {
foreach (const Label &label, *this) {
sample_index_t lp = label.pos();
if (lp >= from) break;
best = lp;
found = true;
}
}
return (found) ? best : 0;
}
//***************************************************************************
sample_index_t LabelList::nextLabelRight(sample_index_t from)
{
if (!isEmpty()) {
foreach (const 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;
}
//***************************************************************************
//***************************************************************************