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
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-12 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "../JuceDemoHeader.h"
  19. //==============================================================================
  20. class AudioSettingsDemo : public Component,
  21. public ChangeListener
  22. {
  23. public:
  24. AudioSettingsDemo()
  25. {
  26. setOpaque (true);
  27. addAndMakeVisible (audioSetupComp
  28. = new AudioDeviceSelectorComponent (MainAppWindow::getSharedAudioDeviceManager(),
  29. 0, 256, 0, 256, true, true, true, false));
  30. addAndMakeVisible (diagnosticsBox);
  31. diagnosticsBox.setMultiLine (true);
  32. diagnosticsBox.setReturnKeyStartsNewLine (true);
  33. diagnosticsBox.setReadOnly (true);
  34. diagnosticsBox.setScrollbarsShown (true);
  35. diagnosticsBox.setCaretVisible (false);
  36. diagnosticsBox.setPopupMenuEnabled (true);
  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. fillTiledBackground (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 ("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");