private void btnPlay_Click(object sender, EventArgs e) { updateTimer.Stop(); Bass.BASS_StreamFree(stream); if (filename != string.Empty) { stream = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN); if (stream != 0) { mslength = (int)Bass.BASS_ChannelSeconds2Bytes(stream, 0.03); deviceLatencyBytes = (int)Bass.BASS_ChannelSeconds2Bytes(stream, deviceLatencyMS / 1000.0); myDSPAddr = new DSPPROC(MyDSPGain); Bass.BASS_ChannelSetDSP(stream, myDSPAddr, IntPtr.Zero, 2); if (WF2 != null && WF2.IsRendered) { WF2.SyncPlayback(stream); long cuein = WF2.GetMarker("CUE"); long cueout = WF2.GetMarker("END"); int cueinFrame = WF2.Position2Frames(cuein); int cueoutFrame = WF2.Position2Frames(cueout); if (cuein >= 0) { Bass.BASS_ChannelSetPosition(stream, cuein); } if (cueout >= 0) { Bass.BASS_ChannelRemoveSync(stream, syncer); syncer = Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_POS, cueout, sync, IntPtr.Zero); } } } if (stream != 0 && Bass.BASS_ChannelPlay(stream, false)) { textBox1.Text = ""; updateTimer.Start(); BASS_CHANNELINFO info = new BASS_CHANNELINFO(); Bass.BASS_ChannelGetInfo(stream, info); textBox1.Text += "Info: " + info.ToString() + Environment.NewLine; TAG_INFO tagInfo = new TAG_INFO(); if (BassTags.BASS_TAG_GetFromFile(stream, tagInfo)) { textBoxAlbum.Text = tagInfo.album; textBoxArtist.Text = tagInfo.artist; textBoxTitle.Text = tagInfo.title; textBoxComment.Text = tagInfo.comment; textBoxGenre.Text = tagInfo.genre; textBoxYear.Text = tagInfo.year; textBoxTrack.Text = tagInfo.track; } btnStop.Enabled = true; btnPlay.Enabled = false; } } }
private void DrawWavePosition(long pos, long len) { if (_WF == null || len == 0 || pos < 0) { this.pictureBoxWaveForm.Image = null; return; } Bitmap bitmap = null; Graphics g = null; Pen p = null; double bpp = 0; try { if (_zoomed) { // total length doesn't have to be _zoomDistance sec. here len = _WF.Frame2Bytes(_zoomEnd) - _zoomStartBytes; int scrollOffset = 10; // 10*20ms = 200ms. // if we scroll out the window...(scrollOffset*20ms before the zoom window ends) if (pos > (_zoomStartBytes + len - scrollOffset * _WF.Wave.bpf)) { // we 'scroll' our zoom with a little offset _zoomStart = _WF.Position2Frames(pos - scrollOffset * _WF.Wave.bpf); _zoomStartBytes = _WF.Frame2Bytes(_zoomStart); _zoomEnd = _zoomStart + _WF.Position2Frames(_zoomDistance) - 1; if (_zoomEnd >= _WF.Wave.data.Length) { // beyond the end, so we zoom from end - _zoomDistance. _zoomEnd = _WF.Wave.data.Length - 1; _zoomStart = _zoomEnd - _WF.Position2Frames(_zoomDistance) + 1; if (_zoomStart < 0) { _zoomStart = 0; } _zoomStartBytes = _WF.Frame2Bytes(_zoomStart); // total length doesn't have to be _zoomDistance sec. here len = _WF.Frame2Bytes(_zoomEnd) - _zoomStartBytes; } // get the new wave image for the new zoom window DrawWave(); } // zoomed: starts with _zoomStartBytes and is _zoomDistance long pos -= _zoomStartBytes; // offset of the zoomed window bpp = len / (double)this.pictureBoxWaveForm.Width; // bytes per pixel } else { // not zoomed: width = length of stream bpp = len / (double)this.pictureBoxWaveForm.Width; // bytes per pixel } p = new Pen(Color.Red); bitmap = new Bitmap(this.pictureBoxWaveForm.Width, this.pictureBoxWaveForm.Height); g = Graphics.FromImage(bitmap); g.Clear(Color.Black); int x = (int)Math.Round(pos / bpp); // position (x) where to draw the line g.DrawLine(p, x, 0, x, this.pictureBoxWaveForm.Height - 1); bitmap.MakeTransparent(Color.Black); } catch { bitmap = null; } finally { // clean up graphics resources if (p != null) { p.Dispose(); } if (g != null) { g.Dispose(); } } this.pictureBoxWaveForm.Image = bitmap; }