HISE Logo Forum
    • Categories
    • Register
    • Login

    Expansion - Access AdditionalSourcecode file

    Scheduled Pinned Locked Moved General Questions
    60 Posts 3 Posters 5.5k 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.
    • DanHD
      DanH @Lindon
      last edited by

      @Lindon Thanks! :)

      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
      https://dhplugins.com/ | https://dcbreaks.com/
      London, UK

      DanHD 1 Reply Last reply Reply Quote 0
      • DanHD
        DanH @DanH
        last edited by

        @d-healey @Lindon thanks both, that's working perfectly - in the case that the JSON file is missing how can I set "MyNewNumber" to a certain value? I'm already in an if / else statement. I can't seem to find a way out after calling

        var myObj = Engine.loadFromJSON("somefile");
        

        DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
        https://dhplugins.com/ | https://dcbreaks.com/
        London, UK

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

          @DanH You can use if (!isDefined(myObj)) to check if it's there or not.

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

          DanHD 1 Reply Last reply Reply Quote 0
          • DanHD
            DanH @d.healey
            last edited by

            @d-healey ok trying. I'm not sure where to put "reg mrdata = cx.loadDataFile("maxrandomdata.json");" as if it goes before the if statement then I get an error, and if it goes in the else statement it gets ignored... I was trying:

            if (cx.loadDataFile("maxrandomdata.json") == undefined)
            

            before you wrote that... Where I'm at now is below:

            if (!isDefined(mrdata))
                    {
                        maxrandom = 35;
                    }
                    
                    else
                    {
                        reg mrdata = cx.loadDataFile("maxrandomdata.json");
                        maxrandom = mrdata.maxrandomnumber;
                    }
            

            DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
            https://dhplugins.com/ | https://dcbreaks.com/
            London, UK

            d.healeyD LindonL 2 Replies Last reply Reply Quote 0
            • d.healeyD
              d.healey @DanH
              last edited by

              @DanH Make a minimal snippet, we need to see some context.

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

              DanHD 1 Reply Last reply Reply Quote 0
              • LindonL
                Lindon @DanH
                last edited by

                @DanH

                var myObj = Engine.loadFromJSON("somefile");
                if (myObj)
                {
                      Console.print(myObj.NumberData);
                }else{
                    myObj = {NumberData : 444};
                }
                

                HISE Development for hire.
                www.channelrobot.com

                1 Reply Last reply Reply Quote 0
                • DanHD
                  DanH @d.healey
                  last edited by

                  @d-healey there's some general expansion stuff at the top, head down to the end for this bit

                  HiseSnippet 1477.3ocsW8uaaaCDVJIZXVaCaEaO.D9elLPhqy5O1.JJVhcbZLVicPbZ2JxJJnonrYiDofDcsMJ567dC1tSRVR1xIKyXUHHvj7tie22c73wKhTLdbrJxvr1UKB4Fles0vER8jNSnBoQuSLL+Vq.57HpzUEn4wZi1KBowwbWCSyceAJjYs8LR99qesM0mJY7hoLLdsRv3uTDHzEydwQ+lv2+TpK+JQPIoe7Q8XJYGkuZJ.ncsZYDRY2PGy6SQw1wxv7K55JzpngZJ.FCy8ZqbWLbhZlLU9WKhEi743fCMFBFJc5SU9tHhwYM5LQ36dwRGO1.rxEEzvtozvOXctvUjOeAc7cIKPJznLeXtypva2Uf2gkgWqRvaCPxrDj1KEROvZHKRDpKVAwyWY0Sp4QdTf1KCkTYM14c0r5n.Ij5lAza3mFACx0v4osZsOA9WimYaCTerl7AZDgOO7LHf6yiHOmzUNVH4MYQbvm5NOjJiEJY15NUTLc4XPwBqzbLWmq4KEw5D0JsdLWeruuZF2MWLzmicttjPmJ74sof6sOwlbe9JoahGGvcEfOrEp2UxhVDp4tuE.98R4MQJXVLRLW+1TuuzrMCmFOwo9oG24pAW9l5H83ohb3Dg7t4wF1YPshw3nzPtRHORK.prQSbwL7WBd4FbH2myfjW.gKyX.KzQEDpjv.m5UjDwYkIwfoScglGDWe+0Q16UBoS8+TVuA5hO7gqsLjTq6S0Sin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L+XG7rP53V3XjAFxktIC9a3KawCwwlYKd3xEMBnrH06XomfvWa8kIy.XRl7PyZVmiiIGt7vhkUqlsLBfG98NFCc+CfimaVmeZKz4QagNOdKz4IagNOcKz4m2Bc9k6TG7M2GOUqBRON.SbQ2jhVllckTHyJIKz3e.x75wPB
                  

                  Thank you!

                  DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                  https://dhplugins.com/ | https://dcbreaks.com/
                  London, UK

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

                    As far as I'm aware this is no longer required, but the docs haven't been updated.

                    expHandler.setAllowedExpansionTypes([expHandler.FileBased, 
                                                         expHandler.Intermediate, 
                                                         expHandler.Encrypted]);
                    

                    The only variable you should ever be declaring inside inline functions is local.
                    https://docs.hise.audio/scripting/scripting-in-hise/hise-script-coding-standards.html#variables

                    Don't do this:

                    if (cx.loadDataFile("NewNumber.json") == undefined)

                    It's inefficient because you'll have to read from disk more than once. Instead load it once and store it in a local variable, or if you are going to be using the data in other parts of your script you could use a reg variable in your on init callback or at the top of your namespace.

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

                    DanHD 1 Reply Last reply Reply Quote 0
                    • DanHD
                      DanH @d.healey
                      last edited by DanH

                      @d-healey said in Expansion - Access AdditionalSourcecode file:

                      Don't do this:

                      if (cx.loadDataFile("NewNumber.json") == undefined)

                      It's inefficient because you'll have to read from disk more than once. Instead load it once and store it in a local variable, or if you are going to be using the data in other parts of your script you could use a reg variable in your on init callback or at the top of your namespace.

                      Thanks :)

                      But if the file doesn't exist then I get the error which prevents the rest of the script from running. That's the wall that I'm hitting. Unless I misunderstand?

                      To put this into context I've supplied an Expansion which doesn't have this file inside and I'd rather not update all the users if there's a way to get around it!

                      I'm using this elsewhere which works fine (no errors) - was hoping the same would apply in my expansion callback:

                      if(Engine.loadFromJSON("..//AnaData.js") == undefined)
                      

                      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                      https://dhplugins.com/ | https://dcbreaks.com/
                      London, UK

                      LindonL 1 Reply Last reply Reply Quote 0
                      • LindonL
                        Lindon @DanH
                        last edited by

                        @DanH as I said:

                        var myObj = Engine.loadFromJSON("somefile");
                        if (myObj)
                        {
                              Console.print(myObj.NumberData);
                        }else{
                            myObj = {NumberData : 444};
                        }
                        
                        

                        HISE Development for hire.
                        www.channelrobot.com

                        DanHD 1 Reply Last reply Reply Quote 0
                        • DanHD
                          DanH @Lindon
                          last edited by

                          @Lindon Thanks, but that will look in the appData folder for the file, whereas I'm in an active expansion.... Or am I getting confused?

                          DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                          https://dhplugins.com/ | https://dcbreaks.com/
                          London, UK

                          d.healeyD DanHD 2 Replies Last reply Reply Quote 0
                          • d.healeyD
                            d.healey @DanH
                            last edited by d.healey

                            @DanH You're not confused, but you could just take Lindon's code and adjust it to load from an expansion (and don't use var) :)

                                local e = expHandler.getCurrentExpansion();
                                local data = e.loadDAtaFile("NewNumber.json");
                            
                                if (isDefined(data))
                                {
                                    // Do the thing
                                }
                                else
                                {
                                    // Do the other thing
                                }
                            

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

                            DanHD 1 Reply Last reply Reply Quote 0
                            • DanHD
                              DanH @DanH
                              last edited by

                              @DanH my takeaway from this is that Engine.loadFromJSON can handle a file not being there but currentexpansion.loadDataFile cannot, and produces an error...

                              DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                              https://dhplugins.com/ | https://dcbreaks.com/
                              London, UK

                              1 Reply Last reply Reply Quote 0
                              • DanHD
                                DanH @d.healey
                                last edited by

                                @d-healey yup, but I can't get past .loadDataFile if there's no data file 😆

                                HISE doesn't seem to like it (unlike Engine.loadFromJSON)

                                DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                https://dhplugins.com/ | https://dcbreaks.com/
                                London, UK

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

                                  @DanH Which line gives the error and what is the error?

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

                                  DanHD 1 Reply Last reply Reply Quote 0
                                  • DanHD
                                    DanH @d.healey
                                    last edited by

                                    @d-healey
                                    Error:

                                    Interface:! Cant find data file {EXP::TEST}NewNumber.json
                                    

                                    Line:

                                    local data = e.loadDAtaFile("NewNumber.json");
                                    

                                    DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                    https://dhplugins.com/ | https://dcbreaks.com/
                                    London, UK

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

                                      @DanH I see the problem. I've got to go out now but I'll take a look in the HISE source when I get back in a few hours and see if there is an easy fix.

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

                                      DanHD 1 Reply Last reply Reply Quote 0
                                      • DanHD
                                        DanH @d.healey
                                        last edited by

                                        @d-healey ok thanks!

                                        DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                        https://dhplugins.com/ | https://dcbreaks.com/
                                        London, UK

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

                                          This is how Engine.loadFromJSON handles a missing file.

                                          4b5e1a15-ec98-4b6e-ac2a-8016f94fcd3d-image.png

                                          And this is how loadDataFile handles it:

                                          5f809006-6dd4-4d00-a604-c9528daa6be6-image.png

                                          So it reports an error but does it actually stop the rest of your script running? In other words, if you put Console.print("HELLO WORLD"); on the next line does anything print to the console?

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

                                          DanHD 1 Reply Last reply Reply Quote 0
                                          • DanHD
                                            DanH @d.healey
                                            last edited by

                                            @d-healey yeah it stops it - i.e no "Hello World"

                                            DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
                                            https://dhplugins.com/ | https://dcbreaks.com/
                                            London, UK

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

                                            23

                                            Online

                                            1.8k

                                            Users

                                            12.1k

                                            Topics

                                            105.6k

                                            Posts