-
Notifications
You must be signed in to change notification settings - Fork 1
/
jackclient.h
127 lines (119 loc) · 4.36 KB
/
jackclient.h
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
// "jackclient" is a C++ wrapper for the JACK API.
// This file is part of jack_playrec
// Copyright (C) 2018 Hörtech gGmbH
// Copyright (C) 2011 Giso Grimm
//
// 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 3 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, see <https://www.gnu.org/licenses/>.
#ifndef JACKCLIENT_H
#define JACKCLIENT_H
#include <sndfile.hh>
#include <jack/jack.h>
#include <string>
#include <vector>
class jackc_portless_t {
public:
jackc_portless_t(const std::string& clientname);
virtual ~jackc_portless_t();
void tp_start();
void tp_stop();
void tp_locate(uint32_t p);
void tp_locate(double t_sec);
uint32_t tp_get_frame() const;
double tp_get_time() const;
void activate();
void deactivate();
std::string get_client_name();
int get_srate() { return srate; };
int get_fragsize() { return fragsize; };
void connect(const std::string& src, const std::string& dest, bool btry=false);
uint32_t get_xruns() const { return xruns;};
uint32_t get_xrun_latency() const { return xrun_latency;};
float get_cpu_load() const { return jack_cpu_load(jc);};
private:
static int xrun_callback(void *arg);
static void on_shutdown(void *arg);
public:
jack_client_t* jc;
int srate;
int fragsize;
int rtprio;
bool active;
uint32_t xruns;
double xrun_latency;
};
class jackc_t : public jackc_portless_t {
public:
jackc_t(const std::string& clientname);
virtual ~jackc_t();
virtual void add_input_port(const std::string& name);
virtual void add_output_port(const std::string& name);
void connect_in(unsigned int port,const std::string& pname,bool btry=false);
void connect_out(unsigned int port,const std::string& pname,bool btry=false);
size_t get_num_input_ports() const {return inPort.size();};
size_t get_num_output_ports() const {return outPort.size();};
std::vector<std::string> get_input_ports() const { return input_port_names; };
std::vector<std::string> get_output_ports() const { return output_port_names; };
protected:
virtual int process(jack_nframes_t nframes,const std::vector<float*>& inBuffer,const std::vector<float*>& outBuffer) { return 0; };
private:
static int process_(jack_nframes_t nframes, void *arg);
int process_(jack_nframes_t nframes);
private:
std::vector<jack_port_t*> inPort;
std::vector<jack_port_t*> outPort;
std::vector<float*> inBuffer;
std::vector<float*> outBuffer;
std::vector<std::string> input_port_names;
std::vector<std::string> output_port_names;
};
class jackc_db_t : public jackc_t {
public:
jackc_db_t(const std::string& clientname,jack_nframes_t fragsize);
virtual ~jackc_db_t();
virtual void add_input_port(const std::string& name);
virtual void add_output_port(const std::string& name);
protected:
virtual int inner_process(jack_nframes_t nframes,const std::vector<float*>& inBuffer,const std::vector<float*>& outBuffer) { return 0; };
virtual int process(jack_nframes_t nframes,const std::vector<float*>& inBuffer,const std::vector<float*>& outBuffer);
private:
static void * service(void* h);
void service();
std::vector<float*> dbinBuffer[2];
std::vector<float*> dboutBuffer[2];
jack_nframes_t inner_fragsize;
bool inner_is_larger;
uint32_t ratio;
jack_native_thread_t inner_thread;
pthread_mutex_t mutex[2];
pthread_mutex_t mtx_inner_thread;
bool buffer_filled[2];
uint32_t current_buffer;
bool b_exit_thread;
uint32_t inner_pos;
};
class jackc_transport_t : public jackc_t {
public:
jackc_transport_t(const std::string& clientname);
protected:
int process(jack_nframes_t nframes,const std::vector<float*>& inBuffer,const std::vector<float*>& outBuffer);
virtual int process(jack_nframes_t nframes,const std::vector<float*>& inBuffer,const std::vector<float*>& outBuffer,uint32_t tp_frame, bool tp_rolling) = 0;
};
#endif
/*
* Local Variables:
* mode: c++
* c-basic-offset: 2
* indent-tabs-mode: nil
* compile-command: "make -C .."
* End:
*/