Prechádzať zdrojové kódy

minor: add clang-tidy and clang-format

Douglas A 1 rok pred
rodič
commit
aed969c7b2
9 zmenil súbory, kde vykonal 524 pridanie a 238 odobranie
  1. 258 0
      .clang-format
  2. 28 0
      .clang-tidy
  3. 6 6
      src/App.cpp
  4. 6 6
      src/App.h
  5. 62 62
      src/Audio.cpp
  6. 31 31
      src/Audio.h
  7. 103 101
      src/BaseWindow.cpp
  8. 28 28
      src/BaseWindow.h
  9. 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'
+...
+

+ 6 - 6
src/App.cpp

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

+ 6 - 6
src/App.h

@@ -7,11 +7,11 @@
 static Color grey = {0.45, 0.45, 0.45, 1.0};
 
 class App {
- private:
-  std::unique_ptr<BaseWindow> m_window;
-  std::unique_ptr<Audio> m_audio;
+private:
+    std::unique_ptr<BaseWindow> m_window;
+    std::unique_ptr<Audio> m_audio;
 
- public:
-  App();
-  void Run();
+public:
+    App();
+    void Run();
 };

+ 62 - 62
src/Audio.cpp

@@ -8,98 +8,98 @@
 
 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);
-  decoder->is_finished = false;
-  if (result == MA_AT_END) {
-    std::cout << "end of the song... next.\n";
-    decoder->is_finished = true;
-  }
+    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);
+    decoder->is_finished = false;
+    if (result == MA_AT_END) {
+        std::cout << "end of the song... next.\n";
+        decoder->is_finished = true;
+    }
 }
 
 Audio::Audio() {
-  m_device_config = ma_device_config_init(ma_device_type_playback);
-  m_device_config.dataCallback = data_callback;
+    m_device_config = ma_device_config_init(ma_device_type_playback);
+    m_device_config.dataCallback = data_callback;
 }
 
 Audio::~Audio() {
-  ma_device_uninit(&m_device);
-  ma_decoder_uninit(&m_decoder.decoder);
-  return;
+    ma_device_uninit(&m_device);
+    ma_decoder_uninit(&m_decoder.decoder);
+    return;
 }
 
 void Audio::load_file(std::filesystem::path file_path) {
-  m_loaded_files.push_back(file_path);
-  std::cout << "Loaded file: " << file_path.string() << "\n";
+    m_loaded_files.push_back(file_path);
+    std::cout << "Loaded file: " << file_path.string() << "\n";
 }
 
 void Audio::play() {
-  if (is_playing()) {
-    stop();
-  }
+    if (is_playing()) {
+        stop();
+    }
 
-  m_selected_file = m_loaded_files[m_selected_file_idx];
+    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);
-  if (result != MA_SUCCESS) {
-    std::cout << "could not load file: " << m_selected_file.string().c_str()
-              << "\n";
-    return;
-  }
+    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";
+        return;
+    }
 
-  m_device_config.playback.format = m_decoder.decoder.outputFormat;
-  m_device_config.playback.channels = m_decoder.decoder.outputChannels;
-  m_device_config.sampleRate = m_decoder.decoder.outputSampleRate;
-  m_device_config.pUserData = &m_decoder;
+    m_device_config.playback.format = m_decoder.decoder.outputFormat;
+    m_device_config.playback.channels = m_decoder.decoder.outputChannels;
+    m_device_config.sampleRate = m_decoder.decoder.outputSampleRate;
+    m_device_config.pUserData = &m_decoder;
 
-  if (ma_device_init(NULL, &m_device_config, &m_device) != MA_SUCCESS) {
-    std::cout << "failed to open playback device.\n";
-    return;
-  }
+    if (ma_device_init(NULL, &m_device_config, &m_device) != MA_SUCCESS) {
+        std::cout << "failed to open playback device.\n";
+        return;
+    }
 
-  if (ma_device_start(&m_device) != MA_SUCCESS) {
-    std::cout << "could not start playback device"
-              << "\n";
-    return;
-  }
+    if (ma_device_start(&m_device) != MA_SUCCESS) {
+        std::cout << "could not start playback device"
+                  << "\n";
+        return;
+    }
 
-  m_is_playing = true;
+    m_is_playing = true;
 }
 
 void Audio::stop() {
-  if (is_playing()) {
-    ma_device_uninit(&m_device);
-    ma_decoder_uninit(&m_decoder.decoder);
-    m_is_playing = false;
-  }
+    if (is_playing()) {
+        ma_device_uninit(&m_device);
+        ma_decoder_uninit(&m_decoder.decoder);
+        m_is_playing = false;
+    }
 }
 
 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;
+    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() {
-  m_selected_file_idx += 1;
-  if (m_loaded_files.size() <= m_selected_file_idx) {
-    m_selected_file_idx = 0;
-  }
+    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() {
-  return m_loaded_files;
+    return m_loaded_files;
 }

+ 31 - 31
src/Audio.h

@@ -6,38 +6,38 @@
 #include <vector>
 
 struct DecoderState {
-  ma_decoder decoder{};
-  bool is_finished = false;
-  ma_decoder_config m_decoder_config{};
+    ma_decoder decoder{};
+    bool is_finished = false;
+    ma_decoder_config m_decoder_config{};
 };
 
 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::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);
-
- public:
-  Audio();
-  ~Audio();
-
-  void load_file(std::filesystem::path file_path);
-  void play();
-  void stop();
-  void select_file(std::filesystem::path file);
-  bool is_playing() { return m_is_playing; }
-  void next_music();
-  DecoderState decoder() { return m_decoder; }
-
-  std::vector<std::filesystem::path> loaded_files();
+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::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);
+
+public:
+    Audio();
+    ~Audio();
+
+    void load_file(std::filesystem::path file_path);
+    void play();
+    void stop();
+    void select_file(std::filesystem::path file);
+    bool is_playing() { return m_is_playing; }
+    void next_music();
+    DecoderState decoder() { return m_decoder; }
+
+    std::vector<std::filesystem::path> loaded_files();
 };

+ 103 - 101
src/BaseWindow.cpp

@@ -6,7 +6,7 @@
 #include <iostream>
 
 void window_resize_callback(GLFWwindow *, int width, int height) {
-  glViewport(0, 0, width, height);
+    glViewport(0, 0, width, height);
 }
 
 BaseWindow::BaseWindow(int width, int height, const char *title,
@@ -18,116 +18,118 @@ BaseWindow::BaseWindow(int width, int height, const char *title,
       m_audio_handler(audio_handler) {}
 
 BaseWindow::~BaseWindow() {
-  ImGui_ImplOpenGL3_Shutdown();
-  ImGui_ImplGlfw_Shutdown();
-  ImGui::DestroyContext();
-  glfwDestroyWindow(m_window);
-  glfwTerminate();
+    ImGui_ImplOpenGL3_Shutdown();
+    ImGui_ImplGlfw_Shutdown();
+    ImGui::DestroyContext();
+    glfwDestroyWindow(m_window);
+    glfwTerminate();
 }
 
 int BaseWindow::run() {
-  glfwInit();
-
-  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
-  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
-  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) {
-    std::cout << "could not intialize GLFW Window"
-              << "\n";
-    glfwTerminate();
-    return 1;
-  }
-
-  glfwMakeContextCurrent(m_window);
-
-  if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
-    std::cout << "Failed to initialize GLAD" << std::endl;
-    return 1;
-  }
-
-  glfwSetFramebufferSizeCallback(m_window, window_resize_callback);
-  IMGUI_CHECKVERSION();
-  ImGui::CreateContext();
-  ImGuiIO &io = ImGui::GetIO();
-  (void)io;
-  ImGui::StyleColorsDark();
-  ImGui_ImplGlfw_InitForOpenGL(m_window, true);
-  ImGui_ImplOpenGL3_Init("#version 330");
-
-  ImGui::FileBrowser fileDialog;
-  fileDialog.SetTitle("title");
-  fileDialog.SetTypeFilters({".mp3"});
-
-  // Main game loop
-  while (!glfwWindowShouldClose(m_window)) {
-    // Create new imgui frames
-    ImGui_ImplOpenGL3_NewFrame();
-    ImGui_ImplGlfw_NewFrame();
-    ImGui::NewFrame();
-
-    // Draw IMGUI
-    ImGui::Begin("Hello!");
-    {
-      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)) {
-              selected = file;
-              m_audio_handler->select_file(file);
+    glfwInit();
+
+    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
+    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) {
+        std::cout << "could not intialize GLFW Window"
+                  << "\n";
+        glfwTerminate();
+        return 1;
+    }
+
+    glfwMakeContextCurrent(m_window);
+
+    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
+        std::cout << "Failed to initialize GLAD" << std::endl;
+        return 1;
+    }
+
+    glfwSetFramebufferSizeCallback(m_window, window_resize_callback);
+    IMGUI_CHECKVERSION();
+    ImGui::CreateContext();
+    ImGuiIO &io = ImGui::GetIO();
+    (void)io;
+    ImGui::StyleColorsDark();
+    ImGui_ImplGlfw_InitForOpenGL(m_window, true);
+    ImGui_ImplOpenGL3_Init("#version 330");
+
+    ImGui::FileBrowser fileDialog;
+    fileDialog.SetTitle("title");
+    fileDialog.SetTypeFilters({".mp3"});
+
+    // Main game loop
+    while (!glfwWindowShouldClose(m_window)) {
+        // Create new imgui frames
+        ImGui_ImplOpenGL3_NewFrame();
+        ImGui_ImplGlfw_NewFrame();
+        ImGui::NewFrame();
+
+        // Draw IMGUI
+        ImGui::Begin("Hello!");
+        {
+            if (ImGui::Button("Add Music")) {
+                fileDialog.Open();
             }
 
-            if (is_selected) {
-              ImGui::SetItemDefaultFocus();
+            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)) {
+                            selected = file;
+                            m_audio_handler->select_file(file);
+                        }
+
+                        if (is_selected) {
+                            ImGui::SetItemDefaultFocus();
+                        }
+                    }
+                }
+                ImGui::EndListBox();
             }
-          }
         }
-        ImGui::EndListBox();
-      }
-    }
-    ImGui::End();
-    fileDialog.Display();
-    if (fileDialog.HasSelected()) {
-      m_audio_handler->load_file(fileDialog.GetSelected());
-      m_audio_handler->select_file(fileDialog.GetSelected());
-      fileDialog.ClearSelected();
-    }
+        ImGui::End();
+        fileDialog.Display();
+        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("Stop")) {
-        m_audio_handler->stop();
-      }
-    }
-    ImGui::End();
+        ImGui::Begin("Player controls");
+        {
+            if (ImGui::Button("Play")) {
+                m_audio_handler->play();
+            }
+            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();
+        ImGui::Render();
 
-    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();
-  }
+        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();
+    }
 
-  return 0;
+    return 0;
 }

+ 28 - 28
src/BaseWindow.h

@@ -10,35 +10,35 @@
 #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) {
-    Color c;
-    c.r = r / 256.0f;
-    c.g = g / 256.0f;
-    c.b = b / 256.0f;
-    c.a = alpha / 256.0f;
-
-    return c;
-  }
+    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) {
+        Color c;
+        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 clear_color,
-             Audio *audio_handler);
-  ~BaseWindow();
-  int run();
-
- 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;
+public:
+    BaseWindow(int width, int height, const char *title, Color clear_color,
+               Audio *audio_handler);
+    ~BaseWindow();
+    int run();
+
+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;
 };

+ 2 - 4
src/main.cpp

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