Skip to content

Commit

Permalink
new cmake config, kit path portable with home dir
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Jul 9, 2024
1 parent b83faa4 commit 0f310b2
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 47 deletions.
74 changes: 49 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,64 +32,88 @@ set(FETCHCONTENT_QUIET FALSE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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)
add_subdirectory(${juce_SOURCE_DIR} ${juce_BINARY_DIR} EXCLUDE_FROM_ALL)
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)
Expand Down
4 changes: 3 additions & 1 deletion Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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];
}

Expand Down
23 changes: 16 additions & 7 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 <juce::XmlElement> xml (state.createXml());
Expand Down
34 changes: 20 additions & 14 deletions Source/kits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ juce::AudioBuffer<float> * 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
Expand Down Expand Up @@ -166,10 +166,9 @@ juce::AudioBuffer<float> * CDrumLayer::load_whole_sample_resampled (const std::s
*/

std::shared_ptr<speex_resampler_cpp::Resampler> 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<speex_resampler_cpp::Resampler> 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;
Expand All @@ -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

Expand Down Expand Up @@ -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;

Expand Down
32 changes: 32 additions & 0 deletions Source/utl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
4 changes: 4 additions & 0 deletions Source/utl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ bool findStringIC(const std::string & strHaystack, const std::string & strNeedle

std::vector <std::string> 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

0 comments on commit 0f310b2

Please sign in to comment.