The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

144 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. #include "DSPDemo.h"
  21. #include "MainComponent.h"
  22. //==============================================================================
  23. class DSPSamplesApplication : public JUCEApplication,
  24. private TimeSliceThread,
  25. private Value::Listener,
  26. private ChangeListener
  27. {
  28. public:
  29. //==============================================================================
  30. DSPSamplesApplication();
  31. const String getApplicationName() override { return ProjectInfo::projectName; }
  32. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  33. //==============================================================================
  34. void initialise (const String&) override;
  35. void shutdown() override;
  36. //==============================================================================
  37. static DSPSamplesApplication& getApp();
  38. //==============================================================================
  39. bool loadFile (const File&);
  40. void togglePlay();
  41. void stop();
  42. void init();
  43. void play();
  44. void setLooping (bool);
  45. //==============================================================================
  46. void setCurrentDemo (int index, bool force = false);
  47. int getCurrentDemoIndex() const { return demoIndex; }
  48. const std::vector<DSPDemoParameterBase*>& getCurrentDemoParameters() { return currentDemo->getParameters(); }
  49. AudioDeviceManager& getDeviceManager() { return audioDeviceManager; }
  50. AudioFormatManager& getFormatManager() { return formatManager; }
  51. AudioTransportSource* getTransportSource() { return transportSource; }
  52. Value& getPlayState() { return playState; }
  53. Value& getLoopState() { return loopState; }
  54. //==============================================================================
  55. struct MainWindow : public DocumentWindow
  56. {
  57. MainWindow (String name)
  58. : DocumentWindow (name,
  59. Desktop::getInstance().getDefaultLookAndFeel()
  60. .findColour (ResizableWindow::backgroundColourId),
  61. DocumentWindow::allButtons)
  62. {
  63. setUsingNativeTitleBar (true);
  64. setContentOwned (mainComponent = new MainContentComponent(), true);
  65. #if JUCE_ANDROID || JUCE_IOS
  66. setFullScreen (true);
  67. #else
  68. centreWithSize (getWidth(), getHeight());
  69. setResizable (true, false);
  70. setResizeLimits (500, 400, 32000, 32000);
  71. #endif
  72. setVisible (true);
  73. }
  74. void closeButtonPressed() override
  75. {
  76. JUCEApplication::getInstance()->systemRequestedQuit();
  77. }
  78. void setTransportSource (AudioTransportSource* source)
  79. {
  80. mainComponent->getThumbnailComponent().setTransportSource (source);
  81. }
  82. void initParameters()
  83. {
  84. mainComponent->initParameters();
  85. }
  86. private:
  87. ScopedPointer<MainContentComponent> mainComponent;
  88. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
  89. };
  90. private:
  91. //==============================================================================
  92. void valueChanged (Value&) override;
  93. void changeListenerCallback (ChangeBroadcaster*) override;
  94. //==============================================================================
  95. AudioDeviceManager audioDeviceManager;
  96. AudioFormatManager formatManager;
  97. Value playState { var (false) };
  98. Value loopState { var (false) };
  99. double currentSampleRate = 44100.0;
  100. uint32 currentBlockSize = 512;
  101. uint32 currentNumChannels = 2;
  102. ScopedPointer<AudioFormatReader> reader;
  103. ScopedPointer<AudioFormatReaderSource> readerSource;
  104. ScopedPointer<AudioTransportSource> transportSource;
  105. ScopedPointer<DSPDemoBase> currentDemo;
  106. AudioSourcePlayer audioSourcePlayer;
  107. ScopedPointer<MainWindow> mainWindow;
  108. int demoIndex = -1;
  109. AudioBuffer<float> fileReadBuffer;
  110. };