Skip to content

Commit

Permalink
Fix bugs in samplers (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
stonepreston authored Jun 4, 2022
1 parent 06543d4 commit 148c9d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ DrumSamplerViewModel::DrumSamplerViewModel(
itemListState.listSize = drumKitNames.size();

if (drumKitNames.size() > 0) {
DBG("current kit index: " +
std::to_string(itemListState.getSelectedItemIndex()));
juce::File currentMap = mapFiles[itemListState.getSelectedItemIndex()];
readMappingFileIntoSampler(currentMap,
samplerPlugin->getNumSounds() <= 0);
readMappingFileIntoSampler(currentMap, true);
DBG("updating thumb");
updateThumb();
}
Expand Down Expand Up @@ -52,6 +53,10 @@ void DrumSamplerViewModel::valueTreePropertyChanged(
void DrumSamplerViewModel::readMappingFileIntoSampler(
const juce::File &mappingFile, bool shouldUpdateSounds) {
drumSampleFiles.clear();
for (int i = 0; i < samplerPlugin->getNumSounds(); i++) {
samplerPlugin->removeSound(i);
}

YAML::Node rootNode =
YAML::LoadFile(mappingFile.getFullPathName().toStdString());
const auto kitDir =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ SynthSamplerViewModel::SynthSamplerViewModel(
jassert(error.isEmpty());
}

const auto file = files[0];
const auto file = files[itemListState.getSelectedItemIndex()];
auto *reader = formatManager.createReaderFor(file);
if (reader != nullptr) {
// This must be set in order for the plugin state to be loaded in
// correctly if the sound already existed (ie the number of sounds was >
// 0)
samplerPlugin->setSoundMedia(0, file.getFullPathName());
samplerPlugin->setSoundMedia(selectedSoundIndex.get(),
file.getFullPathName());

std::unique_ptr<juce::AudioFormatReaderSource> newSource(
new juce::AudioFormatReaderSource(reader, true));
Expand Down

0 comments on commit 148c9d6

Please sign in to comment.