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 } }
/// <summary> /// Load External BASS Audio Decoder Plugins /// </summary> private 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); 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(); } }
/// <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(); } }
private void BASSStreamSystem(String str) { Microsoft.Win32.RegistryKey Settings = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Keppy's MIDI Converter\\Settings", false); Globals._recHandle = BassMidi.BASS_MIDI_StreamCreateFile(str, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIDI_DECAYEND, Globals.Frequency); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_GVOL_STREAM, Globals.Volume); Bass.BASS_ChannelSetAttribute(Globals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_VOICES, Globals.LimitVoicesInt); Bass.BASS_ChannelSetAttribute(Globals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_CPU, 0); if (Path.GetFileNameWithoutExtension(str).Length >= 49) Globals.NewWindowName = String.Format(res_man.GetString("ConversionText", cul), Path.GetFileNameWithoutExtension(str).Truncate(45)); else Globals.NewWindowName = String.Format(res_man.GetString("ConversionText", cul), Path.GetFileNameWithoutExtension(str)); BASS_MIDI_FONT[] fonts = new BASS_MIDI_FONT[Globals.Soundfonts.Length]; int sfnum = 0; foreach (string s in Globals.Soundfonts) { fonts[sfnum].font = BassMidi.BASS_MIDI_FontInit(s); fonts[sfnum].preset = -1; fonts[sfnum].bank = 0; BassMidi.BASS_MIDI_FontSetVolume(fonts[sfnum].font, ((float)Globals.Volume / 10000)); BassMidi.BASS_MIDI_StreamSetFonts(Globals._recHandle, fonts, sfnum + 1); sfnum += 1; } Globals._plm = new Un4seen.Bass.Misc.DSP_PeakLevelMeter(Globals._recHandle, 1); Globals._plm.CalcRMS = true; BassMidi.BASS_MIDI_StreamLoadSamples(Globals._recHandle); }
private void RealTimePlayBackBeta_DoWork(object sender, DoWorkEventArgs e) { PlayConversionStart(); try { if (Globals.Soundfonts[0] == null) { throw new Exception(res_man.GetString("SelectOneSF", cul)); } if (this.MIDIList.Items.Count == 0) { throw new Exception(res_man.GetString("AddOneMIDI", cul)); } try { bool KeepLooping = true; while (KeepLooping) { foreach (string str in this.MIDIList.Items) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(str); string encpath = null; Bass.BASS_Init(-1, Globals.Frequency, BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, 32); BASS_INFO info = Bass.BASS_GetInfo(); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, info.minbuf + 10); Un4seen.Bass.Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, 100000); Globals._recHandle = BassMidi.BASS_MIDI_StreamCreateFile(str, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIDI_DECAYEND, Globals.Frequency); Bass.BASS_ChannelSetAttribute(Globals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_VOICES, Convert.ToInt32(Globals.LimitVoicesInt)); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_GVOL_STREAM, Globals.Volume); Un4seen.Bass.Bass.BASS_ChannelSetAttribute(Globals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_CPU, 85); if (Path.GetFileNameWithoutExtension(str).Length >= 49) Globals.NewWindowName = String.Format(res_man.GetString("PlaybackText", cul), Path.GetFileNameWithoutExtension(str).Truncate(45)); else Globals.NewWindowName = String.Format(res_man.GetString("PlaybackText", cul), Path.GetFileNameWithoutExtension(str)); BASSVSTInit(Globals._recHandle); Globals._plm = new Un4seen.Bass.Misc.DSP_PeakLevelMeter(Globals._recHandle, 1); Globals._plm.CalcRMS = true; BASS_MIDI_FONT[] fonts = new BASS_MIDI_FONT[Globals.Soundfonts.Length]; int sfnum = 0; foreach (string s in Globals.Soundfonts) { fonts[sfnum].font = BassMidi.BASS_MIDI_FontInit(s); fonts[sfnum].preset = -1; fonts[sfnum].bank = 0; BassMidi.BASS_MIDI_StreamSetFonts(Globals._recHandle, fonts, sfnum + 1); sfnum += 1; } BassMidi.BASS_MIDI_StreamLoadSamples(Globals._recHandle); if (Globals.FXDisabled == true) { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, BASSFlag.BASS_MIDI_NOFX, BASSFlag.BASS_MIDI_NOFX); } else { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, 0, BASSFlag.BASS_MIDI_NOFX); } if (Globals.NoteOff1Event == true) { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, BASSFlag.BASS_MIDI_NOTEOFF1, BASSFlag.BASS_MIDI_NOTEOFF1); } else { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, 0, BASSFlag.BASS_MIDI_NOTEOFF1); } Bass.BASS_ChannelPlay(Globals._recHandle, false); int tempo = BassMidi.BASS_MIDI_StreamGetEvent(Globals._recHandle, 0, BASSMIDIEvent.MIDI_EVENT_TEMPO); Globals.OriginalTempo = 60000000 / tempo; while (Un4seen.Bass.Bass.BASS_ChannelIsActive(Globals._recHandle) == BASSActive.BASS_ACTIVE_PLAYING) { if (Globals.CancellationPendingValue != 1) { if (MainWindow.Globals.TempoOverride == true) { BassMidi.BASS_MIDI_StreamEvent(Globals._recHandle, 0, BASSMIDIEvent.MIDI_EVENT_TEMPO, 60000000 / Globals.FinalTempo); } else { // NULL } if (Globals.FXDisabled == true) { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, BASSFlag.BASS_MIDI_NOFX, BASSFlag.BASS_MIDI_NOFX); } else { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, 0, BASSFlag.BASS_MIDI_NOFX); } if (Globals.NoteOff1Event == true) { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, BASSFlag.BASS_MIDI_NOTEOFF1, BASSFlag.BASS_MIDI_NOTEOFF1); } else { Un4seen.Bass.Bass.BASS_ChannelFlags(Globals._recHandle, 0, BASSFlag.BASS_MIDI_NOTEOFF1); } Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_GVOL_STREAM, Globals.Volume); Bass.BASS_ChannelSetAttribute(Globals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_VOICES, Convert.ToInt32(Globals.LimitVoicesInt)); long pos = Un4seen.Bass.Bass.BASS_ChannelGetLength(Globals._recHandle); long num6 = Un4seen.Bass.Bass.BASS_ChannelGetPosition(Globals._recHandle); float num7 = ((float)pos) / 1048576f; float num8 = ((float)num6) / 1048576f; double num9 = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(Globals._recHandle, pos); double num10 = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(Globals._recHandle, num6); TimeSpan span = TimeSpan.FromSeconds(num9); TimeSpan span2 = TimeSpan.FromSeconds(num10); string str4 = span.Minutes.ToString() + ":" + span.Seconds.ToString().PadLeft(2, '0'); string str5 = span2.Minutes.ToString() + ":" + span2.Seconds.ToString().PadLeft(2, '0'); float percentage = num8 / num7; float percentagefinal; if (percentage * 100 < 0) percentagefinal = 0.0f; else if (percentage * 100 > 100) percentagefinal = 1.0f; else percentagefinal = percentage; float num11 = 0f; Un4seen.Bass.Bass.BASS_ChannelGetAttribute(Globals._recHandle, BASSAttribute.BASS_ATTRIB_MIDI_VOICES_ACTIVE, ref num11); Globals.CurrentStatusTextString = String.Format(res_man.GetString("PlaybackStatus", cul), percentage.ToString("0%"), str5, str4); Globals.ActiveVoicesInt = Convert.ToInt32(num11); Globals.CurrentStatusMaximumInt = Convert.ToInt32((long)(pos / 0x100000L)); Globals.CurrentStatusValueInt = Convert.ToInt32((long)(num6 / 0x100000L)); Bass.BASS_ChannelUpdate(Globals._recHandle, 0); } else if (Globals.CancellationPendingValue == 1) { BassEnc.BASS_Encode_Stop(Globals._Encoder); Bass.BASS_StreamFree(Globals._recHandle); Bass.BASS_Free(); Globals.CurrentStatusTextString = res_man.GetString("PlaybackAborted", cul); Globals.ActiveVoicesInt = 0; Globals.NewWindowName = "Keppy's MIDI Converter"; MessageBox.Show(res_man.GetString("PlaybackAborted", cul), res_man.GetString("PlaybackXPTitle", cul), MessageBoxButtons.OK, MessageBoxIcon.Exclamation); Globals.CurrentStatusTextString = null; KeepLooping = false; break; Globals.PlaybackMode = false; } } if (Globals.CancellationPendingValue == 1) { KeepLooping = false; if (KeepLooping == false) { break; } } else { continue; } } if (Globals.CancellationPendingValue == 1) { BassEnc.BASS_Encode_Stop(Globals._Encoder); Bass.BASS_StreamFree(Globals._recHandle); Bass.BASS_Free(); Globals.CancellationPendingValue = 0; Globals.ActiveVoicesInt = 0; Globals.CurrentStatusTextString = res_man.GetString("PlaybackAborted", cul); Globals.NewWindowName = "Keppy's MIDI Converter"; KeepLooping = false; Globals.PlaybackMode = false; if (Environment.OSVersion.Version.Major == 5) { MessageBox.Show(String.Format(res_man.GetString("PlaybackAbortedXPMessage", cul), Bass.BASS_ErrorGetCode().ToString()), res_man.GetString("PlaybackXPTitle", cul), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { PlayConversionStop(); } } else { BassEnc.BASS_Encode_Stop(Globals._Encoder); Bass.BASS_StreamFree(Globals._recHandle); Bass.BASS_Free(); Globals.CancellationPendingValue = 0; Globals.ActiveVoicesInt = 0; Globals.CurrentStatusTextString = null; Globals.NewWindowName = "Keppy's MIDI Converter"; KeepLooping = false; Globals.PlaybackMode = false; if (Environment.OSVersion.Version.Major == 5) { MessageBox.Show(String.Format(res_man.GetString("PlaybackCompletedXPMessage", cul), Bass.BASS_ErrorGetCode().ToString()), res_man.GetString("PlaybackXPTitle", cul), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { PlayConversionStop(); } } } } catch (Exception exception) { BASSCloseStreamCrash(exception); Globals.PlaybackMode = false; } } catch (Exception exception2) { BASSCloseStreamCrash(exception2); Globals.PlaybackMode = false; } }