Explorar o código

fix conflictsZerge branch 'main' of https://git.delta.labs.andreanidr.com/cmte/basic-mp3-player

Douglas Andreani hai 1 ano
pai
achega
f01caec788
Modificáronse 11 ficheiros con 396 adicións e 139 borrados
  1. 258 0
      .clang-format
  2. 28 0
      .clang-tidy
  3. 2 2
      .gitignore
  4. 2 1
      CMakeLists.txt
  5. 10 11
      src/App.cpp
  6. 6 8
      src/App.h
  7. 23 33
      src/Audio.cpp
  8. 8 10
      src/Audio.h
  9. 40 55
      src/BaseWindow.cpp
  10. 17 15
      src/BaseWindow.h
  11. 2 4
      src/main.cpp

+ 258 - 0
.clang-format

@@ -0,0 +1,258 @@
+---
+Language:        Cpp
+# BasedOnStyle:  Google
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignArrayOfStructures: None
+AlignConsecutiveAssignments:
+  Enabled:         false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    true
+AlignConsecutiveBitFields:
+  Enabled:         false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    false
+AlignConsecutiveDeclarations:
+  Enabled:         false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    false
+AlignConsecutiveMacros:
+  Enabled:         false
+  AcrossEmptyLines: false
+  AcrossComments:  false
+  AlignCompound:   false
+  PadOperators:    false
+AlignEscapedNewlines: Left
+AlignOperands:   Align
+AlignTrailingComments:
+  Kind:            Always
+  OverEmptyLines:  0
+AllowAllArgumentsOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortEnumsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: WithoutElse
+AllowShortLambdasOnASingleLine: All
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: Yes
+AttributeMacros:
+  - __capability
+BinPackArguments: true
+BinPackParameters: true
+BitFieldColonSpacing: Both
+BraceWrapping:
+  AfterCaseLabel:  false
+  AfterClass:      false
+  AfterControlStatement: Never
+  AfterEnum:       false
+  AfterExternBlock: false
+  AfterFunction:   false
+  AfterNamespace:  false
+  AfterObjCDeclaration: false
+  AfterStruct:     false
+  AfterUnion:      false
+  BeforeCatch:     false
+  BeforeElse:      false
+  BeforeLambdaBody: false
+  BeforeWhile:     false
+  IndentBraces:    false
+  SplitEmptyFunction: true
+  SplitEmptyRecord: true
+  SplitEmptyNamespace: true
+BreakAfterAttributes: Never
+BreakAfterJavaFieldAnnotations: false
+BreakArrays:     true
+BreakBeforeBinaryOperators: None
+BreakBeforeConceptDeclarations: Always
+BreakBeforeBraces: Attach
+BreakBeforeInlineASMColon: OnlyMultiline
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeColon
+BreakInheritanceList: BeforeColon
+BreakStringLiterals: true
+ColumnLimit:     80
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: true
+DisableFormat:   false
+EmptyLineAfterAccessModifier: Never
+EmptyLineBeforeAccessModifier: LogicalBlock
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+  - foreach
+  - Q_FOREACH
+  - BOOST_FOREACH
+IfMacros:
+  - KJ_IF_MAYBE
+IncludeBlocks:   Regroup
+IncludeCategories:
+  - Regex:           '^<ext/.*\.h>'
+    Priority:        2
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '^<.*\.h>'
+    Priority:        1
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '^<.*'
+    Priority:        2
+    SortPriority:    0
+    CaseSensitive:   false
+  - Regex:           '.*'
+    Priority:        3
+    SortPriority:    0
+    CaseSensitive:   false
+IncludeIsMainRegex: '([-_](test|unittest))?$'
+IncludeIsMainSourceRegex: ''
+IndentAccessModifiers: false
+IndentCaseLabels: true
+IndentExternBlock: AfterExternBlock
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentRequiresClause: true
+IndentWidth:     4
+IndentWrappedFunctionNames: false
+InsertBraces:    false
+InsertNewlineAtEOF: false
+InsertTrailingCommas: None
+IntegerLiteralSeparator:
+  Binary:          0
+  BinaryMinDigits: 0
+  Decimal:         0
+  DecimalMinDigits: 0
+  Hex:             0
+  HexMinDigits:    0
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+LambdaBodyIndentation: Signature
+LineEnding:      DeriveLF
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Never
+ObjCBlockIndentWidth: 2
+ObjCBreakBeforeNestedBlockParam: true
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PackConstructorInitializers: NextLine
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakOpenParenthesis: 0
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyIndentedWhitespace: 0
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Left
+PPIndentWidth:   -1
+QualifierAlignment: Leave
+RawStringFormats:
+  - Language:        Cpp
+    Delimiters:
+      - cc
+      - CC
+      - cpp
+      - Cpp
+      - CPP
+      - 'c++'
+      - 'C++'
+    CanonicalDelimiter: ''
+    BasedOnStyle:    google
+  - Language:        TextProto
+    Delimiters:
+      - pb
+      - PB
+      - proto
+      - PROTO
+    EnclosingFunctions:
+      - EqualsProto
+      - EquivToProto
+      - PARSE_PARTIAL_TEXT_PROTO
+      - PARSE_TEST_PROTO
+      - PARSE_TEXT_PROTO
+      - ParseTextOrDie
+      - ParseTextProtoOrDie
+      - ParseTestProto
+      - ParsePartialTestProto
+    CanonicalDelimiter: pb
+    BasedOnStyle:    google
+ReferenceAlignment: Pointer
+ReflowComments:  true
+RemoveBracesLLVM: false
+RemoveSemicolon: false
+RequiresClausePosition: OwnLine
+RequiresExpressionIndentation: OuterScope
+SeparateDefinitionBlocks: Leave
+ShortNamespaceLines: 1
+SortIncludes:    CaseSensitive
+SortJavaStaticImport: Before
+SortUsingDeclarations: LexicographicNumeric
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceAroundPointerQualifiers: Default
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCaseColon: false
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeParensOptions:
+  AfterControlStatements: true
+  AfterForeachMacros: true
+  AfterFunctionDefinitionName: false
+  AfterFunctionDeclarationName: false
+  AfterIfMacros:   true
+  AfterOverloadedOperator: false
+  AfterRequiresInClause: false
+  AfterRequiresInExpression: false
+  BeforeNonEmptyParentheses: false
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles:  Never
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInLineCommentPrefix:
+  Minimum:         1
+  Maximum:         -1
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Auto
+StatementAttributeLikeMacros:
+  - Q_EMIT
+StatementMacros:
+  - Q_UNUSED
+  - QT_REQUIRE_VERSION
+TabWidth:        8
+UseTab:          Never
+WhitespaceSensitiveMacros:
+  - BOOST_PP_STRINGIZE
+  - CF_SWIFT_NAME
+  - NS_SWIFT_NAME
+  - PP_STRINGIZE
+  - STRINGIZE
+...
+

+ 28 - 0
.clang-tidy

@@ -0,0 +1,28 @@
+---
+Checks:          'clang-diagnostic-*,clang-analyzer-*'
+WarningsAsErrors: ''
+HeaderFilterRegex: ''
+AnalyzeTemporaryDtors: false
+FormatStyle:     google
+User:            cmte
+CheckOptions:
+  llvm-else-after-return.WarnOnConditionVariables: 'false'
+  modernize-loop-convert.MinConfidence: reasonable
+  modernize-replace-auto-ptr.IncludeStyle: llvm
+  modernize-pass-by-value.IncludeStyle: llvm
+  google-readability-namespace-comments.ShortNamespaceLines: '10'
+  google-readability-namespace-comments.SpacesBeforeComments: '2'
+  cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true'
+  google-readability-braces-around-statements.ShortStatementLines: '1'
+  cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
+  modernize-loop-convert.MaxCopySize: '16'
+  cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
+  cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
+  cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
+  modernize-use-nullptr.NullMacros: 'NULL'
+  llvm-qualified-auto.AddConstToQualified: 'false'
+  modernize-loop-convert.NamingStyle: CamelCase
+  llvm-else-after-return.WarnOnUnfixable: 'false'
+  google-readability-function-size.StatementThreshold: '800'
+...
+

+ 2 - 2
.gitignore

@@ -1,7 +1,7 @@
 .vscode/
 build/
 build-msvc/
-
+compile_commands.json
 
 
 ## Ignore Visual Studio temporary files, build results, and
@@ -401,4 +401,4 @@ FodyWeavers.xsd
 *.msp
 
 # JetBrains Rider
-*.sln.iml
+*.sln.iml

+ 2 - 1
CMakeLists.txt

@@ -13,10 +13,11 @@ include_directories(libs/imgui)
 
 file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/imgui/*.cpp)
 
-find_library(GLFW_LIBRARY NAMES glfw3 HINTS "c:/usr/lib")
+find_library(GLFW_LIBRARY NAMES glfw glfw3 HINTS c:/usr/lib/)
 
 add_executable(music-imgui ${SOURCES} src/main.cpp src/App.cpp src/glad.c src/Audio.cpp src/BaseWindow.cpp )
 
 find_package(OpenGL REQUIRED)
 target_link_libraries(music-imgui PRIVATE ${OPENGL_gl_LIBRARY})
 target_link_libraries(music-imgui PRIVATE ${GLFW_LIBRARY})
+

+ 10 - 11
src/App.cpp

@@ -1,20 +1,19 @@
 #include "App.h"
-#include "Audio.h"
-#include "BaseWindow.h"
 
-#include <memory>
 #include <iostream>
+#include <memory>
 
-App::App()
-{
-    
-    m_audio = std::make_unique<Audio>(Audio());
-    m_window = std::make_unique<BaseWindow>(BaseWindow(800, 600, "Music", grey, *m_audio));
+#include "Audio.h"
+#include "BaseWindow.h"
+
+App::App() {
+    m_audio = std::make_unique<Audio>();
+    m_window =
+        std::make_unique<BaseWindow>(800, 600, "Music", grey, m_audio.get());
 }
 
-void App::Run()
-{
+void App::Run() {
     if (m_window->run()) {
         std::cout << "Something wrong happened. Quitting.\n";
     }
-}
+}

+ 6 - 8
src/App.h

@@ -1,19 +1,17 @@
 #pragma once
-#include "BaseWindow.h"
-#include "Audio.h"
-
 #include <memory>
 
-static Color grey = {0.45, 0.45, 0.45, 1.0};
+#include "Audio.h"
+#include "BaseWindow.h"
 
+static Color grey = {0.45, 0.45, 0.45, 1.0};
 
 class App {
-
-    private:
+private:
     std::unique_ptr<BaseWindow> m_window;
     std::unique_ptr<Audio> m_audio;
 
-    public:
+public:
     App();
     void Run();
-};
+};

+ 23 - 33
src/Audio.cpp

@@ -3,18 +3,19 @@
 #define MINIAUDIO_IMPLEMENTATION
 #include <miniaudio/miniaudio.h>
 
-#include <iostream>
 #include <filesystem>
+#include <iostream>
 
-void Audio::data_callback(ma_device *device, void *output, const void *input, ma_uint32 frame_count)
-{
-    DecoderState* decoder = (DecoderState*)device->pUserData;
-    if(decoder == NULL) {
+void Audio::data_callback(ma_device *device, void *output, const void *input,
+                          ma_uint32 frame_count) {
+    DecoderState *decoder = (DecoderState *)device->pUserData;
+    if (decoder == NULL) {
         std::cout << "could not find suitable decoder\n";
         return;
     }
 
-    ma_result result = ma_decoder_read_pcm_frames(&decoder->decoder, output, frame_count, NULL);
+    ma_result result = ma_decoder_read_pcm_frames(&decoder->decoder, output,
+                                                  frame_count, NULL);
     decoder->is_finished = false;
     if (result == MA_AT_END) {
         std::cout << "end of the song... next.\n";
@@ -22,40 +23,34 @@ void Audio::data_callback(ma_device *device, void *output, const void *input, ma
     }
 }
 
-Audio::Audio()
-{
-
+Audio::Audio() {
     m_device_config = ma_device_config_init(ma_device_type_playback);
     m_device_config.dataCallback = data_callback;
 }
 
-Audio::~Audio()
-{
+Audio::~Audio() {
     ma_device_uninit(&m_device);
     ma_decoder_uninit(&m_decoder.decoder);
     return;
 }
 
-void Audio::load_file(std::filesystem::path file_path)
-{
+void Audio::load_file(std::filesystem::path file_path) {
     m_loaded_files.push_back(file_path);
     std::cout << "Loaded file: " << file_path.string() << "\n";
-
 }
 
-
-void Audio::play()
-{
+void Audio::play() {
     if (is_playing()) {
         stop();
     }
-       
 
     m_selected_file = m_loaded_files[m_selected_file_idx];
 
-    ma_result result = ma_decoder_init_file(m_selected_file.string().c_str(), NULL, &m_decoder.decoder);
+    ma_result result = ma_decoder_init_file(m_selected_file.string().c_str(),
+                                            NULL, &m_decoder.decoder);
     if (result != MA_SUCCESS) {
-        std::cout << "could not load file: " << m_selected_file.string().c_str() << "\n";
+        std::cout << "could not load file: " << m_selected_file.string().c_str()
+                  << "\n";
         return;
     }
 
@@ -70,15 +65,15 @@ void Audio::play()
     }
 
     if (ma_device_start(&m_device) != MA_SUCCESS) {
-        std::cout << "could not start playback device" << "\n";
+        std::cout << "could not start playback device"
+                  << "\n";
         return;
     }
 
     m_is_playing = true;
 }
 
-void Audio::stop()
-{
+void Audio::stop() {
     if (is_playing()) {
         ma_device_uninit(&m_device);
         ma_decoder_uninit(&m_decoder.decoder);
@@ -86,30 +81,25 @@ void Audio::stop()
     }
 }
 
-void Audio::select_file(std::filesystem::path file)
-{
-    
+void Audio::select_file(std::filesystem::path file) {
     for (size_t i = 0; i < m_loaded_files.size(); i++) {
         if (file == m_loaded_files[i]) {
             m_selected_file = file;
             m_selected_file_idx = i;
         }
     }
-    //m_select_file_idx = m_loaded_files
+    // m_select_file_idx = m_loaded_files
 }
 
-void Audio::next_music()
-{
+void Audio::next_music() {
     m_selected_file_idx += 1;
     if (m_loaded_files.size() <= m_selected_file_idx) {
         m_selected_file_idx = 0;
     }
 
-    if (is_playing())
-        play();
+    if (is_playing()) play();
 }
 
-std::vector<std::filesystem::path> Audio::loaded_files()
-{
+std::vector<std::filesystem::path> Audio::loaded_files() {
     return m_loaded_files;
 }

+ 8 - 10
src/Audio.h

@@ -1,10 +1,10 @@
 #pragma once
 
-#include <vector>
-#include <filesystem>
-
 #include <miniaudio/miniaudio.h>
 
+#include <filesystem>
+#include <vector>
+
 struct DecoderState {
     ma_decoder decoder{};
     bool is_finished = false;
@@ -12,20 +12,20 @@ struct DecoderState {
 };
 
 class Audio {
-    
 private:
     ma_device m_device{};
     ma_device_config m_device_config{};
 
     DecoderState m_decoder{};
 
-
-    std::vector<std::filesystem::path> m_loaded_files = std::vector<std::filesystem::path>();
+    std::vector<std::filesystem::path> m_loaded_files =
+        std::vector<std::filesystem::path>();
     std::filesystem::path m_selected_file = std::filesystem::path();
     size_t m_selected_file_idx = 0;
     bool m_is_playing = false;
 
-    static void data_callback(ma_device* device, void* output, const void* input, ma_uint32 frame_count);
+    static void data_callback(ma_device *device, void *output,
+                              const void *input, ma_uint32 frame_count);
 
 public:
     Audio();
@@ -39,7 +39,5 @@ public:
     void next_music();
     DecoderState decoder() { return m_decoder; }
 
-
-
     std::vector<std::filesystem::path> loaded_files();
-};
+};

+ 40 - 55
src/BaseWindow.cpp

@@ -1,34 +1,31 @@
 
 #include "BaseWindow.h"
-#include <imfilebrowser.h>
 
+#include <imfilebrowser.h>
 #include <iostream>
 
-void window_resize_callback(GLFWwindow *window, int width, int height)
-{
+void window_resize_callback(GLFWwindow * /*unused*/, int width, int height) {
     glViewport(0, 0, width, height);
 }
 
-BaseWindow::BaseWindow(int width, int height, const char *title, Color clear_color, Audio audio_handler)
-    : m_window_height(height),
+BaseWindow::BaseWindow(int width, int height, const char *title,
+                       Color clear_color, Audio *audio_handler)
+    : m_clear_color(clear_color),
       m_window_width(width),
+      m_window_height(height),
       m_window_title(title),
-      m_clear_color(clear_color),
       m_audio_handler(audio_handler) {}
 
-BaseWindow::~BaseWindow()
-{
-    
-    //ImGui_ImplOpenGL3_Shutdown();
-    //ImGui_ImplGlfw_Shutdown();
-    //ImGui::DestroyContext();
+BaseWindow::~BaseWindow() {
+    ImGui_ImplOpenGL3_Shutdown();
+    ImGui_ImplGlfw_Shutdown();
+    ImGui::DestroyContext();
     glfwDestroyWindow(m_window);
     glfwTerminate();
     
 }
 
-int BaseWindow::run()
-{
+auto BaseWindow::run() -> int {
     glfwInit();
 
     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
@@ -36,9 +33,9 @@ int BaseWindow::run()
     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
     glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
 
-    m_window = glfwCreateWindow(m_window_width, m_window_height, m_window_title, NULL, NULL);
-    if (m_window == NULL)
-    {
+    m_window = glfwCreateWindow(m_window_width, m_window_height, m_window_title,
+                                nullptr, nullptr);
+    if (m_window == nullptr) {
         std::cout << "could not intialize GLFW Window"
                   << "\n";
         glfwTerminate();
@@ -47,8 +44,7 @@ int BaseWindow::run()
 
     glfwMakeContextCurrent(m_window);
 
-    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
-    {
+    if (gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress)) == 0) {
         std::cout << "Failed to initialize GLAD" << std::endl;
         return 1;
     }
@@ -56,7 +52,7 @@ int BaseWindow::run()
     glfwSetFramebufferSizeCallback(m_window, window_resize_callback);
     IMGUI_CHECKVERSION();
     ImGui::CreateContext();
-    ImGuiIO &io = ImGui::GetIO();
+    ImGuiIO  const&io = ImGui::GetIO();
     (void)io;
     ImGui::StyleColorsDark();
     ImGui_ImplGlfw_InitForOpenGL(m_window, true);
@@ -67,9 +63,7 @@ int BaseWindow::run()
     fileDialog.SetTypeFilters({".mp3"});
 
     // Main game loop
-    while (!glfwWindowShouldClose(m_window))
-    {
-
+    while (glfwWindowShouldClose(m_window) == 0) {
         // Create new imgui frames
         ImGui_ImplOpenGL3_NewFrame();
         ImGui_ImplGlfw_NewFrame();
@@ -78,29 +72,25 @@ int BaseWindow::run()
         // Draw IMGUI
         ImGui::Begin("Hello!");
         {
-            static int clicked = 0;
-            if (ImGui::Button("Add Music"))
-            {
+            if (ImGui::Button("Add Music")) {
                 fileDialog.Open();
             }
 
             static std::filesystem::path selected;
-            if (m_audio_handler.loaded_files().size() > 0)
-            {
-                if (ImGui::BeginListBox("##", ImVec2(-FLT_MIN, 5 * ImGui::GetTextLineHeightWithSpacing())))
-                {
-
-                    for (auto file : m_audio_handler.loaded_files())
-                    {
-                        bool is_selected = selected.compare(file);
-                        if (ImGui::Selectable(file.string().c_str(), is_selected))
-                        {
+            if (!m_audio_handler->loaded_files().empty()) {
+                if (ImGui::BeginListBox(
+                        "##",
+                        ImVec2(-FLT_MIN,
+                               5 * ImGui::GetTextLineHeightWithSpacing()))) {
+                    for (const auto& file : m_audio_handler->loaded_files()) {
+                        bool const is_selected = selected.compare(file) != 0;
+                        if (ImGui::Selectable(file.string().c_str(),
+                                              is_selected)) {
                             selected = file;
-                            m_audio_handler.select_file(file);
+                            m_audio_handler->select_file(file);
                         }
 
-                        if (is_selected)
-                        {
+                        if (is_selected) {
                             ImGui::SetItemDefaultFocus();
                         }
                     }
@@ -110,41 +100,36 @@ int BaseWindow::run()
         }
         ImGui::End();
         fileDialog.Display();
-        if (fileDialog.HasSelected())
-        {
-            m_audio_handler.load_file(fileDialog.GetSelected());
-            m_audio_handler.select_file(fileDialog.GetSelected());
+        if (fileDialog.HasSelected()) {
+            m_audio_handler->load_file(fileDialog.GetSelected());
+            m_audio_handler->select_file(fileDialog.GetSelected());
             fileDialog.ClearSelected();
         }
 
         ImGui::Begin("Player controls");
         {
-            if (ImGui::Button("Play"))
-            {
-                m_audio_handler.play();
+            if (ImGui::Button("Play")) {
+                m_audio_handler->play();
             }
-            if (ImGui::Button("Stop"))
-            {
-                m_audio_handler.stop();
+            if (ImGui::Button("Stop")) {
+                m_audio_handler->stop();
             }
         }
         ImGui::End();
 
-        if (m_audio_handler.decoder().is_finished)
-        {
-            m_audio_handler.next_music();
+        if (m_audio_handler->decoder().is_finished) {
+            m_audio_handler->next_music();
         }
 
         ImGui::Render();
 
-        glClearColor(m_clear_color.r, m_clear_color.g, m_clear_color.b, m_clear_color.a);
+        glClearColor(m_clear_color.r, m_clear_color.g, m_clear_color.b,
+                     m_clear_color.a);
         glClear(GL_COLOR_BUFFER_BIT);
         ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
         glfwSwapBuffers(m_window);
         glfwPollEvents();
     }
 
-    // Unload and destroy
-    
     return 0;
 }

+ 17 - 15
src/BaseWindow.h

@@ -1,43 +1,45 @@
 #pragma once
 
-#include <glad/glad.h>
+#define GLFW_INCLUDE_NONE
 #include <GLFW/glfw3.h>
+
+#include <glad/glad.h>
 #include <imgui.h>
 #include <imgui_impl_glfw.h>
 #include <imgui_impl_opengl3.h>
 
 #include "Audio.h"
 
-
 struct Color {
     float r;
     float g;
     float b;
     float a;
 
-    static Color color_from_short(uint8_t r, uint8_t g, uint8_t b, uint8_t alpha) {
+    static Color color_from_short(uint8_t r, uint8_t g, uint8_t b,
+                                  uint8_t alpha) {
         Color c;
-        c.r = r/256;
-        c.g = g/256;
-        c.b = b/256;
-        c.a = alpha/256;
+        c.r = r / 256.0f;
+        c.g = g / 256.0f;
+        c.b = b / 256.0f;
+        c.a = alpha / 256.0f;
 
         return c;
     }
 };
 
 class BaseWindow {
-
-    public:
-    BaseWindow(int width, int height, const char* title, Color, Audio audio_handler);
+public:
+    BaseWindow(int width, int height, const char *title, Color clear_color,
+               Audio *audio_handler);
     ~BaseWindow();
     int run();
 
-    private:
+private:
     Color m_clear_color = {0};
     int m_window_width;
     int m_window_height;
-    const char* m_window_title;
-    GLFWwindow* m_window{};
-    Audio m_audio_handler;
-};
+    const char *m_window_title;
+    GLFWwindow *m_window{};
+    Audio *m_audio_handler;
+};

+ 2 - 4
src/main.cpp

@@ -1,10 +1,8 @@
 #include <iostream>
-#include "App.h"
 
+#include "App.h"
 
 int main() {
-
     App app = App();
     app.Run();
-
-}
+}