From cc1cffed9f676ccc63d1883126df147a424aa7ea Mon Sep 17 00:00:00 2001
From: Marek Blok <Marek.Blok@pg.edu.pl>
Date: Tue, 28 Nov 2023 22:08:36 +0100
Subject: [PATCH] DSP::u::Switch fix

---
 CHANGELOG               | 14 ++++++++
 src/cpp/DSP_modules.cpp | 77 +++--------------------------------------
 src/include/DSP_lib.h   |  2 +-
 3 files changed, 20 insertions(+), 73 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 1a9a251..15a862b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,15 @@
 TODO::
+- BUG: When sources or multirate blocks are added after DSP::Clock::Execute have been called the can be out of sync with global and local clock cycles
+    resulting in error stating that there are no signal activated clock but there are still block that cannot be processed.
+    \note: Basic solution is to call DSP::Clock::Execute for number of global clock cycles that are an integer multiply of concerned local clock cycles,
+    so the added sources and blocks are in sync with local clock cycles. Nonetheless, it can be difficult to find the correct number of clock or it can be to high to be of practical use.
+    \todo: derive concept for adding new sources, blocks and clock with synch with current glocal clock cycle
+      - add virtual method of component: init based on clock cycle
+        - optionally generate warning of clock's cycle mismatch on block/compoment's creation
+      - check if created clocks operate based only on global clock cycle or on their own cycle counter
+      - consider adding clocks generation with selected clock cycle offset or funcion for setting clocks cycle offset after its creation
+        (can be useful in some multirate scenarios like polyphase structures)
+
 - BUG: When block connected to the output od the autosplitter is deleted number of autosplitter outputs is not reduced.
   - the new block connected to the output connected to this autospliter generates new autospliter output
   - [DONE: ver. 0.20.032] minimal correction: reuse unconnected autospliter outputs when new block is connected
@@ -6,6 +17,7 @@ TODO::
     - 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)
+- BUG "Info(  Number of components): 1c" and similar print out numbers in hex (check switching: std::dec/std::hex)
 - 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
@@ -17,6 +29,8 @@ TODO::
 LAST DONE:
 
 CHANGES:
+- ver. 0.20.035 <b>2023.11.28</b> Fixed:
+  - DSP::u::Switch - inputs were incorrectly defined as ouputs.
 - 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.
diff --git a/src/cpp/DSP_modules.cpp b/src/cpp/DSP_modules.cpp
index 605499d..9b05af1 100644
--- a/src/cpp/DSP_modules.cpp
+++ b/src/cpp/DSP_modules.cpp
@@ -5193,9 +5193,6 @@ DSP::u::Switch::~Switch(void)
 void DSP::u::Switch::Init(bool IsInputComplex,
     unsigned int InputsNo, unsigned int OutputsNo)
 {
-  unsigned int ind;
-  std::string temp;
-
   SetName("Switch", false);
 
   if (IsInputComplex == false)
@@ -5215,80 +5212,16 @@ void DSP::u::Switch::Init(bool IsInputComplex,
   LastInputInd=ValuesPerOutput*InputsNo-1; //index starts from 0
   InputSelectionInd = DSP::FO_NoInput;
   OutputSelectionInd = DSP::FO_NoOutput;
-  /*
-  if (UseSelectorInputs == true)
-  {
-    if ((InputsNo==1) || (OutputsNo==1))
-    {
-      SetNoOfInputs(ValuesPerOutput*InputsNo+1,false);
-      if (OutputsNo==1)
-      {
-        InputSelectionInd=ValuesPerOutput*InputsNo;
-        DefineOutput("input_selector", ValuesPerOutput*InputsNo);
-      }
-      else
-      {
-        OutputSelectionInd=ValuesPerOutput*InputsNo;
-        DefineOutput("output_selector", OutputSelectionInd);
-      }
-    }
-    else
-    {
-      InputSelectionInd=ValuesPerOutput*InputsNo;
-      OutputSelectionInd=ValuesPerOutput*InputsNo+1;
-      SetNoOfInputs(ValuesPerOutput*InputsNo+2,false);
-      DefineOutput("input_selector", InputSelectionInd);
-      DefineOutput("output_selector", OutputSelectionInd);
-    }
-  }
-  else
-  {
-*/
-    SetNoOfInputs(ValuesPerOutput*InputsNo,false);
-/*  } */
+
+  SetNoOfInputs(ValuesPerOutput*InputsNo,false);
+
   SelectedInputNo  = DSP::FO_NoInput;
   SelectedOutputNo = DSP::FO_NoOutput;
   MaxSelectedInputNo=InputsNo-1;
   MaxSelectedOutputNo=OutputsNo-1;
 
-  if (IsInputComplex == false)
-  {
-    for (ind=0; ind<InputsNo; ind++)
-    {
-      temp = "in" + std::to_string(ind+1);
-      DefineOutput(temp, ind);
-      temp = "in" + std::to_string(ind+1) + ".re";
-      DefineOutput(temp, ind);
-    }
-    for (ind=0; ind<OutputsNo; ind++)
-    {
-      temp = "out" + std::to_string(ind+1);
-      DefineOutput(temp, ind);
-      temp = "out" + std::to_string(ind+1) + ".re";
-      DefineOutput(temp, ind);
-    }
-  }
-  else
-  {
-    for (ind=0; ind<InputsNo; ind++)
-    {
-      temp = "in" + std::to_string(ind+1);
-      DefineOutput(temp, 2*ind, 2*ind+1);
-      temp = "in" + std::to_string(ind+1) + ".re";
-      DefineOutput(temp, 2*ind);
-      temp = "in" + std::to_string(ind+1) + ".im";
-      DefineOutput(temp, 2*ind+1);
-    }
-    for (ind=0; ind<OutputsNo; ind++)
-    {
-      temp = "out" + std::to_string(ind+1);
-      DefineOutput(temp, 2*ind, 2*ind+1);
-      temp = "out" + std::to_string(ind+1) + ".re";
-      DefineOutput(temp, 2*ind);
-      temp = "out" + std::to_string(ind+1) + ".im";
-      DefineOutput(temp, 2*ind+1);
-    }
-  }
+  DefineStandardInputs(IsInputComplex);
+  DefineStandardOutputs(IsInputComplex);
 
   ClockGroups.AddInputs2Group("all", 0, NoOfInputs-1);
   ClockGroups.AddOutputs2Group("all", 0, NoOfOutputs-1);
diff --git a/src/include/DSP_lib.h b/src/include/DSP_lib.h
index 3df269b..6570d93 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 33 // !!! without zeroes before, else this will be treated as octal number
+#define DSP_VER_BUILD 34 // !!! 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