How to pass a string between scripts?
-
Using setAttribute on a panel seems to work only with numbers, not strings or objects. I first tried using a global variable, but the order of the scripts appears to influence whether the variable is ready on init. Is there a recommended way to do this?
-
@Simon When you say "between scripts" do you mean between two separate MIDI processors? What are you trying to achieve?
-
Yes, between MIDI processors. A string needs to get generated in the audio thread, which is passed to the deferred Interface script to be displayed on screen. I know that sounds weird, but I promise it makes sense and is for a good reason :)
-
@Simon said in How to pass a string between scripts?:
and is for a good reason
Whatever it is you're doing it wrong :) Anything UI related should be done in the UI script.
Let's say you have a realtime script to change articulation based on key press (on note on), and when that happens you want to write some text on the UI. The solution is that you put the same (or similar) keyswitch checking code in your UI script and write the text you want. The two scripts work completely independently.
-
I could add "or object" to the title.
When the user clicks a button, a sequence about 100 steps long gets randomly generated in the audio thread, so it's ready even if the user is currently playing. The sequence should be represented on the UI.
At the moment the audio script makes a string, which it puts in a global variable. I suppose the better way to do this is to store the sequence object to a global variable and make the string in the UI script, but the question of how to get an object to another processor remains.
Or to use the setAttribute method, I could encode the sequence as a bunch of integers and put it in a sliderpack. Would that be preferable?
I'm used to PGS in Kontakt, so the added step of going through a UI control for script communication is definitely odd to adapt to.
-
@Simon said in How to pass a string between scripts?:
I suppose the better way to do this is to store the sequence object to a global variable
Global variable and better way don't go in the same sentence.
I don't know if you saw my Mariachi library but I have a guitar instrument in that with this fancy fretboard on the UI that shows the fingering of the chord being played in realtime.
I have two totally separate scripts, one that does the strumming, triggers notes in a sequence, and the other that displays the fretboard. The two scripts do not communicate when a strum happens. The only link between them is during non-realtime when I establish that both have the same guitar tuning, hand position, etc.
Separate the UI from any realtime stuff. Imagine the two scripts have no way to communicate. This will make your project way more modular too and easier to debug/maintain.
-
@Simon said in How to pass a string between scripts?:
I could encode the sequence as a bunch of integers and put it in a sliderpack. Would that be preferable?
Possibly, without knowing the details of your project it's hard to give specific and detailed advice.
-
@d-healey Everything else about the two scripts is totally separated, but the sequence is randomly generated, so at some point a few hundred bits of data need to get from one script to the other. You could do RNG with a seed that you keep in sync in both scripts, but that's getting into time sink territory.
The global variable seems to work fine as long as the script that sets the variable comes first so I'll use that for now.
-
@Simon Ah I see, it's the random part that's the issue... ok now I understand. Sliderpack is the way to go I think. I'll just test something...
-
@Simon Ok there is a broadcaster that can watch the sliderpack in the realtime script and update the UI script, except it doesn't seem to work, or I'm using it wrong.
@Christoph-Hart Might need to check this, here is a test snippet
HiseSnippet 1353.3oc0W0saaaCElxIpnVccacX2N.Nek5Rfqchq+YcCq0NIsYqI1HNsccECELhT1rQhTihNMdE8cYOh6MX6PIYI4lrzVisKluvPj7bN767y2QGMRI8XwwRExx434QLj0mXOdtPOcvTBWf1eGj0WYGGvoLUDw6TOYX3LA2in4RglEqQ8mGQhiYTjk0ZOznhU00QI+9yenOIfH7XEagPOUx8XOlGx0E6N59+DOHXOBkcLOrjzst+9dRw.YfbF.u0rafLPfLgcHwHVEaziHwSQVeici61lw5rsOkR1daZ61s60sWqdMI9MZQNoY6ds1pUms51wGYcscobsTMVS.zCFsujNe7T4qEoWvS4w7SBXlEMQigaNcazfo7.5nEwpXDxZ8QEQt0Ribeo8AbJOe+hH3mmb.tPixAMqJWEjZ9Q.oJkfz5oP5V1i8T7HcwIF7bC68gjmxm.4lxPIUVTk4UrGXRuBc8Pxor8TvhbMba2nwlX3uaeOGm6bGbekjP8HwvwXJymK3lZCGHyEqwmQT3zpmQPp6ojfYrmQzdSAY+d7thIbAqtmhAddIy39FGLtFmV6aw0tbkqsoQBhZRLHyKpEsv6psInmfxN27vYFEp8qNuMCnDsl3MEqkX1YfqgMQHmK290Sk8X4.YXT.67cHZhasw4xVOK7XtFEQPkglmZX9q1x2lOWAgg.N3WBl5e75nzGmIhKDbqcDKNRJnwFvVP9vdSIhIrX3Z7mI7LgY2bWeSbhiuINwsusyabpBfLVFvpGo3Bsa592KIbrPcrTbnTyFJbSTv4sN328He+K8LS.PICB..eYGaHxpqRQWwrvSXpxv0HHT3tLa3ZeXrAuz7QIAkh8gJwgQrr06ICnlpbyyWj6fxRnvSOYeS1FnSVY6AxEwTZtANV6vNCZfkRtpZuCK9TsLBZgUv7ruJl20sSKWVh1c3rvhRK3Rrsr.brfLdy0xIiwL8iX7IS0tMuaF86qwmnEGkXyLJW9ZfgsPQn9p+LsFpWpczhx0lPglwH4xaLuaMd7AxPPGhZNHjVkTyrjLYYvAjffS..6JE4GmcjAZbQ.PtKm4eWobgWl.U4vcUtJf6iyJUcpVMMXwiYtlB2T+MNHZL62lwfWrj4wEjJSl6car7.A8H1DC6RMdIAcMd+BKjaykiZEZ.z+LILwklsyhdkzrth4yTGKSr8xXZQtZurnQ7EBOk7TSTvWpvtb.KMtGli+tx.r9DlNuhIFBLX9FaXBVkkARSoB7.nwMzVvkuI9.hdZ8z6w81.hpV0YIcR6tPSB0++oAg8+VMHtplBVUxPEHpNgd+oYz6TZEhSMb6zxaTBhKOzCJW60S09Kxztn7JwB2vNuFagQrs9LPepoij0Kra2pNq8zmsgvu9q6LuU29mML5vAm2y+UmJaMnQ+GoG97d+te2i6b7NaOt2dupwvGR687MTOT8icGL74SiFdDSp64OR+Kc3859L9vy2cvS1n9p01yDVxnv.Re+AlyM9iC3OyMOXBLk51rnuGpjM+vCWIl9OJaZzEmFBlCSRmEPzKOblYr0rCfRvkZMal5QDy0yKOV6GwDaMtxI19Pg3srGwgAEtbLV4Rvnoh8+.LlMm6Ms202m4oK.35168yq5Psumq+H4LMWLAZdo3ljro0G78.dL31EBVPx6KqXJaRW2XQ9eLSPSV7WvurCal+xU3vlKNDER7TxW5kRRMSRe8jc.LIR9Rip1GXViadQpcHLX+K87V1TWPwsVUE2dUUr0pp3cWUEaupJ1YUUr66WQy2c8fYZYXJsAgNXztI84rr1UPfJvjpUzeSDqxFF
-
Oh actually, since you're not using a button to generate the random sequence, as in my snippet, but the note number which both scripts can already see, you can just use a connected sliderpack on the UI and keep it simple.
Press middle C
HiseSnippet 1198.3oc6Ws0baSDEdkSDTanCTFdkYDY3AYbFWqXG43ojgj3jzZvI1sNMjAdnyZ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