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.
WaveNet: A generative model for raw audio
WaveGAN Sound Examples
What Is MIDI? How To Use the Most Powerful Tool in Music
Markov Music Demo using monome grid & Max/MSP