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.

174 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: AudioSettingsDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Displays information about audio devices.
  24. dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
  25. juce_audio_processors, juce_audio_utils, juce_core,
  26. juce_data_structures, juce_events, juce_graphics,
  27. juce_gui_basics, juce_gui_extra
  28. exporters: xcode_mac, vs2022, linux_make, androidstudio, xcode_iphone
  29. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  30. type: Component
  31. mainClass: AudioSettingsDemo
  32. useLocalCopy: 1
  33. END_JUCE_PIP_METADATA
  34. *******************************************************************************/
  35. #pragma once
  36. #include "../Assets/DemoUtilities.h"
  37. //==============================================================================
  38. class AudioSettingsDemo final : public Component,
  39. public ChangeListener
  40. {
  41. public:
  42. AudioSettingsDemo()
  43. {
  44. setOpaque (true);
  45. #ifndef JUCE_DEMO_RUNNER
  46. RuntimePermissions::request (RuntimePermissions::recordAudio,
  47. [this] (bool granted)
  48. {
  49. int numInputChannels = granted ? 2 : 0;
  50. audioDeviceManager.initialise (numInputChannels, 2, nullptr, true, {}, nullptr);
  51. });
  52. #endif
  53. audioSetupComp.reset (new AudioDeviceSelectorComponent (audioDeviceManager,
  54. 0, 256, 0, 256, true, true, true, false));
  55. addAndMakeVisible (audioSetupComp.get());
  56. addAndMakeVisible (diagnosticsBox);
  57. diagnosticsBox.setMultiLine (true);
  58. diagnosticsBox.setReturnKeyStartsNewLine (true);
  59. diagnosticsBox.setReadOnly (true);
  60. diagnosticsBox.setScrollbarsShown (true);
  61. diagnosticsBox.setCaretVisible (false);
  62. diagnosticsBox.setPopupMenuEnabled (true);
  63. audioDeviceManager.addChangeListener (this);
  64. logMessage ("Audio device diagnostics:\n");
  65. dumpDeviceInfo();
  66. setSize (500, 600);
  67. }
  68. ~AudioSettingsDemo() override
  69. {
  70. audioDeviceManager.removeChangeListener (this);
  71. }
  72. void paint (Graphics& g) override
  73. {
  74. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground));
  75. }
  76. void resized() override
  77. {
  78. auto r = getLocalBounds().reduced (4);
  79. audioSetupComp->setBounds (r.removeFromTop (proportionOfHeight (0.65f)));
  80. diagnosticsBox.setBounds (r);
  81. }
  82. void dumpDeviceInfo()
  83. {
  84. logMessage ("--------------------------------------");
  85. logMessage ("Current audio device type: " + (audioDeviceManager.getCurrentDeviceTypeObject() != nullptr
  86. ? audioDeviceManager.getCurrentDeviceTypeObject()->getTypeName()
  87. : "<none>"));
  88. if (AudioIODevice* device = audioDeviceManager.getCurrentAudioDevice())
  89. {
  90. logMessage ("Current audio device: " + device->getName().quoted());
  91. logMessage ("Sample rate: " + String (device->getCurrentSampleRate()) + " Hz");
  92. logMessage ("Block size: " + String (device->getCurrentBufferSizeSamples()) + " samples");
  93. logMessage ("Output Latency: " + String (device->getOutputLatencyInSamples()) + " samples");
  94. logMessage ("Input Latency: " + String (device->getInputLatencyInSamples()) + " samples");
  95. logMessage ("Bit depth: " + String (device->getCurrentBitDepth()));
  96. logMessage ("Input channel names: " + device->getInputChannelNames().joinIntoString (", "));
  97. logMessage ("Active input channels: " + getListOfActiveBits (device->getActiveInputChannels()));
  98. logMessage ("Output channel names: " + device->getOutputChannelNames().joinIntoString (", "));
  99. logMessage ("Active output channels: " + getListOfActiveBits (device->getActiveOutputChannels()));
  100. }
  101. else
  102. {
  103. logMessage ("No audio device open");
  104. }
  105. }
  106. void logMessage (const String& m)
  107. {
  108. diagnosticsBox.moveCaretToEnd();
  109. diagnosticsBox.insertTextAtCaret (m + newLine);
  110. }
  111. private:
  112. // if this PIP is running inside the demo runner, we'll use the shared device manager instead
  113. #ifndef JUCE_DEMO_RUNNER
  114. AudioDeviceManager audioDeviceManager;
  115. #else
  116. AudioDeviceManager& audioDeviceManager { getSharedAudioDeviceManager() };
  117. #endif
  118. std::unique_ptr<AudioDeviceSelectorComponent> audioSetupComp;
  119. TextEditor diagnosticsBox;
  120. void changeListenerCallback (ChangeBroadcaster*) override
  121. {
  122. dumpDeviceInfo();
  123. }
  124. void lookAndFeelChanged() override
  125. {
  126. diagnosticsBox.applyFontToAllText (diagnosticsBox.getFont());
  127. }
  128. static String getListOfActiveBits (const BigInteger& b)
  129. {
  130. StringArray bits;
  131. for (int i = 0; i <= b.getHighestBit(); ++i)
  132. if (b[i])
  133. bits.add (String (i));
  134. return bits.joinIntoString (", ");
  135. }
  136. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSettingsDemo)
  137. };