You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
4.1 KiB
164 lines
4.1 KiB
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";
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
private void BPMSlider(object sender, ValueChangedEventArgs e)
|
|
{
|
|
float selectedValue = (float)e.NewValue;
|
|
metronome.ReglerTempo(selectedValue);
|
|
}
|
|
|
|
}
|