コード例 #1
0
        /// <summary>
        /// Gets the current stream position.
        /// </summary>
        /// <returns></returns>
        public TimeSpan GetPosition()
        {
            long bytes = Bass.BASS_ChannelGetPosition(Handle);

            if (bytes == -1)
            {
                CheckException("BASS_ChannelGetPosition");
                return(TimeSpan.Zero);
            }

            double seconds = Bass.BASS_ChannelBytes2Seconds(Handle, bytes);

            return(TimeSpan.FromSeconds(seconds));
        }
コード例 #2
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (bRestart)
            {
                bRestart = false;
                Audio_Stop();
                Audio_Start();
            }

            pct = (double)(fpos = Bass.BASS_ChannelGetPosition(Audio_Stream)) / flen;

            if (bSpiral)
            {
                double eee    = (DateTime.Now.Ticks / 10000000 % 61) / 61.0;              //31,61,101
                double spiral = Math.Sin(Math.PI * 2.0 * eee);
                double kkk    = (bInside ? 1.0 + Math.Abs(spiral) / 9.0 : 1.0 - Math.Abs(spiral) / 18.0);
                for (int i = 0; i < DISTORTION; i++)
                {
                    double a = (double)(DISTORTION - 1 - i) / DISTORTION;
                    a        = alpha + spiral * a * a;
                    Xrot [i] = Math.Cos(a) * kkk;
                    Yrot [i] = Math.Sin(a) * kkk;
                }
            }

            if (iFilter != iFilter2)
            {
                iFilter2 = iFilter;
                Xfir     = Mfir [iFilter, 0];
                Yfir     = Mfir [iFilter, 1];
            }

            if (bFlex)
            {
                Palitra = DateTime.Now.Ticks / 10000000 % 100 / 100.0;                 // дрейф палитры
            }

            if (bDistortion)
            {
                kDistortion = 0.5 * Math.Sin(2.0 * Math.PI * (System.Environment.TickCount / 1000 & 127) / 127.0);                 // дрейф искажения
                double kk = (bInside ? (kDistortion < 0.0 ? 0.0 : Math.Abs(kDistortion) / 2.0) : (kDistortion < 0.0 ? -Math.Abs(kDistortion) / 2.0 : 0.0));
                for (int i = 0; i < DISTORTION; i++)
                {
                    DistortionTab [i] = kDistortion * ((double)i / DISTORTION - 1.0) + 1.0 + kk;
                }
            }

            timer1.Interval = Interval;
        }
コード例 #3
0
        public List <int> GetPosOfStream()
        {
            List <int> time      = new List <int>();
            long       TimeBytes = Bass.BASS_ChannelGetPosition(_stream);
            int        Seconds   = (int)Bass.BASS_ChannelBytes2Seconds(_stream, TimeBytes);

            int Minutes = Seconds / 60;

            Seconds = Seconds - Minutes * 60;

            time.Add(Seconds);
            time.Add(Minutes);

            return(time);
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: wirmachenbunt/tooll
        private void Update()
        {
            var time = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetPosition(_soundStream, BASSMode.BASS_POS_BYTES));

            if (time >= _soundLength)
            {
                if (_settings.Looped)
                {
                    Bass.BASS_ChannelSetPosition(_soundStream, 0);
                }
                else if (!_exitTimer.IsRunning)
                {
                    _exitTimer.Restart();
                }
                else if (_exitTimer.ElapsedMilliseconds >= 2000)
                {
                    _form.Close();
                }
            }

//            try {
//                _undoRedoStack.ProcessReceivedCommands();
//            }
//            catch (Exception exception) {
//                Logger.Warn("Error when excecuting remote command: {0}", exception.Message);
//            }

            //double time = (double)_globalTime.ElapsedTicks / Stopwatch.Frequency;
            TimeLogger.BeginFrame(time);
            D3DDevice.BeginFrame();

            DrawFrame((float)time);

            D3DDevice.SwapChain.Present(_settings.VSyncEnabled ? 1 : 0, PresentFlags.None);

            Int64 elapsedTicks = _stopwatch.ElapsedTicks;

            Console.Write("time: {0:000.000}, fps: {1:000.0} ({2:000.0}/{3:000.0}), resources used: {4,2}, free: {5,2}      \r",
                          time, (double)_numMeasureValues * Stopwatch.Frequency / _averagedElapsed.Sum(e => e), (double)Stopwatch.Frequency / _averagedElapsed.Max(), (double)Stopwatch.Frequency / _averagedElapsed.Min(),
                          ResourceManager.NumUsedResources, ResourceManager.NumFreeResources);
            _averagedElapsed[_currentAveragedElapsedIndex] = elapsedTicks;
            _currentAveragedElapsedIndex++;
            _currentAveragedElapsedIndex %= _numMeasureValues;
            _stopwatch.Restart();

            D3DDevice.EndFrame();
            TimeLogger.EndFrame();
        }
コード例 #5
0
        private void updateTimer_Tick(object sender, EventArgs e)
        {
            if (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
            {
            }
            else
            {
                updateTimer.Stop();
                progressBarPeakLeft.Value  = 0;
                progressBarPeakRight.Value = 0;
                lblTime.Text = "Stopped";
                drawWavePosition(-1, -1);
                pictureBoxSpectrum.Image = null;
                btnStop.Enabled          = false;
                btnPlay.Enabled          = true;
                return;
            }
            tickCounter++;

            long position = Bass.BASS_ChannelGetPosition(stream);
            long length   = Bass.BASS_ChannelGetLength(stream);

            if (tickCounter == 5)
            {
                tickCounter = 0;
                double totaltime   = Bass.BASS_ChannelBytes2Seconds(stream, length);
                double elapsedtime = Bass.BASS_ChannelBytes2Seconds(stream, position);

                double remaingtime = totaltime - elapsedtime;

                lblTime.Text = String.Format("Elapsed: {0:#0.00} - Total: {1:#0.00} - Remain: {2:#0.00}", Utils.FixTimespan(elapsedtime, "MMSS"), Utils.FixTimespan(totaltime, "MMSS"), Utils.FixTimespan(remaingtime, "MMSS"));
            }

            int peakL = 0;
            int peakR = 0;

            RMS(stream, out peakL, out peakR);

            double dblevelL = Utils.LevelToDB(peakL, 65535);
            double dbLevelR = Utils.LevelToDB(peakR, 65535);

            this.progressBarPeakLeft.Value  = peakL;
            this.progressBarPeakRight.Value = peakR;

            drawWavePosition(position, length);

            drawSpectrum();
        }
コード例 #6
0
 /// <summary>
 ///     Gets the current audioStream position.
 /// </summary>
 /// <param name="audioStream">The audio stream.</param>
 /// <returns>The current audio stream position</returns>
 public static long GetPosition(AudioStream audioStream)
 {
     if (audioStream == null)
     {
         return(0);
     }
     if (!audioStream.IsAudioLoaded())
     {
         return(0);
     }
     //lock (Lock)
     {
         var position = Bass.BASS_ChannelGetPosition(audioStream.ChannelId);
         Thread.Sleep(1);
         return(position);
     }
 }
コード例 #7
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            Config.Position = Bass.BASS_ChannelGetPosition(Config.Stream, BASSMode.BASS_POS_BYTES);
            if (Config.Position == Length)
            {
                switch (Config.PlayMode)
                {
                case PlayMode.SinglePlay:
                    PlayCommandExecute();
                    break;

                default:
                    NextCommandExecute();
                    break;
                }
            }
        }
コード例 #8
0
        internal static void UpdateAudioTime()
        {
            audioTimeRaw = Bass.BASS_ChannelGetPosition(audioStream);


            //force a stopped state when reaching end of song
            if (AudioState != AudioStates.Stopped && audioTimeRaw == audioLengthRaw)
            {
                AudioState = AudioStates.Stopped;
            }

            if (cachedSeek >= 0)
            {
                audioTime = (float)(cachedSeek) / 1000;
            }
            else if (audioStream != 0)
            {
                audioTime = Bass.BASS_ChannelBytes2Seconds(audioStream, audioTimeRaw);
            }
            else
            {
                audioTime = 0;
            }


            TimeRaw = (int)Math.Round(audioTime * 1000);

            Offset = BeatmapManager.Current != null && BeatmapManager.Current.BeatmapVersion < 5 &&
                     GameBase.Mode != Modes.Edit
                         ? 24
                         : 0;
            Offset += GameBase.Mode != Modes.Edit && BeatmapManager.Current != null
                          ? BeatmapManager.Current.PlayerOffset
                          : 0;
            if (audioRate < 100)
            {
                Offset -= (int)(((100 - audioRate) / 75f) * 30);
            }

            Offset -= (int)((audioRate / 100f) * ConfigManager.sOffset);

            if (UpdateTime)
            {
                Time = TimeRaw - Offset;
            }
        }
コード例 #9
0
 public void StopFile(int handle, bool fadeOut, int fadeOutTime, bool isCrossFade)
 {
     if (!fadeOut || fadeOutTime == 0)
     {
         Bass.BASS_ChannelStop(handle); // no error handling, unimportant
         FileFinished(handle, true);
     }
     else
     {
         long pos           = Bass.BASS_ChannelGetPosition(handle);
         long length        = Bass.BASS_ChannelGetLength(handle);
         long remaining     = length - pos;
         long fadeOutLength = Bass.BASS_ChannelSeconds2Bytes(handle, 0.001 * fadeOutTime);
         if (fadeOutLength == -1)
         {
             // on error, just stop the file
             Bass.BASS_ChannelStop(handle);
             FileFinished(handle, true);
             return;
         }
         if (pos == -1 || length == -1 || remaining <= 0)
         {
             // web radio doesn't have a length
             remaining = fadeOutLength;
         }
         if (fadeOutLength > remaining)
         {
             fadeOutLength = remaining;
         }
         // if (Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_POS, pos + fadeOutLength, m_StopSync, new IntPtr(0)) == 0)
         if (Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_SLIDE | BASSSync.BASS_SYNC_ONETIME, 0, m_StopSync, new IntPtr(handle)) == 0)
         {
             // on error, just stop the file
             Bass.BASS_ChannelStop(handle);
             FileFinished(handle, true);
             return;
         }
         FadeOut(handle, fadeOutTime);
         if (isCrossFade)
         {
             // call finished immediately to start the next file
             FileFinished(handle, false);
         }
     }
 }
コード例 #10
0
        private string getTime(int channel)
        {
            // Format the string of "elapsed time / totaltime"
            long len = Bass.BASS_ChannelGetLength(channel);   // get length of song
            long pos = Bass.BASS_ChannelGetPosition(channel); // get position in the song

            double totaltime   = Bass.BASS_ChannelBytes2Seconds(channel, len);
            double elapsedtime = Bass.BASS_ChannelBytes2Seconds(channel, pos);

            int minutes1 = Convert.ToInt16(elapsedtime / 60.0);
            int seconds1 = Convert.ToInt16(elapsedtime % 60.0);
            int minutes2 = Convert.ToInt16(totaltime / 60.0);
            int seconds2 = Convert.ToInt16(totaltime % 60.0);
            // not sure if it's silly to recreate lots of timespans
            TimeSpan left  = new TimeSpan(0, minutes1, seconds1);
            TimeSpan right = new TimeSpan(0, minutes2, seconds2);

            return(left.ToString() + " | " + right.ToString());
        }
コード例 #11
0
ファイル: App.xaml.cs プロジェクト: wirmachenbunt/tooll
        private void UpdateGlobalTime()
        {
            double newTime = Model.GlobalTime + MainWindow.CompositionView.PlaySpeed * TimeSinceLastFrame;

            // During playback override time from soundtrack
            if (Bass.BASS_ChannelIsActive(m_SoundStream) != BASSActive.BASS_ACTIVE_STOPPED &&
                IsPlayingForward() &&
                IsTimeWithinSongRange(newTime))
            {
                newTime = Bass.BASS_ChannelBytes2Seconds(m_SoundStream,
                                                         Bass.BASS_ChannelGetPosition(m_SoundStream, BASSMode.BASS_POS_BYTES));
            }

            if (App.Current.MainWindow.CompositionView.XTimeView.LoopMode && IsPlayingForward())
            {
                if (newTime > MainWindow.CompositionView.XTimeView.EndTime)
                {
                    newTime = MainWindow.CompositionView.XTimeView.StartTime;
                    SetStreamToTime(newTime);
                }
            }

            if (IsTimeWithinSongRange(newTime))
            {
                if (!IsPlayingForward())
                {
                    SetStreamToTime(newTime);
                }
                else if (Bass.BASS_ChannelIsActive(m_SoundStream) != BASSActive.BASS_ACTIVE_PLAYING)
                {
                    Bass.BASS_ChannelPlay(m_SoundStream, false);
                }
            }
            else
            {
                Bass.BASS_ChannelPause(m_SoundStream);
            }

            if (Model.GlobalTime != newTime)    // Prevent triggering Dependency property change
            {
                Model.GlobalTime = newTime;
            }
        }
コード例 #12
0
ファイル: AudioSample.cs プロジェクト: Anegorami/EUAP
        /// <summary>
        /// Update method.
        /// </summary>
        public void Update()
        {
            if (looped)
            {
                foreach (int channel in channels)
                {
                    long   current_position_bytes = Bass.BASS_ChannelGetPosition(channel);
                    double current_position       = Bass.BASS_ChannelBytes2Seconds(channel, current_position_bytes);

                    if (current_position > loop_end)
                    {
                        double new_position = loop_start + (current_position - loop_end);
                        Bass.BASS_ChannelSetPosition(channel, new_position);
                    }
                }
            }

            channels.RemoveAll(IsChannelInactive);
        }
コード例 #13
0
ファイル: MixerStream.cs プロジェクト: edalex86/MediaPortal-1
        /// <summary>
        /// Sets a SyncPos on the mixer stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="timePos"></param>
        public void SetSyncPos(MusicStream stream, double timePos)
        {
            double fadeOutSeconds = Config.CrossFadeIntervalMs / 1000.0;
            double totalStreamLen = Bass.BASS_ChannelBytes2Seconds(stream.BassStream, Bass.BASS_ChannelGetLength(stream.BassStream, BASSMode.BASS_POS_BYTES));
            long   mixerPos       = Bass.BASS_ChannelGetPosition(_mixer, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
            long   syncPos        = mixerPos + Bass.BASS_ChannelSeconds2Bytes(_mixer, totalStreamLen - timePos - fadeOutSeconds);

            if (_syncProc != 0)
            {
                Bass.BASS_ChannelRemoveSync(_mixer, _syncProc);
            }

            GCHandle pFilePath = GCHandle.Alloc(stream);

            _syncProc = Bass.BASS_ChannelSetSync(_mixer,
                                                 BASSSync.BASS_SYNC_ONETIME | BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
                                                 syncPos, _playbackEndProcDelegate,
                                                 GCHandle.ToIntPtr(pFilePath));
        }
コード例 #14
0
ファイル: SimpleFX.cs プロジェクト: MackZ28/EZiePlayer
        private void timerUpdate_Tick(object sender, System.EventArgs e)
        {
            // here we gather info about the stream, when it is playing...
            if (Bass.BASS_ChannelIsActive(_StreamFX) == BASSActive.BASS_ACTIVE_PLAYING)
            {
                // the stream is still playing...
                this.labelBPM.BackColor = SystemColors.Control;
            }
            else
            {
                // the stream is NOT playing anymore...
                this.timerUpdate.Stop();
                this.progressBarPeakLeft.Value  = 0;
                this.progressBarPeakRight.Value = 0;
                this.labelTime.Text             = "Stopped";
                return;
            }

            // display the level bars
            int    peakL = 0;
            int    peakR = 0;
            double rms   = RMS(_StreamFX, out peakL, out peakR);

            this.progressBarPeakLeft.Value  = peakL;
            this.progressBarPeakRight.Value = peakR;

            // from here on, the stream is for sure playing...
            _TickCounter++;
            if (_TickCounter == 4)
            {
                // display the position every 200ms (since timer is 50ms)
                _TickCounter = 0;
                long   len           = Bass.BASS_ChannelGetLength(_StreamFX);          // length in bytes
                long   pos           = Bass.BASS_ChannelGetPosition(_StreamFX);        // position in bytes
                double totaltime     = Bass.BASS_ChannelBytes2Seconds(_StreamFX, len); // the total time length
                double elapsedtime   = Bass.BASS_ChannelBytes2Seconds(_StreamFX, pos); // the elapsed time length
                double remainingtime = totaltime - elapsedtime;
                this.labelTime.Text     = String.Format("Elapsed: {0} - Total: {1} - Remain: {2}", Utils.FixTimespan(elapsedtime, "MMSS"), Utils.FixTimespan(totaltime, "MMSS"), Utils.FixTimespan(remainingtime, "MMSS"));
                this.Text               = String.Format("CPU: {0:0.00}%", Bass.BASS_GetCPU());
                this.labelRMSValue.Text = Utils.LevelToDB(rms, 1d).ToString("0.0");
            }
        }
コード例 #15
0
        private void Plus_B_Click(object sender, RoutedEventArgs e)
        {
            if (IsClosing)
            {
                return;
            }
            long position = Bass.BASS_ChannelGetPosition(Stream);

            if (Bass.BASS_ChannelBytes2Seconds(Stream, position) + 5 > Location_S.Maximum)
            {
                Music_Pos_Change(Location_S.Maximum, true);
            }
            else
            {
                Music_Pos_Change(Bass.BASS_ChannelBytes2Seconds(Stream, position) + 5, true);
            }
            long position2 = Bass.BASS_ChannelGetPosition(Stream);

            Location_S.Value = Bass.BASS_ChannelBytes2Seconds(Stream, position2);
        }
コード例 #16
0
 private void Rewind_MouseUp()
 {
     try
     {
         Bass.BASS_ChannelPause(model.stream);
         double end    = Bass.BASS_ChannelBytes2Seconds(model.stream, Bass.BASS_ChannelGetLength(model.stream));
         double newPos = view.musicProgress.Value * end / 100;
         Bass.BASS_ChannelSetPosition(model.stream, newPos);
         int allInterval = (int)Bass.BASS_ChannelBytes2Seconds(model.stream, Bass.BASS_ChannelGetLength(model.stream));
         int newInterval = (int)Bass.BASS_ChannelBytes2Seconds(model.stream, Bass.BASS_ChannelGetPosition(model.stream));
         view.timerForChange.Interval = (allInterval - newInterval) * 1000;
         BarTimer.Start();
         view.timerForChange.Start();
         Bass.BASS_ChannelPlay(model.stream, false);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error");
     }
 }
コード例 #17
0
ファイル: Player.cs プロジェクト: yarwelp/tooll
 private void KeyDownHandler(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Left)
     {
         var time = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetPosition(_soundStream, BASSMode.BASS_POS_BYTES));
         Bass.BASS_ChannelSetPosition(_soundStream, time - 1);
     }
     if (e.KeyCode == Keys.Right)
     {
         var time = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetPosition(_soundStream, BASSMode.BASS_POS_BYTES));
         Bass.BASS_ChannelSetPosition(_soundStream, time + 1);
     }
     if (e.KeyCode == Keys.P)
     {
         using (Texture2D texture = Texture2D.FromSwapChain <Texture2D>(D3DDevice.SwapChain, 0)) {
             Directory.CreateDirectory("Temp/Screenshots");
             Texture2D.ToFile(D3DDevice.Device.ImmediateContext, texture, ImageFileFormat.Png, String.Format(@"Temp/Screenshots/{0}.png", DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss_fff")));
         }
     }
     e.Handled = true;
 }
コード例 #18
0
        void timer_Tick(object sender, EventArgs e)
        {
            var level = Bass.BASS_ChannelGetLevel(stream);
            var left  = Utils.LowWord32(level) / (double)Int16.MaxValue;
            var right = Utils.HighWord32(level) / (double)Int16.MaxValue;

            var diff = 200 * (left + right) - currentItem.VuValue;

            if (diff > 0)
            {
                currentItem.VuValue += diff / 10d;
            }
            else
            {
                currentItem.VuValue += diff / 20d;
            }

            currentItem.Time = TimeSpan.FromSeconds(
                Bass.BASS_ChannelBytes2Seconds(stream,
                                               Bass.BASS_ChannelGetPosition(stream)));
        }
コード例 #19
0
ファイル: frmMain.cs プロジェクト: wex/modplay
        private void timerUpdate_Tick(object sender, System.EventArgs e)
        {
            if (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING)
            {
            }
            else
            {
                _updateTimer.Stop();
                button1_Click(sender, e);
                return;
            }

            long   pos         = Bass.BASS_ChannelGetPosition(stream);
            long   len         = Bass.BASS_ChannelGetLength(stream);
            double totaltime   = Bass.BASS_ChannelBytes2Seconds(stream, len);
            double elapsedtime = Bass.BASS_ChannelBytes2Seconds(stream, pos);

            lblProgress.Text    = String.Format("{0:#0.00} / {1:#0.00}", Utils.FixTimespan(elapsedtime, "MMSS"), Utils.FixTimespan(totaltime, "MMSS"));
            barProgress.Maximum = (int)totaltime;
            barProgress.Value   = (int)elapsedtime;
        }
コード例 #20
0
 private void update_elapsedtime(object sender, EventArgs e)
 {
     if (Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_PLAYING)
     {
         double totaltime     = Bass.BASS_ChannelBytes2Seconds(_stream, Bass.BASS_ChannelGetLength(_stream));
         double elapsedtime   = Bass.BASS_ChannelBytes2Seconds(_stream, Bass.BASS_ChannelGetPosition(_stream));
         double remainingtime = totaltime - elapsedtime;
         LabelTime.Content     = String.Format(Utils.FixTimespan(elapsedtime, "MMSS"));
         LabelLeftTime.Content = " -" + String.Format(Utils.FixTimespan(remainingtime, "MMSS"));
         MainProgressBar.Value = (int)Bass.BASS_ChannelBytes2Seconds(_stream, Bass.BASS_ChannelGetPosition(_stream));
     }
     else if (Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_STOPPED)
     {
         _maintimer.Stop();
         iconPlay.Kind = MaterialDesignThemes.Wpf.PackIconKind.Play;
         Bass.BASS_ChannelStop(_stream);
         LabelTime.Content     = m_totaltime;
         LabelLeftTime.Content = String.Format(Utils.FixTimespan(00000, "MMSS"));
         System.Diagnostics.Debug.Write("stoped");
         return;
     }
 }
        private void TimerPosition1_Tick(object sender, EventArgs e)
        {
            Dispatcher.Invoke(new ThreadStart(delegate
            {
                Time1 = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream));
                Time2 = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream));

                var t1 = Convert.ToString((int)Time1 / 60);
                var t2 = Convert.ToString((int)Time1 % 60);
                if (t1.Length == 1)
                {
                    t1 = "0" + t1;
                }
                if (t2.Length == 1)
                {
                    t2 = "0" + t2;
                }
                TextTime.Text = t1 + " : " + t2;
                OldNumber     = CurrentPlayIndex;

                SliderTrack.Value        = Time1;
                MyTaskItem.ProgressValue = (Time1) / Time2;
                if (!Time1.Equals(Time2))
                {
                    return;
                }

                if (CurrentPlayIndex == CurrentListBox.Items.Count - 1)
                {
                    CurrentPlayIndex = 0;
                }
                else
                {
                    CurrentPlayIndex = CurrentPlayIndex + 1;
                }
                Play(CurrentListBox);
            }));
        }
コード例 #22
0
        internal void SetDirection(bool reverse)
        {
            if (IsDisposed)
            {
                return;
            }

            if (reverse == IsReversed)
            {
                return;
            }

            bool wasPlaying = State != AudioStates.Stopped;

            if (wasPlaying)
            {
                TogglePause();
            }

            long pos = Bass.BASS_ChannelGetPosition(audioStream);

            if (reverse)
            {
                audioStream = audioStreamBackwards;
            }
            else
            {
                audioStream = audioStreamForwards;
            }

            Bass.BASS_ChannelSetPosition(audioStream, pos);
            //Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_FREQ, audioFrequency);

            if (wasPlaying)
            {
                TogglePause();
            }
        }
コード例 #23
0
        private void timerUpdate_Tick(object sender, EventArgs e)
        {
            // here we gather info about the stream, when it is playing...
            if (Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PLAYING &&
                Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PAUSED)
            {
                // the stream is NOT playing anymore...
                _updateTimer.Stop();
                playBackSlider.Value     = 0;
                pictureBoxSpectrum.Image = null;
                return;
            }

            // from here on, the stream is for sure playing...
            _tickCounter++;

            if (_tickCounter == 5)
            {
                // display the position every 250ms (since timer is 50ms)
                _tickCounter = 0;
                double elapsedtime = Bass.BASS_ChannelBytes2Seconds(_stream, Bass.BASS_ChannelGetPosition(_stream));
                // the elapsed time length
                string timeFormatted = String.Format("{0:#0:00}", Utils.FixTimespan(elapsedtime, "MMSS"));

                // Move the PlaybackSlider
                playBackSlider.Value = (int)(Math.Round((elapsedtime / _songLength), 2) * 100.0);

                // Now Paint the time to the Picturebox
                Graphics g = Graphics.FromHwnd(pictureBoxTime.Handle);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.Black);
                g.DrawString(timeFormatted, new Font("Verdana", 18), new SolidBrush(Color.CornflowerBlue), 0, 0);
                g.Dispose();
            }

            // update spectrum
            DrawSpectrum();
        }
コード例 #24
0
        private void updateFrames()
        {
            double curSecond = Bass.BASS_ChannelBytes2Seconds(myStreamHandle, Bass.BASS_ChannelGetPosition(myStreamHandle, BASSMode.BASS_POS_BYTES));

            curFrame = myWaveForm.Position2Frames(Bass.BASS_ChannelGetPosition(myStreamHandle));
            //MessageBox.Show(curSecond + " " + curFrame);

            /*
             * double secondOffset = myWaveForm.FrameResolution*5;
             * double secondLeft = curSecond - secondOffset;
             * double secondRight = curSecond + secondOffset;*/


//            startFrame = curFrame - framesOffset / 2;
            endFrame   = curFrame + framesOffset;
            startFrame = curFrame;
            //if (curFrame > framesOffset)
            //{
            //    endFrame = curFrame;
            //}
            //else endFrame = framesOffset;
            //startFrame = endFrame-framesOffset;
        }
コード例 #25
0
        /// <summary>
        ///   Starts encoding using the given Parameters
        /// </summary>
        /// <param name = "stream"></param>
        /// <param name = "encoderParms"></param>
        public BASSError StartEncoding(int stream)
        {
            BaseEncoder encoder = SetEncoderSettings(stream);

            encoder.EncoderDirectory = _pathToEncoders;
            encoder.OutputFile       = _outFile;
            encoder.InputFile        = null; // Use stdin

            bool encoderHandle = encoder.Start(null, IntPtr.Zero, false);

            if (!encoderHandle)
            {
                return(Bass.BASS_ErrorGetCode());
            }

            long pos        = 0;
            long chanLength = Bass.BASS_ChannelGetLength(stream);

            _isAborted = false;

            byte[] encBuffer = new byte[60000]; // our encoding buffer
            while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING && !_isAborted)
            {
                // getting sample data will automatically feed the encoder
                int len = Bass.BASS_ChannelGetData(stream, encBuffer, encBuffer.Length);
                pos = Bass.BASS_ChannelGetPosition(stream);
                double percentComplete = pos / (double)chanLength * 100.0;

                // Send the message
                msg.MessageData["progress"] = percentComplete;
                queue.Send(msg);
            }

            encoder.Stop();
            return(BASSError.BASS_OK);
        }
コード例 #26
0
        public void Loop(Preset preset)
        {
            this.Pause();

            startPos = Bass.BASS_ChannelSeconds2Bytes(chan, preset.Begin);
            endPos   = Bass.BASS_ChannelSeconds2Bytes(chan, preset.End);

            LoopSync = new SYNCPROC(ProcSync);
            if (lysnc != 0)
            {
                Bass.BASS_ChannelRemoveSync(chan, lysnc);
            }

            lysnc = Bass.BASS_ChannelSetSync(chan, BASSSync.BASS_SYNC_POS, endPos, LoopSync, (IntPtr)0);

            long curPos = Bass.BASS_ChannelGetPosition(chan);

            if (curPos < startPos || curPos >= endPos)
            {
                Bass.BASS_ChannelSetPosition(chan, startPos, BASSMode.BASS_POS_BYTES);
            }

            this.Play();
        }
コード例 #27
0
        private void timerUpdate_Tick(object sender, System.EventArgs e)
        {
            _tickCounter++;
            if (_tickCounter == 4)
            {
                _tickCounter = 0;
                long   len           = Bass.BASS_ChannelGetLength(_streamFX);          // length in bytes
                long   pos           = Bass.BASS_ChannelGetPosition(_streamFX);        // position in bytes
                double totaltime     = Bass.BASS_ChannelBytes2Seconds(_streamFX, len); // the total time length
                double elapsedtime   = Bass.BASS_ChannelBytes2Seconds(_streamFX, pos); // the elapsed time length
                double remainingtime = totaltime - elapsedtime;
                this.labelTime.Text = String.Format("Elapsed: {0:#0.00} - Total: {1:#0.00} - Remain: {2:#0.00}", Utils.FixTimespan(elapsedtime, "MMSS"), Utils.FixTimespan(totaltime, "MMSS"), Utils.FixTimespan(remainingtime, "MMSS"));
                this.Text           = String.Format("CPU: {0:0.00}%", BassAsio.BASS_ASIO_GetCPU());
                // set the track bar
                if (_trackBarPositionCanDisplay)
                {
                    this.trackBarPosition.Maximum = (int)len;
                    this.trackBarPosition.Value   = (int)pos;
                }
            }

            this.progressBarVULeft.Value  = _peakL;
            this.progressBarVURight.Value = _peakR;
        }
コード例 #28
0
        private void positionTrackTimer_Tick(object sender, EventArgs e)
        {
            int math = 0;
            var len  = Bass.BASS_ChannelGetLength(_stream);
            var pos  = Bass.BASS_ChannelGetPosition(_stream);

            if (pos != 0)
            {
                double dProgress = ((double)pos / len) * 100.0;
                math = (int)Math.Round(dProgress);
            }

            double dProgres = math * (456.0 / 100.0);

            int math2 = (int)Math.Round(dProgres);

            panelProgressTrack.Width = math2;
#if DEBUG
            var barLen = 456.0;
            debugPositionLabel.Visible = true;
            debugPositionLabel.Text    = "Len: " + len.ToString() + "\r\nPos: " + pos.ToString() + "\r\nPosP: " + math.ToString() + "\r\nBarLen: " +
                                         barLen.ToString() + "\r\nPosBar: " + math2.ToString() + "\r\nSpectrum type: " + Functions.SpectrumType.ToString();
#endif
        }
コード例 #29
0
ファイル: BassEngine.cs プロジェクト: newcat/LedMusic
 private void positionTimer_Tick(object sender, EventArgs e)
 {
     if (ActiveStreamHandle == 0)
     {
         ChannelPosition = 0;
     }
     else
     {
         inChannelTimerUpdate = true;
         ChannelPosition      = Bass.BASS_ChannelBytes2Seconds(ActiveStreamHandle, Bass.BASS_ChannelGetPosition(ActiveStreamHandle, 0));
         inChannelTimerUpdate = false;
     }
 }
コード例 #30
0
        public Player(int deviceNumber)
        {
            _playlist = new Playlist(this);

            InitBassLibrary(deviceNumber);

            _timer          = new System.Timers.Timer(100);
            _timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);

            _meta_proc = new SYNCPROC(meta_sync);

            void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                BASSActive active = Bass.BASS_ChannelIsActive(_stream);

                if (active == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    _position = Bass.BASS_ChannelBytes2Seconds(_stream, Bass.BASS_ChannelGetPosition(_stream));
                    PositionChanged(this, EventArgs.Empty);

                    if (Convert.ToInt32(_lastPosition) != Convert.ToInt32(_position))
                    {
                        OnPositionDescriptionChanged();
                        _lastPosition = _position;
                    }

                    _timerTicks += 100;
                    if (_timerTicks >= 1000)
                    {
                        _timerTicks = 0;
                        _secondsPlayed++;
                        if (_secondsPlayed >= SecondsBeforeUpdatePlayCount && !_playCountUpdated)
                        {
                            System.Diagnostics.Debug.WriteLine(SecondsBeforeUpdatePlayCount.ToString() + " seconds, updating play count");

                            _playCountUpdated = true;
                            if (_lib != null)
                            {
                                _lib.UpdatePlayCount(_currentSong.FileName);
                                if (AudioscrobblerEnabled)
                                {
                                    var req = new AudioscrobblerRequest();
                                    req.Username = AudioscrobblerUserName;
                                    req.Password = AudioscrobblerPassword;
                                    req.SubmitTrack(_currentSong);
                                }
                            }
                        }
                    }
                }
                else if (active == (int)BASSActive.BASS_ACTIVE_STOPPED)
                {
                    if (!_playCountUpdated)
                    {
                        if (Convert.ToInt32(this.CurrentSong.Duration) <= SecondsBeforeUpdatePlayCount)
                        {
                            System.Diagnostics.Debug.WriteLine("Didn't reach " + SecondsBeforeUpdatePlayCount.ToString() + " seconds because song finished, updating play count");

                            _playCountUpdated = true;
                            if (_lib != null)
                            {
                                _lib.UpdatePlayCount(_currentSong.FileName);
                            }
                        }
                    }
                    _timer.Stop();
                    this.State = PlayerState.Stopped;
                    OnSongFinished();
                    if (_autoTrackAdvance)
                    {
                        if (_repeatCurrentTrack)
                        {
                            Stop();
                            Play();
                        }
                        else
                        {
                            Next();
                        }
                    }
                }
            }
        }