/
looper.hpp
184 lines (130 loc) · 4.54 KB
/
looper.hpp
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
/*
** Copyright (C) 2004 Jesse Chappell <jesse@essej.net>
**
** 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.
**
** This program 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*/
#ifndef __sooperlooper_looper__
#define __sooperlooper_looper__
#include <string>
#if HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef HAVE_SAMPLERATE
#include <samplerate.h>
#endif
#include "audio_driver.hpp"
#include "lockmonitor.hpp"
#include "ladspa.h"
#include "plugin.hpp"
#include "event.hpp"
#include "event_nonrt.hpp"
#include "utils.hpp"
#include <pbd/xml++.h>
namespace SooperLooper {
class OnePoleFilter;
class Panner;
class Looper
{
public:
Looper (AudioDriver * driver, unsigned int index, unsigned int channel_count=1, float loopsecs=40.0, bool discrete=true);
Looper (AudioDriver * driver, XMLNode & node);
~Looper ();
bool initialize (unsigned int index, unsigned int channel_count=1, float loopsecs=40.0, bool discrete=true);
void destroy();
bool operator() () const { return _ok; }
void run (nframes_t offset, nframes_t nframes);
void do_event (Event *ev);
float get_control_value (Event::control_t ctrl);
void set_port (ControlPort n, LADSPA_Data val);
bool load_loop (std::string fname);
bool save_loop (std::string fname = "", LoopFileEvent::FileFormat format = LoopFileEvent::FormatFloat);
void set_buffer_size (nframes_t bufsize);
sample_t * get_sync_in_buf() { return _our_syncin_buf; }
sample_t * get_sync_out_buf() { return _our_syncout_buf; }
void use_sync_buf(sample_t * buf);
unsigned int get_index() { return _index; }
void set_use_common_ins (bool val);
bool get_use_common_ins () { return _use_common_ins; }
void set_use_common_outs (bool val);
bool get_use_common_outs () { return _use_common_outs; }
bool get_have_discrete_io () { return _have_discrete_io; }
XMLNode& get_state () const;
int set_state (const XMLNode&);
protected:
void run_loops (nframes_t offset, nframes_t nframes);
void run_loops_resampled (nframes_t offset, nframes_t nframes);
static void compute_peak (sample_t *buf, nframes_t nsamples, float& peak) {
float p = peak;
for (nframes_t n = 0; n < nsamples; ++n) {
p = f_max (p, fabsf(buf[n]));
}
peak = p;
}
int requested_cmd;
int last_requested_cmd;
AudioDriver * _driver;
port_id_t* _input_ports;
port_id_t* _output_ports;
unsigned int _index;
unsigned int _chan_count;
LADSPA_Handle * _instances;
float _loopsecs;
LADSPA_Descriptor* descriptor;
LADSPA_Data ports[LASTPORT];
float _curr_dry;
float _target_dry;
float _curr_input_gain;
float _targ_input_gain;
bool _relative_sync;
// keeps track of down/up commands for SUS purposes
nframes_t _down_stamps[Event::LAST_COMMAND+1];
nframes_t _longpress_frames;
nframes_t _running_frames;
nframes_t _buffersize;
LADSPA_Data * _our_syncin_buf;
LADSPA_Data * _our_syncout_buf;
LADSPA_Data * _use_sync_buf;
LADSPA_Data * _dummy_buf;
LADSPA_Data * _tmp_io_buf;
Panner * _panner;
float _input_peak;
float _output_peak;
float _falloff_per_sample;
LADSPA_Data _slave_sync_port;
LADSPA_Data _slave_dummy_port;
bool _use_common_ins;
bool _use_common_outs;
bool _have_discrete_io;
// SRC stuff
#ifdef HAVE_SAMPLERATE
SRC_STATE** _in_src_states;
SRC_STATE** _out_src_states;
SRC_STATE* _insync_src_state;
SRC_STATE* _outsync_src_state;
float * _src_in_buffer;
float * _src_sync_buffer;
nframes_t _src_buffer_len;
double _src_in_ratio;
double _src_out_ratio;
SRC_DATA _src_data;
#endif
OnePoleFilter ** _lp_filter;
bool _ok;
bool request_pending;
PBD::NonBlockingLock _loop_lock;
};
};
#endif