parent
0e3b7d82cd
commit
7fce572d0d
@ -1,163 +1,215 @@
|
|||||||
using Android.Service.Voice;
|
using Microsoft.Maui.Controls.PlatformConfiguration;
|
||||||
using Microsoft.Maui.Controls.PlatformConfiguration;
|
using MusiLib.Model;
|
||||||
using MusiLib.Model;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Concurrent;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
|
namespace MusiLib.Views;
|
||||||
namespace MusiLib.Views;
|
|
||||||
|
|
||||||
|
public partial class PartitionView : ContentPage
|
||||||
public partial class PartitionView : ContentPage
|
{
|
||||||
{
|
|
||||||
|
public Manager MyManager => (App.Current as App).MyManager;
|
||||||
public Manager MyManager => (App.Current as App).MyManager;
|
|
||||||
|
public Metronome music = new Metronome();
|
||||||
public Metronome music = new Metronome();
|
public Metronome metronome = new Metronome();
|
||||||
public Metronome metronome = new Metronome();
|
public int IdTab { get; set; }
|
||||||
public int IdTab { get; set; }
|
|
||||||
|
|
||||||
|
public PartitionView()
|
||||||
public PartitionView()
|
{
|
||||||
{
|
InitializeComponent();
|
||||||
InitializeComponent();
|
BindingContext = MyManager;
|
||||||
BindingContext = MyManager;
|
}
|
||||||
}
|
|
||||||
|
public PartitionView(int id)
|
||||||
public PartitionView(int id)
|
{
|
||||||
{
|
InitializeComponent();
|
||||||
InitializeComponent();
|
IdTab = id;
|
||||||
IdTab = id;
|
Part.BindingContext = MyManager.partitions[IdTab];
|
||||||
Part.BindingContext = MyManager.partitions[IdTab];
|
|
||||||
Part2.BindingContext = MyManager;
|
InitializeButton();
|
||||||
|
ChargerPartitionsSimilaires();
|
||||||
InitializeButton();
|
}
|
||||||
}
|
|
||||||
|
private void Play_Music(object sender, EventArgs e)
|
||||||
private void Play_Music(object sender, EventArgs e)
|
{
|
||||||
{
|
|
||||||
|
Button button = (Button)sender;
|
||||||
Button button = (Button)sender;
|
if (!music.isMusicBeginning)
|
||||||
if (!music.isMusicBeginning)
|
{
|
||||||
{
|
_ = music.Lancer(MyManager.partitions[IdTab].Son);
|
||||||
_ = music.Lancer(MyManager.partitions[IdTab].Son);
|
button.Text = "Pause";
|
||||||
button.Text = "Pause";
|
}
|
||||||
}
|
else if(!music.isMusicPlaying)
|
||||||
else if(!music.isMusicPlaying)
|
{
|
||||||
{
|
music.PlayMusic();
|
||||||
music.PlayMusic();
|
button.Text = "Pause";
|
||||||
button.Text = "Pause";
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
music.PauseMusic();
|
||||||
music.PauseMusic();
|
button.Text = "Jouer";
|
||||||
button.Text = "Jouer";
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void Play_Metronome(object sender, EventArgs e)
|
||||||
private void Play_Metronome(object sender, EventArgs e)
|
{
|
||||||
{
|
|
||||||
|
Button button = (Button)sender;
|
||||||
Button button = (Button)sender;
|
if (!metronome.isMusicBeginning)
|
||||||
if (!metronome.isMusicBeginning)
|
{
|
||||||
{
|
_ = metronome.Lancer("40_BPM_Metronome.mp3");
|
||||||
_ = metronome.Lancer("40_BPM_Metronome.mp3");
|
button.Text = "Pause";
|
||||||
button.Text = "Pause";
|
}
|
||||||
}
|
else if (!metronome.isMusicPlaying)
|
||||||
else if (!metronome.isMusicPlaying)
|
{
|
||||||
{
|
metronome.PlayMusic();
|
||||||
metronome.PlayMusic();
|
button.Text = "Pause";
|
||||||
button.Text = "Pause";
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
metronome.PauseMusic();
|
||||||
metronome.PauseMusic();
|
button.Text = "Jouer";
|
||||||
button.Text = "Jouer";
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void Stop_Music(object sender, EventArgs e)
|
||||||
private void Stop_Music(object sender, EventArgs e)
|
{
|
||||||
{
|
music.StopMusic();
|
||||||
music.StopMusic();
|
Button button = (Button)FindByName("play_music_button");
|
||||||
Button button = (Button)FindByName("play_music_button");
|
button.Text = "Jouer";
|
||||||
button.Text = "Jouer";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void Stop_Metronome(object sender, EventArgs e)
|
private void Stop_Metronome(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
metronome.StopMusic();
|
metronome.StopMusic();
|
||||||
Button button = (Button)FindByName("play_metronome_button");
|
Button button = (Button)FindByName("play_metronome_button");
|
||||||
button.Text = "Jouer";
|
button.Text = "Jouer";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
metronome.StopMusic();
|
metronome.StopMusic();
|
||||||
music.StopMusic();
|
music.StopMusic();
|
||||||
return base.OnBackButtonPressed();
|
return base.OnBackButtonPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDisappearing()
|
protected override void OnDisappearing()
|
||||||
{
|
{
|
||||||
base.OnDisappearing();
|
base.OnDisappearing();
|
||||||
metronome.StopMusic();
|
metronome.StopMusic();
|
||||||
music.StopMusic();
|
music.StopMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnAppearing()
|
protected override void OnAppearing()
|
||||||
{
|
{
|
||||||
base.OnAppearing();
|
base.OnAppearing();
|
||||||
Shell.Current.Navigating += Shell_Navigating;
|
Shell.Current.Navigating += Shell_Navigating;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Shell_Navigating(object sender, ShellNavigatingEventArgs e)
|
private void Shell_Navigating(object sender, ShellNavigatingEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.Source == ShellNavigationSource.ShellItemChanged)
|
if (e.Source == ShellNavigationSource.ShellItemChanged)
|
||||||
{
|
{
|
||||||
metronome.StopMusic();
|
metronome.StopMusic();
|
||||||
music.StopMusic();
|
music.StopMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeButton()
|
private void InitializeButton()
|
||||||
{
|
{
|
||||||
if (MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom))
|
if (MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom))
|
||||||
{
|
{
|
||||||
favoriButton.Source = "etoile.png";
|
favoriButton.Source = "etoile.png";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
favoriButton.Source = "etoile_vide.png";
|
favoriButton.Source = "etoile_vide.png";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddFavoriButton(object sender, EventArgs e)
|
private void ChargerPartitionsSimilaires()
|
||||||
{
|
{
|
||||||
ImageButton button = (ImageButton)sender;
|
string auteur = MyManager.partitions[IdTab].Auteur;
|
||||||
|
string instrument = MyManager.partitions[IdTab].Instrument;
|
||||||
if (!MyManager.favoris.Any(favori => favori.Nom == MyManager.partitions[IdTab].Nom))
|
|
||||||
{
|
var partitionsSimilaires = MyManager.partitions.Where(p => p.Auteur.ToLower() == auteur.ToLower() ||
|
||||||
MyManager.favoris.Add(MyManager.partitions[IdTab]);
|
p.Instrument.ToLower() == instrument.ToLower()).ToList();
|
||||||
MyManager.sauvegardeFavoriAdd(MyManager.partitions[IdTab]);
|
|
||||||
button.Source = "etoile.png";
|
uint i = 1;
|
||||||
}
|
|
||||||
else
|
foreach (var partition in partitionsSimilaires)
|
||||||
{
|
{
|
||||||
MyManager.favoris.RemoveAll(f => f.Nom == MyManager.partitions[IdTab].Nom);
|
++i;
|
||||||
MyManager.sauvegardeFavoriRemove(MyManager.partitions[IdTab]);
|
if(i>9)
|
||||||
button.Source = "etoile_vide.png";
|
{
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
|
int indicePartition = MyManager.partitions.IndexOf(partition);
|
||||||
private void TempoSlider(object sender, ValueChangedEventArgs e)
|
|
||||||
{
|
var imageButton = new ImageButton
|
||||||
float selectedValue = (float)e.NewValue;
|
{
|
||||||
music.ReglerTempo(selectedValue);
|
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)
|
private void BPMSlider(object sender, ValueChangedEventArgs e)
|
||||||
{
|
{
|
||||||
float selectedValue = (float)e.NewValue;
|
float selectedValue = (float)e.NewValue;
|
||||||
metronome.ReglerTempo(selectedValue);
|
metronome.ReglerTempo(selectedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue