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.

874 lines
30KB

  1. /* Copyright 2013-2019 Matt Tytel
  2. *
  3. * vital is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * vital is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with vital. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "full_interface.h"
  17. #include "about_section.h"
  18. #include "bank_exporter.h"
  19. #include "bend_section.h"
  20. #include "delete_section.h"
  21. #include "extra_mod_section.h"
  22. #include "skin.h"
  23. #include "effects_interface.h"
  24. #include "fonts.h"
  25. #include "sound_engine.h"
  26. #include "keyboard_interface.h"
  27. #include "load_save.h"
  28. #include "master_controls_interface.h"
  29. #include "modulation_interface.h"
  30. #include "modulation_manager.h"
  31. #include "modulation_matrix.h"
  32. #include "modulation_meter.h"
  33. #include "wavetable_edit_section.h"
  34. #include "overlay.h"
  35. #include "portamento_section.h"
  36. #include "preset_browser.h"
  37. #include "synthesis_interface.h"
  38. #include "synth_gui_interface.h"
  39. #include "text_look_and_feel.h"
  40. #include "voice_section.h"
  41. FullInterface::FullInterface(SynthGuiData* synth_data) : SynthSection("full_interface"), width_(0), resized_width_(0),
  42. last_render_scale_(0.0f), display_scale_(1.0f),
  43. pixel_multiple_(1), setting_all_values_(false),
  44. unsupported_(false), animate_(true),
  45. enable_redo_background_(true),
  46. open_gl_(open_gl_context_) {
  47. full_screen_section_ = nullptr;
  48. Skin default_skin;
  49. setSkinValues(default_skin, true);
  50. default_skin.copyValuesToLookAndFeel(DefaultLookAndFeel::instance());
  51. bool synth = synth_data->wavetable_creators[0];
  52. if (synth) {
  53. synthesis_interface_ = std::make_unique<SynthesisInterface>(synth_data->mono_modulations,
  54. synth_data->poly_modulations);
  55. for (int i = 0; i < vital::kNumOscillators; ++i) {
  56. wavetable_edits_[i] = std::make_unique<WavetableEditSection>(i, synth_data->wavetable_creators[i]);
  57. addSubSection(wavetable_edits_[i].get());
  58. wavetable_edits_[i]->setVisible(false);
  59. wavetable_edits_[i]->setWaveFrameSlider(synthesis_interface_->getWaveFrameSlider(i));
  60. }
  61. addSubSection(synthesis_interface_.get());
  62. }
  63. effects_interface_ = std::make_unique<EffectsInterface>(synth_data->mono_modulations);
  64. addSubSection(effects_interface_.get());
  65. effects_interface_->setVisible(false);
  66. effects_interface_->addListener(this);
  67. master_controls_interface_ = std::make_unique<MasterControlsInterface>(synth_data->mono_modulations,
  68. synth_data->poly_modulations,
  69. synth);
  70. addSubSection(master_controls_interface_.get());
  71. master_controls_interface_->setVisible(false);
  72. if (synthesis_interface_) {
  73. for (int i = 0; i < vital::kNumOscillators; ++i)
  74. master_controls_interface_->passOscillatorSection(i, synthesis_interface_->getOscillatorSection(i));
  75. }
  76. header_ = std::make_unique<HeaderSection>();
  77. addSubSection(header_.get());
  78. header_->addListener(this);
  79. modulation_interface_ = std::make_unique<ModulationInterface>(synth_data);
  80. addSubSection(modulation_interface_.get());
  81. extra_mod_section_ = std::make_unique<ExtraModSection>("extra_mod_section", synth_data);
  82. addSubSection(extra_mod_section_.get());
  83. keyboard_interface_ = std::make_unique<KeyboardInterface>(synth_data->synth->getKeyboardState());
  84. addSubSection(keyboard_interface_.get());
  85. bend_section_ = std::make_unique<BendSection>("BEND");
  86. addSubSection(bend_section_.get());
  87. portamento_section_ = std::make_unique<PortamentoSection>("PORTAMENTO");
  88. addSubSection(portamento_section_.get());
  89. voice_section_ = std::make_unique<VoiceSection>("VOICE");
  90. addSubSection(voice_section_.get());
  91. modulation_matrix_ = std::make_unique<ModulationMatrix>(synth_data->modulation_sources, synth_data->mono_modulations);
  92. addSubSection(modulation_matrix_.get());
  93. modulation_matrix_->setVisible(false);
  94. modulation_matrix_->addListener(this);
  95. createModulationSliders(synth_data->mono_modulations, synth_data->poly_modulations);
  96. preset_browser_ = std::make_unique<PresetBrowser>();
  97. addSubSection(preset_browser_.get());
  98. preset_browser_->setVisible(false);
  99. popup_browser_ = std::make_unique<PopupBrowser>();
  100. addSubSection(popup_browser_.get());
  101. popup_browser_->setVisible(false);
  102. popup_selector_ = std::make_unique<SinglePopupSelector>();
  103. addSubSection(popup_selector_.get());
  104. popup_selector_->setVisible(false);
  105. popup_selector_->setAlwaysOnTop(true);
  106. popup_selector_->setWantsKeyboardFocus(true);
  107. dual_popup_selector_ = std::make_unique<DualPopupSelector>();
  108. addSubSection(dual_popup_selector_.get());
  109. dual_popup_selector_->setVisible(false);
  110. dual_popup_selector_->setAlwaysOnTop(true);
  111. dual_popup_selector_->setWantsKeyboardFocus(true);
  112. popup_display_1_ = std::make_unique<PopupDisplay>();
  113. addSubSection(popup_display_1_.get());
  114. popup_display_1_->setVisible(false);
  115. popup_display_1_->setAlwaysOnTop(true);
  116. popup_display_1_->setWantsKeyboardFocus(false);
  117. popup_display_2_ = std::make_unique<PopupDisplay>();
  118. addSubSection(popup_display_2_.get());
  119. popup_display_2_->setVisible(false);
  120. popup_display_2_->setAlwaysOnTop(true);
  121. popup_display_2_->setWantsKeyboardFocus(false);
  122. bank_exporter_ = std::make_unique<BankExporter>();
  123. addSubSection(bank_exporter_.get());
  124. bank_exporter_->setVisible(false);
  125. header_->setBankExporter(bank_exporter_.get());
  126. save_section_ = std::make_unique<SaveSection>("save_section");
  127. addSubSection(save_section_.get(), false);
  128. addChildComponent(save_section_.get());
  129. preset_browser_->setSaveSection(save_section_.get());
  130. header_->setSaveSection(save_section_.get());
  131. header_->setBrowser(preset_browser_.get());
  132. delete_section_ = std::make_unique<DeleteSection>("delete_section");
  133. addSubSection(delete_section_.get(), false);
  134. addChildComponent(delete_section_.get());
  135. preset_browser_->setDeleteSection(delete_section_.get());
  136. about_section_ = std::make_unique<AboutSection>("about");
  137. addSubSection(about_section_.get(), false);
  138. addChildComponent(about_section_.get());
  139. if (synthesis_interface_)
  140. synthesis_interface_->toFront(true);
  141. master_controls_interface_->toFront(true);
  142. effects_interface_->toFront(true);
  143. modulation_interface_->toFront(true);
  144. extra_mod_section_->toFront(true);
  145. keyboard_interface_->toFront(true);
  146. bend_section_->toFront(true);
  147. portamento_section_->toFront(true);
  148. voice_section_->toFront(true);
  149. modulation_manager_->toFront(false);
  150. preset_browser_->toFront(false);
  151. bank_exporter_->toFront(false);
  152. about_section_->toFront(true);
  153. save_section_->toFront(true);
  154. delete_section_->toFront(true);
  155. popup_browser_->toFront(true);
  156. popup_selector_->toFront(true);
  157. dual_popup_selector_->toFront(true);
  158. popup_display_1_->toFront(true);
  159. popup_display_2_->toFront(true);
  160. setAllValues(synth_data->controls);
  161. setOpaque(true);
  162. setSkinValues(default_skin, true);
  163. open_gl_context_.setContinuousRepainting(true);
  164. open_gl_context_.setOpenGLVersionRequired(OpenGLContext::openGL3_2);
  165. open_gl_context_.setSwapInterval(0);
  166. open_gl_context_.setRenderer(this);
  167. open_gl_context_.setComponentPaintingEnabled(false);
  168. open_gl_context_.attachTo(*this);
  169. }
  170. FullInterface::FullInterface() : SynthSection("EMPTY"), open_gl_(open_gl_context_) {
  171. Skin default_skin;
  172. setSkinValues(default_skin, true);
  173. open_gl_context_.setContinuousRepainting(true);
  174. open_gl_context_.setOpenGLVersionRequired(OpenGLContext::openGL3_2);
  175. open_gl_context_.setSwapInterval(0);
  176. open_gl_context_.setRenderer(this);
  177. open_gl_context_.setComponentPaintingEnabled(false);
  178. open_gl_context_.attachTo(*this);
  179. reset();
  180. setOpaque(true);
  181. }
  182. FullInterface::~FullInterface() {
  183. open_gl_context_.detach();
  184. open_gl_context_.setRenderer(nullptr);
  185. }
  186. void FullInterface::paintBackground(Graphics& g) {
  187. g.fillAll(findColour(Skin::kBackground, true));
  188. paintChildrenShadows(g);
  189. if (effects_interface_ == nullptr)
  190. return;
  191. int padding = getPadding();
  192. int bar_width = 6 * padding;
  193. g.setColour(header_->findColour(Skin::kBody, true));
  194. int y = header_->getBottom();
  195. int height = keyboard_interface_->getY() - y;
  196. int x1 = extra_mod_section_->getRight() + padding;
  197. g.fillRect(x1, y, bar_width, height);
  198. if (synthesis_interface_) {
  199. int x2 = synthesis_interface_->getRight() + padding;
  200. g.fillRect(x2, y, bar_width, height);
  201. }
  202. paintKnobShadows(g);
  203. paintChildrenBackgrounds(g);
  204. }
  205. void FullInterface::copySkinValues(const Skin& skin) {
  206. ScopedLock open_gl_lock(open_gl_critical_section_);
  207. skin.copyValuesToLookAndFeel(DefaultLookAndFeel::instance());
  208. setSkinValues(skin, true);
  209. }
  210. void FullInterface::reloadSkin(const Skin& skin) {
  211. copySkinValues(skin);
  212. Rectangle<int> bounds = getBounds();
  213. setBounds(0, 0, bounds.getWidth() / 4, bounds.getHeight() / 4);
  214. setBounds(bounds);
  215. }
  216. void FullInterface::repaintChildBackground(SynthSection* child) {
  217. if (!background_image_.isValid() || setting_all_values_)
  218. return;
  219. if (child->getParentComponent() == synthesis_interface_.get()) {
  220. repaintSynthesisSection();
  221. return;
  222. }
  223. if (effects_interface_ != nullptr && effects_interface_->isParentOf(child))
  224. child = effects_interface_.get();
  225. background_.lock();
  226. Graphics g(background_image_);
  227. paintChildBackground(g, child);
  228. background_.updateBackgroundImage(background_image_);
  229. background_.unlock();
  230. }
  231. void FullInterface::repaintSynthesisSection() {
  232. if (synthesis_interface_ == nullptr || !synthesis_interface_->isVisible() || !background_image_.isValid())
  233. return;
  234. background_.lock();
  235. Graphics g(background_image_);
  236. int padding = findValue(Skin::kPadding);
  237. g.setColour(findColour(Skin::kBackground, true));
  238. g.fillRect(synthesis_interface_->getBounds().expanded(padding));
  239. paintChildShadow(g, synthesis_interface_.get());
  240. paintChildBackground(g, synthesis_interface_.get());
  241. background_.updateBackgroundImage(background_image_);
  242. background_.unlock();
  243. }
  244. void FullInterface::repaintOpenGlBackground(OpenGlComponent* component) {
  245. if (!background_image_.isValid())
  246. return;
  247. background_.lock();
  248. Graphics g(background_image_);
  249. paintOpenGlBackground(g, component);
  250. background_.updateBackgroundImage(background_image_);
  251. background_.unlock();
  252. }
  253. void FullInterface::redoBackground() {
  254. int width = std::ceil(display_scale_ * getWidth());
  255. int height = std::ceil(display_scale_ * getHeight());
  256. if (width < vital::kMinWindowWidth || height < vital::kMinWindowHeight)
  257. return;
  258. ScopedLock open_gl_lock(open_gl_critical_section_);
  259. background_.lock();
  260. background_image_ = Image(Image::RGB, width, height, true);
  261. Graphics g(background_image_);
  262. paintBackground(g);
  263. background_.updateBackgroundImage(background_image_);
  264. background_.unlock();
  265. }
  266. void FullInterface::checkShouldReposition(bool resize) {
  267. float old_scale = display_scale_;
  268. int old_pixel_multiple = pixel_multiple_;
  269. display_scale_ = getDisplayScale();
  270. pixel_multiple_ = std::max<int>(1, display_scale_);
  271. if (resize && (old_scale != display_scale_ || old_pixel_multiple != pixel_multiple_))
  272. resized();
  273. }
  274. void FullInterface::resized() {
  275. checkShouldReposition(false);
  276. width_ = getWidth();
  277. if (!enable_redo_background_)
  278. return;
  279. resized_width_ = width_;
  280. ScopedLock lock(open_gl_critical_section_);
  281. static constexpr int kTopHeight = 48;
  282. if (effects_interface_ == nullptr)
  283. return;
  284. int left = 0;
  285. int top = 0;
  286. int width = std::ceil(getWidth() * display_scale_);
  287. int height = std::ceil(getHeight() * display_scale_);
  288. Rectangle<int> bounds(0, 0, width, height);
  289. float width_ratio = getWidth() / (1.0f * vital::kDefaultWindowWidth);
  290. float ratio = width_ratio * display_scale_;
  291. float height_ratio = getHeight() / (1.0f * vital::kDefaultWindowHeight);
  292. if (width_ratio > height_ratio + 1.0f / vital::kDefaultWindowHeight) {
  293. ratio = height_ratio;
  294. width = height_ratio * vital::kDefaultWindowWidth * display_scale_;
  295. left = (getWidth() - width) / 2;
  296. }
  297. if (height_ratio > width_ratio + 1.0f / vital::kDefaultWindowHeight) {
  298. ratio = width_ratio;
  299. height = ratio * vital::kDefaultWindowHeight * display_scale_;
  300. top = (getHeight() - height) / 2;
  301. }
  302. setSizeRatio(ratio);
  303. popup_browser_->setBounds(bounds);
  304. int padding = getPadding();
  305. int voice_padding = findValue(Skin::kLargePadding);
  306. int extra_mod_width = findValue(Skin::kModulationButtonWidth);
  307. int main_x = left + extra_mod_width + 2 * voice_padding;
  308. int top_height = kTopHeight * ratio;
  309. int knob_section_height = getKnobSectionHeight();
  310. int keyboard_section_height = knob_section_height * 0.7f;
  311. int voice_height = height - top_height - keyboard_section_height;
  312. int section_one_width = 350 * ratio;
  313. int section_two_width = section_one_width;
  314. int audio_width = section_one_width + section_two_width + padding;
  315. int modulation_width = width - audio_width - extra_mod_width - 4 * voice_padding;
  316. header_->setTabOffset(extra_mod_width + 2 * voice_padding);
  317. header_->setBounds(left, top, width, top_height);
  318. Rectangle<int> main_bounds(main_x, top + top_height, audio_width, voice_height);
  319. if (synthesis_interface_)
  320. synthesis_interface_->setBounds(main_bounds);
  321. effects_interface_->setBounds(main_bounds.withRight(main_bounds.getRight() + voice_padding));
  322. modulation_matrix_->setBounds(main_bounds);
  323. int modulation_height = voice_height - knob_section_height - padding;
  324. modulation_interface_->setBounds(main_bounds.getRight() + voice_padding,
  325. main_bounds.getY(), modulation_width, modulation_height);
  326. int voice_y = top + height - knob_section_height - keyboard_section_height;
  327. int portamento_width = 4 * (int)findValue(Skin::kModulationButtonWidth);
  328. int portamento_x = modulation_interface_->getRight() - portamento_width;
  329. portamento_section_->setBounds(portamento_x, voice_y, portamento_width, knob_section_height);
  330. int voice_width = modulation_interface_->getWidth() - portamento_width - padding;
  331. voice_section_->setBounds(modulation_interface_->getX(), voice_y, voice_width, knob_section_height);
  332. bend_section_->setBounds(left + voice_padding, top + height - knob_section_height - padding,
  333. extra_mod_width, knob_section_height);
  334. int extra_mod_height = height - top_height - knob_section_height - padding - 1;
  335. extra_mod_section_->setBounds(left + voice_padding, top + top_height, extra_mod_width, extra_mod_height);
  336. int keyboard_height = keyboard_section_height - voice_padding - padding;
  337. int keyboard_x = extra_mod_section_->getRight() + voice_padding;
  338. int keyboard_width = modulation_interface_->getRight() - keyboard_x;
  339. keyboard_interface_->setBounds(keyboard_x, top + height - keyboard_height - padding, keyboard_width, keyboard_height);
  340. about_section_->setBounds(bounds);
  341. save_section_->setBounds(bounds);
  342. delete_section_->setBounds(bounds);
  343. Rectangle<int> browse_bounds(main_bounds.getX(), main_bounds.getY(),
  344. width - main_bounds.getX(), main_bounds.getHeight());
  345. preset_browser_->setBounds(browse_bounds);
  346. bank_exporter_->setBounds(browse_bounds);
  347. SynthSection::resized();
  348. modulation_manager_->setBounds(bounds);
  349. for (int i = 0; i < vital::kNumOscillators; ++i) {
  350. if (wavetable_edits_[i])
  351. wavetable_edits_[i]->setBounds(left, 0, width, height);
  352. }
  353. if (synthesis_interface_) {
  354. for (int i = 0; i < vital::kNumOscillators; ++i)
  355. master_controls_interface_->setOscillatorBounds(i, synthesis_interface_->getOscillatorBounds(i));
  356. }
  357. master_controls_interface_->setBounds(main_bounds);
  358. if (full_screen_section_) {
  359. Rectangle<float> relative = synthesis_interface_->getOscillatorSection(0)->getWavetableRelativeBounds();
  360. int total_width = getWidth() / relative.getWidth();
  361. full_screen_section_->setBounds(-total_width * relative.getX(), 0, total_width, getHeight());
  362. }
  363. if (getWidth() && getHeight())
  364. redoBackground();
  365. }
  366. void FullInterface::setOscilloscopeMemory(const vital::poly_float* memory) {
  367. if (header_)
  368. header_->setOscilloscopeMemory(memory);
  369. if (master_controls_interface_)
  370. master_controls_interface_->setOscilloscopeMemory(memory);
  371. }
  372. void FullInterface::setAudioMemory(const vital::StereoMemory* memory) {
  373. if (header_)
  374. header_->setAudioMemory(memory);
  375. if (master_controls_interface_)
  376. master_controls_interface_->setAudioMemory(memory);
  377. }
  378. void FullInterface::createModulationSliders(const vital::output_map& mono_modulations,
  379. const vital::output_map& poly_modulations) {
  380. std::map<std::string, SynthSlider*> all_sliders = getAllSliders();
  381. std::map<std::string, SynthSlider*> modulatable_sliders;
  382. for (auto& destination : mono_modulations) {
  383. if (all_sliders.count(destination.first))
  384. modulatable_sliders[destination.first] = all_sliders[destination.first];
  385. }
  386. modulation_manager_ = std::make_unique<ModulationManager>(getAllModulationButtons(),
  387. modulatable_sliders, mono_modulations, poly_modulations);
  388. modulation_manager_->setOpaque(false);
  389. addSubSection(modulation_manager_.get());
  390. }
  391. void FullInterface::animate(bool animate) {
  392. if (animate_ != animate)
  393. open_gl_context_.setContinuousRepainting(animate);
  394. animate_ = animate;
  395. SynthSection::animate(animate);
  396. }
  397. void FullInterface::reset() {
  398. ScopedLock lock(open_gl_critical_section_);
  399. if (modulation_interface_)
  400. modulation_interface_->reset();
  401. setting_all_values_ = true;
  402. SynthSection::reset();
  403. modulationChanged();
  404. if (effects_interface_ && effects_interface_->isVisible())
  405. effects_interface_->redoBackgroundImage();
  406. setWavetableNames();
  407. setting_all_values_ = false;
  408. repaintSynthesisSection();
  409. }
  410. void FullInterface::setAllValues(vital::control_map& controls) {
  411. ScopedLock lock(open_gl_critical_section_);
  412. setting_all_values_ = true;
  413. SynthSection::setAllValues(controls);
  414. setting_all_values_ = false;
  415. }
  416. void FullInterface::setWavetableNames() {
  417. for (int i = 0; i < vital::kNumOscillators; ++i) {
  418. if (wavetable_edits_[i])
  419. synthesis_interface_->setWavetableName(i, wavetable_edits_[i]->getName());
  420. }
  421. }
  422. void FullInterface::newOpenGLContextCreated() {
  423. double version_supported = OpenGLShaderProgram::getLanguageVersion();
  424. unsupported_ = version_supported < kMinOpenGlVersion;
  425. if (unsupported_) {
  426. NativeMessageBox::showMessageBoxAsync(AlertWindow::WarningIcon, "Unsupported OpenGl Version",
  427. String("Vitalium requires OpenGL version: ") + String(kMinOpenGlVersion) +
  428. String("\nSupported version: ") + String(version_supported));
  429. return;
  430. }
  431. shaders_ = std::make_unique<Shaders>(open_gl_context_);
  432. open_gl_.shaders = shaders_.get();
  433. open_gl_.display_scale = display_scale_;
  434. last_render_scale_ = display_scale_;
  435. background_.init(open_gl_);
  436. initOpenGlComponents(open_gl_);
  437. }
  438. void FullInterface::renderOpenGL() {
  439. if (unsupported_)
  440. return;
  441. float render_scale = open_gl_.context.getRenderingScale();
  442. if (render_scale != last_render_scale_) {
  443. last_render_scale_ = render_scale;
  444. MessageManager::callAsync([=] { checkShouldReposition(true); });
  445. }
  446. ScopedLock lock(open_gl_critical_section_);
  447. open_gl_.display_scale = display_scale_;
  448. background_.render(open_gl_);
  449. modulation_manager_->renderMeters(open_gl_, animate_);
  450. renderOpenGlComponents(open_gl_, animate_);
  451. }
  452. void FullInterface::openGLContextClosing() {
  453. if (unsupported_)
  454. return;
  455. background_.destroy(open_gl_);
  456. destroyOpenGlComponents(open_gl_);
  457. open_gl_.shaders = nullptr;
  458. shaders_ = nullptr;
  459. }
  460. void FullInterface::showAboutSection() {
  461. ScopedLock lock(open_gl_critical_section_);
  462. about_section_->setVisible(true);
  463. }
  464. void FullInterface::deleteRequested(File preset) {
  465. delete_section_->setFileToDelete(preset);
  466. delete_section_->setVisible(true);
  467. }
  468. void FullInterface::tabSelected(int index) {
  469. ScopedLock lock(open_gl_critical_section_);
  470. bool make_visible = !preset_browser_->isVisible() && !bank_exporter_->isVisible();
  471. if (synthesis_interface_)
  472. synthesis_interface_->setVisible(index == 0 && make_visible);
  473. effects_interface_->setVisible(index == 1 && make_visible);
  474. modulation_matrix_->setVisible(index == 2 && make_visible);
  475. master_controls_interface_->setVisible(index == 3 && make_visible);
  476. modulation_manager_->setModulationAmounts();
  477. modulation_manager_->resized();
  478. modulation_manager_->setVisibleMeterBounds();
  479. modulation_manager_->hideUnusedHoverModulations();
  480. redoBackground();
  481. }
  482. void FullInterface::clearTemporaryTab(int current_tab) {
  483. ScopedLock lock(open_gl_critical_section_);
  484. preset_browser_->setVisible(false);
  485. bank_exporter_->setVisible(false);
  486. modulation_interface_->setVisible(true);
  487. portamento_section_->setVisible(true);
  488. voice_section_->setVisible(true);
  489. tabSelected(current_tab);
  490. }
  491. void FullInterface::setPresetBrowserVisibility(bool visible, int current_tab) {
  492. ScopedLock lock(open_gl_critical_section_);
  493. preset_browser_->setVisible(visible);
  494. modulation_interface_->setVisible(!visible);
  495. portamento_section_->setVisible(!visible);
  496. voice_section_->setVisible(!visible);
  497. synthesis_interface_->setVisible(!visible);
  498. if (visible) {
  499. tabSelected(-1);
  500. bank_exporter_->setVisible(false);
  501. preset_browser_->repaintBackground();
  502. preset_browser_->grabKeyboardFocus();
  503. header_->setTemporaryTab("PRESET BROWSER");
  504. }
  505. else {
  506. tabSelected(current_tab);
  507. header_->setTemporaryTab("");
  508. }
  509. }
  510. void FullInterface::setBankExporterVisibility(bool visible, int current_tab) {
  511. ScopedLock lock(open_gl_critical_section_);
  512. bank_exporter_->setVisible(visible);
  513. modulation_interface_->setVisible(!visible);
  514. portamento_section_->setVisible(!visible);
  515. voice_section_->setVisible(!visible);
  516. synthesis_interface_->setVisible(!visible);
  517. if (visible) {
  518. tabSelected(-1);
  519. preset_browser_->setVisible(false);
  520. bank_exporter_->repaintBackground();
  521. header_->setTemporaryTab("EXPORT BANK");
  522. }
  523. else {
  524. tabSelected(current_tab);
  525. header_->setTemporaryTab("");
  526. }
  527. }
  528. void FullInterface::bankImported() {
  529. preset_browser_->loadPresets();
  530. }
  531. void FullInterface::effectsMoved() {
  532. modulation_manager_->setVisibleMeterBounds();
  533. }
  534. void FullInterface::modulationsScrolled() {
  535. modulation_manager_->setVisibleMeterBounds();
  536. }
  537. void FullInterface::setFocus() {
  538. if (synthesis_interface_ && synthesis_interface_->isShowing())
  539. synthesis_interface_->setFocus();
  540. }
  541. void FullInterface::notifyChange() {
  542. if (header_)
  543. header_->notifyChange();
  544. }
  545. void FullInterface::notifyFresh() {
  546. if (header_)
  547. header_->notifyFresh();
  548. }
  549. void FullInterface::externalPresetLoaded(const File& preset) {
  550. if (preset_browser_)
  551. preset_browser_->externalPresetLoaded(preset);
  552. }
  553. void FullInterface::showFullScreenSection(SynthSection* full_screen) {
  554. ScopedLock lock(open_gl_critical_section_);
  555. full_screen_section_ = full_screen;
  556. if (full_screen_section_) {
  557. addSubSection(full_screen_section_);
  558. full_screen_section_->setBounds(getLocalBounds());
  559. }
  560. for (int i = 0; i < vital::kNumOscillators; ++i)
  561. wavetable_edits_[i]->setVisible(false);
  562. bool show_rest = full_screen == nullptr;
  563. header_->setVisible(show_rest);
  564. synthesis_interface_->setVisible(show_rest);
  565. modulation_interface_->setVisible(show_rest);
  566. keyboard_interface_->setVisible(show_rest);
  567. extra_mod_section_->setVisible(show_rest);
  568. modulation_manager_->setVisible(show_rest);
  569. voice_section_->setVisible(show_rest);
  570. bend_section_->setVisible(show_rest);
  571. portamento_section_->setVisible(show_rest);
  572. redoBackground();
  573. }
  574. void FullInterface::showWavetableEditSection(int index) {
  575. if (!wavetableEditorsInitialized())
  576. return;
  577. ScopedLock lock(open_gl_critical_section_);
  578. for (int i = 0; i < vital::kNumOscillators; ++i)
  579. wavetable_edits_[i]->setVisible(i == index);
  580. bool show_rest = index < 0;
  581. header_->setVisible(show_rest);
  582. synthesis_interface_->setVisible(show_rest);
  583. modulation_interface_->setVisible(show_rest);
  584. keyboard_interface_->setVisible(show_rest);
  585. extra_mod_section_->setVisible(show_rest);
  586. modulation_manager_->setVisible(show_rest);
  587. voice_section_->setVisible(show_rest);
  588. bend_section_->setVisible(show_rest);
  589. portamento_section_->setVisible(show_rest);
  590. redoBackground();
  591. }
  592. std::string FullInterface::getLastBrowsedWavetable(int index) {
  593. return wavetable_edits_[index]->getLastBrowsedWavetable();
  594. }
  595. std::string FullInterface::getWavetableName(int index) {
  596. return wavetable_edits_[index]->getName();
  597. }
  598. void FullInterface::hideWavetableEditSection() {
  599. showWavetableEditSection(-1);
  600. }
  601. void FullInterface::loadWavetableFile(int index, const File& wavetable) {
  602. if (wavetable_edits_[index])
  603. wavetable_edits_[index]->loadFile(wavetable);
  604. }
  605. void FullInterface::loadWavetable(int index, json& wavetable_data) {
  606. if (wavetable_edits_[index])
  607. wavetable_edits_[index]->loadWavetable(wavetable_data);
  608. }
  609. void FullInterface::loadDefaultWavetable(int index) {
  610. if (wavetable_edits_[index])
  611. wavetable_edits_[index]->loadDefaultWavetable();
  612. }
  613. void FullInterface::resynthesizeToWavetable(int index) {
  614. if (wavetable_edits_[index])
  615. wavetable_edits_[index]->resynthesizeToWavetable();
  616. }
  617. void FullInterface::saveWavetable(int index) {
  618. save_section_->setIsPreset(false);
  619. save_section_->setSaveBounds();
  620. save_section_->setFileExtension(vital::kWavetableExtension);
  621. save_section_->setFileType("Wavetable");
  622. File destination = LoadSave::getUserWavetableDirectory();
  623. if (!destination.exists())
  624. destination.createDirectory();
  625. save_section_->setDirectory(destination);
  626. save_section_->setFileData(getWavetableJson(index));
  627. save_section_->setVisible(true);
  628. }
  629. void FullInterface::saveLfo(const json& data) {
  630. save_section_->setIsPreset(false);
  631. save_section_->setFileExtension(vital::kLfoExtension);
  632. save_section_->setFileType("LFO");
  633. save_section_->setDirectory(LoadSave::getUserLfoDirectory());
  634. save_section_->setFileData(data);
  635. save_section_->setVisible(true);
  636. }
  637. json FullInterface::getWavetableJson(int index) {
  638. if (wavetable_edits_[index])
  639. return wavetable_edits_[index]->getWavetableJson();
  640. return json();
  641. }
  642. bool FullInterface::loadAudioAsWavetable(int index, const String& name, InputStream* audio_stream,
  643. WavetableCreator::AudioFileLoadStyle style) {
  644. if (wavetable_edits_[index])
  645. return wavetable_edits_[index]->loadAudioAsWavetable(name, audio_stream, style);
  646. delete audio_stream;
  647. return true;
  648. }
  649. void FullInterface::popupBrowser(SynthSection* owner, Rectangle<int> bounds, std::vector<File> directories,
  650. String extensions, std::string passthrough_name,
  651. std::string additional_folders_name) {
  652. popup_browser_->setIgnoreBounds(getLocalArea(owner, owner->getLocalBounds()));
  653. popup_browser_->setBrowserBounds(getLocalArea(owner, bounds));
  654. popup_browser_->setVisible(true);
  655. popup_browser_->grabKeyboardFocus();
  656. popup_browser_->setOwner(owner);
  657. popup_browser_->loadPresets(directories, extensions, passthrough_name, additional_folders_name);
  658. }
  659. void FullInterface::popupBrowserUpdate(SynthSection* owner) {
  660. if (popup_browser_)
  661. popup_browser_->setOwner(owner);
  662. }
  663. void FullInterface::popupSelector(Component* source, Point<int> position, const PopupItems& options,
  664. std::function<void(int)> callback, std::function<void()> cancel) {
  665. popup_selector_->setCallback(callback);
  666. popup_selector_->setCancelCallback(cancel);
  667. popup_selector_->showSelections(options);
  668. Rectangle<int> bounds(0, 0, std::ceil(display_scale_ * getWidth()), std::ceil(display_scale_ * getHeight()));
  669. popup_selector_->setPosition(getLocalPoint(source, position), bounds);
  670. popup_selector_->setVisible(true);
  671. }
  672. void FullInterface::dualPopupSelector(Component* source, Point<int> position, int width,
  673. const PopupItems& options, std::function<void(int)> callback) {
  674. dual_popup_selector_->setCallback(callback);
  675. dual_popup_selector_->showSelections(options);
  676. Rectangle<int> bounds(0, 0, std::ceil(display_scale_ * getWidth()), std::ceil(display_scale_ * getHeight()));
  677. dual_popup_selector_->setPosition(getLocalPoint(source, position), width, bounds);
  678. dual_popup_selector_->setVisible(true);
  679. }
  680. void FullInterface::popupDisplay(Component* source, const std::string& text,
  681. BubbleComponent::BubblePlacement placement, bool primary) {
  682. PopupDisplay* display = primary ? popup_display_1_.get() : popup_display_2_.get();
  683. display->setContent(text, getLocalArea(source, source->getLocalBounds()), placement);
  684. display->setVisible(true);
  685. }
  686. void FullInterface::hideDisplay(bool primary) {
  687. PopupDisplay* display = primary ? popup_display_1_.get() : popup_display_2_.get();
  688. if (display)
  689. display->setVisible(false);
  690. }
  691. void FullInterface::modulationChanged() {
  692. if (modulation_matrix_)
  693. modulation_matrix_->updateModulations();
  694. if (modulation_interface_)
  695. modulation_interface_->checkNumShown();
  696. if (modulation_manager_)
  697. modulation_manager_->reset();
  698. }
  699. void FullInterface::modulationValueChanged(int index) {
  700. if (modulation_matrix_)
  701. modulation_matrix_->updateModulationValue(index);
  702. if (modulation_manager_)
  703. modulation_manager_->setModulationAmounts();
  704. }
  705. void FullInterface::toggleOscillatorZoom(int index) {
  706. if (full_screen_section_)
  707. showFullScreenSection(nullptr);
  708. else
  709. showFullScreenSection(synthesis_interface_->getOscillatorSection(index));
  710. }
  711. void FullInterface::toggleFilter1Zoom() {
  712. if (full_screen_section_)
  713. showFullScreenSection(nullptr);
  714. else
  715. showFullScreenSection(synthesis_interface_->getFilterSection1());
  716. }
  717. void FullInterface::toggleFilter2Zoom() {
  718. if (full_screen_section_)
  719. showFullScreenSection(nullptr);
  720. else
  721. showFullScreenSection(synthesis_interface_->getFilterSection2());
  722. }