diff --git a/src/debug.h b/src/debug.h index da6285c..2878c37 100644 --- a/src/debug.h +++ b/src/debug.h @@ -2,6 +2,28 @@ #if defined (QT_DEBUG) || defined (DEBUG) || defined (_DEBUG) +#ifdef INIT_FILELOG + std::wstring_convert, wchar_t> converter; + FILE* fileLog; + errno_t lfResult; + bool writable = false; + + void inline initializeFileLogging() { + lfResult = fopen_s(&fileLog, "log.txt", "w"); + if (!lfResult) writable = true; + else writable = false; + } + +#else + extern std::wstring_convert, wchar_t> converter; + extern errno_t lfResult; + extern FILE* fileLog; + extern bool writable; + extern bool initializeFileLogging(); +#endif + +#define initialize_file_log() initializeFileLogging() + template std::bitset varToBitset(T info) { std::bitset content(info); @@ -15,6 +37,7 @@ std::bitset varToBitset(T info) { #define log_wdebugcpp(str) do { \ std::wcout << "[DEBUG]" << "(" << __FILE__ << ":" << __LINE__ << "): " << str << std::endl; \ } while (0) + #else #include @@ -29,19 +52,35 @@ std::bitset varToBitset(T info) { #define log_wdebugcpp(str) do { \ OutputDebugStringW(std::wstring(L"[DEBUG] (" + std::wstring(WFILE) + L":" + std::to_wstring(__LINE__) + L"): " + std::wstring(str) +L"\n").c_str()); \ } while (0) + #endif + +#define log_to_file_simple(fmt) log_to_file(fmt, "") +#define log_to_file(fmt, cnt...) do { \ + if(writable) fprintf_s(fileLog, fmt, cnt); \ +} while (0) + + #define print_as_binary(len, type, info) varToBitset(info) +#define close_file_log_buffer() do { \ + fclose(fileLog); \ +} while (0) + #else #define log_debugcpp(str) #define log_wdebugcpp(str) #define print_as_binary(len, type, info) +#define log_to_file_simple(fmt) +#define log_to_file(fmt, cnt...) +#define initialize_file_log() false +#define close_file_log_buffer() #endif /* Here as a quick reference, in case smthn similar is needed again */ /* typedef void (EndpointWidget::*epwMuteFunc)(bool muted); */ -/* typedef void (EndpointWidget::*epwMainVolumeFunc)(float newValue); */ +/* Typedef void (EndpointWidget::*epwMainVolumeFunc)(float newValue); */ /* typedef void (EndpointWidget::*epwChannelVolumeFunc)(uint32_t channel, float newValue); */ /* typedef void (EndpointWidget::*epwToggleFrontFunc)(bool active); */ diff --git a/src/global.h b/src/global.h index f1ac09c..b8b9bcb 100644 --- a/src/global.h +++ b/src/global.h @@ -1,11 +1,14 @@ #pragma once +#define __STDC_WANT_LIB_EXT1__ 1 +#include +#include +#include +#include #include #include -#include #include #include -#include #include #include "debug.h" diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index afd2f62..b7a90ba 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -78,10 +78,12 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) { } void MainWindow::compose() { + //todo: invalidate layout when adding sessions with window open //We need dynamically added child widgets to expand so that we know their height /* * Setting correct widget widths and heights */ + log_to_file_simple("[Compose]\n"); screen = this->getCurrentScreen(); log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString()); @@ -106,9 +108,9 @@ void MainWindow::compose() { log_debugcpp("epw loop"); log_debugcpp("epw roles: " + std::to_string(epw->getEndpointHandler()->getRoles())); //std::bitset content = - print_as_binary(8, uint8_t, (epw->getEndpointHandler()->getRoles())); + //print_as_binary(8, uint8_t, (epw->getEndpointHandler()->getRoles())); //log_debugcpp(content); - varToBitset(epw->getEndpointHandler()->getRoles()); + //varToBitset(epw->getEndpointHandler()->getRoles()); } /* @@ -160,7 +162,9 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) widgetLayout = new QHBoxLayout(this); //widgetLayout->setSizeConstraint(QLayout::SetFixedSize); widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); - widgetLayout->setContentsMargins(0, 10, 0, 10); + int left = 0, top = 0, right = 0, bottom = 0; + widgetLayout->getContentsMargins(&left, &top, &right, &bottom); + widgetLayout->setContentsMargins(0, top, 0, bottom); muteButton = new QCheckBox(this); mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this); @@ -236,7 +240,19 @@ void SessionWidget::calculateSize(uint64_t width, uint64_t height) { this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/32th 1080p*/); //this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/16 1080p*/); this->mainSlider->setMinimumWidth((int)(width * 0.30) /*1/16 1080p*/); - widthSpacer->changeSize((int)width * 0.20, 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/); + widthSpacer->changeSize((int)(width * 0.20), 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/); + + log_to_file("\t[Session %s sizes]\n", converter.to_bytes(this->getName()).c_str()); + log_to_file("\tMain label Maximum size: %d, %d \n", mainLabel->maximumWidth(), mainLabel->maximumHeight()); + log_to_file("\tMain label Minimum size: %d, %d \n", mainLabel->minimumWidth(), mainLabel->minimumHeight()); + log_to_file("\tMute btn Maximum width: %d \n", muteButton->maximumWidth()); + log_to_file("\tMute btn Minimum width: %d \n", muteButton->minimumWidth()); + log_to_file("\tSlider Minimum width: %d \n", mainSlider->minimumWidth()); + log_to_file("\tSpacer Minimum width: %d \n\n", widthSpacer->minimumSize().width()); +} + +std::wstring SessionWidget::getName() { + return sh->getName(); } void SessionWidget::updateMute(int checked){ @@ -257,6 +273,7 @@ SessionWidget::~SessionWidget() { ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent) : QWidget(parent){ this->eph = eph; this->channelCount = channelCount; + this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); widgetLayout = new QGridLayout(this); float volume = 100; int left = 0, top = 0, right = 0, bottom = 0; @@ -267,31 +284,30 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge * Channel sliders setup */ //uint32_t epChannelCount = eph->getChannelCount(); - for(uint32_t i = 0; i < channelCount && channelCount > 1; i++){ + for(uint64_t channel = 0, col = 0, row = 0; channel < channelCount && channelCount > 1; channel++){ QSlider* tmp = new QSlider(Qt::Horizontal); QLabel* tmpLb = new QLabel(""); - this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - //tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); tmp->setTickInterval(5); tmp->setSingleStep(1); tmp->setRange(0,100); - volume = eph->getVolume(i) * 100; + volume = eph->getVolume(channel) * 100; tmp->setValue((int) volume); tmpLb->setText(QString::number(volume)); //tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - tmp->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - tmpLb->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); + tmp->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + tmpLb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->channelSliders.push_back(tmp); this->channelLabels.push_back(tmpLb); - widgetLayout->addWidget(tmp, 0, i); - widgetLayout->addWidget(tmpLb, 1, i); + widgetLayout->addWidget(tmp, row , col); + widgetLayout->addWidget(tmpLb, row + 1, col++); + if(channel % 2 != 0) { row += 2; col = 0; } //TODO: check if there's a need to prevent deadlocks; probably this will eventually turn into its own func //this causes channel bar desync when back -> front. blocksignals below fix it. huh. - connect(tmp, &QSlider::valueChanged, [this, i](int newValue){ - this->eph->setVolume(osh->getGuid(), i, newValue); - this->channelLabels.at(i)->setText(QString::number(newValue)); + connect(tmp, &QSlider::valueChanged, [this, channel](int newValue){ + this->eph->setVolume(osh->getGuid(), channel, newValue); + this->channelLabels.at(channel)->setText(QString::number(newValue)); }); } this->setLayout(widgetLayout); @@ -314,6 +330,10 @@ void ChannelWidget::updateChannel(int channel) { this->channelSliders.at(channel)->blockSignals(false); } +uint32_t ChannelWidget::getChannelCount() const { + return channelCount; +} + EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t idx) : QWidget(parent) { //todo: based on qgridlayout, name+mute should be its own widget, same with channels row = 0; @@ -392,7 +412,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i uint32_t epChannelCount = eph->getChannelCount(); if(epChannelCount > 1) { - cw = new ChannelWidget(epChannelCount, eph, this); + cw = new ChannelWidget(epChannelCount, eph, nullptr); //cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); widgetLayout->addWidget(cw, row++, 0, 1, 4 /*colmax*/, Qt::AlignTop); } @@ -583,11 +603,17 @@ void MainWindow::reorderEndpointWidgetCollection() { void EndpointWidget::calculateSize(uint64_t width, uint64_t height) { /* og 1080p 120% testing values */ - this->mainLabel->setMaximumWidth((int)width * 0.50 /* 1080p 120%*/); - this->mainLabel->setMinimumWidth((int)width * 0.50 /* 1080p 120%*/); + log_to_file("[EndpointWidget %s sizes]\n", converter.to_bytes(this->getEndpointHandler()->getName()).c_str()); + log_to_file("Params: {Width: %u Height: %u}\n", width, height); + this->mainLabel->setMaximumWidth((int)(width * 0.50) /* 1080p 120%*/); + this->mainLabel->setMinimumWidth((int)(width * 0.50) /* 1080p 120%*/); + log_to_file("Main label width: %d \n", this->mainLabel->maximumWidth()); + if (cw) { - this->cw->setMinimumSize(QSize(1, height * 0.06)); - this->cw->setMaximumSize(QSize(QWIDGETSIZE_MAX, height * 0.06)); + this->cw->setMinimumSize(QSize(1, (height * 0.06) * (int)((cw->getChannelCount() / 2) + 0.5))); + this->cw->setMaximumSize(QSize(QWIDGETSIZE_MAX, (height * 0.06) * (int)((cw->getChannelCount() / 2) + 0.5))); + log_to_file("Channels Maximum size: %d, %d \n", cw->maximumWidth(), cw->maximumHeight()); + log_to_file("Channels Minimum size: %d, %d \n", cw->minimumWidth(), cw->minimumHeight()); } for (auto sw : sessionWidgets){ if (sw) sw->calculateSize(width, height); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index ab7b7e3..524c7bb 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -87,7 +87,9 @@ Q_OBJECT public: SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent /* = nullptr */); ~SessionWidget(); - void calculateSize(uint64_t width, uint64_t height); + void calculateSize(uint64_t width, uint64_t height); + std::wstring getName(); + public slots: void updateMainVolume(int newValue); void updateMute(int checked); @@ -111,7 +113,8 @@ public: //QSize minimumSizeHint() const override; //void setMinimum(QSize minimum); void updateChannel(int channel); - + uint32_t getChannelCount() const; + private: const double roundingFactor = 0.005; EndpointHandler* eph; diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index 19f3491..7f953c0 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -6,6 +6,7 @@ #include #include //#include "contclasses.h" +#define INIT_FILELOG #include "qtclasses.h" #include "global.h" @@ -31,10 +32,24 @@ QLocalServer* startSingleInstanceServer(QString appName) { return server; } +void closeDebugFileLog() { + close_file_log_buffer(); +} + +/* set_terminate + * void closeDebugFileLog2() { + * close_file_log_buffer(); + * abort(); + * } + */ + int main (int argc, char* argv[]) { //QApplication::setStyle("windowsvista"); //Check if running //https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running + initialize_file_log(); + atexit(closeDebugFileLog); + //std::set_terminate(closeDebugFileLog2); if (!isSingleInstanceRunning("Mixer")) startSingleInstanceServer("Mixer"); else exit(0);