ReaWwise

REAPER extension
Log | Files | Refs | Submodules

MainComponent.cpp (5654B)


      1 /*----------------------------------------------------------------------------------------
      2 
      3 Copyright (c) 2023 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 "MainComponent.h"
     17 
     18 #include "Persistance/ApplicationState.h"
     19 
     20 namespace AK::WwiseTransfer
     21 {
     22 	namespace MainComponentConstants
     23 	{
     24 		constexpr int margin = 10;
     25 		constexpr int originalsSubfolderComponentHeight = 62;
     26 		constexpr int importDestinationComponentHeight = 26;
     27 		constexpr int importComponentHeight = 292;
     28 		constexpr int importConflictsComponentHeight = 62;
     29 		constexpr int importControlsComponentHeight = 24;
     30 		constexpr int ouputLogComponentHeight = 50;
     31 		constexpr int mainComponentWidth = 600;
     32 		constexpr int mainComponentHeight = 600;
     33 		constexpr int connectionMonitorDelayDefault = 200;
     34 		constexpr int minConnectionRetryDelayDefault = 200;
     35 		constexpr int maxConnectionRetryDelayDefault = 1000;
     36 		constexpr int splitterHeight = 8;
     37 	} // namespace MainComponentConstants
     38 
     39 	MainComponent::MainComponent(DawContext& dawContext, const juce::String& applicationName)
     40 		: applicationState(ApplicationState::create())
     41 		, validator(applicationState, waapiClient)
     42 		, applicationProperties(applicationName)
     43 		, waapiClientWatcher(applicationState,
     44 			  waapiClient,
     45 			  WaapiClientWatcherConfig{applicationProperties.getWaapiIp(), applicationProperties.getWaapiPort(),
     46 				  MainComponentConstants::connectionMonitorDelayDefault, MainComponentConstants::minConnectionRetryDelayDefault,
     47 				  MainComponentConstants::maxConnectionRetryDelayDefault})
     48 		, originalsSubfolderComponent(applicationState, applicationName, applicationProperties, waapiClientWatcher)
     49 		, importDestinationComponent(applicationState, waapiClient)
     50 		, importComponent(applicationState, waapiClient, applicationProperties, applicationName)
     51 		, importPreviewComponent(applicationState)
     52 		, dawWatcher(applicationState, waapiClient, dawContext, applicationProperties.getPreviewRefreshInterval())
     53 		, importConflictsComponent(applicationState)
     54 		, importControlsComponent(applicationState, waapiClient, dawContext, applicationProperties, applicationName)
     55 		, featureSupport(applicationState, waapiClient)
     56 		, persistanceSupport(applicationState, dawContext)
     57 		, wwiseProjectSupport(applicationState, waapiClient)
     58 		, collapsedUI(applicationState, IDs::collapsedUI, nullptr)
     59 		, logger(applicationName)
     60 		, tooltipWindow(this)
     61 	{
     62 		using namespace MainComponentConstants;
     63 
     64 		if(hasScaleFactorOverride())
     65 			juce::Desktop::getInstance().setGlobalScaleFactor(applicationProperties.getScaleFactorOverride());
     66 
     67 		setSize(mainComponentWidth, mainComponentHeight);
     68 
     69 		juce::Logger::setCurrentLogger(&logger);
     70 
     71 		splitter.getToggleStateValue().referTo(collapsedUI.getPropertyAsValue());
     72 
     73 		waapiClientWatcher.start();
     74 		dawWatcher.start();
     75 
     76 		applicationState.addListener(this);
     77 
     78 		addAndMakeVisible(originalsSubfolderComponent);
     79 
     80 		addChildComponent(importDestinationComponent);
     81 		addChildComponent(importComponent);
     82 		addChildComponent(importConflictsComponent);
     83 
     84 		addAndMakeVisible(importPreviewComponent);
     85 		addAndMakeVisible(importControlsComponent);
     86 		addAndMakeVisible(splitter);
     87 
     88 		refreshComponent(false);
     89 	}
     90 
     91 	MainComponent::~MainComponent()
     92 	{
     93 		waapiClientWatcher.stop();
     94 		dawWatcher.stop();
     95 
     96 		applicationState.removeListener(this);
     97 
     98 		juce::Logger::setCurrentLogger(nullptr);
     99 	}
    100 
    101 	void MainComponent::resized()
    102 	{
    103 		using namespace MainComponentConstants;
    104 
    105 		auto area = getLocalBounds();
    106 		area.reduce(margin, margin);
    107 
    108 		originalsSubfolderComponent.setBounds(area.removeFromTop(originalsSubfolderComponentHeight));
    109 
    110 		if(!collapsedUI)
    111 		{
    112 			area.removeFromTop(margin);
    113 
    114 			importDestinationComponent.setBounds(area.removeFromTop(importDestinationComponentHeight));
    115 
    116 			area.removeFromTop(margin);
    117 
    118 			importComponent.setBounds(area.removeFromTop(importComponentHeight));
    119 
    120 			area.removeFromTop(margin);
    121 
    122 			importConflictsComponent.setBounds(area.removeFromTop(importConflictsComponentHeight));
    123 		}
    124 
    125 		area.removeFromTop(margin);
    126 
    127 		splitter.setBounds(area.removeFromTop(splitterHeight));
    128 
    129 		area.removeFromTop(margin);
    130 
    131 		importControlsComponent.setBounds(area.removeFromBottom(importControlsComponentHeight));
    132 
    133 		area.removeFromBottom(margin);
    134 
    135 		importPreviewComponent.setBounds(area);
    136 	}
    137 
    138 	void MainComponent::valueTreePropertyChanged(juce::ValueTree& treeWhosePropertyHasChanged, const juce::Identifier& property)
    139 	{
    140 		if(treeWhosePropertyHasChanged.getType() == IDs::application && property == IDs::collapsedUI)
    141 		{
    142 			triggerAsyncUpdate();
    143 		}
    144 	}
    145 
    146 	void MainComponent::handleAsyncUpdate()
    147 	{
    148 		refreshComponent(true);
    149 	}
    150 
    151 	void MainComponent::refreshComponent(bool shouldResize)
    152 	{
    153 		importDestinationComponent.setVisible(!collapsedUI);
    154 		importComponent.setVisible(!collapsedUI);
    155 		importConflictsComponent.setVisible(!collapsedUI);
    156 
    157 		if(shouldResize)
    158 			resized();
    159 	}
    160 
    161 	bool MainComponent::hasScaleFactorOverride()
    162 	{
    163 		return applicationProperties.getScaleFactorOverride() > 0.0;
    164 	}
    165 
    166 	void MainComponent::transferToWwise()
    167 	{
    168 		importControlsComponent.transferToWwise();
    169 	}
    170 } // namespace AK::WwiseTransfer