From 2e88266531fec7d78e5c6ab621c8791315668f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sun, 8 Oct 2023 21:13:22 -0400 Subject: [PATCH] [code] Various improvements to max & pd --- cmake/avendish.max.cmake | 37 +++++++++++++++---- cmake/avendish.pd.cmake | 4 ++ cmake/avendish.sources.cmake | 11 ++++++ include/avnd/binding/max/outputs.hpp | 2 +- include/avnd/binding/max/to_atoms.hpp | 2 +- include/avnd/binding/vst3/bus_info.hpp | 5 --- include/avnd/binding/vst3/component.hpp | 7 ++++ .../avnd/wrappers/audio_channel_manager.hpp | 4 +- .../wrappers/process/per_channel_port.hpp | 2 +- include/halp/audio.hpp | 2 +- 10 files changed, 57 insertions(+), 19 deletions(-) diff --git a/cmake/avendish.max.cmake b/cmake/avendish.max.cmake index 42bad5a8..df7462d3 100644 --- a/cmake/avendish.max.cmake +++ b/cmake/avendish.max.cmake @@ -28,12 +28,31 @@ else() # set(MAXSDK_API_LIBRARY MaxAPI) endif() +file(READ "${MAXSDK_MAX_INCLUDE_DIR}/c74_linker_flags.txt" MAXSDK_LINKER_FLAGS) +string(STRIP "${MAXSDK_LINKER_FLAGS}" MAXSDK_LINKER_FLAGS) + set(MAXSDK_MAX_INCLUDE_DIR "${MAXSDK_MAX_INCLUDE_DIR}" CACHE INTERNAL "MAXSDK_MAX_INCLUDE_DIR") set(MAXSDK_MSP_INCLUDE_DIR "${MAXSDK_MSP_INCLUDE_DIR}" CACHE INTERNAL "MAXSDK_MSP_INCLUDE_DIR") set(MAXSDK_API_LIBRARY "${MAXSDK_API_LIBRARY}" CACHE INTERNAL "MAXSDK_API_LIBRARY") - +set(MAXSDK_LINKER_FLAGS "${MAXSDK_LINKER_FLAGS}" CACHE INTERNAL "MAXSDK_LINKER_FLAGS") + +add_library(maxmsp_commonsyms STATIC + "${MAXSDK_MAX_INCLUDE_DIR}/common/commonsyms.c" +) +target_compile_definitions( + maxmsp_commonsyms + PRIVATE + AVND_MAXMSP=1 + MAXAPI_USE_MSCRT=1 + C74_USE_STRICT_TYPES=1 +) + +target_include_directories(maxmsp_commonsyms PRIVATE + "${MAXSDK_MAX_INCLUDE_DIR}" + "${MAXSDK_MSP_INCLUDE_DIR}" +) function(avnd_make_max) - if(NOT MAXSDK_API_LIBRARY) + if(NOT MAXSDK_MAX_INCLUDE_DIR) return() endif() @@ -48,6 +67,10 @@ function(avnd_make_max) NEWLINE_STYLE LF ) + if(APPLE) + set_source_files_properties("${CMAKE_BINARY_DIR}/${MAIN_OUT_FILE}_max.cpp" PROPERTIES COMPILE_FLAGS -Wno-unreachable-code) + endif() + set(AVND_FX_TARGET "${AVND_TARGET}_max") add_library(${AVND_FX_TARGET} MODULE) @@ -57,6 +80,7 @@ function(avnd_make_max) OUTPUT_NAME "${AVND_C_NAME}" LIBRARY_OUTPUT_DIRECTORY max RUNTIME_OUTPUT_DIRECTORY max + MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) target_sources( @@ -64,7 +88,6 @@ function(avnd_make_max) PRIVATE "${AVND_MAIN_FILE}" "${CMAKE_BINARY_DIR}/${MAIN_OUT_FILE}_max.cpp" - "${MAXSDK_MAX_INCLUDE_DIR}/common/commonsyms.c" "${AVND_SOURCE_DIR}/include/avnd/binding/max/all.hpp" "${AVND_SOURCE_DIR}/include/avnd/binding/max/attributes_setup.hpp" @@ -101,16 +124,14 @@ function(avnd_make_max) PUBLIC Avendish::Avendish_max DisableExceptions + maxmsp_commonsyms ) if(APPLE) - find_library(MAXSDK_API_LIBRARY NAMES MaxAPI HINTS "${MAXSDK_MAX_INCLUDE_DIR}") - find_library(MAXSDK_MSP_LIBRARY NAMES MaxAudioAPI HINTS "${MAXSDK_MSP_INCLUDE_DIR}") - target_compile_definitions(${AVND_FX_TARGET} PUBLIC MAC_VERSION) set_property(TARGET ${AVND_FX_TARGET} PROPERTY BUNDLE True) set_property(TARGET ${AVND_FX_TARGET} PROPERTY BUNDLE_EXTENSION "mxo") - target_link_libraries(${AVND_FX_TARGET} PRIVATE -Wl,-undefined,dynamic_lookup) + target_link_libraries(${AVND_FX_TARGET} PUBLIC ${MAXSDK_LINKER_FLAGS} -Wl,-U,_class_dspinit -Wl,-U,_dsp_add64 -Wl,-U,_z_dsp_setup ) file(COPY "${AVND_SOURCE_DIR}/include/avnd/binding/max/resources/PkgInfo" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/max/${AVND_C_NAME}.mxo/Contents/) elseif(WIN32) target_compile_definitions(${AVND_FX_TARGET} PUBLIC WIN_VERSION _CRT_SECURE_NO_WARNINGS) @@ -123,9 +144,9 @@ function(avnd_make_max) find_library(MAXSDK_API_LIBRARY NAMES MaxAPI.lib HINTS "${MAXSDK_MAX_INCLUDE_DIR}") find_library(MAXSDK_MSP_LIBRARY NAMES MaxAudio.lib HINTS "${MAXSDK_MSP_INCLUDE_DIR}") endif() + target_link_libraries(${AVND_FX_TARGET} PRIVATE ${MAXSDK_API_LIBRARY} ${MAXSDK_MSP_LIBRARY}) endif() - target_link_libraries(${AVND_FX_TARGET} PRIVATE ${MAXSDK_API_LIBRARY} ${MAXSDK_MSP_LIBRARY}) # We only export ext_main to prevent conflicts in e.g. Max4Live. #if(APPLE) diff --git a/cmake/avendish.pd.cmake b/cmake/avendish.pd.cmake index 184ef441..60db1eb7 100644 --- a/cmake/avendish.pd.cmake +++ b/cmake/avendish.pd.cmake @@ -53,6 +53,10 @@ function(avnd_make_pd) NEWLINE_STYLE LF ) + if(APPLE) + set_source_files_properties("${CMAKE_BINARY_DIR}/${MAIN_OUT_FILE}_pd.cpp" PROPERTIES COMPILE_FLAGS -Wno-unreachable-code) + endif() + set(AVND_FX_TARGET "${AVND_TARGET}_pd") add_library(${AVND_FX_TARGET} MODULE) diff --git a/cmake/avendish.sources.cmake b/cmake/avendish.sources.cmake index 43f0664c..889987dc 100644 --- a/cmake/avendish.sources.cmake +++ b/cmake/avendish.sources.cmake @@ -14,6 +14,17 @@ if(MSVC) "-Zc:templateScope" -wd4244) target_compile_definitions(Avendish PUBLIC -DNOMINMAX=1 -DWIN32_LEAN_AND_MEAN=1) +elseif(APPLE) + target_compile_options(Avendish + PUBLIC + -Wno-c99-extensions + -Wno-global-constructors + -Wno-extra-semi + -Wno-exit-time-destructors + -Wno-cast-function-type + -Wno-unused-template + -Wno-unused-local-typedef + ) endif() target_sources(Avendish diff --git a/include/avnd/binding/max/outputs.hpp b/include/avnd/binding/max/outputs.hpp index 3929455f..531c8310 100644 --- a/include/avnd/binding/max/outputs.hpp +++ b/include/avnd/binding/max/outputs.hpp @@ -151,7 +151,7 @@ struct outputs out_k = 0; avnd::output_introspection::for_all( - avnd::get_outputs(implementation), [this, &out_k, &x_obj](auto& ctl) { + avnd::get_outputs(implementation), [this, &out_k](auto& ctl) { this->setup(ctl, *outlets[out_k]); out_k++; }); diff --git a/include/avnd/binding/max/to_atoms.hpp b/include/avnd/binding/max/to_atoms.hpp index 2be95afe..aa545e61 100644 --- a/include/avnd/binding/max/to_atoms.hpp +++ b/include/avnd/binding/max/to_atoms.hpp @@ -191,7 +191,7 @@ struct to_atoms } else { *ac = n_atoms; - *av = (t_atom *)getbytes(sizeof(t_atom) * (*ac)); + *av = reinterpret_cast(getbytes(sizeof(t_atom) * (*ac))); if (!(*av)) { *ac = 0; return {}; diff --git a/include/avnd/binding/vst3/bus_info.hpp b/include/avnd/binding/vst3/bus_info.hpp index 48cb00fb..dbe64abc 100644 --- a/include/avnd/binding/vst3/bus_info.hpp +++ b/include/avnd/binding/vst3/bus_info.hpp @@ -232,8 +232,6 @@ struct audio_bus_info static Steinberg::tresult inputInfo(Steinberg::int32 index, Steinberg::Vst::BusInfo& info) { - static const constexpr int input_audio_busses - = avnd::bus_introspection::input_busses; if(index == 0) { info.channelCount = avnd::input_channels(2); @@ -249,9 +247,6 @@ struct audio_bus_info static Steinberg::tresult outputInfo(Steinberg::int32 index, Steinberg::Vst::BusInfo& info) { - static const constexpr int output_audio_busses - = avnd::bus_introspection::output_busses; - if(index == 0) { info.channelCount = avnd::output_channels(2); diff --git a/include/avnd/binding/vst3/component.hpp b/include/avnd/binding/vst3/component.hpp index abaec244..f42d53e0 100644 --- a/include/avnd/binding/vst3/component.hpp +++ b/include/avnd/binding/vst3/component.hpp @@ -400,30 +400,37 @@ struct Component final break; } case Event::kDataEvent: { + [[maybe_unused]] auto& e = event.data; break; } case Event::kPolyPressureEvent: { + [[maybe_unused]] auto& e = event.polyPressure; break; } case Event::kNoteExpressionValueEvent: { + [[maybe_unused]] auto& e = event.noteExpressionValue; break; } case Event::kNoteExpressionTextEvent: { + [[maybe_unused]] auto& e = event.noteExpressionText; break; } case Event::kChordEvent: { + [[maybe_unused]] auto& e = event.chord; break; } case Event::kScaleEvent: { + [[maybe_unused]] auto& e = event.scale; break; } case Event::kLegacyMIDICCOutEvent: { + [[maybe_unused]] auto& e = event.midiCCOut; break; } diff --git a/include/avnd/wrappers/audio_channel_manager.hpp b/include/avnd/wrappers/audio_channel_manager.hpp index b2d2abc7..6e04a6f5 100644 --- a/include/avnd/wrappers/audio_channel_manager.hpp +++ b/include/avnd/wrappers/audio_channel_manager.hpp @@ -366,7 +366,7 @@ struct audio_channel_manager i++; return; } - mimick_output(inputs, out, i); + this->mimick_output(inputs, out, i); i++; }); } @@ -376,7 +376,7 @@ struct audio_channel_manager auto& inputs = avnd::get_inputs(processor); int i = 0; out_refl::for_all(outputs, [this, &inputs, &i](auto& out) { - mimick_output(inputs, out, i); + this->mimick_output(inputs, out, i); i++; }); } diff --git a/include/avnd/wrappers/process/per_channel_port.hpp b/include/avnd/wrappers/process/per_channel_port.hpp index 4db38d31..3a7e96de 100644 --- a/include/avnd/wrappers/process/per_channel_port.hpp +++ b/include/avnd/wrappers/process/per_channel_port.hpp @@ -24,7 +24,6 @@ struct process_adapter : audio_buffer_storage { int k = 0; Info::for_all(ports, [&](auto& bus) { - using sample_type = std::decay_t; if(k + 1 <= buffers.size()) { bus.channel = const_cast(buffers[k]); @@ -32,6 +31,7 @@ struct process_adapter : audio_buffer_storage else { #if AVND_ENABLE_SAFE_BUFFER_STORAGE + using sample_type = std::decay_t; auto& b = this->zero_storage_for(sample_type{}); if constexpr(Input) { diff --git a/include/halp/audio.hpp b/include/halp/audio.hpp index 99adb581..927f6e16 100644 --- a/include/halp/audio.hpp +++ b/include/halp/audio.hpp @@ -207,7 +207,7 @@ struct tick_musical }; double cur = start_in_bar; double q = std::floor(start_in_bar / div); - if(cur == q * div) + if(std::abs(cur - q * div) < 1e-9) { // Add it: we're on 0 or the correct thing frames.emplace_back(pos_to_frame(cur), q);