What is a Midi note in Juce?

The SamplerSound class JUCE: SamplerSound Class Reference accepts

const BigInteger & *midiNotes*

BigInterger is simply a class for storing an infinite number of bits to represent a very big integer.

This is an example from a code of a drums sampler:

juce::BigInteger range;
range.setRange(0, 128, true);
        {
            std::unique_lock<std::recursive_mutex> lk{samplerMutex};
            sampler.addSound(new juce::SamplerSound("Sample", *reader, range, 60, 1, 0.7, 10.0));
        }

if I understood it correctly, it’s creating a sound that is activated by all midi sounds. However, on a MIDI message, the range of possible keys goes from 0x00 to 0x7F. A 128 bit number is much much bigger.

Can someone explain me what’s happening? Don’t I have only 0x7F keys to choose from?

bool SamplerSound::appliesToNote (int midiNoteNumber)
{
    return midiNotes[midiNoteNumber];
}

The bits are just on/off switches for the 128 available midi notes in the midi spec.

SamplerSound::SamplerSound (const String& soundName,
                            AudioFormatReader& source,
                            const BigInteger& notes,         <<<<<<<<<<<<<
                            int midiNoteForNormalPitch,
                            double attackTimeSecs,
                            double releaseTimeSecs,
                            double maxSampleLengthSeconds)
    : name (soundName),
      sourceSampleRate (source.sampleRate),
      midiNotes (notes),                                     <<<<<<<<<<<<

so if I want a sampler to have more than 13 sounds, each with 10 different pitches, it’s not possible?

The BigInteger is a bit set with 128 bools. A Midi note can represent 128 different notes afaik. This is a limitation of the MIDI messages.
A BigInteger can hold many more bits. It is not meant as a 128 bit number but a bit set to keep track of which key is down and which isn’t.

The BigInteger is a bit set to tell to which note the sound should react.

To have multiple sounds, you can create different SamplerSound objects and have the bits in the range set, where this sound shall react to.
To use a sound only the lowest two octaves you would call

range.setRange (0, 23, true);

And the next two:

range.setRange (24, 23, true);

Hope that helps.

1 Like