Calling child functions

  • In my instrument I have 3 samplers, each one has a function for setting up the key colours related to its own samples. On the master container's interface the user can change various settings which has the result of changing some of the keyboard colours. Rather than putting the keyboard colour script in the master containers script I think it would be better to call the child's function. This would keep things nicely encapsulated.

    The method I have of doing this is to store the child's function in a variable inside the Globals object. I'm happy with this method but I wanted to know if there is another or better way of doing this in HISE?

  • This works, but I would recommend using include statements and external files for boring function declarations.

    The problem with the global object is that the scripts get compiled top down. When the instrument is loaded and the main script is accessing a function at compiling which is not defined yet (because the sampler script isn't compiled yet), it won't call the function (because the name is undefined).

    And from a encapsulation point of view, it also might be better to put them in the main container script because then you'll have everything interface related at one place (that's how I am handling it): one main interface with deferred callbacks and multiple MIDI processor scripts at various places that are controlled by the main interface script.

  • That sounds like a good approach. I'm already finding the include statement useful for all the JSON stuff.

  • OK so I have a similar set up that defined by Dave, actually 4 samplers in containers, I would like to "direct" play_note to only specific containers, so holding the play_note activity at the sub-container level and calling it as a function would be really nice, in effect giving us an extensible encapsulation model. In this instance I'm attempting to get $EVENT_PAR_ALLOW_GROUP type functionality, but I could see how other stuff would work nicely this way. Still is there a way to get at least this $EVENT_PAR_ALLOW_GROUP functionality?

  • Sampler.setActiveGroup does the same thing IIRC.

    I can add the Synth.playNote function to child synth objects, although I have to be careful not to mess up the natural event flow with this...

  • OK great, so Sampler.setActiveGroup means all play-note commands just get pointed at the Active Group? AN "Group" is a pseudonym for Container?

  • Not quite. Think of the group as z-axis for the usual two dimensional mapping notenumber / velocity.

  • Coming from Kontakt I think of it this way, each sampler you use in HISE is essentially what you get when you have a single NKI in Kontakt. Each sampler can have groups, just like a Kontakt instrument, into which you can map your RR or dynamic layer samples.

Log in to reply