DenseTimeValueModel.cpp
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 #include "DenseTimeValueModel.h"
17 
18 #include <QStringList>
19 
20 using namespace std;
21 
22 QVector<QString>
24 {
25  int ch = getChannelCount();
26  QVector<QString> sv;
27  for (int i = 0; i < ch; ++i) {
28  sv.push_back(QString("Channel%1").arg(i+1));
29  }
30  return sv;
31 }
32 
33 QVector<QVector<QString>>
35  sv_frame_t startFrame,
36  sv_frame_t duration) const
37 {
38  int ch = getChannelCount();
39 
40  if (duration <= 0) return {};
41 
42  auto data = getMultiChannelData(0, ch - 1, startFrame, duration);
43 
44  if (data.empty() || data[0].empty()) return {};
45 
46  QVector<QVector<QString>> rows;
47 
48  for (sv_frame_t i = 0; in_range_for(data[0], i); ++i) {
49  QVector<QString> row;
50  row.push_back(QString("%1").arg(startFrame + i));
51  for (int c = 0; in_range_for(data, c); ++c) {
52  row.push_back(QString("%1").arg(data[c][i]));
53  }
54  rows.push_back(row);
55  }
56 
57  return rows;
58 }
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
QVector< QVector< QString > > toStringExportRows(DataExportOptions options, sv_frame_t startFrame, sv_frame_t duration) const override
Emit events starting within the given range as string rows ready for conversion to an e...
bool in_range_for(const C &container, T i)
Check whether an integer index is in range for a container, avoiding overflows and signed/unsigned co...
Definition: BaseTypes.h:37
QVector< QString > getStringExportHeaders(DataExportOptions options) const override
Return a label for each column that would be written by toStringExportRows.
int DataExportOptions