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.

135 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../JuceDemoHeader.h"
  18. //==============================================================================
  19. class AudioSettingsDemo : public Component,
  20. public ChangeListener
  21. {
  22. public:
  23. AudioSettingsDemo()
  24. {
  25. setOpaque (true);
  26. addAndMakeVisible (audioSetupComp
  27. = new AudioDeviceSelectorComponent (MainAppWindow::getSharedAudioDeviceManager(),
  28. 0, 256, 0, 256, true, true, true, false));
  29. addAndMakeVisible (diagnosticsBox);
  30. diagnosticsBox.setMultiLine (true);
  31. diagnosticsBox.setReturnKeyStartsNewLine (true);
  32. diagnosticsBox.setReadOnly (true);
  33. diagnosticsBox.setScrollbarsShown (true);
  34. diagnosticsBox.setCaretVisible (false);
  35. diagnosticsBox.setPopupMenuEnabled (true);
  36. diagnosticsBox.setColour (TextEditor::textColourId, Colours::white);
  37. diagnosticsBox.setColour (TextEditor::backgroundColourId, Colour (0x32ffffff));
  38. diagnosticsBox.setColour (TextEditor::outlineColourId, Colour (0x1c000000));
  39. diagnosticsBox.setColour (TextEditor::shadowColourId, Colour (0x16000000));
  40. MainAppWindow::getSharedAudioDeviceManager().addChangeListener (this);
  41. logMessage ("Audio device diagnostics:\n");
  42. dumpDeviceInfo();
  43. }
  44. ~AudioSettingsDemo()
  45. {
  46. MainAppWindow::getSharedAudioDeviceManager().removeChangeListener (this);
  47. }
  48. void paint (Graphics& g) override
  49. {
  50. fillStandardDemoBackground (g);
  51. }
  52. void resized() override
  53. {
  54. Rectangle<int> r (getLocalBounds().reduced (4));
  55. audioSetupComp->setBounds (r.removeFromTop (proportionOfHeight (0.65f)));
  56. diagnosticsBox.setBounds (r);
  57. }
  58. void dumpDeviceInfo()
  59. {
  60. AudioDeviceManager& dm = MainAppWindow::getSharedAudioDeviceManager();
  61. logMessage ("--------------------------------------");
  62. logMessage ("Current audio device type: " + (dm.getCurrentDeviceTypeObject() != nullptr
  63. ? dm.getCurrentDeviceTypeObject()->getTypeName()
  64. : "<none>"));
  65. if (AudioIODevice* device = dm.getCurrentAudioDevice())
  66. {
  67. logMessage ("Current audio device: " + device->getName().quoted());
  68. logMessage ("Sample rate: " + String (device->getCurrentSampleRate()) + " Hz");
  69. logMessage ("Block size: " + String (device->getCurrentBufferSizeSamples()) + " samples");
  70. logMessage ("Output Latency: " + String (device->getOutputLatencyInSamples()) + " samples");
  71. logMessage ("Input Latency: " + String (device->getInputLatencyInSamples()) + " samples");
  72. logMessage ("Bit depth: " + String (device->getCurrentBitDepth()));
  73. logMessage ("Input channel names: " + device->getInputChannelNames().joinIntoString (", "));
  74. logMessage ("Active input channels: " + getListOfActiveBits (device->getActiveInputChannels()));
  75. logMessage ("Output channel names: " + device->getOutputChannelNames().joinIntoString (", "));
  76. logMessage ("Active output channels: " + getListOfActiveBits (device->getActiveOutputChannels()));
  77. }
  78. else
  79. {
  80. logMessage ("No audio device open");
  81. }
  82. }
  83. void logMessage (const String& m)
  84. {
  85. diagnosticsBox.moveCaretToEnd();
  86. diagnosticsBox.insertTextAtCaret (m + newLine);
  87. }
  88. private:
  89. ScopedPointer<AudioDeviceSelectorComponent> audioSetupComp;
  90. TextEditor diagnosticsBox;
  91. void changeListenerCallback (ChangeBroadcaster*) override
  92. {
  93. dumpDeviceInfo();
  94. }
  95. static String getListOfActiveBits (const BitArray& b)
  96. {
  97. StringArray bits;
  98. for (int i = 0; i <= b.getHighestBit(); ++i)
  99. if (b[i])
  100. bits.add (String (i));
  101. return bits.joinIntoString (", ");
  102. }
  103. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSettingsDemo)
  104. };
  105. // This static object will register this demo type in a global list of demos..
  106. static JuceDemoType<AudioSettingsDemo> demo ("30 Audio: Settings");