Beispiel #1
0
        private void EBPV_Click(object sender, EventArgs e)
        {
            List <String> SFErr = new List <String>();

            foreach (ListViewItem Item in Lis.SelectedItems)
            {
                try {
                    Int32[] OldValues =
                    {
                        Convert.ToInt32(Item.SubItems[1].Text),
                        Convert.ToInt32(Item.SubItems[2].Text),
                        Convert.ToInt32(Item.SubItems[3].Text),
                        Convert.ToInt32(Item.SubItems[4].Text),
                        Convert.ToInt32(Item.SubItems[5].Text),
                        Convert.ToInt32(Item.SubItems[6].Text.ToLowerInvariant().Equals("yes") ? 1 : 0)
                    };

                    using (var BPOW = new BankNPresetSel(Path.GetFileName(Item.Text), true, Path.GetExtension(Item.Text).ToLowerInvariant() != ".sfz", OldValues))
                    {
                        var RES = BPOW.ShowDialog();

                        if (RES == DialogResult.OK)
                        {
                            Item.SubItems[1].Text = BPOW.BankValueReturn.ToString();
                            Item.SubItems[2].Text = BPOW.PresetValueReturn.ToString();
                            Item.SubItems[3].Text = BPOW.DesBankValueReturn.ToString();
                            Item.SubItems[4].Text = BPOW.DesPresetValueReturn.ToString();
                            Item.SubItems[5].Text = BPOW.DesBankLSBValueReturn.ToString();
                            Item.SubItems[6].Text = BPOW.XGModeC ? "Yes" : "No";
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                catch { SFErr.Add(Item.Text); }
            }

            if (SFErr.Count > 0)
            {
                Program.ShowError(
                    2,
                    "Unable to edit SoundFont(s)",
                    String.Format(
                        "The configurator was unable to edit the following SoundFont(s).\n\n{0}\n\nPress OK to continue.",
                        String.Join(Environment.NewLine, SFErr.ToArray())),
                    null);
            }
        }
Beispiel #2
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());
        }
Beispiel #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[] 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());
        }
Beispiel #4
0
 public static void AddSoundfontsToSelectedList(String CurrentList, String[] Soundfonts)
 {
     for (int i = 0; i < Soundfonts.Length; i++)
     {
         if (Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".sf1" | Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".sf2" | Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".sfark" | Path.GetExtension(Soundfonts[i]) == ".sfpack".ToLowerInvariant())
         {
             int test = BassMidi.BASS_MIDI_FontInit(Soundfonts[i], BASSFlag.BASS_DEFAULT);
             if (Bass.BASS_ErrorGetCode() != 0)
             {
                 Functions.ShowErrorDialog(ErrorType.Error, System.Media.SystemSounds.Hand, "Error while adding soundfont", String.Format("{0} is not a valid soundfont file!", Path.GetFileName(Soundfonts[i])), false, null);
             }
             else
             {
                 if (OmniMIDIConfiguratorMain.Delegate.BankPresetOverride.Checked == true)
                 {
                     using (var form = new BankNPresetSel(Path.GetFileName(Soundfonts[i]), false, true, null))
                     {
                         var result = form.ShowDialog();
                         if (result == DialogResult.OK)
                         {
                             FileInfo     file = new FileInfo(Soundfonts[i]);
                             ListViewItem SF   = new ListViewItem(new[] {
                                 Soundfonts[i],
                                 form.BankValueReturn, form.PresetValueReturn, form.DesBankValueReturn, form.DesPresetValueReturn, form.XGModeC ? "Yes" : "No",
                                 ReturnSoundFontFormat(Path.GetExtension(Soundfonts[i])),
                                 ReturnSoundFontSize(Soundfonts[i], Path.GetExtension(Soundfonts[i]), file.Length)
                             });
                             SF.ForeColor = SFEnabled;
                             OmniMIDIConfiguratorMain.Delegate.Lis.Items.Add(SF);
                         }
                     }
                 }
                 else
                 {
                     FileInfo     file = new FileInfo(Soundfonts[i]);
                     ListViewItem SF   = new ListViewItem(new[] {
                         Soundfonts[i],
                         "-1", "-1", "0", "-1", "No",
                         ReturnSoundFontFormat(Path.GetExtension(Soundfonts[i])),
                         ReturnSoundFontSize(Soundfonts[i], Path.GetExtension(Soundfonts[i]), file.Length)
                     });
                     SF.ForeColor = SFEnabled;
                     OmniMIDIConfiguratorMain.Delegate.Lis.Items.Add(SF);
                 }
                 SaveList(CurrentList);
                 TriggerReload(false);
             }
             Program.DebugToConsole(false, String.Format("Added soundfont to list: {0}", Soundfonts[i]), null);
         }
         else if (Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".sfz")
         {
             int test = BassMidi.BASS_MIDI_FontInit(Soundfonts[i], BASSFlag.BASS_DEFAULT);
             if (Bass.BASS_ErrorGetCode() != 0)
             {
                 Functions.ShowErrorDialog(ErrorType.Error, System.Media.SystemSounds.Hand, "Error while adding soundfont", String.Format("{0} is not a valid soundfont file!", Path.GetFileName(Soundfonts[i])), false, null);
             }
             else
             {
                 using (var form = new BankNPresetSel(Path.GetFileName(Soundfonts[i]), false, false, null))
                 {
                     var result = form.ShowDialog();
                     if (result == DialogResult.OK)
                     {
                         FileInfo     file = new FileInfo(Soundfonts[i]);
                         ListViewItem SF   = new ListViewItem(new[] {
                             Soundfonts[i],
                             form.BankValueReturn, form.PresetValueReturn, form.DesBankValueReturn, form.DesPresetValueReturn, form.XGModeC ? "Yes" : "No",
                             ReturnSoundFontFormat(Path.GetExtension(Soundfonts[i])),
                             ReturnSoundFontSize(Soundfonts[i], Path.GetExtension(Soundfonts[i]), file.Length)
                         });
                         SF.ForeColor = SFEnabled;
                         OmniMIDIConfiguratorMain.Delegate.Lis.Items.Add(SF);
                     }
                 }
                 SaveList(CurrentList);
                 TriggerReload(false);
             }
             Program.DebugToConsole(false, String.Format("Added soundfont to list: {0}", Soundfonts[i]), null);
         }
         else if (Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".dls")
         {
             Functions.ShowErrorDialog(ErrorType.Error, System.Media.SystemSounds.Exclamation, "Error", "BASSMIDI does NOT support the downloadable sounds (DLS) format!", false, null);
         }
         else if (Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".exe" | Path.GetExtension(Soundfonts[i]).ToLowerInvariant() == ".dll")
         {
             Functions.ShowErrorDialog(ErrorType.Error, System.Media.SystemSounds.Exclamation, "Error", "Are you really trying to add executables to the soundfonts list?", false, null);
         }
         else
         {
             Functions.ShowErrorDialog(ErrorType.Error, System.Media.SystemSounds.Exclamation, "Error", String.Format("Invalid soundfont!\n\nFile: {0}\n\nPlease select a valid soundfont and try again!", Soundfonts[i]), false, null);
         }
     }
 }