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.

179 lines
3.8KB

  1. #include "app.hpp"
  2. #include "gui.hpp"
  3. #include "engine.hpp"
  4. namespace rack {
  5. struct NewItem : MenuItem {
  6. void onAction() {
  7. gRackWidget->clear();
  8. }
  9. };
  10. struct OpenItem : MenuItem {
  11. void onAction() {
  12. gRackWidget->openDialog();
  13. }
  14. };
  15. struct SaveItem : MenuItem {
  16. void onAction() {
  17. gRackWidget->saveDialog();
  18. }
  19. };
  20. struct SaveAsItem : MenuItem {
  21. void onAction() {
  22. gRackWidget->saveAsDialog();
  23. }
  24. };
  25. struct FileChoice : ChoiceButton {
  26. void onAction() {
  27. Menu *menu = gScene->createMenu();
  28. menu->box.pos = getAbsolutePos().plus(Vec(0, box.size.y));
  29. menu->box.size.x = box.size.x;
  30. {
  31. MenuItem *newItem = new NewItem();
  32. newItem->text = "New";
  33. menu->pushChild(newItem);
  34. MenuItem *openItem = new OpenItem();
  35. openItem->text = "Open";
  36. menu->pushChild(openItem);
  37. MenuItem *saveItem = new SaveItem();
  38. saveItem->text = "Save";
  39. menu->pushChild(saveItem);
  40. MenuItem *saveAsItem = new SaveAsItem();
  41. saveAsItem->text = "Save As";
  42. menu->pushChild(saveAsItem);
  43. }
  44. }
  45. };
  46. struct PauseItem : MenuItem {
  47. void onAction() {
  48. gPaused = !gPaused;
  49. }
  50. };
  51. struct SampleRateItem : MenuItem {
  52. float sampleRate;
  53. void onAction() {
  54. gSampleRate = sampleRate;
  55. }
  56. };
  57. struct SampleRateChoice : ChoiceButton {
  58. void onAction() {
  59. Menu *menu = gScene->createMenu();
  60. menu->box.pos = getAbsolutePos().plus(Vec(0, box.size.y));
  61. menu->box.size.x = box.size.x;
  62. PauseItem *pauseItem = new PauseItem();
  63. pauseItem->text = gPaused ? "Resume Engine" : "Pause Engine";
  64. menu->pushChild(pauseItem);
  65. float sampleRates[] = {44100, 48000, 88200, 96000, 176400, 192000};
  66. int sampleRatesLen = sizeof(sampleRates) / sizeof(sampleRates[0]);
  67. for (int i = 0; i < sampleRatesLen; i++) {
  68. SampleRateItem *item = new SampleRateItem();
  69. item->text = stringf("%.0f Hz", sampleRates[i]);
  70. item->sampleRate = sampleRates[i];
  71. menu->pushChild(item);
  72. }
  73. }
  74. void step() {
  75. text = stringf("%.0f Hz", gSampleRate);
  76. }
  77. };
  78. Toolbar::Toolbar() {
  79. float margin = 5;
  80. box.size.y = BND_WIDGET_HEIGHT + 2*margin;
  81. float xPos = 0;
  82. xPos += margin;
  83. {
  84. ChoiceButton *fileChoice = new FileChoice();
  85. fileChoice->box.pos = Vec(xPos, margin);
  86. fileChoice->box.size.x = 100;
  87. fileChoice->text = "File";
  88. addChild(fileChoice);
  89. xPos += fileChoice->box.size.x;
  90. }
  91. xPos += margin;
  92. {
  93. SampleRateChoice *srChoice = new SampleRateChoice();
  94. srChoice->box.pos = Vec(xPos, margin);
  95. srChoice->box.size.x = 100;
  96. addChild(srChoice);
  97. xPos += srChoice->box.size.x;
  98. }
  99. xPos += margin;
  100. {
  101. wireOpacitySlider = new Slider();
  102. wireOpacitySlider->box.pos = Vec(xPos, margin);
  103. wireOpacitySlider->box.size.x = 150;
  104. wireOpacitySlider->label = "Cable opacity";
  105. wireOpacitySlider->precision = 0;
  106. wireOpacitySlider->unit = "%";
  107. wireOpacitySlider->setLimits(0.0, 100.0);
  108. wireOpacitySlider->setDefaultValue(50.0);
  109. addChild(wireOpacitySlider);
  110. xPos += wireOpacitySlider->box.size.x;
  111. }
  112. xPos += margin;
  113. {
  114. wireTensionSlider = new Slider();
  115. wireTensionSlider->box.pos = Vec(xPos, margin);
  116. wireTensionSlider->box.size.x = 150;
  117. wireTensionSlider->label = "Cable tension";
  118. // wireTensionSlider->unit = "";
  119. wireTensionSlider->setLimits(0.0, 1.0);
  120. wireTensionSlider->setDefaultValue(0.5);
  121. addChild(wireTensionSlider);
  122. xPos += wireTensionSlider->box.size.x;
  123. }
  124. /*
  125. xPos += margin;
  126. {
  127. cpuUsageButton = new RadioButton();
  128. cpuUsageButton->box.pos = Vec(xPos, margin);
  129. cpuUsageButton->box.size.x = 100;
  130. cpuUsageButton->label = "CPU usage";
  131. addChild(cpuUsageButton);
  132. xPos += cpuUsageButton->box.size.x;
  133. }
  134. */
  135. xPos += margin;
  136. {
  137. Widget *pluginManager = new PluginManagerWidget();
  138. pluginManager->box.pos = Vec(xPos, margin);
  139. addChild(pluginManager);
  140. xPos += pluginManager->box.size.x;
  141. }
  142. }
  143. void Toolbar::draw(NVGcontext *vg) {
  144. bndBackground(vg, 0.0, 0.0, box.size.x, box.size.y);
  145. bndBevel(vg, 0.0, 0.0, box.size.x, box.size.y);
  146. Widget::draw(vg);
  147. }
  148. } // namespace rack