コード例 #1
0
        private void ProcessMidi(string midifile)
        {
            var songMidi = Tools.NemoLoadMIDI(midifile);

            if (songMidi == null)
            {
                Log("Error parsing MIDI file ... can't analyze contents");
                return;
            }
            for (var i = 0; i < songMidi.Events.Tracks; i++)
            {
                if (Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()).ToLowerInvariant().Contains("real_guitar_22"))
                {
                    Song.ProGuitar22 = true;
                }
                else if (Tools.GetMidiTrackName(songMidi.Events[i][0].ToString()).ToLowerInvariant().Contains("real_bass_22"))
                {
                    Song.ProBass22 = true;
                }
            }
        }
コード例 #2
0
        private void btnBundle_Click(object sender, EventArgs e)
        {
            if (!File.Exists(orig_midi))
            {
                Log("MIDI file " + Path.GetFileName(orig_midi) + " is missing! Did you just delete it?");
                MIDIFixFailed(orig_midi, false);
                return;
            }
            if (!File.Exists(orig_dta))
            {
                Log("DTA file " + Path.GetFileName(orig_dta) + " is missing! Did you just delete it?");
                MIDIFixFailed(orig_dta, false);
                return;
            }

            newMIDI = Path.GetDirectoryName(orig_midi) + "\\" + Path.GetFileNameWithoutExtension(orig_midi) + " (bundled).mid";
            newDTA  = Path.GetDirectoryName(orig_dta) + "\\" + Path.GetFileNameWithoutExtension(orig_dta) + " (bundled).dta";
            var skip_tracks = ignoreNoninstrumentTracks.Checked ? new List <string> {
                "EVENTS", "VENUE", "BEAT"
            } : new List <string>();

            var midi = Tools.NemoLoadMIDI(orig_midi);

            if (midi == null)
            {
                MIDIFixFailed(orig_midi);
                return;
            }

            var harm1 = false;
            var harm2 = false;
            var harm3 = false;

            foreach (var UpgMidi in UpgradeMidis)
            {
                if (!File.Exists(UpgMidi))
                {
                    Log("Upgrade MIDI file " + Path.GetFileName(UpgMidi) + " is missing! Did you just delete it?");
                    continue;
                }
                var upgrade = Tools.NemoLoadMIDI(UpgMidi);
                if (upgrade == null)
                {
                    MIDIFixFailed(UpgMidi);
                    return;
                }
                Tools.DeleteFile(newMIDI);
                Tools.DeleteFile(newDTA);
                var origtracks = new List <string>();
                //check which tracks are in original midi
                for (var i = 0; i < midi.Events.Tracks; i++)
                {
                    var trackname = Tools.GetMidiTrackName(midi.Events[i][0].ToString());
                    if (!origtracks.Contains(trackname) && !skip_tracks.Contains(trackname))
                    {
                        origtracks.Add(trackname);
                    }
                }
                var upgtracks = new List <string>();
                //check what tracks are in the upgrade midi
                //skip track 0 = tempo track
                for (var i = 1; i < upgrade.Events.Tracks; i++)
                {
                    var trackname = Tools.GetMidiTrackName(upgrade.Events[i][0].ToString());
                    if (trackname.Contains("HARM1") || trackname.Contains("VOCALS"))
                    {
                        harm1 = true;
                    }
                    else if (trackname.Contains("HARM2"))
                    {
                        harm2 = true;
                    }
                    else if (trackname.Contains("HARM3"))
                    {
                        harm3 = true;
                    }
                    if (!upgtracks.Contains(trackname) && !skip_tracks.Contains(trackname))
                    {
                        upgtracks.Add(trackname);
                    }
                }
                if (overwriteExistingTrack.Checked) //only remove if checked to overwrite
                {
                    var to_remove = new List <int>();
                    for (var i = 0; i < midi.Events.Tracks; i++)
                    {
                        var trackname = Tools.GetMidiTrackName(midi.Events[i][0].ToString());
                        if (upgtracks.Contains(trackname))
                        {
                            to_remove.Add(i); //remove only if found in the upgrade midi and overwrite is checked
                        }
                    }
                    to_remove.Sort();
                    for (var i = to_remove.Count - 1; i >= 0; i--)
                    {
                        var trackname = Tools.GetMidiTrackName(midi.Events[to_remove[i]][0].ToString());
                        try
                        {
                            midi.Events.RemoveTrack(to_remove[i]);
                        }
                        catch (Exception ex)
                        {
                            Log("There was an error deleting track " + trackname);
                            Log("Error: " + ex.Message);
                        }
                    }
                }
                var rbhp_xkeys = false;
                var rbhp_ekeys = false;
                //combine upgrade with original
                for (var i = 0; i < upgrade.Events.Tracks; i++)
                {
                    var trackname = Tools.GetMidiTrackName(upgrade.Events[i][0].ToString());
                    if (!upgtracks.Contains(trackname) || (origtracks.Contains(trackname) && onlyAddNewTracks.Checked))
                    {
                        continue;
                    }
                    try
                    {
                        if (trackname.Contains("KEYS_X"))
                        {
                            if (!rbhp_xkeys)
                            {
                                midi.Events.AddTrack(upgrade.Events[i]);
                            }
                            rbhp_xkeys = true; //sometimes rbhp uses two pro keys x tracks for whatever reason, only add one
                            continue;
                        }
                        if (trackname.Contains("KEYS_E"))
                        {
                            if (!rbhp_ekeys)
                            {
                                midi.Events.AddTrack(upgrade.Events[i]);
                            }
                            rbhp_ekeys = true; //sometimes rbhp uses two pro keys e tracks for whatever reason, only add one
                            continue;
                        }
                        midi.Events.AddTrack(upgrade.Events[i]);
                    }
                    catch (Exception ex)
                    {
                        Log("There was an error processing the upgrade MIDI file");
                        Log("Error: " + ex.Message);
                    }
                }
            }
            try
            {
                MidiFile.Export(newMIDI, midi.Events);
            }
            catch (Exception ex)
            {
                Log("There was an error exporting the combined MIDI file");
                Log("Error: " + ex.Message);
            }
            if (File.Exists(newMIDI))
            {
                Log("Combined MIDI files successfully");
            }
            else
            {
                Log("There was an error creating the combined MIDI file");
                return;
            }
            if (string.IsNullOrWhiteSpace(orig_con))
            {
                Log("Process completed successfully");
                Log("Bundled MIDI file can be found in:");
                Log(newMIDI);
                return;
            }
            if (!string.IsNullOrWhiteSpace(newsongdta) && File.Exists(newsongdta))
            {
                Log("Replacing original songs.dta with RBHP songs.dta file");
                orig_dta = newsongdta; //if we got RBHP dta, completely replace original one
            }
            if (!string.IsNullOrWhiteSpace(newupgdta) && File.Exists(newupgdta))
            {
                Log("Merging upgrades.dta information into songs.dta file");
                var sr         = new StreamReader(orig_dta, Encoding.Default);
                var sw         = new StreamWriter(newDTA, false, Encoding.Default);
                var doneTuning = false;
                //first pass, replace values if already present
                while (sr.Peek() > 0)
                {
                    var line = sr.ReadLine();
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        if (line.Contains("rank"))
                        {
                            sw.WriteLine(line);
                            while (line != null && !line.Contains("format"))
                            {
                                line = sr.ReadLine();
                                if (string.IsNullOrWhiteSpace(line))
                                {
                                    continue;
                                }
                                if (line.Contains("bass") && !line.Contains("real_bass"))
                                {
                                    sw.WriteLine(line);
                                    sw.WriteLine(probassdiff);
                                    line = "";
                                }
                                else if (line.Contains("guitar") && !line.Contains("real_guitar"))
                                {
                                    sw.WriteLine(line);
                                    sw.WriteLine(proguitardiff);
                                    line = "";
                                }
                                else if (line.Contains("real_guitar") || line.Contains("real_bass"))
                                {
                                    line = "";
                                }
                                if (!string.IsNullOrWhiteSpace(line))
                                {
                                    sw.WriteLine(line);
                                }
                            }
                        }
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        if (line.Contains("real_guitar") || line.Contains("real_bass"))
                        {
                            line = "";
                        }
                        else if (line.Contains(";The following values"))
                        {
                            sw.WriteLine(proguitartuning);
                            sw.WriteLine(probasstuning);
                            doneTuning = true;
                        }
                        else if (line == ")" && !doneTuning)
                        {
                            if (sr.Peek() <= 0)
                            {
                                sw.WriteLine(proguitartuning);
                                sw.WriteLine(probasstuning);
                            }
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        sw.WriteLine(line);
                    }
                }
                sr.Dispose();
                sw.Dispose();
                if (File.Exists(newDTA))
                {
                    Log("Merged DTA information successfully");
                }
                else
                {
                    Log("There was an error merging DTA information");
                    return;
                }
            }
            else
            {
                Tools.DeleteFile(newDTA);
                File.Copy(orig_dta, newDTA);
            }
            var vocals = harm3 ? 3 : (harm2 ? 2 : (harm1) ? 1 : 0);

            if (showSongIDPrompt.Checked)
            {
                var popup = new PasswordUnlocker(songID == NA || useUpgradeID.Checked ? upgradeID : songID);
                popup.IDChanger();
                popup.ShowDialog();
                var newID = popup.EnteredText;
                popup.Dispose();
                if (!string.IsNullOrWhiteSpace(newID))
                {
                    songID = newID;
                }
            }
            else if (useUpgradeID.Checked)
            {
                songID = upgradeID;
            }
            Tools.ReplaceSongID(newDTA, songID, vocals.ToString(CultureInfo.InvariantCulture));
            Log("Creating the bundled file");
            EnableDisable(false);
            btnBundle.Visible = false;
            backgroundWorker1.RunWorkerAsync();
        }
コード例 #3
0
ファイル: MidiTester.cs プロジェクト: i0brendan0/MagmaLite2
        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();
        }