HISE Logo Forum
    • Categories
    • Register
    • Login

    How do I load a midi script programmatically?

    Scheduled Pinned Locked Moved Scripting
    26 Posts 4 Posters 341 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.
    • O
      Orvillain
      last edited by

      I've not been able to figure this out. I want to load a script on disk into a midi processor. Anyone got a snippet for that??

      Ideally I'd have just one template script that I load into all of my midi processors. But if I have to write a specific one for each of them, I'm happy to do that too.

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

        @Orvillain Could you explain more what you want to do? I don't quite follow.

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

        O 1 Reply Last reply Reply Quote 0
        • O
          Orvillain @d.healey
          last edited by

          @d-healey

          I have a namespace that builds my module tree for me based on a JSON document I feed it. It will auto create the required samplers, effects routing, channel counts, and routing.

          Part of this procedure needs to be populating the midi processor for each sampler with a control script template.

          So I've got this:

          	local midi_processor = builder.create(
          						builder.MidiProcessors.ScriptProcessor,
          						sampler_name + "_midi_proc",
          						slot_data['module_index'],
          						builder.ChainIndexes.Midi);
          	
          	builder.connectToScript(midi_processor, "{PROJECT_FOLDER}/Scripts/midi_processor.js");
          

          However, it does not seem to work. The midi processor gets created, but it is completely blank. I have to load the script in manually, which I don't want to do.

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

            @Orvillain Ah ok, I haven't used the builder so I don't know what the solution is.

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

            O 1 Reply Last reply Reply Quote 0
            • O
              Orvillain @d.healey
              last edited by

              @d-healey No probs.

              This is what the docs says:
              26be5270-85f0-44ed-b9b1-1b0520a0d480-image.png

              So far as I can tell, I am doing this. But the script is not being loaded into the midi processor.

              @Christoph-Hart could there be a bug?

              Here is my midi_processor.js file:

              var test_var = "test";
              
              function onNoteOn()
              {
              	
              }
               function onNoteOff()
              {
              	
              }
               function onController()
              {
              	
              }
               function onTimer()
              {
              	
              }
               function onControl(number, value)
              {
              	
              }
               
              

              And here is my builder instruction:

              	local midi_processor = builder.create(
              						builder.MidiProcessors.ScriptProcessor,
              						sampler_name + "_midi_proc",
              						slot_data['module_index'],
              						builder.ChainIndexes.Midi);
              	
              	builder.connectToScript(midi_processor, "{PROJECT_FOLDER}/Scripts/ScriptProcessors/midi_processor.js");
              

              Here's a screenshot showing that the file is in the right path:
              0afbfd90-ebd8-47ca-9200-ad2cad387c92-image.png

              Don't know if I am misunderstanding something, haven't debugged something properly, or if I'm making a mistake. But so far as I can tell, the builder is definitely alive because everything else gets correctly setup. The only thing I can think is, there's something wrong with the path.

              1 Reply Last reply Reply Quote 0
              • rglidesR
                rglides
                last edited by

                I'm not sure I'm fully understanding, but this loads an empty MIDI in the player, is that what you want? This uses a button but you can easily just write it to work however

                const var MIDIPlayerSine = Synth.getMidiPlayer("MIDI Player Sine");
                
                
                const var midiCreate = Content.getComponent("midiCreate");
                inline function onmidiCreateControl(component, value)
                {
                if (value)
                    {
                        MIDIPlayerSine.clearAllSequences();        
                        MIDIPlayerSine.create(4, 4, 8);
                       } 
                
                };
                
                Content.getComponent("midiCreate").setControlCallback(onmidiCreateControl);
                
                
                O 1 Reply Last reply Reply Quote 0
                • O
                  Orvillain @rglides
                  last edited by

                  @rglides I don't think that is relevant really. I'm wanting to load a file on disk into a midi script processor. I'm not looking to clear a midi player. Thanks though!

                  rglidesR 1 Reply Last reply Reply Quote 0
                  • rglidesR
                    rglides @Orvillain
                    last edited by

                    @Orvillain I thought the issue was needing to load an empty (or predefined) file into the midi player via script rather than having to do it manually, sorry I totally misunderstood

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

                      The reference path doesn't need to include "/scripts/" as {PROJECT_FOLDER} will automatically go to the scripts folder.

                      Does midi_processor contain an index?

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

                      O 1 Reply Last reply Reply Quote 0
                      • O
                        Orvillain @d.healey
                        last edited by

                        @d-healey I bet you that's what it is! I bet it is looking inside:
                        PROJECT_FOLDER/Scripts/Scripts/ScriptProcessors/midi_processor.js

                        If the project folder flag automatically includes the scripts sub folder.

                        I will check and get back to you. Yes, midi_processor does have an index assigned to it.

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

                          @Orvillain said in How do I load a midi script programmatically?:

                          Yes, midi_processor does have an index assigned to it.

                          But is midi_processor itself an index? The documentation your posted indicates that first parameter is a buildIndex, and you're passing midi_processor.

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

                          O 1 Reply Last reply Reply Quote 0
                          • O
                            Orvillain @d.healey
                            last edited by

                            @d-healey Yes, because builder.create(blahblahblah) returns the build index. So midi_processor is the build index. Variable name could be clearer, I grant you.

                            1 Reply Last reply Reply Quote 1
                            • O
                              Orvillain
                              last edited by

                              There is DEFINITELY something funky with this. If I start a new project, add a sampler, add a midi script processor to it, and then right-click the script processor in the module tree, choose 'connect to external script' and choose my script, it also fails.

                              But then if I unload the external script, all of a sudden my test variable is then right there in the onInit method.

                              If I write a script in HISE manually, right-click and save as a new file... and then try and connect to that file... again... HISE fails to connect....

                              If I then disconnect, the new script is there.

                              @Christoph-Hart I'm 100% convinced this is a bug.

                              1 Reply Last reply Reply Quote 0
                              • O
                                Orvillain
                                last edited by

                                I made a video showing what happens when you just try to connect to an external script manually, not even using code.

                                It seems to be broken.

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

                                  @Orvillain That's the correct behaviour. Once you're connected to an external script you lose those tabs. The idea is if it's external you shouldn't be editing it in HISE - although you still can in the main code editor but I think that's a more recent feature.

                                  I made a video about this several years ago:

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

                                  O 1 Reply Last reply Reply Quote 0
                                  • O
                                    Orvillain @d.healey
                                    last edited by

                                    @d-healey Riiiiight. That seems very odd to me. HISE could at least draw in the scripts and make it read only, or otherwise indicate success. Because it looks broken to me, and is the same "symptom" as what I see when trying to connect a script in code.

                                    The only difference being when I try to connect a script in code, I get an error that says "onControl could not be parsed!"

                                    Hmmmmm. I guess I need to dig into this some more. Your tip about removing the "Scripts" folder from the path was a good one, but does not seem to have made any difference.

                                    But now that you've said what you've said... I'm wondering, how do I even confirm the script has been attached successfully? It looks exactly the same in the actual project:
                                    ae189414-edf9-4bd0-aa3b-d193f23191be-image.png

                                    And alllllll this time, I've been assuming it didn't work properly because of how empty it looks, and also because of the parse error in the log.

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

                                      @Orvillain If you add controls to your scripts interface they will show up in that blank area.

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

                                      1 Reply Last reply Reply Quote 1
                                      • O
                                        Orvillain
                                        last edited by

                                        Okay. I've gotten it to work by replacing the forward slash with a backslash. This is on Windows. I don't know if MacOS will cope with that???

                                        I was reasonably sure that even on Windows this should work?? It works for a bunch of other things, iirc.

                                        ad4392ad-3d1c-42e2-8704-c166d73f7820-image.png

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

                                          @Orvillain you are going to have to use different separators based on the OS in question
                                          fwd slash for mac os backslash for windows:

                                          Link Preview Image
                                          HISE | Docs

                                          favicon

                                          (docs.hise.dev)

                                          HISE Development for hire.
                                          www.channelrobot.com

                                          O d.healeyD 2 Replies Last reply Reply Quote 1
                                          • O
                                            Orvillain @Lindon
                                            last edited by

                                            @Lindon Thanks!

                                            Really sorry for the n00b question here. It was just boggling my mind, and I was making it a lot more complicated than it needed to be.

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

                                            20

                                            Online

                                            1.7k

                                            Users

                                            11.8k

                                            Topics

                                            102.5k

                                            Posts