Inheritance: System.Windows.Forms.Form
 private void AddSF_Click(object sender, EventArgs e)
 {
     try
     {
         SoundfontImport.InitialDirectory = LastBrowserPath;
         SoundfontImport.FileName = "";
         Functions.OpenFileDialogAddCustomPaths(SoundfontImport);
         if (SoundfontImport.ShowDialog() == DialogResult.OK)
         {
             foreach (string str in SoundfontImport.FileNames)
             {
                 if (Path.GetExtension(str).ToLower() == ".sf2" | Path.GetExtension(str).ToLower() == ".sfpack")
                 {
                     if (BankPresetOverride.Checked == true)
                     {
                         using (var form = new BankNPresetSel(Path.GetFileName(str), 0, 1))
                         {
                             var result = form.ShowDialog();
                             if (result == DialogResult.OK)
                             {
                                 string sbank = form.BankValueReturn;
                                 string spreset = form.PresetValueReturn;
                                 string dbank = form.DesBankValueReturn;
                                 string dpreset = form.DesPresetValueReturn;
                                 Lis.Items.Add("p" + sbank + "," + spreset + "=" + dbank + "," + dpreset + "|" + str);
                             }
                         }
                     }
                     else
                     {
                         Lis.Items.Add(str);
                     }
                 }
                 else if (Path.GetExtension(str).ToLower() == ".sfz")
                 {
                     using (var form = new BankNPresetSel(Path.GetFileName(str), 0, 0))
                     {
                         var result = form.ShowDialog();
                         if (result == DialogResult.OK)
                         {
                             string sbank = form.BankValueReturn;
                             string spreset = form.PresetValueReturn;
                             string dbank = form.DesBankValueReturn;
                             string dpreset = form.DesPresetValueReturn;
                             Lis.Items.Add("p" + sbank + "," + spreset + "=" + dbank + "," + dpreset + "|" + str);
                         }
                     }
                 }
                 else
                 {
                     MessageBox.Show(Path.GetFileName(str) + " is not a valid soundfont file!", "Error while adding soundfont", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 LastBrowserPath = Path.GetDirectoryName(str);
                 Functions.SetLastPath(LastBrowserPath);
             }
             Functions.SaveList(CurrentList);
             Functions.TriggerReload();
         }
     }
     catch (Exception ex)
     {
         Functions.ReinitializeList(ex, CurrentList);
     }
 }
Exemplo n.º 2
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(1, 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 (KeppySynthConfiguratorMain.Delegate.BankPresetOverride.Checked == true)
                 {
                     using (var form = new BankNPresetSel(Path.GetFileName(Soundfonts[i]), 0, 1))
                     {
                         var result = form.ShowDialog();
                         if (result == DialogResult.OK)
                         {
                             string       sbank   = form.BankValueReturn;
                             string       spreset = form.PresetValueReturn;
                             string       dbank   = form.DesBankValueReturn;
                             string       dpreset = form.DesPresetValueReturn;
                             FileInfo     file    = new FileInfo(Soundfonts[i]);
                             ListViewItem SF      = new ListViewItem(new[] {
                                 "p" + sbank + "," + spreset + "=" + dbank + "," + dpreset + "|" + Soundfonts[i],
                                 ReturnSoundFontFormat(Path.GetExtension(Soundfonts[i])),
                                 ReturnSoundFontSize(Soundfonts[i], Path.GetExtension(Soundfonts[i]), file.Length)
                             });
                             KeppySynthConfiguratorMain.Delegate.Lis.Items.Add(SF);
                         }
                     }
                 }
                 else
                 {
                     FileInfo     file = new FileInfo(Soundfonts[i]);
                     ListViewItem SF   = new ListViewItem(new[] {
                         Soundfonts[i],
                         ReturnSoundFontFormat(Path.GetExtension(Soundfonts[i])),
                         ReturnSoundFontSize(Soundfonts[i], Path.GetExtension(Soundfonts[i]), file.Length)
                     });
                     KeppySynthConfiguratorMain.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(1, 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]), 1, 0))
                 {
                     var result = form.ShowDialog();
                     if (result == DialogResult.OK)
                     {
                         string       sbank   = form.BankValueReturn;
                         string       spreset = form.PresetValueReturn;
                         string       dbank   = form.DesBankValueReturn;
                         string       dpreset = form.DesPresetValueReturn;
                         FileInfo     file    = new FileInfo(Soundfonts[i]);
                         ListViewItem SF      = new ListViewItem(new[] {
                             "p" + sbank + "," + spreset + "=" + dbank + "," + dpreset + "|" + Soundfonts[i],
                             ReturnSoundFontFormat(Path.GetExtension(Soundfonts[i])),
                             ReturnSoundFontSize(Soundfonts[i], Path.GetExtension(Soundfonts[i]), file.Length)
                         });
                         KeppySynthConfiguratorMain.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(1, 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(1, System.Media.SystemSounds.Exclamation, "Error", "Are you really trying to add executables to the soundfonts list?", false, null);
         }
         else
         {
             Functions.ShowErrorDialog(1, 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);
         }
     }
 }
 private void AddSoundfontDragNDrop(String SelectedList, DragEventArgs e)
 {
     string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
     int i;
     for (i = 0; i < s.Length; i++)
     {
         if (Path.GetExtension(s[i]) == ".sf2" | Path.GetExtension(s[i]) == ".SF2" | Path.GetExtension(s[i]) == ".sf3" | Path.GetExtension(s[i]) == ".SF3" | Path.GetExtension(s[i]) == ".sfpack" | Path.GetExtension(s[i]) == ".SFPACK")
         {
             if (BankPresetOverride.Checked == true)
             {
                 using (var form = new BankNPresetSel(Path.GetFileName(s[i]), 0, 1))
                 {
                     var result = form.ShowDialog();
                     if (result == DialogResult.OK)
                     {
                         string sbank = form.BankValueReturn;
                         string spreset = form.PresetValueReturn;
                         string dbank = form.DesBankValueReturn;
                         string dpreset = form.DesPresetValueReturn;
                         Lis.Items.Add("p" + sbank + "," + spreset + "=" + dbank + "," + dpreset + "|" + s[i]);
                     }
                 }
             }
             else
             {
                 Lis.Items.Add(s[i]);
             }
             Functions.SaveList(CurrentList);
             Functions.TriggerReload();
         }
         else if (Path.GetExtension(s[i]) == ".sfz" | Path.GetExtension(s[i]) == ".SFZ")
         {
             using (var form = new BankNPresetSel(Path.GetFileName(s[i]), 1, 0))
             {
                 var result = form.ShowDialog();
                 if (result == DialogResult.OK)
                 {
                     string sbank = form.BankValueReturn;
                     string spreset = form.PresetValueReturn;
                     string dbank = form.DesBankValueReturn;
                     string dpreset = form.DesPresetValueReturn;
                     Lis.Items.Add("p" + sbank + "," + spreset + "=" + dbank + "," + dpreset + "|" + s[i]);
                 }
             }
             Functions.SaveList(CurrentList);
             Functions.TriggerReload();
         }
         else if (Path.GetExtension(s[i]) == ".dls" | Path.GetExtension(s[i]) == ".DLS")
         {
             MessageBox.Show("BASSMIDI does NOT support the downloadable sounds (DLS) format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (Path.GetExtension(s[i]) == ".exe" | Path.GetExtension(s[i]) == ".EXE" | Path.GetExtension(s[i]) == ".dll" | Path.GetExtension(s[i]) == ".DLL")
         {
             MessageBox.Show("Are you really trying to add executables to the soundfonts list?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             MessageBox.Show("Invalid soundfont!\n\nPlease select a valid soundfont and try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }