Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "CoreMinimal.h"
- #include <memory>
- #include "SoundManager_Fmod.h"
- #include "UObject/NoExportTypes.h"
- #include "Async/AsyncWork.h"
- #include "Kismet/BlueprintAsyncActionBase.h"
- #include "AudioManager.generated.h"
- //DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSongPlayedSignature, bool, success);
- //DECLARE_DELEGATE_OneParam(FSongPlayedSignature, bool);
- UCLASS(Blueprintable, BlueprintType)
- class UAudioManager : public UObject
- {
- GENERATED_BODY()
- public:
- //UFUNCTIONS
- /*
- * Opens a file dialog for the specified data. Leave FileTypes empty to be able to select any files.
- * Filetypes must be in the format of: <File type Description>|*.<actual extension>
- * You can combine multiple extensions by placing ";" between them
- * For example: Text Files|*.txt|Excel files|*.csv|Image Files|*.png;*.jpg;*.bmp will display 3 lines for 3 different type of files.
- */
- UFUNCTION(BlueprintCallable, Category = "FilePicker")
- void OpenFileDialog(const FString& DialogTitle, const FString& DefaultPath, const FString& FileTypes, TArray<FString>& OutFileNames);
- /*Prints the data of the given file*/
- UFUNCTION(BlueprintCallable, Category = "FilePicker")
- void PrintData(const FString& File);
- UFUNCTION(BlueprintCallable, Category = Init)
- int32 InitializeManager();
- UFUNCTION(BlueprintCallable, Category = Init)
- int32 InitSpectrum_Linear(const int32 numBars);
- UFUNCTION(BlueprintCallable, Category = Init)
- int32 InitSpectrum_Log(const int32 numBars);
- UFUNCTION(BlueprintCallable, Category = Actions)
- bool PlaySong(FString songPath);
- UFUNCTION(BlueprintCallable, Category = Actions)
- void PlaySongAsync(FString songPath);
- UFUNCTION(BlueprintCallable, Category = Actions)
- void PauseSong(bool unPause);
- UFUNCTION(BlueprintCallable, Category = Actions)
- void Update();
- UFUNCTION(BlueprintCallable, Category = Init)
- void InitBeatDetector();
- UFUNCTION(BlueprintCallable, Category = Access)
- void GetBeat(TArray<float>& frequencyValues, TArray<float>& frequencyAverageValues, bool& isBass, bool& isLowM);
- UFUNCTION(BlueprintCallable, Category = Actions)
- int GetSongLength();
- UFUNCTION(BlueprintPure, Category = Access)
- const FString& GetSongName() const;
- UFUNCTION(BlueprintCallable, Category = Access)
- void GetSpectrum_Linear(TArray<float>& frequencyValues, TArray<float>& frequencyAverageValues, const int32 effectiveBars);
- UFUNCTION(BlueprintCallable, Category = Access)
- void GetSpectrum_Log(TArray<float>& frequencyValues, TArray<float>& frequencyAverageValues, const int32 effectiveBars);
- UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = Actions)
- void PlaySongAsyncCallbackEvent(bool success);
- UFUNCTION(BlueprintPure, Category = AsyncVariables)
- bool GetCanPlaySongRunTask();
- UFUNCTION(BlueprintCallable, Category = AsyncVariables)
- void SetCanPlaySongRunTask(bool canPlaySongRunTask);
- //NORMAL FUNCTIONS
- UAudioManager();
- ~UAudioManager();
- private:
- TWeakObjectPtr<UAudioManager> _audioManager;
- std::shared_ptr<SoundManager_Fmod> _soundManager;
- FString currentSongName;
- public:
- UPROPERTY(BlueprintReadOnly, Category = Actions)
- bool CanPlaySongRunTask = true;
- };
- class FAsyncPlaySong : public FNonAbandonableTask
- {
- friend class FAutoDeleteAsyncTask<FAsyncPlaySong>;
- public:
- FAsyncPlaySong(std::shared_ptr<SoundManager_Fmod> manager, FString _songPath, TWeakObjectPtr<UAudioManager> audioManager);
- ~FAsyncPlaySong();
- bool success;
- FString SongPath;
- TWeakObjectPtr<UAudioManager> AudioManager;
- std::shared_ptr<SoundManager_Fmod> Manager;
- void DoWork();
- void EndTask();
- //Next Section
- FORCEINLINE TStatId GetStatId() const
- {
- RETURN_QUICK_DECLARE_CYCLE_STAT(FAsyncPlaySong, STATGROUP_ThreadPoolAsyncTasks);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement