juce_Sampler: Assigning different sounds to each note


#1

I want to assign a different Sound to each midi note pressed;

I have 72 different Sounds.

So I load 72 voices:

for(unsigned int i = 0; i < 72; ++i) synth.addVoice (new SamplerVoice());

Then I add some sounds to the Synthesizer:

for(unsigned int i = 0; i < 72; ++i) BigInteger note; note.setRange(i, i, true); synth.addSound (new SamplerSound ("ogg sound", *audioReader, note, i, // root midi note 0.1f, // attack time 0.1f, // release time 10.0 // maximum sample length ));

Actual code:

[code]//Load files into memory
bool JlethalAudioProcessor::LoadOggSamples (const char* path)
{
synth.clearVoices();
synth.clearSounds();

for(unsigned int i = 0; i < 72; ++i)
	synth.addVoice (new SamplerVoice()); 

synth.clearSounds();

for(int i = 0; i < 72; ++i)
{
	char filename[256];
	sprintf(filename, "%s\\%s\\%i.ogg", File::getCurrentWorkingDirectory().getFullPathName(), path, i+1, i+1);
	//MessageBox(0, filename, "", MB_OK | MB_TOPMOST);
	loadOggFile(juce::File(filename), i);
}
return true;

}

bool JlethalAudioProcessor::loadOggFile (const File& sourceFile, int i)
{
ScopedPointer inputStream (sourceFile.createInputStream());

if (inputStream != nullptr)
{
	ScopedPointer<AudioFormatReader> audioReader (OggVorbisAudioFormat().createReaderFor (inputStream, true));
    
    if (audioReader != nullptr)
    {
		BigInteger note;
		note.setRange(i, i, true);
		synth.addSound (new SamplerSound ("ogg sound",
										*audioReader,
										note,
										i,   // root midi note
										0.1f,  // attack time
										0.1f,  // release time
										10.0  // maximum sample length
										));
		inputStream.release();

		return true;
    }
}

return false;

}[/code]

I assume this should map the sounds across the midi keyboard scale… but it doesnt seem to do so? Am I doing this correctly?


#2

try looking at SynthesiserSound::appliesToNote.