Exemplo n.º 1
0
 public void ReSync()
 {
     if (!base.IsAssigned)
     {
         return;
     }
     if (this._isOutputBuffered && this.TargetMixerStream != 0 && this.SourceMixerStream != 0)
     {
         Bass.BASS_ChannelLock(this.SourceMixerStream, true);
         int num = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
         if (num > 0)
         {
             num = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num));
             if (!this._isSourceMixerNonstop && this._isTargetMixerNonstop)
             {
                 this._streamCopyDelay = num;
                 BassMix.BASS_Mixer_ChannelSetPosition(this._streamCopy, 0L);
             }
             else if (!this._isTargetMixerNonstop)
             {
                 int num2 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                 num2 = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num2));
                 if (num2 > num)
                 {
                     byte[] buffer = new byte[num2 - num];
                     Bass.BASS_StreamPutData(this._streamCopy, buffer, num2 - num);
                 }
             }
         }
         else if (this._isSourceMixerNonstop)
         {
             int num3 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
             num3 = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num3));
             int num4 = (int)Bass.BASS_ChannelSeconds2Bytes(this._streamCopy, (double)this._outputLatency / 1000.0);
             if (num3 > num4)
             {
                 BassMix.BASS_Mixer_ChannelSetPosition(this._streamCopy, 0L);
                 byte[] buffer2 = new byte[num3 - num4];
                 Bass.BASS_StreamPutData(this._streamCopy, buffer2, num3 - num4);
             }
         }
         if (this._isTargetMixerImmediate && !this._isTargetMixerNonstop)
         {
             Bass.BASS_ChannelUpdate(this.TargetMixerStream, 0);
         }
         Bass.BASS_ChannelLock(this.SourceMixerStream, false);
     }
 }
Exemplo n.º 2
0
        private void Encode(string filename)
        {
            // Отключаем кнопки
            playButton.Enabled   = false;
            saveButton.Enabled   = false;
            selectButton.Enabled = false;

            encodeProgress.Visible = true;

            // Энкодим в мп3
            ThreadPool.QueueUserWorkItem(w =>
            {
                int encoder = BassEnc.BASS_Encode_Start(fxStream, "lame -b192 - \"" + filename + "\"", 0, null, IntPtr.Zero /*this.Handle*/);

                long i          = 0;
                long chanLenght = Bass.BASS_ChannelGetLength(fxStream);
                while (i < chanLenght - 1)
                {
                    // Так как буфер в 1сек, то и записываем по одной секунде данных в проход
                    Bass.BASS_ChannelSetPosition(fxStream, i, BASSMode.BASS_POS_BYTES);
                    long len = Bass.BASS_ChannelSeconds2Bytes(fxStream, 1);
                    Bass.BASS_ChannelUpdate(fxStream, 1000);

                    i += len;

                    this.Invoke((MethodInvoker) delegate
                    {
                        encodeProgress.Value = (int)(i * 100 / chanLenght);
                        debugInfo.Text       = Bass.BASS_ErrorGetCode().ToString() + "\n" + len + "\n" + i + "\n" + Bass.BASS_ChannelGetLength(fxStream);
                    });
                }

                // ехал инвок через инвок
                this.Invoke((MethodInvoker) delegate
                {
                    encodeProgress.Visible = false;

                    playButton.Enabled   = true;
                    saveButton.Enabled   = true;
                    selectButton.Enabled = true;
                });

                BassEnc.BASS_Encode_Stop(encoder);
            });
        }
Exemplo n.º 3
0
        /***************  Ctrl  ************************/
        public void Play()
        {
            if (CurrentMusicHandle == 0)
            {
                Debug.LogError("No music loading");
                return;
            }
            BASSActive bASSActive = Bass.BASS_ChannelIsActive(CurrentMusicHandle);

            if (bASSActive == BASSActive.BASS_ACTIVE_PAUSED) //如果暂停了,重新播放
            {
                Bass.BASS_ChannelPlay(CurrentMusicHandle, false);
            }
            else  //否则重头开始播放
            {
                //预缓冲
                Bass.BASS_ChannelUpdate(CurrentMusicHandle, 0);
                //播放 是否重新开始
                Bass.BASS_ChannelPlay(CurrentMusicHandle, true);
            }
        }
Exemplo n.º 4
0
        public override void OnStarted()
        {
            int num = Bass.BASS_GetDevice();

            if (num != this._streamCopyDevice)
            {
                Bass.BASS_SetDevice(this._streamCopyDevice);
            }
            if (base.ChannelBitwidth == 32)
            {
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_8BITS;
                this._streamCopyFlags |= BASSFlag.BASS_SAMPLE_FLOAT;
            }
            else if (base.ChannelBitwidth == 8)
            {
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_FLOAT;
                this._streamCopyFlags |= BASSFlag.BASS_SAMPLE_8BITS;
            }
            else
            {
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_FLOAT;
                this._streamCopyFlags &= ~BASSFlag.BASS_SAMPLE_8BITS;
            }
            int num2 = Bass.BASS_StreamCreatePush(base.ChannelSampleRate, base.ChannelNumChans, this._streamCopyFlags, IntPtr.Zero);

            this._streamCopyDelay = 0;
            if (this.SourceMixerStream == 0)
            {
                Bass.BASS_ChannelLock(base.ChannelHandle, true);
            }
            else
            {
                Bass.BASS_ChannelLock(this.SourceMixerStream, true);
            }
            if (this._isOutputBuffered)
            {
                if (this.SourceMixerStream != 0)
                {
                    if (this.TargetMixerStream != 0)
                    {
                        if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                        {
                            int num3 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                            int num4 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                            num4 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num4));
                            if (num4 > 0)
                            {
                                num3 -= num4;
                            }
                            if (num3 > 0)
                            {
                                int num5 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                                if (num4 > 0)
                                {
                                    num5 = 0;
                                }
                                byte[] array = new byte[num3];
                                num3 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array, num3);
                                if (num3 > num5)
                                {
                                    if (num5 > 0)
                                    {
                                        Array.Copy(array, num5, array, 0, num3 - num5);
                                    }
                                    Bass.BASS_StreamPutData(num2, array, num3 - num5);
                                }
                            }
                        }
                        else
                        {
                            int num6 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                            num6 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num6));
                            int num7 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                            num7  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num7));
                            num6 -= num7;
                            if (num6 > 0)
                            {
                                int num8 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                                if (num7 > 0)
                                {
                                    num8 = 0;
                                }
                                byte[] array2 = new byte[num6];
                                if (!base.ChannelInfo.IsDecodingChannel)
                                {
                                    num6 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array2, num6);
                                    num6 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num6));
                                }
                                if (num6 > num8)
                                {
                                    if (num8 > 0)
                                    {
                                        Array.Copy(array2, num8, array2, 0, num6 - num8);
                                    }
                                    Bass.BASS_StreamPutData(num2, array2, num6 - num8);
                                }
                            }
                        }
                    }
                    else if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                    {
                        int num9 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                        if (num9 > 0)
                        {
                            int    num10  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                            byte[] array3 = new byte[num9];
                            num9 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array3, num9);
                            if (num9 > num10)
                            {
                                if (num10 > 0)
                                {
                                    Array.Copy(array3, num10, array3, 0, num9 - num10);
                                }
                                Bass.BASS_StreamPutData(num2, array3, num9 - num10);
                            }
                        }
                    }
                    else
                    {
                        int num11 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                        num11 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num11));
                        if (num11 > 0)
                        {
                            int    num12  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                            byte[] array4 = new byte[num11];
                            if (!base.ChannelInfo.IsDecodingChannel)
                            {
                                num11 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array4, num11);
                                num11 = (int)Bass.BASS_ChannelSeconds2Bytes(num2, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num11));
                            }
                            if (num11 > num12)
                            {
                                if (num12 > 0)
                                {
                                    Array.Copy(array4, num12, array4, 0, num11 - num12);
                                }
                                Bass.BASS_StreamPutData(num2, array4, num11 - num12);
                            }
                        }
                    }
                }
                else if (!base.ChannelInfo.IsDecodingChannel)
                {
                    int    num13  = (int)Bass.BASS_ChannelSeconds2Bytes(num2, (double)this._outputLatency / 1000.0);
                    int    num14  = Bass.BASS_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                    byte[] array5 = new byte[num14];
                    num14 = Bass.BASS_ChannelGetData(base.ChannelHandle, array5, num14);
                    if (num14 > num13)
                    {
                        if (num13 > 0)
                        {
                            Array.Copy(array5, num13, array5, 0, num14 - num13);
                        }
                        Bass.BASS_StreamPutData(num2, array5, num14 - num13);
                    }
                }
            }
            this._streamCopy = num2;
            if (this.TargetMixerStream != 0 && (this._streamCopyFlags & BASSFlag.BASS_STREAM_DECODE) != BASSFlag.BASS_DEFAULT)
            {
                BassMix.BASS_Mixer_StreamAddChannel(this.TargetMixerStream, this._streamCopy, ((BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT) ? BASSFlag.BASS_RECORD_ECHOCANCEL : BASSFlag.BASS_DEFAULT);
                if (!this._isTargetMixerImmediate && !this._isTargetMixerNonstop)
                {
                    Bass.BASS_ChannelUpdate(this.TargetMixerStream, 0);
                }
            }
            if ((!base.ChannelInfo.IsDecodingChannel || this.SourceMixerStream != 0) && Bass.BASS_ChannelIsActive(base.ChannelHandle) == BASSActive.BASS_ACTIVE_PLAYING)
            {
                Bass.BASS_ChannelPlay(this._streamCopy, false);
            }
            if (this.SourceMixerStream == 0)
            {
                Bass.BASS_ChannelLock(base.ChannelHandle, false);
            }
            else
            {
                Bass.BASS_ChannelLock(this.SourceMixerStream, false);
            }
            if (!base.ChannelInfo.IsDecodingChannel)
            {
                Bass.BASS_ChannelSetLink(base.ChannelHandle, this._streamCopy);
            }
            Bass.BASS_SetDevice(num);
        }
Exemplo n.º 5
0
 public override void OnBypassChanged()
 {
     if (base.IsBypassed)
     {
         if (this._isOutputBuffered && !base.ChannelInfo.IsDecodingChannel)
         {
             Bass.BASS_ChannelPause(this._streamCopy);
             Bass.BASS_ChannelSetPosition(this._streamCopy, 0L);
             return;
         }
     }
     else
     {
         int streamCopy = this._streamCopy;
         this._streamCopy = 0;
         if (this.SourceMixerStream == 0)
         {
             Bass.BASS_ChannelLock(base.ChannelHandle, true);
         }
         else
         {
             Bass.BASS_ChannelLock(this.SourceMixerStream, true);
         }
         if (this._isOutputBuffered)
         {
             if (this.SourceMixerStream != 0)
             {
                 if (this.TargetMixerStream != 0)
                 {
                     if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                     {
                         int num  = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                         int num2 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                         num2 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num2));
                         if (num2 > 0)
                         {
                             num -= num2;
                         }
                         if (num > 0)
                         {
                             int num3 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                             if (num2 > 0)
                             {
                                 num3 = 0;
                             }
                             byte[] array = new byte[num];
                             num = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array, num);
                             if (num > num3)
                             {
                                 if (num3 > 0)
                                 {
                                     Array.Copy(array, num3, array, 0, num - num3);
                                 }
                                 Bass.BASS_StreamPutData(streamCopy, array, num - num3);
                             }
                         }
                     }
                     else
                     {
                         int num4 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                         num4 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num4));
                         int num5 = Bass.BASS_ChannelGetData(this.TargetMixerStream, IntPtr.Zero, 0);
                         num5  = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.TargetMixerStream, (long)num5));
                         num4 -= num5;
                         if (num4 > 0)
                         {
                             int num6 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                             if (num5 > 0)
                             {
                                 num6 = 0;
                             }
                             byte[] array2 = new byte[num4];
                             if (!base.ChannelInfo.IsDecodingChannel)
                             {
                                 num4 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array2, num4);
                                 num4 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num4));
                             }
                             if (num4 > num6)
                             {
                                 if (num6 > 0)
                                 {
                                     Array.Copy(array2, num6, array2, 0, num4 - num6);
                                 }
                                 Bass.BASS_StreamPutData(streamCopy, array2, num4 - num6);
                             }
                         }
                     }
                 }
                 else if (base.ChannelInfo.IsDecodingChannel && (BassMix.BASS_Mixer_ChannelFlags(base.ChannelHandle, BASSFlag.BASS_RECORD_ECHOCANCEL, BASSFlag.BASS_DEFAULT) & BASSFlag.BASS_RECORD_ECHOCANCEL) != BASSFlag.BASS_DEFAULT)
                 {
                     int num7 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                     if (num7 > 0)
                     {
                         int    num8   = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                         byte[] array3 = new byte[num7];
                         num7 = BassMix.BASS_Mixer_ChannelGetData(base.ChannelHandle, array3, num7);
                         if (num7 > num8)
                         {
                             if (num8 > 0)
                             {
                                 Array.Copy(array3, num8, array3, 0, num7 - num8);
                             }
                             Bass.BASS_StreamPutData(streamCopy, array3, num7 - num8);
                         }
                     }
                 }
                 else
                 {
                     int num9 = Bass.BASS_ChannelGetData(this.SourceMixerStream, IntPtr.Zero, 0);
                     num9 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num9));
                     if (num9 > 0)
                     {
                         int    num10  = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                         byte[] array4 = new byte[num9];
                         if (!base.ChannelInfo.IsDecodingChannel)
                         {
                             num9 = Bass.BASS_ChannelGetData(this.SourceMixerStream, array4, num9);
                             num9 = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, Bass.BASS_ChannelBytes2Seconds(this.SourceMixerStream, (long)num9));
                         }
                         if (num9 > num10)
                         {
                             if (num10 > 0)
                             {
                                 Array.Copy(array4, num10, array4, 0, num9 - num10);
                             }
                             Bass.BASS_StreamPutData(streamCopy, array4, num9 - num10);
                         }
                     }
                 }
             }
             else if (!base.ChannelInfo.IsDecodingChannel)
             {
                 int    num11  = (int)Bass.BASS_ChannelSeconds2Bytes(streamCopy, (double)this._outputLatency / 1000.0);
                 int    num12  = Bass.BASS_ChannelGetData(base.ChannelHandle, IntPtr.Zero, 0);
                 byte[] array5 = new byte[num12];
                 num12 = Bass.BASS_ChannelGetData(base.ChannelHandle, array5, num12);
                 if (num12 > num11)
                 {
                     if (num11 > 0)
                     {
                         Array.Copy(array5, num11, array5, 0, num12 - num11);
                     }
                     Bass.BASS_StreamPutData(streamCopy, array5, num12 - num11);
                 }
             }
         }
         this._streamCopy = streamCopy;
         if (this.TargetMixerStream != 0 && !this._isTargetMixerImmediate && !this._isTargetMixerNonstop)
         {
             Bass.BASS_ChannelUpdate(this.TargetMixerStream, 0);
         }
         if ((!base.ChannelInfo.IsDecodingChannel || this.SourceMixerStream != 0) && Bass.BASS_ChannelIsActive(base.ChannelHandle) == BASSActive.BASS_ACTIVE_PLAYING)
         {
             Bass.BASS_ChannelPlay(this._streamCopy, false);
         }
         if (this.SourceMixerStream == 0)
         {
             Bass.BASS_ChannelLock(base.ChannelHandle, false);
             return;
         }
         Bass.BASS_ChannelLock(this.SourceMixerStream, false);
     }
 }
Exemplo n.º 6
0
        private void PreviewThread_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                // Init BASS
                ChangePreviewButtonText("Initializing BASS...", false);
                ChangeWindowTitle("Initializing BASS...");
                Bass.BASS_StreamFree(hStream);
                Bass.BASS_MusicFree(hStream);
                Bass.BASS_Free();
                Bass.BASS_Init(-1, Convert.ToInt32(Program.SynthSettings.GetValue("AudioFrequency", 48000)), BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero);
                BASS_INFO info = Bass.BASS_GetInfo();
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, 0);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, info.minbuf + 10 + 50);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, Convert.ToInt32(Program.SynthSettings.GetValue("MaxVoices", 500)));
                System.Threading.Thread.Sleep(200);

                if (Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".xm" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".it" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".s3m" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".mod" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".mtm" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".umx")
                {
                    InitializeBASSMODStream();
                }
                else if (Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".mid" ||
                         Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".midi" ||
                         Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".rmi")
                {
                    InitializeBASSMIDIStream();
                }
                else
                {
                    MessageBox.Show("This is not a valid MIDI file.\n\nClick OK to abort.", "OmniMIDI- Preview error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ChangePreviewButtonText("Play SoundFont preview", true);
                    ChangeWindowTitle("Information about the SoundFont");
                    this.Invoke((MethodInvoker) delegate
                    {
                        StartNormalPrvw1.Enabled = true;
                        StartNormalPrvw2.Enabled = true;
                        StartNormalPrvw3.Enabled = true;
                        StartCustomPrvw.Enabled  = true;
                    });
                    Bass.BASS_Free();
                    return;
                }

                long len = Bass.BASS_ChannelGetLength(hStream, BASSMode.BASS_POS_BYTE);
                Bass.BASS_ChannelPlay(hStream, false);
                ChangePreviewButtonText("Stop SoundFont preview", true);
                ChangeWindowTitle(String.Format("Playing \"{0}\"", Path.GetFileNameWithoutExtension(MIDIPreview)));

                while (Bass.BASS_ChannelIsActive(hStream) == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    Bass.BASS_ChannelUpdate(hStream, 0);
                    if (!IsPreviewEnabled)
                    {
                        break;
                    }
                    Thread.Sleep(1);
                }

                if (!Quitting)
                {
                    ChangePreviewButtonText("Play SoundFont preview", true);
                    ChangeWindowTitle("Information about the SoundFont");
                    this.Invoke((MethodInvoker) delegate
                    {
                        StartNormalPrvw1.Enabled = true;
                        StartNormalPrvw2.Enabled = true;
                        StartNormalPrvw3.Enabled = true;
                        StartCustomPrvw.Enabled  = true;
                    });
                }

                Bass.BASS_StreamFree(hStream);
                Bass.BASS_MusicFree(hStream);
                Bass.BASS_Free();
            }
            catch { }
        }
Exemplo n.º 7
0
        private void PreviewThread_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                // Init BASS
                ChangePreviewButtonText("Initializing BASS...", false);
                ChangeWindowTitle("Initializing BASS...");
                Bass.BASS_StreamFree(hStream);
                Bass.BASS_MusicFree(hStream);
                Bass.BASS_Free();
                Bass.BASS_Init(-1, Convert.ToInt32(KeppySynthConfiguratorMain.Delegate.Frequency.Text), BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero);
                BASS_INFO info = Bass.BASS_GetInfo();
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATETHREADS, 0);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, info.minbuf + 10 + 50);
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_MIDI_VOICES, Convert.ToInt32(KeppySynthConfiguratorMain.Delegate.PolyphonyLimit.Value));
                System.Threading.Thread.Sleep(200);

                if (Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".xm" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".it" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".s3m" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".mod" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".mtm" ||
                    Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".umx")
                {
                    InitializeBASSMODStream();
                }
                else if (Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".mid" ||
                         Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".midi" ||
                         Path.GetExtension(MIDIPreview).ToLowerInvariant() == ".rmi")
                {
                    InitializeBASSMIDIStream();
                }
                else
                {
                    MessageBox.Show("This is not a valid MIDI file.\n\nClick OK to abort.", "Keppy's Synthesizer - Preview error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ChangePreviewButtonText("Play SoundFont preview", true);
                    ChangeWindowTitle("Information about the SoundFont");
                    this.Invoke((MethodInvoker) delegate
                    {
                        StartNormalPrvw1.Enabled = true;
                        StartNormalPrvw2.Enabled = true;
                        StartNormalPrvw3.Enabled = true;
                        StartCustomPrvw.Enabled  = true;
                    });
                    Bass.BASS_Free();
                    return;
                }

                int howmanytimes = 1;

RestartStream:
                CheckPlayTimes(howmanytimes);
                Bass.BASS_ChannelPlay(hStream, false);
                ChangePreviewButtonText("Stop SoundFont preview", true);
                ChangeWindowTitle(String.Format("Playing \"{0}\"", Path.GetFileNameWithoutExtension(MIDIPreview)));

                while (Bass.BASS_ChannelIsActive(hStream) == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    Bass.BASS_ChannelUpdate(hStream, 0);
                    if (!IsPreviewEnabled)
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(1);
                }

                if (!Quitting)
                {
                    if (LoopYesNo.Checked == true && IsPreviewEnabled == true)
                    {
                        howmanytimes++;
                        goto RestartStream;
                    }

                    ChangePreviewButtonText("Play SoundFont preview", true);
                    ChangeWindowTitle("Information about the SoundFont");
                    this.Invoke((MethodInvoker) delegate
                    {
                        StartNormalPrvw1.Enabled = true;
                        StartNormalPrvw2.Enabled = true;
                        StartNormalPrvw3.Enabled = true;
                        StartCustomPrvw.Enabled  = true;
                    });
                }

                Bass.BASS_StreamFree(hStream);
                Bass.BASS_MusicFree(hStream);
                Bass.BASS_Free();
            }
            catch
            {
            }
        }