### Install Static Library Target Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Configures installation rules for the static library target. ```cmake if(libADLMIDI_STATIC) install(TARGETS ADLMIDI_static EXPORT libADLMIDIStaticTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") ``` -------------------------------- ### Install Documentation Files Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Collects and installs project documentation files like LICENSE and README to the system documentation directory. ```cmake file(GLOB DOCTXT_FILES "${libADLMIDI_SOURCE_DIR}/LICENSE*.txt" README.md AUTHORS ) install(FILES ${DOCTXT_FILES} DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/doc/libADLMIDI") ``` -------------------------------- ### Install adldumpwopl binary Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/dumpwopl/CMakeLists.txt Installs the adldumpwopl executable to the configured binary installation directory (CMAKE_INSTALL_BINDIR). ```cmake install(TARGETS adldumpwopl RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### Configure and Install pkg-config File Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Generates and installs the pkg-config file for non-Android platforms to facilitate library discovery. ```cmake if(NOT ANDROID) configure_file(libADLMIDI.pc.in libADLMIDI.pc @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libADLMIDI.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endif() ``` -------------------------------- ### Install pyalsaaudio with pip Source: https://github.com/wohlstand/libadlmidi/blob/master/examples/python-alsa/ReadMe.txt Install the pyalsaaudio package using pip with sudo. This is a required prerequisite before running the library. ```bash sudo pip3 install pyalsaaudio ``` -------------------------------- ### Define adldumpmiles executable and install Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/dumpmiles/CMakeLists.txt Creates the adldumpmiles executable from dumpmiles.cpp, disables PIE, and installs it to the binary directory. ```cmake add_executable(adldumpmiles dumpmiles.cpp) set_nopie(adldumpmiles) install(TARGETS adldumpmiles RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### Build mid2wav.go with go build Source: https://github.com/wohlstand/libadlmidi/blob/master/examples/golang-mid2wav/README.txt Run this command from a terminal to compile the mid2wav.go example. The resulting executable is named `mid2wav`. ```bash go build mid2wav.go ``` -------------------------------- ### Install Static and Shared Library Targets Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Configures the installation of static and shared library targets, including exporting targets to CMake files for downstream consumption. ```cmake install(EXPORT libADLMIDIStaticTargets FILE libADLMIDI-static-targets.cmake NAMESPACE libADLMIDI:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libADLMIDI") endif() if(libADLMIDI_SHARED) install(TARGETS ADLMIDI_shared EXPORT libADLMIDISharedTargets RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(EXPORT libADLMIDISharedTargets FILE libADLMIDI-shared-targets.cmake NAMESPACE libADLMIDI:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libADLMIDI") endif() ``` -------------------------------- ### CMake configuration for SDL2 audio demo Source: https://github.com/wohlstand/libadlmidi/blob/master/examples/sdl2_audio/CMakeLists.txt Configures the build for the adlmidi_sdl2_demo executable. It sets CMake policy CMP0111, finds SDL2, creates an interface target ADLMIDIEXAMPLE_SDL2 that links SDL2 (with mingw32 and SDL2main on MinGW), and builds the demo from sdl2_sample.c. It links pthread on non-MSVC, dl and m on non-Windows/non-Haiku, sets RPATH for shared ADLMIDI, and installs the executable. ```cmake if(POLICY CMP0111) cmake_policy(SET CMP0111 NEW) endif() find_package(SDL2 REQUIRED) add_library(ADLMIDIEXAMPLE_SDL2 INTERFACE) if(TARGET SDL2::SDL2) if(MINGW) target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE mingw32 SDL2::SDL2main SDL2::SDL2) else() target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE SDL2::SDL2) endif() target_include_directories(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_INCLUDE_DIRS}) else() string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES) target_include_directories(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_INCLUDE_DIRS}) target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_LIBRARIES}) endif() add_executable(adlmidi_sdl2_demo sdl2_sample.c) target_link_libraries(adlmidi_sdl2_demo PRIVATE ADLMIDI ADLMIDIEXAMPLE_SDL2) set_nopie(adlmidi_sdl2_demo) if(NOT MSVC) target_link_libraries(adlmidi_sdl2_demo PRIVATE pthread) endif() if(NOT WIN32 AND NOT HAIKU) target_link_libraries(adlmidi_sdl2_demo PRIVATE dl m) endif() if(TARGET ADLMIDI_shared) set_target_properties(adlmidi_sdl2_demo PROPERTIES INSTALL_RPATH "$ORIGIN/../lib") endif() install(TARGETS adlmidi_sdl2_demo RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### Build libADLMIDI with CMake Source: https://github.com/wohlstand/libadlmidi/blob/master/README.md Standard sequence of commands to configure, build, and install the library on Linux systems. ```bash mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make sudo make install ``` -------------------------------- ### Install Public Headers Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Installs the public header files defined in the ADLMIDI_PUBLIC_HEADERS variable to the standard include directory. ```cmake install(FILES ${ADLMIDI_PUBLIC_HEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") ``` -------------------------------- ### Configure and Install Package Config Files Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Uses CMakePackageConfigHelpers to generate and install the project configuration file for find_package support. ```cmake include(CMakePackageConfigHelpers) configure_package_config_file(libADLMIDIConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/libADLMIDIConfig.cmake" PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_INSTALL_FULL_BINDIR CMAKE_INSTALL_FULL_INCLUDEDIR CMAKE_INSTALL_FULL_LIBDIR INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libADLMIDI" ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libADLMIDIConfig.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libADLMIDI" ) ``` -------------------------------- ### CMake configuration for SDL2 Mixer example Source: https://github.com/wohlstand/libadlmidi/blob/master/examples/sdl2_mixer/CMakeLists.txt Sets CMake policy CMP0111, finds SDL2 and SDL2_mixer, creates an interface library for dependencies, and builds the demo executable. Handles different target configurations and links platform-specific libraries. ```cmake if(POLICY CMP0111) cmake_policy(SET CMP0111 NEW) endif() find_package(SDL2 REQUIRED) find_package(SDL2_MIXER REQUIRED) add_library(ADLMIDIEXAMPLE_SDL2 INTERFACE) if(TARGET SDL2_mixer::SDL2_mixer) target_include_directories(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_MIXER_INCLUDE_DIRS}) else() string(STRIP ${SDL2_MIXER_LIBRARIES} SDL2_MIXER_LIBRARIES) target_include_directories(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_MIXER_INCLUDE_DIRS}) target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_MIXER_LIBRARIES}) endif() if(TARGET SDL2::SDL2) if(MINGW) target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE mingw32 SDL2::SDL2main SDL2::SDL2) else() target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE SDL2::SDL2) endif() target_include_directories(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_INCLUDE_DIRS}) else() string(STRIP ${SDL2_LIBRARIES} SDL2_LIBRARIES) target_include_directories(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_INCLUDE_DIRS}) target_link_libraries(ADLMIDIEXAMPLE_SDL2 INTERFACE ${SDL2_LIBRARIES}) endif() add_executable(adlmidi_sdl2_mixer_demo sdl2_mixer_example.c) target_link_libraries(adlmidi_sdl2_mixer_demo PRIVATE ADLMIDI ADLMIDIEXAMPLE_SDL2) set_nopie(adlmidi_sdl2_mixer_demo) if(NOT MSVC) target_link_libraries(adlmidi_sdl2_mixer_demo PRIVATE pthread) endif() if(NOT WIN32) target_link_libraries(adlmidi_sdl2_mixer_demo PRIVATE dl m) endif() if(TARGET ADLMIDI_shared) set_target_properties(adlmidi_sdl2_mixer_demo PROPERTIES INSTALL_RPATH "$ORIGIN/../lib") endif() install(TARGETS adlmidi_sdl2_mixer_demo RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### CMake configuration for xmi2mid executable Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/xmi2mid/CMakeLists.txt Defines the xmi2mid executable target, includes necessary source directories, and sets up installation rules. ```cmake add_executable(xmi2mid xmi2mid.cpp) # TODO: Use own library target_include_directories(xmi2mid PRIVATE ${PROJECT_SOURCE_DIR}/src) install(TARGETS xmi2mid RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### CMake project setup and OpenMP flags Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt Initializes the gen_adldata project with C++11 and enables OpenMP if found, adding appropriate compiler flags for MSVC or other compilers. ```cmake cmake_minimum_required (VERSION 3.2...3.5) project(gen_adldata CXX) set(CMAKE_CXX_STANDARD 11) find_package(OpenMP QUIET) if(OPENMP_FOUND) if(MSVC AND NOT (MSVC_VERSION LESS 1900)) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -openmp:experimental") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -openmp:experimental") else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) ``` -------------------------------- ### CMake configuration for mus2mid Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/mus2mid/CMakeLists.txt Defines the executable target, installation path, and platform-specific build properties. ```cmake add_executable(mus2mid mus2mid.cpp cvt_mus2mid.hpp) install(TARGETS mus2mid RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") if(WIN32) set_property(TARGET mus2mid PROPERTY WIN32_EXECUTABLE OFF) if(MSVC) target_compile_definitions(mus2mid PRIVATE -DWIN32_CONSOLE) endif() endif() if(ADLMIDI_DOS) set_target_properties(mus2mid PROPERTIES SUFFIX ".exe") endif() ``` -------------------------------- ### CMake build configuration for adldumpbank Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/dumpbank/CMakeLists.txt Defines the adldumpbank executable from dumpbank.cpp, disables PIE, and installs it to the binary directory. ```cmake add_executable(adldumpbank dumpbank.cpp) set_nopie(adldumpbank) install(TARGETS adldumpbank RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") if(WIN32) set_property(TARGET adldumpbank PROPERTY WIN32_EXECUTABLE OFF) if(MSVC) target_compile_definitions(adldumpbank PRIVATE -DWIN32_CONSOLE) endif() endif() ``` -------------------------------- ### CMake configuration for ADLMIDI VLC plugin Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/vlc_codec/CMakeLists.txt Builds the adlmidi_vlc_plugin as a MODULE library. On macOS, it finds VLC libraries from the VLC.app bundle; otherwise uses find_package(LIBVLC). Defines module metadata (copyright, license, module string) and links against ADLMIDI_static. On Windows with GCC, adds static linking flags for libgcc/libstdc++ and pthread. Installs to VLC plugin path unless VLC_PLUGIN_NOINSTALL is set, then to CMAKE_INSTALL_LIBDIR/vlc-codec/. ```cmake set(CMAKE_C_STANDARD 99) if(APPLE) find_library(LIBVLC_LIBRARY vlc REQUIRED PATHS /Applications/VLC.app/Contents/MacOS/lib) find_library(LIBVLCCORE_LIBRARY vlccore REQUIRED PATHS /Applications/VLC.app/Contents/MacOS/lib) set(VLCPLUGIN_CODEC_INSTALL_PATH "/Applications/VLC.app/Contents/MacOS/plugins/") else() find_package(LIBVLC REQUIRED) endif() add_library(adlmidi_vlc_plugin MODULE libadlmidi.c) set_target_properties(adlmidi_vlc_plugin PROPERTIES OUTPUT_NAME adlmidi_plugin) target_compile_definitions(adlmidi_vlc_plugin PUBLIC "VLC_MODULE_COPYRIGHT=\"Copyright (c) Vitaly Novichkov\"" "VLC_MODULE_LICENSE=\"GPLv3\"" "MODULE_STRING=\"adlmidi\"" ) if(APPLE) target_include_directories(adlmidi_vlc_plugin PRIVATE "/Applications/VLC.app/Contents/MacOS/include" "/Users/vitaly/Repos/vlc-3.0.21/include" ) target_link_libraries(adlmidi_vlc_plugin PRIVATE ADLMIDI_static ${LIBVLCCORE_LIBRARY} ${LIBVLC_LIBRARY}) else() target_link_libraries(adlmidi_vlc_plugin PRIVATE ADLMIDI_static libvlc::plugin m) endif() if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX) set_property(TARGET adlmidi_vlc_plugin APPEND_STRING PROPERTY LINK_FLAGS " -static-libgcc -static-libstdc++") set_property(TARGET adlmidi_vlc_plugin APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-Bstatic,--whole-archive -lpthread -Wl,-Bdynamic,--no-whole-archive") endif() if(NOT VLC_PLUGIN_NOINSTALL) message("VLC install path: ${VLCPLUGIN_CODEC_INSTALL_PATH} ${LIBVLCCORE_LIBRARY} ${LIBVLC_LIBRARY}") install(TARGETS adlmidi_vlc_plugin DESTINATION "${VLCPLUGIN_CODEC_INSTALL_PATH}") else() install(TARGETS adlmidi_vlc_plugin DESTINATION "${CMAKE_INSTALL_LIBDIR}/vlc-codec/") endif() ``` -------------------------------- ### CMake build configuration for mididump Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/mididump/CMakeLists.txt Defines the mididump executable target with its source files, compile definitions, include directories, linking, and installation rules. Requires the common utf8main.cmake and uses the set_nopie helper. ```cmake include(../common/utf8main.cmake) set(ADLMIDI_PLAY_SRC mididump.cpp ${UTF8MAIN_SRCS} ../../src/midiseq/file_reader.hpp ../../src/midiseq/midi_sequencer.h ../../src/midiseq/midi_sequencer.hpp ../../src/midiseq/midi_sequencer_impl.hpp ../../src/midiseq/impl/common.hpp ../../src/midiseq/impl/cvt_xmi2mid.hpp ../../src/midiseq/impl/databank_impl.hpp ../../src/midiseq/impl/debug_songdump.hpp ../../src/midiseq/impl/durated_note_impl.hpp ../../src/midiseq/impl/err_string_impl.hpp ../../src/midiseq/impl/io_impl.hpp ../../src/midiseq/impl/load_music_impl.hpp ../../src/midiseq/impl/loop_impl.hpp ../../src/midiseq/impl/mididata_impl.hpp ../../src/midiseq/impl/miditrack_impl.hpp ../../src/midiseq/impl/platform_impl.hpp ../../src/midiseq/impl/process_impl.hpp ../../src/midiseq/impl/read_cmf_impl.hpp ../../src/midiseq/impl/read_gmf_impl.hpp ../../src/midiseq/impl/read_hmi_impl.hpp ../../src/midiseq/impl/read_imf_impl.hpp ../../src/midiseq/impl/read_klm_impl.hpp ../../src/midiseq/impl/read_mus_impl.hpp ../../src/midiseq/impl/read_rsxx_impl.hpp ../../src/midiseq/impl/read_smf_impl.hpp ../../src/midiseq/impl/read_xmi_impl.hpp ../../src/midiseq/impl/tempo_fraction.hpp ) add_executable(mididump ${ADLMIDI_PLAY_SRC}) set_nopie(mididump) target_compile_definitions(mididump PRIVATE BWMIDI_ENABLE_DEBUG_SONG_DUMP BWMIDI_ENABLE_OPL_MUSIC_SUPPORT) target_include_directories(mididump PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../../src/midiseq/") target_link_libraries(mididump PRIVATE ADLMIDI) install(TARGETS mididump RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### Conditional Subdirectory Inclusion Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Adds various utility and example subdirectories based on specific build options. ```cmake if(WITH_OLD_UTILS) # Old utility to dump AdLib bank files add_subdirectory(utils/dumpbank) # Old utility to dump AIL bank files add_subdirectory(utils/dumpmiles) # A special utility to dump the WOPL bank content add_subdirectory(utils/dumpwopl) endif() if(WITH_EMBEDDED_BANKS AND WITH_GENADLDATA AND NOT ADLMIDI_DOS) add_subdirectory(utils/gen_adldata) endif() if(WITH_MIDIPLAY) add_subdirectory(utils/midiplay) endif() if(WITH_ADLMIDI2) add_subdirectory(utils/adlmidi-2) endif() if(WITH_MUS2MID) add_subdirectory(utils/mus2mid) endif() if(WITH_XMI2MID) add_subdirectory(utils/xmi2mid) endif() if(WITH_MIDIDUMP) add_subdirectory(utils/mididump) endif() if(EXAMPLE_SDL2_AUDIO AND NOT ADLMIDI_DOS) add_subdirectory(examples/sdl2_audio) endif() if(WITH_VLC_PLUGIN AND NOT ADLMIDI_DOS) add_subdirectory(utils/vlc_codec) endif() if(WIN32 AND WITH_WINMMDRV) add_subdirectory(utils/winmm_drv) endif() ``` -------------------------------- ### Initialize the library with adl_init Source: https://github.com/wohlstand/libadlmidi/wiki/Basic-use Initializes the library with a sample rate of 44100 Hz. To change the sample rate later, free the instance with adl_close and call adl_init again with a new value. ```c midi_player = adl_init(44100); ``` -------------------------------- ### Select bank list and cache file paths Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt Determines the input bank list and output cache file based on custom bank list option and existence of banks.ini. ```cmake if("${GENADLDATA_CUSTOM_BANKLIST}" STREQUAL "") if(EXISTS "${libADLMIDI_SOURCE_DIR}/banks.ini" AND NOT BUILD_NO_GREY_BANKS) set(ADLDATA_INI_FILE "${libADLMIDI_SOURCE_DIR}/banks.ini") set(ADLDATA_CACHE_FILE "${libADLMIDI_SOURCE_DIR}/fm_banks/adldata-cache.dat") else() set(ADLDATA_INI_FILE "${libADLMIDI_SOURCE_DIR}/banks-no-grey.ini") set(ADLDATA_CACHE_FILE "${libADLMIDI_SOURCE_DIR}/fm_banks_new/adldata-no-grey-cache.dat") endif() else() set(ADLDATA_INI_FILE "${GENADLDATA_CUSTOM_BANKLIST}") set(ADLDATA_CACHE_FILE "${CMAKE_BINARY_DIR}/instdb/adldata-cache.dat") endif() ``` -------------------------------- ### Load a MIDI file with adl_openFile Source: https://github.com/wohlstand/libadlmidi/wiki/Basic-use Loads a MIDI file. Returns 0 on success, -1 on failure (wrong path or invalid file). On failure, prints the error using adl_errorInfo and closes the instance. ```c if (adl_openFile(midi_player, "myfile.mid") < 0) { printf("Couldn't open music file: %s\n", adl_errorInfo(midi_player)); adl_close(midi_player); exit(1); } ``` -------------------------------- ### Add Test Subdirectories Source: https://github.com/wohlstand/libadlmidi/blob/master/test/CMakeLists.txt Includes the bankmap, conversion, and wopl-file subdirectories into the build process. ```cmake add_subdirectory(bankmap) add_subdirectory(conversion) add_subdirectory(wopl-file) ``` -------------------------------- ### Include OPL Models Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Includes the OPL models configuration file. ```cmake include(src/models/opl_models.cmake) ``` -------------------------------- ### CMake configuration for WoplFile test Source: https://github.com/wohlstand/libadlmidi/blob/master/test/wopl-file/CMakeLists.txt Sets C++ standard to 11, includes common and source directories, builds the WoplFile executable with wopl_file.cpp and wopl_file.c, links Catch2 objects, defines GSL_THROW_ON_CONTRACT_VIOLATION, and adds a CTest test named WoplFileTest. ```cmake set(CMAKE_CXX_STANDARD 11) include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../common ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) add_executable(WoplFile wopl_file.cpp ${libADLMIDI_SOURCE_DIR}/src/wopl/wopl_file.c $) target_compile_definitions(WoplFile PRIVATE GSL_THROW_ON_CONTRACT_VIOLATION) add_test(NAME WoplFileTest COMMAND WoplFile WORKING_DIRECTORY "${libADLMIDI_SOURCE_DIR}") ``` -------------------------------- ### Select DOSBox emulator sources Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt When USE_DOSBOX_EMULATOR is enabled, adds DOSBox OPL3 emulator source files; otherwise defines ADLMIDI_DISABLE_DOSBOX_EMULATOR. ```cmake if(USE_DOSBOX_EMULATOR) set(HAS_EMULATOR TRUE) list(APPEND GEN_ADLDATA_SRC ${libADLMIDI_SOURCE_DIR}/src/chips/dosbox_opl3.cpp ${libADLMIDI_SOURCE_DIR}/src/chips/dosbox_opl3.h ${libADLMIDI_SOURCE_DIR}/src/chips/dosbox/dbopl.cpp ${libADLMIDI_SOURCE_DIR}/src/chips/dosbox/dbopl.h ) else() add_definitions(-DADLMIDI_DISABLE_DOSBOX_EMULATOR) endif() ``` -------------------------------- ### Add include directories Source: https://github.com/wohlstand/libadlmidi/blob/master/test/bankmap/CMakeLists.txt Adds include directories for common, include, and src. ```cmake include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../common ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) ``` -------------------------------- ### Configure Nuked OPL3 LLE emulator sources Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt When USE_NUKED_OPL3_LLE_EMULATOR is enabled, adds the OPL3 LLE emulator source files to the target, sets HAS_EMULATOR to TRUE, and defines ADLMIDI_ENABLE_OPL3_LLE_EMULATOR publicly. ```CMake if(USE_NUKED_OPL3_LLE_EMULATOR) set(HAS_EMULATOR TRUE) target_sources(${targetLib} PRIVATE ${libADLMIDI_SOURCE_DIR}/src/chips/ymf262_lle.cpp ${libADLMIDI_SOURCE_DIR}/src/chips/ymf262_lle.h ${libADLMIDI_SOURCE_DIR}/src/chips/ymf262_lle/nopl3.c ${libADLMIDI_SOURCE_DIR}/src/chips/ymf262_lle/nopl3.h ${libADLMIDI_SOURCE_DIR}/src/chips/ymf262_lle/nuked_fmopl3.c ${libADLMIDI_SOURCE_DIR}/src/chips/ymf262_lle/nuked_fmopl3.h ) target_compile_definitions(${targetLib} PUBLIC ADLMIDI_ENABLE_OPL3_LLE_EMULATOR) endif() ``` -------------------------------- ### Progress and minify compile options Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt Adds compile definitions for progress printing (if enabled) and minification (default ON), plus optional comments. ```cmake option(WITH_GENADLDATA_PROGRESS "Enable progress printing in gen_adldata" OFF) if(WITH_GENADLDATA_PROGRESS OR WITH_GENADLDATA_DEEPDEBUG) target_compile_options(gen_adldata PUBLIC "-DADL_GENDATA_PRINT_PROGRESS") endif() option(WITH_GENADLDATA_MINIFY "Minify the printing result at gen_adldata" ON) if(WITH_GENADLDATA_MINIFY) target_compile_options(gen_adldata PUBLIC "-DADL_GENDATA_MINIFY") endif() if(WITH_GENADLDATA_COMMENTS) target_compile_options(gen_adldata PUBLIC "-DADLDATA_WITH_COMMENTS") endif() ``` -------------------------------- ### Configure Nuked OPL2 LLE emulator sources Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt When USE_NUKED_OPL2_LLE_EMULATOR is enabled, adds the OPL2 LLE emulator source files to the target, sets HAS_EMULATOR to TRUE, and defines ADLMIDI_ENABLE_OPL2_LLE_EMULATOR publicly. ```CMake if(USE_NUKED_OPL2_LLE_EMULATOR) set(HAS_EMULATOR TRUE) target_sources(${targetLib} PRIVATE ${libADLMIDI_SOURCE_DIR}/src/chips/ym3812_lle.cpp ${libADLMIDI_SOURCE_DIR}/src/chips/ym3812_lle.h ${libADLMIDI_SOURCE_DIR}/src/chips/ym3812_lle/nopl2.c ${libADLMIDI_SOURCE_DIR}/src/chips/ym3812_lle/nopl2.h ${libADLMIDI_SOURCE_DIR}/src/chips/ym3812_lle/nuked_fmopl2.c ${libADLMIDI_SOURCE_DIR}/src/chips/ym3812_lle/nuked_fmopl2.h ) target_compile_definitions(${targetLib} PUBLIC ADLMIDI_ENABLE_OPL2_LLE_EMULATOR) endif() ``` -------------------------------- ### Define driver source files and create module library Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/winmm_drv/CMakeLists.txt Sets the list of source files for the WinMM driver and creates a MODULE library named adlmididrv. It also sets properties to remove the prefix, links against winmm and ADLMIDI_static, adds the config include directory, and defines necessary compile definitions. ```cmake set(ADLMIDI_DRIVER_SRC src/winmm_drv.def src/winmm_drv.cpp src/MidiSynth.cpp src/MidiSynth.h src/stdafx.h src/targetver.h config/regconfig.c config/regconfig.h ) add_library(adlmididrv MODULE ${ADLMIDI_DRIVER_SRC}) set_target_properties(adlmididrv PROPERTIES PREFIX "") target_link_libraries(adlmididrv PRIVATE winmm ADLMIDI_static) target_include_directories(adlmididrv PRIVATE config) target_compile_definitions(adlmididrv PRIVATE -D_USRDLL -D_WINDLL -DMM_WIN32DRV_EXPORTS -DENABLE_REG_SERVER ) ``` -------------------------------- ### mid2wav command-line usage and flags Source: https://github.com/wohlstand/libadlmidi/blob/master/examples/golang-mid2wav/README.txt Shows the usage of the compiled `./mid2wav` binary. The `-b` flag sets the bank (default 59), `-c` sets the number of chips (default 2), `-i` specifies the input MIDI file, and `-o` specifies the output wave file. ```text Usage of ./mid2wav: -b int bank (default 59) -c int chips (default 2) -i string input midi file -o string output wave file ``` -------------------------------- ### Configure hardware serial emulator sources Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt When USE_HW_SERIAL is enabled, adds the serial port source file, sets HAS_EMULATOR to TRUE, defines ENABLE_HW_OPL_SERIAL_PORT privately and ADLMIDI_ENABLE_HW_SERIAL publicly. ```CMake if(USE_HW_SERIAL) set(HAS_EMULATOR TRUE) target_sources(${targetLib} PRIVATE ${libADLMIDI_SOURCE_DIR}/src/chips/opl_serial_port.cpp ) target_compile_definitions(${targetLib} PRIVATE ENABLE_HW_OPL_SERIAL_PORT) target_compile_definitions(${targetLib} PUBLIC ADLMIDI_ENABLE_HW_SERIAL) endif() ``` -------------------------------- ### Enable Compiler Warnings Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Enables -Wall and -Wextra warnings for both C and C++ compilers. ```cmake set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") ``` -------------------------------- ### Build executable and link libraries Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt Creates the gen_adldata executable from the collected sources, sets C++ latest for MSVC, links pthread and m on other platforms, and disables PIE. ```cmake add_executable(gen_adldata ${GEN_ADLDATA_SRC} ) if(MSVC) message("Turned on C++11 on MSVC") target_compile_options(gen_adldata PUBLIC "/std:c++latest") else() target_link_libraries(gen_adldata PRIVATE pthread m) endif() set_nopie(gen_adldata) ``` -------------------------------- ### Include directory configuration for libADLMIDI Source: https://github.com/wohlstand/libadlmidi/blob/master/android/CMakeLists.txt Specifies the include directories for the libADLMIDI target, setting them for both private and interface usage. ```cmake # Specify directories which the compiler should look for headers target_include_directories(libADLMIDI PRIVATE ${include_DIR} ) target_include_directories(libADLMIDI INTERFACE ${include_DIR} ) ``` -------------------------------- ### Windows-specific configuration for xmi2mid Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/xmi2mid/CMakeLists.txt Configures the executable for Windows, ensuring it runs as a console application when using MSVC. ```cmake if(WIN32) set_property(TARGET xmi2mid PROPERTY WIN32_EXECUTABLE OFF) if(MSVC) target_compile_definitions(xmi2mid PRIVATE -DWIN32_CONSOLE) endif() endif() ``` -------------------------------- ### Play audio with adl_play Source: https://github.com/wohlstand/libadlmidi/wiki/Basic-use Generates audio in a loop. adl_play takes the instance, the number of 16-bit PCM samples (must be a multiple of two), and a buffer. It returns the number of samples generated; 0 indicates end of file. The buffer receives 2048 stereo frames (each frame has two samples). ```c short buffer[4096]; int samples_count = 0; do { samples_count = adl_play(midi_player, 4096, buffer); if (samples_count > 0) { /* do something with the generated chunk */ } } while (samples_count <= 0); ``` -------------------------------- ### Custom target to run gen_adldata Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt Creates a custom target 'gen-adldata-run' that executes gen_adldata with the selected bank list and cache file, producing the database. ```cmake if(WITH_GENADLDATA_RUN) add_custom_target(gen-adldata-run #OUTPUT ${ADLDATA_DATABASE} COMMAND gen_adldata "${ADLDATA_INI_FILE}" "${ADLDATA_DATABASE}" "${ADLDATA_CACHE_FILE}" WORKING_DIRECTORY ${libADLMIDI_SOURCE_DIR} DEPENDS gen_adldata COMMENT "Running Embedded FM banks database generation" VERBATIM BYPRODUCTS "${ADLDATA_DATABASE}" ) endif() ``` -------------------------------- ### Apply Platform-Specific Flags Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Applies -fcompare-debug-second for VITA and Nintendo platforms to suppress specific GCC warnings. ```cmake if(VITA) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVITA -DVITA=1 -fcompare-debug-second") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVITA -DVITA=1 -fcompare-debug-second") endif() if(NINTENDO_3DS OR NINTENDO_WII OR NINTENDO_WIIU OR NINTENDO_SWITCH) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcompare-debug-second") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcompare-debug-second") endif() ``` -------------------------------- ### Define Library Source Files Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Sets the base list of source files for libADLMIDI and conditionally appends DOS-specific source files. ```cmake set(libADLMIDI_SOURCES ${libADLMIDI_SOURCE_DIR}/src/adlmidi.cpp ${libADLMIDI_SOURCE_DIR}/src/adlmidi_load.cpp ${libADLMIDI_SOURCE_DIR}/src/adlmidi_midiplay.cpp ${libADLMIDI_SOURCE_DIR}/src/adlmidi_opl3.cpp ${libADLMIDI_SOURCE_DIR}/src/adlmidi_private.cpp ${libADLMIDI_SOURCE_DIR}/src/wopl/wopl_file.c ${OPL_MODELS_SOURCES} ) if(ADLMIDI_DOS) list(APPEND libADLMIDI_SOURCES ${libADLMIDI_SOURCE_DIR}/src/adlmidi_dos.c) endif() ``` -------------------------------- ### Declare the ADL_MIDIPlayer instance Source: https://github.com/wohlstand/libadlmidi/wiki/Basic-use Declares a pointer to the ADL_MIDIPlayer structure, initialized to NULL. ```c struct ADL_MIDIPlayer *midi_player = NULL; ``` -------------------------------- ### Define Catch-objects Library Source: https://github.com/wohlstand/libadlmidi/blob/master/test/CMakeLists.txt Creates an object library for Catch and sets the include directory for the common test files. ```cmake add_library(Catch-objects OBJECT "common/catch_main.cpp") target_include_directories(Catch-objects PRIVATE "common") ``` -------------------------------- ### Check initialization success with adl_errorString Source: https://github.com/wohlstand/libadlmidi/wiki/Basic-use Checks if initialization succeeded. If not, prints the error using adl_errorString and exits. adl_errorString should only be used for initialization errors, not after the library is initialized. ```c if (!midi_player) { printf("Couldn't initialize ADLMIDI: %s\n", adl_errorString()); exit(1); } ``` -------------------------------- ### CMake configuration for ConversionTest Source: https://github.com/wohlstand/libadlmidi/blob/master/test/conversion/CMakeLists.txt Sets the C++11 standard, includes common and source directories, and defines the ConversionTest executable with Catch-objects. ```cmake set(CMAKE_CXX_STANDARD 11) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../common ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) add_executable(ConversionTest conversion.cpp $) target_compile_definitions(ConversionTest PRIVATE GSL_THROW_ON_CONTRACT_VIOLATION) add_test(NAME ConversionTest COMMAND ConversionTest) ``` -------------------------------- ### Configure Build Type Definitions Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Sets preprocessor definitions based on the build type, such as NDEBUG for release or debug-specific GLIBCXX flags. ```cmake if(DEFINED CMAKE_BUILD_TYPE) string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) endif() if(CMAKE_BUILD_TYPE_LOWER EQUAL "release") add_definitions(-DNDEBUG) ENDIF() if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug" AND CMAKE_COMPILER_IS_GNUCXX) add_definitions(-D_GLIBCXX_DEBUG=1 -D_GLIBCXX_ASSERTIONS=1) endif() ``` -------------------------------- ### Define gen_adldata source file list Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/CMakeLists.txt Lists all source and header files required to build gen_adldata, including file format loaders and utility modules. ```cmake set(GEN_ADLDATA_SRC) list(APPEND GEN_ADLDATA_SRC gen_adldata.cc progs_cache.cpp progs_cache.h measurer.cpp measurer.h midi_inst_list.h ini/ini_processing.cpp ini/ini_processing.h file_formats/common.h file_formats/load_ail.h file_formats/load_bisqwit.h file_formats/load_bnk.h file_formats/load_bnk2.h file_formats/load_ea.h file_formats/load_ibk.h file_formats/load_jv.h file_formats/load_op2.h file_formats/load_tmb.h file_formats/load_wopl.h file_formats/load_woplx.h ) ``` -------------------------------- ### Add BankMapTest executable Source: https://github.com/wohlstand/libadlmidi/blob/master/test/bankmap/CMakeLists.txt Adds the BankMapTest executable from bank_map.cpp and Catch-objects. ```cmake add_executable(BankMapTest bank_map.cpp $) ``` -------------------------------- ### Define adldumpwopl executable target Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/dumpwopl/CMakeLists.txt Creates the adldumpwopl executable from dumpwopl.c and the WOPL file source and header. This is the primary build target for the utility. ```cmake add_executable(adldumpwopl dumpwopl.c ../../src/wopl/wopl_file.c ../../src/wopl/wopl_file.h ) ``` -------------------------------- ### Configure Sanitizer Options Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Conditional blocks to enable AddressSanitizer and UndefinedBehaviorSanitizer for the target library. ```cmake if(ENABLE_ADDRESS_SANITIZER) target_compile_options(${targetLib} PUBLIC -fsanitize=address) target_link_options(${targetLib} PUBLIC -fsanitize=address) endif() if(ENABLE_UNDEFINED_BEHAVIOUR_SANITIZER) target_compile_options(${targetLib} PUBLIC -fsanitize=undefined) target_link_options(${targetLib} PUBLIC -fsanitize=undefined) endif() endfunction() ``` -------------------------------- ### Link zita-resampler for high-quality resampling Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt When WITH_HQ_RESAMPLER is enabled and not DOS, finds the zita-resampler library, fails if not found, defines ADLMIDI_ENABLE_HQ_RESAMPLER privately, and links the library publicly. ```CMake if(WITH_HQ_RESAMPLER AND NOT ADLMIDI_DOS) find_library(ZITA_RESAMPLER_LIBRARY "zita-resampler") if(NOT ZITA_RESAMPLER_LIBRARY) message(FATAL_ERROR "zita-resampler library not found") endif() target_compile_definitions(${targetLib} PRIVATE ADLMIDI_ENABLE_HQ_RESAMPLER) target_link_libraries(${targetLib} PUBLIC ${ZITA_RESAMPLER_LIBRARY}) endif() ``` -------------------------------- ### Windows-specific settings for adldumpmiles Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/dumpmiles/CMakeLists.txt For Windows builds, sets WIN32_EXECUTABLE to OFF and defines WIN32_CONSOLE when using MSVC. ```cmake if(WIN32) set_property(TARGET adldumpmiles PROPERTY WIN32_EXECUTABLE OFF) if(MSVC) target_compile_definitions(adldumpmiles PRIVATE -DWIN32_CONSOLE) endif() endif() ``` -------------------------------- ### Load Doom bank with LoadDoom Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/scrapped.txt Loads a Doom format bank using the LoadDoom function, assigning bank number 64 and name 'rapt'. ```cpp LoadDoom("fm_banks/raptor/genmidi.op2", 64, "rapt"); ``` -------------------------------- ### Opal emulator conditional source selection Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Adds Opal OPL3 source files when USE_OPAL_EMULATOR is enabled, otherwise defines ADLMIDI_DISABLE_OPAL_EMULATOR. ```cmake if(USE_OPAL_EMULATOR) set(HAS_EMULATOR TRUE) target_sources(${targetLib} PRIVATE ${libADMIDI_SOURCE_DIR}/src/chips/opal_opl3.cpp ${libADMIDI_SOURCE_DIR}/src/chips/opal_opl3.h ${libADMIDI_SOURCE_DIR}/src/chips/opal/opal.c ${libADMIDI_SOURCE_DIR}/src/chips/opal/opal.h ) else() target_compile_definitions(${targetLib} PUBLIC ADLMIDI_DISABLE_OPAL_EMULATOR) endif() ``` -------------------------------- ### Set Global Optimization Flags Source: https://github.com/wohlstand/libadlmidi/blob/master/CMakeLists.txt Appends -fno-omit-frame-pointer to release, relwithdebinfo, and minsizerel build configurations for both C and C++ compilers. ```cmake set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-omit-frame-pointer") set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -fno-omit-frame-pointer") set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -fno-omit-frame-pointer") ``` -------------------------------- ### CMake configuration for libADLMIDI Source: https://github.com/wohlstand/libadlmidi/blob/master/android/CMakeLists.txt Defines the minimum CMake version, source file paths, and the shared library target for libADLMIDI. ```cmake cmake_minimum_required(VERSION 3.4.1) set(src_DIR ../src) set(include_DIR ../include) set(libADLMIDI_sources ${src_DIR}/adldata.cpp ${src_DIR}/adlmidi_load.cpp ${src_DIR}/adlmidi_midiplay.cpp ${src_DIR}/adlmidi_mus2mid.c ${src_DIR}/adlmidi_opl3.cpp ${src_DIR}/adlmidi_private.cpp ${src_DIR}/adlmidi_xmi2mid.c ${src_DIR}/adlmidi.cpp ${src_DIR}/wopl/wopl_file.c ${src_DIR}/chips/dosbox_opl3.cpp ${src_DIR}/chips/nuked_opl3_v174.cpp ${src_DIR}/chips/nuked_opl3.cpp ${src_DIR}/chips/opl_chip_base.cpp ${src_DIR}/chips/dosbox/dbopl.cpp ${src_DIR}/chips/nuked/nukedopl3_174.c ${src_DIR}/chips/nuked/nukedopl3.c ) add_library(libADLMIDI SHARED ${libADLMIDI_sources}) ``` -------------------------------- ### Commented-out LoadBNK calls Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/gen_adldata/scrapped.txt Two commented-out LoadBNK calls that are not active, showing alternative bank loading attempts. ```cpp //LoadBNK("bnk_files/grassman1.bnk", 63, "b63", false); //LoadBNK("bnk_files/grassman2.bnk", 64, "b64", false); ``` -------------------------------- ### MinGW-specific options for WinMM driver Source: https://github.com/wohlstand/libadlmidi/blob/master/utils/winmm_drv/CMakeLists.txt Defines options to control static linking of libwinpthreads and libmingwex when using MinGW (GCC) on Windows. These options are only available when WIN32 and CMAKE_COMPILER_IS_GNUCXX are true. ```cmake if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX) option(WITH_WINMMDRV_PTHREADS "Link libwinpthreads statically (when using pthread-based builds)" ON) option(WITH_WINMMDRV_MINGWEX "Link libmingwex statically (when using vanilla MinGW builds)" OFF) endif() ``` -------------------------------- ### FMwriteChannel implementation with operator tables Source: https://github.com/wohlstand/libadlmidi/blob/master/fm_banks/ymf262.pdf This block contains the implementation of FMwriteChannel, including operator mapping tables for OPL3 and SB Pro II, and the logic to write to the correct registers. It is a continuation of the earlier FMwriteChannel declaration. ```C++ static BYTE adlib_op[] = {0, 1, 2, 8, 9, 10, 16, 17, 18}; static BYTE sbpro_op[] = { 0, 1, 2, 6, 7, 8, 12, 13, 14, 18, 19, 20, 24, 25, 26, 30, 31, 32}; static WORD rg[] = {0x000,0x001,0x002,0x003,0x004,0x005, 0x008,0x009,0x00A,0x00B,0x00C,0x00D, 0x010,0x011,0x012,0x013,0x014,0x015, 0x100,0x101,0x102,0x103,0x104,0x105, 0x108,0x109,0x10A,0x10B,0x10C,0x10D, 0x110,0x111,0x112,0x113,0x114,0x115}; if (OPL3) { register WORD reg = sbpro_op[channel]; FMwriteReg(rg[reg]+regbase, data1); FMwriteReg(rg[reg+3]+regbase, data2); } else { register WORD reg = regbase+adlib_op[channel]; FMwriteReg(reg, data1); FMwriteReg(reg+3, data2); } } ```