I’m trying to setup Quartz through C++ to use for a rhythm project I’m playing around with. However, while the documentation for BP is fairly decent - it is entirely non-existent for C++.
This is how I try and initialize my Quartz clock and its settings;
BeginPlay() Method
void ANewConductor::BeginPlay()
{
if (!IsValid(Chart)) return;
AudioComponent->SetSound(Chart->Sound);
UQuartzSubsystem* QuartzSubsystem = AudioComponent->GetQuartzSubsystem();
const UWorld* World = AudioComponent->QuartzGetWorld();
FQuartzClockSettings ClockSettings = FQuartzClockSettings();
ClockSettings.TimeSignature.NumBeats = 4;
ClockSettings.TimeSignature.BeatType = EQuartzTimeSignatureQuantization::QuarterNote;
ClockHandle = QuartzSubsystem->CreateNewClock(World, FName("ConductorClock"), ClockSettings);
FQuartzQuantizationBoundary QuantizationBoundary = FQuartzQuantizationBoundary();
QuantizationBoundary.Quantization = EQuartzCommandQuantization::Beat;
QuantizationBoundary.CountingReferencePoint = EQuarztQuantizationReference::BarRelative;
FOnQuartzMetronomeEventBP MetronomeEvent = FOnQuartzMetronomeEventBP();
MetronomeEvent.BindUFunction(this, "OnBar");
FOnQuartzCommandEventBP CommandEvent = FOnQuartzCommandEventBP();
CommandEvent.BindUFunction(this, "IgnoreMe");
ClockHandle->SetBeatsPerMinute(World, QuantizationBoundary, CommandEvent, ClockHandle, Chart->BeatsPerMinute);
ClockHandle->SubscribeToQuantizationEvent(World, EQuartzCommandQuantization::Bar, MetronomeEvent, ClockHandle);
ClockHandle->StartClock(World, ClockHandle);
AudioComponent->PlayQuantized(World, ClockHandle, QuantizationBoundary, CommandEvent, 0.0f, 0.0f, 0.25f);
}
And these are the errors;
Errors
- Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x0000000000000198
- [Callstack] 0x00007fff06f1adbb UnrealEditor-AudioMixer.dll!UQuartzClockHandle::SetBeatsPerMinute() [D:\build\++UE5\Sync\Engine\Source\Runtime\AudioMixer\Private\Quartz\AudioMixerClockHandle.cpp:463]
- [Callstack] 0x00007ffeed1d33cc UnrealEditor-MusicGame.dll!ANewConductor::BeginPlay() [C:\Users\Dealman\Documents\Unreal Projects\MusicGame\Source\MusicGame\Private\NewConductor.cpp:54]
- [Callstack] 0x00007fff120c4fef UnrealEditor-Engine.dll!AActor::DispatchBeginPlay() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Actor.cpp:3849]
- [Callstack] 0x00007fff13ebcae2 UnrealEditor-Engine.dll!AWorldSettings::NotifyBeginPlay() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\WorldSettings.cpp:283]
- [Callstack] 0x00007fff129f9d11 UnrealEditor-Engine.dll!AGameStateBase::HandleBeginPlay() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\GameStateBase.cpp:205]
- [Callstack] 0x00007fff13de6298 UnrealEditor-Engine.dll!UWorld::BeginPlay() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\World.cpp:4908]
- [Callstack] 0x00007fff129b45d5 UnrealEditor-Engine.dll!UGameInstance::StartPlayInEditorGameInstance() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\GameInstance.cpp:500]
- [Callstack] 0x00007fff10099918 UnrealEditor-UnrealEd.dll!UEditorEngine::CreateInnerProcessPIEGameInstance() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:3052]
- [Callstack] 0x00007fff100cece6 UnrealEditor-UnrealEd.dll!UEditorEngine::OnLoginPIEComplete_Deferred() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1568]
- [Callstack] 0x00007fff1009a3c2 UnrealEditor-UnrealEd.dll!UEditorEngine::CreateNewPlayInEditorInstance() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1830]
- [Callstack] 0x00007fff100ed4aa UnrealEditor-UnrealEd.dll!UEditorEngine::StartPlayInEditorSession() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:2798]
- [Callstack] 0x00007fff100f0cb7 UnrealEditor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequestImpl() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1148]
- [Callstack] 0x00007fff100f05a1 UnrealEditor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequest() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp:1051]
- [Callstack] 0x00007fff0fa8dcf3 UnrealEditor-UnrealEd.dll!UEditorEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\EditorEngine.cpp:1665]
- [Callstack] 0x00007fff1041aac6 UnrealEditor-UnrealEd.dll!UUnrealEdEngine::Tick() [D:\build\++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\UnrealEdEngine.cpp:474]
- [Callstack] 0x00007ff7e6d482f6 UnrealEditor.exe!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:5215]
- [Callstack] 0x00007ff7e6d60d9c UnrealEditor.exe!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:183]
- [Callstack] 0x00007ff7e6d60e8a UnrealEditor.exe!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:147]
- [Callstack] 0x00007ff7e6d63c4d UnrealEditor.exe!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:283]
- [Callstack] 0x00007ff7e6d75564 UnrealEditor.exe!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:330]
- [Callstack] 0x00007ff7e6d78736 UnrealEditor.exe!__scrt_common_main_seh() [d:\a01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
- [Callstack] 0x00007fffb7177034 KERNEL32.DLL!UnknownFunction []
- [Callstack] 0x00007fffb76c2651 ntdll.dll!UnknownFunction []
The line in particular from my class that show up in the error is this;
ClockHandle->SubscribeToQuantizationEvent(World, EQuartzCommandQuantization::Bar, MetronomeEvent, ClockHandle);
And this is how my event is defined;
// Header
UFUNCTION()
void OnBar(FName ClockName, EQuartzCommandQuantization QuantizationType, int32 NumBars, int32 Beat, float BeatFraction);
// Code
void ANewConductor::OnBar(FName ClockName, EQuartzCommandQuantization QuantizationType, int32 NumBars, int32 Beat, float BeatFraction)
{
GEngine->AddOnScreenDebugMessage(1, 0.3f, FColor::Green, FString::Printf(TEXT("Bar Event")));
}
I’ve been stumped by this for quite a while now, have tried so much random stuff I can’t even remember what I’ve tried. Might be worth to mention that I’m still fairly new to C++.
Please, oh almighty @MaxHayes bestow thy infinite wisdom upon me