public BASSMIDI(WaveFormat WF) { lock (Lock) { WaveFormat = WF; InitializeSettings(); Handle = BassMidi.BASS_MIDI_StreamCreate(16, Flags, WaveFormat.SampleRate); if (!CheckError(Handle, "Unable to create stream.")) { ErroredOut = true; return; } if (Handle == 0) { BASSError ERR = Bass.BASS_ErrorGetCode(); Debug.ShowMsgBox( "BASSMIDI error", String.Format("Unable to create stream.\n\nError encountered: {0}", ERR), null, MessageBoxButtons.OK, MessageBoxIcon.Error); ErroredOut = true; return; } Debug.PrintToConsole("ok", String.Format("{0} - Stream is open.", UniqueID)); Int32 Tracks = BassMidi.BASS_MIDI_StreamGetTrackCount(Handle); Debug.PrintToConsole("ok", String.Format("{0} - Total tracks = {1}", UniqueID, Tracks)); SetSoundFonts(); } }
// This is a really unstable mode, touching anything in its code might break it public BASSMIDI(Boolean RTS, WaveFormat WF) { if (!RTS) { Debug.ShowMsgBox("Wait what!?", "The \"RTS\" argument should be set to TRUE!", null, MessageBoxButtons.OK, MessageBoxIcon.Error); ErroredOut = true; return; } lock (Lock) { Int32 MT = Properties.Settings.Default.MultiThreadedMode ? Properties.Settings.Default.MultiThreadedLimitV : 1; RTSMode = RTS; WaveFormat = WF; InitializeSettings(); // Remove DECAYEND since it's not applicable to this type of stream Flags &= ~BASSFlag.BASS_MIDI_DECAYEND; // Create stream which will feed the events to Handle = BassMidi.BASS_MIDI_StreamCreate(16, Flags, WaveFormat.SampleRate); if (!CheckError(Handle, String.Format("Unable to create RTS stream ({0}).", UniqueID))) { ErroredOut = true; return; } Debug.PrintToConsole("ok", String.Format("{0} - RTS stream.", UniqueID)); SetSoundFonts(); } }
public static void BASSStreamSystemRT(String str, Boolean PreviewMode) { try { MainWindow.KMCGlobals._recHandle = BassMidi.BASS_MIDI_StreamCreateFile(str, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, 0); BASSCheckError(); BASS_MIDI_EVENT[] eventChunk; try { // Thank you so much Falcosoft for helping me there!!! // Visit his website: http://falcosoft.hu/index.html#start MainWindow.KMCGlobals.eventc = (UInt32)BassMidi.BASS_MIDI_StreamGetEvents(MainWindow.KMCGlobals._recHandle, -1, 0, null); // Counts all the events in the MIDI MainWindow.KMCGlobals.events = new BASS_MIDI_EVENT[MainWindow.KMCGlobals.eventc]; // Creates an array with the events count as size for (int i = 0; i <= (MainWindow.KMCGlobals.eventc / 50000000); i++) { int subCount = Math.Min(50000000, (int)MainWindow.KMCGlobals.eventc - (i * 50000000)); eventChunk = new BASS_MIDI_EVENT[subCount]; BassMidi.BASS_MIDI_StreamGetEvents(MainWindow.KMCGlobals._recHandle, -1, 0, eventChunk, i * 50000000, subCount); //Falcosoft: to avoid marshalling errors pass the smaller local buffer to the function eventChunk.CopyTo(MainWindow.KMCGlobals.events, i * 50000000); //Falcosoft: copy local buffer to global one at each iteration } eventChunk = null; } catch { BASSCloseStreamException(new MIDILoadError("This MIDI is too big for the real-time conversion process.\n\nMake sure you're using the 64-bit version of the converter.")); } Bass.BASS_StreamFree(MainWindow.KMCGlobals._recHandle); MainWindow.KMCGlobals._recHandle = BassMidi.BASS_MIDI_StreamCreate(16, BASSFlag.BASS_STREAM_DECODE | (PreviewMode ? 0 : (Properties.Settings.Default.SincInter ? BASSFlag.BASS_MIDI_SINCINTER : 0)) | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_SOFTWARE, 0); BASSCheckError(); if (PreviewMode) { BASS_WASAPI_DEVICEINFO infoDW = new BASS_WASAPI_DEVICEINFO(); BassWasapi.BASS_WASAPI_Init(-1, 0, 2, BASSWASAPIInit.BASS_WASAPI_BUFFER, 0, 0, null, IntPtr.Zero); BassWasapi.BASS_WASAPI_GetDevice(); BassWasapi.BASS_WASAPI_GetDeviceInfo(BassWasapi.BASS_WASAPI_GetDevice(), infoDW); BassWasapi.BASS_WASAPI_Free(); BassWasapi.BASS_WASAPI_Init(-1, infoDW.mixfreq, 2, BASSWASAPIInit.BASS_WASAPI_SHARED, infoDW.minperiod, 0, null, IntPtr.Zero); BASSCheckError(); } BASSInitializeChanAttributes(); BASSTempoAndFilter(); if (Path.GetFileNameWithoutExtension(str).Length >= 49) { MainWindow.KMCGlobals.NewWindowName = Path.GetFileNameWithoutExtension(str).Truncate(45); } else { MainWindow.KMCGlobals.NewWindowName = Path.GetFileNameWithoutExtension(str); } MainWindow.KMCGlobals._plm = new Un4seen.Bass.Misc.DSP_PeakLevelMeter(MainWindow.KMCGlobals._recHandle, 1); MainWindow.KMCGlobals._plm.CalcRMS = true; } catch (Exception ex) { BASSCloseStreamException(ex); } }