HISE Logo Forum
    • Categories
    • Register
    • Login

    BPM value from the DAW

    Scheduled Pinned Locked Moved General Questions
    6 Posts 4 Posters 435 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.
    • MikeBM
      MikeB
      last edited by

      How do I make a BPM knob continuously take the BPM value from the DAW?

      So if I change the BPM value in the DAW, the BPM value in the plug-in automatically adjusts.

      "One hour of trial and error can save 10 minutes of reading the manual."
      "It's easier to hit the developer with feature requests than to spend 10 minutes reading the manual. :-)))"
      HISE Develop - Mac Pro 5.1, OS X 10.14.6, Projucer 6.02, Xcode 10.3

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User
        last edited by A Former User

        You could use a timer with a long timer tickrate to avoid unnecessary CPU usage alongside Engine.getHostBpm() to update the knob value in the timer callback

        Edit:

        const var timer = Engine.createTimerObject();
        var BPM = Engine.getHostBpm();
        
        timer.setTimerCallback(function()
        {
            if (Engine.getHostBpm() != BPM) //only updates if the BPM has changed
            {
                BPM = Engine.getHostBpm();
                Knob.setValue(BPM);
                Knob.changed(); //make sure to call .changed()
            }
        }
        
        timer.startTimer(200); //Checks every .2s
        

        If you need to update more frequenty, use a smaller number in timer.startTimer()

        ulrikU 1 Reply Last reply Reply Quote 1
        • ulrikU
          ulrik @A Former User
          last edited by

          @iamlamprey @MikeB or you could use this, then you don't need any timer. It will react as soon as the daw tempo change

          const var HostBpm = Content.getComponent("HostBpm");
          const TH = Engine.createTransportHandler();
          
          inline function tempoChange(newTempo)
          {
          	Console.print(newTempo);
          	HostBpm.setValue(newTempo);
          	
          	//	if you only want the tempo displayed and
          	//	not to trigger the HostBpm CB you dont need this line
          	HostBpm.changed();
          }
          
          TH.setOnTempoChange(true, tempoChange);
          

          Hise Develop branch
          MacOs 15.3.1, Xcode 16.2
          http://musikboden.se

          ? 1 Reply Last reply Reply Quote 1
          • ?
            A Former User @ulrik
            last edited by

            @ulrik oh right transport handler exists, yeah use that lol

            Christoph HartC 1 Reply Last reply Reply Quote 0
            • Christoph HartC
              Christoph Hart @A Former User
              last edited by

              @ulrik you're example is almost perfect, with the exception of the first parameter of setOnTempoChange() which defines whether the callback should be executed immediately or should be deferred to the UI thread. This might have serious implications on the audio performance (if you're doing heavyweight UI stuff in the knob callback) so it should be addressed carefully.

              In your example it's set to true, which means, well ... no idea, I have to look up what the bool value means EVERY SINGLE TIME. This is bad and has nagged me for quite a while now (in fact I changed some functions for the broadcaster last week to address that problem there). Also I should have learned from the great masters of API design because JUCE also had some old methods using a bool value instead of a more descriptive notification type and they (or Jules alone back in the days) changed the API interface to use a enum instead.

              So a breaking change in the API interface is out of the question as this is a bit too old so many people might already use it. So what I did was to define two global variables with some magic numbers, SyncNotification and AsyncNotification and all methods that have previously taken a bool value (spoiler alert, bool means synchronous) will now accept and handle the magic number value accordingly. The bool value will still work like before so it won't break older projects, but the way going forward is this:

              TH.setOnTempoChange(SyncNotification, tempoChange);
              

              which makes it immediately clear how this function will be executed (and also what the argument does at all, which was especially confusing with function calls that had another bool parameter).

              ulrikU 1 Reply Last reply Reply Quote 3
              • ulrikU
                ulrik @Christoph Hart
                last edited by

                @Christoph-Hart thanks for explaining!

                Hise Develop branch
                MacOs 15.3.1, Xcode 16.2
                http://musikboden.se

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

                12

                Online

                1.7k

                Users

                11.8k

                Topics

                102.8k

                Posts