/
port.cpp
135 lines (110 loc) · 3.95 KB
/
port.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
///////////////////////////////////////////////////////////////////////////////
// //
// This file is part of QtJack. //
// Copyright (C) 2014-2015 Jacob Dawid <jacob@omg-it.works> //
// //
// QtJack 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. //
// //
// QtJack 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 QtJack. If not, see <http://www.gnu.org/licenses/>. //
// //
// It is possible to obtain a closed-source license of QtJack. //
// If you're interested, contact me at: jacob@omg-it.works //
// //
///////////////////////////////////////////////////////////////////////////////
// Own includes
#include "port.h"
#include "client.h"
// Qt includes
#include <QStringList>
namespace QtJack {
Port::Port(jack_port_t *jackPort)
{
_jackPort = jackPort;
}
Port::Port()
{
_jackPort = 0;
}
Port::Port(const Port& other) {
_jackPort = other._jackPort;
}
Port::~Port() {
}
QString Port::fullName() const {
if(!isValid()) {
return QString();
}
return jack_port_name(_jackPort);
}
QString Port::clientName() const {
if(!isValid()) {
return QString();
}
return fullName().split(":").at(0);
}
QString Port::portName() const {
if(!isValid()) {
return QString();
}
return jack_port_short_name(_jackPort);
}
QString Port::portType() const {
if(!isValid()) {
return QString();
}
return QString(jack_port_type(_jackPort));
}
bool Port::isAudioPort() const {
QString portType(jack_port_type(_jackPort));
return isValid() && portType.toLower().contains("audio");
}
bool Port::isMidiPort() const {
QString portType(jack_port_type(_jackPort));
return isValid() && portType.toLower().contains("midi");
}
bool Port::isInput() const {
return isValid() && (jack_port_flags(_jackPort) & JackPortIsInput);
}
bool Port::isOutput() const {
return isValid() && (jack_port_flags(_jackPort) & JackPortIsOutput);
}
bool Port::isPhysical() const {
return isValid() && (jack_port_flags(_jackPort) & JackPortIsPhysical);
}
bool Port::canMonitor() const {
return isValid() && (jack_port_flags(_jackPort) & JackPortCanMonitor);
}
bool Port::isTerminal() const {
return isValid() && (jack_port_flags(_jackPort) & JackPortIsTerminal);
}
int Port::numberOfConnections() const {
if(!isValid()) {
return 0;
}
return jack_port_connected(_jackPort);
}
bool Port::isConnectedTo(const Port &other) const {
if(!isValid() || !other.isValid()) {
return false;
}
return jack_port_connected_to(_jackPort, other.fullName().toStdString().c_str());
}
bool Port::rename(QString name) {
if(!isValid()) {
return false;
}
return jack_port_set_name(_jackPort, name.toStdString().c_str()) == 0;
}
bool Port::operator ==(const Port& other) const {
return _jackPort == other._jackPort;
}
} // namespace QtJack