コード例 #1
0
        private void FreeSoundFonts()
        {
            Debug.PrintToConsole("ok", "Freeing SoundFont handles...");
            foreach (BASS_MIDI_FONTEX SF in Program.SFArray.BMFEArray)
            {
                BassMidi.BASS_MIDI_FontFree(SF.font);
            }

            Debug.PrintToConsole("ok", "Handles freed.");
            Program.SFArray.BMFEArray.Clear();
        }
コード例 #2
0
ファイル: BASSControl.cs プロジェクト: walney/KMC
        public static void ReleaseResources(bool StillRendering, bool Closing)
        {
            foreach (Int32 Stream in MainWindow.VSTs._DummyVSTHandles)
            {
                BassVst.BASS_VST_ChannelRemoveDSP(0, Stream);
            }

            if (MainWindow.KMCGlobals.SoundFonts != null)
            {
                foreach (BASS_MIDI_FONTEX pr in MainWindow.KMCGlobals.SoundFonts)
                {
                    BassMidi.BASS_MIDI_FontFree(pr.font);
                }
            }

            BassVst.BASS_VST_ChannelRemoveDSP(0, MainWindow.VSTs._DummyLoudMaxHan);
            MainWindow.KMCGlobals.DoNotCountNotes = false;
            BassWasapi.BASS_WASAPI_Stop(true);
            BassWasapi.BASS_WASAPI_Free();
            Bass.BASS_StreamFree(MainWindow.KMCGlobals._recHandle);
            BassVst.BASS_VST_ChannelFree(MainWindow.VSTs._VSTiHandle);
            MainWindow.KMCStatus.IsKMCBusy         = StillRendering;
            MainWindow.KMCStatus.IsKMCNowExporting = false;
            MainWindow.KMCGlobals.eventc           = 0;
            MainWindow.KMCGlobals.events           = null;

            if (Closing)
            {
                Bass.BASS_Free();
                MainWindow.KMCGlobals.ActiveVoicesInt = 0;
                MainWindow.KMCStatus.IsKMCBusy        = false;
                MainWindow.KMCGlobals.NewWindowName   = null;
                MainWindow.KMCStatus.RenderingMode    = false;
                RTF.CPUUsage     = 0.0f;
                RTF.ActiveVoices = 0.0f;
            }
        }
コード例 #3
0
        public static ListViewItem[] AddSFToList(String[] SFs, Boolean BPO, Boolean NoErrs)
        {
            List <ListViewItem> iSFs   = new List <ListViewItem>();
            List <String>       SFErrs = new List <String>();

            int  BV = -1, PV = -1, DBV = 0, DPV = -1;
            bool XGMode = false;

            foreach (String SF in SFs)
            {
                if (Path.GetExtension(SF).ToLowerInvariant() == ".sf1" |
                    Path.GetExtension(SF).ToLowerInvariant() == ".sf2" |
                    Path.GetExtension(SF).ToLowerInvariant() == ".sfz" |
                    Path.GetExtension(SF).ToLowerInvariant() == ".sfark" |
                    Path.GetExtension(SF).ToLowerInvariant() == ".sfpack")
                {
                    // Check if it's valid
                    int       SFH = BassMidi.BASS_MIDI_FontInit(SF, BASSFlag.BASS_DEFAULT);
                    BASSError Err = Bass.BASS_ErrorGetCode();

                    // SoundFont is valid, continue
                    if (Err == 0)
                    {
                        BassMidi.BASS_MIDI_FontFree(SFH);

                        if (BPO | Path.GetExtension(SF).ToLowerInvariant() == ".sfz")
                        {
                            using (var BPOW = new BankNPresetSel(Path.GetFileName(SF), false, (BPO && Path.GetExtension(SF).ToLowerInvariant() != ".sfz"), null))
                            {
                                var RES = BPOW.ShowDialog();

                                if (RES == DialogResult.OK)
                                {
                                    BV     = BPOW.BankValueReturn;
                                    PV     = BPOW.PresetValueReturn;
                                    DBV    = BPOW.DesBankValueReturn;
                                    DPV    = BPOW.DesPresetValueReturn;
                                    XGMode = BPOW.XGModeC;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        FileInfo     file = new FileInfo(SF);
                        ListViewItem iSF  = new ListViewItem(new[]
                        {
                            SF,
                            BV.ToString(), PV.ToString(), DBV.ToString(), DPV.ToString(), XGMode ? "Yes" : "No",
                            ReturnSoundFontFormat(Path.GetExtension(SF)),
                            ReturnSoundFontSize(SF, Path.GetExtension(SF), file.Length)
                        });

                        iSF.ForeColor = SFEnabled;

                        iSFs.Add(iSF);
                    }
                    else
                    {
                        SFErrs.Add(SF);
                    }
                }
                else
                {
                    SFErrs.Add(SF);
                }
            }

            if (SFErrs.Count > 0)
            {
                if (!NoErrs)
                {
                    Program.ShowError(
                        4,
                        "Invalid SoundFont(s) detected",
                        String.Format(
                            "The following SoundFont(s) were not valid, and have not been added to the list.\n\n{0}\n\nPress OK to continue",
                            string.Join(Environment.NewLine, SFErrs.ToArray())),
                        null);
                }

                return(new ListViewItem[] { });
            }

            return(iSFs.ToArray());
        }
コード例 #4
0
        private void AddSF_Click(object sender, EventArgs e)
        {
            List <String>  SFErrs   = new List <String>();
            OpenFileDialog SFImport = new OpenFileDialog();

            SFImport.InitialDirectory = (Properties.Settings.Default.LastPathSFImport.ToLowerInvariant() == "null" ?
                                         Environment.GetFolderPath(Environment.SpecialFolder.Desktop) : Properties.Settings.Default.LastPathMIDIImport);
            SFImport.Filter      = String.Format("{0}|*.sf1;*.sf2;*.sfz;*.sf2pack;", "SoundFonts");
            SFImport.Multiselect = true;

            Debug.PrintToConsole("ok", "Spawned SFImport window.");
            if (SFImport.ShowDialog() == DialogResult.OK)
            {
                Debug.PrintToConsole("ok", "Returned OK, analyzing SoundFont(s)...");

                Properties.Settings.Default.LastPathSFImport = Path.GetDirectoryName(SFImport.FileNames[0]);
                Properties.Settings.Default.Save();

                foreach (String SF in SFImport.FileNames)
                {
                    Debug.PrintToConsole("ok", String.Format("Current SoundFont = {0}", SF));

                    // Check if valid
                    int       SFH = BassMidi.BASS_MIDI_FontInit(SF, BASSFlag.BASS_DEFAULT);
                    BASSError Err = Bass.BASS_ErrorGetCode();

                    if (Err == 0)
                    {
                        Debug.PrintToConsole("ok", "The SoundFont is valid.");

                        Int32 NotSFZ = (Path.GetExtension(SF) != ".sfz") ? -1 : 0;
                        int[] TV     = new int[] { NotSFZ, NotSFZ, 0, NotSFZ, 0, 0 };
                        BassMidi.BASS_MIDI_FontFree(SFH);

                        // Split filename in case of automatic preset/bank assign values
                        Match match = Regex.Match(Path.GetFileNameWithoutExtension(SF), @"\d{3}\.\d{3}\.\d{3}\.\d{3}\.\d{1}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            Debug.PrintToConsole("ok", "The SoundFont's name has valid bank and preset values. Parsing...");

                            String[] Values = Path.GetFileNameWithoutExtension(SF).Split('-')[0].Split('.');
                            MessageBox.Show(Values.ToString());
                            for (int i = 0; i < Values.Length && i < TV.Length; i++)
                            {
                                Int32 T = -1;
                                if (Int32.TryParse(Values[i], out T))
                                {
                                    TV[i] = T;
                                }
                            }

                            Debug.PrintToConsole("ok", "Values parsed.");
                        }

                        Debug.PrintToConsole("ok", String.Format("SFP = {0}", SF));
                        Debug.PrintToConsole("ok", String.Format("SP = {0}", TV[1]));
                        Debug.PrintToConsole("ok", String.Format("SB = {0}", TV[0]));
                        Debug.PrintToConsole("ok", String.Format("DP = {0}", TV[2]));
                        Debug.PrintToConsole("ok", String.Format("DB = {0}", TV[3]));
                        Debug.PrintToConsole("ok", String.Format("DBLSB = {0}", TV[4]));
                        Debug.PrintToConsole("ok", String.Format("XG = {0}", Convert.ToBoolean(TV[5])));
                        Debug.PrintToConsole("ok", String.Format("Enabled = {0}", true));

                        Program.SFArray.List.Add(new SoundFont(SF, TV[1], TV[0], TV[3], TV[2], TV[4], true, Convert.ToBoolean(TV[5])));
                    }
                    else
                    {
                        Debug.PrintToConsole("err", String.Format("SoundFont invalid: {0}", SF));
                        SFErrs.Add(SF);
                    }
                }

                if (SFErrs.Count > 0)
                {
                    Debug.ShowMsgBox("Invalid SoundFont(s) detected", String.Format(
                                         "The following SoundFont(s) were not valid, and have not been added to the list.\n\n{0}\n\nPress OK to continue",
                                         string.Join(Environment.NewLine, SFErrs.ToArray())), null, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                RebindList();
            }
        }
コード例 #5
0
        public SoundFontInfo(String SoundFont)
        {
            InitializeComponent();

            ERROR = false;

            // Here we go
            String   next;
            String   sf = "";
            Int32    fonthandle;
            FileInfo f;

            OriginalSF = SoundFont;

            if (SoundFont.ToLower().IndexOf('=') != -1)
            {
                sf = SoundFont.Substring(SoundFont.LastIndexOf('|') + 1);
                if (!File.Exists(sf))
                {
                    Program.ShowError(4, "Error", String.Format("The SoundFont \"{0}\" doesn't exist.", SoundFont), null);
                    ERROR = true;
                    Close();
                    return;
                }
                fonthandle = BassMidi.BASS_MIDI_FontInit(sf);
                f          = new FileInfo(sf);
                next       = sf;
            }
            else
            {
                sf = SoundFont;
                if (!File.Exists(SoundFont))
                {
                    Program.ShowError(4, "Error", String.Format("The SoundFont \"{0}\" doesn't exist.", SoundFont), null);
                    ERROR = true;
                    Close();
                    return;
                }
                fonthandle = BassMidi.BASS_MIDI_FontInit(SoundFont);
                f          = new FileInfo(SoundFont);
                next       = SoundFont;
            }

            BASS_MIDI_FONTINFO fontinfo = BassMidi.BASS_MIDI_FontGetInfo(fonthandle);

            FNBox.Text  = next;
            ISFBox.Text = ReturnName(fontinfo.name, next);
            CIBox.Text  = ReturnCopyright(fontinfo.copyright);
            SamF.Text   = String.Format("{0} ({1})", ReturnSampleType(fontinfo.samtype), fontinfo.samtype);

            if (f.Length > (long)2147483648)
            {
                SofSFLab.Font      = new Font(SofSFLab.Font, FontStyle.Bold);
                SofSFLab.ForeColor = Color.DarkRed;
                SofSFLab.Cursor    = Cursors.Help;
                SizeWarning.SetToolTip(SofSFLab, "SoundFonts bigger than 2GB may not load correctly\non 32-bit applications, cause audio corruptions or even cause loss of data!\n\nBe careful!");
            }

            if (Path.GetExtension(sf).ToLowerInvariant() == ".sfz")
            {
                SofSFLab.Text = String.Format("{0} (Samples: {1}, Presets: {2})",
                                              Functions.ReturnLength(f.Length + SFZ.GetSoundFontZSize(sf), true),
                                              Functions.ReturnLength(SFZ.GetSoundFontZSize(sf), true),
                                              Functions.ReturnLength(f.Length - (long)fontinfo.samsize, false));
            }
            else
            {
                SofSFLab.Text = String.Format("{0} (Samples: {1}, Presets: {2})",
                                              Functions.ReturnLength(f.Length, false),
                                              Functions.ReturnLength(fontinfo.samsize, false),
                                              Functions.ReturnLength(f.Length - (long)fontinfo.samsize, false));
            }

            SFfLab.Text      = SoundFontListExtension.ReturnSoundFontFormatMore(Path.GetExtension(next));
            CommentRich.Text = ReturnComment(fontinfo.comment);
            LELabel.Text     = f.LastWriteTimeUtc.ToString();

            BassMidi.BASS_MIDI_FontFree(fonthandle);
        }
コード例 #6
0
        public SoundFontInfo(String SoundFont)
        {
            InitializeComponent();

            ERROR = false;

            LastMIDIPath = KeppySynthConfiguratorMain.SynthPaths.GetValue("lastpathmidimport", Environment.GetFolderPath(Environment.SpecialFolder.Desktop)).ToString();

            // Here we go
            String   next;
            String   sf = "";
            Int32    fonthandle;
            FileInfo f;

            OriginalSF = SoundFont;

            if (SoundFont.ToLower().IndexOf('=') != -1)
            {
                sf = SoundFont.Substring(SoundFont.LastIndexOf('|') + 1);
                if (!File.Exists(sf))
                {
                    Functions.ShowErrorDialog(2, System.Media.SystemSounds.Exclamation, "Error", String.Format("The SoundFont \"{0}\" doesn't exist.", SoundFont), false, null);
                    ERROR = true;
                    Close();
                }
                SoundFontT = sf;
                fonthandle = BassMidi.BASS_MIDI_FontInit(sf);
                f          = new FileInfo(sf);
                next       = sf;
            }
            else
            {
                sf = SoundFont;
                if (!File.Exists(SoundFont))
                {
                    Functions.ShowErrorDialog(2, System.Media.SystemSounds.Exclamation, "Error", String.Format("The SoundFont \"{0}\" doesn't exist.", SoundFont), false, null);
                    ERROR = true;
                    Close();
                }
                SoundFontT = SoundFont;
                fonthandle = BassMidi.BASS_MIDI_FontInit(SoundFont);
                f          = new FileInfo(SoundFont);
                next       = SoundFont;
            }

            BASS_MIDI_FONTINFO fontinfo = BassMidi.BASS_MIDI_FontGetInfo(fonthandle);

            FNBox.Text  = next;
            ISFBox.Text = ReturnName(fontinfo.name, next);
            CIBox.Text  = ReturnCopyright(fontinfo.copyright);

            if (f.Length > (long)2147483648)
            {
                SofSFLab.Font      = new Font(SofSFLab.Font, FontStyle.Bold);
                SofSFLab.ForeColor = Color.DarkRed;
                SofSFLab.Cursor    = Cursors.Help;
                SizeWarning.SetToolTip(SofSFLab, "SoundFonts bigger than 2GB may not load correctly\non 32-bit applications, cause audio corruptions or even cause loss of data!\n\nBe careful!");
            }

            if (Path.GetExtension(sf).ToLowerInvariant() == ".sfz")
            {
                SofSFLab.Text = String.Format("{0} (Samples: {1}, Presets: {2})",
                                              Functions.ReturnLength(f.Length + SFZInfo.GetSoundFontZSize(sf)),
                                              Functions.ReturnLength(SFZInfo.GetSoundFontZSize(sf)),
                                              Functions.ReturnLength(f.Length - (long)fontinfo.samsize));
            }
            else
            {
                SofSFLab.Text = String.Format("{0} (Samples: {1}, Presets: {2})",
                                              Functions.ReturnLength(f.Length),
                                              Functions.ReturnLength(fontinfo.samsize),
                                              Functions.ReturnLength(f.Length - (long)fontinfo.samsize));
            }

            SFfLab.Text      = Functions.ReturnSoundFontFormatMore(Path.GetExtension(next));
            CommentRich.Text = ReturnComment(fontinfo.comment);
            LELabel.Text     = f.LastWriteTimeUtc.ToString();

            BassMidi.BASS_MIDI_FontFree(fonthandle);
        }
コード例 #7
0
        public static ListViewItem[] AddSFToList(String[] SFs, Boolean BPO, Boolean NoErrs)
        {
            List <ListViewItem> iSFs   = new List <ListViewItem>();
            List <String>       SFErrs = new List <String>();

            int[] TV = new int[] { -1, -1, 0, -1, 0, 0 };

            foreach (String SF in SFs)
            {
                if (CheckSupportedFormat(Path.GetExtension(SF)))
                {
                    // Check if it's valid
                    int       SFH = BassMidi.BASS_MIDI_FontInit(SF, BASSFlag.BASS_DEFAULT);
                    BASSError Err = Bass.BASS_ErrorGetCode();

                    // SoundFont is valid, continue
                    if (Err == 0)
                    {
                        BassMidi.BASS_MIDI_FontFree(SFH);

                        // Split filename in case of automatic preset/bank assign values
                        String[] Values = Path.GetFileNameWithoutExtension(SF).Split('-')[0].Split('.');
                        for (int i = 0; i < Values.Length && i < TV.Length; i++)
                        {
                            Int32 T = -1;
                            if (Int32.TryParse(Values[i], out T))
                            {
                                TV[i] = T;
                            }
                        }

                        if (BPO | Path.GetExtension(SF).ToLowerInvariant() == ".sfz")
                        {
                            using (var BPOW = new BankNPresetSel(Path.GetFileName(SF), false, (BPO && Path.GetExtension(SF).ToLowerInvariant() != ".sfz"), TV))
                            {
                                var RES = BPOW.ShowDialog();

                                if (RES == DialogResult.OK)
                                {
                                    TV[0] = BPOW.BankValueReturn;
                                    TV[1] = BPOW.PresetValueReturn;
                                    TV[2] = BPOW.DesBankValueReturn;
                                    TV[3] = BPOW.DesPresetValueReturn;
                                    TV[4] = BPOW.DesBankLSBValueReturn;
                                    TV[5] = Convert.ToInt32(BPOW.XGModeC);
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }

                        FileInfo     file = new FileInfo(SF);
                        ListViewItem iSF  = new ListViewItem(new[]
                        {
                            SF,
                            TV[0].ToString(), TV[1].ToString(), TV[2].ToString(), TV[3].ToString(), TV[4].ToString(), Convert.ToBoolean(TV[5]) ? "Yes" : "No", "Yes",
                            ReturnSoundFontFormat(Path.GetExtension(SF)),
                            ReturnSoundFontSize(SF, Path.GetExtension(SF), file.Length)
                        });

                        iSF.Checked = true;

                        iSFs.Add(iSF);
                    }
                    else
                    {
                        SFErrs.Add(SF);
                    }
                }
                else
                {
                    SFErrs.Add(SF);
                }
            }

            if (SFErrs.Count > 0)
            {
                if (!NoErrs)
                {
                    Program.ShowError(
                        4,
                        "Invalid SoundFont(s) detected",
                        String.Format(
                            "The following SoundFont(s) were not valid, and have not been added to the list.\n\n{0}\n\nPress OK to continue",
                            string.Join(Environment.NewLine, SFErrs.ToArray())),
                        null);
                }

                return(new ListViewItem[] { });
            }

            return(iSFs.ToArray());
        }