Skip to content

Commit

Permalink
add name customization; fix wem indexing; add option to stream, but d…
Browse files Browse the repository at this point in the history
…isable prefetching
  • Loading branch information
ArthurHeitmann committed Aug 25, 2024
1 parent 28af06b commit 691b114
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 55 deletions.
12 changes: 7 additions & 5 deletions lib/background/wemFilesIndexer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ class WemFilesLookup {
loadingCompleter = Completer();
lookup.clear();
var prefs = PreferencesData();
var waiExtractDir = prefs.waiExtractDir?.value;
if (waiExtractDir == null || waiExtractDir.isEmpty) {
var waiExtractDir = prefs.waiExtractDir?.value ?? "";
var wemExtractDir = prefs.wemExtractDir?.value ?? "";
if (waiExtractDir.isEmpty && wemExtractDir.isEmpty) {
loadingCompleter!.complete();
return;
}

try {
await _indexDir(waiExtractDir);
if (prefs.wemExtractDir != null && prefs.wemExtractDir!.value.isNotEmpty)
await _indexDir(prefs.wemExtractDir!.value);
if (waiExtractDir.isNotEmpty)
await _indexDir(waiExtractDir);
if (wemExtractDir.isNotEmpty)
await _indexDir(wemExtractDir);
} catch (e, s) {
print("Error indexing WAI files:");
print("$e\n$s");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import 'hierarchyBaseElements.dart';

class WwiseActorMixer extends WwiseHierarchyElement<BnkActorMixer> {
WwiseActorMixer({required super.wuId, required super.project, required super.chunk}) :
super(tagName: "ActorMixer", name: wwiseIdToStr(chunk.uid, fallbackPrefix: "Actor Mixer"), shortId: chunk.uid);
super(tagName: "ActorMixer", name: makeElementName(project, id: chunk.uid, parentId: chunk.baseParams.directParentID, category: "Actor Mixer"), shortId: chunk.uid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Future<void> saveAttenuationsIntoWu(WwiseProjectGenerator project) async {
var attenuationElement = WwiseAttenuation(
wuId: project.attenuationsWu.id,
project: project,
name: wwiseIdToStr(attenuation.uid, fallbackPrefix: "Attenuation"),
name: makeElementName(project, id: attenuation.uid, category: "Attenuation"),
attenuation: attenuation
);
project.attenuationsWu.children.add(attenuationElement);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/wwiseProjectGenerator/elements/wwiseEffect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WwiseEffect extends WwiseElement {
_config = config,
super(
tagName: "Effect",
name: wwiseIdToStr(effect.uid, fallbackPrefix: "Effect"),
name: makeElementName(project, id: effect.uid, category: "Effect"),
shortId: effect.uid,
comment: project.getComment(effect.uid),
properties: config.handler(effect.pluginData),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class WwiseMusicSwitch extends WwiseHierarchyElement<BnkMusicSwitch> {
WwiseMusicSwitch({required super.wuId, required super.project, required super.chunk}) :
super(
tagName: "MusicSwitchContainer",
name: "${wemIdsToNames[chunk.ulGroupID] ?? chunk.ulGroupID.toString()} Music Switch Container",
name: makeElementName(project, id: chunk.uid, parentId: chunk.getBaseParams().directParentID, name: wemIdsToNames[chunk.ulGroupID], category: "Music Switch Container"),
shortId: chunk.uid,
properties: [
if (chunk.bIsContinuousValidation != 1)
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/wwiseProjectGenerator/elements/wwiseMusicTrack.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ const _bnkFadeInterpolationToWwiseShape = {
class WwiseMusicTrack extends WwiseHierarchyElement<BnkMusicTrack> {
WwiseMusicTrack({required super.wuId, required super.project, required super.chunk}) : super(
tagName: "MusicTrack",
name: "${wemIdsToNames[chunk.sources.first.sourceID] ?? wemIdsToNames[chunk.sources.first.fileID] ?? chunk.uid.toString()} Music Track",
name: makeElementName(project, id: chunk.uid, parentId: chunk.baseParams.directParentID, name: wemIdsToNames[chunk.sources.first.sourceID] ?? wemIdsToNames[chunk.sources.first.fileID], category: "Music Track"),
shortId: chunk.uid,
properties: [
if (project.options.streaming && (chunk.sources.firstOrNull?.streamType ?? 0) >= 1)
WwiseProperty("IsStreamingEnabled", "bool", values: ["True"]),
if (project.options.streaming && (chunk.sources.firstOrNull?.streamType ?? 0) == 2)
if (project.options.streaming && project.options.streamingPrefetch && (chunk.sources.firstOrNull?.streamType ?? 0) == 2)
WwiseProperty("IsZeroLantency", "bool", values: ["True"]),
if (chunk.iLookAheadTime != 100)
WwiseProperty("LookAheadTime", "int16", value: chunk.iLookAheadTime.toString()),
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/wwiseProjectGenerator/elements/wwiseSound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WwiseSound extends WwiseHierarchyElement<BnkSound> {
properties: [
if (project.options.streaming && chunk.bankData.streamType >= 1)
WwiseProperty("IsStreamingEnabled", "bool", values: ["True"]),
if (project.options.streaming && chunk.bankData.streamType == 2)
if (project.options.streaming && project.options.streamingPrefetch && chunk.bankData.streamType == 2)
WwiseProperty("IsZeroLantency", "bool", values: ["True"]),
],
children: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'package:xml/xml.dart';

import '../../../fileTypeUtils/audio/bnkIO.dart';
import '../../../fileTypeUtils/audio/wemIdsToNames.dart';
import '../../utils.dart';
import '../wwiseElement.dart';
import '../wwiseProperty.dart';
Expand All @@ -14,7 +15,7 @@ class WwiseSwitchContainer extends WwiseHierarchyElement<BnkSoundSwitch> {

WwiseSwitchContainer({required super.wuId, required super.project, required super.chunk, required this.childElements}) : super(
tagName: "SwitchContainer",
name: "${wwiseIdToStr(chunk.ulGroupID, fallbackPrefix: "Switch Container")} (${chunk.uid})",
name: makeElementName(project, id: chunk.uid, parentId: chunk.baseParams.directParentID, name: wemIdsToNames[chunk.ulGroupID], category: "Switch Container"),
shortId: chunk.uid,
properties: [
if (chunk.eGroupType == 1)
Expand Down
59 changes: 31 additions & 28 deletions lib/utils/wwiseProjectGenerator/wwiseProjectGenerator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,26 @@ class WwiseProjectGeneratorOptions {
final bool audioHierarchy;
final bool wems;
final bool streaming;
final bool streamingPrefetch;
final bool seekTable;
final bool translate;
final bool events;
final bool actions;
final bool nameId;
final bool namePrefix;

WwiseProjectGeneratorOptions({
this.audioHierarchy = true,
this.wems = true,
this.streaming = true,
this.seekTable = true,
this.translate = true,
this.events = true,
this.actions = true,
required this.audioHierarchy,
required this.wems,
required this.streaming,
required this.streamingPrefetch,
required this.seekTable,
required this.translate,
required this.events,
required this.actions,
required this.nameId,
required this.namePrefix,
});

WwiseProjectGeneratorOptions copyWith({
bool? audioHierarchy,
bool? gameSyncs,
bool? wems,
bool? streaming,
bool? seekTable,
bool? translate,
bool? events,
bool? actions,
}) {
return WwiseProjectGeneratorOptions(
audioHierarchy: audioHierarchy ?? this.audioHierarchy,
wems: wems ?? this.wems,
streaming: streaming ?? this.streaming,
seekTable: seekTable ?? this.seekTable,
translate: translate ?? this.translate,
events: events ?? this.events,
actions: actions ?? this.actions,
);
}
}

class WwiseProjectGeneratorStatus {
Expand All @@ -100,6 +85,7 @@ class WwiseProjectGenerator {
final Map<String, WwiseElementBase> _elements = {};
final Map<int, String> shortToFullId = {};
final WwiseIdGenerator idGen;
final Map<int, Map<String, int>> _usedNamesByParent = {};
final Map<int, WwiseAudioFile> soundFiles = {};
final Map<int, WwiseSwitchOrStateGroup> stateGroups = {};
final Map<int, WwiseSwitchOrStateGroup> switchGroups = {};
Expand Down Expand Up @@ -288,6 +274,23 @@ class WwiseProjectGenerator {
return comment;
}

String makeName(String name, int parentId) {
if (!_usedNamesByParent.containsKey(parentId))
_usedNamesByParent[parentId] = {};
var usedNames = _usedNamesByParent[parentId]!;
var i = _usedNamesByParent[parentId]![name] ?? 1;
var newName = name;
if (i > 1)
newName = "$name $i";
i++;
while (usedNames.containsKey(newName)) {
i++;
newName = "$name $i";
}
usedNames[name] = i;
return newName;
}

Future<void> _enableSeekTable() async {
var wuPath = join(projectPath, "Conversion Settings", "Factory Conversion Settings.wwu");
var wuDoc = XmlDocument.parse(await File(wuPath).readAsString());
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/wwiseProjectGenerator/wwiseUtils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ String getCommonString(List<String> strings) {
return strings.first.substring(0, minLen);
}

String makeElementName(WwiseProjectGenerator project, {required int id, required String category, String? name, int? parentId, List<int>? childIds, bool addId = false}) {
String makeElementName(WwiseProjectGenerator project, {required int id, required String category, int parentId = 0, String? name, List<int>? childIds, bool addId = false}) {
String? parentPrefix;
if (parentId != null) {
if (parentId != 0 && project.options.namePrefix) {
var parent = project.hircChunkById<BnkHircChunkBase>(parentId);
int? stateId;
if (parent is BnkSoundSwitch) {
Expand Down Expand Up @@ -138,7 +138,7 @@ String makeElementName(WwiseProjectGenerator project, {required int id, required
name ??= category;
if (parentPrefix != null)
name = parentPrefix + name;
if (addId)
if (addId && project.options.nameId)
name += " ($id)";
return name;
return project.makeName(name, parentId);
}
55 changes: 45 additions & 10 deletions lib/widgets/misc/wwiseProjectGeneratorPopup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu
final optAudioHierarchy = BoolProp(true, fileId: null);
final optWems = BoolProp(true, fileId: null);
final optStreaming = BoolProp(true, fileId: null);
final optStreamingPrefetch = BoolProp(true, fileId: null);
final optSeekTable = BoolProp(true, fileId: null);
final optTranslate = BoolProp(true, fileId: null);
final optNameId = BoolProp(false, fileId: null);
final optNamePrefix = BoolProp(true, fileId: null);
final optEvents = BoolProp(true, fileId: null);
final optActions = BoolProp(true, fileId: null);
final List<(String, BoolProp)> labeledOptions = [];
final savePath = StringProp("", fileId: null);
WwiseProjectGenerator? generator;
bool hasStarted = false;
Expand All @@ -66,15 +68,6 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu
super.initState();
if (!widget.bnkName.contains("BGM"))
optSeekTable.value = false;
labeledOptions.addAll([
("Actor-Mixer & Interactive Music Hierarchy", optAudioHierarchy),
("Events", optEvents),
("Actions", optActions),
("WAV sources (requires \"WEM Extract Directory\" from settings)", optWems),
("Use seek table for wems", optSeekTable),
("Copy streaming settings", optStreaming),
("Translate Japanese notes", optTranslate),
]);
var prefs = PreferencesData();
savePath.value = prefs.lastWwiseProjectDir?.value ?? "";
status.logs.addListener(onNewLog);
Expand Down Expand Up @@ -104,6 +97,20 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu
}

List<Widget> _makeOptions(BuildContext context) {
var labeledOptions = [
("Actor-Mixer & Interactive Music Hierarchy", optAudioHierarchy),
("Events", optEvents),
("Actions", optActions),
("WAV sources (requires \"WEM Extract Directory\" from settings)", optWems),
("Use seek table for wems", optSeekTable),
("Copy streaming settings", optStreaming),
("Copy streaming zero latency settings", optStreamingPrefetch),
("Translate Japanese notes", optTranslate),
];
var labeledNameOptions = [
("Parent state as prefix", optNamePrefix),
("Object ID", optNameId),
];
return [
Row(
children: [
Expand Down Expand Up @@ -142,6 +149,31 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu
),
],
),
Row(
children: [
Text("Name settings: ", style: Theme.of(context).textTheme.bodyMedium),
for (var (label, prop) in labeledNameOptions)
Row(
children: [
BoolPropCheckbox(prop: prop),
const SizedBox(width: 5),
GestureDetector(
onTap: () => prop.value = !prop.value,
child: Text(label, style: Theme.of(context).textTheme.bodyMedium)
),
],
),
],
),
ChangeNotifierBuilder(
notifiers: [optNameId, optNamePrefix],
builder: (context) => Text(
"Preview: "
"${(optNamePrefix.value ? "[Intro] " : "")}"
"Stage_Prologue "
"${(optNameId.value ? "(715346925)" : "")}",
),
),
const SizedBox(height: 15),
Align(
alignment: Alignment.center,
Expand Down Expand Up @@ -216,10 +248,13 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu
audioHierarchy: optAudioHierarchy.value,
wems: optWems.value,
streaming: optStreaming.value,
streamingPrefetch: optStreamingPrefetch.value,
seekTable: optSeekTable.value,
translate: optTranslate.value,
events: optEvents.value,
actions: optActions.value,
nameId: optNameId.value,
namePrefix: optNamePrefix.value,
);
hasStarted = true;
setState(() {});
Expand Down

0 comments on commit 691b114

Please sign in to comment.