To implement a rather robust Markov modeler in Max/MSP we recommend the following 2 part tutorial on YouTube. It covers the use of the Markov object in the ml.star library. Going through this ourselves was fun, we definitely had to pause a lot to double check the patching. After you are done you will have built a patch that can merge, mash up and generate MIDI.
We also offer a pre-built patch here. There is a PDF available here that covers how to use it.
For more info on digital audio data and digital signal processing the link below is an excellent resource to bookmark.
SEEING CIRCLES, SINES, AND SIGNALS: A Compact Primer on Digital Signal Processing
WaveNet: A generative model for raw audio
https://deepmind.com/blog/article/wavenet-generative-model-raw-audio
WaveGAN Sound Examples
https://chrisdonahue.com/wavegan_examples/
What Is MIDI? How To Use the Most Powerful Tool in Music
Markov Music Demo using monome grid & Max/MSP
Some free MIDI file resources
http://www.piano-midi.de/midi_files.htm
https://beatmodo.com/free-midi-files/