HISE Logo Forum
    • Categories
    • Register
    • Login

    Accurate range conversion

    Scheduled Pinned Locked Moved General Questions
    21 Posts 3 Posters 651 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.
    • toxonicT
      toxonic
      last edited by

      I'm trying to setup a MacroContol to receive tempochanges from the DAW and want to assign knobs to the macro control. Since the MacroControls work in a range 1...127, it seems, which doesn't fit to BPM values, i tried to convert the range with a function. But this doesn't work very precise, when i look at the Tempo value from the HISE keyboard / controller compared to the knob, connected to the MacroControl. Can someone take a look at the snippet and tell me, how i can get the conversion more accurate?

      HiseSnippet 1042.3ocsVstaiTCF0SZmER3hXE7.Xs+ZBjMLIscKnHfPSaoQPaiHgpkeU4cFmDqNi8HOdZZ.wy.OA77vqCuAvm8byARWsJhcTUi9t5i+FeNdlHEAzzTgD4zb15DJx48cmtlqVNZIgwQiOE76dgHUcRRL5j0IjzTZHxwYuuSG1o49Hyye8MmPhH7.ZsKD5FAKf9CrXlp16jgeOKJ5bRHcFK1J6CGNNPvGIhDY.T1y0GkPBtirfdEQmVCWjySNKjoDxoJhhlhb1+DQ35oKEq344eCKk8pHp1nGZJznb2mKhB0HV6EMZIKJbR4VNEAcYR8.Xu7Avm3dIKjU4udP7Ql.35JrmGNM1Dd6sA75YCOeK3sEH4XAo8ygzScmFHYIp5HZ77dti4JpbNAF61PIOWTi+ng6HAjAW0MlbG8bIXTUgWee+N3d99sGzBl7oJ78DIt3MM9qvkUtfpFIhSDbvv6YEweVUQyt.x8L9BFm1MPRg89LIgmlHjpKH7vHpzCxs07LdfhI3XH3BJzar2nLoD54MjnLZG70QgWx34+RdnC9J5Jis9WxCsa8qsvvi4eZbBtMEBKtm2FsB+7hd0F+oXu7xAe48qca7mi8xWi5Dai+rh3CLKfjpxj7p0XPqeqUKFOB1h3p8ghByD3nAra73zUyzlZT1D1aohHZ2DICFXUgFzpogV0MkptjDHE54qTD40qS4HoJ4N3C7wcv8OT+BB9q+wswsMnX1E55ulOyZ0g1FbkPwlyBHZn0wFasGTgXAGxhdM2y.Sna3+cn4y2ZrBjZdUtkvZdr70UnGOK9UTYG3EGLMqRDNbuIiw8wYL1D5f7ClVIJ3i4L00IT9iQyQEml0rqBTAopLbqOrfaMMhERkHVnshmAxkpT+9e9xgneZ7oDEorQPOg0IgJUL8Vv4T58flWNoso6ozz6ThDStETHv8avx9fsL5ZaiXhUL9vUrP0xZGrgKorEKsza+4gw15ze8vTEMYJ6Wn1Z2n+qhCn0IByhHpME.0p9EAf2wan5nUV3oL0Z6N++lp3aJDep6DlJX41wXisfQ3M4aCLVbWxG3d174z.UM.2287W914hCzOJxTL9hKIJICNk3dUV7T35z.pVKfSizbLmFZ1Ptsu1VOAlR4gFi+FdJB1Sa6TDrWYP37GnccaPNGRea06Z7.XhatntoqQcC2qj57wtG1q6weo9o+AG6+B+iNBECWidaPfdX7bn0NAkJLg2lPjPef6nfVo4D12wYEK+CDJLusboKoOli7Ow8.+t94Dl2wEDSAiHwpp.KAhRcDF+dfDm+gB9H3hrPAOZcgdx12h8K2httlEZiM0iTyA6PMGtC0bzNTyK1gZNdGp4Kds0n+DquMSIhyYufiImYTbcbNiS.hfgzf9G.tpz5RC�
      
      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        Link Preview Image
        HiseUtilityScripts/libraries/Helpers.js at master · davidhealey/HiseUtilityScripts

        Contribute to davidhealey/HiseUtilityScripts development by creating an account on GitHub.

        favicon

        GitHub (github.com)

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

        toxonicT 1 Reply Last reply Reply Quote 1
        • toxonicT
          toxonic @d.healey
          last edited by

          @d-healey basically, this is pretty much the same conversion that i use, isn't it?

          function rangeCon (CurrentValue, OldMin, OldMax, NewMin, NewMax)
          {
              
              var NewValue = (((CurrentValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin;
              return NewValue;
          }�
          
          d.healeyD 1 Reply Last reply Reply Quote 0
          • d.healeyD
            d.healey @toxonic
            last edited by d.healey

            @toxonic I didn't open your snippet I just answered the question :p

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

            toxonicT 1 Reply Last reply Reply Quote 0
            • toxonicT
              toxonic @d.healey
              last edited by toxonic

              @d-healey Hehehe, okay.... :D Then it's seems not to be an issue of my conversion function, that there are inaccuracies... any ideas?

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

                @toxonic Why do you want to use macros for this?

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

                toxonicT 1 Reply Last reply Reply Quote 0
                • toxonicT
                  toxonic @d.healey
                  last edited by

                  @d-healey To be honest, I just try to learn scripting in HISE, and I'm at the very beginning.
                  I have several Faust FX which can be dynamically loaded into 6 Hardcoded Master FX Slots.
                  Some of these FX have BPM Knobs, which should automatically receive tempochanges by the DAW using Transport Handler. Since i have no idea, how to connect them in that moment, the effect gets loaded into a Hardcoded FX Slot, without using an array, which will be problematic as soon as the effect is getting removed again from the Slot, i thought it might be a simpler option to use a Macro Control and get all "BPM" buttons connected to it, when the effect gets loaded. (excuse that awkward explanation and my poor english, but i'm afraid, i can't do better ;-) ).

                  Btw, i tried to "borrough" your Helpers.js file and put it into the default location for global scripts, but when I try to include it via:

                  'Helpers.js'include({GLOBAL_SCRIPT_FOLDER}Helpers.js);�
                  

                  HISE tells me

                  Master Chain:! Line 1, column 1: File /home/toxonic/Audio/HISE_Projects/Test/Scripts/Helpers.js not found�
                  

                  This is not the global script path at all. Is the wildcard broken?

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

                    @toxonic

                    I think you should just be using setAttribute rather than macros for this. Another option is to put a tempo knob on your UI and connect that to the knob of your effect, and update its value inside your tempo change callback.

                    Did you set the global script folder in project preferences? Also why do you have 'Helpers.js' before the include?

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

                    toxonicT 1 Reply Last reply Reply Quote 0
                    • toxonicT
                      toxonic @d.healey
                      last edited by

                      @d-healey said in Accurate range conversion:

                      @toxonic

                      I think you should just be using setAttribute rather than macros for this. Another option is to put a tempo knob on your UI and connect that to the knob of your effect, and update its value inside your tempo change callback.

                      I will try this out, i could make the UI Knob invisible too.

                      Did you set the global script folder in project preferences? Also why do you have 'Helpers.js' before the include?

                      Well, i tried it according to the tool tip
                      Screenshot from 2022-11-25 18-14-38.png

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

                        @toxonic I think that tool tip is badly worded. I have a video on Patreon about the Global Scripts Folder - https://www.patreon.com/posts/sharing-scripts-72393541

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

                        Christoph HartC 1 Reply Last reply Reply Quote 1
                        • Christoph HartC
                          Christoph Hart @d.healey
                          last edited by

                          You're a bit off-track and scripting and macro controls are definitely the wrong tool for the job.

                          Some of these FX have BPM Knobs, which should automatically receive tempochanges by the DAW using Transport Handler. Since i have no idea, how to connect them in that moment

                          Just use a tempo-sync node and connect it to whatever faust parameter you need to be synced. The tempo sync node automatically converts the current tempo to a ms value (and if you want to connect it to a frequency parameter you can use a converter node with the appropriate mode).

                          toxonicT 1 Reply Last reply Reply Quote 2
                          • toxonicT
                            toxonic @Christoph Hart
                            last edited by

                            @Christoph-Hart Hmm, but the tempo sync node updates tempo changes in 64t at best, correct? Thats 's not really accurate, right?

                            toxonicT 1 Reply Last reply Reply Quote 0
                            • toxonicT
                              toxonic @toxonic
                              last edited by

                              Okay, i got it working now by scanning the array with all HardcodedMasterFX References for a parameter called "bpm" and if available, assign to the Transport Handler function.

                              const var HardcodedMasterFX = [Synth.getEffect("HardcodedMasterFX1"), Synth.getEffect("HardcodedMasterFX2"),
                              Synth.getEffect("HardcodedMasterFX3")];
                              
                              const var th = Engine.createTransportHandler();
                              
                              th.setOnTempoChange(false, function(newTempo)
                              {
                              	for (x in HardcodedMasterFX)
                              	{
                              		var bpmknob = x.getAttributeIndex("bpm");
                              		if (bpmknob != -1) x.setAttribute(bpmknob, newTempo);
                              		else continue;
                              	}
                              	
                              });
                              

                              The result of one day of trial and error... sad but true! :-( But yeah, every beginning is difficult! ;-)

                              Christoph HartC 1 Reply Last reply Reply Quote 0
                              • Christoph HartC
                                Christoph Hart @toxonic
                                last edited by Christoph Hart

                                Hmm, but the tempo sync node updates tempo changes in 64t at best, correct? Thats 's not really accurate, right?

                                No, that's just the smallest divisor. The host tempo is converted to milliseconds using the full double precision but if your faust class expects a parameter as BPM, you will have to convert it back to BPM values.

                                The formula is BPM = 60.0 / (ms * 0.001) so you could just use a control.cable_expr node, but I've also added a converter mode to the control.converter node that does this for you.

                                7380168f-5dc4-407c-b3db-b677f4ca1b4b-image.png

                                toxonicT 1 Reply Last reply Reply Quote 2
                                • toxonicT
                                  toxonic @Christoph Hart
                                  last edited by

                                  @Christoph-Hart said in Accurate range conversion:

                                  No, that's just the smallest divisor. The host tempo is converted to milliseconds using the full double precision....

                                  Aha, okay, then i got that wrong. It seemd to me, that it only updates the ms values in dependence to the tempo.

                                  ...but if your faust class expects a parameter as BPM, you will have to convert it back to BPM values.
                                  The formula is BPM = 60.0 / (ms * 0.001) ....

                                  I have already converted the values inside some of the Faust files according this formula.

                                  ....so you could just use a control.cable_expr node, but I've also added a converter mode to the control.converter node that does this for you.

                                  Ah, nice, that you already added the MS2BPMModeto the converter node! :-)
                                  Just one more question: The solution i posted in my above post seems to me quite satisfying at the moment, but due to my lack of experience i just want to ask you, if you think, if there's something to complain about. What do you think?

                                  Christoph HartC 1 Reply Last reply Reply Quote 0
                                  • Christoph HartC
                                    Christoph Hart @toxonic
                                    last edited by

                                    @toxonic Yes you're using a asynchronous tempo callback so the tempo update will be dragged through the UI thread and might be updated a few milliseconds later if the UI is busy.

                                    Whether you can live with that kind of hack is up to you, but the cleaner solution is to use a tempo_sync node like I suggested.

                                    toxonicT 1 Reply Last reply Reply Quote 0
                                    • toxonicT
                                      toxonic @Christoph Hart
                                      last edited by

                                      @Christoph-Hart What about putting it into an inline function to get it synchronous?

                                      const var th = Engine.createTransportHandler();
                                      
                                      th.setOnTempoChange(true, TempoChange);
                                      
                                      inline function TempoChange(newTempo)
                                      {
                                      	for (x in HardcodedMasterFX)
                                      	{
                                      		local bpmknob = x.getAttributeIndex("bpm");
                                      		if (bpmknob != -1) x.setAttribute(bpmknob, newTempo);
                                      		else continue;
                                      	}
                                      	
                                      };�```
                                      Christoph HartC 1 Reply Last reply Reply Quote 0
                                      • Christoph HartC
                                        Christoph Hart @toxonic
                                        last edited by

                                        @toxonic Yes, but then you get a string comparison function in a loop whenever the tempo changes in the audio callback.

                                        toxonicT 1 Reply Last reply Reply Quote 1
                                        • toxonicT
                                          toxonic @Christoph Hart
                                          last edited by

                                          @Christoph-Hart Yes, right - you mean, this is a question of CPU usage? I thought, it would maybe suck more ressources, if i have multiple instances of the tempo sync node / converter nodes running ? No?

                                          Christoph HartC 1 Reply Last reply Reply Quote 0
                                          • Christoph HartC
                                            Christoph Hart @toxonic
                                            last edited by

                                            @toxonic It won't burn your CPU to use this, but it's vastly more ineffective than a tempo sync node, which is just a virtual function call with the new tempo value which is basically free unless you have thousands of tempo sync nodes (with your solution you also get the overhead of calling into HiseScript).

                                            It's not critical per se but you asked me what's wrong with the code and I would do it differently.

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

                                            25

                                            Online

                                            1.7k

                                            Users

                                            11.8k

                                            Topics

                                            103.0k

                                            Posts