From d4b8937fdf07925d684f5955cfd457ff8a5cf225 Mon Sep 17 00:00:00 2001
From: Marek Blok <Marek.Blok@pg.edu.pl>
Date: Sat, 11 Nov 2023 23:35:14 +0100
Subject: [PATCH] DSP::u::OutputBuffer ParentClock check

---
 CHANGELOG               |  7 ++++++-
 src/cpp/DSP_IO.cpp      | 10 ++++++++++
 src/cpp/DSP_modules.cpp |  7 ++++++-
 src/include/DSP_lib.h   |  2 +-
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index fb8f48a..1a9a251 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ TODO::
   - best correction: remove unconnected autospliter outputs when its output block is deleted (or its output is freed)
     - TODO: create minimal example: source => two output blocks : delete one and check scheme for Noname blocks before reconnection
     - NOTE: if the last output of autosplitter is cleared the autospliter block should be deleted also.
+- BUG (minor): DSP::Component::GetHtmlNodeLabel_DOTfile should not add '\\' before space (at least). New nodes drawing doend't need escaping (needs more tests)
 - DSP::u::Zeroinserter => add variant with possibility to define number of inputs
 
   SOUND_support_t::get_wave_in_raw_buffer - zastąpić metodą zawierającą konwersję typu, ew. rozbudować konwersję w DSP::u::AudioInput
@@ -16,7 +17,11 @@ TODO::
 LAST DONE:
 
 CHANGES:
-- ver. 0.20.032 <b>2023.11.11</b> Fixed:
+- ver. 0.20.033 <b>2023.11.11</b> Fixed:
+  - DSP::u::OutputBuffer - added setting OutputBuffer inputs' clocks (SetBlockInputClock) as equal to ParentClock to allow clock mismatch check when buffers ParentClock dows not match the inputs' clocks. 
+    - PROBLEM: the ParentClock match to InputClock is not checked for DSP::u::OutputBuffer which might lead user to not notice that expected NotificationClock is incorectly selected.
+      - Solution: Set OutputBuffer inputs' clocks as equal to ParentClock
+      - Note: The similar solusion can be applicable to other blocks with notification clocks and no outputs.
   - DSP::Component::AddOutputLine - can now reuse free output line instead of adding new one
     - This is minimal correction for the bug causing autospliter to have unconnected outputs after block deletion.
       The unconnected output will now be reused on new connection.
diff --git a/src/cpp/DSP_IO.cpp b/src/cpp/DSP_IO.cpp
index eefaa45..8b87ee7 100644
--- a/src/cpp/DSP_IO.cpp
+++ b/src/cpp/DSP_IO.cpp
@@ -4887,6 +4887,7 @@ DSP::u::OutputBuffer::OutputBuffer(unsigned int BufferSize_in, unsigned int NoOf
   UserData_ptr = NULL;
   UserCallbackID = (CallbackIdentifier & DSP::CallbackID_mask);
 
+  // Set OutputBuffer inputs' clocks as equal to ParentClock
   if ((ParentClock != NULL) && (func_ptr != NULL))
   {
     if (NotificationsStep > 1)
@@ -4897,6 +4898,9 @@ DSP::u::OutputBuffer::OutputBuffer(unsigned int BufferSize_in, unsigned int NoOf
     RegisterForNotification(NotificationClock);
   }
 
+  for (unsigned int ind = 0; ind < NoOfInputs; ind++)
+    SetBlockInputClock(ind, ParentClock);
+
   Execute_ptr = &InputExecute;
 
   if (NotificationFunction_ptr != NULL)
@@ -4955,6 +4959,9 @@ DSP::u::OutputBuffer::OutputBuffer(unsigned int BufferSize_in, unsigned int NoOf
     RegisterForNotification(OutputClock);
   }
 
+  for (unsigned int ind = 0; ind < NoOfInputs; ind++)
+    SetBlockInputClock(ind, ParentClock);
+
   ///////////////////////////////////////////////
   OutputsValues.clear();
   OutputsValues.resize(NoOfOutputs, 0.0);
@@ -5006,6 +5013,9 @@ DSP::u::OutputBuffer::OutputBuffer(unsigned int BufferSize_in, unsigned int NoOf
   else
     NotificationsStep = -1;
 
+  for (unsigned int ind = 0; ind < NoOfInputs; ind++)
+    SetBlockInputClock(ind, ParentClock);
+
   if (func_ptr != NULL)
   {
     IsMultiClock = false;
diff --git a/src/cpp/DSP_modules.cpp b/src/cpp/DSP_modules.cpp
index 32e5b77..605499d 100644
--- a/src/cpp/DSP_modules.cpp
+++ b/src/cpp/DSP_modules.cpp
@@ -2658,7 +2658,12 @@ void DSP::Block::SetBlockInputClock(unsigned int InputNo, DSP::Clock_ptr InputCl
     #ifdef __DEBUG__
       if (InputClocks[InputNo] != NULL)
       {
-        DSP::log << DSP::e::LogMode::Error << "Input clock has been already set" << std::endl;
+        if (InputClocks[InputNo] != InputClock) {
+          DSP::log << DSP::e::LogMode::Error << GetName() << DSP::e::LogMode::second << "Different input clock has been already set to input number " << InputNo << std::endl;
+        }
+        // else {
+        //   DSP::log << DSP::e::LogMode::Info << GetName() << DSP::e::LogMode::second << "Input clock has been already set to the same value" << std::endl;
+        // }
       }
     #endif // __DEBUG__
 
diff --git a/src/include/DSP_lib.h b/src/include/DSP_lib.h
index 303e897..3df269b 100644
--- a/src/include/DSP_lib.h
+++ b/src/include/DSP_lib.h
@@ -11,7 +11,7 @@
 
 #define DSP_VER_MAJOR 0
 #define DSP_VER_MINOR 20
-#define DSP_VER_BUILD 32 // !!! without zeroes before, else this will be treated as octal number
+#define DSP_VER_BUILD 33 // !!! without zeroes before, else this will be treated as octal number
 #define DSP_VER_YEAR  2023
 #define DSP_VER       DSP_VER_MAJOR.DSP_VER_MINOR.DSP_VER_BUILD
 
-- 
GitLab