-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjack_client.h
127 lines (101 loc) · 3 KB
/
jack_client.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
/**
* jack_client.h
*
* Copyright (C) 2023 Pablo Alvarado
* EL5802 Procesamiento Digital de Señales
* Escuela de Ingeniería Electrónica
* Tecnológico de Costa Rica
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef _JACK_CLIENT_H
#define _JACK_CLIENT_H
#include <jack/jack.h>
#include <ostream>
namespace jack {
enum class client_state {
Idle,
Initializing,
Running,
ShuttingDown,
Stopped,
Error
};
/**
* Jack client class
*
* This class wraps some basic jack functionality.
*
* It follows the monostate pattern to keep just one state
* encompassing jack's functionality
*/
class client {
private:
/// Part of monostate
static jack_client_t* _client_ptr;
static client_state _state;
static jack_nframes_t _buffer_size;
static jack_nframes_t _sample_rate;
protected:
static jack_port_t* _input_port;
static jack_port_t* _output_port;
public:
typedef jack_default_audio_sample_t sample_t;
/**
* Creates a client in Idle state. You still have to call init()
* when ready to start processing.
*/
client();
client(const client&) = delete; // not copyable
virtual ~client();
/**
* Process nframes from the input in array writing the output on
* out.
*
* Return true if successful or false otherwise
*/
virtual bool process(jack_nframes_t nframes,
const sample_t *const in,
sample_t *const out) = 0;
virtual void shutdown();
client& operator=(const client&) = delete; // not copyable
/**
* Initialize all necessary Jack callbacks, ports, etc. and
* start processing.
*/
client_state init();
/**
* Stop processing. After calling this method, the application must
* end, as no Jack client will be available anymore.
*/
void stop();
void set_sample_rate(const jack_nframes_t sample_rate);
void set_buffer_size(const jack_nframes_t buffer_size);
/**
* Get input port
*/
jack_port_t *const input_port() const;
/**
* Get output port
*/
jack_port_t *const output_port() const;
/**
* Get sample rate
*/
jack_nframes_t get_sample_rate();
jack_nframes_t get_buffer_size();
};
} // namespace jack
std::ostream& operator<<(std::ostream& os,const JackStatus& s);
#endif