ReaWwise

REAPER extension
Log | Files | Refs | Submodules

Import.h (7212B)


      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 #pragma once
     17 
     18 #include "Model/IDs.h"
     19 #include "Model/Waapi.h"
     20 #include "Model/Wwise.h"
     21 
     22 #include <algorithm>
     23 
     24 namespace AK::WwiseTransfer::Import
     25 {
     26 	enum class ContainerNameExistsOption : int
     27 	{
     28 		Unknown,
     29 		UseExisting,
     30 		CreateNew,
     31 		Replace
     32 	};
     33 
     34 	enum class AudioFilenameExistsOption
     35 	{
     36 		UseExisting = 1,
     37 		Replace
     38 	};
     39 
     40 	enum class ApplyTemplateOption
     41 	{
     42 		Always = 1,
     43 		NewObjectCreationOnly
     44 	};
     45 
     46 	enum class ObjectStatus
     47 	{
     48 		NoChange,
     49 		Replaced,
     50 		New,
     51 		NewRenamed
     52 	};
     53 
     54 	enum class WavStatus
     55 	{
     56 		Unknown,
     57 		Replaced,
     58 		New
     59 	};
     60 
     61 	struct PreviewItem
     62 	{
     63 		juce::String path;
     64 		juce::String originalsSubFolder;
     65 		juce::String audioFilePath;
     66 	};
     67 
     68 	struct Item : public PreviewItem
     69 	{
     70 		juce::String renderFilePath;
     71 		juce::String renderFileWavBase64;
     72 		juce::String renderFileName;
     73 	};
     74 
     75 	struct PreviewItemNode
     76 	{
     77 		juce::String name;
     78 		Wwise::ObjectType type{};
     79 		ObjectStatus objectStatus{};
     80 		juce::String audioFilePath;
     81 		WavStatus wavStatus{};
     82 		bool unresolvedWildcard{false};
     83 	};
     84 
     85 	struct HierarchyMappingNode
     86 	{
     87 		HierarchyMappingNode(const juce::String& name, bool nameValid, const juce::String& nameErrorMessage, Wwise::ObjectType type, bool typeValid, const juce::String& typeErrorMessage,
     88 			const juce::String& propertyTemplatePath, bool propertyTemplatePathEnabled, bool propertyTemplatePathValid, const juce::String& propertyTemplatePathErrorMessage, const juce::String& language)
     89 			: name(name)
     90 			, nameValid(nameValid)
     91 			, nameErrorMessage(nameErrorMessage)
     92 			, type(type)
     93 			, typeValid(typeValid)
     94 			, typeErrorMessage(typeErrorMessage)
     95 			, propertyTemplatePath(propertyTemplatePath)
     96 			, propertyTemplatePathEnabled(propertyTemplatePathEnabled)
     97 			, propertyTemplatePathValid(propertyTemplatePathValid)
     98 			, propertyTemplatePathErrorMessage(propertyTemplatePathErrorMessage)
     99 			, language(language)
    100 		{
    101 		}
    102 
    103 		HierarchyMappingNode(juce::String name, Wwise::ObjectType type)
    104 			: name(name)
    105 			, nameValid(true)
    106 			, type(type)
    107 			, typeValid(true)
    108 			, propertyTemplatePathEnabled(false)
    109 			, propertyTemplatePathValid(true)
    110 		{
    111 		}
    112 
    113 		juce::String name;
    114 		bool nameValid{};
    115 		juce::String nameErrorMessage;
    116 		Wwise::ObjectType type{};
    117 		bool typeValid{};
    118 		juce::String typeErrorMessage;
    119 		juce::String propertyTemplatePath;
    120 		bool propertyTemplatePathEnabled{};
    121 		bool propertyTemplatePathValid{};
    122 		juce::String propertyTemplatePathErrorMessage;
    123 		juce::String language;
    124 	};
    125 
    126 	struct Options
    127 	{
    128 		Options(const juce::String& importDestination, const juce::String& originalsSubfolder, const juce::String& hierarchyMappingPath)
    129 			: importDestination(importDestination)
    130 			, originalsSubfolder(originalsSubfolder)
    131 			, hierarchyMappingPath(hierarchyMappingPath)
    132 		{
    133 		}
    134 
    135 		juce::String importDestination;
    136 		juce::String originalsSubfolder;
    137 		juce::String hierarchyMappingPath;
    138 	};
    139 
    140 	struct Summary
    141 	{
    142 		struct Object
    143 		{
    144 			juce::String id;
    145 			Wwise::ObjectType type{};
    146 			juce::String propertyTemplatePath;
    147 			juce::String originalWavFilePath;
    148 			Import::WavStatus wavStatus{};
    149 			Import::ObjectStatus objectStatus{};
    150 		};
    151 
    152 		std::map<juce::String, Object> objects;
    153 		std::vector<AK::WwiseTransfer::Waapi::Error> errors;
    154 
    155 		using PathObjectPair = std::pair<juce::String, Object>;
    156 
    157 		int getNumAudiofilesTransfered() const
    158 		{
    159 			auto predicate = [](const PathObjectPair& pathObjectPair)
    160 			{
    161 				return pathObjectPair.second.type == Wwise::ObjectType::AudioFileSource;
    162 			};
    163 			return std::count_if(objects.begin(), objects.end(), predicate);
    164 		}
    165 
    166 		int getNumObjectsCreated() const
    167 		{
    168 			auto predicate = [](const PathObjectPair& pathObjectPair)
    169 			{
    170 				return pathObjectPair.second.objectStatus == Import::ObjectStatus::New;
    171 			};
    172 			return std::count_if(objects.begin(), objects.end(), predicate);
    173 		}
    174 
    175 		int getNumObjectTemplatesApplied() const
    176 		{
    177 			auto predicate = [](const PathObjectPair& pathObjectPair)
    178 			{
    179 				return pathObjectPair.second.propertyTemplatePath.isNotEmpty();
    180 			};
    181 			return std::count_if(objects.begin(), objects.end(), predicate);
    182 		}
    183 	};
    184 
    185 	namespace Task
    186 	{
    187 		struct Options
    188 		{
    189 			std::vector<Import::Item> importItems;
    190 			Import::ContainerNameExistsOption containerNameExistsOption{};
    191 			Import::ApplyTemplateOption applyTemplateOption{Import::ApplyTemplateOption::Always};
    192 			juce::String importDestination;
    193 			std::vector<Import::HierarchyMappingNode> hierarchyMappingNodeList;
    194 			juce::String originalsFolder;
    195 			juce::String languageSubfolder;
    196 			juce::String selectObjectsOnImportCommand;
    197 			bool applyTemplateFeatureEnabled{false};
    198 			bool undoGroupFeatureEnabled{false};
    199 			bool waqlEnabled{false};
    200 		};
    201 	} // namespace Task
    202 } // namespace AK::WwiseTransfer::Import
    203 
    204 template <>
    205 struct juce::VariantConverter<AK::WwiseTransfer::Import::ContainerNameExistsOption>
    206 {
    207 	static AK::WwiseTransfer::Import::ContainerNameExistsOption fromVar(const juce::var& v)
    208 	{
    209 		return static_cast<AK::WwiseTransfer::Import::ContainerNameExistsOption>(int(v));
    210 	}
    211 
    212 	static juce::var toVar(AK::WwiseTransfer::Import::ContainerNameExistsOption option)
    213 	{
    214 		return int(option);
    215 	}
    216 };
    217 
    218 template <>
    219 struct juce::VariantConverter<AK::WwiseTransfer::Import::AudioFilenameExistsOption>
    220 {
    221 	static AK::WwiseTransfer::Import::AudioFilenameExistsOption fromVar(const juce::var& v)
    222 	{
    223 		return static_cast<AK::WwiseTransfer::Import::AudioFilenameExistsOption>(int(v));
    224 	}
    225 
    226 	static juce::var toVar(AK::WwiseTransfer::Import::AudioFilenameExistsOption option)
    227 	{
    228 		return int(option);
    229 	}
    230 };
    231 
    232 template <>
    233 struct juce::VariantConverter<AK::WwiseTransfer::Import::ApplyTemplateOption>
    234 {
    235 	static AK::WwiseTransfer::Import::ApplyTemplateOption fromVar(const juce::var& v)
    236 	{
    237 		return static_cast<AK::WwiseTransfer::Import::ApplyTemplateOption>(int(v));
    238 	}
    239 
    240 	static juce::var toVar(AK::WwiseTransfer::Import::ApplyTemplateOption option)
    241 	{
    242 		return int(option);
    243 	}
    244 };
    245 
    246 template <>
    247 struct juce::VariantConverter<AK::WwiseTransfer::Import::ObjectStatus>
    248 {
    249 	static AK::WwiseTransfer::Import::ObjectStatus fromVar(const juce::var& v)
    250 	{
    251 		return static_cast<AK::WwiseTransfer::Import::ObjectStatus>(int(v));
    252 	}
    253 
    254 	static juce::var toVar(AK::WwiseTransfer::Import::ObjectStatus option)
    255 	{
    256 		return int(option);
    257 	}
    258 };
    259 
    260 template <>
    261 struct juce::VariantConverter<AK::WwiseTransfer::Import::WavStatus>
    262 {
    263 	static AK::WwiseTransfer::Import::WavStatus fromVar(const juce::var& v)
    264 	{
    265 		return static_cast<AK::WwiseTransfer::Import::WavStatus>(int(v));
    266 	}
    267 
    268 	static juce::var toVar(AK::WwiseTransfer::Import::WavStatus option)
    269 	{
    270 		return int(option);
    271 	}
    272 };