{"id":11,"date":"2019-10-04T21:44:50","date_gmt":"2019-10-04T21:44:50","guid":{"rendered":"http:\/\/metajack.org\/blog\/?p=11"},"modified":"2019-10-05T04:15:42","modified_gmt":"2019-10-05T04:15:42","slug":"deeply-diving-into-the-performer-generator-code","status":"publish","type":"post","link":"https:\/\/metajack.org\/blog\/2019\/10\/04\/deeply-diving-into-the-performer-generator-code\/","title":{"rendered":"Deeply diving into the Performer Generator Code"},"content":{"rendered":"\n<p>I don&#8217;t ask for much in life. &#8220;Just a bed and a Bible&#8221; as a man once said. But beyond the basics I do crave effective randomization for my sequencer. The Westlicht performer actually provides quite a bit in this regard. However within the many options, I found myself needing basic, quick randomization. The following is my journey to add that feature.<\/p>\n\n\n\n<p>After getting a basic compile of the sequencer to work (see <a href=\"http:\/\/metajack.org\/blog\/2019\/10\/04\/getting-started-developing-for-the-westlicht-performer\/\">http:\/\/metajack.org\/blog\/2019\/10\/04\/getting-started-developing-for-the-westlicht-performer\/<\/a>) I decided to work backwards. Update the UI and then fill the features in. This also will hopefully help me better find the code I need to modify.<\/p>\n\n\n\n<p>I&#8217;m writing this after a brief session of digging and upon reflection I would recommend one at least goes through the directories to get a feel of the organization. Me? I dug right in with find and grep. It worked but I should have took a more civilized look at the code first.<\/p>\n\n\n\n<p>I started with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ pwd\n\/Users\/jack\/performer-sequencer\/performer\/src\n$ find . -type f -exec grep -q \"Euclidean\" {} \\; -print\n.\/apps\/sequencer\/CMakeLists.txt\n.\/apps\/sequencer\/engine\/generators\/EuclideanGenerator.cpp\n.\/apps\/sequencer\/engine\/generators\/EuclideanGenerator.h\n.\/apps\/sequencer\/engine\/generators\/Generator.cpp\n.\/apps\/sequencer\/engine\/generators\/Generator.h\n.\/apps\/sequencer\/ui\/pages\/GeneratorPage.cpp\n.\/apps\/sequencer\/ui\/pages\/GeneratorPage.h<\/code><\/pre>\n\n\n\n<p>At first it appears that each generator type has a class but inspecting Generator.h shows some code involving both types (or at least the selecting between them). Not sure if this is purposeful or not.<\/p>\n\n\n\n<p>First though, let&#8217;s make a minor tweak and make sure things work as we expect. Let&#8217;s modify a bit of UI, compile and test:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ find . -type f -exec grep -q \"Seed\" {} \\; -print\n.\/apps\/sequencer\/engine\/generators\/RandomGenerator.cpp\n.\/apps\/sequencer\/engine\/generators\/RandomGenerator.h\n.\/platform\/sim\/libs\/args\/catch.hpp\n.\/platform\/sim\/libs\/soloud\/doc\/sfxr.mmd\n.\/platform\/sim\/libs\/soloud\/include\/soloud_c.h\n.\/platform\/sim\/libs\/soloud\/include\/soloud_sfxr.h\n.\/platform\/sim\/libs\/soloud\/src\/audiosource\/sfxr\/soloud_sfxr.cpp\n.\/platform\/sim\/libs\/soloud\/src\/c_api\/soloud_c.cpp\n.\/platform\/stm32\/libs\/libopencm3\/include\/libopencm3\/stm32\/common\/rng_common_v1.h<\/code><\/pre>\n\n\n\n<p>I had hoped keeping &#8220;Seed&#8221; case-sensitive would lesson the matches. Inspecting  RandomGenerator.cpp :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>emacs .\/apps\/sequencer\/engine\/generators\/RandomGenerator.cpp<\/code><\/pre>\n\n\n\n<p>yields up :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const char *RandomGenerator::paramName(int index) const {\n    switch (Param(index)) {\n    case Param::Seed:   return \"Seed\";\n    case Param::Smooth: return \"Smooth\";\n    case Param::Bias:   return \"Bias\";\n    case Param::Scale:  return \"Scale\";\n    case Param::Last:   break;\n    }\n    return nullptr;\n}\n<\/code><\/pre>\n\n\n\n<p>We&#8217;ll change &#8220;Seed&#8221; to &#8220;Gene&#8221; then compile and run :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..\/build\/sim\/debug\nmake -j\n.\/src\/apps\/sequencer\/sequencer<\/code><\/pre>\n\n\n\n<p>and indeed our change is there. Undo our change and set about how to add our own option&#8230;<\/p>\n\n\n\n<p>Generator.cpp seems to be where we call our new custom Generator but how to add to the UI? Generator.h has the text for the modes. If we add a line for ours (let&#8217;s call our mode &#8220;Quick Random&#8221;) :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   static const char *modeName(Mode mode) {\n\tswitch (mode) {\n        case Mode::Euclidean:   return \"Euclidean\";\n        case Mode::Random:      return \"Random\";\n        case Mode::QuickRandom:      return \"Quick Random\";\n        case Mode::Last:        break;\n\t}\n<\/code><\/pre>\n\n\n\n<p>and compile we&#8217;ll get an error &#8211; we&#8217;ve not defined QuickRandom. What if we copy and existing mode and rename it QuickRandom?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ cp RandomGenerator.h QuickRandomGenerator.h\n$ cp RandomGenerator.cpp QuickRandomGenerator.cpp<\/code><\/pre>\n\n\n\n<p>If we just rename the class, we&#8217;ll stick get an error when compiling. Need to check the errors and add a few more things in Generator.cpp<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># add (keeping the string hash\/pound symbol as it is a compiler directive\n#include \"QuickRandomGenerator.h\"\n\n# modify\nstatic Container&lt;EuclideanGenerator, RandomGenerator, QuickRandom> generatorContainer;\n\n# add\ncase Mode::QuickRandom:\n        return generatorContainer.create&lt;QuickRandomGenerator>(builder);<\/code><\/pre>\n\n\n\n<p>and in Generator.h<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public:\n    enum class Mode {\n        Euclidean,\n        Random,\n        QuickRandom,\n        Last\n    };\n<\/code><\/pre>\n\n\n\n<p>still not compiling &#8230;. did a few more things &#8230;<\/p>\n\n\n\n<p>Finally add your files to cmakeList.txt so that the files you add are compiled and linked<\/p>\n\n\n\n<p>After all this, got it working and we now have a new Generator menu item. For now our generator does the same thing as the one we copied. We&#8217;ll work on that next.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t ask for much in life. &#8220;Just a bed and a Bible&#8221; as a man once said. But beyond the basics I do crave effective randomization for my sequencer. The Westlicht performer actually provides quite a bit in this regard. However within the many options, I found myself needing basic, quick randomization. The following &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/metajack.org\/blog\/2019\/10\/04\/deeply-diving-into-the-performer-generator-code\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Deeply diving into the Performer Generator Code&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/11","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":2,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metajack.org\/blog\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}