Implement demo app
This commit is contained in:
37
.clang-format
Normal file
37
.clang-format
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
# This configuration requires clang-format 3.8 or higher.
|
||||
Language: Cpp
|
||||
BasedOnStyle: Mozilla
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
AccessModifierOffset: '0'
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: 'true'
|
||||
AlignConsecutiveDeclarations: 'true'
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: 'true'
|
||||
AlignTrailingComments: 'true'
|
||||
AllowAllParametersOfDeclarationOnNextLine: 'false'
|
||||
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortLoopsOnASingleLine: 'false'
|
||||
AlwaysBreakBeforeMultilineStrings: 'false'
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeTernaryOperators: 'true'
|
||||
ColumnLimit: '0'
|
||||
FixNamespaceComments: 'true'
|
||||
IncludeBlocks: Regroup
|
||||
IndentCaseLabels: 'true'
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: '2'
|
||||
NamespaceIndentation: None
|
||||
PointerAlignment: Right
|
||||
ReflowComments: 'true'
|
||||
SortIncludes: 'true'
|
||||
SortUsingDeclarations: 'true'
|
||||
SpacesBeforeTrailingComments: 5
|
||||
TabWidth: '2'
|
||||
UseTab: Never
|
||||
|
||||
...
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -32,3 +32,6 @@
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# built and editor files
|
||||
.vs/
|
||||
out/
|
||||
281
CMakeLists.txt
Normal file
281
CMakeLists.txt
Normal file
@@ -0,0 +1,281 @@
|
||||
cmake_minimum_required (VERSION 3.23)
|
||||
|
||||
#--- v1.0.0 ---
|
||||
#------------------------------------------------
|
||||
#--- Setup compiler settings ---
|
||||
#------------------------------------------------
|
||||
# Set C language standard
|
||||
set(CMAKE_C_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_C_EXTENSIONS OFF) # Only standard features, no compiler-specific extensions
|
||||
|
||||
# Set C++ language standard
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF) # Only standard features, no compiler-specific extensions
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Project configuration ---
|
||||
#------------------------------------------------
|
||||
# Define the project settings
|
||||
project("bitBuzzer")
|
||||
|
||||
# Source directory
|
||||
set(SRC_DIR "src")
|
||||
|
||||
# Resource files (add resource files here if needed)
|
||||
set(RESOURCE_FILES "")
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Sanity checks ---
|
||||
#------------------------------------------------
|
||||
# Ensure build type is set (Debug, Release, etc.)
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
message(FATAL_ERROR "CMAKE_BUILD_TYPE must be set")
|
||||
endif()
|
||||
|
||||
# Ensure DEV_LIB environment variable is defined (used for external libraries)
|
||||
if(NOT DEFINED ENV{DEV_LIB})
|
||||
message(FATAL_ERROR "DEV_LIB environment variable must be defined")
|
||||
endif()
|
||||
set(DEV_LIB $ENV{DEV_LIB})
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Include directories ---
|
||||
#------------------------------------------------
|
||||
# General include directories (add your common include paths here)
|
||||
set(GENERAL_INCLUDE_DIRS
|
||||
"src"
|
||||
"pitches"
|
||||
"sdi_toolBox_1.0.x"
|
||||
"${DEV_LIB}/boost_1_87_0"
|
||||
)
|
||||
|
||||
# Additional include directories for Debug configuration
|
||||
set(DEBUG_INCLUDE_DIRS
|
||||
# "path/to/debug/include"
|
||||
)
|
||||
|
||||
# Additional include directories for Release configuration
|
||||
set(RELEASE_INCLUDE_DIRS
|
||||
# "path/to/debug/include"
|
||||
)
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Library directories ---
|
||||
#------------------------------------------------
|
||||
# General library directories (add your common library paths here)
|
||||
set(GENERAL_LIBRARY_DIRS
|
||||
${CMAKE_BINARY_DIR}
|
||||
"${DEV_LIB}/boost_1_87_0/stage/lib"
|
||||
)
|
||||
|
||||
# Additional library directories for Debug configuration
|
||||
set(DEBUG_LIBRARY_DIRS
|
||||
# "path/to/debug/lib"
|
||||
)
|
||||
|
||||
# Additional library directories for Release configuration
|
||||
set(RELEASE_LIBRARY_DIRS
|
||||
# "path/to/debug/lib"
|
||||
)
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Preprocessor definitions ---
|
||||
#------------------------------------------------
|
||||
# General preprocessor definitions (add your common defines here)
|
||||
set(GENERAL_PREPROCESSOR_DEFINITIONS
|
||||
"_CRT_SECURE_NO_DEPRECATE"
|
||||
"_CRT_NONSTDC_NO_DEPRECATE"
|
||||
"_UNICODE"
|
||||
"_WINDOWS"
|
||||
"NOMINMAX"
|
||||
"UNICODE"
|
||||
"WIN32"
|
||||
"WIN32_LEAN_AND_MEAN"
|
||||
)
|
||||
|
||||
# Additional preprocessor definitions for Debug configuration
|
||||
set(DEBUG_PREPROCESSOR_DEFINITIONS
|
||||
"_DEBUG"
|
||||
"DEBUG"
|
||||
"WXDEBUG"
|
||||
)
|
||||
|
||||
# Additional preprocessor definitions for Release configuration
|
||||
set(RELEASE_PREPROCESSOR_DEFINITIONS
|
||||
"NDEBUG"
|
||||
)
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Libraries and DLLs ---
|
||||
#------------------------------------------------
|
||||
# General libraries to link (add your common libraries here)
|
||||
set(GENERAL_LIB
|
||||
"winmm.lib"
|
||||
# "SDL2main.lib"
|
||||
)
|
||||
|
||||
# Additional libraries for Debug configuration
|
||||
set(DEBUG_LIB
|
||||
# "libDebug.lib"
|
||||
)
|
||||
|
||||
# Additional libraries for Release configuration
|
||||
set(RELEASE_LIB
|
||||
# "libRelease.lib"
|
||||
)
|
||||
|
||||
# General DLLs to copy after build (add your common DLLs here)
|
||||
set(GENERAL_BIN
|
||||
# "${DEV_LIB}/SDL2/SDL2-2.30.4/lib/x64/SDL2.dll"
|
||||
)
|
||||
|
||||
# Additional DLLs for Debug configuration
|
||||
set(DEBUG_BIN
|
||||
# "path/to/debug/dll"
|
||||
)
|
||||
|
||||
# Additional DLLs for Release configuration
|
||||
set(RELEASE_BIN
|
||||
# "path/to/release/dll"
|
||||
)
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- MSVC Debug Information Format Policy ---
|
||||
#------------------------------------------------
|
||||
# Ensure CMake policy CMP0141 is set to NEW to control the MSVC debug information format.
|
||||
# This sets CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to "EditAndContinue" for Debug and RelWithDebInfo configurations,
|
||||
# and to "ProgramDatabase" for other configurations, but only when using the MSVC compiler.
|
||||
if (POLICY CMP0141)
|
||||
cmake_policy(SET CMP0141 NEW)
|
||||
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
|
||||
endif()
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Source files gathering ---
|
||||
#------------------------------------------------
|
||||
# Collect all C and C++ source files recursively
|
||||
file(GLOB_RECURSE SOURCES_C "${SRC_DIR}/*.c")
|
||||
file(GLOB_RECURSE SOURCES_CPP "${SRC_DIR}/*.cpp")
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Target definition ---
|
||||
#------------------------------------------------
|
||||
# Define the main executable target
|
||||
add_executable(${PROJECT_NAME}
|
||||
${SOURCES_C}
|
||||
${SOURCES_CPP}
|
||||
${RESOURCE_FILES}
|
||||
)
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Target properties setup ---
|
||||
#------------------------------------------------
|
||||
# Setup include directories
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${GENERAL_INCLUDE_DIRS}
|
||||
$<$<CONFIG:Debug>:${DEBUG_INCLUDE_DIRS}>
|
||||
$<$<CONFIG:Release>:${RELEASE_INCLUDE_DIRS}>
|
||||
)
|
||||
|
||||
# Setup library directories
|
||||
target_link_directories(${PROJECT_NAME} PRIVATE
|
||||
${GENERAL_LIBRARY_DIRS}
|
||||
$<$<CONFIG:Debug>:${DEBUG_LIBRARY_DIRS}>
|
||||
$<$<CONFIG:Release>:${RELEASE_LIBRARY_DIRS}>
|
||||
)
|
||||
|
||||
# Setup preprocessor definitions
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
${GENERAL_PREPROCESSOR_DEFINITIONS}
|
||||
$<$<CONFIG:Debug>:${DEBUG_PREPROCESSOR_DEFINITIONS}>
|
||||
$<$<CONFIG:Release>:${RELEASE_PREPROCESSOR_DEFINITIONS}>
|
||||
)
|
||||
|
||||
# Setup linked libraries
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
${GENERAL_LIB}
|
||||
$<$<CONFIG:Debug>:${DEBUG_LIB}>
|
||||
$<$<CONFIG:Release>:${RELEASE_LIB}>
|
||||
)
|
||||
|
||||
# Setup compiler and linker options (MSVC specific)
|
||||
if(MSVC)
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE /MP)
|
||||
target_link_options(${PROJECT_NAME} PRIVATE "/ignore:4099" /PROFILE)
|
||||
endif()
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Post-build: Copy DLLs ---
|
||||
#------------------------------------------------
|
||||
# Copy DLLs to the output directory after build
|
||||
if(GENERAL_BIN OR DEBUG_BIN OR RELEASE_BIN)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${GENERAL_BIN}
|
||||
$<$<CONFIG:Debug>:${DEBUG_BIN}>
|
||||
$<$<CONFIG:Release>:${RELEASE_BIN}>
|
||||
${CMAKE_BINARY_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
#------------------------------------------------
|
||||
#--- Project compilation log ---
|
||||
#------------------------------------------------
|
||||
# Print project and environment information for diagnostics
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "--- Platform Information --------------------------")
|
||||
message(STATUS "System Name: ${CMAKE_SYSTEM_NAME}")
|
||||
message(STATUS "Processor: ${CMAKE_SYSTEM_PROCESSOR}")
|
||||
message(STATUS "CMake Generator: ${CMAKE_GENERATOR}")
|
||||
message(STATUS "Install Prefix: ${CMAKE_INSTALL_PREFIX}")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "--- Compiler/Language Settings --------------------")
|
||||
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
|
||||
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")
|
||||
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
|
||||
message(STATUS "Common Compiler Flags: ${CMAKE_CXX_FLAGS}")
|
||||
message(STATUS "Debug Compiler Flags: ${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
message(STATUS "Release Compiler Flags: ${CMAKE_CXX_FLAGS_RELEASE}")
|
||||
message(STATUS "Common Linker Flags: ${CMAKE_EXE_LINKER_FLAGS}")
|
||||
message(STATUS "Debug Linker Flags: ${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
||||
message(STATUS "Release Linker Flags: ${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "--- Path Information ------------------------------")
|
||||
message(STATUS "Source Dir: ${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
message(STATUS "Binary Dir: ${CMAKE_CURRENT_BINARY_DIR}")
|
||||
if(MSVC)
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "--- Microsoft Visual C++ (MSVC) Information -------")
|
||||
# Check the major compiler version
|
||||
if(MSVC_VERSION GREATER_EQUAL 1950)
|
||||
message(STATUS "MSVC Compiler Version: ${MSVC_VERSION} (Visual Studio 2026 or newer)")
|
||||
elseif(MSVC_VERSION GREATER_EQUAL 1930)
|
||||
message(STATUS "MSVC Compiler Version: ${MSVC_VERSION} (Visual Studio 2022)")
|
||||
endif()
|
||||
message(STATUS "MSVC Toolset Version: ${MSVC_TOOLSET_VERSION}")
|
||||
message(STATUS "CPP Compiler Version: ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
message(STATUS "C Compiler Version: ${CMAKE_C_COMPILER_VERSION}")
|
||||
endif()
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "--- Project Information ---------------------------")
|
||||
message(STATUS "Project Name: ${PROJECT_NAME}")
|
||||
message(STATUS "Preset Name: ${PRESET_NAME}")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
message(STATUS "---------------------------------------------------")
|
||||
|
||||
41
CMakePresets.json
Normal file
41
CMakePresets.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "windows-base",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"installDir": "${sourceDir}/out/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe"
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x64-debug",
|
||||
"displayName": "x64 Debug",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x64-release",
|
||||
"displayName": "x64 Release",
|
||||
"inherits": "x64-debug",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
46
src/main.cpp
Normal file
46
src/main.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "midiPlayer.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <pitches/all.h>
|
||||
#include <span>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
//--------------------------------------------------------------
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
cout << "Playing melodies..." << endl;
|
||||
|
||||
// Prepare melodies look-up table
|
||||
unordered_map<string, std::span<const pitches::Note>> melodies = {
|
||||
{ "Amazing Grace", pitches::amazing_grace },
|
||||
{ "An die Freude (Ode a la joie)", pitches::an_die_freude },
|
||||
{ "Auld Lang Syne", pitches::auld_lang_syne },
|
||||
{ "Canon de Pachelbel", pitches::canon_pachelbel },
|
||||
{ "Au clair de la Lune", pitches::au_clair_lune },
|
||||
{ "Douce Nuit", pitches::douce_nuit },
|
||||
{ "Frere Jacques", pitches::frere_jacques },
|
||||
{ "Fur Elise", pitches::fur_elise },
|
||||
{ "God Save the Queen", pitches::god_save_the_queen },
|
||||
{ "Greensleeves", pitches::greensleeves },
|
||||
{ "Happy Birthday", pitches::happy_birthday },
|
||||
{ "Indiana Jones", pitches::indiana_jones },
|
||||
{ "Jingle Bells", pitches::jingle_bells },
|
||||
{ "Super Mario Theme", pitches::mario },
|
||||
{ "La Marseillaise", pitches::marseillaise },
|
||||
{ "Tetris", pitches::tetris },
|
||||
{ "Twinkle Twinkle", pitches::twinkle_twinkle },
|
||||
{ "Vive le Vent", pitches::vive_le_vent }
|
||||
};
|
||||
|
||||
// Play melodies
|
||||
const MidiPlayer player;
|
||||
for (const auto &[title, melody] : melodies)
|
||||
{
|
||||
cout << " Playing: " << title << endl;
|
||||
player.playBuffer(melody);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
Reference in New Issue
Block a user