diff --git a/src/EugeneModule.cpp b/src/EugeneModule.cpp index 20343c8..cdd2eb6 100644 --- a/src/EugeneModule.cpp +++ b/src/EugeneModule.cpp @@ -46,6 +46,25 @@ EugeneDisplayData RareBreeds_Orbits_Eugene::getDisplayData(void) return data; } +EugeneDisplayData RareBreeds_Orbits_Eugene::getDisplayData(RareBreeds_Orbits_Eugene *module) +{ + if(module) + { + return module->getDisplayData(); + } + else + { + EugeneDisplayData data; + data.length = rhythm::max_length; + data.hits = rhythm::max_length / 2; + data.shift = 0; + data.current_step = 0; + data.reverse = false; + data.invert = false; + return data; + } +} + unsigned int RareBreeds_Orbits_Eugene::readLength() { float value = params[LENGTH_KNOB_PARAM].getValue(); diff --git a/src/EugeneModule.hpp b/src/EugeneModule.hpp index bb0749c..d6148a7 100644 --- a/src/EugeneModule.hpp +++ b/src/EugeneModule.hpp @@ -85,4 +85,5 @@ struct RareBreeds_Orbits_Eugene : Module int getEOCMode(void); void setEOCMode(int eoc_mode); EugeneDisplayData getDisplayData(void); + static EugeneDisplayData getDisplayData(RareBreeds_Orbits_Eugene *module); }; diff --git a/src/EugeneWidget.cpp b/src/EugeneWidget.cpp index c0c636a..195c8a3 100644 --- a/src/EugeneWidget.cpp +++ b/src/EugeneWidget.cpp @@ -170,17 +170,12 @@ EugeneRhythmDisplay::EugeneRhythmDisplay(RareBreeds_Orbits_Eugene *module, Vec p void EugeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) { - if(!m_module) - { - return; - } - // Drawings to layer 1 don't dim when the room lights are dimmed if(layer == 1) { nvgGlobalTint(args.vg, color::WHITE); - EugeneDisplayData data = m_module->getDisplayData(); + EugeneDisplayData data = RareBreeds_Orbits_Eugene::getDisplayData(m_module); if(data != m_ub->m_data) { m_ub->m_data = data; @@ -194,13 +189,13 @@ void EugeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) RareBreeds_Orbits_EugeneWidget::RareBreeds_Orbits_EugeneWidget(RareBreeds_Orbits_Eugene *module) : OrbitsWidget(&config) { setModule(module); - beat_widget.m_module = &module->m_beat; - eoc_widget.m_module = &module->m_eoc; // Module may be NULL if this is the module selection screen if(module) { module->m_widget = this; + beat_widget.m_module = &module->m_beat; + eoc_widget.m_module = &module->m_eoc; } m_theme = m_config->getDefaultThemeId(); diff --git a/src/PolygeneModule.cpp b/src/PolygeneModule.cpp index 822d70e..343e3a3 100644 --- a/src/PolygeneModule.cpp +++ b/src/PolygeneModule.cpp @@ -203,6 +203,53 @@ void RareBreeds_Orbits_Polygene::Channel::onRandomize() m_invert = (random::uniform() < 0.5f); } +PolygeneDisplayData RareBreeds_Orbits_Polygene::getDisplayData(void) +{ + PolygeneDisplayData data; + data.active_channel_id = m_active_channel_id; + data.active_channels = m_active_channels; + for(int c = 0; c < PORT_MAX_CHANNELS; ++c) + { + auto ch = &data.channels[c]; + ch->length = m_channels[c].readLength(); + ch->hits = m_channels[c].readHits(ch->length); + ch->shift = m_channels[c].readShift(ch->length); + ch->variation = m_channels[c].readVariation(ch->length, ch->hits); + ch->invert = m_channels[c].readInvert(); + ch->current_step = m_channels[c].readStep(ch->length); + } + return data; +} + +PolygeneDisplayData RareBreeds_Orbits_Polygene::getDisplayData(RareBreeds_Orbits_Polygene *module) +{ + if(module) + { + return module->getDisplayData(); + } + else + { + PolygeneDisplayData data = {3, PORT_MAX_CHANNELS, + {{32, 6, 0, 0, 0, 4}, + {16, 9, 3, 0, 0, 0}, + {7, 3, 6, 0, 0, 5}, + {9, 7, 2, 0, 0, 3}, + {17, 4, 12, 0, 0, 14}, + {30, 20, 15, 0, 0, 20}, + {19, 4, 14, 0, 0, 10}, + {4, 2, 3, 0, 0, 2}, + {7, 1, 0, 0, 0, 6}, + {8, 5, 3, 0, 0, 1}, + {16, 10, 4, 0, 0, 4}, + {19, 16, 2, 0, 0, 18}, + {24, 20, 8, 0, 0, 14}, + {28, 14, 6, 0, 0, 20}, + {21, 12, 4, 0, 0, 4}, + {9, 3, 3, 0, 0, 7}}}; + return data; + } +} + RareBreeds_Orbits_Polygene::RareBreeds_Orbits_Polygene() { config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); diff --git a/src/PolygeneModule.hpp b/src/PolygeneModule.hpp index c8eb7c7..e776060 100644 --- a/src/PolygeneModule.hpp +++ b/src/PolygeneModule.hpp @@ -11,6 +11,15 @@ enum SyncMode SYNC_MODE_ALL_CHANNELS }; +struct PolygeneDisplayData +{ + unsigned int active_channel_id, active_channels; + struct + { + unsigned int length, hits, shift, variation, invert, current_step; + } channels[PORT_MAX_CHANNELS]; +}; + struct RareBreeds_Orbits_Polygene : Module { enum ParamIds @@ -79,8 +88,8 @@ struct RareBreeds_Orbits_Polygene : Module void init(RareBreeds_Orbits_Polygene *module, int channel); bool readReverse(void); bool readInvert(void); - bool isOnBeat(unsigned int length, unsigned int hits, unsigned int shift, unsigned int variation, - unsigned int beat, bool invert); + static bool isOnBeat(unsigned int length, unsigned int hits, unsigned int shift, unsigned int variation, + unsigned int beat, bool invert); unsigned int readLength(); unsigned int readStep(unsigned int length) { @@ -116,4 +125,6 @@ struct RareBreeds_Orbits_Polygene : Module void dataFromJson(json_t *root) override; void onRandomize(const RandomizeEvent& e) override; void onReset(const ResetEvent& e) override; + PolygeneDisplayData getDisplayData(void); + static PolygeneDisplayData getDisplayData(RareBreeds_Orbits_Polygene *module); }; diff --git a/src/PolygeneWidget.cpp b/src/PolygeneWidget.cpp index 4f184c2..d1d4dfb 100644 --- a/src/PolygeneWidget.cpp +++ b/src/PolygeneWidget.cpp @@ -28,14 +28,11 @@ void PolygeneRhythmDisplay::loadTheme(int theme) void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) { - if(!module) - { - return; - } - // Drawings to layer 1 don't dim when the room lights are dimmed if(layer == 1) { + PolygeneDisplayData data = RareBreeds_Orbits_Polygene::getDisplayData(module); + nvgGlobalTint(args.vg, color::WHITE); const auto foreground_color = color::WHITE; nvgStrokeColor(args.vg, foreground_color); @@ -58,8 +55,8 @@ void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) std::shared_ptr font = APP->window->loadFont(asset::plugin(pluginInstance, "res/fonts/ShareTechMono-Regular.ttf")); nvgFontFaceId(args.vg, font->handle); - const auto active_length = module->m_active_channel->readLength(); - const auto active_hits = module->m_active_channel->readHits(active_length); + const auto active_length = data.channels[data.active_channel_id].length; + const auto active_hits = data.channels[data.active_channel_id].hits; nvgText(args.vg, 0.f, -6.f, std::to_string(active_hits).c_str(), NULL); nvgText(args.vg, 0.f, 6.f, std::to_string(active_length).c_str(), NULL); nvgFill(args.vg); @@ -81,25 +78,20 @@ void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) nvgScale(args.vg, 1.0 - channel_width, 1.0 - channel_width); nvgStrokeWidth(args.vg, arc_stroke_width); - int c = 0; - for(auto &channel : module->m_channels) + for(unsigned int c = 0; c < PORT_MAX_CHANNELS; ++c) { - const auto length = channel.readLength(); - const auto hits = channel.readHits(length); - const auto shift = channel.readShift(length); - const auto variation = channel.readVariation(length, hits); - const auto invert = channel.readInvert(); + const auto length = data.channels[c].length; const auto radius = 1.0f - c * channel_width; const auto pi2_len = 2.0f * M_PI / length; const auto beat_gap = 0.06f; const auto len = pi2_len - beat_gap; NVGcolor dash_colour; - if(c == module->m_active_channel_id) + if(c == data.active_channel_id) { dash_colour = m_display_accent; } - else if(c < module->m_active_channels) + else if(c < data.active_channels) { dash_colour = nvgRGB(0xff, 0xff, 0xff); } @@ -113,7 +105,7 @@ void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) // The engine is run in a different thread, m_current_step is only updated on each clock // cycle so may not have been wrapped to a new length parameter yet. If the current step // is out of bounds then display it at 0. - auto current_step = channel.readStep(length); + auto current_step = data.channels[c].current_step; for(auto k = 0u; k < length; ++k) { const auto a0 = k * pi2_len + M_PI_2; @@ -127,7 +119,8 @@ void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) nvgFill(args.vg); } - auto on_beat = channel.isOnBeat(length, hits, shift, variation, k, invert); + auto on_beat = RareBreeds_Orbits_Polygene::Channel::isOnBeat(length, data.channels[c].hits, data.channels[c].shift, + data.channels[c].variation, k, data.channels[c].invert); if(on_beat) { nvgBeginPath(args.vg); @@ -135,7 +128,6 @@ void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer) nvgStroke(args.vg); } } - ++c; } nvgResetScissor(args.vg); @@ -149,13 +141,13 @@ RareBreeds_Orbits_PolygeneWidget::RareBreeds_Orbits_PolygeneWidget(RareBreeds_Or : OrbitsWidget(&config) { setModule(module); - beat_widget.m_module = &module->m_beat; - eoc_widget.m_module = &module->m_eoc; // Module may be NULL if this is the module selection screen if(module) { module->m_widget = this; + beat_widget.m_module = &module->m_beat; + eoc_widget.m_module = &module->m_eoc; } m_theme = m_config->getDefaultThemeId();