kwave  18.07.70
Writer.h
Go to the documentation of this file.
1 /***************************************************************************
2  Writer.h - base class for writers, providing a C++ stream interface
3  -------------------
4  begin : Sun Aug 23 2009
5  copyright : (C) 2009 by Thomas Eschenbacher
6  email : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
7 
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #ifndef KWAVE_WRITER_H
20 #define KWAVE_WRITER_H
21 
22 #include "config.h"
23 
24 #include <QtGlobal>
25 #include <QObject>
26 
27 #include "libkwave/InsertMode.h"
28 #include "libkwave/SampleSink.h"
29 
30 namespace Kwave
31 {
32  class SampleArray;
33  class SampleReader;
34 
35  class Q_DECL_EXPORT Writer: public Kwave::SampleSink
36  {
37  Q_OBJECT
38  public:
39 
41  Writer();
42 
52  explicit Writer(Kwave::InsertMode mode,
53  sample_index_t left = 0, sample_index_t right = 0);
54 
56  virtual ~Writer() Q_DECL_OVERRIDE;
57 
59  virtual Writer &operator << (const Kwave::SampleArray &samples);
60 
62  virtual Writer &operator << (const sample_t &sample);
63 
65  inline Writer &operator << (Writer &(*modifier)(Writer &))
66  {
67  return modifier(*this);
68  }
69 
74  Writer &operator << (Kwave::SampleReader &reader);
75 
87  virtual bool write(const Kwave::SampleArray &buffer,
88  unsigned int &count) = 0;
89 
94  inline bool flush() { return write(m_buffer, m_buffer_used); }
95 
102  virtual bool eof() const;
103 
105  virtual bool done() const Q_DECL_OVERRIDE { return eof(); }
106 
108  inline sample_index_t first() const { return m_first; }
109 
114  inline sample_index_t last() const {
115  return ((m_mode == Kwave::Append) ?
116  (m_last + m_buffer_used) : m_last);
117  }
118 
122  inline sample_index_t position() const { return m_position; }
123 
125  inline Kwave::InsertMode mode() const { return m_mode; }
126 
127  signals:
128 
133  void sigSamplesWritten(sample_index_t);
134 
136  void proceeded();
137 
138  public slots:
139 
144  void input(Kwave::SampleArray data);
145 
146  protected:
147 
150 
153 
156 
159 
162 
164  unsigned int m_buffer_size;
165 
167  unsigned int m_buffer_used;
168 
169  };
170 
171 }
172 
174 Kwave::Writer &flush(Kwave::Writer &s) Q_DECL_EXPORT;
175 
176 #endif /* KWAVE_WRITER_H */
177 
178 //***************************************************************************
179 //***************************************************************************
Definition: App.h:33
Kwave::Writer & flush(Kwave::Writer &s) Q_DECL_EXPORT
Definition: Writer.cpp:145
bool flush()
Definition: Writer.h:94
quint64 sample_index_t
Definition: Sample.h:28
Kwave::SampleArray m_buffer
Definition: Writer.h:161
sample_index_t m_first
Definition: Writer.h:149
virtual bool done() const Q_DECL_OVERRIDE
Definition: Writer.h:105
unsigned int m_buffer_used
Definition: Writer.h:167
sample_index_t last() const
Definition: Writer.h:114
sample_index_t position() const
Definition: Writer.h:122
sample_index_t m_last
Definition: Writer.h:152
sample_index_t m_position
Definition: Writer.h:158
sample_index_t first() const
Definition: Writer.h:108
InsertMode
Definition: InsertMode.h:26
unsigned int m_buffer_size
Definition: Writer.h:164
Kwave::InsertMode mode() const
Definition: Writer.h:125
Kwave::InsertMode m_mode
Definition: Writer.h:155
qint32 sample_t
Definition: Sample.h:37