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.

176 lines
3.9KB

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