3 * Copyright (C) 2011-2014 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 #include "CarlaPatchbayUtils.hpp"
20 static const GroupNameToId kGroupNameToIdFallback
= { 0, { '\0' } };
21 static const PortNameToId kPortNameToIdFallback
= { 0, 0, { '\0' }, { '\0' }, { '\0' } };
23 uint
PatchbayGroupList::getGroupId(const char* const groupName
) const noexcept
25 CARLA_SAFE_ASSERT_RETURN(groupName
!= nullptr && groupName
[0] != '\0', 0);
27 for (LinkedList
<GroupNameToId
>::Itenerator it
= list
.begin2(); it
.valid(); it
.next())
29 const GroupNameToId
& groupNameToId(it
.getValue(kGroupNameToIdFallback
));
30 CARLA_SAFE_ASSERT_CONTINUE(groupNameToId
.group
!= 0);
32 if (std::strncmp(groupNameToId
.name
, groupName
, STR_MAX
) == 0)
33 return groupNameToId
.group
;
39 const char* PatchbayGroupList::getGroupName(const uint groupId
) const noexcept
41 static const char fallback
[] = { '\0' };
43 for (LinkedList
<GroupNameToId
>::Itenerator it
= list
.begin2(); it
.valid(); it
.next())
45 const GroupNameToId
& groupNameToId(it
.getValue(kGroupNameToIdFallback
));
46 CARLA_SAFE_ASSERT_CONTINUE(groupNameToId
.group
!= 0);
48 if (groupNameToId
.group
== groupId
)
49 return groupNameToId
.name
;
55 const char* PatchbayPortList::getFullPortName(const uint groupId
, const uint portId
) const noexcept
57 static const char fallback
[] = { '\0' };
59 for (LinkedList
<PortNameToId
>::Itenerator it
= list
.begin2(); it
.valid(); it
.next())
61 const PortNameToId
& portNameToId(it
.getValue(kPortNameToIdFallback
));
62 CARLA_SAFE_ASSERT_CONTINUE(portNameToId
.group
!= 0);
64 if (portNameToId
.group
== groupId
&& portNameToId
.port
== portId
)
65 return portNameToId
.fullName
;
71 const PortNameToId
& PatchbayPortList::getPortNameToId(const char* const fullPortName
) const noexcept
73 CARLA_SAFE_ASSERT_RETURN(fullPortName
!= nullptr && fullPortName
[0] != '\0', kPortNameToIdFallback
);
75 for (LinkedList
<PortNameToId
>::Itenerator it
= list
.begin2(); it
.valid(); it
.next())
77 const PortNameToId
& portNameToId(it
.getValue(kPortNameToIdFallback
));
78 CARLA_SAFE_ASSERT_CONTINUE(portNameToId
.group
!= 0);
80 if (std::strncmp(portNameToId
.fullName
, fullPortName
, STR_MAX
) == 0)
84 return kPortNameToIdFallback
;