Code Snippet - New SampleMap Broadcaster Attachment
-
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:
After a SampleMap has loaded: