Ejemplo n.º 1
0
        private void SequenceImportButton_Click(object sender, RoutedEventArgs e)
        {
            bool chplay = false;

            if (!Stop && Playing)
            {
                chplay             = true;
                PlayButton.Content = new PackIcon
                {
                    Kind = PackIconKind.Play
                };
                Playing = !Playing;
            }
            OpenFileDialog od = new OpenFileDialog
            {
                Title       = "Replace sound sequence",
                Filter      = "MIDI audio|*.mid|Nitro Sound Sequence (SSEQ)|*.sseq",
                Multiselect = false,
            };

            if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string ext  = Path.GetExtension(od.FileName);
                string sseq = "";
                if (ext.EndsWith("sseq"))
                {
                    sseq = od.FileName;
                }
                else if (ext.EndsWith("mid"))
                {
                    string        fname = Path.GetFileNameWithoutExtension(od.FileName);
                    MIDIConverter cvtr  = ROMUtils.DetermineConverter();
                    if (cvtr == MIDIConverter.Invalid)
                    {
                        Utils.ShowMessage("No MIDI conversion tool was found.");
                        return;
                    }
                    else if (cvtr == MIDIConverter.MIDI2SSEQ)
                    {
                        string midi2sseq = ROMUtils.GetExePath() + "\\midi2sseq.exe";
                        var    p         = new Process
                        {
                            StartInfo = new ProcessStartInfo
                            {
                                FileName        = midi2sseq,
                                Arguments       = "\"" + od.FileName + "\"",
                                UseShellExecute = false,
                                CreateNoWindow  = true,
                            }
                        };
                        p.Start();
                        p.WaitForExit();
                        if (!File.Exists(ROMUtils.GetExePath() + "\\" + fname + ".sseq"))
                        {
                            Utils.ShowMessage("Unable to convert MIDI audio to SSEQ.");
                            if (chplay)
                            {
                                PlayButton.Content = new PackIcon
                                {
                                    Kind = PackIconKind.Pause
                                };
                                Playing = !Playing;
                            }
                            return;
                        }
                        sseq = ROMUtils.GetExePath() + "\\" + fname + ".sseq";
                    }
                    else if (cvtr == MIDIConverter.SmfSeqConv)
                    {
                        string smfconv = ROMUtils.GetExePath() + "\\smfconv.exe";
                        string seqconv = ROMUtils.GetExePath() + "\\seqconv.exe";
                        var    p       = new Process
                        {
                            StartInfo = new ProcessStartInfo
                            {
                                FileName        = smfconv,
                                Arguments       = "\"" + od.FileName + "\"",
                                UseShellExecute = false,
                                CreateNoWindow  = true,
                            }
                        };
                        p.Start();
                        p.WaitForExit();
                        string basenoext = Path.GetDirectoryName(od.FileName) + "\\" + fname;
                        if (!File.Exists(basenoext + ".smft"))
                        {
                            Utils.ShowMessage("Unable to generate SMFT from MIDI audio.");
                            if (chplay)
                            {
                                PlayButton.Content = new PackIcon
                                {
                                    Kind = PackIconKind.Pause
                                };
                                Playing = !Playing;
                            }
                            return;
                        }
                        var p2 = new Process
                        {
                            StartInfo = new ProcessStartInfo
                            {
                                FileName        = seqconv,
                                Arguments       = "\"" + basenoext + ".smft\"",
                                UseShellExecute = false,
                                CreateNoWindow  = true,
                            }
                        };
                        p2.Start();
                        p2.WaitForExit();
                        if (!File.Exists(basenoext + ".sseq"))
                        {
                            Utils.ShowMessage("Unable to generate SSEQ from SMFT data.");
                            if (chplay)
                            {
                                PlayButton.Content = new PackIcon
                                {
                                    Kind = PackIconKind.Play
                                };
                                Playing = false;
                                Stop    = true;
                            }
                            return;
                        }
                        File.Delete(basenoext + ".smft");
                        sseq = basenoext + ".sseq";
                    }
                }
                Data.FileAllocationTable.Entries[(int)Data.InfoBlock.SequenceInfos[MKDS.Sequences[SequencesCombo.SelectedIndex]].FileId].Data = File.ReadAllBytes(sseq);
                Reload();
                if (ext.EndsWith("mid"))
                {
                    File.Delete(sseq);
                }
            }
            if (chplay)
            {
                PlayButton.Content = new PackIcon
                {
                    Kind = PackIconKind.Play
                };
                Playing = false;
                Stop    = true;
            }
        }