diff --git a/MusiLib/MusiLib/Views/PartitionView.xaml b/MusiLib/MusiLib/Views/PartitionView.xaml index 79f1148..344515d 100644 --- a/MusiLib/MusiLib/Views/PartitionView.xaml +++ b/MusiLib/MusiLib/Views/PartitionView.xaml @@ -20,7 +20,7 @@ + - - - - - - - - - - - - - - - - - + + + diff --git a/MusiLib/MusiLib/Views/PartitionView.xaml.cs b/MusiLib/MusiLib/Views/PartitionView.xaml.cs index 4527b44..725d9ea 100644 --- a/MusiLib/MusiLib/Views/PartitionView.xaml.cs +++ b/MusiLib/MusiLib/Views/PartitionView.xaml.cs @@ -1,163 +1,215 @@ -using Android.Service.Voice; -using Microsoft.Maui.Controls.PlatformConfiguration; -using MusiLib.Model; -using System.Collections.Concurrent; -using System.Diagnostics; - -namespace MusiLib.Views; - - -public partial class PartitionView : ContentPage -{ - - public Manager MyManager => (App.Current as App).MyManager; - - public Metronome music = new Metronome(); - public Metronome metronome = new Metronome(); - public int IdTab { get; set; } - - - public PartitionView() - { - InitializeComponent(); - BindingContext = MyManager; - } - - public PartitionView(int id) - { - InitializeComponent(); - IdTab = id; - Part.BindingContext = MyManager.partitions[IdTab]; - Part2.BindingContext = MyManager; - - InitializeButton(); - } - - private void Play_Music(object sender, EventArgs e) - { - - Button button = (Button)sender; - if (!music.isMusicBeginning) - { - _ = music.Lancer(MyManager.partitions[IdTab].Son); - button.Text = "Pause"; - } - else if(!music.isMusicPlaying) - { - music.PlayMusic(); - button.Text = "Pause"; - } - else - { - music.PauseMusic(); - button.Text = "Jouer"; - } - } - - private void Play_Metronome(object sender, EventArgs e) - { - - Button button = (Button)sender; - if (!metronome.isMusicBeginning) - { - _ = metronome.Lancer("40_BPM_Metronome.mp3"); - button.Text = "Pause"; - } - else if (!metronome.isMusicPlaying) - { - metronome.PlayMusic(); - button.Text = "Pause"; - } - else - { - metronome.PauseMusic(); - button.Text = "Jouer"; - } - } - - private void Stop_Music(object sender, EventArgs e) - { - music.StopMusic(); - Button button = (Button)FindByName("play_music_button"); - button.Text = "Jouer"; - } - +using Microsoft.Maui.Controls.PlatformConfiguration; +using MusiLib.Model; +using System.Collections.Concurrent; +using System.Diagnostics; + +namespace MusiLib.Views; + + +public partial class PartitionView : ContentPage +{ + + public Manager MyManager => (App.Current as App).MyManager; + + public Metronome music = new Metronome(); + public Metronome metronome = new Metronome(); + public int IdTab { get; set; } + + + public PartitionView() + { + InitializeComponent(); + BindingContext = MyManager; + } + + public PartitionView(int id) + { + InitializeComponent(); + IdTab = id; + Part.BindingContext = MyManager.partitions[IdTab]; + + InitializeButton(); + ChargerPartitionsSimilaires(); + } + + private void Play_Music(object sender, EventArgs e) + { + + Button button = (Button)sender; + if (!music.isMusicBeginning) + { + _ = music.Lancer(MyManager.partitions[IdTab].Son); + button.Text = "Pause"; + } + else if(!music.isMusicPlaying) + { + music.PlayMusic(); + button.Text = "Pause"; + } + else + { + music.PauseMusic(); + button.Text = "Jouer"; + } + } + + private void Play_Metronome(object sender, EventArgs e) + { + + Button button = (Button)sender; + if (!metronome.isMusicBeginning) + { + _ = metronome.Lancer("40_BPM_Metronome.mp3"); + button.Text = "Pause"; + } + else if (!metronome.isMusicPlaying) + { + metronome.PlayMusic(); + button.Text = "Pause"; + } + else + { + metronome.PauseMusic(); + button.Text = "Jouer"; + } + } + + private void Stop_Music(object sender, EventArgs e) + { + music.StopMusic(); + Button button = (Button)FindByName("play_music_button"); + button.Text = "Jouer"; + } + private void Stop_Metronome(object sender, EventArgs e) { metronome.StopMusic(); Button button = (Button)FindByName("play_metronome_button"); button.Text = "Jouer"; - } - - protected override bool OnBackButtonPressed() - { - metronome.StopMusic(); - music.StopMusic(); - return base.OnBackButtonPressed(); - } - - protected override void OnDisappearing() - { - base.OnDisappearing(); - metronome.StopMusic(); - music.StopMusic(); - } - - protected override void OnAppearing() - { - base.OnAppearing(); - Shell.Current.Navigating += Shell_Navigating; - } - - private void Shell_Navigating(object sender, ShellNavigatingEventArgs e) - { - if (e.Source == ShellNavigationSource.ShellItemChanged) - { - metronome.StopMusic(); - music.StopMusic(); - } - } - - private void InitializeButton() - { - if (MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom)) - { - favoriButton.Source = "etoile.png"; - } - else - { - favoriButton.Source = "etoile_vide.png"; - } - } - - private void AddFavoriButton(object sender, EventArgs e) - { - ImageButton button = (ImageButton)sender; - - if (!MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom)) - { - MyManager.favoris.Add(MyManager.partitions[IdTab]); - MyManager.sauvegardeFavoriAdd(MyManager.partitions[IdTab]); - button.Source = "etoile.png"; - } - else - { - MyManager.favoris.RemoveAll(f => f.Nom == MyManager.partitions[IdTab].Nom); - MyManager.sauvegardeFavoriRemove(MyManager.partitions[IdTab]); - button.Source = "etoile_vide.png"; - } - } - - private void TempoSlider(object sender, ValueChangedEventArgs e) - { - float selectedValue = (float)e.NewValue; - music.ReglerTempo(selectedValue); - } - + } + + protected override bool OnBackButtonPressed() + { + metronome.StopMusic(); + music.StopMusic(); + return base.OnBackButtonPressed(); + } + + protected override void OnDisappearing() + { + base.OnDisappearing(); + metronome.StopMusic(); + music.StopMusic(); + } + + protected override void OnAppearing() + { + base.OnAppearing(); + Shell.Current.Navigating += Shell_Navigating; + } + + private void Shell_Navigating(object sender, ShellNavigatingEventArgs e) + { + if (e.Source == ShellNavigationSource.ShellItemChanged) + { + metronome.StopMusic(); + music.StopMusic(); + } + } + + private void InitializeButton() + { + if (MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom)) + { + favoriButton.Source = "etoile.png"; + } + else + { + favoriButton.Source = "etoile_vide.png"; + } + } + + private void ChargerPartitionsSimilaires() + { + string auteur = MyManager.partitions[IdTab].Auteur; + string instrument = MyManager.partitions[IdTab].Instrument; + + var partitionsSimilaires = MyManager.partitions.Where(p => p.Auteur.ToLower() == auteur.ToLower() || + p.Instrument.ToLower() == instrument.ToLower()).ToList(); + + uint i = 1; + + foreach (var partition in partitionsSimilaires) + { + ++i; + if(i>9) + { + return; + } + int indicePartition = MyManager.partitions.IndexOf(partition); + + var imageButton = new ImageButton + { + Source = partition.Image[0], + HeightRequest = 80, + WidthRequest = 80, + AutomationId = indicePartition.ToString() + }; + + imageButton.Clicked += GoToPartitionButton; + + PartitionsSimilairesStackLayout.Children.Add(imageButton); + } + } + + + + + private void GoToPartitionButton(object sender, EventArgs e) + { + if (!IAllowClick.AllowTap) return; + else IAllowClick.AllowTap = false; + + var button = (ImageButton)sender; + var idAutomation = button.AutomationId; + + if (int.TryParse(idAutomation, out int id)) + { + Navigation.PushAsync(new PartitionView(id)); + } + + IAllowClick.ResumeTap(); + } + + + private void AddFavoriButton(object sender, EventArgs e) + { + ImageButton button = (ImageButton)sender; + + if (!MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom)) + { + MyManager.favoris.Add(MyManager.partitions[IdTab]); + MyManager.sauvegardeFavoriAdd(MyManager.partitions[IdTab]); + button.Source = "etoile.png"; + } + else + { + MyManager.favoris.RemoveAll(f => f.Nom == MyManager.partitions[IdTab].Nom); + MyManager.sauvegardeFavoriRemove(MyManager.partitions[IdTab]); + button.Source = "etoile_vide.png"; + } + } + + private void TempoSlider(object sender, ValueChangedEventArgs e) + { + float selectedValue = (float)e.NewValue; + music.ReglerTempo(selectedValue); + } + private void BPMSlider(object sender, ValueChangedEventArgs e) { float selectedValue = (float)e.NewValue; metronome.ReglerTempo(selectedValue); - } - -} + } + +}