public async void LoadSong(string fileName) { IPlatformStorage storage = MainPage.PlatformStorage; await storage.OpenFile(fileName, false); try { // Get song details // Name // Number of section SongName = storage.FileReadString(); int length = storage.FileReadInt(); SongList.Clear(); // For each section, get section details // Name // Repetitions // Tempo // BeatsPerMeasure // BeatValue // Number of notes in the sequence // (The sequence) for (int s = 0; s < length; s++) { // Basic properties Section sec = Section.GetNewBasicSection(); sec.Name = storage.FileReadString(); sec.Repetitions = storage.FileReadInt(); sec.Tempo = (double)storage.FileReadFloat(); sec.BeatsPerMeasure = storage.FileReadInt(); sec.BeatValue = storage.FileReadInt(); int numberOfNotes = storage.FileReadInt(); sec.Sequence = new List <Note>(); // For each note in sequence, put all non-derived properties // IsSound // NoteType // IsDotted // Tuplet // TieString // Accent for (int n = 0; n < numberOfNotes; n++) { Note note = new Note(4, 0); note.IsSound = storage.FileReadBool(); note.NoteType = storage.FileReadInt(); note.IsDotted = storage.FileReadBool(); note.Tuplet = storage.FileReadInt(); note.TieString = storage.FileReadInt(); note.Accent = storage.FileReadInt(); sec.Sequence.Add(note); } SongList.Add(sec); CurrentSong.Sections[s].CalculateDerivedAttributes(); } ParentPage.UpdateDisplay(); SongHasUnsavedChanges = false; } catch (Exception ex) { await DisplayAlert("Issue", "Could not load the song - " + ex.Message, "OK"); } finally { await storage.CloseFile(false); } }
private async void SaveSong(object sender, EventArgs e) { IPlatformStorage storage = MainPage.PlatformStorage; string fileName = CurrentSong.Name + ".gma"; bool exists = await storage.FileExists(fileName); if (exists) { bool accepted = await DisplayAlert("Information", "A song is already saved with that name. Would you like to overwrite it?", "Yes", "No"); if (!accepted) { await DisplayAlert("Information", "The song was not saved.", "OK"); return; } } await storage.OpenFile(fileName, true); try { // Put song details // Name // Number of section int length = CurrentSong.NumberOfSections; storage.FileWriteString(CurrentSong.Name); storage.FileWriteInt(length); // For each section, put section details // Name // Repetitions // Tempo // BeatsPerMeasure // BeatValue // Number of notes in the sequence // (The sequence) for (int s = 0; s < length; s++) { // Basic properties Section sec = CurrentSong.Sections[s]; int numberOfNotes = sec.Sequence.Count; storage.FileWriteString(sec.Name); storage.FileWriteInt(sec.Repetitions); storage.FileWriteFloat((float)sec.Tempo); storage.FileWriteInt(sec.BeatsPerMeasure); storage.FileWriteInt(sec.BeatValue); storage.FileWriteInt(numberOfNotes); // For each note in sequence, put all non-derived properties // IsSound // NoteType // IsDotted // Tuplet // TieString // Accent for (int n = 0; n < numberOfNotes; n++) { Note note = sec.Sequence[n]; storage.FileWriteBool(note.IsSound); storage.FileWriteInt(note.NoteType); storage.FileWriteBool(note.IsDotted); storage.FileWriteInt(note.Tuplet); storage.FileWriteInt(note.TieString); storage.FileWriteInt(note.Accent); } } await DisplayAlert("Information", "Song saved.", "OK"); SongHasUnsavedChanges = false; } catch (Exception ex) { await DisplayAlert("Issue", "Could not save the song - " + ex.Message, "OK"); } finally { await storage.CloseFile(true); } }