HISE Logo Forum
    • Categories
    • Register
    • Login

    Code Snippet - New SampleMap Broadcaster Attachment

    Scheduled Pinned Locked Moved Scripting
    1 Posts 1 Posters 148 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.
    • clevername27C
      clevername27
      last edited by clevername27

      We can use a Panel callback to alert us when a SampleMap has finished loading. But the timing isn't perfect, and might indicate to us that loading is complete when it isn't (yet).

      Enter the new SampleMap attachment. It fixes the above problem, and enables lots of other stuff.

      Here's how to replace the Callback to learn when a SampleMap has finished loading into a specific Sampler.


      1. Create the Broadcaster

      We specify the Broadcaster's name and signature. You can use any strings for these four parameters — just keep it consistent.

      const var sampleMapBroadcaster = Engine.createBroadcaster({
      	id: "sampleMapListener",
      	args: ["samplerId", "eventType", "data"]
      });
      

      2. Attach our Broadcaster to Receive SampleMap-related Messages

      sampleMapBroadcaster.attachToSampleMap("Sampler", "SampleMapChanged", "");
      
      • Parameter 1: "Sampler" is the raw ID of the sampler as listed in your module tree.
      • Parameter 2: "SampleMapChanged" is the type of message we want to be broadcast.
      • Parameter 3: Not needed.

      3. Add the Listener, Do Something Useful

      sampleMapBroadcaster.addListener("SampleMap Name", "sampleMapListener", function(eventType, samplerId, data) {
      	Console.print("Samplemap Changed: " + data);
      });
      
      • Field 1: Optional. In my case, I'm using the string for documentation in HISE's Broadcaster graph. You can also use empty quotes.
      • Field 2: The ID we defined for the Broadcaster.
      • Field 3: An anonymous function that gets called when the Listener receives a message. Ensure your signature matches the Broadcaster! The data field is where the message comes through.

      Usage

      In this example, when a SampleMap loads into the Sampler we specified, the name of the SampleMap is printed to the console.


      HISE Broadcaster Map

      Before any SampleMaps load:
      4c05471c-7b20-41c3-9328-e332aa6cb331-image.png

      After a SampleMap has loaded:

      f86b2081-76c1-4eff-8114-9b521bf0d4f0-image.png

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

      34

      Online

      1.7k

      Users

      11.7k

      Topics

      102.1k

      Posts