From 52c653fd4ddb16f460ff36c509c0c88850cc6c25 Mon Sep 17 00:00:00 2001 From: Or Shalom Dvori Date: Sat, 14 Sep 2024 23:16:06 +0300 Subject: [PATCH 1/2] Fixed a bug in the integrate function, that was caused by warning fixes session. --- plugins/Xpressive/ExprSynth.cpp | 41 ++++++++++++++++++++++----------- plugins/Xpressive/Xpressive.cpp | 17 +++++++------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/plugins/Xpressive/ExprSynth.cpp b/plugins/Xpressive/ExprSynth.cpp index c48b94ec8dc..cf27a57d09e 100644 --- a/plugins/Xpressive/ExprSynth.cpp +++ b/plugins/Xpressive/ExprSynth.cpp @@ -83,6 +83,7 @@ struct IntegrateFunction : public exprtk::ifunction IntegrateFunction(const unsigned int* frame, unsigned int sample_rate,unsigned int max_counters) : exprtk::ifunction(1), + m_first_value(0), m_frame(frame), m_sample_rate(sample_rate), m_max_counters(max_counters), @@ -96,15 +97,26 @@ struct IntegrateFunction : public exprtk::ifunction inline T operator()(const T& x) override { - if (*m_frame == 0) + if (m_frame) { - ++m_nCountersCalls; - if (m_nCountersCalls > m_max_counters) - { - return 0; - } - m_cc = m_nCounters; - ++m_nCounters; + if (m_nCountersCalls == 0) + { + m_first_value = *m_frame; + } + if (m_first_value == *m_frame) + { + ++m_nCountersCalls; + if (m_nCountersCalls > m_max_counters) + { + return 0; + } + m_cc = m_nCounters; + ++m_nCounters; + } + else // we moved to the next frame + { + m_frame = 0; // this will indicate that we are no longer in init phase. + } } T res = 0; @@ -116,12 +128,15 @@ struct IntegrateFunction : public exprtk::ifunction m_cc = (m_cc + 1) % m_nCountersCalls; return res / m_sample_rate; } - - const unsigned int* const m_frame; + unsigned int m_first_value; + const unsigned int* m_frame; const unsigned int m_sample_rate; - const unsigned int m_max_counters; - unsigned int m_nCounters; - unsigned int m_nCountersCalls; + // number of counters allocated + const unsigned int m_max_counters; + // number of integrate instances that has counters allocated + unsigned int m_nCounters; + // real number of integrate instances + unsigned int m_nCountersCalls; unsigned int m_cc; double *m_counters; }; diff --git a/plugins/Xpressive/Xpressive.cpp b/plugins/Xpressive/Xpressive.cpp index 23a76b22820..ebf8ec5f708 100644 --- a/plugins/Xpressive/Xpressive.cpp +++ b/plugins/Xpressive/Xpressive.cpp @@ -553,7 +553,7 @@ void XpressiveView::expressionChanged() { ExprFront expr(text.constData(),sample_rate); float t=0; const float f=10,key=5,v=0.5; - unsigned int i; + unsigned int frame_counter = 0; expr.add_variable("t", t); if (m_output_expr) @@ -572,20 +572,21 @@ void XpressiveView::expressionChanged() { expr.add_cyclic_vector("W2",e->graphW2().samples(),e->graphW2().length()); expr.add_cyclic_vector("W3",e->graphW3().samples(),e->graphW3().length()); } - expr.setIntegrate(&i,sample_rate); + expr.setIntegrate(&frame_counter,sample_rate); expr.add_constant("srate",sample_rate); const bool parse_ok=expr.compile(); if (parse_ok) { e->exprValid().setValue(0); - const auto length = static_cast(m_raw_graph->length()); + const unsigned int length = static_cast(m_raw_graph->length()); auto const samples = new float[length]; - for (auto i = std::size_t{0}; i < length; i++) { - t = i / (float) length; - samples[i] = expr.evaluate(); - if (std::isinf(samples[i]) != 0 || std::isnan(samples[i]) != 0) - samples[i] = 0; + // frame_counter's reference is used in the integrate function. + for ( frame_counter = 0; frame_counter < length; ++frame_counter) { + t = frame_counter / (float) length; + samples[frame_counter] = expr.evaluate(); + if (std::isinf(samples[frame_counter]) != 0 || std::isnan(samples[frame_counter]) != 0) + samples[frame_counter] = 0; } m_raw_graph->setSamples(samples); delete[] samples; From 399769bffd149e599df61b6716f8ca80ebe5e1e6 Mon Sep 17 00:00:00 2001 From: Or Shalom Dvori Date: Sun, 27 Oct 2024 20:07:17 +0200 Subject: [PATCH 2/2] Xpressive - fixed code style issues. --- plugins/Xpressive/ExprSynth.cpp | 66 ++++++++++++++++----------------- plugins/Xpressive/Xpressive.cpp | 21 ++++++----- 2 files changed, 45 insertions(+), 42 deletions(-) diff --git a/plugins/Xpressive/ExprSynth.cpp b/plugins/Xpressive/ExprSynth.cpp index cf27a57d09e..e6783211d8e 100644 --- a/plugins/Xpressive/ExprSynth.cpp +++ b/plugins/Xpressive/ExprSynth.cpp @@ -83,10 +83,10 @@ struct IntegrateFunction : public exprtk::ifunction IntegrateFunction(const unsigned int* frame, unsigned int sample_rate,unsigned int max_counters) : exprtk::ifunction(1), - m_first_value(0), + m_firstValue(0), m_frame(frame), - m_sample_rate(sample_rate), - m_max_counters(max_counters), + m_sampleRate(sample_rate), + m_maxCounters(max_counters), m_nCounters(0), m_nCountersCalls(0), m_cc(0) @@ -97,26 +97,26 @@ struct IntegrateFunction : public exprtk::ifunction inline T operator()(const T& x) override { - if (m_frame) + if (m_frame) { - if (m_nCountersCalls == 0) - { - m_first_value = *m_frame; - } - if (m_first_value == *m_frame) - { - ++m_nCountersCalls; - if (m_nCountersCalls > m_max_counters) - { - return 0; - } - m_cc = m_nCounters; - ++m_nCounters; - } - else // we moved to the next frame - { - m_frame = 0; // this will indicate that we are no longer in init phase. - } + if (m_nCountersCalls == 0) + { + m_firstValue = *m_frame; + } + if (m_firstValue == *m_frame) + { + ++m_nCountersCalls; + if (m_nCountersCalls > m_maxCounters) + { + return 0; + } + m_cc = m_nCounters; + ++m_nCounters; + } + else // we moved to the next frame + { + m_frame = 0; // this will indicate that we are no longer in init phase. + } } T res = 0; @@ -126,17 +126,17 @@ struct IntegrateFunction : public exprtk::ifunction m_counters[m_cc] += x; } m_cc = (m_cc + 1) % m_nCountersCalls; - return res / m_sample_rate; - } - unsigned int m_first_value; - const unsigned int* m_frame; - const unsigned int m_sample_rate; - // number of counters allocated - const unsigned int m_max_counters; - // number of integrate instances that has counters allocated - unsigned int m_nCounters; - // real number of integrate instances - unsigned int m_nCountersCalls; + return res / m_sampleRate; + } + unsigned int m_firstValue; + const unsigned int* m_frame; + const unsigned int m_sampleRate; + // number of counters allocated + const unsigned int m_maxCounters; + // number of integrate instances that has counters allocated + unsigned int m_nCounters; + // real number of integrate instances + unsigned int m_nCountersCalls; unsigned int m_cc; double *m_counters; }; diff --git a/plugins/Xpressive/Xpressive.cpp b/plugins/Xpressive/Xpressive.cpp index ebf8ec5f708..5ee7dcf8d89 100644 --- a/plugins/Xpressive/Xpressive.cpp +++ b/plugins/Xpressive/Xpressive.cpp @@ -553,7 +553,7 @@ void XpressiveView::expressionChanged() { ExprFront expr(text.constData(),sample_rate); float t=0; const float f=10,key=5,v=0.5; - unsigned int frame_counter = 0; + unsigned int frame_counter = 0; expr.add_variable("t", t); if (m_output_expr) @@ -572,21 +572,24 @@ void XpressiveView::expressionChanged() { expr.add_cyclic_vector("W2",e->graphW2().samples(),e->graphW2().length()); expr.add_cyclic_vector("W3",e->graphW3().samples(),e->graphW3().length()); } - expr.setIntegrate(&frame_counter,sample_rate); + expr.setIntegrate(&frame_counter,sample_rate); expr.add_constant("srate",sample_rate); const bool parse_ok=expr.compile(); if (parse_ok) { e->exprValid().setValue(0); - const unsigned int length = static_cast(m_raw_graph->length()); + const unsigned int length = static_cast(m_raw_graph->length()); auto const samples = new float[length]; - // frame_counter's reference is used in the integrate function. - for ( frame_counter = 0; frame_counter < length; ++frame_counter) { - t = frame_counter / (float) length; - samples[frame_counter] = expr.evaluate(); - if (std::isinf(samples[frame_counter]) != 0 || std::isnan(samples[frame_counter]) != 0) - samples[frame_counter] = 0; + // frame_counter's reference is used in the integrate function. + for (frame_counter = 0; frame_counter < length; ++frame_counter) + { + t = frame_counter / (float) length; + samples[frame_counter] = expr.evaluate(); + if (std::isinf(samples[frame_counter]) != 0 || std::isnan(samples[frame_counter]) != 0) + { + samples[frame_counter] = 0; + } } m_raw_graph->setSamples(samples); delete[] samples;