HISE Logo Forum
    • Categories
    • Register
    • Login

    SNEX struct and function parameter

    Scheduled Pinned Locked Moved Unsolved Scripting
    5 Posts 2 Posters 234 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ustkU
      ustk
      last edited by ustk

      @Christoph-Hart Probably a noob error, but I can't understand what I am doing wrong.
      I get no warning at compile time

      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};
      
      float processSample(float sample, const MyStruct &param)
      {
          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);
      

      Can't help pressing F5 in the forum...

      1 Reply Last reply Reply Quote 0
      • ustkU
        ustk
        last edited by

        Found the culprit

        I was dumbly writing

        const MyStruct BLUBLU = {anObject, anotherObject};
        

        somewhere that killed the struct...

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 2
        • ustkU ustk marked this topic as a question on
        • ustkU ustk has marked this topic as solved on
        • ustkU ustk has marked this topic as unsolved on
        • ustkU
          ustk
          last edited by ustk

          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 for unsafe index access
          Where is it unsafe if it is clamped?

          While I'm here, index::safe<0> can't be parsed.

          Can't help pressing F5 in the forum...

          griffinboyG 1 Reply Last reply Reply Quote 1
          • griffinboyG
            griffinboy @ustk
            last edited by griffinboy

            @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)
            	{
            		
            	}
            };
            
            
            1 Reply Last reply Reply Quote 0
            • ustkU
              ustk
              last edited by

              @Christoph-Hart Still having issues with struct and even span

              	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???
              Screenshot 2024-07-15 at 20.55.06.png

              Can't help pressing F5 in the forum...

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              26

              Online

              1.7k

              Users

              11.8k

              Topics

              102.6k

              Posts