Пример #1
0
        /// <summary>
        /// Loads a session from a binary file
        /// </summary>
        public void LoadSession()
        {
            SessionSVI.Width = Grid.ActualWidth;
            SessionSVI.Height = Grid.ActualHeight;

            ratio = Grid.ActualWidth / 1920.0;

            string path = "Sessions/sess" + SessionID + ".bin";
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream stream = File.Open(path, FileMode.Open);
            SessionData sd = (SessionData)formatter.Deserialize(stream);
            stream.Close();

            Session = new Session();
            Session.ThemeID = sd.ThemeID;

            switch (Session.ThemeID)
            {
                case 2: Session.Theme = new Theme2(); break;
                case 3: Session.Theme = new Theme3(); break;
                case 4: Session.Theme = new Theme4(); break;
                default: Session.Theme = new Theme1(); break;
            }

            ThemeVM = new ThemeViewModel(Session.Theme, this);
            Converter conv = new Converter();
            Session.StaveTop = new Stave(Session.Theme.InstrumentsTop[0]);
            Session.StaveBottom = new Stave(Session.Theme.InstrumentsBottom[0]);

            Grid.Background = ThemeVM.BackgroundImage;
            PlayBarCache.Background = ThemeVM.PlayBarCache;

            Bubbles = new ScatterView();
            Notes = new ScatterView();
            UpdateSound = new ChangeSoundViewModel(this);
            NotesOnStave = new List<NoteViewModel>();

            NbgVM = new NoteBubbleGeneratorViewModel(Session.NoteBubbleGenerator, this);
            MbgVM = new MelodyBubbleGeneratorViewModel(Session.MelodyBubbleGenerator, this);

            displayTrees(new Thickness(20.0 * ratio, 0, 0, 130.0 * ratio), new Thickness(20.0 * ratio, 0, 0, 580.0 * ratio));

            Play_Button = new Grid();
            Play_Button.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            Play_Button.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            Play_Button.Background = ThemeVM.PlayImage;
            Play_Button.Visibility = Visibility.Visible;
            IsPlaying = false;

            Play_Button.PreviewTouchDown += new EventHandler<TouchEventArgs>(Play_Button_TouchDown);

            switch (Session.ThemeID)
            {
                case 2: Grid.Children.Add(ThemeChooser.Bird); break;
                case 3: Grid.Children.Add(ThemeChooser.Dragon); break;
                case 4: Grid.Children.Add(ThemeChooser.Cat); break;
                default: break;
            }
            Grid.Children.Add(Bubbles);
            Grid.Children.Add(Notes);
            Grid.Children.Add(Play_Button);
            Grid.Children.Add(UpdateSound.Grid);
            Grid.Children.Add(NbgVM.Grid);
            Grid.Children.Add(MbgVM.Grid);
            Grid.Children.Add(Theme_Button);
            Grid.Children.Add(Tempo_Button);
            Grid.Children.Add(PlayBar);
            Grid.Children.Add(PlayBarCache);
            Grid.Children.Add(StaveCache);
            Grid.Children.Add(previewGrid);
            Grid.Children.Add(topStaveHighlight);
            Grid.Children.Add(bottomStaveHighlight);

            Grid.SetZIndex(UpdateSound.Grid, 7);
            Grid.SetZIndex(TreeUp.Grid, 6);
            Grid.SetZIndex(TreeDown.Grid, 6);
            Grid.SetZIndex(Bubbles, 5);
            Grid.SetZIndex(Notes, 4);
            Grid.SetZIndex(NbgVM.Grid, 3);
            Grid.SetZIndex(MbgVM.Grid, 3);
            Grid.SetZIndex(Play_Button, 3);
            Grid.SetZIndex(Theme_Button, 3);
            Grid.SetZIndex(Tempo_Button, 3);
            Grid.SetZIndex(previewGrid, 2);
            Grid.SetZIndex(StaveCache, 2);
            Grid.SetZIndex(topStaveHighlight, 2);
            Grid.SetZIndex(bottomStaveHighlight, 2);
            Grid.SetZIndex(PlayBarCache, 1);
            Grid.SetZIndex(PlayBar, 0);
            Grid.SetZIndex(ThemeChooser.Bird, 0);
            Grid.SetZIndex(ThemeChooser.Dragon, 0);
            Grid.SetZIndex(ThemeChooser.Cat, 0);

            Theme_Button.Background = ThemeVM.ThemesImage;

            double XCenter;
            foreach (Note note in sd.StaveTopNotes)
            {
                XCenter = ((note.Position * 60.0 + 120.0) / 1920.0) * Grid.ActualWidth;
                Note newNote = new Note(note);
                NoteViewModel noteVM = new NoteViewModel(new Point(XCenter, (conv.getCenterY(true, note) / 1080.0) * Grid.ActualHeight), newNote, Notes, this);
                Session.StaveTop.AddNote(newNote, newNote.Position);
                Notes.Items.Add(noteVM.SVItem);
                NotesOnStave.Add(noteVM);
            }

            foreach (Note note in sd.StaveBottomNotes)
            {
                XCenter = ((note.Position * 60.0 + 120.0) / 1920.0) * Grid.ActualWidth;
                Note newNote = new Note(note);
                NoteViewModel noteVM = new NoteViewModel(new Point(XCenter, (conv.getCenterY(false, note) / 1080.0) * Grid.ActualHeight), newNote, Notes, this);
                Session.StaveBottom.AddNote(newNote, newNote.Position);
                Notes.Items.Add(noteVM.SVItem);
                NotesOnStave.Add(noteVM);
                Session.StaveBottom.AddNote(noteVM.Note, noteVM.Note.Position);
            }

            switch (sd.bpm)
            {
                default : Tempo_Button.Background = ThemeVM.TempoImage[0]; break;
                case 90: Tempo_Button.Background = ThemeVM.TempoImage[1]; break;
                case 120: Tempo_Button.Background = ThemeVM.TempoImage[2]; break;

            }

            TreeDown.SetInstrument(sd.TopInstrument);
            TreeUp.SetInstrument(sd.BottomInstrument);
            Session.PlayBackgroundSound();

            SetDimensions(Grid.ActualWidth, Grid.ActualHeight);
            //UpdateEveryDimensions(Grid.ActualWidth, Grid.ActualHeight);
            if (sd.bpm == 0)
            {
                Session.ChangeBpm(60);
            }
            else Session.ChangeBpm(sd.bpm);
        }
Пример #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="width">The real Width</param>
        /// <param name="height">The real Height</param>
        /// <param name="s">The Session</param>
        /// <param name="IDs">List of IDs</param>
        /// <param name="animated">True if animated</param>
        public SessionViewModel(Double width, Double height, Session s, List<int> IDs, bool animated)
        {
            Session = s;
            BeingDeleted = false;
            InitialScale = true;
            removeDeleteButtonsOnTouchUp = false;
            SessionSVI = new ScatterViewItem();
            SessionSVI.Width = width;
            SessionSVI.Height = height;

            ratio = width / 1920.0;
            originalRatio = width / 1920.0;

            ThemeVM = new ThemeViewModel(Session.Theme, this);
            Grid = new Grid();
            UpdateSound = new ChangeSoundViewModel(this);
            Bubbles = new ScatterView();
            Notes = new ScatterView();
            NotesOnStave = new List<NoteViewModel>();
            NbgVM = new NoteBubbleGeneratorViewModel(Session.NoteBubbleGenerator, this);
            MbgVM = new MelodyBubbleGeneratorViewModel(Session.MelodyBubbleGenerator, this);

            Orientation = "bottom";
            SessionSVI.Opacity = 0;
            Bubbles.Visibility = Visibility.Visible;
            Notes.Visibility = Visibility.Visible;

            Grid.Background = (new ThemeViewModel(Session.Theme, this)).BackgroundImage;

            Play_Button = new Grid();
            Play_Button.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            Play_Button.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            Play_Button.Background = ThemeVM.PlayImage;
            Play_Button.Visibility = Visibility.Visible;
            IsPlaying = false;

            previewGrid = new Grid();
            ImageBrush previewGridImage = new ImageBrush();
            previewGridImage.ImageSource = new BitmapImage(new Uri(@"../../Resources/Images/ui_items/previewGrid.png", UriKind.Relative));
            previewGrid.Background = previewGridImage;
            previewGrid.Opacity = 0;
            previewGrid.Margin = new Thickness(150.0 * ratio, 90.0 * ratio, 90.0 * ratio, 480.0 * ratio);

            topStaveHighlight = new Grid();
            ImageBrush tSHImage = new ImageBrush();
            tSHImage.ImageSource = new BitmapImage(new Uri(@"../../Resources/Images/ui_items/blackStaveHighlight.png", UriKind.Relative));
            topStaveHighlight.Background = tSHImage;
            topStaveHighlight.Opacity = 0;
            topStaveHighlight.Margin = new Thickness(0.0, 60.0 * ratio, 0.0, 480.0 * ratio);

            bottomStaveHighlight = new Grid();
            ImageBrush bSHImage = new ImageBrush();
            bSHImage.ImageSource = new BitmapImage(new Uri(@"../../Resources/Images/ui_items/whiteStaveHighlight.png", UriKind.Relative));
            bottomStaveHighlight.Background = bSHImage;
            bottomStaveHighlight.Opacity = 0;
            bottomStaveHighlight.Margin = new Thickness(0.0, 60.0 * ratio, 0.0, 480.0 * ratio);

            Play_Button.PreviewTouchDown += new EventHandler<TouchEventArgs>(Play_Button_TouchDown);

            Theme_Button = new Grid();
            Theme_Button.Width = 351;
            Theme_Button.Height = 110;
            Theme_Button.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            Theme_Button.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            Theme_Button.Margin = new Thickness(0, 0, 100.0 * ratio, 0);
            Theme_Button.Background = ThemeVM.ThemesImage;

            Tempo_Button = new Grid();
            Tempo_Button.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
            Tempo_Button.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            Tempo_Button.Margin = new Thickness(0, 0, 470.0 * ratio, 0);
            Tempo_Button.Background = ThemeVM.TempoImage[1];
            Tempo_Button.PreviewTouchDown += new EventHandler<TouchEventArgs>(Tempo_Button_TouchDown);

            SessionSVI.CanMove = false;
            SessionSVI.CanRotate = false;
            SessionSVI.ShowsActivationEffects = false;

            displayTrees(new Thickness(20.0 * ratio, 0, 0, 130.0 * ratio), new Thickness(20.0 * ratio, 0, 0, 580.0 * ratio));

            PlayBar = new Grid();
            PlayBar.Width = 12.0 * ratio;
            PlayBar.Height = 490.0 * ratio;
            ImageBrush PBImage = new ImageBrush();
            PBImage.ImageSource = new BitmapImage(new Uri(@"../../Resources/Images/ui_items/play_bar.png", UriKind.Relative));
            PlayBar.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            PlayBar.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            PlayBar.Margin = new Thickness(120.0 * ratio, 99.0 * ratio, 0.0, 0.0);
            PlayBar.Background = PBImage;
            PlayBar.Opacity = 0.0;

            PlayBarCache = new Grid();
            PlayBarCache.Width = 1920.0 * ratio;
            PlayBarCache.Height = 531.0 * ratio;
            PlayBarCache.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            PlayBarCache.Margin = new Thickness(0.0, 98.0 * ratio, 0.0, 0.0);
            PlayBarCache.Background = ThemeVM.PlayBarCache;
            PlayBarCache.Opacity = 0.0;

            StaveCache = new Grid();
            StaveCache.Width = 1920.0 * ratio;
            StaveCache.Height = 491.0 * ratio;
            ImageBrush SCImage = new ImageBrush();
            SCImage.ImageSource = new BitmapImage(new Uri(@"../../Resources/Images/ui_items/staves.png", UriKind.Relative));
            StaveCache.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            StaveCache.Margin = new Thickness(0.0, 98.0 * ratio, 0.0, 0.0);
            StaveCache.Background = SCImage;
            StaveCache.Opacity = 0.0;

            Grid.Children.Add(PlayBar);
            Grid.Children.Add(PlayBarCache);
            Grid.Children.Add(StaveCache);
            Grid.Children.Add(Bubbles);
            Grid.Children.Add(Notes);
            Grid.Children.Add(NbgVM.Grid);
            Grid.Children.Add(MbgVM.Grid);
            Grid.Children.Add(Play_Button);
            Grid.Children.Add(Tempo_Button);
            Grid.Children.Add(UpdateSound.Grid);
            Grid.Children.Add(previewGrid);
            Grid.Children.Add(topStaveHighlight);
            Grid.Children.Add(bottomStaveHighlight);

            Grid.SetZIndex(UpdateSound.Grid, 7);
            Grid.SetZIndex(TreeUp.Grid, 6);
            Grid.SetZIndex(TreeDown.Grid, 6);
            Grid.SetZIndex(Bubbles, 5);
            Grid.SetZIndex(Notes, 4);
            Grid.SetZIndex(NbgVM.Grid, 3);
            Grid.SetZIndex(MbgVM.Grid, 3);
            Grid.SetZIndex(Play_Button, 3);
            Grid.SetZIndex(Theme_Button, 3);
            Grid.SetZIndex(Tempo_Button, 3);
            Grid.SetZIndex(previewGrid, 2);
            Grid.SetZIndex(StaveCache, 2);
            Grid.SetZIndex(topStaveHighlight, 2);
            Grid.SetZIndex(bottomStaveHighlight, 2);
            Grid.SetZIndex(PlayBarCache, 1);
            Grid.SetZIndex(PlayBar, 0);

            SessionSVI.Content = Grid;

            ThemeChooser = new ThemeChooser(this);
            Theme_Button.PreviewTouchDown += new EventHandler<TouchEventArgs>(ThemeChooser.Theme_Button_TouchDown);

            int i = 1;
            while (IDs.Contains(i)) i++;
            SessionID = i;
            IDs.Add(i);

            SetDimensions(width, height);
            SessionSVI.Center = new Point(width / 2.0, height / 2.0);

            if (animated) Animation = new SessionAnimation(this);

            DeleteButton = new SurfaceButton();
            DeleteButton.Visibility = Visibility.Hidden;
            ImageBrush ib = new ImageBrush();
            ib.ImageSource = new BitmapImage(new Uri(@"../../Resources/Images/ui_items/delete-icon.png", UriKind.Relative));
            DeleteButton.Background = ib;
            DeleteButton.Width = 25.0;
            DeleteButton.Height = 25.0;
            DeleteButton.HorizontalAlignment = HorizontalAlignment.Left;
            DeleteButton.VerticalAlignment = VerticalAlignment.Top;
            Grid.Children.Add(DeleteButton);

            Grid.SetZIndex(DeleteButton, 1000);

            DeleteButton.PreviewTouchDown += new EventHandler<TouchEventArgs>(DeleteButton_PreviewTouchDown);

            SessionSVI.SizeChanged += new SizeChangedEventHandler(SessionSVI_SizeChanged);
            SessionSVI.PreviewTouchUp += new EventHandler<TouchEventArgs>(SessionSVI_TouchLeave);
        }