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.

172 lines
6.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2017 - ROLI Ltd.
  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, vs2017, linux_make, androidstudio, xcode_iphone
  29. type: Component
  30. mainClass: AudioSettingsDemo
  31. useLocalCopy: 1
  32. END_JUCE_PIP_METADATA
  33. *******************************************************************************/
  34. #pragma once
  35. #include "../Assets/DemoUtilities.h"
  36. //==============================================================================
  37. class AudioSettingsDemo : public Component,
  38. public ChangeListener
  39. {
  40. public:
  41. AudioSettingsDemo()
  42. {
  43. setOpaque (true);
  44. #ifndef JUCE_DEMO_RUNNER
  45. RuntimePermissions::request (RuntimePermissions::recordAudio,
  46. [this] (bool granted)
  47. {
  48. int numInputChannels = granted ? 2 : 0;
  49. audioDeviceManager.initialise (numInputChannels, 2, nullptr, true, {}, nullptr);
  50. });
  51. #endif
  52. audioSetupComp.reset (new AudioDeviceSelectorComponent (audioDeviceManager,
  53. 0, 256, 0, 256, true, true, true, false));
  54. addAndMakeVisible (audioSetupComp.get());
  55. addAndMakeVisible (diagnosticsBox);
  56. diagnosticsBox.setMultiLine (true);
  57. diagnosticsBox.setReturnKeyStartsNewLine (true);
  58. diagnosticsBox.setReadOnly (true);
  59. diagnosticsBox.setScrollbarsShown (true);
  60. diagnosticsBox.setCaretVisible (false);
  61. diagnosticsBox.setPopupMenuEnabled (true);
  62. audioDeviceManager.addChangeListener (this);
  63. logMessage ("Audio device diagnostics:\n");
  64. dumpDeviceInfo();
  65. setSize (500, 600);
  66. }
  67. ~AudioSettingsDemo()
  68. {
  69. audioDeviceManager.removeChangeListener (this);
  70. }
  71. void paint (Graphics& g) override
  72. {
  73. g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground));
  74. }
  75. void resized() override
  76. {
  77. auto r = getLocalBounds().reduced (4);
  78. audioSetupComp->setBounds (r.removeFromTop (proportionOfHeight (0.65f)));
  79. diagnosticsBox.setBounds (r);
  80. }
  81. void dumpDeviceInfo()
  82. {
  83. logMessage ("--------------------------------------");
  84. logMessage ("Current audio device type: " + (audioDeviceManager.getCurrentDeviceTypeObject() != nullptr
  85. ? audioDeviceManager.getCurrentDeviceTypeObject()->getTypeName()
  86. : "<none>"));
  87. if (AudioIODevice* device = audioDeviceManager.getCurrentAudioDevice())
  88. {
  89. logMessage ("Current audio device: " + device->getName().quoted());
  90. logMessage ("Sample rate: " + String (device->getCurrentSampleRate()) + " Hz");
  91. logMessage ("Block size: " + String (device->getCurrentBufferSizeSamples()) + " samples");
  92. logMessage ("Output Latency: " + String (device->getOutputLatencyInSamples()) + " samples");
  93. logMessage ("Input Latency: " + String (device->getInputLatencyInSamples()) + " samples");
  94. logMessage ("Bit depth: " + String (device->getCurrentBitDepth()));
  95. logMessage ("Input channel names: " + device->getInputChannelNames().joinIntoString (", "));
  96. logMessage ("Active input channels: " + getListOfActiveBits (device->getActiveInputChannels()));
  97. logMessage ("Output channel names: " + device->getOutputChannelNames().joinIntoString (", "));
  98. logMessage ("Active output channels: " + getListOfActiveBits (device->getActiveOutputChannels()));
  99. }
  100. else
  101. {
  102. logMessage ("No audio device open");
  103. }
  104. }
  105. void logMessage (const String& m)
  106. {
  107. diagnosticsBox.moveCaretToEnd();
  108. diagnosticsBox.insertTextAtCaret (m + newLine);
  109. }
  110. private:
  111. // if this PIP is running inside the demo runner, we'll use the shared device manager instead
  112. #ifndef JUCE_DEMO_RUNNER
  113. AudioDeviceManager audioDeviceManager;
  114. #else
  115. AudioDeviceManager& audioDeviceManager { getSharedAudioDeviceManager() };
  116. #endif
  117. std::unique_ptr<AudioDeviceSelectorComponent> audioSetupComp;
  118. TextEditor diagnosticsBox;
  119. void changeListenerCallback (ChangeBroadcaster*) override
  120. {
  121. dumpDeviceInfo();
  122. }
  123. void lookAndFeelChanged() override
  124. {
  125. diagnosticsBox.applyFontToAllText (diagnosticsBox.getFont());
  126. }
  127. static String getListOfActiveBits (const BigInteger& b)
  128. {
  129. StringArray bits;
  130. for (int i = 0; i <= b.getHighestBit(); ++i)
  131. if (b[i])
  132. bits.add (String (i));
  133. return bits.joinIntoString (", ");
  134. }
  135. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSettingsDemo)
  136. };