HISE Logo Forum
    • Categories
    • Register
    • Login

    onNoteOn() - Illegal operation in audio thread: String creation (in HISE plugin only!?)

    Scheduled Pinned Locked Moved General Questions
    24 Posts 4 Posters 866 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.
    • d.healeyD
      d.healey @gorangrooves
      last edited by

      @gorangrooves Why you only get the error in the plugin I don't know.

      There are two threads, audio and message. The audio is the fast lane, and you want to keep it clear of slow moving traffic (like GUI stuff) so that you don't get audio dropouts. The message thread is the slow lane, here you can take your time.

      You should almost always defer your main interface script - defer means move everything in that script into the slow lane. This prevents the UI stuff from interfering with the audio thread. Use Synth.deferCallbacks(true); in on init.

      Anything you want to happen on the audio thread you put in a separate script.

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

      gorangroovesG 1 Reply Last reply Reply Quote 0
      • gorangroovesG
        gorangrooves @d.healey
        last edited by

        @d-healey Thanks for that explanation. Splitting my main script into several just to display these labels doesn't seem like a practical or even relevant solution. Everything has worked perfectly in the currently compiled plugins the way I have it set up, and the new stuff in the standalone. I don't even really know if there is any "audio" specific function in the Interface script that is not relevant to the GUI.

        The main playable functionalities are happening inside the samplers and their scripts anyway. The interface script deals with GUI, meters, sliders, and any action a user wants to take. Surely displaying a note played is relevant to the GUI and not to the audio performance side of a plugin. I would expect this to work in the interface onNoteOn/ onController.

        Do you know of another way I can set the labels with played-in notes without reshuffling everything else I have put together to date?

        If it works in the standalone, but not in the plugin, could this be a bug, @Christoph-Hart ? (Sorry if I screamed "bug" prematurely again. I'll be known as "that bug guy" 😂 ).

        Goran Rista
        https://gorangrooves.com

        Handy Drums and Handy Grooves
        https://library.gorangrooves.com

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

          @gorangrooves I don't think you need to split your script because it sounds like you're only using it for GUI purposes. So you just need to defer it.

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

          gorangroovesG 1 Reply Last reply Reply Quote 0
          • gorangroovesG
            gorangrooves @d.healey
            last edited by

            @d-healey I tried that, but it is not as simple as "just" 😬, as it opens up a can of worms in the form of new errors (Call of setNoteNumber() outside of midi event callback).

            So, going back to my original script, if I do something like this:

            *onNoteOn
            label.set("text", "Static text");
            

            It will work fine.

            However, as soon as we try to add this:

            label.set("text", "Dynamic text: " + Message.getNoteNumber()):
            

            all hell gets loose: Illegal operation in audio thread: String creation
            😭

            Goran Rista
            https://gorangrooves.com

            Handy Drums and Handy Grooves
            https://library.gorangrooves.com

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

              @gorangrooves Then perhaps you are doing stuff in the audio thread in your interface script and you'll need to do some re-arranging.

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

              gorangroovesG 1 Reply Last reply Reply Quote 0
              • gorangroovesG
                gorangrooves @d.healey
                last edited by

                @d-healey Nope. This is definitely a bug. YAY I finally found a real bug :lady_beetle:

                How do I know? I created a blank project with nothing more than a label. I set the label with MIDI in number onNoteOn. It works perfectly in the standalone, but not in the plugin HISE.

                Further, I compiled one of my plugins that get this error and it works as it should.

                I filed a bug report.
                It has the snippet, if you want to try it out.

                Goran Rista
                https://gorangrooves.com

                Handy Drums and Handy Grooves
                https://library.gorangrooves.com

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

                  There is a bug, but the bug is that it doesn't complain in the standalone version. You absolutely must not do this in the audio thread and the error that is reported is correctly.

                  I'll check why the AudioThreadGuard (yup, that's what it's called) isn't enabled in the standalone HISE version.

                  gorangroovesG 1 Reply Last reply Reply Quote 1
                  • gorangroovesG
                    gorangrooves @Christoph Hart
                    last edited by

                    @Christoph-Hart Damn it. I was hoping you were not going to say that. 😩

                    Goran Rista
                    https://gorangrooves.com

                    Handy Drums and Handy Grooves
                    https://library.gorangrooves.com

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

                      @gorangrooves But I don't think that this is a big problem. Can't you just defer the Interface script?

                      gorangroovesG 1 Reply Last reply Reply Quote 0
                      • gorangroovesG
                        gorangrooves @Christoph Hart
                        last edited by

                        @Christoph-Hart I tried that. Now I get:

                        Call of setNoteNumber() outside of midi event callback
                        

                        on the following line for my note audition buttons and mapping (onNoteOn):

                        Message.setNoteNumber(noteSources[arrayPos]);
                        

                        Full portion of that code:

                        arrayPos = noteTriggers.indexOf(Message.getNoteNumber());
                            if (arrayPos > -1)
                            {      
                               Message.setNoteNumber(noteSources[arrayPos]);  // yes so play its matching source note
                            }else{
                               Message.ignoreEvent(true); // no ignore it..
                            };
                        

                        If moving a controller, I get this:

                        Call of setControllerValue() outside of midi event callback
                        

                        for that infamous Table line I recently cried bug about:

                         if(Message.getControllerNumber() == 4)
                            {
                        	    UnifiedVari = Message.getControllerValue();
                        		
                        	    tv = Math.round(127 * (VarHatsControllerTable.getTableValue(UnifiedVari/127.0)));
                        	    Message.setControllerValue(tv);
                        	    
                        	    Console.print("table value: " + tv);
                            }
                        

                        If I could understand exactly what kind of script should go where, I could perhaps split them. It seems that only these two are throwing a fit.

                        What does this mean and what do I need to do, please?

                        Goran Rista
                        https://gorangrooves.com

                        Handy Drums and Handy Grooves
                        https://library.gorangrooves.com

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

                          You basically have two tasks in one function that cannot coexist:

                          • you can only change the note number in a synchronous callback
                          • you can only do UI stuff in a deferred callback

                          You'll need to untwist that into separate functions. Ideally anything that changes the note number is a separate script and the rest can stay in the main UI script.

                          gorangroovesG 1 Reply Last reply Reply Quote 0
                          • gorangroovesG
                            gorangrooves @Christoph Hart
                            last edited by

                            @Christoph-Hart Thank you!

                            So, lets say I create a script file called extra.js.

                            Inside it, I put the script relevant to the mapping (and anything else which may currently cause an error), including the relevant onNoteOn portion of the script.

                            I include the script in my project with

                            include("extra.js");
                            

                            before the line

                            Synth.deferCallbacks(true);
                            

                            And that should do the job?

                            Goran Rista
                            https://gorangrooves.com

                            Handy Drums and Handy Grooves
                            https://library.gorangrooves.com

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

                              @gorangrooves You need to put the audio stuff in a completely separate MIDI processor.

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

                              gorangroovesG 1 Reply Last reply Reply Quote 0
                              • gorangroovesG
                                gorangrooves @d.healey
                                last edited by

                                @d-healey So, I create a MIDI script processor for the Main Container (the sampler window) and put all of this there?

                                Goran Rista
                                https://gorangrooves.com

                                Handy Drums and Handy Grooves
                                https://library.gorangrooves.com

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

                                  @gorangrooves I can't say without being more familiar with your project.

                                  Anything that is not UI related needs to go into one or more separate MIDI processors.

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

                                  gorangroovesG 1 Reply Last reply Reply Quote 0
                                  • gorangroovesG
                                    gorangrooves @d.healey
                                    last edited by

                                    @d-healey Ok, but are we talking about the same thing? See the image, please.

                                    Desktop Screenshot 2022.10.25 - 16.24.56.23.png

                                    Goran Rista
                                    https://gorangrooves.com

                                    Handy Drums and Handy Grooves
                                    https://library.gorangrooves.com

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

                                      @gorangrooves Yes

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

                                      gorangroovesG 1 Reply Last reply Reply Quote 0
                                      • gorangroovesG
                                        gorangrooves @d.healey
                                        last edited by

                                        @d-healey Alright. Thank you. I'll give it a shot.

                                        Goran Rista
                                        https://gorangrooves.com

                                        Handy Drums and Handy Grooves
                                        https://library.gorangrooves.com

                                        gorangroovesG 1 Reply Last reply Reply Quote 0
                                        • gorangroovesG
                                          gorangrooves @gorangrooves
                                          last edited by gorangrooves

                                          I am getting nowhere with this. It is like a f'ing Rubik's cube 🥴
                                          Is anyone of you guys available 1-on-1 to help me with this? I'll compensate you fairly. I want to get this done asap and move on.

                                          Goran Rista
                                          https://gorangrooves.com

                                          Handy Drums and Handy Grooves
                                          https://library.gorangrooves.com

                                          LindonL 1 Reply Last reply Reply Quote 0
                                          • LindonL
                                            Lindon @gorangrooves
                                            last edited by Lindon

                                            @gorangrooves

                                            so you need to get this bit of code into your seperate midi processor - the one you've identified.

                                            arrayPos = noteTriggers.indexOf(Message.getNoteNumber());
                                                if (arrayPos > -1)
                                                {      
                                                   Message.setNoteNumber(noteSources[arrayPos]);  // yes so play its matching source note
                                                }else{
                                                   Message.ignoreEvent(true); // no ignore it..
                                                };
                                            

                                            so it wont know about noteSources, so you need a way to tell it - ahead of time when noteSources changes - or explicitly if its always the same.

                                            so either:

                                            declare noteSources in the midi processor init and populate it
                                            or
                                            make noteSources a global variable (not a great solution)
                                            or
                                            create a table in the MIDI processor that you can reference (and set) from your UI script

                                            HISE Development for hire.
                                            www.channelrobot.com

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

                                            55

                                            Online

                                            1.7k

                                            Users

                                            11.7k

                                            Topics

                                            101.8k

                                            Posts