Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion packs/rigComponent
148 changes: 148 additions & 0 deletions src/core/util/Monitors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#include "core/util/Monitors.h"

#include "rendering/U_gladGlfw.h"

#include <GLFW/glfw3.h>

#include <algorithm>
#include <cctype>
#include <sstream>

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<MonitorInfo> enumerateMonitors() {
std::vector<MonitorInfo> out;
int count = 0;
GLFWmonitor** mons = glfwGetMonitors(&count);
if (!mons || count <= 0) {
return out;
}
out.reserve(static_cast<size_t>(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<MonitorInfo>& 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<int>(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
56 changes: 56 additions & 0 deletions src/core/util/Monitors.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <vector>

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<MonitorInfo> 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<MonitorInfo>& live);

/** @brief `index: name WxH @Hz`, plus position for a twin and `(offline)` when absent. */
std::string monitorLabel(const MonitorInfo& monitor);

} // namespace rigkit
Loading