You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
3.5KB

  1. #if!defined EXTENDEDMODULEWIDGET_HPP
  2. #define EXTENDEDMODULEWIDGET_HPP
  3. #include <app.hpp>
  4. /*!
  5. \class ExtendedModuleWidget
  6. \brief Ease the widget setup.
  7. */
  8. class ExtendedModuleWidget : public rack::ModuleWidget
  9. {
  10. public:
  11. /*!
  12. \brief Create an input widget and add it to the module.
  13. \param pos Position of the graphic input slot
  14. \param inputId Input identifier
  15. \return Returns the new input port. Unlike rack::createInput, this method returns an
  16. instance of TInput instead of an instance of rack::Input, and the input port is
  17. direcly added to this using rack::ModuleWidget::addInput.
  18. \tparam TInput Type of input port.
  19. \code
  20. {
  21. rack::PJ301MPort* const input = this->createInput<rack::PJ301MPort>({30, 30}, YourModule::YOUR_INPUT_INDEX);
  22. // use input here...
  23. }
  24. \endcode
  25. */
  26. template <class TInput>
  27. TInput* createInput(rack::Vec const& pos, int const inputId)
  28. {
  29. assert( this->module != nullptr );
  30. TInput* const input = new TInput;
  31. input->box.pos = pos;
  32. input->module = this->module;
  33. input->type = rack::Port::INPUT;
  34. input->portId = inputId;
  35. rack::ModuleWidget::addInput(input);
  36. return input;
  37. }
  38. /*!
  39. \brief Create an output widget and add it to the module.
  40. \param pos Position of the graphic output slot
  41. \param outputId Output identifier
  42. \return Returns the new output port. Unlike rack::createOutput, this method returns an
  43. instance of TOutput instead of an instance of rack::Output, and the output port is
  44. direcly added to this using rack::ModuleWidget::addOutput.
  45. \tparam TOutput Type of output port.
  46. \code
  47. {
  48. rack::PJ301MPort* const output = this->createOutput<rack::PJ301MPort>({30, 30}, YourModule::YOUR_INPUT_INDEX);
  49. // use output here...
  50. }
  51. \endcode
  52. */
  53. template <class TOutput>
  54. TOutput* createOutput(rack::Vec const& pos, int const outputId)
  55. {
  56. assert( this->module != nullptr );
  57. TOutput* const output = new TOutput;
  58. output->box.pos = pos;
  59. output->module = module;
  60. output->type = rack::Port::OUTPUT;
  61. output->portId = outputId;
  62. rack::ModuleWidget::addOutput(output);
  63. return output;
  64. }
  65. /*!
  66. \brief Create a param widget and add it to the module.
  67. \param pos Position of the graphic param slot
  68. \param paramId Param identifier
  69. \param minValue The minimum value accepted
  70. \param maxValue The maximum value accepted
  71. \param defaultValue The default value
  72. \return Returns the new param port. Unlike rack::createParam, this method returns an
  73. instance of TParam instead of an instance of rack::Param, and the param port is
  74. direcly added to this using rack::ModuleWidget::addParam.
  75. \tparam TParam Type of param port.
  76. \code
  77. {
  78. rack::PJ301MPort* const param = this->createParam<rack::PJ301MPort>({30, 30}, YourModule::YOUR_INPUT_INDEX);
  79. // use param here...
  80. }
  81. \endcode
  82. */
  83. template <class TParam>
  84. TParam* createParam(rack::Vec const& pos, int const paramId, float const minValue, float const maxValue, float const defaultValue)
  85. {
  86. assert( this->module != nullptr );
  87. TParam* const param = new TParam;
  88. param->box.pos = pos;
  89. param->module = this->module;
  90. param->paramId = paramId;
  91. param->setLimits(minValue, maxValue);
  92. param->setDefaultValue(defaultValue);
  93. rack::ModuleWidget::addParam(param);
  94. return param;
  95. }
  96. template <class TLight>
  97. TLight* createLight(rack::Vec const& pos, int const lightId)
  98. {
  99. assert( this->module != nullptr );
  100. TLight* const light = new TLight;
  101. light->box.pos = pos;
  102. light->module = this->module;
  103. light->firstLightId = lightId;
  104. rack::ModuleWidget::addChild(light);
  105. return light;
  106. }
  107. };
  108. #endif