Skip to content

Commit

Permalink
[code] Various improvements to max & pd
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Oct 9, 2023
1 parent 36353eb commit 2e88266
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 19 deletions.
37 changes: 29 additions & 8 deletions cmake/avendish.max.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)

Expand All @@ -57,14 +80,14 @@ function(avnd_make_max)
OUTPUT_NAME "${AVND_C_NAME}"
LIBRARY_OUTPUT_DIRECTORY max
RUNTIME_OUTPUT_DIRECTORY max
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
)

target_sources(
${AVND_FX_TARGET}
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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmake/avendish.pd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions cmake/avendish.sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/binding/max/outputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ struct outputs

out_k = 0;
avnd::output_introspection<T>::for_all(
avnd::get_outputs<T>(implementation), [this, &out_k, &x_obj](auto& ctl) {
avnd::get_outputs<T>(implementation), [this, &out_k](auto& ctl) {
this->setup(ctl, *outlets[out_k]);
out_k++;
});
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/binding/max/to_atoms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ struct to_atoms
}
else {
*ac = n_atoms;
*av = (t_atom *)getbytes(sizeof(t_atom) * (*ac));
*av = reinterpret_cast<t_atom *>(getbytes(sizeof(t_atom) * (*ac)));
if (!(*av)) {
*ac = 0;
return {};
Expand Down
5 changes: 0 additions & 5 deletions include/avnd/binding/vst3/bus_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ struct audio_bus_info<T>
static Steinberg::tresult
inputInfo(Steinberg::int32 index, Steinberg::Vst::BusInfo& info)
{
static const constexpr int input_audio_busses
= avnd::bus_introspection<T>::input_busses;
if(index == 0)
{
info.channelCount = avnd::input_channels<T>(2);
Expand All @@ -249,9 +247,6 @@ struct audio_bus_info<T>
static Steinberg::tresult
outputInfo(Steinberg::int32 index, Steinberg::Vst::BusInfo& info)
{
static const constexpr int output_audio_busses
= avnd::bus_introspection<T>::output_busses;

if(index == 0)
{
info.channelCount = avnd::output_channels<T>(2);
Expand Down
7 changes: 7 additions & 0 deletions include/avnd/binding/vst3/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions include/avnd/wrappers/audio_channel_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ struct audio_channel_manager<T>
i++;
return;
}
mimick_output(inputs, out, i);
this->mimick_output(inputs, out, i);
i++;
});
}
Expand All @@ -376,7 +376,7 @@ struct audio_channel_manager<T>
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++;
});
}
Expand Down
2 changes: 1 addition & 1 deletion include/avnd/wrappers/process/per_channel_port.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ struct process_adapter<T> : audio_buffer_storage<T>
{
int k = 0;
Info::for_all(ports, [&](auto& bus) {
using sample_type = std::decay_t<decltype(bus.channel[0])>;
if(k + 1 <= buffers.size())
{
bus.channel = const_cast<decltype(bus.channel)>(buffers[k]);
}
else
{
#if AVND_ENABLE_SAFE_BUFFER_STORAGE
using sample_type = std::decay_t<decltype(bus.channel[0])>;
auto& b = this->zero_storage_for(sample_type{});
if constexpr(Input)
{
Expand Down
2 changes: 1 addition & 1 deletion include/halp/audio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2e88266

Please sign in to comment.