// SF system private static bool LoadSpecificSoundFont(string path, ref int sfnum) { if (File.Exists(path)) { MainWindow.KMCGlobals.SoundFonts[sfnum].font = BassMidi.BASS_MIDI_FontInit(path, BASSFlag.BASS_MIDI_FONT_XGDRUMS); MainWindow.KMCGlobals.SoundFonts[sfnum].dpreset = -1; MainWindow.KMCGlobals.SoundFonts[sfnum].dbank = 0; MainWindow.KMCGlobals.SoundFonts[sfnum].spreset = -1; MainWindow.KMCGlobals.SoundFonts[sfnum].sbank = -1; MainWindow.KMCGlobals.SoundFonts[sfnum].dbanklsb = 0; BASSCheckError(); if (!Properties.Settings.Default.PreloadSamplesNotSF) { BassMidi.BASS_MIDI_FontLoad(MainWindow.KMCGlobals.SoundFonts[sfnum].font, -1, -1); } BASSCheckError(); sfnum++; return(true); } else { return(false); } }
private void ApplySoundfontToStream(string SoundfontFilename) { int FontHandle = BassMidi.BASS_MIDI_FontInit(SoundfontFilename); if (FontHandle != 0) { BASS_MIDI_FONT Font = new BASS_MIDI_FONT(FontHandle, -1, 0); BassMidi.BASS_MIDI_StreamSetFonts(this.ChannelID, new BASS_MIDI_FONT[] { Font }, 1); // apply it to the stream } }
public void Init() { int tget = BassMidi.BASS_MIDI_FontInit("test.sf2"); Fonts = new BASS_MIDI_FONT[1]; Fonts[0].font = tget; Fonts[0].bank = 0; Fonts[0].preset = -1; NoteStreams = new int[256]; for (int i = 60; i <= 84; ++i) { NoteStreams[i] = BassMidi.BASS_MIDI_StreamCreateEvents(SingleNoteEvent(i), 100, 0, 0); BassMidi.BASS_MIDI_StreamSetFonts(NoteStreams[i], Fonts, 1); } }
private void LoadSoundFonts() { foreach (SoundFont SF in Program.SFArray.List) { if (!SF.IsEnabled) { Debug.PrintToConsole("ok", "SoundFont is disabled, there's no need to load it."); continue; } BASS_MIDI_FONTEX TSF; Debug.PrintToConsole("ok", String.Format("Preparing BASS_MIDI_FONTEX for {0}...", SF.GetSoundFontPath)); TSF.font = BassMidi.BASS_MIDI_FontInit(SF.GetSoundFontPath, SF.GetXGMode ? BASSFlag.BASS_MIDI_FONT_XGDRUMS : BASSFlag.BASS_DEFAULT); Debug.PrintToConsole("ok", String.Format("SoundFont handle initialized. Handle = {0:X8}", TSF.font)); TSF.spreset = SF.GetSourcePreset; TSF.sbank = SF.GetSourceBank; TSF.dpreset = SF.GetDestinationPreset; TSF.dbank = SF.GetDestinationBank; TSF.dbanklsb = SF.GetDestinationBankLSB; Debug.PrintToConsole("ok", String.Format( "spreset = {0}, sbank = {1}, dpreset = {2}, dbank = {3}, dbanklsb = {4}, xg = {5}", TSF.spreset, TSF.sbank, TSF.dpreset, TSF.dbank, TSF.dbanklsb, SF.GetXGMode ) ); if (TSF.font != 0) { Program.SFArray.BMFEArray.Add(TSF); Debug.PrintToConsole("ok", "SoundFont loaded and added to BASS_MIDI_FONTEX array."); } else { Debug.PrintToConsole("err", String.Format("Could not load {0}. BASSERR: {1}", SF.GetSoundFontPath, Bass.BASS_ErrorGetCode())); } } Debug.PrintToConsole("ok", "Reversing array..."); Program.SFArray.BMFEArray.Reverse(); }
private void InitializeBASSMIDIStream() { // Init stream ChangePreviewButtonText("Initializing stream...", false); ChangeWindowTitle("Initializing stream..."); hStream = BassMidi.BASS_MIDI_StreamCreateFile(MIDIPreview, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_SOFTWARE | (Convert.ToBoolean(Program.SynthSettings.GetValue("EnableSFX", 0)) ? BASSFlag.BASS_DEFAULT : BASSFlag.BASS_MIDI_NOFX) | (LoopYesNo.Checked ? BASSFlag.BASS_SAMPLE_LOOP : BASSFlag.BASS_DEFAULT), 0); Bass.BASS_ChannelSetAttribute(hStream, BASSAttribute.BASS_ATTRIB_MIDI_CPU, (int)(Convert.ToInt32(Program.SynthSettings.GetValue("MaxRenderingTime", 75)) / 100)); System.Threading.Thread.Sleep(50); // Init SoundFont ChangePreviewButtonText("Loading SoundFont...", false); ChangeWindowTitle("Loading SoundFont..."); BASS_MIDI_FONTEX[] fonts = new BASS_MIDI_FONTEX[1]; if (OriginalSF.ToLower().IndexOf('=') != -1) { var matches = System.Text.RegularExpressions.Regex.Matches(OriginalSF, "[0-9]+"); string sf = OriginalSF.Substring(OriginalSF.LastIndexOf('|') + 1); fonts[0].font = BassMidi.BASS_MIDI_FontInit(sf); fonts[0].spreset = Convert.ToInt32(matches[0].ToString()); fonts[0].sbank = Convert.ToInt32(matches[1].ToString()); fonts[0].dpreset = Convert.ToInt32(matches[2].ToString()); fonts[0].dbank = Convert.ToInt32(matches[3].ToString()); } else { fonts[0].font = BassMidi.BASS_MIDI_FontInit(OriginalSF); fonts[0].spreset = -1; fonts[0].sbank = -1; fonts[0].dpreset = -1; fonts[0].dbank = 0; } BassMidi.BASS_MIDI_FontSetVolume(fonts[0].font, 1.0f); BassMidi.BASS_MIDI_StreamSetFonts(hStream, fonts, 1); BassMidi.BASS_MIDI_StreamLoadSamples(hStream); }
private void InitializeBASSMIDIStream() { // Init stream ChangePreviewButtonText("Initializing stream...", false); ChangeWindowTitle("Initializing stream..."); hStream = BassMidi.BASS_MIDI_StreamCreateFile(MIDIPreview, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_SOFTWARE, 0); Bass.BASS_ChannelSetAttribute(hStream, BASSAttribute.BASS_ATTRIB_MIDI_CPU, (int)(KeppySynthConfiguratorMain.Delegate.MaxCPU.Value / 100)); System.Threading.Thread.Sleep(50); // Init SoundFont ChangePreviewButtonText("Loading SoundFont...", false); ChangeWindowTitle("Loading SoundFont..."); BASS_MIDI_FONTEX[] fonts = new BASS_MIDI_FONTEX[1]; List <int> termsList = new List <int>(); termsList.Reverse(); if (OriginalSF.ToLower().IndexOf('=') != -1) { var matches = System.Text.RegularExpressions.Regex.Matches(OriginalSF, "[0-9]+"); string sf = OriginalSF.Substring(OriginalSF.LastIndexOf('|') + 1); fonts[0].font = BassMidi.BASS_MIDI_FontInit(sf); fonts[0].spreset = Convert.ToInt32(matches[0].ToString()); fonts[0].sbank = Convert.ToInt32(matches[1].ToString()); fonts[0].dpreset = Convert.ToInt32(matches[2].ToString()); fonts[0].dbank = Convert.ToInt32(matches[3].ToString()); BassMidi.BASS_MIDI_FontSetVolume(fonts[0].font, 1.0f); BassMidi.BASS_MIDI_StreamSetFonts(hStream, fonts, 1); } else { fonts[0].font = BassMidi.BASS_MIDI_FontInit(OriginalSF); fonts[0].spreset = -1; fonts[0].sbank = -1; fonts[0].dpreset = -1; fonts[0].dbank = 0; BassMidi.BASS_MIDI_StreamSetFonts(hStream, fonts, 1); } BassMidi.BASS_MIDI_StreamLoadSamples(hStream); }
private void LoadSoundfont_Click(object sender, EventArgs e) { if (OpenSF.ShowDialog() == DialogResult.OK) { if (Path.GetExtension(OpenSF.FileName).ToLowerInvariant() == ".sfz") { using (var form = new BankNPresetSel(Path.GetFileName(OpenSF.FileName), 1, 0)) { var result = form.ShowDialog(); if (result == DialogResult.OK) { fontb = (int)form.DesBankValueReturn; fontp = (int)form.DesPresetValueReturn; } } } else { fontb = 0; fontp = -1; } int newfont = BassMidi.BASS_MIDI_FontInit(OpenSF.FileName, 0); if (newfont != 0) { BASS_MIDI_FONT[] sf = { new BASS_MIDI_FONT(newfont, fontp, fontb) }; // now set them BassMidi.BASS_MIDI_StreamSetFonts(chan, sf, sf.Length); font = newfont; } else { Error("Can't load soundfont"); } } }
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()); }
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(); } }
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); }
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); } } }
/// <summary> /// Load External BASS Audio Decoder Plugins /// </summary> public static void LoadAudioDecoderPlugins() { Log.Info("BASS: Loading audio decoder add-ins..."); string appPath = Application.StartupPath; string decoderFolderPath = Path.Combine(appPath, @"musicplayer\plugins\audio decoders"); if (!Directory.Exists(decoderFolderPath)) { Log.Error(@"BASS: Unable to find \musicplayer\plugins\audio decoders folder in MediaPortal.exe path."); return; } DirectoryInfo dirInfo = new DirectoryInfo(decoderFolderPath); FileInfo[] decoders = dirInfo.GetFiles(); int pluginHandle = 0; int decoderCount = 0; foreach (FileInfo file in decoders) { if (Path.GetExtension(file.Name).ToLower() != ".dll") { continue; } pluginHandle = Bass.BASS_PluginLoad(file.FullName); if (pluginHandle != 0) { _decoderPluginHandles.Add(pluginHandle); decoderCount++; Log.Debug("BASS: Added DecoderPlugin: {0}", file.FullName); } else { Log.Debug("BASS: Unable to load: {0}", file.FullName); } } if (decoderCount > 0) { Log.Info("BASS: Loaded {0} Audio Decoders.", decoderCount); } else { Log.Error( @"BASS: No audio decoders were loaded. Confirm decoders are present in \musicplayer\plugins\audio decoders folder."); } // Look for any SF2 files available in the folder. // SF2 files contain sound fonts needed for midi playback List <BASS_MIDI_FONT> tmpFonts = new List <BASS_MIDI_FONT>(); foreach (FileInfo file in decoders) { if (Path.GetExtension(file.Name).ToLower() != ".sf2") { continue; } int font = BassMidi.BASS_MIDI_FontInit(file.FullName, BASSFlag.BASS_MIDI_FONT_MMAP); if (font != 0) { BASS_MIDI_FONTINFO fontInfo = new BASS_MIDI_FONTINFO(); BassMidi.BASS_MIDI_FontGetInfo(font, fontInfo); Log.Info("BASS: Loading Midi font: {0}", fontInfo.ToString()); _soundFontHandles.Add(font); BASS_MIDI_FONT soundFont = new BASS_MIDI_FONT(font, -1, 0); tmpFonts.Add(soundFont); } } if (tmpFonts.Count > 0) { _soundFonts = tmpFonts.ToArray(); } }
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); }
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()); }
public static void BASSLoadSoundFonts2(ref int sfnum) { // Prepare SoundFonts list MainWindow.KMCGlobals.SoundFonts = new BASS_MIDI_FONTEX[MainWindow.SoundFontChain.SoundFonts.Length + 1]; String[] SoundFontsReverse = MainWindow.SoundFontChain.SoundFonts.Reverse().ToArray(); try { // Then load all the other SFs foreach (string s in SoundFontsReverse) { if (s.ToLower().IndexOf('=') != -1) { var matches = System.Text.RegularExpressions.Regex.Matches(s, "[0-9]+"); MainWindow.KMCGlobals.SoundFonts[sfnum].font = BassMidi.BASS_MIDI_FontInit(s.Substring(s.LastIndexOf('|') + 1), BASSFlag.BASS_MIDI_FONT_XGDRUMS); MainWindow.KMCGlobals.SoundFonts[sfnum].dbank = Convert.ToInt32(matches[0].ToString()); MainWindow.KMCGlobals.SoundFonts[sfnum].dpreset = Convert.ToInt32(matches[1].ToString()); MainWindow.KMCGlobals.SoundFonts[sfnum].sbank = Convert.ToInt32(matches[2].ToString()); MainWindow.KMCGlobals.SoundFonts[sfnum].spreset = Convert.ToInt32(matches[3].ToString()); MainWindow.KMCGlobals.SoundFonts[sfnum].dbanklsb = 0; BASSCheckError(); } else { MainWindow.KMCGlobals.SoundFonts[sfnum].font = BassMidi.BASS_MIDI_FontInit(s); MainWindow.KMCGlobals.SoundFonts[sfnum].dpreset = -1; MainWindow.KMCGlobals.SoundFonts[sfnum].dbank = 0; MainWindow.KMCGlobals.SoundFonts[sfnum].spreset = -1; MainWindow.KMCGlobals.SoundFonts[sfnum].sbank = -1; MainWindow.KMCGlobals.SoundFonts[sfnum].dbanklsb = 0; BASSCheckError(); } if (!Properties.Settings.Default.PreloadSamplesNotSF) { BassMidi.BASS_MIDI_FontLoad(MainWindow.KMCGlobals.SoundFonts[sfnum].font, MainWindow.KMCGlobals.SoundFonts[sfnum].spreset, MainWindow.KMCGlobals.SoundFonts[sfnum].sbank); } BASSCheckError(); sfnum++; } } catch { BASSCloseStreamException(new InvalidSoundFont("Invalid SoundFont chain.")); } finally { // Always preload default SoundFont if (Properties.Settings.Default.PreloadDefaultSF) { DirectoryInfo PathToGenericSF = Directory.GetParent(Assembly.GetExecutingAssembly().Location); String FullPath = String.Format("{0}\\GMGeneric.sf2", PathToGenericSF.Parent.FullName); LoadSpecificSoundFont(FullPath, ref sfnum); } BassMidi.BASS_MIDI_StreamSetFonts(MainWindow.KMCGlobals._recHandle, MainWindow.KMCGlobals.SoundFonts, sfnum); BASSCheckError(); if (Properties.Settings.Default.PreloadSamplesNotSF) { BassMidi.BASS_MIDI_StreamLoadSamples(MainWindow.KMCGlobals._recHandle); } BASSCheckError(); } }