BigInteger and midiNotes constructor for SamplerSound, correct way for one note?


I’m having trouble getting the SamplerSound class to behave as intended. I see the sampler sound takes a BigInteger for the range of midiNotes it is able to play. It then does a bit check in appliesToNote. Apologies if this is a c++ noob question.

return midiNotes[midiNoteNumber];

So if I set the range to be valid across 0-126. It will play on any midi note fine. What is unclear to me is how to specify one key?

So far I have tried,

BigInteger test;
test.setBit(64) // test 1
test.setRange(64,64,true); // test2

I think I am just misunderstanding how this is supposed to work and can’t find a clear explanation as neither of these result in the note only being played on MidiNote 64. What BigInteger value would I specify to represent key 64?

As a workaround, I overwrote SamplerSound class and created my own appliesToNote function with a simple integer comparison.

if(midiNoteToBePlayed == midiNote) {
            return true;
        return false;


setBit (64) definitely sets bit 64, and midiNotes[64] will definitely return true.

You could have seen that for yourself by doing:

    BigInteger b;
    jassert (b[64]);

…which would have shown that SamplerSound::appliesToNote clearly wasn’t looking at the same set of bits you thought you were giving it. And by debugging the appliesToNote function and looking at the BigInteger it has at that point, you could check that. Probably you just did something silly like passing a different BigInteger into the constructor.


BigInteger didn’t seem to be thread safe when I used it.



No, it’s not, but the one inside the SamplerSound is just initialised in the constructor and used read-only after that. I don’t think you can hit any race conditions with the way it’s used there.


Yeah, I think I was trying to copy it to a different SamplerSound or update the note(s)… and that failed. Since I only needed a single note, I created a separate atomic int to hold the MIDI note instead.




Ya I actually stopped the debugger and saw it return true. I should have been more explicit. When I set it, more keys than just 64 worked so it seemed it was setting other values as well.


Well yes, you said you were calling setRange (64, 64), which would set 64 bits to true


Yea I think I must’ve goofed when using the setBit exclusively. I retested it and have it working as intended. Thanks for your help. BigInteger and bitmasking for key/value comparison was a new concept for me.