diff options
Diffstat (limited to 'src/event_to_string.cpp')
-rw-r--r-- | src/event_to_string.cpp | 203 |
1 files changed, 100 insertions, 103 deletions
diff --git a/src/event_to_string.cpp b/src/event_to_string.cpp index 606c512..d898845 100644 --- a/src/event_to_string.cpp +++ b/src/event_to_string.cpp @@ -41,106 +41,103 @@ namespace patchage { namespace { -struct EventPrinter -{ - using result_type = std::string; ///< For boost::apply_visitor - - std::string operator()(const ClientType type) - { - switch (type) { - case ClientType::jack: - return "JACK"; - case ClientType::alsa: - return "ALSA"; - } - - PATCHAGE_UNREACHABLE(); - } - - std::string operator()(const DriverAttachmentEvent& event) - { - return fmt::format("Attached to {}", (*this)(event.type)); - } - - std::string operator()(const DriverDetachmentEvent& event) - { - return fmt::format("Detached from {}", (*this)(event.type)); - } - - std::string operator()(const ClientCreationEvent& event) - { - return fmt::format( - R"(Add client "{}" ("{}"))", event.id, event.info.label); - } - - std::string operator()(const ClientDestructionEvent& event) - { - return fmt::format(R"(Add{} {} {} port "{}" ("{}"))", event.id); - } - - std::string operator()(const PortType port_type) - { - switch (port_type) { - case PortType::jack_audio: - return "JACK audio"; - case PortType::jack_midi: - return "JACK MIDI"; - case PortType::alsa_midi: - return "ALSA MIDI"; - case PortType::jack_osc: - return "JACK OSC"; - case PortType::jack_cv: - return "JACK CV"; - } - - PATCHAGE_UNREACHABLE(); - } - - std::string operator()(const SignalDirection direction) - { - switch (direction) { - case SignalDirection::input: - return "input"; - case SignalDirection::output: - return "output"; - case SignalDirection::duplex: - return "duplex"; - } - - PATCHAGE_UNREACHABLE(); - } - - std::string operator()(const PortCreationEvent& event) - { - auto result = fmt::format(R"(Add{} {} {} port "{}" ("{}"))", - event.info.is_terminal ? " terminal" : "", - (*this)(event.info.type), - (*this)(event.info.direction), - event.id, - event.info.label); - - if (event.info.order) { - result += fmt::format(" order: {}", *event.info.order); - } - - return result; - } - - std::string operator()(const PortDestructionEvent& event) - { - return fmt::format(R"("Remove port "{}")", event.id); - } - - std::string operator()(const ConnectionEvent& event) - { - return fmt::format(R"(Connect "{}" to "{}")", event.tail, event.head); - } - - std::string operator()(const DisconnectionEvent& event) - { - return fmt::format( - R"(Disconnect "{}" from "{}")", event.tail, event.head); - } +struct EventPrinter { + using result_type = std::string; ///< For boost::apply_visitor + + std::string operator()(const ClientType type) + { + switch (type) { + case ClientType::jack: + return "JACK"; + case ClientType::alsa: + return "ALSA"; + } + + PATCHAGE_UNREACHABLE(); + } + + std::string operator()(const DriverAttachmentEvent& event) + { + return fmt::format("Attached to {}", (*this)(event.type)); + } + + std::string operator()(const DriverDetachmentEvent& event) + { + return fmt::format("Detached from {}", (*this)(event.type)); + } + + std::string operator()(const ClientCreationEvent& event) + { + return fmt::format(R"(Add client "{}" ("{}"))", event.id, event.info.label); + } + + std::string operator()(const ClientDestructionEvent& event) + { + return fmt::format(R"(Add{} {} {} port "{}" ("{}"))", event.id); + } + + std::string operator()(const PortType port_type) + { + switch (port_type) { + case PortType::jack_audio: + return "JACK audio"; + case PortType::jack_midi: + return "JACK MIDI"; + case PortType::alsa_midi: + return "ALSA MIDI"; + case PortType::jack_osc: + return "JACK OSC"; + case PortType::jack_cv: + return "JACK CV"; + } + + PATCHAGE_UNREACHABLE(); + } + + std::string operator()(const SignalDirection direction) + { + switch (direction) { + case SignalDirection::input: + return "input"; + case SignalDirection::output: + return "output"; + case SignalDirection::duplex: + return "duplex"; + } + + PATCHAGE_UNREACHABLE(); + } + + std::string operator()(const PortCreationEvent& event) + { + auto result = fmt::format(R"(Add{} {} {} port "{}" ("{}"))", + event.info.is_terminal ? " terminal" : "", + (*this)(event.info.type), + (*this)(event.info.direction), + event.id, + event.info.label); + + if (event.info.order) { + result += fmt::format(" order: {}", *event.info.order); + } + + return result; + } + + std::string operator()(const PortDestructionEvent& event) + { + return fmt::format(R"("Remove port "{}")", event.id); + } + + std::string operator()(const ConnectionEvent& event) + { + return fmt::format(R"(Connect "{}" to "{}")", event.tail, event.head); + } + + std::string operator()(const DisconnectionEvent& event) + { + return fmt::format(R"(Disconnect "{}" from "{}")", event.tail, event.head); + } }; } // namespace @@ -148,14 +145,14 @@ struct EventPrinter std::string event_to_string(const Event& event) { - EventPrinter printer; - return boost::apply_visitor(printer, event); + EventPrinter printer; + return boost::apply_visitor(printer, event); } std::ostream& operator<<(std::ostream& os, const Event& event) { - return os << event_to_string(event); + return os << event_to_string(event); } } // namespace patchage |