1 /*
2  * Author: Harry van Haaren 2014
3  *         harryhaaren@gmail.com
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18  * MA 02110-1301, USA.
19  */
20 
21 #ifndef OPENAV_CAPTA
22 #define OPENAV_CAPTA
23 
24 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
25 
26 #define CAPTA_URI    "http://www.openavproductions.com/artyfx#capta"
27 #define CAPTA_UI_URI "http://www.openavproductions.com/artyfx#capta/gui"
28 
29 typedef enum {
30 	// audio
31 	CAPTA_INPUT_1 = 0,
32 	CAPTA_INPUT_2,
33 	CAPTA_INPUT_3,
34 	CAPTA_INPUT_4,
35 
36 	// controls
37 	CAPTA_RECORD,
38 
39 } CaptaPortIndex;
40 
41 #include "lv2/lv2plug.in/ns/ext/urid/urid.h"
42 #include "lv2/lv2plug.in/ns/ext/atom/atom.h"
43 
44 #include "ringbuffer.h"
45 #include "zix/sem.h"
46 #include "zix/thread.h"
47 
48 class SndfileHandle;
49 
50 class Capta
51 {
52 public:
53 	Capta(int rate);
54 	~Capta();
55 	static LV2_Handle instantiate(const LV2_Descriptor* descriptor,
56 	                              double samplerate,
57 	                              const char* bundle_path,
58 	                              const LV2_Feature* const* features);
59 	static void activate(LV2_Handle instance);
60 	static void deactivate(LV2_Handle instance);
61 	static void connect_port(LV2_Handle instance, uint32_t port, void *data);
62 	static void run(LV2_Handle instance, uint32_t n_samples);
63 	static void cleanup(LV2_Handle instance);
64 	static const void* extension_data(const char* uri);
65 
66 	/// audio buffers
67 	float* audioInput1;
68 	float* audioInput2;
69 	float* audioInput3;
70 	float* audioInput4;
71 
72 	/// control signals
73 	float* controlRecord;
74 
75 private:
76 	const int sr;
77 	bool recording;
78 
79 	/// ringbuffer for streaming all audio to disk
80 	jack_ringbuffer_t* ringbuffer;
81 	// used to copy the data to disk
82 	float* tmpAudioBuffer;
83 
84 	/// disk thread
85 	SndfileHandle* sndfile;
86 
87 	// signals start/stop recording
88 	ZixSem startRec;
89 	ZixSem stopRec;
90 	ZixSem overrunNotify;
91 	ZixSem quitDiskThread;
92 
93 	// the disk thread
94 	ZixThread diskThread;
95 
96 	void diskFunc();
staticDiskFunc(void * data)97 	static void* staticDiskFunc(void* data)
98 	{
99 		((Capta*)data)->diskFunc();
100 		return 0;
101 	}
102 };
103 
104 #endif // OPENAV_CAPTA
105