File: RecordParams.cpp

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (198 lines) | stat: -rw-r--r-- 5,844 bytes parent folder | download
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*************************************************************************
       RecordParams.cpp  -  holds parameters of the record plugin
                             -------------------
    begin                : Thu Sep 04 2003
    copyright            : (C) 2003 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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "config.h"
#include <errno.h>

#include "libkwave/String.h"

#include "RecordParams.h"

//***************************************************************************
Kwave::RecordParams::RecordParams()
   :method(Kwave::RECORD_NONE),
    pre_record_enabled(false),     pre_record_time(20),
    record_time_limited(false),    record_time(5*60),
    start_time_enabled(false),     start_time(QDateTime::currentDateTime()),
    record_trigger_enabled(false), record_trigger(30),
    amplification_enabled(false),  amplification(+3),
    agc_enabled(false),            agc_decay(50),
    fade_in_enabled(false),        fade_in_time(5),
    fade_out_enabled(false),       fade_out_time(5),
    device_name(_("plug:dsnoop")),
    tracks(2),
    sample_rate(44100.0),
    compression(Kwave::Compression::NONE),
    bits_per_sample(16),
    sample_format(Kwave::SampleFormat::Unknown),
    buffer_count(32),
    buffer_size(13) /* (1 << 13) == 8192 bytes */
{
}

//***************************************************************************
Kwave::RecordParams::~RecordParams()
{
}

#define GET(value,func) \
        value = list[index++].func(&ok); \
        Q_ASSERT(ok); \
        if (!ok) return -EINVAL;

//***************************************************************************
int Kwave::RecordParams::fromList(const QStringList &list)
{
    bool ok;
    int index = 0;

    // check number of elements
    if (list.count() != 17) return -EINVAL;

    // recording method
    unsigned int method_index;
    GET(method_index, toUInt)
    method = (method_index < Kwave::RECORD_INVALID) ?
                static_cast<Kwave::record_method_t>(method_index) :
                Kwave::RECORD_INVALID;

    // pre-record
    GET(pre_record_enabled, toUInt)
    GET(pre_record_time, toUInt)

    // record time
    GET(record_time_limited, toUInt)
    GET(record_time, toUInt)

    // record start time
    GET(start_time_enabled, toUInt)
    start_time = QDateTime::fromString(list[index++], Qt::ISODate);

    // auto-adjust to same hour as last time but not in past
    if (start_time.date() < QDate::currentDate())
        start_time.setDate(QDate::currentDate());
    if (start_time < QDateTime::currentDateTime())
        start_time = start_time.addDays(1);
    // set seconds to zero
    QTime t = start_time.time();
    t.setHMS(t.hour(), t.minute(), 0, 0);
    start_time.setTime(t);

    // record trigger
    GET(record_trigger_enabled, toUInt)
    GET(record_trigger, toUInt)

//     // amplification
//     GET(amplification_enabled, toUInt);
//     GET(amplification, toInt);
//
//     // AGC
//     GET(agc_enabled, toUInt);
//     GET(agc_decay, toUInt);
//
//     // fade in
//     GET(fade_in_enabled, toUInt);
//     GET(fade_in_time, toUInt);
//
//     // fade out
//     GET(fade_out_enabled, toUInt);
//     GET(fade_out_time, toUInt);

    // device name
    device_name = list[index++];

    // tracks, sample rate, compression, sample format, bits per sample
    GET(tracks, toUInt)
    GET(sample_rate, toDouble)
    int ct;
    GET(ct, toInt)
    compression = Kwave::Compression::fromInt(ct);
    GET(bits_per_sample, toUInt)

    int sf;
    GET(sf, toInt)
    Kwave::SampleFormat(sample_format).fromInt(sf);

    // buffer count and power of buffer size
    GET(buffer_count, toUInt)
    GET(buffer_size, toUInt)

    return 0;
}

#define PUT(value) list += param.setNum(value)

//***************************************************************************
QStringList Kwave::RecordParams::toList() const
{
    QStringList list;
    QString param;

    // record method
    PUT(static_cast<unsigned int>(method));

    // pre-record
    PUT(pre_record_enabled);
    PUT(pre_record_time);

    // record time
    PUT(record_time_limited);
    PUT(record_time);

    // start time
    PUT(start_time_enabled);
    list += start_time.toString(Qt::ISODate);

    // record trigger
    PUT(record_trigger_enabled);
    PUT(record_trigger);

//     // amplification
//     PUT(amplification_enabled);
//     PUT(amplification);
//
//     // AGC
//     PUT(agc_enabled);
//     PUT(agc_decay);
//
//     // fade in
//     PUT(fade_in_enabled);
//     PUT(fade_in_time);
//
//     // fade out
//     PUT(fade_out_enabled);
//     PUT(fade_out_time);

    // device name
    list += device_name;

    // tracks, sample rate, compression, sample format, bits per sample
    PUT(tracks);
    PUT(sample_rate);
    PUT(compression);
    PUT(bits_per_sample);
    PUT(Kwave::SampleFormat(sample_format).toInt());

    // buffer count and power of buffer size
    PUT(buffer_count);
    PUT(buffer_size);

    return list;
}

//***************************************************************************
//***************************************************************************