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.

133 lines
4.9KB

  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. #include "../JuceDemoHeader.h"
  20. //==============================================================================
  21. class AudioSettingsDemo : public Component,
  22. public ChangeListener
  23. {
  24. public:
  25. AudioSettingsDemo()
  26. {
  27. setOpaque (true);
  28. addAndMakeVisible (audioSetupComp
  29. = new AudioDeviceSelectorComponent (MainAppWindow::getSharedAudioDeviceManager(),
  30. 0, 256, 0, 256, true, true, true, false));
  31. addAndMakeVisible (diagnosticsBox);
  32. diagnosticsBox.setMultiLine (true);
  33. diagnosticsBox.setReturnKeyStartsNewLine (true);
  34. diagnosticsBox.setReadOnly (true);
  35. diagnosticsBox.setScrollbarsShown (true);
  36. diagnosticsBox.setCaretVisible (false);
  37. diagnosticsBox.setPopupMenuEnabled (true);
  38. MainAppWindow::getSharedAudioDeviceManager().addChangeListener (this);
  39. logMessage ("Audio device diagnostics:\n");
  40. dumpDeviceInfo();
  41. }
  42. ~AudioSettingsDemo()
  43. {
  44. MainAppWindow::getSharedAudioDeviceManager().removeChangeListener (this);
  45. }
  46. void paint (Graphics& g) override
  47. {
  48. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground));
  49. }
  50. void resized() override
  51. {
  52. Rectangle<int> r (getLocalBounds().reduced (4));
  53. audioSetupComp->setBounds (r.removeFromTop (proportionOfHeight (0.65f)));
  54. diagnosticsBox.setBounds (r);
  55. }
  56. void dumpDeviceInfo()
  57. {
  58. AudioDeviceManager& dm = MainAppWindow::getSharedAudioDeviceManager();
  59. logMessage ("--------------------------------------");
  60. logMessage ("Current audio device type: " + (dm.getCurrentDeviceTypeObject() != nullptr
  61. ? dm.getCurrentDeviceTypeObject()->getTypeName()
  62. : "<none>"));
  63. if (AudioIODevice* device = dm.getCurrentAudioDevice())
  64. {
  65. logMessage ("Current audio device: " + device->getName().quoted());
  66. logMessage ("Sample rate: " + String (device->getCurrentSampleRate()) + " Hz");
  67. logMessage ("Block size: " + String (device->getCurrentBufferSizeSamples()) + " samples");
  68. logMessage ("Output Latency: " + String (device->getOutputLatencyInSamples()) + " samples");
  69. logMessage ("Input Latency: " + String (device->getInputLatencyInSamples()) + " samples");
  70. logMessage ("Bit depth: " + String (device->getCurrentBitDepth()));
  71. logMessage ("Input channel names: " + device->getInputChannelNames().joinIntoString (", "));
  72. logMessage ("Active input channels: " + getListOfActiveBits (device->getActiveInputChannels()));
  73. logMessage ("Output channel names: " + device->getOutputChannelNames().joinIntoString (", "));
  74. logMessage ("Active output channels: " + getListOfActiveBits (device->getActiveOutputChannels()));
  75. }
  76. else
  77. {
  78. logMessage ("No audio device open");
  79. }
  80. }
  81. void logMessage (const String& m)
  82. {
  83. diagnosticsBox.moveCaretToEnd();
  84. diagnosticsBox.insertTextAtCaret (m + newLine);
  85. }
  86. private:
  87. ScopedPointer<AudioDeviceSelectorComponent> audioSetupComp;
  88. TextEditor diagnosticsBox;
  89. void changeListenerCallback (ChangeBroadcaster*) override
  90. {
  91. dumpDeviceInfo();
  92. }
  93. static String getListOfActiveBits (const BitArray& b)
  94. {
  95. StringArray bits;
  96. for (int i = 0; i <= b.getHighestBit(); ++i)
  97. if (b[i])
  98. bits.add (String (i));
  99. return bits.joinIntoString (", ");
  100. }
  101. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSettingsDemo)
  102. };
  103. // This static object will register this demo type in a global list of demos..
  104. static JuceDemoType<AudioSettingsDemo> demo ("30 Audio: Settings");