ReaWwise

REAPER extension
Log | Files | Refs | Submodules

WaapiNetworkTransferSettingsComponent.cpp (5773B)


      1 /*----------------------------------------------------------------------------------------
      2 
      3 Copyright (c) 2024 AUDIOKINETIC Inc.
      4 
      5 This file is licensed to use under the license available at:
      6 https://github.com/audiokinetic/ReaWwise/blob/main/License.txt (the "License").
      7 You may not use this file except in compliance with the License.
      8 
      9 Unless required by applicable law or agreed to in writing, software distributed
     10 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
     11 CONDITIONS OF ANY KIND, either express or implied.  See the License for the
     12 specific language governing permissions and limitations under the License.
     13 
     14 ----------------------------------------------------------------------------------------*/
     15 
     16 #include "WaapiNetworkTransferSettingsComponent.h"
     17 
     18 #include "AK/AkWwiseSDKVersion.h"
     19 #include "BinaryData.h"
     20 #include "Theme/CustomLookAndFeel.h"
     21 
     22 #include <juce_gui_basics/juce_gui_basics.h>
     23 
     24 #define AK_WWISE_VST_VERSION_FULL AK_WWISESDK_VERSIONNAME_SHORT "." AK_WWISESDK_NUM2STRING(AK_WWISESDK_VERSION_BUILD)
     25 
     26 namespace AK::WwiseTransfer
     27 {
     28 	namespace CrossMachineTransferComponentConstants
     29 	{
     30 		constexpr int editorBoxHeight = 26;
     31 		constexpr int labelWidth = 220;
     32 		constexpr int margin = 10;
     33 		constexpr int width = 370;
     34 		constexpr int height = 100;
     35 	} // namespace CrossMachineTransferComponentConstants
     36 
     37 	WaapiNetworkTransferSettingsComponent::WaapiNetworkTransferSettingsComponent(const juce::String& applicationName,
     38 		ApplicationProperties& appProps,
     39 		WaapiClientWatcher& waapiCW)
     40 		: applicationProperties(appProps)
     41 		, waapiClientWatcher(waapiCW)
     42 	{
     43 		using namespace CrossMachineTransferComponentConstants;
     44 
     45 		setSize(width, height);
     46 		setLookAndFeel(&lookAndFeel);
     47 
     48 		ipAddressLabel.setText("Waapi IP Address", juce::dontSendNotification);
     49 		ipAddressLabel.setBorderSize(juce::BorderSize(0));
     50 		ipAddressLabel.setMinimumHorizontalScale(1.0f);
     51 		ipAddressLabel.setJustificationType(juce::Justification::left);
     52 
     53 		ipAddressTextEditor.setFont(CustomLookAndFeelConstants::smallFontSize);
     54 		ipAddressTextEditor.setText(applicationProperties.getWaapiIp());
     55 		ipAddressTextEditor.onFocusLost = [this]
     56 		{
     57 			applicationProperties.setWaapiIp(ipAddressTextEditor.getText());
     58 			waapiClientWatcher.changeParameters(applicationProperties.getWaapiIp(), applicationProperties.getWaapiPort());
     59 		};
     60 
     61 		addAndMakeVisible(ipAddressLabel);
     62 		addAndMakeVisible(ipAddressTextEditor);
     63 
     64 		portLabel.setText("Waapi Port", juce::dontSendNotification);
     65 		portLabel.setBorderSize(juce::BorderSize(0));
     66 		portLabel.setMinimumHorizontalScale(1.0f);
     67 		portLabel.setJustificationType(juce::Justification::left);
     68 
     69 		portTextEditor.setFont(CustomLookAndFeelConstants::smallFontSize);
     70 		portTextEditor.setText(juce::String(applicationProperties.getWaapiPort()));
     71 		portTextEditor.onFocusLost = [this]
     72 		{
     73 			applicationProperties.setWaapiPort(portTextEditor.getTextValue().getValue());
     74 			waapiClientWatcher.changeParameters(applicationProperties.getWaapiIp(), applicationProperties.getWaapiPort());
     75 		};
     76 
     77 		addAndMakeVisible(portLabel);
     78 		addAndMakeVisible(portTextEditor);
     79 
     80 		enableCrossMachineTransferLabel.setText("Enable Cross Machine Transfer", juce::dontSendNotification);
     81 		enableCrossMachineTransferLabel.setBorderSize(juce::BorderSize(0));
     82 		enableCrossMachineTransferLabel.setMinimumHorizontalScale(1.0f);
     83 		enableCrossMachineTransferLabel.setJustificationType(juce::Justification::left);
     84 
     85 		enableCrossMachineTransferButton.setToggleState(applicationProperties.getIsCrossMachineTransferEnabled(), juce::dontSendNotification);
     86 		setToCrossMachineTransfer(applicationProperties.getIsCrossMachineTransferEnabled(), true);
     87 		enableCrossMachineTransferButton.onClick = [this]()
     88 		{
     89 			setToCrossMachineTransfer(!applicationProperties.getIsCrossMachineTransferEnabled());
     90 		};
     91 
     92 		addAndMakeVisible(enableCrossMachineTransferLabel);
     93 		addAndMakeVisible(enableCrossMachineTransferButton);
     94 	}
     95 
     96 	WaapiNetworkTransferSettingsComponent::~WaapiNetworkTransferSettingsComponent()
     97 	{
     98 		setLookAndFeel(nullptr);
     99 	}
    100 
    101 	void WaapiNetworkTransferSettingsComponent::resized()
    102 	{
    103 		using namespace CrossMachineTransferComponentConstants;
    104 
    105 		auto area = getLocalBounds();
    106 		area.reduce(margin, margin);
    107 
    108 		auto crossMachineTransferEnableSection = area.removeFromTop(editorBoxHeight);
    109 		{
    110 			enableCrossMachineTransferLabel.setBounds(crossMachineTransferEnableSection.removeFromLeft(labelWidth));
    111 			crossMachineTransferEnableSection.removeFromLeft(margin);
    112 
    113 			enableCrossMachineTransferButton.setBounds(crossMachineTransferEnableSection);
    114 		}
    115 
    116 		auto ipAddressSection = area.removeFromTop(editorBoxHeight);
    117 		{
    118 			ipAddressLabel.setBounds(ipAddressSection.removeFromLeft(labelWidth));
    119 			ipAddressSection.removeFromLeft(margin);
    120 
    121 			ipAddressTextEditor.setBounds(ipAddressSection);
    122 		}
    123 
    124 		auto portSection = area.removeFromTop(editorBoxHeight);
    125 		{
    126 			portLabel.setBounds(portSection.removeFromLeft(labelWidth));
    127 			portSection.removeFromLeft(margin);
    128 
    129 			portTextEditor.setBounds(portSection);
    130 		}
    131 	}
    132 
    133 	void WaapiNetworkTransferSettingsComponent::paint(juce::Graphics& g)
    134 	{
    135 		g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
    136 	}
    137 
    138 	void WaapiNetworkTransferSettingsComponent::setToCrossMachineTransfer(bool isCrossMachineTransfer, bool onInit)
    139 	{
    140 		applicationProperties.setIsCrossMachineTransferEnabled(isCrossMachineTransfer);
    141 		enableCrossMachineTransferButton.setToggleState(isCrossMachineTransfer, juce::dontSendNotification);
    142 		ipAddressTextEditor.setEnabled(isCrossMachineTransfer);
    143 		ipAddressTextEditor.setText(applicationProperties.getWaapiIp(), false);
    144 		if(!onInit)
    145 			waapiClientWatcher.changeParameters(applicationProperties.getWaapiIp(), applicationProperties.getWaapiPort());
    146 	}
    147 } // namespace AK::WwiseTransfer