[6f8185]: libkwave / KwaveMultiTrackSink.h Maximize Restore History

Download this file

KwaveMultiTrackSink.h    110 lines (96 with data), 3.2 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
/*************************************************************************
KwaveMultiTrackSink.h - template for multi-track sinks
-------------------
begin : Sat Oct 20 2007
copyright : (C) 2007 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. *
* *
***************************************************************************/
#ifndef _KWAVE_MULTI_TRACK_SINK_H_
#define _KWAVE_MULTI_TRACK_SINK_H_
#include "config.h"
#include <qobject.h>
#include <qptrvector.h>
#include "libkwave/KwaveSampleSink.h"
namespace Kwave {
template <class SINK>
class MultiTrackSink
:public Kwave::SampleSink,
private QPtrVector<SINK>
{
public:
/**
* Constructor
*
* @param parent a parent object, passed to QObject (optional)
* @param name a free name, for identifying this object,
* will be passed to the QObject (optional)
*/
MultiTrackSink(unsigned int tracks,
QObject *parent = 0,
const char *name = 0)
:Kwave::SampleSink(parent, name),
QPtrVector<SINK>()
{
QPtrVector<SINK>::setAutoDelete(true);
QPtrVector<SampleWriter>::resize(tracks);
};
/** Destructor */
virtual ~MultiTrackSink()
{
QPtrVector<SINK>::setAutoDelete(true);
QPtrVector<SINK>::clear();
};
/** Returns true when all sinks are done */
virtual bool done()
{
for (unsigned int track=0; track < tracks(); ++track) {
Kwave::SampleSink *s = (*this)[track];
if (s && !s->done()) return false;
}
return true;
};
/**
* Returns the number of tracks that the sink provides
* @return number of tracks
*/
virtual unsigned int tracks() const
{
return QPtrVector<SINK>::count();
};
/**
* Returns the source that corresponds to one specific track
* if the object has multiple tracks. For single-track objects
* it returns "this" for the first index and 0 for all others
*/
inline virtual SINK *at(unsigned int track) const {
return QPtrVector<SINK>::at(track);
};
/** @see the Kwave::MultiTrackSink.at()... */
inline virtual SINK * operator [] (unsigned int track) {
return at(track);
};
/**
* Insert a new track with a sink.
*
* @param track index of the track [0...N-1]
* @param sink pointer to a Kwave::SampleSink
* @return true if successful, false if failed
*/
inline virtual bool insert(unsigned int track, SINK *sink) {
return QPtrVector<SINK>::insert(track, sink);
};
/** Remove all tracks / sinks */
inline virtual void clear() {
QPtrVector<SINK>::clear();
};
};
}
#endif /* _KWAVE_MULTI_TRACK_SINK_H_ */