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.

67 lines
2.4KB

  1. /* Copyright 2013-2019 Matt Tytel
  2. *
  3. * pylon 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. * pylon 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 pylon. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "synth_editor.h"
  17. #include "default_look_and_feel.h"
  18. #include "synth_plugin.h"
  19. #include "load_save.h"
  20. SynthEditor::SynthEditor(SynthPlugin& synth) :
  21. AudioProcessorEditor(&synth), SynthGuiInterface(&synth), synth_(synth), was_animating_(true) {
  22. static constexpr int kHeightBuffer = 50;
  23. setLookAndFeel(DefaultLookAndFeel::instance());
  24. gui_->reset();
  25. gui_->setOscilloscopeMemory(synth.getOscilloscopeMemory());
  26. gui_->setAudioMemory(synth.getAudioMemory());
  27. gui_->animate(LoadSave::shouldAnimateWidgets());
  28. constrainer_.setMinimumSize(vital::kMinWindowWidth, vital::kMinWindowHeight);
  29. double ratio = (1.0 * vital::kDefaultWindowWidth) / vital::kDefaultWindowHeight;
  30. constrainer_.setFixedAspectRatio(ratio);
  31. constrainer_.setGui(gui_.get());
  32. setConstrainer(&constrainer_);
  33. Rectangle<int> total_bounds = Desktop::getInstance().getDisplays().getTotalBounds(true);
  34. total_bounds.removeFromBottom(kHeightBuffer);
  35. addAndMakeVisible(gui_.get());
  36. float window_size = LoadSave::loadWindowSize();
  37. window_size = std::min(window_size, total_bounds.getWidth() / (1.0f * vital::kDefaultWindowWidth));
  38. window_size = std::min(window_size, total_bounds.getHeight() / (1.0f * vital::kDefaultWindowHeight));
  39. int width = std::round(window_size * vital::kDefaultWindowWidth);
  40. int height = std::round(window_size * vital::kDefaultWindowHeight);
  41. setResizable(true, true);
  42. setSize(width, height);
  43. }
  44. void SynthEditor::resized() {
  45. AudioProcessorEditor::resized();
  46. gui_->setBounds(getLocalBounds());
  47. }
  48. void SynthEditor::setScaleFactor(float newScale) {
  49. AudioProcessorEditor::setScaleFactor(newScale);
  50. gui_->redoBackground();
  51. }
  52. void SynthEditor::updateFullGui() {
  53. SynthGuiInterface::updateFullGui();
  54. synth_.updateHostDisplay();
  55. }