diff --git a/include/libremidi/backends/linux/pipewire/format.hpp b/include/libremidi/backends/linux/pipewire/format.hpp index 6d11780c..f7190a0b 100644 --- a/include/libremidi/backends/linux/pipewire/format.hpp +++ b/include/libremidi/backends/linux/pipewire/format.hpp @@ -179,21 +179,19 @@ inline bool extract_modifier_choice( if (spa_pod_is_choice(val)) { - const auto* choice = reinterpret_cast(val); - const spa_pod* child = SPA_POD_CHOICE_CHILD(reinterpret_cast(val)); - const std::uint32_t child_size = SPA_POD_BODY_SIZE(child); - const std::uint32_t n_values - = (SPA_POD_BODY_SIZE(val) - sizeof(spa_pod_choice_body)) / child_size; - const std::uint8_t* p = static_cast(SPA_POD_CONTENTS(spa_pod_choice, val)) - + sizeof(spa_pod_choice_body); - for (std::uint32_t i = 0; i < n_values; ++i) + // SPA_POD_CHOICE_VALUES already skips the pod header and the choice body. + const std::uint32_t value_size = SPA_POD_CHOICE_VALUE_SIZE(val); + const std::uint32_t n_values = SPA_POD_CHOICE_N_VALUES(val); + const auto* p = static_cast(SPA_POD_CHOICE_VALUES(val)); + if (value_size == sizeof(std::int64_t)) { - std::int64_t v; - std::memcpy(&v, p, sizeof(v)); - out_choices.push_back(static_cast(v)); - p += child_size; + for (std::uint32_t i = 0; i < n_values; ++i, p += value_size) + { + std::int64_t v; + std::memcpy(&v, p, sizeof(v)); + out_choices.push_back(static_cast(v)); + } } - (void)choice; return true; }