HISE Logo Forum
    • Categories
    • Register
    • Login

    Broadcaster does not send signal when using declared objects.

    Scheduled Pinned Locked Moved Bug Reports
    broadcasterscript
    4 Posts 2 Posters 325 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.
    • oskarshO
      oskarsh
      last edited by

      Hey,
      is this a bug or a feature? When defining a object and assigning it to a broadcaster, it only sends a signal once. Every further update results in no signals being send. It seems like the Object id stays the same since we are technically still using the same Object so it does not register as a valid change.

      1b1c515f-1f47-47c4-953e-cfe9f44cad06-image.png

      Content.makeFrontInterface(600, 600);
      
      var STATE = {
      	'Playlist' : 'Playlist1'
      };
      
      const var b = Engine.createBroadcaster({
      	"id": "My Broadcaster",
      	"args": ["state"]
      });
      
      b.addListener({"id": "Listener"}, "Listening...",
      function(state)
      {
      	Console.print('receiving signal');
      	Console.print(trace(state));
      });
      
      b.state = STATE;
      
      Console.print('updating state');
      STATE['Property'] = {another: 'one'};
      Console.print(trace(STATE));
      b.state = STATE;
      Console.print('Broadcaster does not send out signal');
      
      HiseSnippet 853.3ocsUstZZDDEdVianZuPCzGfA+iFvJZaZZIkRS7RJRiIR0FJDBgwYG0grNyxLylVo36PeT6aP6Y1c8RLhMQn6ODO2+lyb9NSakjxzZoB4jo63.Fx4ItcFKLCqMjvEnl0QNOysEQaXJbrppiCHZMyC43r0mrJbxjFE886OVk3SDT1bUHz4RNkcBeD2LWa6C+L22+XhGqKezBdu2gMoRQMouLDvyVtkQAD50jArSIV2R4hb1tgG2HUcLDCSC9TU5MtyP42Ew9eNWy64yrBUPcfDEqFUaH22q8zypFgbR2d9Ieq3S9Kbaw83yzOuC77HC34QrXOvI05fTkG.jbV.RoigzNtcnJdfYtEKddraSAbgzm.s5EgRrunT+JkaMI3gvTZD4Z1wJPXVDE1ub4hX3mcee1r2PT3NcOpaC7Gv+Lal7s8Ii84ZSd7A3YBUxmcB3Kb0nMXaD8.uaHFvErRTECN1UURhGMZJo.jlbbubGfy0ZLdAC4JBFHpAZvzE4z1tUtKyNwhhdkHddm.UhIrIHI7oJxMo3TAtXPoRkfL0OTPMbonPTd1MKTT3Dqk9rRAJtvTHuhQY7af.vZ9.AwOOTnk7wnrsi3L.VSfRjLb.iZKflkxaXfGwDkVqe1rF43E4gqn.lxLN+k1dIQHMCYJnKJEr7P6aUkNJRaouSUWpnKzFwdRlFCYGqYBOrLzL+.NsqfkhSkF1YhBQclrSxhW1T+9qzlcrQI88gqgUY1RWUqKvBhvQ8XphvXheHaliv77sIIae+HIz3o3EbTJZJ3lyBXIxGK88rC+1+eWJEJgF.+6qMqSLDKKKQWx8E2BGm5raf0TwbtLt0Y5qMx.XQ0cHjvp.oWnOwb68C1EgIFf9wsHkVhmPyMiWbQ4CXoQ40tz39BwcbayMzgqFioVAFgN0+CLlrp8otM52mQMyAXZ2i+1ltW8eT9u.jDfw1hXT7efbbOMbTG3EFJCptPv7gj65jxNsDKW1Ja6.c.FVjvefuDiUrxNIFqL0HZDgpjWQiYA1k4OJRCfIQzaWYfGQAYbETDy.hysboxnQv6JWQo1i+KgA3UGyq1fXd8FDydaPLuYChY+MHl2tAw7t0Fi8I8iBMxQwzAPQ6FQqHbbZHHvjUzTH5u.KbEiQC
      
      Christoph HartC 1 Reply Last reply Reply Quote 0
      • Christoph HartC
        Christoph Hart @oskarsh
        last edited by

        @oskarsh Yes that's actually intended behaviour - a broadcaster is supposed to filter out repetitions of the same message so that it saves execution time. It uses a default JS comparison, so if you have an object as message it will not send the message because it still points to the same object (as you have assumed).

        There are three options:

        1. Don't use a single object but multiple parameters by giving the args an array with multiple IDs. This way it will make sure to send the message when one of the properties change, but it only works if you know how many properties your object will have. From a clean code perspective this is the preferred option
        2. You can explicitly tell the Broadcaster to not filter out repetitions (setEnableQueue(true)). This is required for some scenarios (eg. if a broadcaster listens to multiple sources) and in your case it brute-forces the broadcaster to behave like you want.
        3. If you want to manually resend the message, you can use resendLastMessage() instead of assigning the object again, this will send the message no matter whether it changed or not.
        oskarshO 1 Reply Last reply Reply Quote 3
        • oskarshO
          oskarsh @Christoph Hart
          last edited by

          @Christoph-Hart Thanks I ended up creating a new copy of the object which I then mutate. This is actually best practice in terms of state management. I then assign this newState to my broadcaster and update the actual state object.

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

            @oskarsh ah yeah, that's the fourth option :)

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

            28

            Online

            1.7k

            Users

            11.8k

            Topics

            103.2k

            Posts