From: Clyne Sullivan Date: Mon, 23 May 2022 04:45:34 +0000 (-0800) Subject: Merge branch 'windows' into devel X-Git-Tag: v0.1^2~3 X-Git-Url: https://code.bitgloo.com/?a=commitdiff_plain;h=93c41469829e339df9732f290dd0941bc91acefb;p=clyne%2Fstmdspgui.git Merge branch 'windows' into devel --- 93c41469829e339df9732f290dd0941bc91acefb diff --cc Makefile index 81e580d,6b85111..dc62d10 --- a/Makefile +++ b/Makefile @@@ -1,20 -1,27 +1,30 @@@ -#linux: CXXFILES += source/serial/src/impl/unix.cc source/serial/src/impl/list_ports/list_ports_unix.cc -#linux: LDFLAGS = -lSDL2 -lGL -lpthread - -#CROSS = x86_64-w64-mingw32- -#CXX = $(CROSS)g++ + CXX = g++ + CXXFILES := \ source/serial/src/serial.cc \ - source/serial/src/impl/unix.cc \ - source/serial/src/impl/list_ports/list_ports_linux.cc \ - source/serial/src/impl/win.cc \ - source/serial/src/impl/list_ports/list_ports_win.cc \ $(wildcard source/imgui/backends/*.cpp) \ $(wildcard source/imgui/*.cpp) \ $(wildcard source/stmdsp/*.cpp) \ $(wildcard source/*.cpp) --OFILES := $(patsubst %.cc, %.o, $(patsubst %.cpp, %.o, $(CXXFILES))) -OUTPUT := stmdspgui.exe - + CXXFLAGS := -std=c++20 -O2 \ + -Isource -Isource/imgui -Isource/stmdsp -Isource/serial/include \ - -Wall -Wextra -pedantic \ - -DSTMDSP_WIN32 -Wa,-mbig-obj -DSTMDSP_DISABLE_FORMULAS ++ -Wall -Wextra -pedantic #-DSTMDSP_DISABLE_FORMULAS ++ ++ifeq ($(OS),Windows_NT) ++CXXFILES += source/serial/src/impl/win.cc \ ++ source/serial/src/impl/list_ports/list_ports_win.cc ++CXXFLAGS += -DSTMDSP_WIN32 -Wa,-mbig-obj + LDFLAGS = -mwindows -lSDL2 -lopengl32 -lsetupapi -lole32 ++OUTPUT := stmdspgui.exe ++else ++CXXFILES += source/serial/src/impl/unix.cc \ ++ source/serial/src/impl/list_ports/list_ports_unix.cc ++LDFLAGS = -lSDL2 -lGL -lpthread +OUTPUT := stmdspgui ++endif + - #CXXFLAGS := -std=c++20 -O2 \ - # -Isource -Isource/imgui -Isource/stmdsp -Isource/serial/include - CXXFLAGS := -std=c++20 -ggdb -O0 -g3 \ - -Isource -Isource/imgui -Isource/stmdsp -Isource/serial/include \ - -Wall -Wextra -pedantic ++OFILES := $(patsubst %.cc, %.o, $(patsubst %.cpp, %.o, $(CXXFILES))) all: $(OUTPUT) diff --cc source/device.cpp index 60b1bc9,edd950c..9c50a0d --- a/source/device.cpp +++ b/source/device.cpp @@@ -136,10 -122,20 +138,10 @@@ static void drawSamplesTask(std::shared logSamplesFile << s << '\n'; } } else { - // Device must be busy, cooldown. - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + // Device must be busy, back off for a bit. + std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - if (drawSamplesInput) { - if (lockDevice.try_lock_for(std::chrono::milliseconds(1))) { - const auto chunk2 = tryReceiveChunk(device, - std::mem_fn(&stmdsp::device::continuous_read_input)); - lockDevice.unlock(); - - addToQueue(drawSamplesInputQueue, chunk2); - } - } - std::this_thread::sleep_until(next); } } @@@ -431,9 -417,14 +433,13 @@@ void deviceGenLoadFormula(const std::st std::size_t pullFromQueue( std::deque& queue, -- CircularBuffer& circ, -- double timeframe) ++ CircularBuffer& circ) { + // We know how big the circular buffer should be to hold enough samples to + // fill the current draw samples view. + // If the given buffer does not match this size, notify the caller. + // TODO this could be done better... drawSamplesBufferSize should be a GUI- + // only thing. if (circ.size() != drawSamplesBufferSize) return drawSamplesBufferSize; @@@ -449,17 -448,21 +463,19 @@@ return 0; } + /** + * Pulls a render frame's worth of samples from the draw samples queue, adding + * the samples to the given buffer. + */ std::size_t pullFromDrawQueue( -- CircularBuffer& circ, -- double timeframe) ++ CircularBuffer& circ) { -- return pullFromQueue(drawSamplesQueue, circ, timeframe); ++ return pullFromQueue(drawSamplesQueue, circ); } std::size_t pullFromInputDrawQueue( -- CircularBuffer& circ, -- double timeframe) ++ CircularBuffer& circ) { -- return pullFromQueue(drawSamplesInputQueue, circ, timeframe); ++ return pullFromQueue(drawSamplesInputQueue, circ); } diff --cc source/gui.cpp index 0e67446,80120c4..43c95df --- a/source/gui.cpp +++ b/source/gui.cpp @@@ -40,8 -42,8 +40,8 @@@ bool guiInitialize( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); window = SDL_CreateWindow("stmdsp gui", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - 550, 700, - WINDOW_WIDTH, WINDOW_HEIGHT, - SDL_WINDOW_OPENGL /*| SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI*/); ++ 640, 700, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE /*| SDL_WINDOW_ALLOW_HIGHDPI*/); if (window == nullptr) { puts("Error: Could not create the window!"); diff --cc source/gui_device.cpp index f846414,43c0a58..689ef54 --- a/source/gui_device.cpp +++ b/source/gui_device.cpp @@@ -24,15 -24,14 +24,13 @@@ void deviceLoadAudioFile(const std::str void deviceLoadLogFile(const std::string& file); void deviceSetSampleRate(unsigned int index); void deviceSetInputDrawing(bool enabled); -void deviceStart(bool measureCodeTime, bool logResults, bool drawSamples); +void deviceStart(bool logResults, bool drawSamples); +void deviceStartMeasurement(); void deviceUpdateDrawBufferSize(double timeframe); std::size_t pullFromDrawQueue( -- CircularBuffer& circ, -- double timeframe); ++ CircularBuffer& circ); std::size_t pullFromInputDrawQueue( -- CircularBuffer& circ, -- double timeframe); ++ CircularBuffer& circ); static std::string sampleRatePreview = "?"; static bool measureCodeTime = false; @@@ -319,19 -311,19 +317,19 @@@ void deviceRenderDraw( yMinMax = std::min(4095u, (yMinMax << 1) | 1); } -- auto newSize = pullFromDrawQueue(bufferCirc, drawSamplesTimeframe); ++ auto newSize = pullFromDrawQueue(bufferCirc); if (newSize > 0) { buffer.resize(newSize); bufferCirc = CircularBuffer(buffer); -- pullFromDrawQueue(bufferCirc, drawSamplesTimeframe); ++ pullFromDrawQueue(bufferCirc); } if (drawSamplesInput) { -- auto newSize = pullFromInputDrawQueue(bufferInputCirc, drawSamplesTimeframe); ++ auto newSize = pullFromInputDrawQueue(bufferInputCirc); if (newSize > 0) { bufferInput.resize(newSize); bufferInputCirc = CircularBuffer(bufferInput); -- pullFromInputDrawQueue(bufferInputCirc, drawSamplesTimeframe); ++ pullFromInputDrawQueue(bufferInputCirc); } } diff --cc source/main.cpp index f913cf1,d6277b7..e0d893e --- a/source/main.cpp +++ b/source/main.cpp @@@ -44,10 -45,9 +44,10 @@@ static LogView logView static ImFont *fontSans = nullptr; static ImFont *fontMono = nullptr; +template static void renderWindow(); - int main(int, char **) + int main(int argc, char *argv[]) { if (!guiInitialize()) return -1;