I've tried to merge 2 midi files into one, such that the second midi file will not be heard when playing the output midi file. I've managed to get a result that plays only the first song, but I wonder if there is a way to hide (encrypt) the second file with the option to recover it out of the output file.
In my way, there is no option for recovery, because all of the second song's notes are in velocity 0, so unless I write the original velocity to an external file or something like that, it's impossible to recover them.
def merge(first, second):
mid1 = MidiFile(first)
mid2 = MidiFile(second)
output = MidiFile(ticks_per_beat=mid1.ticks_per_beat, clip=mid1.clip, charset=mid1.charset, type=mid1.type)
for i, track in enumerate(mid2.tracks):
for j, msg in enumerate(mid2.tracks[i]):
try:
msg.velocity = 0
except Exception as e:
pass
output.tracks.append(track)
for i, track in enumerate(mid1.tracks):
output.tracks.append(track)
print(output.length)
output.save(filename="merged.mid")
Thank you!