Adding instrument in synthesiser


#1

I am making a small MIDI file player using the Juce synthesiser and I want to be able to play several instruments (using separate midi channels). Should I modify the SamplerSound::appliesToChannel method or did I miss something in the code which I could use to know which sounds should be played ?

Thanx.


#2

I think the most direct way is to make sub-classes of SamplerSound, one for each channel, and over-ride the appliesToChannel method.  Someone might want to confirm that, it's a while since i played with it!


#3

@bazrush: thx for you reply.

This is how I did it. Seems to work fine:

class AGSounds : public SamplerSound

{

public:
    mySounds (const String& soundName,
               AudioFormatReader& source,
               const BigInteger& notes,
               const int midiNoteForNormalPitch,
               const double attackTimeSecs,
               const double releaseTimeSecs,
               const double maxSampleLengthSeconds) : SamplerSound (soundName, source, notes, midiNoteForNormalPitch, attackTimeSecs, releaseTimeSecs, maxSampleLengthSeconds)

    {
    }

    bool appliesToChannel (const int midiChannel) override {
        String soundName;
        if ((soundName == "GPiano sound") && (midiChannel == 1))
            return true;
        if ((soundName == "Drums sound") && (midiChannel == 10))
            return true;
        if ((soundName == "Bass sound") && (midiChannel == 2))
            return true;
        return false;
    }
  
};