Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "CoreMinimal.h"
  4.  
  5. #include <memory>
  6. #include "SoundManager_Fmod.h"
  7.  
  8. #include "UObject/NoExportTypes.h"
  9. #include "Async/AsyncWork.h"
  10. #include "Kismet/BlueprintAsyncActionBase.h"
  11.  
  12. #include "AudioManager.generated.h"
  13.  
  14. //DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSongPlayedSignature, bool, success);
  15. //DECLARE_DELEGATE_OneParam(FSongPlayedSignature, bool);
  16.  
  17. UCLASS(Blueprintable, BlueprintType)
  18. class UAudioManager : public UObject
  19. {
  20.  
  21.  
  22. GENERATED_BODY()
  23. public:
  24. //UFUNCTIONS
  25. /*
  26. * Opens a file dialog for the specified data. Leave FileTypes empty to be able to select any files.
  27. * Filetypes must be in the format of: <File type Description>|*.<actual extension>
  28. * You can combine multiple extensions by placing ";" between them
  29. * For example: Text Files|*.txt|Excel files|*.csv|Image Files|*.png;*.jpg;*.bmp will display 3 lines for 3 different type of files.
  30. */
  31. UFUNCTION(BlueprintCallable, Category = "FilePicker")
  32. void OpenFileDialog(const FString& DialogTitle, const FString& DefaultPath, const FString& FileTypes, TArray<FString>& OutFileNames);
  33.  
  34. /*Prints the data of the given file*/
  35. UFUNCTION(BlueprintCallable, Category = "FilePicker")
  36. void PrintData(const FString& File);
  37. UFUNCTION(BlueprintCallable, Category = Init)
  38. int32 InitializeManager();
  39. UFUNCTION(BlueprintCallable, Category = Init)
  40. int32 InitSpectrum_Linear(const int32 numBars);
  41. UFUNCTION(BlueprintCallable, Category = Init)
  42. int32 InitSpectrum_Log(const int32 numBars);
  43. UFUNCTION(BlueprintCallable, Category = Actions)
  44. bool PlaySong(FString songPath);
  45. UFUNCTION(BlueprintCallable, Category = Actions)
  46. void PlaySongAsync(FString songPath);
  47. UFUNCTION(BlueprintCallable, Category = Actions)
  48. void PauseSong(bool unPause);
  49. UFUNCTION(BlueprintCallable, Category = Actions)
  50. void Update();
  51. UFUNCTION(BlueprintCallable, Category = Init)
  52. void InitBeatDetector();
  53. UFUNCTION(BlueprintCallable, Category = Access)
  54. void GetBeat(TArray<float>& frequencyValues, TArray<float>& frequencyAverageValues, bool& isBass, bool& isLowM);
  55. UFUNCTION(BlueprintCallable, Category = Actions)
  56. int GetSongLength();
  57. UFUNCTION(BlueprintPure, Category = Access)
  58. const FString& GetSongName() const;
  59. UFUNCTION(BlueprintCallable, Category = Access)
  60. void GetSpectrum_Linear(TArray<float>& frequencyValues, TArray<float>& frequencyAverageValues, const int32 effectiveBars);
  61. UFUNCTION(BlueprintCallable, Category = Access)
  62. void GetSpectrum_Log(TArray<float>& frequencyValues, TArray<float>& frequencyAverageValues, const int32 effectiveBars);
  63. UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = Actions)
  64. void PlaySongAsyncCallbackEvent(bool success);
  65. UFUNCTION(BlueprintPure, Category = AsyncVariables)
  66. bool GetCanPlaySongRunTask();
  67. UFUNCTION(BlueprintCallable, Category = AsyncVariables)
  68. void SetCanPlaySongRunTask(bool canPlaySongRunTask);
  69.  
  70. //NORMAL FUNCTIONS
  71. UAudioManager();
  72. ~UAudioManager();
  73.  
  74.  
  75.  
  76. private:
  77.  
  78. TWeakObjectPtr<UAudioManager> _audioManager;
  79. std::shared_ptr<SoundManager_Fmod> _soundManager;
  80. FString currentSongName;
  81.  
  82. public:
  83.  
  84. UPROPERTY(BlueprintReadOnly, Category = Actions)
  85. bool CanPlaySongRunTask = true;
  86. };
  87.  
  88.  
  89.  
  90.  
  91. class FAsyncPlaySong : public FNonAbandonableTask
  92. {
  93.  
  94. friend class FAutoDeleteAsyncTask<FAsyncPlaySong>;
  95.  
  96. public:
  97. FAsyncPlaySong(std::shared_ptr<SoundManager_Fmod> manager, FString _songPath, TWeakObjectPtr<UAudioManager> audioManager);
  98. ~FAsyncPlaySong();
  99.  
  100. bool success;
  101. FString SongPath;
  102.  
  103. TWeakObjectPtr<UAudioManager> AudioManager;
  104.  
  105.  
  106. std::shared_ptr<SoundManager_Fmod> Manager;
  107.  
  108.  
  109. void DoWork();
  110. void EndTask();
  111. //Next Section
  112.  
  113. FORCEINLINE TStatId GetStatId() const
  114. {
  115. RETURN_QUICK_DECLARE_CYCLE_STAT(FAsyncPlaySong, STATGROUP_ThreadPoolAsyncTasks);
  116. }
  117.  
  118. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement