From b20def6516f43034b6eb843ab757529330895011 Mon Sep 17 00:00:00 2001 From: ak5k <42914711+ak5k@users.noreply.github.com> Date: Thu, 23 Dec 2021 03:36:41 +0200 Subject: [PATCH] dev --- CMakeLists.txt | 17 +++++++++++++---- scripts/ReaBlink_Monitor.lua | 4 ++++ source/reablink/BlinkEngine.cpp | 8 ++++++-- source/reablink/BlinkEngine.hpp | 7 ++++--- source/reablink/ReaBlink.cpp | 18 +++++++++++++++++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88d9703..b189fa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,10 +16,19 @@ if(NOT EXISTS ${PROJECT_SOURCE_DIR}/vendor/reaper-sdk/WDL) find_package(Git QUIET) execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) - file(CREATE_LINK - ${PROJECT_SOURCE_DIR}/vendor/WDL/WDL - ${PROJECT_SOURCE_DIR}/vendor/reaper-sdk/WDL - SYMBOLIC) + if(NOT CMAKE_SYSTEM_NAME MATCHES Windows) + file(CREATE_LINK + ${PROJECT_SOURCE_DIR}/vendor/WDL/WDL + ${PROJECT_SOURCE_DIR}/vendor/reaper-sdk/WDL + SYMBOLIC) + else() + file(COPY + ${PROJECT_SOURCE_DIR}/vendor/WDL/WDL + DESTINATION + ${PROJECT_SOURCE_DIR}/vendor/reaper-sdk/ + ) + endif(NOT CMAKE_SYSTEM_NAME MATCHES Windows) + endif() if (CMAKE_SYSTEM_NAME MATCHES Windows) diff --git a/scripts/ReaBlink_Monitor.lua b/scripts/ReaBlink_Monitor.lua index 8002f12..9b4ce2d 100644 --- a/scripts/ReaBlink_Monitor.lua +++ b/scripts/ReaBlink_Monitor.lua @@ -1,6 +1,10 @@ header = "enabled | num peers | quantum | start stop sync | tempo | beats(QN) | metro\n" gfx.init("ReaBlink Monitor", 640, 32) +if reaper.GetToggleCommandState(40531) ~= 0 then + reaper.Main_OnCommand(40531,0) +end + if not reaper.Blink_GetEnabled() then reaper.Blink_SetEnabled(true) end diff --git a/source/reablink/BlinkEngine.cpp b/source/reablink/BlinkEngine.cpp index a686c00..66e0779 100644 --- a/source/reablink/BlinkEngine.cpp +++ b/source/reablink/BlinkEngine.cpp @@ -292,8 +292,8 @@ void BlinkEngine::AudioCallback(const std::chrono::microseconds& hostTime) (host_start_time.count() - session_start_time.count()) / 1.0e6; frameCountDown++; timepos += startOffset; + std::thread(OnStopButton).detach(); std::thread([timepos]() { - OnStopButton(); SetEditCurPos(timepos, false, true); }).detach(); } @@ -437,7 +437,10 @@ void BlinkEngine::AudioCallback(const std::chrono::microseconds& hostTime) !engineData.isMaster && sessionState.isPlaying() && playbackFrameCount > playbackFrameSafe && diff > syncTolerance && diff < qLen - ceil((frameTime.count() / 1.0e3) * 2)) { - syncCorrection = true; + if (syncCorrection == false) { + syncTolerance--; + syncCorrection = true; + } if (hostBeat - sessionBeat > 0) { // slow_down std::thread([]() { Main_OnCommand(40525, 0); }).detach(); @@ -450,6 +453,7 @@ void BlinkEngine::AudioCallback(const std::chrono::microseconds& hostTime) else if (syncCorrection) { std::thread(Main_OnCommand, 40521, 0).detach(); syncCorrection = false; + syncTolerance++; } } diff --git a/source/reablink/BlinkEngine.hpp b/source/reablink/BlinkEngine.hpp index 97cc046..0cb53ba 100644 --- a/source/reablink/BlinkEngine.hpp +++ b/source/reablink/BlinkEngine.hpp @@ -5,8 +5,9 @@ // Make sure to define this before is included for Windows #define _USE_MATH_DEFINES #define ASIO_NO_EXCEPTIONS -// #define htonll(x) (((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32)) -// #define ntohll(x) (((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32)) +// #define htonll(x) (((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> +// 32)) #define ntohll(x) (((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) +// >> 32)) #endif #include @@ -128,7 +129,7 @@ class BlinkEngine { static constexpr auto beatTolerance = 0.02; static constexpr auto playbackFrameSafe = 16; - static constexpr auto syncTolerance = 3; + int syncTolerance = 3; static constexpr auto tempoTolerance = 0.005; std::mutex m; diff --git a/source/reablink/ReaBlink.cpp b/source/reablink/ReaBlink.cpp index 9d0cf45..a354e52 100644 --- a/source/reablink/ReaBlink.cpp +++ b/source/reablink/ReaBlink.cpp @@ -432,6 +432,22 @@ bool runCommand(int command, int flag) res = true; startStop(); } + if (command == 40073) { + res = true; + startStop(); + } + if (command == 1007) { + res = true; + startStop(); + } + if (command == 1008) { + res = true; + startStop(); + } + if (command == 1016) { + res = true; + blinkEngine.StopPlaying(); + } if (command == 41130) { res = true; const auto tempo = GetTempo(); @@ -458,7 +474,7 @@ void SetCaptureTransportCommands(bool enable) } const char* defstring_SetCaptureTransportCommands = "void\0bool\0enable\0" - "Captures REAPER 'Transport: Play/stop' and 'Tempo: Increase/Decrease " + "Captures REAPER Transport commands and 'Tempo: Increase/Decrease " "current project tempo by 01 BPM' commands and broadcasts them into Link " "session. When used with Master or Puppet mode enabled, provides better " "integration between REAPER and Link session transport and tempos.";