public async Task <bool> DeleteSong(string fileName)
        {
            IPlatformStorage storage = MainPage.PlatformStorage;
            bool             success = await storage.DeleteFile(fileName);

            return(success);
        }
Пример #2
0
        public bool Equals(IPlatformStorage other)
        {
            if (other == null)
            {
                return(false);
            }

            return(m_id == other.Id);
        }
        private async void LoadSong(object sender, EventArgs e)
        {
            if (SongHasUnsavedChanges)
            {
                bool confirm = await DisplayAlert("Question", "The current song has unsaved changes. Are you sure you want to load another song?", "Yes", "No");

                if (!confirm)
                {
                    return;
                }
            }

            IPlatformStorage storage = MainPage.PlatformStorage;

            string[] fileList = await storage.GetExistingFileList();

            await Navigation.PushAsync(new SongSelectPage(this, fileList));
        }
        // Standard constructor, receiving the settings object to modify if the save button is pressed
        public SettingsPage(SettingsObject _settings, IPlatformStorage _platformStorage)
        {
            // Don't show the navigation action bar
            NavigationPage.SetHasNavigationBar(this, false);

            // Stash settings objects locally and initialise the layout stuff
            settings        = _settings;
            platformStorage = _platformStorage;
            InitializeComponent();
            BindingContext = this;

            // Make a local copy of the settings object
            localSettings            = new SettingsObject(null);
            localSettings.FlashCues  = settings.FlashCues;
            localSettings.FlashColor = new Color(
                settings.FlashColor.R,
                settings.FlashColor.G,
                settings.FlashColor.B
                );
            localSettings.OneTapGain     = settings.OneTapGain;
            localSettings.OneTapDuration = settings.OneTapDuration;

            // Set what the sliders do
            sliderBPMGain.PropertyChanged  += SliderBPMGain_PropertyChanged;
            sliderDuration.PropertyChanged += SliderDuration_PropertyChanged;

            // Initialise controls
            sliderBPMGain.Value  = localSettings.OneTapGain * 100.0f;
            sliderDuration.Value = localSettings.OneTapDuration / 6.0f;
            updateCuesDisplay();
            updateSliderBPMGainDisplay(localSettings.OneTapGain);
            updateSliderBPMDurationDisplay(localSettings.OneTapDuration);

            // Initialise more controls
            if (settings.OneTapType == PlaybackObject.TempoLiftType.LiftGradual)
            {
                pickLiftType.SelectedIndex = 0;
            }
            else
            {
                pickLiftType.SelectedIndex = 1;
            }
        }
 // Read platform-specific storage, or set default values if unable
 public SettingsObject(IPlatformStorage platformStorage)
 {
     if (platformStorage != null && platformStorage.KeyExists(KEY_CUES))
     {
         FlashCues  = platformStorage.GetBoolean(KEY_CUES);
         FlashColor = new Color(
             platformStorage.GetFloat(KEY_COLOR_R),
             platformStorage.GetFloat(KEY_COLOR_G),
             platformStorage.GetFloat(KEY_COLOR_B)
             );
         OneTapGain     = platformStorage.GetFloat(KEY_BPM_GAIN);
         OneTapDuration = platformStorage.GetFloat(KEY_BPM_DURATION);
         OneTapType     = (PlaybackObject.TempoLiftType)platformStorage.GetInt(KEY_LIFT_TYPE);
     }
     else
     {
         FlashCues      = false;
         FlashColor     = new Color(0.0, 0.8, 0.8);
         OneTapGain     = 0.2f;
         OneTapDuration = 180.0f;
         OneTapType     = 0;
     }
 }
Пример #6
0
        private SQLiteConnection(string fileName, SQLiteOpen openFlag, bool setTemporaryDirectory)
        {
            this.platformMarshal = Platform.Instance.PlatformMarshal;
            this.platformStorage = Platform.Instance.PlatformStorage;
            this.sqlite3Provider = Platform.Instance.SQLite3Provider;

            if (setTemporaryDirectory)
            {
                this.SetTemporaryDirectory();
            }

            var localFilePath = string.Empty;

            if (fileName.Trim().ToLowerInvariant() == ":memory:")
            {
                localFilePath = ":memory:";
            }
            else if (fileName.Trim() != string.Empty)
            {
                localFilePath = this.platformStorage.GetLocalFilePath(fileName);
            }

            var fileNamePtr = this.platformMarshal.MarshalStringManagedToNativeUTF8(localFilePath);

            int flags;

            switch (openFlag)
            {
            case SQLiteOpen.READONLY:
                // URI|DONTCREATE|READONLY
                flags = 0x41;
                break;

            case SQLiteOpen.READWRITE:
                // URI|CREATE|READWRITE
                flags = 0x46;
                break;

            default:
                // URI|CREATE|READWRITE
                flags = 0x46;
                break;
            }

            try
            {
                var openResult = (SQLiteResult)this.sqlite3Provider.Sqlite3Open(fileNamePtr, out this.db, flags);

                if (openResult != SQLiteResult.OK)
                {
                    if (this.db != IntPtr.Zero)
                    {
                        var errmsgPtr = this.sqlite3Provider.Sqlite3Errmsg(this.db);

                        var errmsg = this.platformMarshal.MarshalStringNativeUTF8ToManaged(errmsgPtr);

                        this.sqlite3Provider.Sqlite3CloseV2(this.db);

                        throw new SQLiteException("Unable to open the database file: " + fileName + " Details: " + errmsg);
                    }
                    else
                    {
                        throw new SQLiteException("Unable to open the database file: " + fileName + " Details: " + openResult.ToString());
                    }
                }
            }
            catch (SQLiteException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SQLiteException("Unable to open the database file: " + fileName, ex);
            }
            finally
            {
                if (fileNamePtr != IntPtr.Zero)
                {
                    this.platformMarshal.CleanUpStringNativeUTF8(fileNamePtr);
                }
            }
        }
Пример #7
0
        public MainPage(IPlatformStorage platformStorage, IPlatformAudioPlayer audioPlayer)
        {
            // Initialise layout, and don't show the navigation action bar
            NavigationPage.SetHasNavigationBar(this, false);
            InitializeComponent();

            // Don't re-create assets if the app is already running and the song etc. are already created
            if (PlatformStorage == null || AudioPlayer == null || Settings == null || Playback == null || song == null || timer == null)
            {
                // Stash the platform storage and audio interface object locally
                PlatformStorage = platformStorage;
                AudioPlayer     = audioPlayer;

                // Create the settings and playback objects
                Settings = new SettingsObject(platformStorage);
                Playback = new PlaybackObject();

                // Create a new default song and timer
                song  = new Song();
                timer = new Timer(TimerElapsed, 1000);
            }

            // Update the section display when MainPage size changes
            SizeChanged += (sender, e) => {
                // Get content window sizes
                double width  = this.Width;
                double height = this.Height;

                // Size according to orientation
                double ctrlSize = width > height ? 0.15 * (height - 40) : 0.25 * (width - 40);
                BottomCtrlRow.Height = ctrlSize;
                CtrlColumn1.Width    = ctrlSize;
                CtrlColumn2.Width    = ctrlSize;
                ctrlSize             = width > height ? 0.15 * (height + 20) : 0.25 * (width + 20);
                PlaybackCtrlPlayStop.WidthRequest  = ctrlSize * 0.5;
                PlaybackCtrlPlayStop.HeightRequest = ctrlSize * 0.5;
                PlaybackCtrlRewind.WidthRequest    = ctrlSize * 0.3;
                PlaybackCtrlRewind.HeightRequest   = ctrlSize * 0.3;
                PlaybackCtrlForward.WidthRequest   = ctrlSize * 0.3;
                PlaybackCtrlForward.HeightRequest  = ctrlSize * 0.3;
                PlaybackCtrlPause.WidthRequest     = ctrlSize * 0.3;
                PlaybackCtrlPause.HeightRequest    = ctrlSize * 0.3;
            };

            // Set image on the play-stop button
            if (Playback.IsPlaying)
            {
                PlaybackCtrlPlayStop.Source = "stopbutton.png";
            }
            else
            {
                PlaybackCtrlPlayStop.Source = "playbutton.png";
            };

            // Populate the song display when the layout is measured
            layoutSectionDisplay.MeasurePerformed += UpdateDisplay;

            // Initialise display parameters
            LastProgressSection = false;
            LastProgressSong    = false;
            LastProgressSession = false;

            // Initialise the timer-type stuff
            TempoSliderChanged(null, null);
            flashTimerRunning = false;
            LastTapTime       = -1;
        }
        private SQLiteConnection(string fileName, SQLiteOpen openFlag, bool setTemporaryDirectory)
        {
            this.platformMarshal = Platform.Instance.PlatformMarshal;
            this.platformStorage = Platform.Instance.PlatformStorage;
            this.sqlite3Provider = Platform.Instance.SQLite3Provider;

            if (setTemporaryDirectory)
            {
                this.SetTemporaryDirectory();
            }

            var localFilePath = string.Empty;

            if (fileName.Trim().ToLowerInvariant() == ":memory:")
            {
                localFilePath = ":memory:";
            }
            else if (fileName.Trim() != string.Empty)
            {
                localFilePath = this.platformStorage.GetLocalFilePath(fileName);
            }

            var fileNamePtr = this.platformMarshal.MarshalStringManagedToNativeUTF8(localFilePath);

            int flags;

            switch (openFlag)
            {
                case SQLiteOpen.READONLY:
                    // URI|DONTCREATE|READONLY
                    flags = 0x41;
                    break;
                case SQLiteOpen.READWRITE:
                    // URI|CREATE|READWRITE
                    flags = 0x46;
                    break;
                default:
                    // URI|CREATE|READWRITE
                    flags = 0x46;
                    break;
            }

            try
            {
                var openResult = (SQLiteResult)this.sqlite3Provider.Sqlite3Open(fileNamePtr, out this.db, flags);

                if (openResult != SQLiteResult.OK)
                {
                    if (this.db != IntPtr.Zero)
                    {
                        var errmsgPtr = this.sqlite3Provider.Sqlite3Errmsg(this.db);

                        var errmsg = this.platformMarshal.MarshalStringNativeUTF8ToManaged(errmsgPtr);

                        this.sqlite3Provider.Sqlite3CloseV2(this.db);

                        throw new SQLiteException("Unable to open the database file: " + fileName + " Details: " + errmsg);
                    }
                    else
                    {
                        throw new SQLiteException("Unable to open the database file: " + fileName + " Details: " + openResult.ToString());
                    }
                }
            }
            catch (SQLiteException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SQLiteException("Unable to open the database file: " + fileName, ex);
            }
            finally
            {
                if (fileNamePtr != IntPtr.Zero)
                {
                    this.platformMarshal.CleanUpStringNativeUTF8(fileNamePtr);
                }
            }
        }
 public string MountStorage(IPlatformStorage storageManager)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 public App(IPlatformStorage platformStorage, IPlatformAudioPlayer audioPlayer)
 {
     InitializeComponent();
     MainPage = new NavigationPage(new MetronomeAmplified.MainPage(platformStorage, audioPlayer));
 }
Пример #11
0
 public static bool Equals(IPlatformStorage left, IPlatformStorage right)
 {
     return(left.Equals(right));
 }
        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);
            }
        }