This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ChannelStrip.cpp
217 lines (159 loc) · 5.29 KB
/
ChannelStrip.cpp
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
#include "ChannelStrip.h"
#include <qdebug.h>
namespace Mixr {
ChannelStrip::ChannelStrip(jack_client_t *clientName, const QString& stripName) :
client{clientName},
name{stripName}
{
input_port_1 = registerPort(name + "/in 1", JackPortIsInput);
input_port_2 = registerPort(name + "/in 2", JackPortIsInput);
output_port_1 = registerPort(name + "/out 1", JackPortIsOutput);
output_port_2 = registerPort(name + "/out 2", JackPortIsOutput);
}
ChannelStrip::~ChannelStrip()
{
}
jack_port_t* ChannelStrip::getInputPort1() {
return input_port_1;
}
jack_port_t* ChannelStrip::getInputPort2() {
return input_port_2;
}
jack_port_t* ChannelStrip::getOutputPort1() {
return output_port_1;
}
jack_port_t* ChannelStrip::getOutputPort2() {
return output_port_2;
}
float ChannelStrip::getPeakL() const {
return peakL;
}
void ChannelStrip::setPeakL(const float peak) {
peakL = peak;
}
float ChannelStrip::getPeakR() const {
return peakR;
}
void ChannelStrip::setPeakR(const float peak) {
peakR = peak;
}
float ChannelStrip::getVolumeL() const {
return volL;
}
float ChannelStrip::getVolumeR() const {
return volR;
}
bool ChannelStrip::isMuted() const {
return mute;
}
void ChannelStrip::isMuted(const bool isMute) {
mute = isMute;
}
float ChannelStrip::getPan() const {
return pan;
}
void ChannelStrip::setPan(const float panValue) {
pan = panValue;
setPortVolumes();
}
jack_port_t* ChannelStrip::registerPort(const QString& portName, const JackPortFlags portFlags) const {
return jack_port_register(client, portName.toLatin1().data(), JACK_DEFAULT_AUDIO_TYPE, portFlags, 0);
}
int ChannelStrip::connectFrom(const QString& portName, const int side) {
const auto* m_portName = portName.toLatin1().data();
if (side == 1)
return jack_connect(client, m_portName, jack_port_name(input_port_1));
else
return jack_connect(client, m_portName, jack_port_name(input_port_2));
}
int ChannelStrip::disconnectFrom(const QString& portName, const int side) {
const auto* m_portName = portName.toLatin1().data();
if (side == 1)
return jack_disconnect (client, m_portName, jack_port_name(input_port_1));
else
return jack_disconnect (client, m_portName, jack_port_name(input_port_2));
}
void ChannelStrip::connectFrom(const QString& portName) {
jack_port_disconnect(client, input_port_1);
jack_port_disconnect(client, input_port_2);
// connect input port 1
const auto* portName1 = portName.toLatin1().data();
jack_connect(client, portName1, jack_port_name(input_port_1));
// connect input port 2
const auto* portName2 = portName1;
if (hasSuffixOne(portName)) {
const auto portNameSuffix2 = ChangeSuffixToTwo(portName);
portName2 = portNameSuffix2.toLatin1().data();
}
jack_connect(client, portName2, jack_port_name(input_port_2));
}
int ChannelStrip::connectTo(const QString& portName, const int side) {
const auto* m_portName = portName.toLatin1().data();
if (side == 1)
return jack_connect (client, jack_port_name(output_port_1), m_portName);
else
return jack_connect (client, jack_port_name(output_port_2), m_portName);
}
int ChannelStrip::disconnectTo(const QString& portName, const int side) {
const auto* m_portName = portName.toLatin1().data();
if (side == 1)
return jack_disconnect (client, jack_port_name(output_port_1), m_portName);
else
return jack_disconnect (client, jack_port_name(output_port_2), m_portName);
}
void ChannelStrip::connectTo(const QString& portName) {
jack_port_disconnect(client, output_port_1);
jack_port_disconnect(client, output_port_2);
// connect output port 1
const auto* portName1 = portName.toLatin1().data();
jack_connect(client, jack_port_name(output_port_1), portName1);
// connect output port 2
if (hasSuffixOne(portName)) {
const auto portNameSuffix2 = ChangeSuffixToTwo(portName);
const auto* portName2 = portNameSuffix2.toLatin1().data();
jack_connect(client, jack_port_name(output_port_2), portName2);
}
}
bool ChannelStrip::hasSuffixOne(const QString& portName) const {
return portName.mid(portName.length()-2, 2) == "_1";
}
QString ChannelStrip::ChangeSuffixToTwo(const QString& portName) const {
QString str{portName};
str.chop(2);
str.append("_2");
return str;
}
void ChannelStrip::setVolume(const float volumeValue) {
volume = volumeValue;
setPortVolumes();
}
void ChannelStrip::setPortVolumes() {
volL = volume * ((1 - pan) * M_PI_2); // equal power, -3db at center
volR = volume * (pan * M_PI_2);
}
QStringList ChannelStrip::getJackPorts(JackPortFlags jackPortFlags) {
const auto** ports = jack_get_ports(client, NULL, NULL, jackPortFlags);
QStringList a{};
int i{0};
while (ports[i] != NULL) {
bool add = true;
foreach (QString s, port_names) {
if (ports[i] == s) {
add = false;
}
}
if (add) {
a.append(ports[i]);
}
i++;
}
jack_free(ports);
return a;
}
QStringList ChannelStrip::getJackInputPorts() {
return getJackPorts(JackPortIsInput);
}
QStringList ChannelStrip::getJackOutputPorts() {
return getJackPorts(JackPortIsOutput);
}
} // namespace Mixr