kwave  18.07.70
MultiTrackSink.h
Go to the documentation of this file.
1 /*************************************************************************
2  MultiTrackSink.h - template for multi-track sinks
3  -------------------
4  begin : Sat Oct 20 2007
5  copyright : (C) 2007 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 #ifndef MULTI_TRACK_SINK_H
19 #define MULTI_TRACK_SINK_H
20 
21 #include "config.h"
22 
23 #include <new>
24 
25 #include <QList>
26 #include <QObject>
27 
28 #include "libkwave/SampleSink.h"
29 
30 namespace Kwave
31 {
32 
33  template <class SINK, const bool INITIALIZE>
35  private QList<SINK *>
36  {
37  public:
43  MultiTrackSink(unsigned int tracks, QObject *parent = Q_NULLPTR)
44  :Kwave::SampleSink(parent),
45  QList<SINK *>()
46  {
47  Q_UNUSED(tracks);
48  Q_ASSERT(INITIALIZE || (tracks == 0));
49  Q_ASSERT(QList<SINK *>::size() == static_cast<int>(tracks));
50  }
51 
53  virtual ~MultiTrackSink() Q_DECL_OVERRIDE
54  {
55  clear();
56  }
57 
59  virtual bool done() const Q_DECL_OVERRIDE
60  {
61  foreach (Kwave::SampleSink *s,
62  static_cast< QList<SINK *> >(*this))
63  if (s && !s->done()) return false;
64  return true;
65  }
66 
71  virtual unsigned int tracks() const Q_DECL_OVERRIDE
72  {
73  return QList<SINK *>::size();
74  }
75 
81  inline virtual SINK *at(unsigned int track) const {
82  return QList<SINK *>::at(track);
83  }
84 
86  inline virtual SINK * operator [] (unsigned int track) Q_DECL_OVERRIDE {
87  return at(track);
88  }
89 
97  virtual bool insert(unsigned int track, SINK *sink) {
98  QList<SINK *>::insert(track, sink);
99  return (at(track) == sink);
100  }
101 
103  virtual void clear() {
104  while (!QList<SINK *>::isEmpty())
105  delete QList<SINK *>::takeLast();
106  }
107  };
108 
113  template <class SINK>
114  class MultiTrackSink<SINK, true>
115  :public Kwave::MultiTrackSink<SINK, false>
116  {
117  public:
124  MultiTrackSink(unsigned int tracks, QObject *parent = Q_NULLPTR)
125  :Kwave::MultiTrackSink<SINK, false>(0, parent)
126  {
127  for (unsigned int i = 0; i < tracks; i++)
128  this->insert(i, new(std::nothrow) SINK());
129  }
130 
132  virtual ~MultiTrackSink() { }
133  };
134 
135 }
136 
137 #endif /* _MULTI_TRACK_SINK_H */
138 
139 //***************************************************************************
140 //***************************************************************************
MultiTrackSink(unsigned int tracks, QObject *parent=Q_NULLPTR)
virtual unsigned int tracks() const Q_DECL_OVERRIDE
virtual void clear()
Definition: App.h:33
virtual ~MultiTrackSink() Q_DECL_OVERRIDE
MultiTrackSink(unsigned int tracks, QObject *parent=Q_NULLPTR)
virtual bool insert(unsigned int track, SINK *sink)
virtual SINK * operator[](unsigned int track) Q_DECL_OVERRIDE
virtual bool done() const Q_DECL_OVERRIDE
virtual bool done() const
Definition: SampleSink.h:52
virtual SINK * at(unsigned int track) const