Exemple #1
0
        public void OnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (!this.control.annoListControl.editTextBox.IsFocused)
            {
                if (e.KeyboardDevice.IsKeyDown(Key.Space))
                {
                    handlePlay();

                    e.Handled = true;
                }


                if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && e.KeyboardDevice.IsKeyDown(Key.L))
                {
                    if (AnnoTierStatic.Selected != null && Properties.Settings.Default.CMLDefaultStream != null)
                    {
                        DatabaseHandler.StoreToDatabase(AnnoTierStatic.Selected.AnnoList, loadedDBmedia, false);
                        CompleteTier(Properties.Settings.Default.CMLContext, AnnoTierStatic.Selected, Properties.Settings.Default.CMLDefaultStream, Properties.Settings.Default.CMLDefaultConf, Properties.Settings.Default.CMLDefaultGap, Properties.Settings.Default.CMLDefaultMinDur);
                    }

                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.D0) || e.KeyboardDevice.IsKeyDown(Key.NumPad0))
                {
                    if (AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.DISCRETE || AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.FREE)
                    {
                        string label = "GARBAGE";
                        if (AnnoTierStatic.Label != null)
                        {
                            AnnoTierStatic.Label.Item.Label      = label;
                            AnnoTierStatic.Label.Item.Color      = Colors.Black;
                            AnnoTierStatic.Label.Item.Confidence = 1.0;
                        }
                    }
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.D1) || e.KeyboardDevice.IsKeyDown(Key.D2) || e.KeyboardDevice.IsKeyDown(Key.D3) || e.KeyboardDevice.IsKeyDown(Key.D4) ||
                    e.KeyboardDevice.IsKeyDown(Key.D5) || e.KeyboardDevice.IsKeyDown(Key.D6) || e.KeyboardDevice.IsKeyDown(Key.D7) || e.KeyboardDevice.IsKeyDown(Key.D8) || e.KeyboardDevice.IsKeyDown(Key.D9) ||
                    e.KeyboardDevice.IsKeyDown(Key.NumPad1) || e.KeyboardDevice.IsKeyDown(Key.NumPad2) || e.KeyboardDevice.IsKeyDown(Key.NumPad3) || e.KeyboardDevice.IsKeyDown(Key.NumPad4) || e.KeyboardDevice.IsKeyDown(Key.NumPad5) ||
                    e.KeyboardDevice.IsKeyDown(Key.NumPad6) || e.KeyboardDevice.IsKeyDown(Key.NumPad7) || e.KeyboardDevice.IsKeyDown(Key.NumPad8) || e.KeyboardDevice.IsKeyDown(Key.NumPad9))
                {
                    int index = 0;
                    if (e.Key - Key.D1 < 10 && AnnoTierStatic.Selected.AnnoList.Scheme.Labels != null && AnnoTierStatic.Selected.AnnoList.Scheme.Labels.Count > 0)
                    {
                        index = Math.Min(AnnoTierStatic.Selected.AnnoList.Scheme.Labels.Count - 1, e.Key - Key.D1);
                    }
                    else if (AnnoTierStatic.Selected.AnnoList.Scheme.Labels != null)
                    {
                        index = Math.Min(AnnoTierStatic.Selected.AnnoList.Scheme.Labels.Count - 1, e.Key - Key.NumPad1);
                    }

                    if (index >= 0 && AnnoTierStatic.Selected.AnnoList.Scheme.Type == AnnoScheme.TYPE.DISCRETE)
                    {
                        string label = AnnoTierStatic.Selected.AnnoList.Scheme.Labels.ElementAt(index).Name;
                        if (AnnoTierStatic.Label != null)
                        {
                            AnnoTierStatic.Label.Item.Label      = label;
                            AnnoTierStatic.Selected.DefaultLabel = label;

                            foreach (AnnoScheme.Label lp in AnnoTierStatic.Selected.AnnoList.Scheme.Labels)
                            {
                                if (label == lp.Name)
                                {
                                    AnnoTierStatic.Label.Item.Color      = lp.Color;
                                    AnnoTierStatic.Label.Item.Confidence = 1.0;
                                    AnnoTierStatic.Selected.DefaultColor = lp.Color;

                                    break;
                                }
                            }
                        }
                    }
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.Right) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl))
                {
                    if (AnnoTierStatic.Label != null && AnnoTierStatic.Selected.isDiscreteOrFree && isKeyDown == false /*&& AnnoTierStatic.Label == null*/)
                    {
                        UIElement container        = VisualTreeHelper.GetParent(AnnoTierStatic.Label) as UIElement;
                        Point     relativeLocation = AnnoTierStatic.Label.TranslatePoint(new Point(0, 0), container);

                        mediaList.move(MainHandler.Time.TimeFromPixel(relativeLocation.X + AnnoTierStatic.Label.Width));

                        if (e.KeyboardDevice.IsKeyDown(Key.LeftShift))
                        {
                            annoCursor.X = relativeLocation.X + AnnoTierStatic.Label.Width;
                        }
                        else
                        {
                            signalCursor.X = relativeLocation.X + AnnoTierStatic.Label.Width;
                        }

                        timeline.CurrentSelectPosition      = annoCursor.X;
                        timeline.CurrentPlayPosition        = MainHandler.Time.TimeFromPixel(signalCursor.X);
                        timeline.CurrentPlayPositionPrecise = MainHandler.Time.TimeFromPixel(signalCursor.X);
                        AnnoTierStatic.Label.select(true);
                        isKeyDown = true;
                    }
                    e.Handled = true;
                }

                else if (e.KeyboardDevice.IsKeyDown(Key.Right) && !e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && !e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && !isKeyDown)
                {
                    isKeyDown = true;
                    if (AnnoTier.Selected != null)
                    {
                        AnnoTier.Selected.Focus();
                    }
                    int    i   = 0;
                    double fps = 1.0 / 25.0;
                    foreach (IMedia im in mediaList.Medias)
                    {
                        if (im.IsVideo())
                        {
                            break;
                        }
                        i++;
                    }

                    if (i < mediaList.Medias.Count)
                    {
                        fps = 1.0 / mediaList.Medias[i].GetSampleRate();
                    }

                    mediaList.move(MainHandler.Time.TimeFromPixel(signalCursor.X) + fps);
                    timeline.CurrentPlayPosition        = MainHandler.Time.TimeFromPixel(signalCursor.X) + fps;
                    timeline.CurrentPlayPositionPrecise = MainHandler.Time.TimeFromPixel(signalCursor.X) + fps;
                    double pos = MainHandler.Time.PixelFromTime(timeline.CurrentPlayPosition);
                    signalCursor.X = pos;


                    if (Time.CurrentPlayPosition >= Time.SelectionStop && control.navigator.followplaybox.IsChecked == true)
                    {
                        double factor = (((timeline.CurrentPlayPosition - timeline.SelectionStart) / (timeline.SelectionStop - timeline.SelectionStart)));
                        control.timeLineControl.rangeSlider.followmedia = true;
                        control.timeLineControl.rangeSlider.MoveAndUpdate(true, factor);

                        if (timeline.SelectionStop - timeline.SelectionStart < 1)
                        {
                            timeline.SelectionStart = timeline.SelectionStop - 1;
                        }
                        signalCursor.X = 1;
                    }
                    else if (control.navigator.followplaybox.IsChecked == false)
                    {
                        control.timeLineControl.rangeSlider.followmedia = false;
                    }



                    double time = Time.TimeFromPixel(pos);
                    control.signalPositionLabel.Text     = FileTools.FormatSeconds(time);
                    control.annoTrackControl.currenttime = Time.TimeFromPixel(pos);
                    e.Handled = true;
                }



                if (e.KeyboardDevice.IsKeyDown(Key.Left) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl))
                {
                    if (AnnoTierStatic.Label != null && AnnoTierStatic.Selected.isDiscreteOrFree && isKeyDown == false /*&& AnnoTierStatic.Label == null*/)
                    {
                        UIElement container        = VisualTreeHelper.GetParent(AnnoTierStatic.Label) as UIElement;
                        Point     relativeLocation = AnnoTierStatic.Label.TranslatePoint(new Point(0, 0), container);

                        mediaList.move(MainHandler.Time.TimeFromPixel(relativeLocation.X));

                        if (e.KeyboardDevice.IsKeyDown(Key.LeftShift))
                        {
                            annoCursor.X = relativeLocation.X;
                        }
                        else
                        {
                            signalCursor.X = relativeLocation.X;
                        }

                        timeline.CurrentSelectPosition      = annoCursor.X;
                        timeline.CurrentPlayPosition        = MainHandler.Time.TimeFromPixel(signalCursor.X);
                        timeline.CurrentPlayPositionPrecise = MainHandler.Time.TimeFromPixel(signalCursor.X);
                        AnnoTierStatic.Label.select(true);
                        isKeyDown = true;
                    }
                    e.Handled = true;
                }

                else if (e.KeyboardDevice.IsKeyDown(Key.Left) && !e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && !e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && !isKeyDown)
                {
                    isKeyDown = true;
                    if (AnnoTier.Selected != null)
                    {
                        AnnoTier.Selected.Focus();
                    }
                    int    i   = 0;
                    double fps = 1.0 / 25.0;
                    foreach (IMedia im in mediaList.Medias)
                    {
                        if (im.IsVideo())
                        {
                            break;
                        }
                        i++;
                    }

                    if (i < mediaList.Medias.Count)
                    {
                        fps = 1.0 / mediaList.Medias[i].GetSampleRate();
                    }

                    mediaList.move(MainHandler.Time.TimeFromPixel(signalCursor.X) - fps);
                    timeline.CurrentPlayPosition        = MainHandler.Time.TimeFromPixel(signalCursor.X) - fps;
                    timeline.CurrentPlayPositionPrecise = timeline.CurrentPlayPosition;
                    double pos = MainHandler.Time.PixelFromTime(timeline.CurrentPlayPosition);
                    signalCursor.X = pos;



                    if (Time.CurrentPlayPosition < Time.SelectionStart && Time.SelectionStart > 0 && control.navigator.followplaybox.IsChecked == true)
                    {
                        double factor = (((timeline.SelectionStop - timeline.CurrentPlayPosition) / (timeline.SelectionStop - timeline.SelectionStart)));
                        control.timeLineControl.rangeSlider.followmedia = true;
                        control.timeLineControl.rangeSlider.MoveAndUpdate(false, factor);

                        if (timeline.SelectionStop - timeline.SelectionStart < 1)
                        {
                            timeline.SelectionStart = timeline.SelectionStop - 1;
                        }
                        signalCursor.X = MainHandler.Time.PixelFromTime(MainHandler.Time.SelectionStop);
                    }
                    else if (control.navigator.followplaybox.IsChecked == false)
                    {
                        control.timeLineControl.rangeSlider.followmedia = false;
                    }



                    double time = Time.TimeFromPixel(pos);
                    if (time != 0)
                    {
                        control.signalPositionLabel.Text     = FileTools.FormatSeconds(time);
                        control.annoTrackControl.currenttime = Time.TimeFromPixel(pos);
                    }

                    e.Handled = true;
                }



                if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && !isKeyDown)
                {
                    if (AnnoTierStatic.Selected != null && !AnnoTierStatic.Selected.isDiscreteOrFree)
                    {
                        AnnoTierStatic.Selected.ContinuousAnnoMode();
                    }
                    isKeyDown = true;
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.T) && e.KeyboardDevice.IsKeyDown(Key.Down))
                {
                    for (int i = 0; i < annoTiers.Count; i++)
                    {
                        if (annoTiers[i] == AnnoTierStatic.Selected && i + 1 < annoTiers.Count)
                        {
                            AnnoTier.SelectTier(annoTiers[i + 1]);
                            AnnoTier.SelectLabel(null);
                            break;
                        }
                    }
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.T) && e.KeyboardDevice.IsKeyDown(Key.Up))
                {
                    for (int i = 0; i < annoTiers.Count; i++)
                    {
                        if (annoTiers[i] == AnnoTierStatic.Selected && i > 0)
                        {
                            AnnoTier.SelectTier(annoTiers[i - 1]);
                            AnnoTier.SelectLabel(null);
                            break;
                        }
                    }
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.C) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.isDiscreteOrFree)
                {
                    if (AnnoTierStatic.Label != null)
                    {
                        temp_segment = AnnoTierStatic.Label;
                        AnnoTierStatic.Label.select(false);
                    }

                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.X) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.isDiscreteOrFree)
                {
                    if (AnnoTierStatic.Label != null)
                    {
                        temp_segment = AnnoTierStatic.Label;
                        AnnoTier.OnKeyDownHandler(sender, e);
                    }

                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.V) && e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && AnnoTierStatic.Selected != null && AnnoTierStatic.Selected.isDiscreteOrFree)
                {
                    if (AnnoTierStatic.Selected != null)
                    {
                        double start = Time.TimeFromPixel(annoCursor.X);
                        if (temp_segment != null)
                        {
                            AnnoTierStatic.Selected.NewAnnoCopy(start, start + temp_segment.Item.Duration, temp_segment.Item.Label, temp_segment.Item.Color, temp_segment.Item.Confidence);
                        }
                    }

                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && e.KeyboardDevice.IsKeyDown(Key.Z))
                {
                    if (AnnoTierStatic.Selected != null)
                    {
                        AnnoTierStatic.Selected.UnDoObject.Undo(1);
                    }
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) && e.KeyboardDevice.IsKeyDown(Key.Y))
                {
                    if (AnnoTierStatic.Selected != null)
                    {
                        AnnoTierStatic.Selected.UnDoObject.Redo(1);
                    }

                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && e.KeyboardDevice.IsKeyDown(Key.Down))
                {
                    if (AnnoTierStatic.Label != null)
                    {
                        AnnoListItem temp = AnnoTierStatic.Label.Item;

                        for (int i = 0; i < annoTiers.Count; i++)
                        {
                            if (annoTiers[i] == AnnoTierStatic.Selected && i + 1 < annoTiers.Count)
                            {
                                AnnoTier.SelectTier(annoTiers[i + 1]);
                                AnnoTier.SelectLabel(null);
                                if (!AnnoTierStatic.Selected.AnnoList.Contains(temp))
                                {
                                    AnnoTierStatic.Selected.NewAnnoCopy(temp.Start, temp.Stop, temp.Label, temp.Color);
                                }

                                break;
                            }
                        }
                    }
                    e.Handled = true;
                }

                if (e.KeyboardDevice.IsKeyDown(Key.LeftAlt) && e.KeyboardDevice.IsKeyDown(Key.Up))
                {
                    if (AnnoTierStatic.Label != null)
                    {
                        AnnoListItem temp = AnnoTierStatic.Label.Item;

                        for (int i = 0; i < annoTiers.Count; i++)
                        {
                            if (annoTiers[i] == AnnoTierStatic.Selected && i > 0)
                            {
                                AnnoTier.SelectTier(annoTiers[i - 1]);
                                AnnoTier.SelectLabel(null);
                                if (!AnnoTierStatic.Selected.AnnoList.Contains(temp))
                                {
                                    AnnoTierStatic.Selected.NewAnnoCopy(temp.Start, temp.Stop, temp.Label, temp.Color);
                                }
                                break;
                            }
                        }
                    }
                    e.Handled = true;
                }
            }
        }
        private void annoTrackGrid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (control.navigator.askforlabels.IsChecked == true)
            {
                AnnoTier.askForLabel = true;
            }
            else
            {
                AnnoTier.askForLabel = false;
            }

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (AnnoTierStatic.Label != null)
                {
                    AnnoTierStatic.Label.isMoveable = true;
                    AnnoTierStatic.Selected.LeftMouseButtonDown(e);
                }
            }

            if (e.RightButton == MouseButtonState.Pressed)
            {
                if (AnnoTierStatic.Label != null)
                {
                    AnnoTierStatic.Label.select(false);
                }

                if (AnnoTierStatic.Selected != null && (AnnoTierStatic.Selected.AnnoList.Scheme.Type != AnnoScheme.TYPE.CONTINUOUS || isMouseButtonDown == false))
                {
                    foreach (AnnoTier a in annoTiers)
                    {
                        if (a.IsMouseOver)
                        {
                            AnnoTier.SelectLabel(null);
                            AnnoTier.SelectTier(a);
                            break;
                        }
                    }
                }

                if (AnnoTierStatic.Selected != null)
                {
                    AnnoTierStatic.Selected.RightMouseButtonDown(e);
                }
                isMouseButtonDown = true;
            }

            if (AnnoTierStatic.Selected != null)
            {
                if (AnnoTierStatic.Selected.isDiscreteOrFree || (!AnnoTierStatic.Selected.isDiscreteOrFree && Keyboard.IsKeyDown(Key.LeftShift)))
                {
                    double pos = e.GetPosition(control.trackGrid).X;
                    annoCursor.X = pos;
                    Time.CurrentSelectPosition = pos;

                    annoCursor.Visibility = Visibility.Visible;
                    double time = Time.TimeFromPixel(pos);
                    control.annoPositionLabel.Text = FileTools.FormatSeconds(time);
                }
                else
                {
                    annoCursor.X = 0;
                    double time = Time.TimeFromPixel(0);
                    annoCursor.Visibility          = Visibility.Hidden;
                    control.annoPositionLabel.Text = FileTools.FormatSeconds(time);
                }
            }
        }