这是我从Plugin.cpp
编译的代码的一部分:
...
addParam(MyModuleWidget::create<MyModuleButton>(Vec(10, 10), module, this, ParamEnum::RESET_PARAM, 0.0, 1.0, 0.0));
addParam(MyModuleWidget::create<MyModuleSwitch>(Vec(10, 10), module, this, ParamEnum::RUN_PARAM, 0.0, 1.0, 1.0));
addParam(MyModuleWidget::create<MyModuleKnob>(Vec(10, 10), module, this, ParamEnum::SEED_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleKnob>(Vec(10, 10), module, this, ParamEnum::CLOCK_SWING_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleKnob>(Vec(10, 10), module, this, ParamEnum::CLOCK_RANDOM_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleKnob>(Vec(10, 10), module, this, ParamEnum::CLOCK_OFFSET_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleKnob>(Vec(10, 10), module, this, ParamEnum::CLOCK_CURVE_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SECTION_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SECTION_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SECTION_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_2_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_2_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_3_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_3_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_3_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_4_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_4_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_4_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SECTION_4_STEP_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_2_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_2_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_3_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_3_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_3_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_4_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_4_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_4_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SECTION_4_STEP_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_2_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_2_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_3_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_3_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_3_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_4_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_4_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_4_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SECTION_4_STEP_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_2_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_2_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_3_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_3_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_3_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_4_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_4_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_4_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SECTION_4_STEP_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_SERIAL_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_SERIAL_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_SERIAL_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_SERIAL_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_1_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_5_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_6_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_7_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_8_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_9_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_10_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_11_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_12_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_13_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_14_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_15_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::SERIAL_STEP_16_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_DIV_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_DIV_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_DIV_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_DIV_2ND_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_DIV_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_DIV_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_DIV_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_DIV_2ND_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_DIV_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_DIV_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_DIV_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_DIV_2ND_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_DIV_2_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_DIV_3_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_DIV_4_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_DIV_2ND_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_LENGTH_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_LENGTH_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_LENGTH_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_LENGTH_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_LENGTH_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_LENGTH_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_LENGTH_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_LENGTH_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_VELOCITY_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_VELOCITY_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH1_VELOCITY_DIV_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_VELOCITY_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_VELOCITY_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH2_VELOCITY_DIV_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_VELOCITY_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_VELOCITY_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH3_VELOCITY_DIV_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_VELOCITY_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_VELOCITY_VAR_PARAM, 0.0, 1.0, 0.5));
addParam(MyModuleWidget::create<MyModuleSlider>(Vec(10, 10), module, this, ParamEnum::CH4_VELOCITY_DIV_PARAM, 0.0, 1.0, 0.5));
...
在另一个MyModuleWidget.cpp
文件上,如果我编写此*create
函数,则需要花费2-3秒的时间来编译两个文件:
struct MyModuleWidget {
//...
template <class T = MyModuleWidget>
static T* create(Vec pos, MyModuleModule *MyModuleModule, MyModuleModuleWidget *MyModuleModuleWidget, int paramId, float minValue, float maxValue, float defaultValue) {
T *widget = ParamWidget::create<T>(pos, MyModuleModule, paramId, minValue, maxValue, defaultValue);
return widget;
}
};
但是,如果我改用它(请注意添加一行代码):
struct MyModuleWidget {
//...
template <class T = MyModuleWidget>
static T* create(Vec pos, MyModuleModule *MyModuleModule, MyModuleModuleWidget *MyModuleModuleWidget, int paramId, float minValue, float maxValue, float defaultValue) {
T *widget = ParamWidget::create<T>(pos, MyModuleModule, paramId, minValue, maxValue, defaultValue);
widget->nwkModule = nwkModule; // added line
return widget;
}
};
编译文件Plugin.cpp
花费了大约10(或更多)秒的时间。
这是怎么回事?为什么那行的编译时间更长?
注意:如果需要,这里是addParam函数
void ModuleWidget::addParam(ParamWidget *param) {
params.push_back(param);
addChild(param);
}
注意2:我注意到,如果在编译T
时使用3个不同的Plugin.cpp
,它会变“慢”。例如:如果我仅addParam
键入MyModuleKnob
和MyModuleSlider
,它的速度很快。如果以后再在那些MyModuleButton
上添加类型addParam
,它将变得很慢。