private int IndexSegmentUnderCursor(Point pt1) { SetSegmentEndPoints(); pt1 = new Point(SoundLineEditor.Clamp(pt1.X, lineStartPos.X, playerLeghtPerPixel), pt1.Y); int index = -1; if (project.listSamples.Count > 0) { for (int i = 0; i < project.listSamples.Count; i++) { if (pt1.X >= project.listSamples[i].startPos.X && pt1.X <= project.listSamples[i].endPos.X) { index = i; } } if (pt1.X <= project.listSamples[0].endPos.X) { index = 0; } else if (pt1.X >= project.listSamples[project.listSamples.Count - 1].startPos.X) { index = project.listSamples.Count - 1; } } return(index); }
// Мы двигаем маркер точку. private void pictureBox_MouseMove_MovingMarker(object sender, MouseEventArgs e) { markerPoint = new Point(SoundLineEditor.Clamp(e.X + OffsetX, lineStartPos.X, playerLeghtPerPixel), markerPoint.Y); // Перерисовать. pictureBox.Invalidate(); }
protected void buttonPlay_Click(object sender, EventArgs e) { Button button = (sender as Button); if (project.listSamples.Count > 0) { if (button.Text == ">") { if (markerPoint.X >= project.listSamples[project.listSamples.Count - 1].endPos.X) { markerPoint = new Point(SoundLineEditor.Clamp(lineStartPos.X, lineStartPos.X, project.listSamples[project.listSamples.Count - 1].endPos.X), markerPoint.Y); } currentPlayed = IndexSegmentUnderCursor(markerPoint); player.Stop(); mp3Reader = new Mp3FileReader(project.listSamples[currentPlayed].SoundPath); int leghtSegmentPerPixel = (project.listSamples[currentPlayed].endPos.X - project.listSamples[currentPlayed].startPos.X); TimeSpan currentTime = TimeSpan.FromSeconds ( project.listSamples[currentPlayed].SplitStartTimeFromSecond + (((double)(markerPoint.X - project.listSamples[currentPlayed].startPos.X)) / leghtSegmentPerPixel) * project.listSamples[currentPlayed].LeghtFromSecond ); //MessageBox.Show(currentTime.ToString()); mp3Reader.CurrentTime = currentTime; player.Init(mp3Reader); player.Play(); timer.Start(); button.Text = "||"; } else { timer.Stop(); button.Text = ">"; player.Pause(); } } }
private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) { // Посмотрим, чем мы закончили. int segment_number; if (MouseIsOverSegment(e.Location, out segment_number)) { // Запомните номер сегмента. MovingSegment = segment_number; project.listSamples.RemoveAt(MovingSegment); SetSegmentEndPoints(); setPlayerLeghtPrePixel(); markerPoint = new Point(SoundLineEditor.Clamp(markerPoint.X, lineStartPos.X, playerLeghtPerPixel), markerPoint.Y); updatePlayingSegment(); pictureBox.Invalidate(); } }
protected void pictureBox_DragDrop(object sender, DragEventArgs e) { SetSegmentEndPoints(); int index = SetIndexQueue(pictureBox.PointToClient(new Point(e.X, e.Y))); Sample s = e.Data.GetData(typeof(Sample)) as Sample; if (FinalLeght() + s.LeghtFromSecond <= maxLeghtOutFromSecond) { // MessageBox.Show(""+s.indexQueue); project.listSamples.Add(s); s.IndexQueue = index; SetSegmentEndPoints(); s.ResizeBitMap(new Size(s.endPos.X - s.startPos.X, pictureBox.Height)); } else { MessageBox.Show(String.Format("Выходной файл не может привышать {0} минут! Лимит привышен на {1} секунд!", maxLeghtOutFromSecond / 60, FinalLeght() + s.LeghtFromSecond - maxLeghtOutFromSecond)); } setPlayerLeghtPrePixel(); markerPoint = new Point(SoundLineEditor.Clamp(markerPoint.X, lineStartPos.X, playerLeghtPerPixel), markerPoint.Y); updatePlayingSegment(); pictureBox.Invalidate(); }
protected void pictureBox_Paint(object sender, PaintEventArgs e) { int penWidth = 1; Pen greyPen = new Pen(Color.DarkOrange, 3); Pen darkGreyPen = new Pen(Color.Black, 1); Pen orangePen = new Pen(Color.DarkOrange, penWidth); penWidth = 0; SetSegmentEndPoints(); e.Graphics.DrawLine(greyPen, lineStartPos, new Point(playerLeghtPerPixel, lineStartPos.Y)); int index = -1; for (int i = 0; i < project.listSamples.Count(); i++) { if (MovingSegment == i) { index = i; } else { e.Graphics.DrawLine(darkGreyPen, new Point(project.listSamples[i].startPos.X, 0 + penWidth) , new Point(project.listSamples[i].endPos.X, 0 + penWidth)); e.Graphics.DrawLine(darkGreyPen, new Point(project.listSamples[i].startPos.X, pictureBox.Height - 1) , new Point(project.listSamples[i].endPos.X, pictureBox.Height - 1)); e.Graphics.DrawLine(darkGreyPen, new Point(project.listSamples[i].startPos.X, 0) , new Point(project.listSamples[i].startPos.X, pictureBox.Height)); e.Graphics.DrawLine(darkGreyPen, new Point(project.listSamples[i].endPos.X, 0) , new Point(project.listSamples[i].endPos.X, pictureBox.Height)); e.Graphics.DrawImage(project.listSamples[i].FrequencyBitMap, project.listSamples[i].startPos.X, lineStartPos.Y - project.listSamples[i].FrequencyBitMap.Height / 2); } } // e.Graphics.DrawLine(greyPen, lineStartPos, lineEndPos); e.Graphics.DrawLine(darkGreyPen, new Point(0, 0) , new Point(pictureBox.Width, 0)); e.Graphics.DrawLine(darkGreyPen, new Point(0, pictureBox.Height - 1) , new Point(pictureBox.Width, pictureBox.Height - 1)); e.Graphics.DrawLine(darkGreyPen, new Point(0, 0) , new Point(0, pictureBox.Height)); e.Graphics.DrawLine(darkGreyPen, new Point(pictureBox.Width - 1, 0) , new Point(pictureBox.Width - 1, pictureBox.Height)); if (index != -1) { e.Graphics.DrawImage(project.listSamples[index].FrequencyBitMap, project.listSamples[index].startPos.X, lineStartPos.Y - project.listSamples[index].FrequencyBitMap.Height / 2); e.Graphics.DrawLine(orangePen, new Point(project.listSamples[index].startPos.X, 0 + penWidth) , new Point(project.listSamples[index].endPos.X, 0 + penWidth)); e.Graphics.DrawLine(orangePen, new Point(project.listSamples[index].startPos.X, pictureBox.Height - 1) , new Point(project.listSamples[index].endPos.X, pictureBox.Height - 1)); e.Graphics.DrawLine(orangePen, new Point(project.listSamples[index].startPos.X, 0), new Point(project.listSamples[index].startPos.X, pictureBox.Height)); e.Graphics.DrawLine(orangePen, new Point(project.listSamples[index].endPos.X, 0) , new Point(project.listSamples[index].endPos.X, pictureBox.Height)); } e.Graphics.DrawLine(greyPen, lineStartPos, new Point(playerLeghtPerPixel, lineStartPos.Y)); int penSize = 3; Pen splitPen = new Pen(Color.OrangeRed, penSize); Pen cursorPen = new Pen(Color.Black, penSize); //Рисуем маркер cursorPen.Color = Color.Black; e.Graphics.DrawLine(cursorPen, lineStartPos, new Point(markerPoint.X, lineStartPos.Y)); e.Graphics.DrawPolygon(cursorPen, new Point[] { new Point(SoundLineEditor.Clamp(markerPoint.X - object_radius, lineStartPos.X, lineEndPos.X) , markerPoint.Y - object_radius), new Point(SoundLineEditor.Clamp(markerPoint.X + object_radius, Math.Min(lineStartPos.X, lineEndPos.X), Math.Max(lineStartPos.X, lineEndPos.X)) , markerPoint.Y - object_radius), new Point(markerPoint.X, lineStartPos.Y) }); // } }
protected void timer_Tick(object sender, EventArgs e) { if (player != null && player.PlaybackState != PlaybackState.Stopped) { if (project.listSamples.Count > 0) { int leghtSegmentPerPixel = (project.listSamples[currentPlayed].endPos.X - project.listSamples[currentPlayed].startPos.X); double leghtSound = project.listSamples[currentPlayed].SplitEndTimeFromSecond - project.listSamples[currentPlayed].SplitStartTimeFromSecond; int lineLeght = leghtSegmentPerPixel; markerPoint = new Point(((project.listSamples[currentPlayed].startPos.X) + (int)(lineLeght * (((mp3Reader.CurrentTime.TotalSeconds - project.listSamples[currentPlayed].SplitStartTimeFromSecond) / (leghtSound))))), markerPoint.Y); if (markerPoint.X >= project.listSamples[project.listSamples.Count - 1].endPos.X) { markerPoint = new Point(SoundLineEditor.Clamp(markerPoint.X, lineStartPos.X, project.listSamples[project.listSamples.Count - 1].endPos.X), markerPoint.Y); buttonPlay.Text = ">"; player.Stop(); timer.Stop(); } else if (IndexSegmentUnderCursor(markerPoint) != currentPlayed) { if (IndexSegmentUnderCursor(markerPoint) != -1) { currentPlayed = IndexSegmentUnderCursor(markerPoint); player.Stop(); mp3Reader = new Mp3FileReader(project.listSamples[currentPlayed].SoundPath); TimeSpan currentTime = TimeSpan.FromSeconds ( project.listSamples[currentPlayed].SplitStartTimeFromSecond + (((double)(markerPoint.X - project.listSamples[currentPlayed].startPos.X)) / leghtSegmentPerPixel) * project.listSamples[currentPlayed].LeghtFromSecond ); //MessageBox.Show(currentTime.ToString()); mp3Reader.CurrentTime = currentTime; player.Init(mp3Reader); player.Play(); timer.Start(); } else { // markerPoint = new Point(SoundLineEditor.Clamp(markerPoint.X, lineStartPos.X, listSegment[listSegment.Count - 1].segmentEndPos.X), markerPoint.Y); buttonPlay.Text = ">"; player.Stop(); timer.Stop(); } } pictureBox.Invalidate(); } } }