The Teensy MIDI page shows how to use 74HC4051 (8:1 multiplexer); the 74HC4067 (16:1 multiplexer) is otherwise similar, but uses four address lines instead of three. Both seem to be available at typical stores (Digikey, Mouser, LCSC) at less than a dollar/euro apiece.
However, the MCP23017 MichaelMeissner suggested is in many ways superior, because you only need to connect four pins (I2C SCL, I2C SDA, 3.3V, and GND) for up to 128 buttons (8 MCP23017 chips). It too seems to be available at those same stores, at about a dollar/euro apiece, or slightly over.
The idea is that instead of using digitalReadFast() to obtain the button states, you communicate with the MCP23017 chips using I2C, using the Wire library. Essentially, after you setup the Wire and initialize the chip, to check the button states you do
Code:
uint8_t b0to7, b8to15;
Wire.begintransmission(32 + address); /* address = 0..7, depending on MCP23017 A0,A1,A2 pins */
Wire.write(0x12);
Wire.requestfrom(32 + address, 2); /* Same as above! */
if (Wire.available() > 0) {
b0to7 = Wire.read();
if (Wire.available() > 0)
b8to15 = Wire.read();
}
Wire.endtransmission();
for each chip, to get the first 8 button states in b0to7, and the second 8 button states in b8to15, for that particular chip.
There is also a SPI version of the same chip, MCP23S17, which is used in a very similar way, except with the SPI bus (and SPI library). (I didn't know this chip existed, only found out about it in the MCP23017 datasheet!)
This chip is interesting in that if one wants to isolate the button circuits, it is rather easy to do with say an ADuM1401 and an isolated DC-DC converter (to supply current to the button circuits). I don't know why anyone would need to isolate the button circuits from the microcontroller, but with this chip it is quite cheap (< $10) and simple. (Each MCP23s17 needs their own chip select pin, so to use multiple chips, you need more isolated channels. With a Si8661, you can use three MCP23s17 chips, for a total of 48 isolated buttons/digital inputs.)
Depending on your use case, you may also wish to debounce the buttons in software.