Пример #1
0
        /// <summary>
        /// Event occured when the NoteBubble finished its move (to the right place)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void moveCenter_Completed(object sender, EventArgs e)
        {
            Converter converter = new Converter();
            DisplayPreviewGrid(false);

            noteBubbleVM.SVItem.Center = bubbleCenter;
            for (int i = 0; i < sessionVM.NotesOnStave.Count && NothingAtThisPlace; i++)
            {
                if ((int)((virtualCenter.X - 120.0) / 60.0) == sessionVM.NotesOnStave[i].Note.Position
                    && !sessionVM.NotesOnStave[i].Picked
                    && converter.getOctave(virtualCenter.Y) == sessionVM.NotesOnStave[i].Note.Octave
                    && converter.getPitch(virtualCenter.Y) == sessionVM.NotesOnStave[i].Note.Pitch
                    && ((bubbleDroppedTopStave && sessionVM.Session.StaveTop.Notes.Contains(sessionVM.NotesOnStave[i].Note)) ||
                        (!bubbleDroppedTopStave && sessionVM.Session.StaveBottom.Notes.Contains(sessionVM.NotesOnStave[i].Note))))
                {
                    if (noteBubbleVM.NoteBubble.Note.Duration == NoteValue.alteration)
                    {
                        NothingAtThisPlace = false;
                        noteVM = sessionVM.NotesOnStave[i];
                    }
                    else
                    {
                        sessionVM.NotesOnStave[i].Animation.BackToBubbleFormat(true);
                        NothingAtThisPlace = true;
                    }
                }
                else NothingAtThisPlace = true;
            }

            int positionNote = (int)((virtualCenter.X - 120.0) / 60.0);
            double betweenStave = (350 - GlobalVariables.ManipulationGrid.ElementAtOrDefault(noteBubbleVM.NoteBubble.Note.Position + 2)) * (sessionVM.SessionSVI.ActualHeight / 1080);
            bool isUp = (bubbleCenter.Y < betweenStave);

            if (NothingAtThisPlace)
            {
                NoteViewModel noteViewModel = new NoteViewModel(bubbleCenter, noteBubbleVM.NoteBubble.Note, sessionVM.Notes, sessionVM);
                if (!noteViewModel.Note.Sharp && !noteViewModel.Note.Flat)
                {
                    if (isUp)
                    {
                        sessionVM.Session.StaveTop.CurrentInstrument.PlayNote(noteViewModel.Note);
                        sessionVM.Session.StaveTop.AddNote(noteViewModel.Note, positionNote);
                    }
                    else
                    {
                        sessionVM.Session.StaveBottom.CurrentInstrument.PlayNote(noteViewModel.Note);
                        sessionVM.Session.StaveBottom.AddNote(noteViewModel.Note, positionNote);
                    }
                    sessionVM.Bubbles.Items.Remove(noteBubbleVM.SVItem);
                    sessionVM.NbgVM.NoteBubbleVMs.Remove(noteBubbleVM);
                    sessionVM.Notes.Items.Add(noteViewModel.SVItem);
                    sessionVM.NotesOnStave.Add(noteViewModel);
                }
            }
            else
            {
                //If the NoteBubbleViewModel is a (#) or (b)
                if (noteBubbleVM.NoteBubble.Note.Sharp || noteBubbleVM.NoteBubble.Note.Flat)
                {
                    bool changeline = false;
                    if (noteBubbleVM.NoteBubble.Note.Sharp)
                        changeline = noteVM.Note.UpSemiTone();
                    if (noteBubbleVM.NoteBubble.Note.Flat)
                        changeline = noteVM.Note.DownSemiTone();

                    double y = converter.getCenterY(isUp, noteVM.Note);
                    if (y < 80)
                    {
                        if (noteBubbleVM.NoteBubble.Note.Sharp)
                            noteVM.Note.DownSemiTone();
                        if (noteBubbleVM.NoteBubble.Note.Flat)
                            noteVM.Note.UpSemiTone();

                        canAnimate = true;
                        Animate();
                    }
                    else
                    {
                        y *= sessionVM.SessionSVI.ActualHeight / 1080.0;
                        sessionVM.NbgVM.NoteBubbleVMs.Remove(noteBubbleVM);
                        sessionVM.Bubbles.Items.Remove(noteBubbleVM.SVItem);
                        sessionVM.Notes.Items.Remove(noteVM.SVItem);
                        sessionVM.NotesOnStave.Remove(noteVM);
                        noteVM = new NoteViewModel(new Point(bubbleCenter.X, y), noteVM.Note, sessionVM.Notes, sessionVM);

                        if (isUp)
                        {
                            sessionVM.Session.StaveTop.RemoveNote(noteVM.Note);
                            sessionVM.Session.StaveTop.CurrentInstrument.PlayNote(noteVM.Note);
                            sessionVM.Session.StaveTop.AddNote(noteVM.Note, positionNote);
                        }
                        else
                        {
                            sessionVM.Session.StaveBottom.RemoveNote(noteVM.Note);
                            sessionVM.Session.StaveBottom.CurrentInstrument.PlayNote(noteVM.Note);
                            sessionVM.Session.StaveBottom.AddNote(noteVM.Note, positionNote);
                        }
                        sessionVM.Notes.Items.Add(noteVM.SVItem);
                        sessionVM.NotesOnStave.Add(noteVM);
                    }
                }

                else
                {
                    canAnimate = true;
                    Animate();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Display the images of the notes from the melodyBubble
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void previewDt_Tick(object sender, EventArgs e)
        {
            ScatterViewItem bubble = SVItem;
            Point virtualBubbleCenter = new Point(bubble.ActualCenter.X, bubble.ActualCenter.Y);

            int width = (int)sessionVM.Grid.ActualWidth;
            int height = (int)sessionVM.Grid.ActualHeight;
            virtualBubbleCenter.X = virtualBubbleCenter.X * 1920.0 / width;
            virtualBubbleCenter.Y = virtualBubbleCenter.Y * 1080.0 / height;

            if (virtualBubbleCenter.X < 150.0) virtualBubbleCenter.X = 150.0;
            else if (virtualBubbleCenter.X >= 1830) virtualBubbleCenter.X = 1800;
            else virtualBubbleCenter.X = Math.Floor((virtualBubbleCenter.X + 30) / 60) * 60;

            //"Applatissement" de la portée
            int offset = GlobalVariables.ManipulationGrid.ElementAtOrDefault((int)((double)virtualBubbleCenter.X / 60.0));
            virtualBubbleCenter.Y += offset;

            PositionMelody = new Point(virtualBubbleCenter.X, virtualBubbleCenter.Y);

            previewNotesGrid.Items.Clear();

            //Y dans le cadre portée ?
            //Si oui, animation
            //pas de else
            if (virtualBubbleCenter.Y < 576 && virtualBubbleCenter.Y > 165)
            {
                if (virtualBubbleCenter.Y < 370)
                {
                    if (virtualBubbleCenter.Y >= 344) virtualBubbleCenter.Y = 344;
                    virtualBubbleCenter.Y = Math.Floor((virtualBubbleCenter.Y + 6.0) / 20.0) * 20.0 + 4.0;
                }
                else
                {
                    if (virtualBubbleCenter.Y <= 395) virtualBubbleCenter.Y = 395;
                    virtualBubbleCenter.Y = Math.Floor((virtualBubbleCenter.Y + 15.0) / 20.0) * 20.0 - 5.0;
                }

            List<NoteViewModel> ListOfNotes = melodyBubbleVM.melodyToListOfNote(PositionMelody);
            Converter cvrt = new Converter();

            double ratio = sessionVM.Grid.ActualWidth / 1920.0;

            for (int i = 0; i < ListOfNotes.Count; i++)
            {
                ScatterViewItem previewNote = new ScatterViewItem();
                FrameworkElementFactory notePreviewImage = new FrameworkElementFactory(typeof(Image));
                int offset2 = GlobalVariables.ManipulationGrid.ElementAtOrDefault(ListOfNotes[i].Note.Position + 2);
                double betweenStave = (350 - offset2) * ratio;
                bool up;

                previewNote.CanScale = false;
                previewNote.HorizontalAlignment = HorizontalAlignment.Center;
                previewNote.CanRotate = false;
                previewNote.HorizontalAlignment = HorizontalAlignment.Center;

                if (ListOfNotes[i].SVItem.Center.Y < betweenStave)
                {
                    up = true;
                    if (ListOfNotes[i].Note.Flat)
                        notePreviewImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/PreviewNotes/black/" + ListOfNotes[i].Note.Duration + "_bemol.png", UriKind.Relative)));
                    else if (ListOfNotes[i].Note.Sharp)
                        notePreviewImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/PreviewNotes/black/" + ListOfNotes[i].Note.Duration + "_diese.png", UriKind.Relative)));
                    else
                        notePreviewImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/PreviewNotes/black/" + ListOfNotes[i].Note.Duration + ".png", UriKind.Relative)));
                }
                else
                {
                    up = false;
                    if (ListOfNotes[i].Note.Flat)
                        notePreviewImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/PreviewNotes/white/" + ListOfNotes[i].Note.Duration + "_bemol.png", UriKind.Relative)));
                    else if (ListOfNotes[i].Note.Sharp)
                        notePreviewImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/PreviewNotes/white/" + ListOfNotes[i].Note.Duration + "_diese.png", UriKind.Relative)));
                    else
                        notePreviewImage.SetValue(Image.SourceProperty, new BitmapImage(new Uri(@"../../Resources/Images/UI_items/PreviewNotes/white/" + ListOfNotes[i].Note.Duration + ".png", UriKind.Relative)));
                }

                double Xpos = virtualBubbleCenter.X + melodyBubbleVM.MelodyBubble.Melody.Notes[i].Position * 60.0;
                double Ypos = cvrt.getCenterY(up, melodyBubbleVM.MelodyBubble.Melody.Notes[i]) + GlobalVariables.ManipulationGrid.ElementAtOrDefault(melodyBubbleVM.MelodyBubble.Melody.Notes[i].Position + 2) - offset;
                previewNote.Center = new Point(Xpos * ratio, Ypos * ratio);

                notePreviewImage.SetValue(Image.IsHitTestVisibleProperty, false);

                notePreviewImage.SetValue(Image.WidthProperty, (125.0 / 1920.0) * sessionVM.Grid.ActualWidth);
                notePreviewImage.SetValue(Image.HeightProperty, (260.0 / 1080.0) * sessionVM.Grid.ActualHeight);

                FrameworkElementFactory grid = new FrameworkElementFactory(typeof(Grid));
                grid.AppendChild(notePreviewImage);

                ControlTemplate ct = new ControlTemplate(typeof(ScatterViewItem));
                ct.VisualTree = grid;

                Style notePreviewStyle = new Style(typeof(ScatterViewItem));
                notePreviewStyle.Setters.Add(new Setter(ScatterViewItem.TemplateProperty, ct));
                previewNote.Style = notePreviewStyle;
                previewNote.Opacity = 0.6;

                previewNotesGrid.Items.Add(previewNote);
            }
            try { sessionVM.Grid.Children.Add(previewNotesGrid); }
            catch (Exception exc) { }
            }
        }