Skip to content

Commit

Permalink
Draw something to the display in the module browser.
Browse files Browse the repository at this point in the history
  • Loading branch information
RareBreeds committed Dec 2, 2021
1 parent 2c09e7f commit 27efa0f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
19 changes: 19 additions & 0 deletions src/EugeneModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/EugeneModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
11 changes: 3 additions & 8 deletions src/EugeneWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
47 changes: 47 additions & 0 deletions src/PolygeneModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 13 additions & 2 deletions src/PolygeneModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
};
34 changes: 13 additions & 21 deletions src/PolygeneWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -58,8 +55,8 @@ void PolygeneRhythmDisplay::drawLayer(const DrawArgs &args, int layer)
std::shared_ptr<Font> 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);
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -127,15 +119,15 @@ 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);
nvgArc(args.vg, 0.0f, 0.0f, radius, a0, a1, NVG_CW);
nvgStroke(args.vg);
}
}
++c;
}

nvgResetScissor(args.vg);
Expand All @@ -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();
Expand Down

0 comments on commit 27efa0f

Please sign in to comment.