From 0f310b24210cc5f15ca92b3d9d73c3992e995bd0 Mon Sep 17 00:00:00 2001 From: Petr Semiletov Date: Tue, 9 Jul 2024 19:14:58 +0300 Subject: [PATCH] new cmake config, kit path portable with home dir --- CMakeLists.txt | 74 +++++++++++++++++++++++++------------- Source/PluginEditor.cpp | 4 ++- Source/PluginProcessor.cpp | 23 ++++++++---- Source/kits.cpp | 34 ++++++++++-------- Source/utl.cpp | 32 +++++++++++++++++ Source/utl.h | 4 +++ 6 files changed, 124 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a35213..a45b485 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,57 +32,60 @@ set(FETCHCONTENT_QUIET FALSE) set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +if(CMAKE_VERSION VERSION_LESS "3.2.8") -#FetchContent_Declare( -# drumkits - #GIT_REPOSITORY https://github.com/psemiletov/drum_sklad.git - #GIT_TAG master # last one - #GIT_PROGRESS TRUE -#) - +message("CMake less than 3.2.8") +FetchContent_Declare( + drum_sklad + URL https://github.com/psemiletov/drum_sklad/archive/refs/heads/main.zip + GIT_PROGRESS TRUE + DOWNLOAD_EXTRACT_TIMESTAMP TRUE +#since cmake 3.28 +# EXCLUDE_FROM_ALL +# +) -#FetchContent_GetProperties(drumkits) -#if(NOT drumkits_POPULATED) - #FetchContent_Populate(drumkits - #CONFIGURE_COMMAND "" - #BUILD_COMMAND "" - #) - #add_subdirectory(${drumkits_SOURCE_DIR} ${drumkits_BINARY_DIR} EXCLUDE_FROM_ALL) -#endif() +FetchContent_GetProperties(drum_sklad) +if(NOT drum_sklad_POPULATED) + FetchContent_Populate(drum_sklad) + message (${drum_sklad_SOURCE_DIR}) +endif() +else() FetchContent_Declare( drum_sklad URL https://github.com/psemiletov/drum_sklad/archive/refs/heads/main.zip GIT_PROGRESS TRUE DOWNLOAD_EXTRACT_TIMESTAMP TRUE +#since cmake 3.28 + EXCLUDE_FROM_ALL +# ) +FetchContent_MakeAvailable(drum_sklad) + -FetchContent_GetProperties(drum_sklad) -if(NOT drum_sklad_POPULATED) - FetchContent_Populate(drum_sklad) -# add_subdirectory(${drum_sklad_SOURCE_DIR} ${drum_sklad_BINARY_DIR} EXCLUDE_FROM_ALL) - message (${drum_sklad_SOURCE_DIR}) endif() -#FetchContent_MakeAvailable(drum_sklad) + +if(CMAKE_VERSION VERSION_LESS "3.2.8") + FetchContent_Declare( juce GIT_REPOSITORY https://github.com/juce-framework/JUCE.git # GIT_TAG 2a27ebcfae7ca7f6eb62b29d5f002ceefdaadbdb # release-7.0.7 GIT_TAG 7.0.10 # release-7.0.10 - +#since cmake 3.28 +# EXCLUDE_FROM_ALL +# GIT_PROGRESS TRUE ) - -#FetchContent_MakeAvailable(juce) - FetchContent_GetProperties(juce) if(NOT juce_POPULATED) FetchContent_Populate(juce) @@ -90,6 +93,27 @@ if(NOT juce_POPULATED) endif() +else() + +FetchContent_Declare( + juce + GIT_REPOSITORY https://github.com/juce-framework/JUCE.git +# GIT_TAG 2a27ebcfae7ca7f6eb62b29d5f002ceefdaadbdb # release-7.0.7 + GIT_TAG 7.0.10 # release-7.0.10 +#since cmake 3.28 + EXCLUDE_FROM_ALL +# + GIT_PROGRESS TRUE +) + + +FetchContent_MakeAvailable(juce) + +endif() + + + + # default plugin formats #set(JUCE_FORMATS AU VST3 Standalone) diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 6e6e666..ff18b50 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -504,6 +504,8 @@ void CAudioProcessorEditor::load_kit (const std::string &kitpath) { //make all drum labels empty + std::string real_kitpath = transform_kit_path_to_local (kitpath); + for (size_t i = 0; i < 36; i++) { drumcells[i].set_name ("EMPTY CELL"); @@ -519,7 +521,7 @@ void CAudioProcessorEditor::load_kit (const std::string &kitpath) for (size_t i = 0; i < kits_scanner.v_scanned_kits.size() ; i++) { - if (kits_scanner.v_scanned_kits[i]->kit_filename == kitpath) + if (kits_scanner.v_scanned_kits[i]->kit_filename == real_kitpath) k = kits_scanner.v_scanned_kits[i]; } diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 2c92755..2245e32 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -145,13 +145,13 @@ CAudioProcessor::CAudioProcessor() for (size_t i = 0; i < 36; i++) { - lps[i] = parameters.getRawParameterValue ("lp" + std::to_string(i)); - lp_cutoff[i] = parameters.getRawParameterValue ("lp_cutoff" + std::to_string(i)); - lp_reso[i] = parameters.getRawParameterValue ("lp_reso" + std::to_string(i)); + lps[i] = parameters.getRawParameterValue ("lp" + std::to_string(i)); + lp_cutoff[i] = parameters.getRawParameterValue ("lp_cutoff" + std::to_string(i)); + lp_reso[i] = parameters.getRawParameterValue ("lp_reso" + std::to_string(i)); - hps[i] = parameters.getRawParameterValue ("hp" + std::to_string(i)); - hp_cutoff[i] = parameters.getRawParameterValue ("hp_cutoff" + std::to_string(i)); - hp_reso[i] = parameters.getRawParameterValue ("hp_reso" + std::to_string(i)); + hps[i] = parameters.getRawParameterValue ("hp" + std::to_string(i)); + hp_cutoff[i] = parameters.getRawParameterValue ("hp_cutoff" + std::to_string(i)); + hp_reso[i] = parameters.getRawParameterValue ("hp_reso" + std::to_string(i)); analog[i] = parameters.getRawParameterValue ("analog" + std::to_string(i)); analog_amount[i] = parameters.getRawParameterValue ("analog_amount" + std::to_string(i)); @@ -808,7 +808,16 @@ juce::AudioProcessorEditor* CAudioProcessor::createEditor() //save void CAudioProcessor::getStateInformation (juce::MemoryBlock& destData) { - save_string_keyval ("drumkit_path", drumkit_path); + //std::string get_home_dir + + std::string drumkitpath_to_save = transform_kit_path_from_local (drumkit_path); + + std::cout << "SAVE PATH drumkitpath_to_save: " << drumkitpath_to_save << std::endl; + std::cout << "SAVE PATH drumkit_path: " << drumkit_path << std::endl; + + //save_string_keyval ("drumkit_path", drumkit_path); + save_string_keyval ("drumkit_path", drumkitpath_to_save); + save_int_keyval ("base_note_number", base_note_number); auto state = parameters.copyState(); std::unique_ptr xml (state.createXml()); diff --git a/Source/kits.cpp b/Source/kits.cpp index 677c638..d27d563 100644 --- a/Source/kits.cpp +++ b/Source/kits.cpp @@ -129,12 +129,12 @@ juce::AudioBuffer * CDrumLayer::load_whole_sample_resampled (const std::s - float *input_buffer = buffer->getWritePointer(0); - if (! input_buffer) - // continue; - { - delete buffer; - return 0; + float *input_buffer = buffer->getWritePointer(0); + if (! input_buffer) + // continue; + { + delete buffer; + return 0; } //else we need to resample @@ -166,10 +166,9 @@ juce::AudioBuffer * CDrumLayer::load_whole_sample_resampled (const std::s */ - std::shared_ptr rs = speex_resampler_cpp::createResampler (length_in_samples, 1, samplerate, sess_samplerate); - rs->read (input_buffer); - rs->write (out_buf->getWritePointer(0), output_frames_count); - + std::shared_ptr rs = speex_resampler_cpp::createResampler (length_in_samples, 1, samplerate, sess_samplerate); + rs->read (input_buffer); + rs->write (out_buf->getWritePointer(0), output_frames_count); samplerate = sess_samplerate; length_in_samples = output_frames_count; @@ -196,7 +195,7 @@ void CDrumLayer::load (const std::string &fname) file_name = fname; // if (channels > 0) - channel_data [0] = audio_buffer->getReadPointer (0); + channel_data [0] = audio_buffer->getReadPointer (0); //altough we have just mono sample, this "stereo" code is a legacy @@ -696,13 +695,20 @@ void CDrumKit::load (const std::string &fname, int sample_rate) samplerate = sample_rate; + std::string initial_fname = transform_kit_path_to_local (fname); + + //std::string filename = resolve_symlink (fname.c_str()); + std::string filename = resolve_symlink (initial_fname.c_str()); - string filename = resolve_symlink (fname.c_str()); + if (! scan_mode) + cout << "@@@@@@@@@@@@ void CDrumKit::load: " << filename << endl; + + kit_filename = filename; kit_dir = get_file_path (kit_filename); - - std::string source = string_file_load (filename); + + std::string source = string_file_load (kit_filename); if (source.empty()) return; diff --git a/Source/utl.cpp b/Source/utl.cpp index c57a90a..eb72082 100644 --- a/Source/utl.cpp +++ b/Source/utl.cpp @@ -374,3 +374,35 @@ string string_replace_all (const string &s, const string &from, const string &to return result; } + +std::string replace_string (std::string subject, const std::string& search, const std::string& replace) +{ + size_t pos = 0; + while ((pos = subject.find(search, pos)) != std::string::npos) { + subject.replace(pos, search.length(), replace); + pos += replace.length(); + } + return subject; +} + + +std::string transform_kit_path_to_local (const std::string &path) +{ + std::string result = path; + if (result.rfind ("$HOME", 0) == 0) + result = replace_string (result, "$HOME", get_home_dir()); + + return result; + +} + + +std::string transform_kit_path_from_local (const std::string &path) +{ + std::string result = path; + if (result.rfind (get_home_dir(), 0) == 0) + result = replace_string (result, get_home_dir(), "$HOME"); + + return result; + +} diff --git a/Source/utl.h b/Source/utl.h index cbac29e..a8ae951 100644 --- a/Source/utl.h +++ b/Source/utl.h @@ -28,6 +28,10 @@ bool findStringIC(const std::string & strHaystack, const std::string & strNeedle std::vector split_string_to_vector (const std::string& s, const std::string& delimeter, const bool keep_empty); std::string string_replace_all (const std::string &s, const std::string &from, const std::string &to); +std::string replace_string(std::string subject, const std::string& search, const std::string& replace); + +std::string transform_kit_path_to_local (const std::string &path); +std::string transform_kit_path_from_local (const std::string &path); #endif