Itunes2 = {}
function Itunes2:Options_Itunes2()
   MACXT_Repertoire:Reinitialiser_Window()
   Window_Hauteur = 110
   Window_Longueur = 270
   MACXT_Title = "Preferences de Itunes"
   MACXT_Graphic:New_Textes()
   MACXT_Texte_Window[1] = {Caption = "Choisisser votre rubrique :"}
   MACXT_Repertoire:Actualise_Texte_Window()
   Affichage_Button = "Vertical_Drawing"
   MACXT_Draw_Button[1] = {Caption = "Options sur la bibliotheque",Action = "Options_Biblio"}
   MACXT_Draw_Button[2] = {Caption = "Options de lecture",Action = "Options_Playing"}
   MACXT_Draw_Button[3] = {Caption = "Options generales",Action = "Options_generales"}
   MACXT_Draw_Button[4] = {Caption = "Fermer",Action = "Fermer_Preferences"}
   MACXT_Repertoire:Actualise_Draw_Button()
   if Afficher_Personnal_Window == 0 then
      Afficher_Preferences_Itunes2 = 0
      Afficher_Personnal_Window = 0
   end
   if Action_Button == "Fermer_Preferences" then
      Afficher_Personnal_Window = 0
	  Afficher_Preferences_Itunes2 = 0
	  MACXT_Repertoire:Anti_Bug()
   end
   if Action_Button == "Options_generales" then
      REGISTRY:Read("ItunesV2","ListeDeLecture")
      Afficher_Preferences_Itunes2 = 0
      Options_Generales_Itunes2 = 1
      MACXT_Graphic:Init_New_Personnal_Window()
      Afficher_Options__ = 1
      MACXT_Repertoire:Anti_Bug()
   end
end
function Itunes2:Options__()
   if Options_Generales_Itunes2 == 1 then
      MACXT_Repertoire:Reinitialiser_Window()
      Window_Hauteur = 110
      Window_Longueur = 270
      MACXT_Title = "Options Generales"
      MACXT_Graphic:New_Textes()
      MACXT_Texte_Window[1] = {Caption = "Choix :"}
      MACXT_Repertoire:Actualise_Texte_Window()
      Affichage_Button = "Vertical_Drawing"
      if AfficherTitres == 0 then
         MACXT_Draw_Button[1] = {Caption = "Afficher les titres",Action = "AfficherTitres"}
       else
         MACXT_Draw_Button[1] = {Caption = "Ne pad afficher les titres",Action = "AfficherTitres"}
      end
      MACXT_Draw_Button[2] = {Caption = "Retour",Action = "RetourOptions"}
      MACXT_Repertoire:Actualise_Draw_Button()
      if Action_Button == "RetourOptions" then
         Options_Generales_Itunes2 = 0
         MACXT_Graphic:Init_New_Personnal_Window()
         Afficher_Options__ = 0
         Afficher_Preferences_Itunes2 = 1
         MACXT_Repertoire:Anti_Bug()
      end
      if Action_Button == "AfficherTitres" then
         if AfficherTitres == 0 then
            REGISTRY:Write_On_File("ItunesV2","ListeDeLecture","AfficherTitres = 1")
          else
            REGISTRY:Write_On_File("ItunesV2","ListeDeLecture","AfficherTitres = 0")
          end
          REGISTRY:Read("ItunesV2","ListeDeLecture")
          MACXT_Repertoire:Anti_Bug()
      end
   end
end
function Itunes2:Afficher_Bibliotheque()
   YPosItunesBiblio = 118
   local i
   for i=Part_Itunes,Part_Itunes + 5 do
      screen:print(185,YPosItunesBiblio,Itunes_Music_Files[i].Nom_Music_Itunes)
      screen:blit(165,YPosItunesBiblio,Logo_Itunes_MACXT)
      screen:print(5,118,Itunes_Music_Files[SelecteurItunesMusic].Dossier_Music_Itunes)
      YPosItunesBiblio = YPosItunesBiblio + 20
   end
end
function Itunes2:Use_Afficher_Bibliotheque()
   if Other_Process ~= 1 then
      if x >= 160 and x <= 480 and y >= 118 and y <= 235 then
         if y > YPosSelecteurItunesMusic + 20 and SelecteurItunesMusic < n_Itunes_Music then
            YPosSelecteurItunesMusic = YPosSelecteurItunesMusic + 20
            SelecteurItunesMusic = SelecteurItunesMusic + 1
         end
         if y < YPosSelecteurItunesMusic and SelecteurItunesMusic > 1 then
            YPosSelecteurItunesMusic = YPosSelecteurItunesMusic - 20
            SelecteurItunesMusic = SelecteurItunesMusic - 1
         end
         if MACXTKeyPad:r() then
            if Part_Itunes < n_Itunes_Music - 5 then
               Part_Itunes = Part_Itunes + 1
               SelecteurItunesMusic = SelecteurItunesMusic + 1
            end
         end
         if MACXTKeyPad:l() then
            if Part_Itunes > 1 then
               Part_Itunes = Part_Itunes - 1
               SelecteurItunesMusic = SelecteurItunesMusic - 1
            end
         end
         if MACXTKeyPad:cross() and Player == 0 then
            Mp3me.stop()
            Selecteur_Music_Info = SelecteurItunesMusic
            if Itunes_Music_Files[SelecteurItunesMusic].Dossier_Music_Itunes == "Music(ms0:/)" then
               System.currentDirectory("ms0:/MUSIC")
               Mp3me.load(Itunes_Music_Files[SelecteurItunesMusic].Nom_Music_Itunes)
               Annee_Music = Mp3me.year()
			   Titre_Musique = Mp3me.title()
			   Artiste_Musique = Mp3me.artist()
               Album_Music = Mp3me.album()
               Genre_Music = Mp3me.genre()
               Mp3me.play()
               Player = 1
            end
			if Itunes_Music_Files[SelecteurItunesMusic].Dossier_Music_Itunes == "Music(ms0:/PSP/)" then
			   System.currentDirectory("ms0:/PSP/MUSIC")
			   Mp3me.load(Itunes_Music_Files[SelecteurItunesMusic].Nom_Music_Itunes)
               Annee_Music = Mp3me.year()
			   Titre_Musique = Mp3me.title()
			   Artiste_Musique = Mp3me.artist()
               Album_Music = Mp3me.album()
               Genre_Music = Mp3me.genre()
			   Mp3me.play()
               Player = 1
			end
			if Itunes_Music_Files[SelecteurItunesMusic].Dossier_Music_Itunes == "Music(ms0:/Dir)" then
			   System.currentDirectory(Itunes_Music_Files[n_Itunes_Music].Nom_Dossier_Itunes_Dir)
			   Mp3me.load(Itunes_Music_Files[SelecteurItunesMusic].Nom_Music_Itunes)
               Annee_Music = Mp3me.year()
			   Titre_Musique = Mp3me.title()
			   Artiste_Musique = Mp3me.artist()
               Album_Music = Mp3me.album()
               Genre_Music = Mp3me.genre()
			   Mp3me.play()
               Player = 1
			end
			if Itunes_Music_Files[SelecteurItunesMusic].Dossier_Music_Itunes == "Music(ms0:/PSP/Dir)" then
			   System.currentDirectory(Itunes_Music_Files[n_Itunes_Music].Nom_Dossier_Itunes_Dir)
			   Mp3me.load(Itunes_Music_Files[SelecteurItunesMusic].Nom_Music_Itunes)
               Annee_Music = Mp3me.year()
			   Titre_Musique = Mp3me.title()
			   Artiste_Musique = Mp3me.artist()
               Album_Music = Mp3me.album()
               Genre_Music = Mp3me.genre()
			   Mp3me.play()
               Player = 1
			end
         end
      end
   end
end
function Itunes2:AnalyseMusique()
   System.currentDirectory("ms0:/MUSIC/")
   FichiersItunes = nil
   n_Itunes_Music = 0
   Itunes_Music_Files = {}
   Fichiers_Itunes = System.listDirectory()
   n_Fichiers_Itunes = table.getn(Fichiers_Itunes)
   for Itunes_Music = 1,n_Fichiers_Itunes do
      Fichiers_Itunes_String = string.len(Fichiers_Itunes[Itunes_Music].name)
      Fichiers_Itunes_Sub = string.sub(Fichiers_Itunes[Itunes_Music].name,Fichiers_Itunes_String - 3)
      if Fichiers_Itunes_Sub == ".mp3" or Fichiers_Itunes_Sub == ".MP3" then
         n_Itunes_Music = n_Itunes_Music + 1
         Itunes_Music_Files[n_Itunes_Music] = {Nom_Music_Itunes = Fichiers_Itunes[Itunes_Music].name,Dossier_Music_Itunes = "Music(ms0:/)"}
      end
      if Fichiers_Itunes[Itunes_Music].directory == true then
         System.currentDirectory("ms0:/MUSIC/"..Fichiers_Itunes[Itunes_Music].name)
         SFichiers_Itunes = nil
         SFichiers_Itunes = System.listDirectory()
         n_SFichiers_Itunes = table.getn(SFichiers_Itunes)
         for Itunes_Music_Dir = 1,n_SFichiers_Itunes do
            Fichiers_Itunes_String_Dir = string.len(SFichiers_Itunes[Itunes_Music_Dir].name)
            Fichiers_Itunes_Sub_Dir = string.sub(SFichiers_Itunes[Itunes_Music_Dir].name,Fichiers_Itunes_String_Dir - 3)
            if Fichiers_Itunes_Sub_Dir == ".mp3" or Fichiers_Itunes_Sub_Dir == ".MP3" then
               n_Itunes_Music = n_Itunes_Music + 1
               Itunes_Music_Files[n_Itunes_Music] = {Nom_Music_Itunes = SFichiers_Itunes[Itunes_Music_Dir].name,Dossier_Music_Itunes = "Music(ms0:/Dir)",Nom_Dossier_Itunes_Dir = System.currentDirectory().."/"}
            end
         end
      end
   end
   System.currentDirectory("ms0:/PSP/MUSIC/")
   Fichiers_Itunes = nil
   Fichiers_Itunes = System.listDirectory()
   n_Fichiers_Itunes = table.getn(Fichiers_Itunes)
   for Itunes_Music = 1,n_Fichiers_Itunes do
      Fichiers_Itunes_String = string.len(Fichiers_Itunes[Itunes_Music].name)
      Fichiers_Itunes_Sub = string.sub(Fichiers_Itunes[Itunes_Music].name,Fichiers_Itunes_String - 3)
      if Fichiers_Itunes_Sub == ".mp3" or Fichiers_Itunes_Sub == ".MP3" then
         n_Itunes_Music = n_Itunes_Music + 1
         Itunes_Music_Files[n_Itunes_Music] = {Nom_Music_Itunes = Fichiers_Itunes[Itunes_Music].name,Dossier_Music_Itunes = "Music(ms0:/PSP/)"}
      end
      if Fichiers_Itunes[Itunes_Music].directory == true then
         System.currentDirectory("ms0:/PSP/MUSIC/"..Fichiers_Itunes[Itunes_Music].name)
         SFichiers_Itunes = nil
         SFichiers_Itunes = System.listDirectory()
         n_SFichiers_Itunes = table.getn(SFichiers_Itunes)
         for Itunes_Music_Dir = 1,n_SFichiers_Itunes do
            Fichiers_Itunes_String_Dir = string.len(SFichiers_Itunes[Itunes_Music_Dir].name)
            Fichiers_Itunes_Sub_Dir = string.sub(SFichiers_Itunes[Itunes_Music_Dir].name,Fichiers_Itunes_String_Dir - 3)
            if Fichiers_Itunes_Sub_Dir == ".mp3" or Fichiers_Itunes_Sub_Dir == ".MP3" then
               n_Itunes_Music = n_Itunes_Music + 1
               Itunes_Music_Files[n_Itunes_Music] = {Nom_Music_Itunes = SFichiers_Itunes[Itunes_Music_Dir].name,Dossier_Music_Itunes = "Music(ms0:/PSP/Dir)",Nom_Dossier_Itunes_Dir = System.currentDirectory().."/"}
            end
         end
      end
   end
end
Itunes2:AnalyseMusique()