3 * Copyright (C) 2011-2020 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_PATCHBAY_UTILS_HPP_INCLUDED
19 #define CARLA_PATCHBAY_UTILS_HPP_INCLUDED
21 #include "CarlaMutex.hpp"
22 #include "LinkedList.hpp"
26 // -----------------------------------------------------------------------
28 struct GroupNameToId
{
30 char name
[STR_MAX
]; // globally unique
38 void setData(const uint g
, const char n
[]) noexcept
44 void rename(const char n
[]) noexcept
46 std::strncpy(name
, n
, STR_MAX
-1);
47 name
[STR_MAX
-1] = '\0';
50 bool operator==(const GroupNameToId
& groupNameToId
) const noexcept
52 if (groupNameToId
.group
!= group
)
54 if (std::strncmp(groupNameToId
.name
, name
, STR_MAX
-1) != 0)
59 bool operator!=(const GroupNameToId
& groupNameToId
) const noexcept
61 return !operator==(groupNameToId
);
65 struct PatchbayGroupList
{
67 LinkedList
<GroupNameToId
> list
;
70 PatchbayGroupList() noexcept
81 uint
getGroupId(const char* const groupName
) const noexcept
;
83 // always returns valid pointer (non-null)
84 const char* getGroupName(const uint groupId
) const noexcept
;
87 // -----------------------------------------------------------------------
92 char name
[STR_MAX
]; // locally unique (within the same group)
93 char fullName
[STR_MAX
]; // globally unique
94 char identifier
[STR_MAX
]; // globally unique, if used
102 identifier
[0] = '\0';
105 void setData(const uint g
, const uint p
, const char n
[], const char fn
[]) noexcept
112 void setDataWithIdentifier(const uint g
, const uint p
, const char n
[], const char id
[]) noexcept
117 std::strncpy(name
, n
, STR_MAX
-1);
118 name
[STR_MAX
-1] = '\0';
122 std::strncpy(identifier
, id
, STR_MAX
-1);
123 identifier
[STR_MAX
-1] = '\0';
126 void setFullName(const char fn
[]) noexcept
128 std::strncpy(fullName
, fn
, STR_MAX
-1);
129 fullName
[STR_MAX
-1] = '\0';
132 void rename(const char n
[], const char fn
[]) noexcept
134 std::strncpy(name
, n
, STR_MAX
-1);
135 name
[STR_MAX
-1] = '\0';
137 std::strncpy(fullName
, fn
, STR_MAX
-1);
138 fullName
[STR_MAX
-1] = '\0';
141 bool operator==(const PortNameToId
& portNameToId
) noexcept
143 if (portNameToId
.group
!= group
|| portNameToId
.port
!= port
)
145 if (std::strncmp(portNameToId
.name
, name
, STR_MAX
-1) != 0)
147 if (std::strncmp(portNameToId
.fullName
, fullName
, STR_MAX
-1) != 0)
152 bool operator!=(const PortNameToId
& portNameToId
) noexcept
154 return !operator==(portNameToId
);
158 struct PatchbayPortList
{
160 LinkedList
<PortNameToId
> list
;
163 PatchbayPortList() noexcept
168 void clear() noexcept
174 // always returns valid pointer (non-null)
175 const char* getFullPortName(const uint groupId
, const uint portId
) const noexcept
;
177 const PortNameToId
& getPortNameToId(const char* const fullPortName
) const noexcept
;
180 // -----------------------------------------------------------------------
182 struct ConnectionToId
{
187 void clear() noexcept
189 // needed for apple GCC4.2
198 void setData(const uint i
, const uint gA
, const uint pA
, const uint gB
, const uint pB
) noexcept
200 // needed for apple GCC4.2
209 bool operator==(const ConnectionToId
& connectionToId
) const noexcept
211 if (connectionToId
.id
!= id
)
213 if (connectionToId
.groupA
!= groupA
|| connectionToId
.portA
!= portA
)
215 if (connectionToId
.groupB
!= groupB
|| connectionToId
.portB
!= portB
)
220 bool operator!=(const ConnectionToId
& connectionToId
) const noexcept
222 return !operator==(connectionToId
);
226 struct PatchbayConnectionList
{
228 LinkedList
<ConnectionToId
> list
;
231 PatchbayConnectionList() noexcept
236 void clear() noexcept
243 // -----------------------------------------------------------------------
245 #endif // CARLA_PATCHBAY_UTILS_HPP_INCLUDED