File: PlaySettings.h

package info (click to toggle)
lsp-plugins 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,856 kB
  • sloc: cpp: 427,831; xml: 57,779; makefile: 9,961; php: 1,005; sh: 18
file content (318 lines) | stat: -rw-r--r-- 12,520 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
 * Copyright (C) 2022 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2022 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-dsp-units
 * Created on: 18 нояб. 2022 г.
 *
 * lsp-dsp-units is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-dsp-units is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-dsp-units. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef LSP_PLUG_IN_DSP_UNITS_SAMPLING_PLAYSETTINGS_H_
#define LSP_PLUG_IN_DSP_UNITS_SAMPLING_PLAYSETTINGS_H_

#include <lsp-plug.in/dsp-units/version.h>
#include <lsp-plug.in/dsp-units/sampling/types.h>

namespace lsp
{
    namespace dspu
    {
        /**
         * This is a helper class to specify sample playback settings.
         * Specify different options of playing sample.
         */
        class LSP_DSP_UNITS_PUBLIC PlaySettings
        {
            protected:
                size_t              nID;                // The identifier of the sample
                size_t              nChannel;           // The audio channel of the sample
                float               fVolume;            // The volume of the sample
                bool                bReverse;           // Reverse playback
                size_t              nDelay;             // The delay before the playback should start (samples)
                size_t              nStart;             // The start position of the playback
                sample_loop_t       nLoopMode;          // Sample loop mode
                size_t              nLoopStart;         // Start of the loop (samples)
                size_t              nLoopEnd;           // End of the loop (samples)
                sample_crossfade_t  nLoopXFadeType;     // Loop crossfade type
                size_t              nLoopXFadeLength;   // Length of the crossfade between different sample sections

            public:
                static const PlaySettings default_settings;

            public:
                PlaySettings();
                ~PlaySettings();

                void                construct();
                void                destroy();

            public:
                /**
                 * Get sample identifier
                 * @return sample identifier
                 */
                inline size_t       sample_id() const       { return nID;           }

                /**
                 * Get sample channel
                 * @return sample channel
                 */
                inline size_t       sample_channel() const  { return nChannel;      }

                /**
                 * Get the volume of the sample
                 * @return the volume of the sample
                 */
                inline float        volume() const          { return fVolume;       }

                /**
                 * Get the reverse flag
                 * @return reverse playback flag
                 */
                inline bool         reverse() const         { return bReverse;      }

                /**
                 * Get the delay before the playback starts
                 * @return the delay in samples before the playback starts
                 */
                inline size_t       delay() const           { return nDelay;        }

                /**
                 * Get the start point of the playback
                 * @return the start point of the playback in samples
                 */
                inline size_t       start() const           { return nStart;        }

                /**
                 * Get the loop mode of the sample
                 * @return loop mode of the sample
                 */
                inline sample_loop_t loop_mode() const      { return nLoopMode;     }

                /**
                 * Get the start point of the repetition loop
                 * @return the start point of the repetition loop in samples
                 */
                inline size_t       loop_start() const      { return nLoopStart;    }

                /**
                 * Get the end point of the repetition loop
                 * @return the end point of the repetition loop in samples
                 */
                inline size_t       loop_end() const        { return nLoopEnd;      }

                /**
                 * Get type of the crossfade between sample segments in the loop
                 * @return tyoe of the crossfade between sample segments in the loop
                 */
                inline sample_crossfade_t loop_xfade_type() const   { return nLoopXFadeType; }

                /**
                 * Get the length of the crossfade between different parts of the sample
                 * @return the length of the crossfade betweeen different parts of the sample in samples
                 */
                inline size_t       loop_xfade_length() const       { return nLoopXFadeLength;  }

            public:
                /**
                 * Set sample identifier
                 * @param id sample identifier
                 */
                inline void         set_sample_id(size_t id)
                {
                    nID             = id;
                }

                /**
                 * Set sample channel
                 * @param channel sample channel
                 */
                inline void         set_sample_channel(size_t channel)
                {
                    nChannel        = channel;
                }

                /**
                 * Set sample to play
                 * @param sample_id sample identifier
                 * @param channel channel identifier
                 */
                inline void         set_channel(size_t sample_id, size_t channel)
                {
                    nID             = sample_id;
                    nChannel        = channel;
                }

                /**
                 * Set the playback volume of the sample
                 * @param volume playback volume of the sample
                 */
                inline void         set_volume(float volume)
                {
                    fVolume         = volume;
                }

                /**
                 * Set the playback delay
                 * @param delay the delay before the playback starts in samples
                 */
                inline void         set_delay(size_t delay)
                {
                    nDelay          = delay;
                }

                /**
                 * Set start position of the playback
                 * @param position start position of the playback in samples
                 */
                inline void         set_start(size_t position)
                {
                    nStart          = position;
                }

                /**
                 * Set start position of the playback
                 * @param position start position of the playback in samples
                 * @param reverse reverse playback flag
                 */
                inline void         set_start(size_t position, bool reverse)
                {
                    nStart          = position;
                    bReverse        = reverse;
                }

                /**
                 * Set the reversive playback flag
                 * @param reverse reverse playback flag
                 */
                inline void         set_reverse(bool reverse)
                {
                    bReverse        = reverse;
                }

                /**
                 * Set primary playback settings
                 * @param start start position of the playback in samples
                 * @param delay the delay before the playback starts in samples
                 * @param volume playback volume of the sample
                 */
                inline void         set_playback(size_t start, size_t delay, float volume)
                {
                    fVolume         = volume;
                    nDelay          = delay;
                    nStart          = start;
                }

                /**
                 * Set primary playback settings
                 * @param start start position of the playback in samples
                 * @param delay the delay before the playback starts in samples
                 * @param volume playback volume of the sample
                 * @param reverse reverse playback flag
                 */
                inline void         set_playback(size_t start, size_t delay, float volume, bool reverse)
                {
                    fVolume         = volume;
                    nDelay          = delay;
                    nStart          = start;
                    bReverse        = reverse;
                }

                /**
                 * Set-up loop mode
                 * @param mode loop mode
                 */
                inline void         set_loop_mode(sample_loop_t mode)
                {
                    nLoopMode       = mode;
                }

                /**
                 * Set-up start position of the loop range
                 * @param start start position of the loop range in samples
                 */
                inline void         set_loop_start(size_t start)
                {
                    nLoopStart      = start;
                }

                /**
                 * Set-up end position of the loop range
                 * @param end end position of the loop range in samples
                 */
                inline void         set_loop_end(size_t end)
                {
                    nLoopEnd        = end;
                }

                /**
                 * Set-up loop range
                 * @param start start position of the loop range in samples
                 * @param end end position of the loop range in samples
                 */
                inline void         set_loop_range(size_t start, size_t end)
                {
                    nLoopStart      = start;
                    nLoopEnd        = end;
                }

                /**
                 * Set-up loop range
                 * @param mode loop mode
                 * @param start start position of the loop range in samples
                 * @param end end position of the loop range in samples
                 */
                inline void         set_loop_range(sample_loop_t mode, size_t start, size_t end)
                {
                    nLoopMode       = mode;
                    nLoopStart      = start;
                    nLoopEnd        = end;
                }

                /**
                 * Set the crossfade type between different parts of the sample
                 * @param type type of crossfade between different parts of the sample
                 */
                inline void         set_loop_xfade_type(sample_crossfade_t type)
                {
                    nLoopXFadeType  = type;
                }

                /**
                 * Set the crossfade length between different parts of the sample
                 * @param length the crossfade length between different parts of the sample in samples
                 */
                inline void         set_loop_xfade_length(size_t length)
                {
                    nLoopXFadeLength= length;
                }

                /**
                 * Set the crossfade settings for the loop
                 * @param type type of crossfade between different parts of the sample
                 * @param length the crossfade length between different parts of the sample in samples
                 */
                inline void         set_loop_xfade(sample_crossfade_t type, size_t length)
                {
                    nLoopXFadeType  = type;
                    nLoopXFadeLength= length;
                }
        };

    } /* namespace dspu */
} /* namespace lsp */


#endif /* LSP_PLUG_IN_DSP_UNITS_SAMPLING_PLAYSETTINGS_H_ */