Getting a module's name or slug?

Hello! I could use some help. I’m trying to get a module’s slug from within a structure that inherits from “Module”, like so:


struct VoxglitchModule : Module
{
  VoxglitchModule()
  {
    std::string module_slug = {{ ???? }};

Although this is adjacent to my main question, it could be helpful to know that an actual module extends the Voxglitch module:

struct DigitalSequencer : VoxglitchModule
{

Thanks,
Bret

getModel()->slug

See VCV Rack API: rack::engine::Module Struct Reference

1 Like

Hmm… attempting to get the model from the base-class isn’t working.

plugin::Model *temp = getModel();
std::string slug = temp->slug; // this crashes

I did some troubleshooting, and it looks like getModel() is returning null:

plugin::Model *temp = getModel();

if(temp)
{
  std::string slug = temp->slug;  
}
else
{
  DEBUG("temp is false"); // this is output every time
}

I can work around this by moving the code outside of the classes constructor and into a new function, and calling that function from with the derived classes. No worries.

You can’t get the Model in the constructor, as it has not been assigned yet.

EDIT: The best that can be done is to store a reference to this in the ModuleWidget* and later in rendering code try to ->getModel(). At which point .name might also be valid.

I think it does in the browser at least, because the module isn’t actually initialized yet, so the call should be guarded with a check to see if getModel() returns null. But when placed in a patch it should probably work.

struct KModuleWidget : ModuleWidget {
	Model** hook;
};

and

hook = &ASSIGN_NAME(NAME);
//macro for the model var name
//inside extender of KModuleWidget constructor just after setModule 

and

std::string up = (*(m->hook))->name;
//m is a KModuleWidget intermediate struct/class