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.

170 lines
3.8KB

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