satdump/src-ui/main.cpp

216 lines
6.6 KiB
C++
Raw Normal View History

2021-02-17 22:25:03 +01:00
#include "logger.h"
#include "style.h"
2021-02-18 20:42:08 +01:00
#include "gl.h"
#include "logger.h"
#include <signal.h>
2021-02-18 21:15:33 +01:00
#include <GLFW/glfw3.h>
2021-02-19 00:03:52 +01:00
#include "imgui/imgui_flags.h"
2021-03-22 18:53:09 +01:00
#include "credits.h"
#include "global.h"
#include "init.h"
#include "processing.h"
#include "offline.h"
2021-03-22 22:26:21 +01:00
#include "live.h"
2021-02-14 12:05:44 +01:00
2021-02-17 21:13:36 +01:00
static void glfw_error_callback(int error, const char *description)
{
logger->error("Glfw Error " + std::to_string(error) + ": " + description);
}
2021-02-17 22:25:03 +01:00
int main(int argc, char *argv[])
{
2021-02-23 15:39:26 +01:00
std::fill(error_message, &error_message[0], 0);
2021-02-18 20:42:08 +01:00
uiCallList = std::make_shared<std::vector<std::shared_ptr<ProcessingModule>>>();
uiCallListMutex = std::make_shared<std::mutex>();
// Ignore SIGPIPE
#ifndef _WIN32
signal(SIGPIPE, SIG_IGN);
#endif
initLogger();
if (argc < 6)
{
logger->info("Usage : " + std::string(argv[0]) + " [downlink] [input_level] [input_file] [output_level] [output_file_or_directory]");
// exit(1);
}
else
{
downlink_pipeline = argv[1];
input_level = argv[2];
input_file = argv[3];
output_level = argv[4];
output_file = argv[5];
if (argc > 6)
{
for (int i = 6; i < argc; i++)
{
if (i + 1 != argc)
{
if (strcmp(argv[i], "-samplerate") == 0) // This is your parameter name
{
parameters.emplace("samplerate", argv[i + 1]); // The next value in the array is your value
i++; // Move to the next flag
}
else if (strcmp(argv[i], "-baseband_format") == 0) // This is your parameter name
{
parameters.emplace("baseband_format", argv[i + 1]); // The next value in the array is your value
i++; // Move to the next flag
}
else if (strcmp(argv[i], "-dc_block") == 0) // This is your parameter name
{
parameters.emplace("dc_block", argv[i + 1]); // The next value in the array is your value
i++; // Move to the next flag
}
}
}
}
processing = true;
}
2021-03-22 18:53:09 +01:00
initSatdump();
2021-02-18 20:42:08 +01:00
2021-02-17 22:25:03 +01:00
// Setup window
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
2021-02-14 12:05:44 +01:00
{
2021-02-17 22:25:03 +01:00
logger->critical("Could not init GLFW");
2021-02-14 12:05:44 +01:00
exit(1);
}
2021-02-18 20:42:08 +01:00
// GL STUFF
2021-02-17 22:25:03 +01:00
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
2021-02-14 12:05:44 +01:00
2021-02-17 22:25:03 +01:00
// Create window with graphics context
2021-02-21 17:17:44 +01:00
GLFWwindow *window = glfwCreateWindow(1000, 600, "SatDump", NULL, NULL);
2021-02-17 22:25:03 +01:00
if (window == NULL)
2021-02-14 12:05:44 +01:00
{
2021-02-17 22:25:03 +01:00
logger->critical("Could not init GLFW Window");
exit(1);
2021-02-14 12:05:44 +01:00
}
2021-02-17 22:25:03 +01:00
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
2021-02-14 12:05:44 +01:00
2021-02-17 22:25:03 +01:00
if (glewInit() != GLEW_OK)
{
logger->critical("Failed to initialize OpenGL loader!");
exit(1);
}
2021-02-17 20:07:49 +01:00
2021-02-17 22:25:03 +01:00
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
(void)io;
io.IniFilename = NULL;
2021-02-16 13:47:53 +01:00
2021-02-17 22:25:03 +01:00
// Setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true);
if (!ImGui_ImplOpenGL3_Init("#version 150"))
ImGui_ImplOpenGL3_Init("#version 120"); // If 1.5 doesn't work go back to 1.2
2021-02-16 13:47:53 +01:00
2021-02-23 19:18:31 +01:00
style::setDarkStyle(".");
2021-02-18 20:42:08 +01:00
if (processing)
processThreadPool.push([&](int) { process(downlink_pipeline, input_level, input_file, output_level, output_file, parameters); });
2021-02-18 20:42:08 +01:00
2021-02-17 22:25:03 +01:00
// Main loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
2021-02-16 13:47:53 +01:00
2021-02-17 22:25:03 +01:00
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
2021-02-16 13:47:53 +01:00
2021-02-17 22:25:03 +01:00
int wwidth, wheight;
glfwGetWindowSize(window, &wwidth, &wheight);
2021-02-16 13:47:53 +01:00
2021-02-17 22:25:03 +01:00
// User rendering
{
2021-02-18 20:42:08 +01:00
if (processing)
{
uiCallListMutex->lock();
for (std::shared_ptr<ProcessingModule> module : *uiCallList)
{
ImGui::SetNextWindowPos({0, 0});
2021-02-18 21:28:10 +01:00
ImGui::SetNextWindowSize({(float)wwidth, (float)wheight});
2021-02-18 20:42:08 +01:00
module->drawUI();
}
uiCallListMutex->unlock();
}
else
2021-02-17 22:25:03 +01:00
{
2021-02-18 20:42:08 +01:00
ImGui::SetNextWindowPos({0, 0});
2021-02-18 20:56:55 +01:00
ImGui::SetNextWindowSize({(float)wwidth, (float)wheight});
2021-02-21 15:11:02 +01:00
ImGui::Begin("Main Window", NULL, NOWINDOW_FLAGS | ImGuiWindowFlags_NoTitleBar);
2021-02-18 20:42:08 +01:00
2021-02-21 15:11:02 +01:00
if (ImGui::BeginTabBar("Main TabBar", ImGuiTabBarFlags_None))
2021-02-18 20:42:08 +01:00
{
2021-02-21 15:11:02 +01:00
if (ImGui::BeginTabItem("Offline processing"))
2021-02-18 20:42:08 +01:00
{
2021-03-22 18:53:09 +01:00
renderOfflineProcessing();
2021-02-21 15:11:02 +01:00
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Live processing"))
2021-02-18 20:42:08 +01:00
{
2021-03-22 22:26:21 +01:00
#ifdef BUILD_LIVE
renderLiveProcessing();
#else
2021-03-15 13:30:16 +01:00
ImGui::Text("Live support is currently being rewritten, and does not work on Windows yet. If you really need it, please stick to an older version.");
2021-03-22 22:26:21 +01:00
#endif
2021-03-15 13:33:23 +01:00
ImGui::EndTabItem();
2021-02-21 15:11:02 +01:00
}
if (ImGui::BeginTabItem("Credits"))
{
2021-03-22 18:53:09 +01:00
renderCredits(wwidth, wheight);
2021-02-21 15:11:02 +01:00
ImGui::EndTabItem();
2021-02-20 00:36:44 +01:00
}
2021-02-18 20:42:08 +01:00
}
2021-02-21 15:11:02 +01:00
ImGui::EndTabBar();
2021-02-18 20:42:08 +01:00
ImGui::End();
2021-02-16 13:47:53 +01:00
}
}
2021-02-14 12:05:44 +01:00
2021-02-17 22:25:03 +01:00
// Rendering
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
2021-02-14 12:05:44 +01:00
2021-02-18 00:31:24 +01:00
glClearColor(0.0666f, 0.0666f, 0.0666f, 1.0f);
//glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
2021-02-17 22:25:03 +01:00
glClear(GL_COLOR_BUFFER_BIT);
2021-02-17 22:25:03 +01:00
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
2021-02-16 13:47:53 +01:00
2021-02-17 22:25:03 +01:00
glfwSwapBuffers(window);
2021-02-16 13:47:53 +01:00
}
2021-02-14 12:05:44 +01:00
2021-02-17 22:25:03 +01:00
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
2021-02-24 12:58:30 +01:00
processThreadPool.stop();
for (int i = 0; i < processThreadPool.size(); i++)
{
if (processThreadPool.get_thread(i).joinable())
processThreadPool.get_thread(i).join();
}
2021-02-14 12:05:44 +01:00
}