summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-11-28 15:12:14 +0100
committerDavid Robillard <d@drobilla.net>2020-11-28 15:12:14 +0100
commit62b19ed3c43ceb3a88944b892a24686ca0b7b036 (patch)
treeb3ea07b29f8c15aa0517bd8844bb176c7f04e19c /src
parente3f3f3586411136e5b7f61cc1726bbc0635deddd (diff)
downloadpatchage-62b19ed3c43ceb3a88944b892a24686ca0b7b036.tar.gz
patchage-62b19ed3c43ceb3a88944b892a24686ca0b7b036.tar.bz2
patchage-62b19ed3c43ceb3a88944b892a24686ca0b7b036.zip
Remove null port IDs
This statically ensures that a PortID is always valid.
Diffstat (limited to 'src')
-rw-r--r--src/JackDriver.cpp4
-rw-r--r--src/PortID.hpp20
2 files changed, 6 insertions, 18 deletions
diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp
index 904fcc6..0d8c2b9 100644
--- a/src/JackDriver.cpp
+++ b/src/JackDriver.cpp
@@ -259,9 +259,7 @@ JackDriver::create_port(PatchageModule& parent,
_app->show_human_names(),
order);
- if (id.type() != PortID::Type::nothing) {
- dynamic_cast<PatchageCanvas*>(parent.canvas())->index_port(id, ret);
- }
+ _app->canvas()->index_port(id, ret);
return ret;
}
diff --git a/src/PortID.hpp b/src/PortID.hpp
index 84c08a4..a0f1bb9 100644
--- a/src/PortID.hpp
+++ b/src/PortID.hpp
@@ -28,7 +28,6 @@ struct PortID
{
enum class Type
{
- nothing,
jack,
alsa,
};
@@ -41,9 +40,6 @@ struct PortID
~PortID() = default;
- /// Return a null ID that refers to nothing
- static PortID nothing() { return PortID{}; }
-
/// Return an ID for a JACK port by full name (like "client:port")
static PortID jack(std::string name)
{
@@ -64,8 +60,6 @@ struct PortID
bool alsa_is_input() const { return _alsa_is_input; }
private:
- PortID() = default;
-
PortID(const Type type, std::string jack_name)
: _type{type}
, _jack_name{std::move(jack_name)}
@@ -86,19 +80,17 @@ private:
assert(_type == Type::alsa);
}
- Type _type{Type::nothing}; ///< Determines which field is active
- std::string _jack_name{}; ///< Full port name for Type::jack
- uint8_t _alsa_client{}; ///< Client ID for Type::alsa
- uint8_t _alsa_port{}; ///< Port ID for Type::alsa
- bool _alsa_is_input{}; ///< Input flag for Type::alsa
+ Type _type; ///< Determines which field is active
+ std::string _jack_name; ///< Full port name for Type::jack
+ uint8_t _alsa_client{}; ///< Client ID for Type::alsa
+ uint8_t _alsa_port{}; ///< Port ID for Type::alsa
+ bool _alsa_is_input{}; ///< Input flag for Type::alsa
};
static inline std::ostream&
operator<<(std::ostream& os, const PortID& id)
{
switch (id.type()) {
- case PortID::Type::nothing:
- return os << "(null)";
case PortID::Type::jack:
return os << "jack:" << id.jack_name();
case PortID::Type::alsa:
@@ -119,8 +111,6 @@ operator<(const PortID& lhs, const PortID& rhs)
}
switch (lhs.type()) {
- case PortID::Type::nothing:
- return true;
case PortID::Type::jack:
return lhs.jack_name() < rhs.jack_name();
case PortID::Type::alsa: