コード例 #1
0
ファイル: BASSControl.cs プロジェクト: walney/KMC
        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);
            }
        }