/// <summary> /// Constructor by copie. /// </summary> /// <param name="noteVM"></param> public NoteViewModel(NoteViewModel noteVM) { Note = new Note(noteVM.Note); ParentSV = noteVM.ParentSV; SVItem = noteVM.SVItem; Animation = noteVM.Animation; Picked = noteVM.Picked; }
/// <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); }