TLDR: My advice: if you want to use 4 players + trackball on a raspberry pi, buy an iPac 4 and use it in keyboard encoder mode. Do not use consoles in a cabinet, only use MAME or similar. If you don't care about RetroPie's overlay system, just use AttractMode and MAME .78. IF you want RetroPie's overlay stuff, use Mame2003 Plus.
More details:
With regard to arcade cabinets: there are a few things to keep in mind with the RetroPie / Libretro ecosystem. It is VERY MUCH geared towards GAMEPAD use rather than a keyboard and expects to see one gamepad/encoder per person. If you are used to the MAME configuration method of freely mapping whatever control you want to whatever input you want, you'll hate the RetroPie way... there are a lot of layers for mapping controls, and every one of them is annoying. If you don't intend to use GamePads... my advice is to avoid consoles in RetroPie and just use Mame2003-Plus, or skip RetroPie completely and just use AttractMode with a compiled vanilla stand-alone version of MAME.
That said, this only matters IF you are using anything OTHER than MAME or similarly configured emulators. If you want to mix consoles and arcade games in a cabinet, then it'll be a challenge to make them all work together nicely. Using 1 encoder per person is probably the most straightforward method for this. Keep in mind that RetroPie makes ONE configuration PER gamepad type. So if you have 4 encoders and plan to have player 2 use slightly different controls than player 1... it won't work in RetroPie's configuration if all the encoders are the same brand.
OK. So, assuming you're using a keyboard encoder, like an iPad in keyboard mode, or an Ultimate IO in keyboard mode, then managing 4 players in MAME is pretty simple and standard. You will need to use Mame2003 Plus or Mame2016, as Mame2010 is garbage in RetroPie, and doesn't provide access to the tab menu very well for some things. It's not great and should not be made available. If you try to use the encoder in gamepad mode, please note that some of the emulators will not let you configure more than 14 inputs per encoder.
The last thing to keep in mind, if you are going to be using 4 of the same encoder, you'll likely need to make sure they have some kind of unique ID per encoder, otherwise, if you plug them into a hub, they may get swapped at startup. There's a method to tell RetroPie which encoder belongs to which player, but it's not straightforward. IF you don't use a hub and plug them straight into the Pi, then they'll load consistently based on the USB spot they're plugged into.
So basically, read the part where I said "TLDR" above. I have a console version of a Raspberry PI/RetroPie that uses gamepads, and it's pretty awesome. But while trying to accomplish lots of the same things in a cabinet that I'd done on the console version was possible, it was very annoying. Keeping it simple, will be much more satisfying. Avoid mixing classic arcade stuff with console stuff and you'll be fine.