private void ReadMidi(string file) { startTime = DateTime.Now; testfolder = Application.StartupPath + "\\test\\"; originalpath = file; MIDIfile = testfolder + Path.GetFileName(file); btnCleaner.Visible = false; Tools.DeleteFolder(testfolder, true); if (!Directory.Exists(testfolder)) { Directory.CreateDirectory(testfolder); } try { File.Copy(file, MIDIfile); } catch (Exception) { MIDIfile = file; } var songMidi = Tools.NemoLoadMIDI(MIDIfile); if (songMidi == null) { Log("Failed to load MIDI file " + Path.GetFileName(MIDIfile) + "."); EndProcess(); return; } Log("\n"); ProjectFile = new ProjectFile(); ProjectDefaults(); for (var i = 0; i < songMidi.Events.Tracks; i++) { if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("drums")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("drum_kit").Enabled) { var track = new TrackInfo(SilenceStereo44, "drum_kit", 0, 0, true); ProjectFile.SetTrack(track); } foreach (var drummix in from notes in songMidi.Events[i] where notes.CommandCode == MidiCommandCode.MetaEvent select(MetaEvent) notes into mixevent where mixevent.ToString().Contains("mix") && mixevent.ToString().Contains("drums") select mixevent.ToString() into drummix select drummix.Substring(drummix.Length - 1, 1)) { switch (drummix) { case "0": Log("Found standard drum mix event."); break; case "1": case "2": case "3": Log("Found non-standard drum mix event ... make sure you have the right audio files."); break; } break; } } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("guitar")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("guitar").Enabled) { var track = new TrackInfo(SilenceStereo44, "guitar", 0, 0, true); ProjectFile.SetTrack(track); } if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("real_guitar")) { HasProGuitar = true; } } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("bass")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("bass").Enabled) { var track = new TrackInfo(SilenceStereo44, "bass", 0, 0, true); ProjectFile.SetTrack(track); } if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("real_bass")) { HasProBass = true; } } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("keys")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (ProjectFile.GetTrack("keys").Enabled) { continue; } var track = new TrackInfo(SilenceStereo44, "keys", 0, 0, true); ProjectFile.SetTrack(track); } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("vocals")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("vocals").Enabled) { var track = new TrackInfo(SilenceStereo44, "vocals", 0, 0, true); ProjectFile.SetTrack(track); } foreach (var vocal_event in songMidi.Events[i].Where(notes => notes.CommandCode == MidiCommandCode.MetaEvent).Cast <MetaEvent>()) { if (vocal_event.ToString().Contains("[clap")) { ProjectFile.Percussion = "handclap"; Log("Found vocal percussion: hand clap."); break; } if (vocal_event.ToString().Contains("[cowbell")) { ProjectFile.Percussion = "cowbell"; Log("Found vocal percussion: cowbell."); break; } if (!vocal_event.ToString().Contains("[tambourine")) { continue; } ProjectFile.Percussion = "tambourine"; Log("Found vocal percussion: tambourine."); break; } } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("harm1")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("vocals").Enabled) { var track = new TrackInfo(SilenceStereo44, "vocals", 0, 0, true); ProjectFile.SetTrack(track); } ProjectFile.DryVoxFile = BlankDryvox; } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("harm2")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("vocals").Enabled) { var track = new TrackInfo(SilenceStereo44, "vocals", 0, 0, true); ProjectFile.SetTrack(track); } ProjectFile.DryVoxHarmony2File = BlankDryvox; } else if (songMidi.Events[i][0].ToString().ToLowerInvariant().Contains("harm3")) { Log("Found " + Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()) + "..."); if (!ProjectFile.GetTrack("vocals").Enabled) { var track = new TrackInfo(SilenceStereo44, "vocals", 0, 0, true); ProjectFile.SetTrack(track); } ProjectFile.DryVoxHarmony3File = BlankDryvox; } } if (!HasInstruments()) { Log("No instrument charts were found in the MIDI file."); Log("Can't continue without at least one instrument chart."); Log("Stopping here."); EndProcess(); return; } if (!Tools.MidiIsClean(ProjectFile.MidiFile, ProjectFile.GetTrack("keys").Enabled, HasProBass || HasProGuitar)) { Log("\nFound errors in the MIDI file:"); Log(Tools.MIDI_ERROR_MESSAGE.Substring(1, Tools.MIDI_ERROR_MESSAGE.Length - 1)); btnCleaner.Visible = true; Log("Stopping here."); EndProcess(); return; } Log(Tools.MIDIAutoGen(ProjectFile.MidiFile, "[mix # drums0]", false, false, ProjectFile.GetTrack("drum_kit").Enabled, true)); Tools.DoesMidiHaveEMH(ProjectFile.MidiFile); Log(Tools.MIDI_ERROR_MESSAGE); Log("Ready to send files to MagmaCompiler ... hold on."); Tools.RemovePSDrumsXNotes(ProjectFile.MidiFile); if (Tools.CheckMIDIFor2X(ProjectFile.MidiFile)) { if (!Tools.Separate2XMidi(ProjectFile.MidiFile)) { SendtoCompiler(); return; } Log("MIDI file contains 2X Bass Pedal track."); Log("MIDI Will be tested twice, once with each drum track enabled."); Log("Testing standard MIDI..."); ProjectFile.MidiFile = Tools.MIDI1X; SendtoCompiler(); Log("Testing 2X Bass Pedal MIDI..."); ProjectFile.MidiFile = Tools.MIDI2X; SendtoCompiler(); } else { SendtoCompiler(); } EndProcess(); }