HISE Logo Forum
    • Categories
    • Register
    • Login

    Helper Function Logic....Placement?

    Scheduled Pinned Locked Moved Solved Scripting
    24 Posts 3 Posters 124 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.
    • ChazroxC
      Chazrox
      last edited by Chazrox

      I have a helper function inside of a namespace. Should I be able to call it from anywhere else in the script?

      Interface
      {
               HelperFunction(); // Does it work here?
      
           namespace SomeFunctions
           {
               HelperFunction(); // Does it work here?
      
               inline function HelperFunction()
               {
                     // doing something
               }
               
               HelperFunction(); // Does it work here?
           }
      
      }
      
      
      
      dannytaurusD d.healeyD 2 Replies Last reply Reply Quote 0
      • dannytaurusD
        dannytaurus @Chazrox
        last edited by dannytaurus

        @Chazrox Wouldn't you have to call SomeFunctions.HelperFunction() outside the namespace?

        Meat Beats: https://meatbeats.com
        Klippr Video: https://klippr.video

        ChazroxC 1 Reply Last reply Reply Quote 3
        • d.healeyD
          d.healey @Chazrox
          last edited by d.healey

          @Chazrox if you're calling it from outside the namespace you need to included the namespace in the call. SomeFunctions.helperFunction()

          Libre Wave - Freedom respecting instruments and effects
          My Patreon - HISE tutorials
          YouTube Channel - Public HISE tutorials

          1 Reply Last reply Reply Quote 2
          • ChazroxC
            Chazrox @dannytaurus
            last edited by

            @dannytaurus @d-healey wow. Thanks..testing that now. So just for my understanding, can you do that with any function inside of a function?

            d.healeyD 1 Reply Last reply Reply Quote 0
            • d.healeyD
              d.healey @Chazrox
              last edited by

              @Chazrox said in Helper Function Logic....Placement?:

              can you do that with any function inside of a function?

              Do you mean calling a function from within another function?

              Libre Wave - Freedom respecting instruments and effects
              My Patreon - HISE tutorials
              YouTube Channel - Public HISE tutorials

              ChazroxC 1 Reply Last reply Reply Quote 0
              • ChazroxC
                Chazrox @d.healey
                last edited by

                @d-healey yes. and If the functions you're calling on is in another namespace on an external file. That should work with the method you suggested yes?

                d.healeyD 1 Reply Last reply Reply Quote 0
                • d.healeyD
                  d.healey @Chazrox
                  last edited by

                  @Chazrox Yes, doesn't matter if there in an external file or the same file though.

                  Libre Wave - Freedom respecting instruments and effects
                  My Patreon - HISE tutorials
                  YouTube Channel - Public HISE tutorials

                  ChazroxC 2 Replies Last reply Reply Quote 1
                  • ChazroxC
                    Chazrox @d.healey
                    last edited by

                    @d-healey That just opened my mind to so much. Crucial fact. Thanks guys!

                    @dannytaurus 🙏

                    1 Reply Last reply Reply Quote 0
                    • ChazroxC
                      Chazrox @d.healey
                      last edited by

                      @d-healey What if you're inside of a namespace, and you have a function calling to a helper on onInit. Does that need special method?

                      d.healeyD 1 Reply Last reply Reply Quote 0
                      • d.healeyD
                        d.healey @Chazrox
                        last edited by

                        @Chazrox Where is the function call?

                        Libre Wave - Freedom respecting instruments and effects
                        My Patreon - HISE tutorials
                        YouTube Channel - Public HISE tutorials

                        ChazroxC 1 Reply Last reply Reply Quote 0
                        • ChazroxC
                          Chazrox @d.healey
                          last edited by Chazrox

                          @d-healey

                          interface
                          {
                           
                          inline function myHelper()
                          }
                              // Need to do this call }
                          
                             namespace SomeFunctions
                             {
                          
                                  inline function SystemFunction()
                                  {
                          
                                    myHelper();
                          
                                  }
                          
                             }
                          }
                          
                          
                          d.healeyD 1 Reply Last reply Reply Quote 0
                          • d.healeyD
                            d.healey @Chazrox
                            last edited by

                            @Chazrox

                            This code isn't valid

                            interface
                            {
                            inline function myHelper();
                            }
                            

                            Libre Wave - Freedom respecting instruments and effects
                            My Patreon - HISE tutorials
                            YouTube Channel - Public HISE tutorials

                            ChazroxC 1 Reply Last reply Reply Quote 0
                            • ChazroxC
                              Chazrox @d.healey
                              last edited by Chazrox

                              @d-healey aww that was a typo just right here. in my code its proper. what about the structure of the whole thing and the way the code flows? Does it reach my helper on interface script?

                              Sorry I feel like I wasted your time with that stupid typo.

                              d.healeyD 1 Reply Last reply Reply Quote 0
                              • d.healeyD
                                d.healey @Chazrox
                                last edited by

                                @Chazrox

                                Here's an example

                                namespace HelperFunctions
                                {
                                    inline function doAThing()
                                    {
                                        Console.print("Hello World");
                                    }
                                
                                    doAThing();
                                }
                                
                                HelperFunctions.doAThing();
                                
                                

                                Libre Wave - Freedom respecting instruments and effects
                                My Patreon - HISE tutorials
                                YouTube Channel - Public HISE tutorials

                                ChazroxC 1 Reply Last reply Reply Quote 0
                                • ChazroxC
                                  Chazrox @d.healey
                                  last edited by Chazrox

                                  @d-healey Heres my exact use case...

                                  I have a file drop panel that saves a copy of a midi files to the app data folder.
                                  I just want the combobox to reflect the added items.

                                  I tried adding namespace.updateMidiFilesComboBox();

                                  and

                                  just .updateMidiFilesComboBox();

                                  but both give the error that '.updateMidiFilesComboBox' expression is not a function (both ways)

                                  hence me trying to figure out how to jump around namespaces rn...
                                  I've tried calling this function FROM the end of the panel drop function but that gives the same error hence me trying a timer callback.

                                  // This is in a namespace
                                  
                                  const var appDataDir2 = FileSystem.getFolder(FileSystem.AppData);
                                  var midiFiles = FileSystem.findFiles(appDataDir2, "*.mid", false);
                                  cmbMidiFiles.set("items", "");
                                  
                                  
                                  inline function updateMidiFilesComboBox()
                                  {
                                  	
                                  
                                  
                                  		for (i = 0; i < midiFiles.length; i++)
                                  		{
                                  			Console.print(midiFiles[i]);
                                  		
                                  		    cmbMidiFiles.addItem(midiFiles[i].toString(Filename).replace("/Users/user/Library/Application Support/MANGO WORLD/KEYZIE  V29/", "").replace(".mid"));
                                  		
                                  		}
                                  		Console.print("PANEL MIDI MIDI" + trace(pnlMIDIFiles));
                                  		
                                  
                                  
                                  }
                                  
                                  updateMidiFilesComboBox();
                                  
                                  
                                  //this is in onInit
                                  const var midiComboBoxTimer = Engine.createTimerObject();
                                  
                                  midiComboBoxTimer.setTimerCallback(function(component, value)
                                  {
                                  	updateMidiFilesComboBox();
                                  });
                                  midiComboBoxTimer.startTimer(200);
                                  
                                  d.healeyD 1 Reply Last reply Reply Quote 0
                                  • ChazroxC Chazrox marked this topic as a question
                                  • d.healeyD
                                    d.healey @Chazrox
                                    last edited by

                                    @Chazrox what's the timer for? Show me where you're calling it after the file drop.

                                    Libre Wave - Freedom respecting instruments and effects
                                    My Patreon - HISE tutorials
                                    YouTube Channel - Public HISE tutorials

                                    ChazroxC 1 Reply Last reply Reply Quote 0
                                    • ChazroxC
                                      Chazrox @d.healey
                                      last edited by Chazrox

                                      @d-healey
                                      The timer is just a hacky attempt to see if I can get it to work.

                                      Im trying to get my combobox to update after a drop a new file. The combobox searches the appData folder for .mid files and populates the combobox items list.

                                      I want it to happen here somewhere. Someplaces I drop it, it doesnt do anything...in another spot, it duplicates everything in the combobox like 3-4 times and if I keep going it just stacks up.

                                      can you suggest where to put .updateMidiFilesComboBox(); ?

                                      inline function onpnlMIDIFilesFileDrop_B(obj)
                                      {
                                      	
                                      
                                      	
                                      	//Console.print(trace(obj) + "TRACE TRACE TRACE");
                                          // HOVER STATE
                                          local prevHover = this.data.hover ? 1 : 0;
                                      
                                          this.data.hover = (obj.hover && !obj.drop) ? 1 : 0;
                                      
                                          if ((this.data.hover ? 1 : 0) != prevHover)
                                          {
                                          	this.repaint();
                                          }
                                      
                                          // HOVER CHECK
                                          if (obj.hover && !obj.drop)
                                          {
                                              this.data.text    = "Drop to load!";
                                              this.data.dropped = false;
                                              this.changed();
                                              return;
                                          }
                                         
                                          if (!obj.drop || obj.fileName == undefined)
                                          {
                                          	return;	
                                          }
                                      
                                          // PARSE BASE NAME
                                          
                                          local full = obj.fileName;   
                                          local slash = Math.max(full.lastIndexOf("/"), full.lastIndexOf("\\"));   
                                          local dot = full.lastIndexOf(".");
                                      
                                      	//============
                                         
                                           Console.print("full contains:" + full);
                                      
                                      	//=============
                                          
                                          if (dot < 0) 
                                          {
                                          	dot = full.length;
                                          }
                                          
                                          local base = full.substring(slash + 1, dot);
                                      
                                          this.data.filename = base;   // paint()
                                          this.data.fileName = base;   // sync
                                          
                                      
                                      	
                                      	Console.print("BASE__" + base);
                                          // HIDE RANGE SLIDER WHILE NO EVENTS
                                          RangeSlider.set("visible", 0);
                                      
                                          // LOAD MIDI PLAYER TRACK 1
                                          MIDIPlayer1.setFile(full, true, true);
                                          if (MIDIPlayer1.setTrack != undefined) MIDIPlayer1.setTrack(1);
                                      		
                                      	// START POLLING EVENTS
                                      	midiRangeTimer.stopTimer();
                                      	midiRangeTimer.startTimer(50);
                                          
                                      
                                          // -----------------------------------------------------------
                                          // COPY DROPPED FILE INTO AppData 
                                          // -----------------------------------------------------------
                                         
                                      	local original = FileSystem.fromAbsolutePath(full);
                                      	//===========
                                           
                                            Console.print("Original contains:" + original);
                                            Console.print("Original is defined ==:" + (original != undefined));
                                            Console.print("Original is a file ==:" + (original != undefined));
                                      	
                                      	//===========
                                      	
                                      	local filename = full.substring(slash + 1 );
                                      
                                          if (original != undefined)
                                          {
                                      
                                      		Console.print(filename + "IS DEFINED");
                                             	Console.print("ORIGINAL__" + original);
                                              
                                              local appDataDir = FileSystem.getFolder(FileSystem.AppData);
                                              local newFile = appDataDir.getChildFile(base + ".mid");
                                      
                                              original.copy(newFile);
                                              newFile.move(appDataDir);
                                                    
                                      		Console.print("NEWNEWNEW" + newFile);		
                                      		Console.print("Saved copy to AppData: " + base);
                                      		
                                      
                                          }
                                      
                                      	
                                          setAnalysisWindowFull();
                                          disableAllChords();
                                          disableAllChords();
                                      
                                      
                                      	
                                          // UI flags
                                          this.data.text    = "Loaded";
                                          this.data.dropped = true;
                                          this.data.hover   = false;
                                          this.changed();
                                          this.repaint();
                                          
                                      
                                          knbSmartStrength.changed();
                                          pnlCustomMidiPanel.sendRepaintMessage();
                                          pnlCustomMidiRipView.sendRepaintMessage();
                                         	Console.print("DROP PANEL B WAS USED");
                                      }
                                      
                                      d.healeyD 1 Reply Last reply Reply Quote 0
                                      • d.healeyD
                                        d.healey @Chazrox
                                        last edited by

                                        @Chazrox said in Helper Function Logic....Placement?:

                                        this.data.filename = base; // paint()
                                        this.data.fileName = base;

                                        What's going on here?

                                        @Chazrox said in Helper Function Logic....Placement?:

                                        disableAllChords();
                                        disableAllChords();

                                        And here?

                                        I think you need to start by breaking that massive function into smaller more manageable sub functions. It's too chaotic at the moment.

                                        Libre Wave - Freedom respecting instruments and effects
                                        My Patreon - HISE tutorials
                                        YouTube Channel - Public HISE tutorials

                                        ChazroxC 2 Replies Last reply Reply Quote 0
                                        • ChazroxC
                                          Chazrox @d.healey
                                          last edited by

                                          @d-healey

                                          @d-healey said in Helper Function Logic....Placement?:

                                          It's too chaotic at the moment.

                                          it is.

                                          1 Reply Last reply Reply Quote 0
                                          • ChazroxC
                                            Chazrox @d.healey
                                            last edited by

                                            @d-healey said in Helper Function Logic....Placement?:

                                            What's going on here?

                                            setting panel data for other functions to read like my paint functions.

                                            its a mess in here at the moment. but i'll def clean it up. i've been doing the most trying to fix this but im def making a mess. 👍

                                            d.healeyD 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            13

                                            Online

                                            1.9k

                                            Users

                                            12.4k

                                            Topics

                                            108.1k

                                            Posts