Add exporting/importing
This commit is contained in:
parent
fa9216a110
commit
7333fdc401
59
main.cpp
59
main.cpp
@ -8,6 +8,8 @@
|
|||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b);
|
void generateRandomColors(unsigned char& r, unsigned char& g, unsigned char& b);
|
||||||
@ -144,6 +146,53 @@ void sendDMXData(HANDLE hSerial, unsigned char* data, int length) {
|
|||||||
WriteFile(hSerial, data, length, &bytesWritten, NULL);
|
WriteFile(hSerial, data, length, &bytesWritten, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function to export markers to a JSON file
|
||||||
|
void exportMarkersToFile(const std::string& filename) {
|
||||||
|
nlohmann::json j;
|
||||||
|
|
||||||
|
for (const auto& marker : markers) {
|
||||||
|
j.push_back({
|
||||||
|
{"time", std::get<0>(marker)},
|
||||||
|
{"r", std::get<1>(marker)},
|
||||||
|
{"g", std::get<2>(marker)},
|
||||||
|
{"b", std::get<3>(marker)}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream file(filename);
|
||||||
|
if (file.is_open()) {
|
||||||
|
file << j.dump(4); // Pretty print with indentation of 4 spaces
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cerr << "Could not open file for writing: " << filename << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to load markers from a JSON file
|
||||||
|
void loadMarkersFromFile(const std::string& filename) {
|
||||||
|
nlohmann::json j;
|
||||||
|
std::ifstream file(filename);
|
||||||
|
|
||||||
|
if (file.is_open()) {
|
||||||
|
file >> j;
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
markers.clear();
|
||||||
|
for (const auto& element : j) {
|
||||||
|
markers.emplace_back(
|
||||||
|
element["time"].get<float>(),
|
||||||
|
element["r"].get<unsigned char>(),
|
||||||
|
element["g"].get<unsigned char>(),
|
||||||
|
element["b"].get<unsigned char>()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
std::cerr << "Could not open file for reading: " << filename << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GLFWwindow* initOpenGL() {
|
GLFWwindow* initOpenGL() {
|
||||||
if (!glfwInit()) {
|
if (!glfwInit()) {
|
||||||
std::cerr << "Failed to initialize GLFW" << std::endl;
|
std::cerr << "Failed to initialize GLFW" << std::endl;
|
||||||
@ -193,6 +242,16 @@ void renderImGui() {
|
|||||||
// Create a window
|
// Create a window
|
||||||
ImGui::Begin("DMX Controller");
|
ImGui::Begin("DMX Controller");
|
||||||
|
|
||||||
|
if (ImGui::Button("Export Lightshow")) {
|
||||||
|
exportMarkersToFile("lightshow.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button("Load Lightshow")) {
|
||||||
|
loadMarkersFromFile("lightshow.json");
|
||||||
|
}
|
||||||
|
|
||||||
// Create sliders for the first three DMX channels
|
// Create sliders for the first three DMX channels
|
||||||
ImGui::SliderInt("Channel 1", &channel1, 0, 255);
|
ImGui::SliderInt("Channel 1", &channel1, 0, 255);
|
||||||
ImGui::SliderInt("Channel 2", &channel2, 0, 255);
|
ImGui::SliderInt("Channel 2", &channel2, 0, 255);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user