]> code.bitgloo.com Git - clyne/stmdspgui.git/commitdiff
Merge branch 'windows' into devel
authorClyne Sullivan <clyne@bitgloo.com>
Mon, 23 May 2022 04:45:34 +0000 (20:45 -0800)
committerClyne Sullivan <clyne@bitgloo.com>
Mon, 23 May 2022 04:45:34 +0000 (20:45 -0800)
1  2 
Makefile
source/device.cpp
source/gui.cpp
source/gui_device.cpp
source/main.cpp
source/stmdsp/stmdsp.cpp

diff --cc Makefile
index 81e580d2162b48a0af44f7a2ac11b25cfec113c9,6b8511133d6e7a0b43d3bbfb81983eda19c5fd24..dc62d10d41443b8420d5520c961e33ccefd43fde
+++ 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)
  
index 60b1bc9a0cc79099986651e3b0b4ba7b1c8dc756,edd950c1b7caf3cab8286bb2980808465b8102cb..9c50a0df08c7305e955e16352b269f38ac7ab824
@@@ -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<stmdsp::dacsample_t>& queue,
--    CircularBuffer<std::vector, stmdsp::dacsample_t>& circ,
--    double timeframe)
++    CircularBuffer<std::vector, stmdsp::dacsample_t>& 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;
  
      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<std::vector, stmdsp::dacsample_t>& circ,
--    double timeframe)
++    CircularBuffer<std::vector, stmdsp::dacsample_t>& circ)
  {
--    return pullFromQueue(drawSamplesQueue, circ, timeframe);
++    return pullFromQueue(drawSamplesQueue, circ);
  }
  
  std::size_t pullFromInputDrawQueue(
--    CircularBuffer<std::vector, stmdsp::dacsample_t>& circ,
--    double timeframe)
++    CircularBuffer<std::vector, stmdsp::dacsample_t>& circ)
  {
--    return pullFromQueue(drawSamplesInputQueue, circ, timeframe);
++    return pullFromQueue(drawSamplesInputQueue, circ);
  }
  
diff --cc source/gui.cpp
index 0e6744647294c5b5d77ab17eaba27e4d78bd393d,80120c47d56b729a353c5fa1386be6b9f4950a69..43c95df429f8d44929e1e22a31fa04e279b735f1
@@@ -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!");
index f846414d1766991677b77d8762de966e76712f72,43c0a581bae35a1c4c8c0dea35ad03c209db3074..689ef54044edf2419950c0501135293b4fd20ba0
@@@ -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<std::vector, stmdsp::dacsample_t>& circ,
--    double timeframe);
++    CircularBuffer<std::vector, stmdsp::dacsample_t>& circ);
  std::size_t pullFromInputDrawQueue(
--    CircularBuffer<std::vector, stmdsp::dacsample_t>& circ,
--    double timeframe);
++    CircularBuffer<std::vector, stmdsp::dacsample_t>& 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 f913cf148ced358aa18f64749bd5c09fc85bf03b,d6277b7c6296bd67a454e2173f70e1afb57d5d3d..e0d893e1a50ae8f1088a9e7d930114f209e37962
@@@ -44,10 -45,9 +44,10 @@@ static LogView logView
  static ImFont *fontSans = nullptr;
  static ImFont *fontMono = nullptr;
  
 +template<bool first = false>
  static void renderWindow();
  
- int main(int, char **)
+ int main(int argc, char *argv[])
  {
      if (!guiInitialize())
          return -1;
Simple merge