How to control broadcaster message order?
-
I've got a situation in my project where I'm relying on one message being sent before another, from 2 different broadcasters. The first broadcaster triggers the second broadcaster. However they are arriving at their destination in reverse order.
Here is a simple snippet that demonstrates the issue:
HiseSnippet 1024.3ocsVstaaaCElJIJaxaqXcnO.Z5WN.At1tccCqXnY9RJLZcpwTZw.FFJnonrILEofHUWbKx+5yydE1yxdC1av1gTxQxIFwMFX5G15vysuygmKZRljPUJYFxw67koTjyW5FtTnm2eNlIPiFfbtm6XrRSy7KNp2xTrRQiPNN6+byANdGfrO+yy5g4XAgVcDB8FIiPeIKgoqNcxIufw4mhinmyRpI8iOYDQJ5K4xb.O661FkhIKvynmgMhsmKx4vgQLsLKTi0TEHSOYzxv4x+PTH+aXJ1TN0PzAEBFp3XT+4LdzjUwpBgbNXRUjueQj+.2wrH1UmWkA9ZKC+JMpmCb161fTm6.jbpAoCJfz8cCIYrTcEGCd9B2QB3BIFCo55PoPVzdebe29RPBgtUBdA8zLf3JMZ9j1sO1G94nm1ng.RrJHIS8OKrSiOzvCx+Js+TRG+exenXFSPaQxnPj0KShiH1BglM7.I8BXQA+nePu99cBN1PiylofS9s.lHhdQvu2v6RvGdM7d3C+V+WHjS6rx9VBvCqP4LptuLIUJ.hlAVtAFUsu0RY3JzYRdeLmOEJIZJEVVkGW3ElfCv0ONWPzLovecYZRV4fi8eGlmSOpHJfPEbfHBJ5IigTLTs0rfOXzKab454nt0yQcuC4ntaIEAo+VFnfihdICLf.LQf4ZfWRYRx9AITMF9eUL1zZFSj3YCkt2HTJD3oE94ZAyiLAy1cb2s5XHEqjbZqzLl49qW+haOiKMNnaKCxtlC5dkCt6luaPUDU659Lol9JQyiLgEvw+5rhi2HuxBDNfqMw1LhJ61TroHOYJM6pxpRAgd30GLb3m1fARQOQMAkhQBl9UozR5Sk7HSCu48aNFAU1TYFnThPPTscbx8JGmDxYQzLDCLxm4Z6RPVvWevM50iFf03UlArH3kTZllYBFmAz2AC1KlR44NfpVnkoVYKayfMIa0oWT4vyOYYEwfST5klTygVAQIrnHNchTwLo9Zab9KnDJMj8dKx+vC9ym+2u+iOKo9RIDJAeQ8cTp73X1E1sIwLdhRCXaTBzqfb9F2Wqn9QzXbNW6qV.1AForfFctzJO5lCngUCxnbNVu99ByhwRFF.WeHsYPr.Bjk0A0cXIR6acIxmJDuu6DllLeyXbuMfQnN3+CLVt58qbGFGSI5J.df6o+5ttmcKt+Wj4ZlX1XLb0CEBtmkmDBewAgBdWHnbv3tN6Y5jJnaanMYfPX3pk3egmRlcLzNkL6rhITzQxjukTz+YVt+41S.LIreKiG7QU.s+FZ7fhc1aIj0M0MTr6tp3i1UEe7tp32sqJ9jcUwueWU7G1thlOE7my0xjh1FDZ7jg1AkNNCEXnBzVsh9O.XfrJTA
The knob's callback in the first namespace (NS1) triggers the first broadcaster (bc1), also in NS1. This is picked up by a listener in NS2 and NS3. The listener in NS2 triggers the second broadcaster (bc2) which is picked up by the listener in NS3. However BC2 is coming in to NS3 before BC1. What am I missing?
The namespaces aren't necessary to demonstrate the issue but they match the structure of my main project.
-
@d-healey to fully execute your second listener for bc1, it needs to completely execute bc2. That's how I'm interpreting it.
-
@aaronventure I don't think this is the case, I did an experiment and it seems the order is determined by the order in which the listeners are added. This is super annoying though as it means you have to be aware at all times you are adding a listener of what listeners have already been added.
I think a more logical solution is a broadcaster always sends to all its listeners regardless of if another listener was added to another broadcaster in between.
Basically, this works:
HiseSnippet 956.3ocsVstiSaDEdbx5BNzhJR7.L3e4UZUHNPADHDgbYQQPVhp2hpTUEZx3IIi1wyXYOgRnZ+U6KZeC5a.bFeI1YIraIpDo8x45224Lm4LYZhhxRSUIHKmSWGyPVeucvZod4fkDtDMdHx5l1SHoZVBNWU+0wjzTVHxxp4KLJrbN.k84eeVehfHorJUHzaTbJ6U7HttR6zdujKDGSBYmxip4886MlpjCTB0JfOMs6fhIzyHKXmPLt0vFY8ciB4ZURflnYoHqC5qBWGrT8Gxb+eCOkOSvLB9n.HQ4pOVIBML1nEMXIWDNsrtSQPVlV0EZl2Ets8DdHei9ptwOlY.WEQ89gUisoWysnmec50oF81AkrpQoCxozsrCnI7XckECetg8XIb3Lm.s85TI2WTi+po8.E3gT2NhbF63DPXSDdOnSmivvuN7IsZIglbJzvY3SB7a8msbfyhTMdF0G+T7H4Btj0llvfJqehhDRyFJ7Z4.d53xCceL1s+.ru6QFYRxhTPyu4xkgr2696sbNGvvokycu6cvuTpl4Wl+LA.gRVtfoGnhhURPvyMypqIzr+qcpwpTmnDCHBwLX7vSIyLUnNGEtT.zEOekjp4JIdae7nk.bD9cDwJ1g4UATp..xP3B.cBzhgIOub6PROu04a2i5VuG08qnG08xZQW.j6Y.ANOZa3FIL7UbHiRHmtlyEQgDFRI1MhoIveKKZur7ZJMng3.kdpRvZGmvM809Cx6pFHM.zE.n6EAn6F.95Se2MoGpnqt.7uDDL.TxvKd7j6B.B7SsS6STZ1qkdGZ5d.AvWzz746zVw7g.n2tLa1VkbYA5IWEMikrYppvQ3J716Er+x6Epu1hleknliJ4XIW+5Xl7KsLCUbOxrCofUfq5rMH2rXCRffGxRPbXQw0rytXfxHb881neY7PhlTlFHi.JwrDM2T.VCYuC1qmuXxwdHK8LsJNy2haVPQdkf99J.Os25Jgg8foh3.9GJYTu+4C+8yPe9JQXYrJbkfn2dCs4YoBCvwyVqEMq9job855Oa8+1Z6+qT7V1S4Z5xcywF6fivwv2BNV7X2OXOZ9bFUWQvCrO9W+17xF5mUqzb4hIDcBGF.rOYUT.7dOkAnKkLg45gUCyfbtbGiroCD.W8yD9H7ovnuQ1pvneoQTDglndKMe727b50yz.bRl8MIbfuRCHi2wbeD759aozsS0mEX28Mv6suAd+8MveZeC7A6afObeC7QWcflu70yWoUQ4WaPnISGksmxxZjj.SfYSqnOATwzIL.
But it's not compatible with my main project because of the namespace structure I'm using certain files are included before others (all after the broadcaster has been declared).
-
@d-healey If you rely on a certain order of execution, you can set a priority in the metadata object for each listener. From the docs:
https://docs.hise.audio/scripting/scripting-api/broadcaster/index.html (scroll down to Metadata)
This property is only valid when used with a listener item and defines the order of how the listeners are called. By default they are called by the order of the addListener call, but if that is not what you want, you can shuffle around the listeners by supplying a priority (higher priority values means that the items are moved up the list and the default value is 0 ).
const var bc = Engine.createBroadcaster({ "id": "funky", "args": ["value"] }); bc.addListener("", { id: "first callback", priority: 2 }, function(value) { Console.print("FIRST: " + value); }); bc.addListener("", { id: "second callback", priority: 1 }, function(value) { Console.print("SECOND: " + value); }); bc.sendSyncMessage(2);
-
@Christoph-Hart ah this looks perfect, thanks!
-
Yeah that solved it, woohoo!
-