Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ option(RTMIDI_API_CORE "Compile with CoreMIDI support." ${APPLE})
option(RTMIDI_API_ALSA "Compile with ALSA support." ${ALSA})
option(RTMIDI_API_AMIDI "Compile with Android support." ${ANDROID})

# Module options
option(RTMIDI_BUILD_MODULES "Build C++ modules for RtMidi" OFF)
option(RTMIDI_USE_NAMESPACE "Use namespace rtmidi for module" ON)

# Add -Wall if possible
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
Expand Down Expand Up @@ -215,6 +219,15 @@ target_compile_definitions(rtmidi PRIVATE RTMIDI_EXPORT)
target_link_libraries(rtmidi PUBLIC ${PUBLICLINKLIBS}
PRIVATE ${LINKLIBS})

if(RTMIDI_BUILD_MODULES)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28)
message(STATUS "Building rtmidi C++ module")
add_subdirectory(modules)
else()
message(WARNING "Skipping rtmidi C++ module (requires CMake 3.28+, found ${CMAKE_VERSION})")
endif()
endif()

# Add tests if requested.
option(RTMIDI_BUILD_TESTING "Build test programs" ON)
if (NOT DEFINED RTMIDI_BUILD_TESTING OR RTMIDI_BUILD_TESTING STREQUAL "")
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ RtMidi is a set of C++ classes (`RtMidiIn`, `RtMidiOut`, and API specific classe

MIDI input and output functionality are separated into two classes, `RtMidiIn` and `RtMidiOut`. Each class instance supports only a single MIDI connection. RtMidi does not provide timing functionality (i.e., output messages are sent immediately). Input messages are timestamped with delta times in seconds (via a `double` floating point type). MIDI data is passed to the user as raw bytes using an `std::vector<unsigned char>`.

RtMidi is also offered as a module, which is enabled with `RTMIDI_BUILD_MODULES`, and is accessed with `import rtmidi;`. Namespaces are inlined, so classes can be accessed through namespace `rtmidi` or through the global namespace (for example, `rtmidi::MidiApi` and `::MidiApi` are both valid).

## Windows

In some cases, for example to use RtMidi with GS Synth, it may be necessary for your program to call `CoInitializeEx` and `CoUninitialize` on entry to and exit from the thread that uses RtMidi.
Expand Down
5 changes: 5 additions & 0 deletions RtMidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@

#include "RtMidi.h"
#include <sstream>

inline namespace rtmidi {

#if defined(__APPLE__)
#include <TargetConditionals.h>
#endif
Expand Down Expand Up @@ -5270,3 +5273,5 @@ void MidiOutAndroid :: sendMessage( const unsigned char *message, size_t size )
}

#endif // __AMIDI__

}
3 changes: 3 additions & 0 deletions RtMidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include <string>
#include <vector>

inline namespace rtmidi {

/************************************************************************/
/*! \class RtMidiError
Expand Down Expand Up @@ -674,4 +675,6 @@ inline void RtMidiOut :: sendMessage( const std::vector<unsigned char> *message
inline void RtMidiOut :: sendMessage( const unsigned char *message, size_t size ) { static_cast<MidiOutApi *>(rtapi_)->sendMessage( message, size ); }
inline void RtMidiOut :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }

}

#endif
27 changes: 27 additions & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cmake_minimum_required(VERSION 3.28)

add_library(rtmidi_modules)

set(RTMIDI_MODULES
RtMidi.cppm
)

if(NOT COMMAND configure_cpp_module_target)
function(configure_cpp_module_target target)
target_sources(${target} PUBLIC FILE_SET CXX_MODULES FILES ${RTMIDI_MODULES})
endfunction()
endif()

configure_cpp_module_target(rtmidi_modules)

target_link_libraries(rtmidi_modules
PUBLIC
rtmidi
)

target_include_directories(rtmidi_modules
PRIVATE
${PROJECT_SOURCE_DIR}
)

target_compile_features(rtmidi_modules PUBLIC cxx_std_20)
16 changes: 16 additions & 0 deletions modules/RtMidi.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module;

#include "RtMidi.h"

export module rtmidi;

export inline namespace rtmidi {
using rtmidi::RtMidiError;
using rtmidi::RtMidiErrorCallback;
using rtmidi::RtMidi;
using rtmidi::RtMidiIn;
using rtmidi::RtMidiOut;
using rtmidi::MidiApi;
using rtmidi::MidiInApi;
using rtmidi::MidiOutApi;
}
Loading