Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
trying to merge two midi files together so that the note events and track events of each midi file play in sequence. That is, play the first note in the first midi file. Then play the first note in the second midi file. Then play the second note in the first midi file. Then the second note in the second midi file. and so on and so forth.

Currently using drywetmidi but I am not sold on this midi package and if there is another one more suitable to this task I will be happy to try.

What I have tried:

So far the best I have been able to do is read a midi file and creating an (empty) midi file with the following code:

private void button1_Click(object sender, EventArgs e)
{
var midiFile = MidiFile.Read(midFilIn0);
try
{
midiFile.Write(midFilOut);
}
catch (IOException ioExp)
{
var midi = MidiFile.Read("f:\\Midi Files\\My Future Great Song.mid");

var outputDevice = OutputDevice.GetByName("Microsoft GS Wavetable Synth");

_playback = midi.GetPlayback(outputDevice);
_playback.Start();

SpinWait.SpinUntil(() => !_playback.IsRunning);
MessageBox.Show(ioExp.ToString());
File.Delete(midFilOut);
midiFile.Write(midFilOut);
}
}

All this does, however, is open a midi file and creating an (empty) midi file and does not make a copy of anything. Once I figure out how to create a copy of the file, then I can simply open the second file and merge it with the first.

Any help will be greatly appreciated.
Posted
Updated 22-Jun-22 6:25am

1 solution

See this CodeProject article and search for "Merge":
Midi: A Windows MIDI Library in C#[^]
 
Share this answer
 
Comments
Member 14810577 22-Jun-22 15:01pm    
Thank you for your answer but neither the article nor the program mentions anything about merge. What are you talking about? Can you show me specific code?
Member 14810577 22-Jun-22 15:20pm    
Ah. Tried merging two midi files and what that does is append the second midi file to the first file. This is not what I am looking for. I want to take the first note of each file and then write them to a third file. Then take the second note of each file and write them to the same third file. Then take the third, fourth, fifth.... and all write them in the original sequence to the third file so you get a unique new composition. Not two compositions played back to back.
RickZeeland 22-Jun-22 15:24pm    
I never used this library, but you can try to ask the author of the article for more information. Good luck ;)
Member 14810577 22-Jun-22 21:16pm    
Thanks for trying. Your help is still appreciated. And it did get me closer to a solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900