<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How should I implement a common method in multiple namespaces]]></title><description><![CDATA[<p dir="auto">Let's say I have A B C three articulations, and each with a namespace implementing a RR count (using namespace because it's local to a script).</p>
<p dir="auto">I want to use the getNextRR() method in the corresponding namespace based on Message.getChannel(), because each is implemented differently. How should I approach this?</p>
<p dir="auto">The problem is that we can't add namespaces themselves to a list, only methods from namespaces.</p>
<p dir="auto">I can think of three ways to make this work, but each with drawbacks.</p>
<ol>
<li>
<p dir="auto">The simplest way is to use a switch condition, it works fine but lots of code for each method, plus switch in Javascript is not performance friendly.</p>
</li>
<li>
<p dir="auto">Keep only the RR count in namespace, and implement another set of objects with corresponding methods calling Namespace.RR. Methods from objects work, but this method is convoluted and I'm not sure how it performs.</p>
</li>
<li>
<p dir="auto">Implement an object within each namespace itself, then use an const var array for calling based on index, mainly because array[index] is faster than switch in Javascript.<br />
So for each namespace we add a reg methods = {"method1": method1, "method2": method2...}, then in the main script const var articulations = [A.methods, B.methods...], and you call by using articulations[index]<a>"method1"</a>.<br />
However this doesn't work all the time lol. It compiles, but  calling methods this way doesn't trigger Console.print() in them, and returns the wrong value when the method tries to retrieve values from a global array.</p>
</li>
</ol>
<p dir="auto">So what should I do about this?</p>
]]></description><link>https://forum.hise.audio/topic/5055/how-should-i-implement-a-common-method-in-multiple-namespaces</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 00:59:34 GMT</lastBuildDate><atom:link href="https://forum.hise.audio/topic/5055.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Dec 2021 09:39:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How should I implement a common method in multiple namespaces on Thu, 09 Dec 2021 03:41:43 GMT]]></title><description><![CDATA[<p dir="auto">@d-healey okay thanks for the reminder.<br />
I refactored the script like you said and used a switch condition <img src="https://forum.hise.audio/assets/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f602.png?v=fba14f4754a" class="not-responsive emoji emoji-emoji-one emoji--face_with_tears_of_joy" style="height:23px;width:auto;vertical-align:middle" title=":face_with_tears_of_joy:" alt="😂" /></p>
]]></description><link>https://forum.hise.audio/post/45088</link><guid isPermaLink="true">https://forum.hise.audio/post/45088</guid><dc:creator><![CDATA[RCJacH]]></dc:creator><pubDate>Thu, 09 Dec 2021 03:41:43 GMT</pubDate></item><item><title><![CDATA[Reply to How should I implement a common method in multiple namespaces on Wed, 08 Dec 2021 09:51:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.hise.audio/uid/80">@rcjach</a> make a separate script to handle rrs and another one to handle articulations. You don't need a namespace per articulation, namespace aren't classes.</p>
]]></description><link>https://forum.hise.audio/post/45020</link><guid isPermaLink="true">https://forum.hise.audio/post/45020</guid><dc:creator><![CDATA[David Healey]]></dc:creator><pubDate>Wed, 08 Dec 2021 09:51:00 GMT</pubDate></item></channel></rss>