From a14daf5e47d49b46c39e21ce002107da6c50e780 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Sun, 8 Sep 2024 14:46:10 +0200 Subject: [PATCH 1/3] Fixed MERDA module count --- CMakeLists.txt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7945c0cca..29c161e6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,22 +100,26 @@ file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" DESTINATION ${PD_OUTPUT_PATH}/LI file(REMOVE_RECURSE ${PD_OUTPUT_PATH}/audio) # Log the object count -function(count_files_and_directories dir extension file_count) +function(count_files_and_directories dir extension file_count count_dirs) file(GLOB files "${dir}/*") foreach(file ${files}) get_filename_component(file_name "${file}" NAME) - if(NOT file_name MATCHES "^\\.") # Exclude hidden files + if(NOT file_name MATCHES "^\\." + AND NOT file_name MATCHES "-help\\.pd$" + AND NOT file_name MATCHES ".unit\\.pd$" + AND NOT file_name MATCHES "about.MERDA.pd" + AND NOT (IS_DIRECTORY ${file} AND NOT count_dirs)) # Exclude hidden files and help files math(EXPR ${file_count} "${${file_count}} + 1") endif() endforeach() set(${file_count} ${${file_count}} PARENT_SCOPE) endfunction() -count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Source/Control" "c" control_c_file_count) -count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Source/Audio" "c" signal_c_file_count) -count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Abstractions/Control" "pd" control_pd_file_count) -count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Abstractions/Audio" "pd" signal_pd_file_count) -count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Abstractions/Merda/Modules" "pd" modules_pd_file_count) +count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Source/Control" "c" control_c_file_count YES) +count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Source/Audio" "c" signal_c_file_count YES) +count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Abstractions/Control" "pd" control_pd_file_count YES) +count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Abstractions/Audio" "pd" signal_pd_file_count YES) +count_files_and_directories("${CMAKE_CURRENT_SOURCE_DIR}/Abstractions/Merda/Modules" "pd" modules_pd_file_count NO) math(EXPR total_compiled "${control_c_file_count} + ${signal_c_file_count}") math(EXPR total_abstractions "${control_pd_file_count} + ${signal_pd_file_count}") From 60e2b3c17526598cb221c52a2f70f35b6b0b1e2b Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Sun, 8 Sep 2024 14:48:12 +0200 Subject: [PATCH 2/3] Renamed pd.link to pdlink --- Source/Audio/{pd.link~.c => pdlink~.c} | 52 +++++++++++++------------- Source/Control/{pd.link.c => pdlink.c} | 14 +++---- 2 files changed, 33 insertions(+), 33 deletions(-) rename Source/Audio/{pd.link~.c => pdlink~.c} (93%) rename Source/Control/{pd.link.c => pdlink.c} (92%) diff --git a/Source/Audio/pd.link~.c b/Source/Audio/pdlink~.c similarity index 93% rename from Source/Audio/pd.link~.c rename to Source/Audio/pdlink~.c index 8a42ab9bc..74a88d101 100644 --- a/Source/Audio/pd.link~.c +++ b/Source/Audio/pdlink~.c @@ -59,11 +59,11 @@ static void pdlink_audio_stream_init(t_pdlink_tilde *x, t_pdlink_audio_stream *s stream->stream_id = stream_id; stream->stream_active = 0; stream->signal_buffer = calloc(x->x_buf_size, sizeof(t_float)); - + int error; stream->samplerate_converter = src_new(SRC_LINEAR, 1, &error); if (stream->samplerate_converter == NULL || error) { - pd_error(x, "[pd.link~]: failed to initialise libsamplerate"); + pd_error(x, "[pdlink~]: failed to initialise libsamplerate"); stream->samplerate_converter = NULL; } } @@ -84,9 +84,9 @@ static void pdlink_tilde_audio_stream_convert_samplerate(t_pdlink_audio_stream * src_data.output_frames = *output_frames; src_data.src_ratio = sr_target / sr_original; src_data.end_of_input = 0; - + src_process(stream->samplerate_converter, &src_data); - + *output_frames = src_data.output_frames_gen; } @@ -152,7 +152,7 @@ static void pdlink_send_signal_message(t_link_handle link, const uint16_t channe memcpy(message_buf + 2, &channel, sizeof(uint16_t)); memcpy(message_buf + 4, &compressed, sizeof(uint16_t)); memcpy(message_buf + 6, &samplerate, sizeof(float)); - + // Copy signal data memcpy(message_buf + 16, buffer, bufsize); @@ -169,7 +169,7 @@ void pdlink_tilde_receive(void *ptr, const size_t len, const char* message) { uint32_t stream_id; uint16_t stream_channel; uint16_t stream_compressed; - + float stream_samplerate; memcpy(&stream_id, message, sizeof(uint32_t)); memcpy(&stream_channel, message + 2, sizeof(uint16_t)); @@ -180,22 +180,22 @@ void pdlink_tilde_receive(void *ptr, const size_t len, const char* message) { t_pdlink_audio_stream *stream = pdlink_tilde_get_audio_stream(x, stream_id); stream->stream_active = 1; stream->stream_channel = stream_channel; - + if(stream_compressed) { // Decode t_float output_buffer[120]; int num_decoded = udp_audio_decoder_decode(stream->audio_decoder, (unsigned char*)message+16, len - 16, output_buffer, 120); - + // Convert samplerate. Compresed streams are always 48khz int max_buffer_size = ceil((double)num_decoded * 48000.0 / current_samplerate); t_float* converted_samples = ALLOCA(t_float, max_buffer_size); long output_frames = max_buffer_size; pdlink_tilde_audio_stream_convert_samplerate(stream, output_buffer, num_decoded, converted_samples, &output_frames, 48000.0f, current_samplerate); - + if(x->x_debug && stream->buf_num_ready + output_frames > x->x_buf_size) { - if(!x->x_overrun) post("[pd.link~]: buffer overrun for port %i", (uint16_t)stream->stream_id); + if(!x->x_overrun) post("[pdlink~]: buffer overrun for port %i", (uint16_t)stream->stream_id); stream->buf_write_pos = (stream->buf_read_pos + x->x_delay) % x->x_buf_size; stream->buf_num_ready = x->x_delay; memset(stream->signal_buffer, 0, x->x_buf_size * sizeof(t_float)); @@ -218,10 +218,10 @@ void pdlink_tilde_receive(void *ptr, const size_t len, const char* message) { long output_frames = max_buffer_size; t_float* converted_samples = ALLOCA(t_float, max_buffer_size); pdlink_tilde_audio_stream_convert_samplerate(stream, samples, num_float, converted_samples, &output_frames, stream_samplerate, current_samplerate); - + if(x->x_debug && stream->buf_num_ready + output_frames > x->x_buf_size) { - if(!x->x_overrun) post("[pd.link~]: buffer overrun for port %i", (uint16_t)stream->stream_id); + if(!x->x_overrun) post("[pdlink~]: buffer overrun for port %i", (uint16_t)stream->stream_id); stream->buf_write_pos = (stream->buf_read_pos + x->x_delay) % x->x_buf_size; stream->buf_num_ready = x->x_delay; x->x_overrun++; @@ -238,7 +238,7 @@ void pdlink_tilde_receive(void *ptr, const size_t len, const char* message) { else { if(x->x_debug && stream->buf_num_ready + num_float > x->x_buf_size) { - if(!x->x_overrun) post("[pd.link~]: buffer overrun for port %i", (uint16_t)stream->stream_id); + if(!x->x_overrun) post("[pdlink~]: buffer overrun for port %i", (uint16_t)stream->stream_id); stream->buf_write_pos = (stream->buf_read_pos + x->x_delay) % x->x_buf_size; stream->buf_num_ready = x->x_delay; x->x_overrun++; @@ -284,7 +284,7 @@ static t_int *pdlink_tilde_perform(t_int *w){ } link_receive(x->x_link, x, pdlink_tilde_receive); - + // Num channel changed, update DSP chain if(pdlink_tilde_get_num_stream_channels(x) != x->x_out_nchs) { @@ -298,7 +298,7 @@ static t_int *pdlink_tilde_perform(t_int *w){ { if(x->x_debug) { - post("[pd.link~]: buffer underrun for port %i", (uint16_t)stream->stream_id); + post("[pdlink~]: buffer underrun for port %i", (uint16_t)stream->stream_id); } stream->stream_active = 0; continue; @@ -317,7 +317,7 @@ static t_int *pdlink_tilde_perform(t_int *w){ static void pdlink_tilde_dsp(t_pdlink_tilde *x, t_signal **sp) { if(x->x_name == gensym("")) return; - + if(x->x_compress && sp[0]->s_nchans != x->x_in_nchs) { if(x->x_audio_encoders) { @@ -343,7 +343,7 @@ static void pdlink_tilde_connection_lost(void *x, const int port) { if(((t_pdlink_tilde*)x)->x_debug) { - post("[pd.link~]: connection lost: %i", port); + post("[pdlink~]: connection lost: %i", port); } } @@ -366,7 +366,7 @@ static void pdlink_tilde_discover_loop(t_pdlink_tilde *x) int created = link_connect(x->x_link, data.port, data.ip); if(created && x->x_debug) { - post("[pd.link~]: connected to:\n%s\n%s:%i\n%s", data.hostname, data.ip, data.port, data.platform); + post("[pdlink~]: connected to:\n%s\n%s:%i\n%s", data.hostname, data.ip, data.port, data.platform); } } if(data.hostname) free(data.hostname); @@ -384,7 +384,7 @@ static void pdlink_tilde_free(t_pdlink_tilde *x) if(x->x_link) link_free(x->x_link); if(x->x_ping_clock) clock_free(x->x_ping_clock); if(x->x_dsp_reset_clock) clock_free(x->x_dsp_reset_clock); - + if(x->x_audio_streams) { for(int i = 0; i < x->x_num_streams; i++) { @@ -443,7 +443,7 @@ static void pdlink_tilde_set(t_pdlink_tilde *x, t_symbol *s) x->x_link = link_init(x->x_name->s_name, pd_platform, x->x_local, 7680413); if(!x->x_link) { - pd_error(x, "[pd.link]: failed to bind server socket"); + pd_error(x, "[pdlink]: failed to bind server socket"); x->x_link = NULL; // TODO: handle this state! } } @@ -491,7 +491,7 @@ static void *pdlink_tilde_new(t_symbol *s, int argc, t_atom *argv) if(!x->x_link) { - pd_error(x, "[pd.link~]: failed to bind server socket"); + pd_error(x, "[pdlink~]: failed to bind server socket"); pd_free((t_pd*)x); return NULL; } @@ -503,24 +503,24 @@ static void *pdlink_tilde_new(t_symbol *s, int argc, t_atom *argv) if(x->x_delay < 64) { - post("[pd.link~]: bufsize needs to be at least 64 samples"); + post("[pdlink~]: bufsize needs to be at least 64 samples"); post("bufsize set to 64 samples"); x->x_delay = 64; } if(x->x_debug) { - post("[pd.link~]: own IP:\n%s:%i", link_get_own_ip(x->x_link), link_get_own_port(x->x_link)); + post("[pdlink~]: own IP:\n%s:%i", link_get_own_ip(x->x_link), link_get_own_port(x->x_link)); } - + x->x_set_inlet = inlet_new((t_object*)x, (t_pd*)x, &s_symbol, gensym("__set")); x->x_outlet = outlet_new((t_object*)x, &s_signal); x->x_buf_size = x->x_delay >= 4096 ? x->x_delay * 2 : 8192; // needs to have at least a decent size to prevent overruns return (void *)x; } -void setup_pd0x2elink_tilde(void) { - pdlink_tilde_class = class_new(gensym("pd.link~"), +void pdlink_tilde_setup(void) { + pdlink_tilde_class = class_new(gensym("pdlink~"), (t_newmethod)pdlink_tilde_new, (t_method)pdlink_tilde_free, sizeof(t_pdlink_tilde), diff --git a/Source/Control/pd.link.c b/Source/Control/pdlink.c similarity index 92% rename from Source/Control/pd.link.c rename to Source/Control/pdlink.c index 980e17ea6..1bcd01045 100644 --- a/Source/Control/pd.link.c +++ b/Source/Control/pdlink.c @@ -65,7 +65,7 @@ static void pdlink_connection_lost(void *x, const int port) { if(((t_pdlink*)x)->x_debug) { - post("[pd.link]: connection lost: %i", port); + post("[pdlink]: connection lost: %i", port); } } @@ -90,7 +90,7 @@ static void pdlink_receive_loop(t_pdlink *x) int created = link_connect(x->x_link, data.port, data.ip); if(created && x->x_debug) { - post("[pd.link]: connected to:\n%s\n%s:%i\n%s", data.hostname, data.ip, data.port, data.platform); + post("[pdlink]: connected to:\n%s\n%s:%i\n%s", data.hostname, data.ip, data.port, data.platform); } } if(data.hostname) free(data.hostname); @@ -151,7 +151,7 @@ static void pdlink_set(t_pdlink *x, t_symbol *s) x->x_link = link_init(x->x_name->s_name, pd_platform, x->x_local, 7680412); if(!x->x_link) { - pd_error(x, "[pd.link]: failed to bind server socket"); + pd_error(x, "[pdlink]: failed to bind server socket"); x->x_link = NULL; // TODO: handle this state! } } @@ -184,7 +184,7 @@ static void *pdlink_new(t_symbol *s, int argc, t_atom *argv) pdlink_set(x, x->x_name); if(!x->x_link) { - pd_error(x, "[pd.link]: failed to bind server socket"); + pd_error(x, "[pdlink]: failed to bind server socket"); pd_free((t_pd*)x); } if(is_valid) { @@ -197,13 +197,13 @@ static void *pdlink_new(t_symbol *s, int argc, t_atom *argv) if(x->x_debug) { - post("[pd.link]: own IP:\n%s:%i", link_get_own_ip(x->x_link), link_get_own_port(x->x_link)); + post("[pdlink]: own IP:\n%s:%i", link_get_own_ip(x->x_link), link_get_own_port(x->x_link)); } return (void *)x; } -void setup_pd0x2elink(void) { - pdlink_class = class_new(gensym("pd.link"), +void pdlink_setup(void) { + pdlink_class = class_new(gensym("pdlink"), (t_newmethod)pdlink_new, (t_method)pdlink_free, sizeof(t_pdlink), From bde12326b30707acce7b7dd062e898cb12e1fa70 Mon Sep 17 00:00:00 2001 From: Timothy Schoen Date: Sun, 8 Sep 2024 14:54:09 +0200 Subject: [PATCH 3/3] Build fix --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29c161e6b..94e40605d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,9 +71,9 @@ endif() target_link_libraries(play.file_tilde PRIVATE ffmpeg) target_link_libraries(sfload PRIVATE ffmpeg) -target_link_libraries(pd.link PUBLIC link) -target_link_libraries(pd.link_tilde PUBLIC link opus) -target_include_directories(pd.link_tilde PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Source/Shared/libsamplerate ${CMAKE_CURRENT_SOURCE_DIR}/Source/Shared/opus) +target_link_libraries(pdlink PUBLIC link) +target_link_libraries(pdlink_tilde PUBLIC link opus) +target_include_directories(pdlink_tilde PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Source/Shared/libsamplerate ${CMAKE_CURRENT_SOURCE_DIR}/Source/Shared/opus) set(pdf_help "${CMAKE_CURRENT_SOURCE_DIR}/Documentation/README.pdf") file(GLOB help_files "${CMAKE_CURRENT_SOURCE_DIR}/Documentation/Help-files/*")