Skip to content

Commit

Permalink
new Adapt
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Sep 20, 2024
1 parent c5d8b32 commit 488f127
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 28 deletions.
98 changes: 77 additions & 21 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,17 +829,31 @@ void CAudioProcessorEditor::adapt()
if (! audioProcessor.drumkit)
return;

if (! audioProcessor.drumkit->loaded)
if (! audioProcessor.drumkit->loaded)
return;


if (audioProcessor.drumkit->kit_type != KIT_TYPE_DRUMLABOOH)
{
log ("Cannot adapt the non-Drumlabooh kit");
return;
}
if (audioProcessor.drumkit->kit_type == KIT_TYPE_DRUMLABOOH)
{
adapt_drumlabooh();
return;
}

if (audioProcessor.drumkit->kit_type == KIT_TYPE_QDRUMLABOOH)
{
adapt_qdrumlabooh();
return;
}

log ("Cannot adapt the non-Drumlabooh kit");
}


void CAudioProcessorEditor::adapt_drumlabooh()
{

std::string new_path = get_home_dir() + "/drum_sklad/";

std::string srate = std::to_string (audioProcessor.session_samplerate);

new_path += audioProcessor.drumkit->kit_name;
Expand All @@ -848,28 +862,70 @@ if (! audioProcessor.drumkit->loaded)

File source_dir (audioProcessor.drumkit->kit_dir);
File dest_dir (new_path);

if (! source_dir.copyDirectoryTo (dest_dir))
{
log ("CANNOT COPY KIT TO: " + new_path + "\n");
return;
}

if (source_dir.copyDirectoryTo (dest_dir))
{
audioProcessor.scanner.scan();
update_kits_list();
std::string kitfname = "/drumkit.txt";

audioProcessor.scanner.scan();
update_kits_list();

audioProcessor.drumkit_path = new_path + "/drumkit.txt";
audioProcessor.drumkit_path = new_path + kitfname;

tmr_leds.stopTimer();

audioProcessor.load_kit (audioProcessor.drumkit_path);
tmr_leds.stopTimer();
audioProcessor.load_kit (audioProcessor.drumkit_path);

//update GUI
//update GUI
if (audioProcessor.drumkit->kit_type == KIT_TYPE_DRUMLABOOH)
audioProcessor.drumkit->adapt();
load_kit();

load_kit();

log (audioProcessor.drumkit->kit_name);
log (bytes_to_file_size (audioProcessor.drumkit->total_samples_size()));
log (audioProcessor.drumkit->kit_name);
log (bytes_to_file_size (audioProcessor.drumkit->total_samples_size()));

tmr_leds.startTimer (1000 / 15); //15 FPS
}
tmr_leds.startTimer (1000 / 15); //15 FPS
}


void CAudioProcessorEditor::adapt_qdrumlabooh()
{
std::string new_path = get_home_dir() + "/drum_sklad/";

std::string srate = std::to_string (audioProcessor.session_samplerate);

new_path += audioProcessor.drumkit->kit_name;
new_path += "-";
new_path += srate;

File source_dir (audioProcessor.drumkit->kit_dir);
File dest_dir (new_path);

std::string kitfname = "/drumkitq.txt";

audioProcessor.drumkit->adapt_qkit (new_path);

audioProcessor.scanner.scan();
update_kits_list();

audioProcessor.drumkit_path = new_path + kitfname;

tmr_leds.stopTimer();

audioProcessor.load_kit (audioProcessor.drumkit_path);

//update GUI
load_kit();

log (audioProcessor.drumkit->kit_name);
log (bytes_to_file_size (audioProcessor.drumkit->total_samples_size()));

tmr_leds.startTimer (1000 / 15); //15 FPS
}


Expand Down
6 changes: 6 additions & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,13 @@ class CAudioProcessorEditor: public juce::AudioProcessorEditor,
void load_kit(); //call after processor's load_kit to update GUI
void log (const std::string &s);
void update_kits_list();

void adapt();

void adapt_drumlabooh();
void adapt_qdrumlabooh();


void save_quick_kit();

void paint (juce::Graphics&) override;
Expand Down
93 changes: 86 additions & 7 deletions Source/kits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,94 @@ void CDrumKit::adapt() //used at Adapt button handler

delete writer;
}

}

}
}


void CDrumKit::adapt_qkit (std::string new_dir_path) //used at Adapt button handler
{
if (sample_counter == 0)
return;

if (kit_type != KIT_TYPE_QDRUMLABOOH)
return;

// std::cout << "CDrumKit::total_samples_size() - 1\n";

std::string result;

std::filesystem::create_directories (new_dir_path);

for (size_t i = 0; i < 36; i++)
{
CDrumSample *s = a_samples[i];

if (! s)
continue;

if (s->v_layers.size() == 0)
continue;


if (s->v_layers[0]->audio_buffer)
{
juce::File fl (s->v_layers[0]->file_name);

std::string pure_fname = fl.getFileName().toStdString();

fl = new_dir_path + "/" + pure_fname;

s->v_layers[0]->file_name = fl.getFullPathName().toStdString();

result += pure_fname;
result += "=";
result += pure_fname;
result += "\n";

juce::OutputStream *fs = new juce::FileOutputStream (fl); //will be deleted by writer?

juce::AudioFormatWriter *writer = 0;

std::string ext = get_file_ext (s->v_layers[0]->file_name);
ext = string_to_lower (ext);

if (ext == "wav")
writer = WavAudioFormat().createWriterFor (fs, s->v_layers[0]->samplerate,
1, //channels
32,//int bitsPerSample,
StringPairArray(),
0);

if (ext == "aiff")
writer = AiffAudioFormat().createWriterFor (fs, s->v_layers[0]->samplerate,
1, //channels
32,//int bitsPerSample,
StringPairArray(),
0);

if (ext == "flac")
writer = FlacAudioFormat().createWriterFor (fs, s->v_layers[0]->samplerate,
1, //channels
24,//int bitsPerSample,
StringPairArray(),
0);


if (! writer)
return;

if (! writer->writeFromAudioSampleBuffer (*s->v_layers[0]->audio_buffer, 0, s->v_layers[0]->audio_buffer->getNumSamples()))
std::cout << "NO write!\n";

delete writer;
}

}


string_save_to_file (new_dir_path + "/drumkitq.txt", result);


}

Expand Down Expand Up @@ -1717,7 +1801,6 @@ void CDrumKit::save_qkit()
{
result += "#EMPTY\n";

std::cout << "#EMPTY\n";


continue;
Expand All @@ -1726,21 +1809,17 @@ void CDrumKit::save_qkit()
if (s->v_layers.size() == 0)
continue;

std::cout << "AAAA!\n";

std::string line;

if (s->v_layers[0]->audio_buffer)
{
std::cout << "BBBB!\n";


line = s->name;
line += "=";
line += s->v_layers[0]->file_name;
line += "\n";

std::cout << "line: " << line << std::endl;

result += line;
}
Expand Down
1 change: 1 addition & 0 deletions Source/kits.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class CDrumKit
void print_stats();

void adapt(); //for Adapt function
void adapt_qkit (std::string new_dir_path); //for Adapt function

void save_qkit();

Expand Down

0 comments on commit 488f127

Please sign in to comment.