diff --git a/docs/nodes.md b/docs/nodes.md index 7bf937c..7ee3ab6 100644 --- a/docs/nodes.md +++ b/docs/nodes.md @@ -250,6 +250,6 @@ Example binding: Vec2 Out sets orbit radius (x) and height (y). - Wiring outputs into transforms/materials is the **app’s** job each Update. - **Ctrl-P** toggles the Patch bay only. The Node Editor stays. Both edit the same links. -Host MIDI (KidVJ): devices and clock sync are **Preferences > Audio > MIDI**. +Host MIDI: devices and clock sync are **Preferences > Audio > MIDI**. Map Mix sliders with right-click **MIDI Learn** (View > MIDI Map for the table). `mod.beat` follows incoming MIDI clock when Clock Sync is on. diff --git a/packs/rigComponent b/packs/rigComponent index 07c5b0f..fe03edb 160000 --- a/packs/rigComponent +++ b/packs/rigComponent @@ -1 +1 @@ -Subproject commit 07c5b0fba219ace1de81df2ef44410973aa6ee68 +Subproject commit fe03edb141c702415413b6dbabc05c1f6b0d855d diff --git a/packs/rigImGui b/packs/rigImGui index e1dd268..dabadbe 160000 --- a/packs/rigImGui +++ b/packs/rigImGui @@ -1 +1 @@ -Subproject commit e1dd2687ca78610d908672a10d6d36be6f02340f +Subproject commit dabadbe40cfc0df6e7a1cc594a95e988411a25db diff --git a/src/core/util/Monitors.cpp b/src/core/util/Monitors.cpp new file mode 100644 index 0000000..b90c2c2 --- /dev/null +++ b/src/core/util/Monitors.cpp @@ -0,0 +1,148 @@ +#include "core/util/Monitors.h" + +#include "rendering/U_gladGlfw.h" + +#include + +#include +#include +#include + +namespace rigkit { +namespace { + +void slashName(std::string& name) { + for (char& c : name) { + if (c == '|') { + c = '/'; + } + } +} + +std::string modePart(const MonitorInfo& monitor) { + return std::to_string(monitor.width) + "x" + std::to_string(monitor.height) + "@" + + std::to_string(monitor.refresh); +} + +} // namespace + +std::string monitorIdentity(const MonitorInfo& monitor) { + MonitorInfo copy = monitor; + slashName(copy.name); + if (copy.name.empty()) { + copy.name = "monitor"; + } + return copy.name + "|" + modePart(copy) + "|" + std::to_string(copy.x) + "," + + std::to_string(copy.y); +} + +std::string monitorStem(const std::string& identity) { + int idx = 0; + if (identityIsIndex(identity, idx)) { + return identity; + } + const auto last = identity.rfind('|'); + if (last == std::string::npos || last == 0) { + return identity; + } + return identity.substr(0, last); +} + +bool identityIsIndex(const std::string& identity, int& indexOut) { + if (identity.rfind("index:", 0) != 0) { + return false; + } + try { + indexOut = std::stoi(identity.substr(6)); + return true; + } catch (...) { + return false; + } +} + +std::string indexIdentity(int index) { + return "index:" + std::to_string(index); +} + +std::vector enumerateMonitors() { + std::vector out; + int count = 0; + GLFWmonitor** mons = glfwGetMonitors(&count); + if (!mons || count <= 0) { + return out; + } + out.reserve(static_cast(count)); + for (int i = 0; i < count; ++i) { + MonitorInfo monitor; + monitor.index = i; + const char* name = glfwGetMonitorName(mons[i]); + monitor.name = name ? name : "monitor"; + glfwGetMonitorPos(mons[i], &monitor.x, &monitor.y); + if (const GLFWvidmode* vm = glfwGetVideoMode(mons[i])) { + monitor.width = vm->width; + monitor.height = vm->height; + monitor.refresh = vm->refreshRate; + } + monitor.identity = monitorIdentity(monitor); + out.push_back(std::move(monitor)); + } + for (size_t i = 0; i < out.size(); ++i) { + const std::string stem = monitorStem(out[i].identity); + for (size_t j = 0; j < out.size(); ++j) { + if (i != j && monitorStem(out[j].identity) == stem) { + out[i].twin = true; + break; + } + } + } + return out; +} + +int resolveMonitorIndex(const std::string& identity, const std::vector& live) { + if (identity.empty()) { + return -1; + } + for (const MonitorInfo& monitor : live) { + if (monitor.identity == identity) { + return monitor.index; + } + } + int indexed = 0; + if (identityIsIndex(identity, indexed)) { + if (indexed >= 0 && indexed < static_cast(live.size())) { + return indexed; + } + return -1; + } + const std::string stem = monitorStem(identity); + int found = -1; + int hits = 0; + for (const MonitorInfo& monitor : live) { + if (monitorStem(monitor.identity) == stem) { + found = monitor.index; + ++hits; + } + } + if (hits == 1) { + return found; + } + return -1; +} + +std::string monitorLabel(const MonitorInfo& monitor) { + std::ostringstream os; + if (monitor.index >= 0) { + os << monitor.index << ": "; + } + os << (monitor.name.empty() ? "monitor" : monitor.name) << " " << monitor.width << "x" + << monitor.height << " @" << monitor.refresh; + if (monitor.twin) { + os << " pos " << monitor.x << "," << monitor.y; + } + if (monitor.index < 0) { + os << " (offline)"; + } + return os.str(); +} + +} // namespace rigkit diff --git a/src/core/util/Monitors.h b/src/core/util/Monitors.h new file mode 100644 index 0000000..57f3fff --- /dev/null +++ b/src/core/util/Monitors.h @@ -0,0 +1,56 @@ +#pragma once + +/** + * @file + * @brief Attached-monitor identity for output windows. + * @details Identity is display name, video mode, and position. A saved route + * resolves back to the same physical screen after a cable swap when the name + * and mode are unique. Twin displays (same name and mode) stay distinct by + * position. This does not open windows or draw a lineup pattern. + */ + +#include +#include + +namespace rigkit { + +/** @brief One attached monitor, or a remembered one with `index` -1. */ +struct MonitorInfo { + int index = -1; ///< Current GLFW index, or -1 when offline. + std::string name; + int width = 0; + int height = 0; + int refresh = 0; + int x = 0; + int y = 0; + std::string identity; + bool twin = false; ///< Another live monitor has the same name and mode. +}; + +/** @brief `name|WxH@Hz|x,y`. `|` inside the name is stored as `/`. */ +std::string monitorIdentity(const MonitorInfo& monitor); + +/** @brief `name|WxH@Hz` without position. An `index:N` key is unchanged. */ +std::string monitorStem(const std::string& identity); + +/** @brief True when `identity` is the `index:N` fallback. */ +bool identityIsIndex(const std::string& identity, int& indexOut); + +/** @brief Fallback key when a display has no live identity. */ +std::string indexIdentity(int index); + +/** @brief Currently attached monitors. Empty before GLFW is initialized. */ +std::vector enumerateMonitors(); + +/** + * @brief Live GLFW index for a saved identity, or -1. + * @details Exact identity wins. A unique name+mode match ignores position, so + * a cable swap still hits. Two twins with the same stem do not match that way. + * `index:N` resolves only while that index is attached. + */ +int resolveMonitorIndex(const std::string& identity, const std::vector& live); + +/** @brief `index: name WxH @Hz`, plus position for a twin and `(offline)` when absent. */ +std::string monitorLabel(const MonitorInfo& monitor); + +} // namespace rigkit