SNEX struct and function parameter
-
@Christoph-Hart Probably a noob error, but I can't understand what I am doing wrong.
I get no warning at compile timestruct MyStruct { float x1 = 0.0f; float x2 = 0.0f; } const MyStruct BLABLA = {0.5f, 12.0f}; const MyStruct BLOBLO = {0.2f, 7.0f}; static const int LIMIT = 2; span<MyStruct, LIMIT> models = {BLABLA, BLOBLO}; float processSample(float sample, const MyStruct ¶m) { float myNewSample = sample * param.x1; // <= 0.0f, No warning return sample; // sample unchanged, as expected // But return myNewSample; // always 0.0f } // In process s = processSample(s, BLABLA);
-
Found the culprit
I was dumbly writing
const MyStruct BLUBLU = {anObject, anotherObject};
somewhere that killed the struct...
-
-
-
-
so in the same vein
struct MyStruct { float x1 = 0.0f; float x2 = 0.0f; } const MyStruct BLABLA = {0.5f, 12.0f}; const MyStruct BLOBLO = {0.2f, 7.0f}; static const int LIMIT = 2; span<MyStruct, LIMIT> models = {BLABLA, BLOBLO}; MyStruct currentModel; // will be assigned a model later using models[idx] using Idx = index::clamped<LIMIT, true>; Idx idx = 0; // Set the parameters here template <int P> void setParameter(double v) { if (P == Parameters::MyPar) { idx = (int)v; // Idx is index type, clamped currentModel = models[idx]; // WARNING unsafe index access? } }
models[idx]
throws a warning forunsafe index access
Where is it unsafe if it is clamped?While I'm here,
index::safe<0>
can't be parsed. -
@ustk
I'm just starting to use Structures,
if I find out what's up I'll let you know.
I'm only just setting up, so far got this test structure to work in my own code, although it's unrelated to yours:template <int NV> struct Germanium1 { SNEX_NODE(Germanium1); double impedance1 = 0.0f; double impedance2 = 0.0f; // Define the WDFComponent class struct WDFComponent { // Function to calculate impedance (returns the magnitude of a complex number) double calculateImpedance(double real, double imag) { // Calculate the magnitude of the complex number return Math.sqrt(real * real + imag * imag); } // Function to connect to another WDFComponent void connect(double otherComponent, double portName) { // Placeholder: This function currently does nothing } }; // Main function to test the WDFComponent class void main() { // Create an instance of WDFComponent WDFComponent component; // Test values for real and imaginary parts of a complex number double realPart1 = 3.0; double imagPart1 = 4.0; double realPart2 = 1.0; double imagPart2 = 1.0; // Calculate impedance using the test values impedance1 = component.calculateImpedance(realPart1, imagPart1); impedance2 = component.calculateImpedance(realPart2, imagPart2); // Expected output: 5.0 // Expected output: 1.41421356237 // Test the connect function (currently does nothing) component.connect(0.0, 0.0); // Print a message indicating the connect function was called Console.print("Connect function called successfully."); } // Initialise the processing specs here void prepare(PrepareSpecs ps) { // Run the main function main(); } // Reset the processing pipeline here void reset() { } // Process the signal here template <typename ProcessDataType> void process(ProcessDataType& data) { } // Process the signal as frame here template <int C> void processFrame(span<float, C>& data) { } // Process the MIDI events here void handleHiseEvent(HiseEvent& e) { } // Use this function to setup the external data void setExternalData(const ExternalData& d, int index) { } // Set the parameters here template <int P> void setParameter(double v) { } };
-
@Christoph-Hart Still having issues with
struct
and evenspan
SNEX_NODE(snex_struct); struct Params { float a = 1.0f; float b = 1.0f; float c = 1.0f; }; const Params SET_1 = { 0.1f, 0.5f, 0.9f }; const Params SET_2 = { 0.4f, 0.5f, 0.6f }; span<Params, 2> sets = { SET_1, SET_2 }; span<span<float, 3>, 2> test_2D = { { 0.1f, 0.5f, 0.9f }, { 0.4f, 0.5f, 0.6f } };
Huh???