kwave  18.07.70
RecordParams.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  RecordParams.cpp - holds parameters of the record plugin
3  -------------------
4  begin : Thu Sep 04 2003
5  copyright : (C) 2003 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 #include "config.h"
19 #include <errno.h>
20 
21 #include "libkwave/String.h"
22 
23 #include "RecordParams.h"
24 
25 //***************************************************************************
27  :method(Kwave::RECORD_NONE),
28  pre_record_enabled(false), pre_record_time(20),
29  record_time_limited(false), record_time(5*60),
30  start_time_enabled(false), start_time(QDateTime::currentDateTime()),
31  record_trigger_enabled(false), record_trigger(30),
32  amplification_enabled(false), amplification(+3),
33  agc_enabled(false), agc_decay(50),
34  fade_in_enabled(false), fade_in_time(5),
35  fade_out_enabled(false), fade_out_time(5),
36  device_name(_("plug:dsnoop")),
37  tracks(2),
38  sample_rate(44100.0),
39  compression(Kwave::Compression::NONE),
40  bits_per_sample(16),
41  sample_format(Kwave::SampleFormat::Unknown),
42  buffer_count(32),
43  buffer_size(13) /* (1 << 13) == 8192 bytes */
44 {
45 }
46 
47 //***************************************************************************
49 {
50 }
51 
52 #define GET(value,func) \
53  value = list[index++].func(&ok); \
54  Q_ASSERT(ok); \
55  if (!ok) return -EINVAL;
56 
57 //***************************************************************************
58 int Kwave::RecordParams::fromList(const QStringList &list)
59 {
60  bool ok;
61  int index = 0;
62 
63  // check number of elements
64  if (list.count() != 17) return -EINVAL;
65 
66  // recording method
67  unsigned int method_index;
68  GET(method_index, toUInt);
69  method = (method_index < Kwave::RECORD_INVALID) ?
70  static_cast<Kwave::record_method_t>(method_index) :
72 
73  // pre-record
74  GET(pre_record_enabled, toUInt);
75  GET(pre_record_time, toUInt);
76 
77  // record time
78  GET(record_time_limited, toUInt);
79  GET(record_time, toUInt);
80 
81  // record start time
82  GET(start_time_enabled, toUInt);
83  start_time = QDateTime::fromString(list[index++], Qt::ISODate);
84 
85  // auto-adjust to same hour as last time but not in past
86  if (start_time.date() < QDate::currentDate())
87  start_time.setDate(QDate::currentDate());
88  if (start_time < QDateTime::currentDateTime())
89  start_time = start_time.addDays(1);
90  // set seconds to zero
91  QTime t = start_time.time();
92  t.setHMS(t.hour(), t.minute(), 0, 0);
93  start_time.setTime(t);
94 
95  // record trigger
96  GET(record_trigger_enabled, toUInt);
97  GET(record_trigger, toUInt);
98 
99 // // amplification
100 // GET(amplification_enabled, toUInt);
101 // GET(amplification, toInt);
102 //
103 // // AGC
104 // GET(agc_enabled, toUInt);
105 // GET(agc_decay, toUInt);
106 //
107 // // fade in
108 // GET(fade_in_enabled, toUInt);
109 // GET(fade_in_time, toUInt);
110 //
111 // // fade out
112 // GET(fade_out_enabled, toUInt);
113 // GET(fade_out_time, toUInt);
114 
115  // device name
116  device_name = list[index++];
117 
118  // tracks, sample rate, compression, sample format, bits per sample
119  GET(tracks, toUInt);
120  GET(sample_rate, toDouble);
121  int ct;
122  GET(ct, toInt);
124  GET(bits_per_sample, toUInt);
125 
126  int sf;
127  GET(sf, toInt);
129 
130  // buffer count and power of buffer size
131  GET(buffer_count, toUInt);
132  GET(buffer_size, toUInt);
133 
134  return 0;
135 }
136 
137 #define PUT(value) list += param.setNum(value)
138 
139 //***************************************************************************
140 QStringList Kwave::RecordParams::toList() const
141 {
142  QStringList list;
143  QString param;
144 
145  // record method
146  PUT(static_cast<unsigned int>(method));
147 
148  // pre-record
151 
152  // record time
154  PUT(record_time);
155 
156  // start time
158  list += start_time.toString(Qt::ISODate);
159 
160  // record trigger
163 
164 // // amplification
165 // PUT(amplification_enabled);
166 // PUT(amplification);
167 //
168 // // AGC
169 // PUT(agc_enabled);
170 // PUT(agc_decay);
171 //
172 // // fade in
173 // PUT(fade_in_enabled);
174 // PUT(fade_in_time);
175 //
176 // // fade out
177 // PUT(fade_out_enabled);
178 // PUT(fade_out_time);
179 
180  // device name
181  list += device_name;
182 
183  // tracks, sample rate, compression, sample format, bits per sample
184  PUT(tracks);
185  PUT(sample_rate);
186  PUT(compression);
189 
190  // buffer count and power of buffer size
191  PUT(buffer_count);
192  PUT(buffer_size);
193 
194  return list;
195 }
196 
197 //***************************************************************************
198 //***************************************************************************
unsigned int bits_per_sample
Definition: RecordParams.h:105
Definition: App.h:33
#define GET(value, func)
static Kwave::Compression::Type fromInt(int i)
Definition: Compression.cpp:78
unsigned int pre_record_time
Definition: RecordParams.h:78
unsigned int record_time
Definition: RecordParams.h:81
unsigned int record_trigger
Definition: RecordParams.h:87
int toInt(T x)
Definition: Utils.h:127
unsigned int tracks
Definition: RecordParams.h:102
Kwave::SampleFormat::Format sample_format
Definition: RecordParams.h:106
#define _(m)
Definition: memcpy.c:66
#define PUT(value)
QDateTime start_time
Definition: RecordParams.h:84
Kwave::record_method_t method
Definition: RecordParams.h:75
Kwave::Compression::Type compression
Definition: RecordParams.h:104
unsigned int buffer_count
Definition: RecordParams.h:108
virtual int fromList(const QStringList &list)
virtual QStringList toList() const
unsigned int buffer_size
Definition: RecordParams.h:109