HISE Logo Forum
    • Categories
    • Register
    • Login

    Simultaneous array access between UI and real-time processing

    Scheduled Pinned Locked Moved General Questions
    20 Posts 4 Posters 819 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.
    • ustkU
      ustk
      last edited by ustk

      @Christoph-Hart Is it safe to consider updating an array from the UI and reading it from real-time processing block simultaneously?

      Can't help pressing F5 in the forum...

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

        You might get some race conditions, but the worst you can expect is some UI flickering (assuming you read from the UI and write in the audio thread, the other way around it would be more critical).

        ustkU 2 Replies Last reply Reply Quote 0
        • ustkU
          ustk @Christoph Hart
          last edited by

          @Christoph-Hart Ouch... it is, in fact, the other way, writing from UI and reading from block processing... If not possible then how can we create an envelope on the UI and make it work in a script processor?

          Can't help pressing F5 in the forum...

          d.healeyD ustkU 2 Replies Last reply Reply Quote 0
          • d.healeyD
            d.healey @ustk
            last edited by

            @ustk said in Simultaneous array access between UI and real-time processing:

            If not possible then how can we create an envelope on

            How are you creating an envelope?

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

            ustkU 1 Reply Last reply Reply Quote 0
            • ustkU
              ustk @d.healey
              last edited by

              @d-healey With a panel and a lot of caffeine :)

              Can't help pressing F5 in the forum...

              1 Reply Last reply Reply Quote 1
              • ustkU
                ustk @ustk
                last edited by

                @Christoph-Hart Bumpy bump :)
                About UI writing an array while process reading it?

                Can't help pressing F5 in the forum...

                Casey KolbC 1 Reply Last reply Reply Quote 1
                • Casey KolbC
                  Casey Kolb @ustk
                  last edited by

                  @ustk I'm doing this too and I think it does occasionally crash the plugin if you catch it in the wrong moment.

                  Casey Kolb
                  Founder & CEO of Lunacy Audio
                  Composer | Producer | Software Developer

                  1 Reply Last reply Reply Quote 1
                  • ustkU
                    ustk @Christoph Hart
                    last edited by ustk

                    @Christoph-Hart What if I update the array in the noteOn, before the condition (isPlaying) that allows the processBlock to read it? Will the array be ready for the process function in time?

                    note on:

                    • update array
                    • isplaying -> true

                    then in the process:

                    • if isPlaying -> read the array

                    Safe enough?
                    I don't mind updating the array after a note is played...

                    Can't help pressing F5 in the forum...

                    1 Reply Last reply Reply Quote 0
                    • ustkU
                      ustk
                      last edited by

                      So I still get some rare errors when the process is reading the array, despite that the security is set after the array update in the noteOn, meaning the array has not finished updating when the process begins... That's bad... @Christoph-Hart How can I secure this?

                      Can't help pressing F5 in the forum...

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

                        Can you make a minimal example? There are a few synchronisation mechanisms built into HiseScript that allows locking multithreaded access, but I need to look at the exact use case here.

                        ustkU 2 Replies Last reply Reply Quote 0
                        • ustkU
                          ustk @Christoph Hart
                          last edited by

                          @Christoph-Hart Thanks, will do tomorrow morning ;)

                          Can't help pressing F5 in the forum...

                          1 Reply Last reply Reply Quote 0
                          • ustkU
                            ustk @Christoph Hart
                            last edited by ustk

                            @Christoph-Hart Here's a snippet of the principle. This is not throwing errors probably because of the simplicity of the thing, but imagine something bigger... A timer updates the array to keep the snippet simple.

                            HiseSnippet 1427.3oc4Xs0aaaCEVxIpn1cYXanEaOrGHJFJTPxLjxZ6Ff6kbuKX0MFwYsCnnnfVh1lKRjBTTYynn+w1Ka+T19Grm1qaGRJaIE6j5ZrrhsoGbDOWH+NmC4geJcD7.RZJWXYW+3QIDK62yo6Hlb3NCwTl0A6ZY+9NswoRh.YDs8nDbZJIzx1doGoDXWeYK8yu+vswQXV.oPjk0S4z.xiowTYgzNa9Mznn8wgjiowkr91adP.msCOhmA3YIGOqDbvI3AjmfUlUywx9J6ERkbQWIVRRsrWdad3ntC4+.yX+SoozdQD0.eqtvDYDuOOJTgX06V6LjFE1YbbmZYY6zoHKrjIKbcm1zP5D4EYiOPq.U3Q47gcsKBd9KH7rKAukMv6Cc5FHnIxBMJrcMmCXP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KSGeUR.kIpY7rbgQJxf5R8Rq34xjaZmyqpmu2uAtdWNL5NK+sJabJ3ZUNwMEctEif2T74llb4kJCu5i6Z1kpNQrG6TRDLA5NOeTtPzXoU60zly3IC4LZk6jNhHEzACHUtpalsk1RJgOnoPx027HRDAmVhMvms4igdKXAzygbQcmWZ9Jyy22PNyaP9DGCbMcg+uAq2k9eOq2Kly.vn6eOU5O1AXYtARWtQu6q2GwyjPG+1Xna.vK14IYwcAJ8AD.wLFb0EHytlpUlYrmZrBNcIrP8f+DdxU5qFamqzerx+QViXbff+x.SWZUCiqpk.wMS++dqtSa0Xjuk9lHvOGuldVw.Q3WFDn1S+4P9Y19rwB3yWr.9b6Evm6r.9b2EvmubA74qtPeTeCxVYRdrY+OHnyd56HssMeSl9nf0eMg40aB
                            

                            The second one benefits from a little "safety" I've made. It consists of updating the real time array only when a note is played. but to me, it's a bit dirty to copy the original array this way... Well, you tell me...

                            HiseSnippet 1449.3oc4Xs0aaaCEVJNZnVcYXcnEaOrGHJFJTPxLjxZ6Ff6kbuKX0MFwYsCnnnfVh1lKRjFTTYynn+w1Ka+T1Og8zdc6PRYKoXmTWukUrM8fi34B424bHO7SosfGRRS4BK65GOZHwx98c5LhIGry.LkYcvtV1efSKbpjHPFQaOZHNMkDYYaW6QJA10W1R+7aObabLlERJDYY8TNMj7XZBUVHs8leCMNdebD4XZRIqu8lGDxY6vi4Y.dp43aMDGdBtO4IXkYK4XY+d6EQkbQGIVRRsrWdadznNC3+.yX+SooztwD0f.qNvDYDuOONRgX06V6LfFG0dbbmZYY6ztHKTyjEttSKZDch7hrwGpUfJ7nb9vdoKBdAKH7rKAukMv6ZNcBEzgxBMJrcUmCXPgpGFJAkgkwVqk9camc3fELYiD7Ij8EvfId3cWe+0Q2w2e0lttt8i4cwwnD.8XAIZKg.OBcezyeQS2JxZHHoDwoDu.ekmq.tBkvTI5Tr.Igpq.7ZOVeJizHTPfzhpjKNr62SBkdpkRaTiThTqXGbbbWnn60KiEJobl2pq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gjqu4QjXBNsD6hOayGC8pvBnGF4h51Wa9Jyy22jNyaj9DGCbMc0+uAK5Z+umE8EyAAXH9umJ8G6.rV2.oK2n2806i3YRnieKLzM.3Y67jrjNvmHDR.DyXvEbfL6kTsxLi8UiUvoCgEoG7GvStx.0X6bkAiU9OxZjfCE7WFZ5RqZXbEsDHtY5+Wd0cZoFiBrz2DA9432v2JAHV+xvP0d5OGxOy1mMV.e9hEvmau.9bmEvm6t.97kKfOe0E5i5aZ1JSxSL6+AAs2SeGoss4a7zGEr9SvJ57f3
                            

                            Please note that this is a time-variant processor, not an envelope, which makes all of that very dirty anyway to create a scripted envelope...
                            (I tried a DSP network in a scripted envelope with no success. But since I need to update it from the interface...)

                            Can't help pressing F5 in the forum...

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

                              it's a bit dirty to copy the original array this way... Well, you tell me...

                              Assigning an array to another variable doesn't copy the array, it just creates a reference to it:

                              var a = [1, 5, 6];
                              var b = a;
                              b[0] = 90;
                              Console.print(a[0]); // 90
                              

                              But yes if you would copy the array, you would have a problem because of allocations in the audio thread. The second problem is using a global variable for the array (I'd suggest using a slider pack in the modulator script processor and connect it to the main UI:

                              HiseSnippet 2274.3oc4Y80aaibDmzN75Yc0E8NjBzG5CDAEGjASEnjsrjfubmskkcrOaSEKewN4vgfUjqj1XJR4kqjC8gf1OS8w9R6Gk9QnO0WamYWJQpDaGG0SsEs7AZMytyN+l+rC2cbSdnKMJJjqouzowCnZ5+biVwAhd06QXAZ6uil9uv3HRjfxMUr1Nd.IJh5ooqu3dHC8kdfl74u8MaS7IAtzTVZZOOj4ROj0mIR41byuk46uKwidJqelYu1l66FFTOzObHfmEMr0FPbufzkdLAm1BFZ5eRCOlHj2RPDzHM8GrcnWbqdgWEnl+yYQr19TjnnVKXgTr2Mz2CQLxUqdOluWyw1cjlltQyTuvhJuvCMNh4wlvO0a7KkCXlJQV+g9B2E7J9ggm8MAO8Lv6AJ384Fsb4rAhz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f.2O73Dk7brYapkaE.pikTxvxZijlkhuoPfX5wUQrkjLKVv17q+ZSkIMFsicUuuMOkSIa2RURlMCPvGBI.KkQi2Z6TeegSRetco+.Mb8irsp4teUJltIp1ZSkLkkcpiKk6XuUZOXm3CxNoTC6F3lx5t5e6LcB1rkkWZbY4VLbOQifQTeXAjk49hDlli4NcgsiBCBGzKLf4l8ynmPEbV2tzo9T4MVCbKg.On7DNObySn9TRTlSS7a27PnDBgCkxnymx+52yOQ8qMTvUUx++MN07h+e+olu6Ck.mH7+BhzmDNT.UJOh.6qfSnZfeyANbsKEfZP.TxGO8vBXQAEsMRi.pEMvSR7OfmjAKN4nFvfEGO3+VzQehKO7Utppa3VuOUxAr6.4+33kLNBoMS+uKYXWvVqObl0W45hYG+Nv+byxTZFjY0YPl0lAYJOCxr9LHSkYPlp2oL30E1ZnHruJ+GXzrg7qM55paGI2Jn8OQNPgV2
                              

                              You are of course free to change the slider pack values through a custom panel if you want a special UI, but unless you change the size of the slider pack you should be fine (if you change the envelope during playback it might use the start of the previous envelope, but that shouldn't be too critical).

                              d.healeyD ustkU 2 Replies Last reply Reply Quote 2
                              • d.healeyD
                                d.healey @Christoph Hart
                                last edited by

                                Assigning an array to another variable doesn't copy the array, it just creates a reference to it:

                                @ustk https://www.youtube.com/watch?v=inpAs00hWHw

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

                                1 Reply Last reply Reply Quote 1
                                • ustkU
                                  ustk @Christoph Hart
                                  last edited by ustk

                                  @Christoph-Hart Yep sorry I forgot to clone() in the snippet but it is in my actual project... Is there a reasonable limit not to reach for a slider pack? I actually have a resolution of 1024 for my envelope (which is not too big considering an envelope time of 3 seconds, it gives approximately 3ms/step

                                  Can't help pressing F5 in the forum...

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

                                    Yeah, don't clone anything in an onNoteOn callback - the audio thread guard should prevent you from doing so anyway.

                                    1024 should be fine - it might just not get displayed anymore on a slider pack because the width of a slider will be less than a pixel.

                                    ustkU 1 Reply Last reply Reply Quote 1
                                    • ustkU
                                      ustk @Christoph Hart
                                      last edited by ustk

                                      @Christoph-Hart Yeah cool ;)
                                      I don't need to display the slider pack anyway... So what if I register an spData as global so I can directly set it without the need of a component? Or is it better to keep a hidden component and not have a global?

                                      Can't help pressing F5 in the forum...

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

                                        @ustk Use the component and it will saveInPreset (if you need that).

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

                                        ustkU 1 Reply Last reply Reply Quote 0
                                        • ustkU
                                          ustk @d.healey
                                          last edited by

                                          @d-healey No my system that sets all values is already saved in presets, I just need the best way to make those values readable from the real-time processor ;) By best way I mean safe (now it is) and cpu friendly

                                          Can't help pressing F5 in the forum...

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

                                            Whenever you can avoid using globals, go for it and in this case a hidden UI element is the better option.

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

                                            40

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            102.0k

                                            Posts