Skip to content

Commit

Permalink
+ new kits scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Sep 3, 2024
1 parent ec32c24 commit d9de6df
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
52 changes: 33 additions & 19 deletions Source/kits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,8 @@ void CDrumKitsScanner::scan_full()

// juce::File home_location = File::getSpecialLocation (juce::File::SpecialLocationType::userHomeDirectory);

v_kits_locations.push_back ("c:\\drum_sklad");
v_kits_locations.push_back ("d:\\drum_sklad");

v_kits_locations.push_back ("c:\\drumlabooh-kits");
v_kits_locations.push_back ("c:\\sfz-kits");
Expand Down Expand Up @@ -1305,6 +1307,9 @@ void CDrumKitsScanner::scan()
// juce::File home_location = File::getSpecialLocation (juce::File::SpecialLocationType::userHomeDirectory);


v_kits_locations.push_back ("c:\\drum_sklad");
v_kits_locations.push_back ("d:\\drum_sklad");

v_kits_locations.push_back ("c:\\drumlabooh-kits");
v_kits_locations.push_back ("c:\\sfz-kits");
v_kits_locations.push_back ("d:\\drumlabooh-kits");
Expand Down Expand Up @@ -1372,32 +1377,41 @@ void CDrumKitsScanner::scan()

if (kit_exists)
{
CDrumKit *kit = new CDrumKit;
kit->scan_mode = true;
kit->load (fname.c_str(), 44100);
//v_scanned_kits.push_back (kit);
map_kits.insert (pair<string,string> (kit->kit_name, fname));
v_kits_names.push_back (kit->kit_name);
delete kit;
//get kit name here

std::string ext = get_file_ext (fname);
std::string kit_name;

if (ext == "txt")
{
//get the last part of kd
kit_name = get_last_part (kd);
}

if (ext == "sfz")
{
kit_name = get_last_part (kd);
}


if (ext == "xml")
{
std::string fs = string_file_load (fname);
kit_name = get_string_between (fs, "<name>", "</name>");
}



map_kits.insert (pair<string,string> (kit_name, fname));
v_kits_names.push_back (kit_name);
// delete kit;
}

}


std::sort (v_kits_names.begin(), v_kits_names.end());
//CHANGE TO vector sort by ABC filled v_kits_names
/*
std::sort (v_scanned_kits.begin(), v_scanned_kits.end(), [](CDrumKit* a, CDrumKit* b) {return a->kit_name < b->kit_name;});

for (auto i : v_scanned_kits)
{
v_kits_names.push_back (i->kit_name);
///NEWWWW
delete i;
///
}
*/
}


Expand Down
40 changes: 40 additions & 0 deletions Source/utl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,43 @@ std::string bytes_to_file_size (size_t val)

return std::to_string (val) + " bytes";;
}


std::string get_string_between (const std::string &s, const std::string &start, const std::string &end)
{
std::string result;
size_t first = s.find (start);

if (first == std::string::npos)
return result;

first = first + start.length();

// std::cout << "first:" << first << std::endl;

size_t last = s.find (end);

//std::cout << "last:" << last << std::endl;

if (last == std::string::npos)
return result;

result = s.substr (first, last - first);

return result;
}


std::string get_last_part (const std::string &path)
{
std::string result;
size_t pos = path.rfind ("/");

if (pos == std::string::npos)
return result;

result = path.substr (pos + 1, path.length() - pos);

return result;
}

5 changes: 4 additions & 1 deletion Source/utl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ this code is the public domain
#include <vector>

bool file_exists (const std::string &name);
bool ends_with (std::string const &value, std::string const & ending);
bool ends_with (std::string const &value, std::string const &ending);
std::string resolve_symlink (const std::string &path);
std::string get_home_dir();

Expand All @@ -33,6 +33,9 @@ std::string transform_kit_path_to_local (const std::string &path);
std::string transform_kit_path_from_local (const std::string &path);

std::string bytes_to_file_size (size_t val);
std::string get_string_between (const std::string &s, const std::string &start, const std::string &end);
std::string get_last_part (const std::string &path);



#endif

0 comments on commit d9de6df

Please # to comment.