Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS-only: Add input gain / "In Level" slider #255

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Source/ChannelGroupsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,6 @@ ChannelGroupsView::ChannelGroupsView(SonobusAudioProcessor& proc, bool peerMode,
//bgColor = Colour::fromFloatRGBA(0.045f, 0.045f, 0.05f, 1.0f);
bgColor = Colour::fromFloatRGBA(0.08f, 0.045f, 0.08f, 1.0f);

mInGainSlider = std::make_unique<Slider>(Slider::LinearHorizontal, Slider::TextBoxAbove);
mInGainSlider->setName("ingain");
mInGainSlider->setSliderSnapsToMousePosition(processor.getSlidersSnapToMousePosition());
mInGainSlider->setTextBoxIsEditable(true);
mInGainSlider->setScrollWheelEnabled(false);

mAddButton = std::make_unique<TextButton>("+");
mAddButton->setTitle(TRANS("Add Input Group"));
mAddButton->onClick = [this] { addGroupPressed(); };
Expand Down
1 change: 0 additions & 1 deletion Source/ChannelGroupsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ public MultiTimer



std::unique_ptr<Slider> mInGainSlider;
std::unique_ptr<TextButton> mAddButton;
std::unique_ptr<TextButton> mClearButton;
std::unique_ptr<TextButton> mInReverbButton;
Expand Down
3 changes: 3 additions & 0 deletions Source/CrossPlatformUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ void *binaryDataToUrlBookmark(const void * data, size_t size);

juce::URL generateUpdatedURL (juce::URL& urlToUse);

bool getIsInputGainSettable();
float getInputGain();
bool setInputGain(float gain);
#endif
18 changes: 18 additions & 0 deletions Source/CrossPlatformUtilsIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@



#import <AVFoundation/AVFoundation.h>

#import <UIKit/UIView.h>

#include "../JuceLibraryCode/JuceHeader.h"
Expand Down Expand Up @@ -109,5 +111,21 @@ bool urlBookmarkToBinaryData(void * bookmark, const void * & retdata, size_t & r
}


bool getIsInputGainSettable()
{
auto* session = [AVAudioSession sharedInstance];
return [session isInputGainSettable];
}

float getInputGain() {
auto* session = [AVAudioSession sharedInstance];
return [session inputGain];
}

bool setInputGain(float gain) {
auto* session = [AVAudioSession sharedInstance];
NSError* error;
return [session setInputGain:gain error:&error];
}

#endif
94 changes: 79 additions & 15 deletions Source/SonobusPluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "LatencyMatchView.h"
#include "SuggestNewGroupView.h"
#include "SonoCallOutBox.h"
#include "CrossPlatformUtils.h"

#include <sstream>

#if JUCE_ANDROID
Expand Down Expand Up @@ -423,12 +425,18 @@ SonobusAudioProcessorEditor::SonobusAudioProcessorEditor (SonobusAudioProcessor&
mPeerLayoutMinimalButton->setRadioGroupId(PeerLayoutRadioGroupId);


#if JUCE_IOS
mInGainSlider = std::make_unique<Slider>(Slider::LinearHorizontal, Slider::TextBoxAbove);
mInGainSlider->setName("ingain");
mInGainSlider->setTitle(TRANS("In Level"));
mInGainSlider->addListener(this);
mInGainSlider->setSliderSnapsToMousePosition(processor.getSlidersSnapToMousePosition());
mInGainSlider->setTextBoxIsEditable(true);
mInGainSlider->setScrollWheelEnabled(false);
mInGainSlider->setRange(0.0, 1.0);
mInGainSlider->setNumDecimalPlacesToDisplay(2);
mInGainSlider->setValue(getInputGain());
#endif


mInMixerButton = std::make_unique<TextButton>("mix");
Expand Down Expand Up @@ -630,25 +638,31 @@ SonobusAudioProcessorEditor::SonobusAudioProcessorEditor (SonobusAudioProcessor&
mOutGainSlider->setSliderSnapsToMousePosition(processor.getSlidersSnapToMousePosition());
mOutGainSlider->setScrollWheelEnabled(false);

#if JUCE_IOS
configLevelSlider(mInGainSlider.get());
#endif
configLevelSlider(mDrySlider.get());
configLevelSlider(mOutGainSlider.get());

mOutGainSlider->setTextBoxIsEditable(true);
mDrySlider->setTextBoxIsEditable(true);
#if JUCE_IOS
//mInGainSlider->setTextBoxIsEditable(true);
#endif

mDrySlider->setWantsKeyboardFocus(true);
mOutGainSlider->setWantsKeyboardFocus(true);



#if JUCE_IOS
mInGainLabel = std::make_unique<Label>(SonobusAudioProcessor::paramDry, TRANS("In Level"));
configLabel(mInGainLabel.get(), false);
mInGainLabel->setJustificationType(Justification::topLeft);
mInGainLabel->setTooltip(TRANS("This reduces or boosts the level of your own audio input, and it will affect the level of your audio being sent to others and your own monitoring"));
mInGainLabel->setInterceptsMouseClicks(true, false);
mInGainLabel->setAccessible(false);
#endif

mDryLabel = std::make_unique<Label>(SonobusAudioProcessor::paramDry, TRANS("Monitor"));
configLabel(mDryLabel.get(), false);
Expand All @@ -673,7 +687,6 @@ SonobusAudioProcessorEditor::SonobusAudioProcessorEditor (SonobusAudioProcessor&
smallerEditorFontsize = 16;
#endif

mInGainAttachment = std::make_unique<AudioProcessorValueTreeState::SliderAttachment> (p.getValueTreeState(), SonobusAudioProcessor::paramInGain, *mInGainSlider);
mDryAttachment = std::make_unique<AudioProcessorValueTreeState::SliderAttachment> (p.getValueTreeState(), SonobusAudioProcessor::paramDry, *mDrySlider);
mWetAttachment = std::make_unique<AudioProcessorValueTreeState::SliderAttachment> (p.getValueTreeState(), SonobusAudioProcessor::paramWet, *mOutGainSlider);
mMainSendMuteAttachment = std::make_unique<AudioProcessorValueTreeState::ButtonAttachment> (p.getValueTreeState(), SonobusAudioProcessor::paramMainSendMute, *mMainMuteButton);
Expand Down Expand Up @@ -806,6 +819,13 @@ SonobusAudioProcessorEditor::SonobusAudioProcessorEditor (SonobusAudioProcessor&

mMainContainer->addAndMakeVisible(mPeerContainer.get());

#if JUCE_IOS
mInGainContainer = std::make_unique<Component>();
mInGainContainer->addAndMakeVisible(mInGainLabel.get());
mInGainContainer->addAndMakeVisible(mInGainSlider.get());
mMainContainer->addChildComponent(mInGainContainer.get());
#endif

mInputChannelsContainer = std::make_unique<ChannelGroupsView>(processor, false);
mMainContainer->addChildComponent(mInputChannelsContainer.get());
mInputChannelsContainer->addListener(this);
Expand Down Expand Up @@ -1170,7 +1190,9 @@ SonobusAudioProcessorEditor::SonobusAudioProcessorEditor (SonobusAudioProcessor&

mTopLevelContainer->addAndMakeVisible(mDrySlider.get());
mTopLevelContainer->addAndMakeVisible(mOutGainSlider.get());
#if JUCE_IOS
//mTopLevelContainer->addAndMakeVisible(mInGainSlider.get());
#endif
mTopLevelContainer->addAndMakeVisible(mMainMuteButton.get());
mTopLevelContainer->addAndMakeVisible(mMainRecvMuteButton.get());
mTopLevelContainer->addAndMakeVisible(mMainPushToTalkButton.get());
Expand Down Expand Up @@ -1246,7 +1268,9 @@ SonobusAudioProcessorEditor::SonobusAudioProcessorEditor (SonobusAudioProcessor&



#if JUCE_IOS
//mTopLevelContainer->addAndMakeVisible(mInGainLabel.get());
#endif
mTopLevelContainer->addAndMakeVisible(mDryLabel.get());
mTopLevelContainer->addAndMakeVisible(mOutGainLabel.get());
mTopLevelContainer->addAndMakeVisible(inputMeter.get());
Expand Down Expand Up @@ -1938,6 +1962,8 @@ void SonobusAudioProcessorEditor::timerCallback(int timerid)

#if JUCE_IOS
if (JUCEApplicationBase::isStandaloneApp()) {
getAudioDeviceManager()->addChangeListener(this);

bool iaaconn = isInterAppAudioConnected();
if (iaaconn != iaaConnected) {
iaaConnected = iaaconn;
Expand Down Expand Up @@ -2041,6 +2067,10 @@ void SonobusAudioProcessorEditor::buttonClicked (Button* buttonThatWasClicked)
}
else if (buttonThatWasClicked == mInMixerButton.get()) {

#if JUCE_IOS
mInGainContainer->setVisible(getIsInputGainSettable() && mInMixerButton->getToggleState());
#endif

mInputChannelsContainer->setVisible(mInMixerButton->getToggleState());
mInputChannelsContainer->rebuildChannelViews();
resized();
Expand Down Expand Up @@ -2806,7 +2836,9 @@ void SonobusAudioProcessorEditor::updateSliderSnap()
slider->setSliderSnapsToMousePosition(slider->getWidth() > minsize && snap);
};

//snapset(mInGainSlider.get());
#if JUCE_IOS
snapset(mInGainSlider.get());
#endif
snapset(mOutGainSlider.get());
snapset(mDrySlider.get());
//snapset(mOptionsDefaultLevelSlider.get());
Expand Down Expand Up @@ -3207,6 +3239,14 @@ void SonobusAudioProcessorEditor::showConnectPopup(bool flag)

void SonobusAudioProcessorEditor::sliderValueChanged (Slider* slider)
{
#if JUCE_IOS
if (slider == mInGainSlider.get()) {
if (getIsInputGainSettable()) {
setInputGain(slider->getValue());
}
return;
}
#endif
}

void SonobusAudioProcessorEditor::mouseDown (const MouseEvent& event)
Expand Down Expand Up @@ -4525,10 +4565,22 @@ void SonobusAudioProcessorEditor::resized()
Rectangle<int> peersminbounds = mPeerContainer->getMinimumContentBounds();
Rectangle<int> inmixminbounds = mInputChannelsContainer->getMinimumContentBounds();

Rectangle<int> ingainactualbounds = Rectangle<int>(0,0,0,0);
Rectangle<int> inmixactualbounds = Rectangle<int>(0,0,0,0);

#if JUCE_IOS
if (mInGainContainer->isVisible()) {
ingainactualbounds = Rectangle<int>(0, 5,
std::max(inmixminbounds.getWidth(), inchantargwidth),
45);

mInGainSlider->setBounds(ingainactualbounds);
mInGainContainer->setBounds(ingainactualbounds);
}
#endif

if (mInputChannelsContainer->isVisible()) {
inmixactualbounds = Rectangle<int>(0, 0,
inmixactualbounds = Rectangle<int>(0, ingainactualbounds.getBottom() + 5,
std::max(inmixminbounds.getWidth(), inchantargwidth),
inmixminbounds.getHeight() + 5);

Expand Down Expand Up @@ -4602,11 +4654,15 @@ void SonobusAudioProcessorEditor::resized()

mDrySlider->setMouseDragSensitivity(jmax(128, mDrySlider->getWidth()));
mOutGainSlider->setMouseDragSensitivity(jmax(128, mOutGainSlider->getWidth()));
//mInGainSlider->setMouseDragSensitivity(jmax(128, mInGainSlider->getWidth()));
#if JUCE_IOS
mInGainSlider->setMouseDragSensitivity(jmax(128, mInGainSlider->getWidth()));
#endif

mDryLabel->setBounds(mDrySlider->getBounds().removeFromTop(17).removeFromLeft(mDrySlider->getWidth() - mDrySlider->getTextBoxWidth() + 3).translated(4, -2));
//mInGainLabel->setBounds(mInGainSlider->getBounds().removeFromTop(14).removeFromLeft(mInGainSlider->getWidth() - mInGainSlider->getTextBoxWidth() + 3).translated(4, 0));
mOutGainLabel->setBounds(mOutGainSlider->getBounds().removeFromTop(17).removeFromLeft(mOutGainSlider->getWidth() - mOutGainSlider->getTextBoxWidth() + 3).translated(4, -2));
mDryLabel->setBounds(mDrySlider->getBounds().removeFromTop(14).removeFromLeft(mDrySlider->getWidth() - mDrySlider->getTextBoxWidth() + 3).translated(4, 0));
#if JUCE_IOS
mInGainLabel->setBounds(mInGainSlider->getBounds().removeFromTop(14).removeFromLeft(mInGainSlider->getWidth() - mInGainSlider->getTextBoxWidth() + 3).translated(4, 0));
#endif
mOutGainLabel->setBounds(mOutGainSlider->getBounds().removeFromTop(14).removeFromLeft(mOutGainSlider->getWidth() - mOutGainSlider->getTextBoxWidth() + 3).translated(4, 0));



Expand Down Expand Up @@ -4659,13 +4715,12 @@ void SonobusAudioProcessorEditor::updateLayout()
int inmixw = 74;
int choicew = inmixw + mutew + 3;

inGainBox.items.clear();
inGainBox.flexDirection = FlexBox::Direction::row;
//inGainBox.items.add(FlexItem(minKnobWidth, minitemheight, *mInGainSlider).withMargin(0).withFlex(1));
//inGainBox.items.add(FlexItem(choicew, minitemheight, *mSendChannelsLabel).withMargin(0).withFlex(0.5));
inGainBox.items.add(FlexItem(2, 6).withMargin(0).withFlex(0.1));
inGainBox.items.add(FlexItem(choicew, minitemheight, *mSendChannelsChoice).withMargin(0).withFlex(1).withMaxWidth(160));
inGainBox.items.add(FlexItem(2, 6).withMargin(0).withFlex(0.1));
sendChannelsBox.items.clear();
sendChannelsBox.flexDirection = FlexBox::Direction::row;
//sendChannelsBox.items.add(FlexItem(choicew, minitemheight, *mSendChannelsLabel).withMargin(0).withFlex(0.5));
sendChannelsBox.items.add(FlexItem(2, 6).withMargin(0).withFlex(0.1));
sendChannelsBox.items.add(FlexItem(choicew, minitemheight, *mSendChannelsChoice).withMargin(0).withFlex(1).withMaxWidth(160));
sendChannelsBox.items.add(FlexItem(2, 6).withMargin(0).withFlex(0.1));

dryBox.items.clear();
dryBox.flexDirection = FlexBox::Direction::row;
Expand Down Expand Up @@ -4696,7 +4751,7 @@ void SonobusAudioProcessorEditor::updateLayout()

inputLeftBox.items.clear();
inputLeftBox.flexDirection = FlexBox::Direction::column;
inputLeftBox.items.add(FlexItem(choicew + 4, minitemheight, inGainBox).withMargin(0).withFlex(1)); //.withMaxWidth(isNarrow ? 160 : 120));
inputLeftBox.items.add(FlexItem(choicew + 4, minitemheight, sendChannelsBox).withMargin(0).withFlex(1)); //.withMaxWidth(isNarrow ? 160 : 120));
inputLeftBox.items.add(FlexItem(4, 4).withMargin(0).withFlex(0));
inputLeftBox.items.add(FlexItem(mutew+inmixw + 10, minitemheight, inputPannerBox).withMargin(0).withFlex(1)); //.withMaxWidth(maxPannerWidth));

Expand Down Expand Up @@ -5174,6 +5229,15 @@ void SonobusAudioProcessorEditor::changeListenerCallback (ChangeBroadcaster* sou
} else if (source == &(processor.getTransportSource())) {
updateTransportState();
}
#if JUCE_IOS
else if (source == getAudioDeviceManager()) {
mInGainSlider->setValue(getInputGain(), sendNotificationSync);
if (mInMixerButton->getToggleState()) {
mInGainContainer->setVisible(getIsInputGainSettable());
resized();
}
}
#endif
}

class SonobusAudioProcessorEditor::TrimFileJob : public ThreadPoolJob
Expand Down
11 changes: 9 additions & 2 deletions Source/SonobusPluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ public PeersContainerView::Listener
std::unique_ptr<SonoDrawableButton> mMainLinkButton;
std::unique_ptr<Drawable> mMainLinkArrow;

#if JUCE_IOS
std::unique_ptr<Slider> mInGainSlider;
#endif

std::unique_ptr<TextButton> mInMixerButton;

Expand Down Expand Up @@ -332,7 +334,9 @@ public PeersContainerView::Listener
std::unique_ptr<DrawableRectangle> mFileAreaBg;


#if JUCE_IOS
std::unique_ptr<Label> mInGainLabel;
#endif
std::unique_ptr<Label> mDryLabel;
std::unique_ptr<Label> mWetLabel;
std::unique_ptr<Label> mOutGainLabel;
Expand Down Expand Up @@ -531,6 +535,10 @@ public PeersContainerView::Listener
std::unique_ptr<Component> mMainContainer;
std::unique_ptr<PeersContainerView> mPeerContainer;

#if JUCE_IOS
std::unique_ptr<Component> mInGainContainer;
#endif

std::unique_ptr<Viewport> mInputChannelsViewport;
std::unique_ptr<ChannelGroupsView> mInputChannelsContainer;

Expand Down Expand Up @@ -626,7 +634,7 @@ public PeersContainerView::Listener
FlexBox remoteSourceBox;
FlexBox remoteSinkBox;
FlexBox paramsBox;
FlexBox inGainBox;
FlexBox sendChannelsBox;
FlexBox dryBox;
FlexBox wetBox;
FlexBox toolbarBox;
Expand Down Expand Up @@ -697,7 +705,6 @@ public PeersContainerView::Listener

std::unique_ptr<CustomTooltipWindow> tooltipWindow;

std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> mInGainAttachment;
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> mDryAttachment;
std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> mWetAttachment;
std::unique_ptr<AudioProcessorValueTreeState::ButtonAttachment> mMainSendMuteAttachment;
Expand Down
12 changes: 0 additions & 12 deletions Source/SonobusPluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ typedef int socklen_t;
#define SENDBUFSIZE_SCALAR 2.0f
#define PEER_PING_INTERVAL_MS 2000.0

String SonobusAudioProcessor::paramInGain ("ingain");
String SonobusAudioProcessor::paramDry ("dry");
String SonobusAudioProcessor::paramInMonitorMonoPan ("inmonmonopan");
String SonobusAudioProcessor::paramInMonitorPan1 ("inmonpan1");
Expand Down Expand Up @@ -602,10 +601,6 @@ soundboardChannelProcessor(std::make_unique<SoundboardChannelProcessor>()),
mGlobalState("SonobusGlobalState"),
mState (*this, &mUndoManager, "SonoBusAoO",
{
std::make_unique<AudioParameterFloat>(ParameterID(paramInGain, 1), TRANS ("In Gain"), NormalisableRange<float>(0.0, 4.0, 0.0, 0.33), mInGain.get(), "", AudioProcessorParameter::genericParameter,
[](float v, int maxlen) -> String { return Decibels::toString(Decibels::gainToDecibels(v), 1); },
[](const String& s) -> float { return Decibels::decibelsToGain(s.getFloatValue()); }),

std::make_unique<AudioParameterFloat>(ParameterID(paramInMonitorMonoPan, 1), TRANS ("In Pan"), NormalisableRange<float>(-1.0, 1.0, 0.0), mInMonMonoPan.get(), "", AudioProcessorParameter::genericParameter,
[](float v, int maxlen) -> String { if (fabs(v) < 0.01) return TRANS("C"); return String((int)rint(abs(v*100.0f))) + ((v > 0 ? "% R" : "% L")) ; },
[](const String& s) -> float { return s.getFloatValue()*1e-2f; }),
Expand Down Expand Up @@ -691,7 +686,6 @@ mState (*this, &mUndoManager, "SonoBusAoO",

})
{
mState.addParameterListener (paramInGain, this);
mState.addParameterListener (paramDry, this);
mState.addParameterListener (paramWet, this);
mState.addParameterListener (paramInMonitorMonoPan, this);
Expand Down Expand Up @@ -6567,12 +6561,6 @@ void SonobusAudioProcessor::parameterChanged (const String &parameterID, float n
if (parameterID == paramDry) {
mDry = newValue;
}
else if (parameterID == paramInGain) {
//mInGain = newValue; // NO LONGER USE GLOBAL mInGain

// for now just apply it to the first input channel group
//mInputChannelGroups[0].gain = newValue;
}
else if (parameterID == paramMetGain) {
mMetGain = newValue;
//mMetChannelGroup.params.gain = newValue;
Expand Down
1 change: 0 additions & 1 deletion Source/SonobusPluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ class SonobusAudioProcessor : public AudioProcessor, public AudioProcessorValue

AudioProcessorValueTreeState& getValueTreeState();

static String paramInGain;
static String paramInMonitorMonoPan;
static String paramInMonitorPan1;
static String paramInMonitorPan2;
Expand Down