-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow quick (de)activation of output channel
For audio devices with a high number of output channels it can be tedious having to activate or deactivate most channels. Offer buttons to do either very quickly so users only need to activate or deactivate a few more channels. The first channel won't be deactivated since JUCE requires at least one channel to be active.
- Loading branch information
1 parent
3af0035
commit 6d6fddb
Showing
5 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "AudioDeviceComponent.h" | ||
|
||
AudioDeviceComponent::AudioDeviceComponent(juce::AudioDeviceManager& audioDeviceManager) | ||
: selector(audioDeviceManager, 0, 0, 1, 64, false, false, false, false) | ||
, selectAllChannelsButton("selectAll") | ||
, deselectAllChannelsButton("deselectAll") | ||
{ | ||
addAndMakeVisible(selectAllChannelsButton); | ||
selectAllChannelsButton.setButtonText(TRANS("activate all channels")); | ||
selectAllChannelsButton.addListener(this); | ||
selectAllChannelsButton.setWantsKeyboardFocus(false); | ||
|
||
addAndMakeVisible(deselectAllChannelsButton); | ||
deselectAllChannelsButton.setButtonText(TRANS("deactivate all but first channel")); | ||
deselectAllChannelsButton.addListener(this); | ||
deselectAllChannelsButton.setWantsKeyboardFocus(false); | ||
|
||
addAndMakeVisible(selector); | ||
} | ||
|
||
void AudioDeviceComponent::resized() | ||
{ | ||
const static int buttonHeight = 24; | ||
const static int padding = 10; | ||
|
||
const int buttonWidth = (getWidth() - 3 * padding) / 2; | ||
|
||
selectAllChannelsButton.setBounds(padding, padding, buttonWidth, buttonHeight); | ||
deselectAllChannelsButton.setBounds(2 * padding + buttonWidth, padding, buttonWidth, buttonHeight); | ||
|
||
selector.setBounds(0, 2 * padding + buttonHeight, getWidth(), selector.getHeight()); | ||
} | ||
|
||
void AudioDeviceComponent::buttonClicked(juce::Button* buttonThatWasClicked) | ||
{ | ||
if (buttonThatWasClicked == &selectAllChannelsButton) | ||
{ | ||
juce::AudioDeviceManager& manager = selector.deviceManager; | ||
juce::AudioDeviceManager::AudioDeviceSetup setup = manager.getAudioDeviceSetup(); | ||
setup.useDefaultOutputChannels = false; | ||
for (int i = 0; i < manager.getCurrentAudioDevice()->getOutputChannelNames().size(); ++i) | ||
{ | ||
setup.outputChannels.setBit(i); | ||
} | ||
manager.setAudioDeviceSetup(setup, true); | ||
} | ||
else if (buttonThatWasClicked == &deselectAllChannelsButton) | ||
{ | ||
juce::AudioDeviceManager& manager = selector.deviceManager; | ||
juce::AudioDeviceManager::AudioDeviceSetup setup = manager.getAudioDeviceSetup(); | ||
setup.useDefaultOutputChannels = false; | ||
for (int i = 1; i < manager.getCurrentAudioDevice()->getOutputChannelNames().size(); ++i) | ||
{ | ||
setup.outputChannels.clearBit(i); | ||
} | ||
manager.setAudioDeviceSetup(setup, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "juce_audio_utils/juce_audio_utils.h" | ||
|
||
class AudioDeviceComponent | ||
: public juce::Component | ||
, public juce::Button::Listener | ||
{ | ||
public: | ||
AudioDeviceComponent(juce::AudioDeviceManager& audioDeviceManager); | ||
|
||
// Component | ||
void resized() override; | ||
|
||
// Button::Listener | ||
virtual void buttonClicked(juce::Button* buttonThatWasClicked) override; | ||
|
||
private: | ||
juce::AudioDeviceSelectorComponent selector; | ||
juce::TextButton selectAllChannelsButton; | ||
juce::TextButton deselectAllChannelsButton; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AudioDeviceComponent) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters