Arduino midi in merge

I would like to know whether this would be at all possible using only an Arduino, however I am aware this could be done with an extra merge box but they are expensive and are another box to power/carry around etc.

I would like to have an incoming midi stream ( over midi jack ) to be merged with a stream generated by an Arduino sketch ( cc values primarily ) and output over a single output jack to a synth.

any ideas? First research suggests an Arduino mega because they have more serial ports? I wont lie I’m a bit lost.