Re: [AIDE PUREBASIC] Mises à jour.
Publié : mar. 08/juil./2014 20:15
				
				Merci Mesa pour la traduction de la 5.30, je vois que tu as souffert avec la bibliothèque JSON, je compatis  
			Forums PureBasic - Français
https://www.purebasic.fr/french/
dans leur rubrique respectives ...RandomizeArray
RandomizeList
SortArray
SortList
SortStructuredArray
SortStructuredList
Sort et LinkedList sont 2 librairies différentes, d'où cette organisation non ?Dobro a écrit :Petite suggestion
le Dossier "Sort"
pourrai peut etre disparaitre et dispacher les :
dans leur rubrique respectives ...RandomizeArray
RandomizeList
SortArray
SortList
SortStructuredArray
SortStructuredList
RandomizeArray
SortArray
SortStructuredArray
RandomizeList
SortList
SortStructuredList
Code : Tout sélectionner
;
; ------------------------------------------------------------
;
;   PureBasic - Audio CD example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;
;-
;- ------- Initialization -------
;- .: Constants & Variables :.
Enumeration FormWindow
  #Window0
EndEnumeration
Enumeration FormGadget
  #ButtonPlay
  #ButtonPause
  #ButtonStop
  #TextAudioCDDrive
  #ComboBoxDeviceCD
  #ListViewTracks
  #TextStatus
  #ButtonEject
  #ButtonPreviousTrack
  #ButtonNextTrack
  #TextTime
  #TextCDLength
  #TextNbTracks
EndEnumeration
NbCDDrives = InitAudioCD()  ; How many CD Drives ?
If NbCDDrives = 0           ; If no CD Drive found then ends everything
  MessageRequester("Error", "No CD Audio drives found...", 0)
  End
EndIf
;- .: Procedures :.
Procedure.s GetHourFormat(LengthInSeconds) ; Format seconds into minutes and seconds
  Minutes = LengthInSeconds/60
  Seconds = LengthInSeconds-Minutes*60
  If Seconds < 10 
    ProcedureReturn Str(Minutes)+"m:0"+Str(Seconds)+"s"
  Else 
    ProcedureReturn Str(Minutes)+"m:"+Str(Seconds)+"s" 
  EndIf  
EndProcedure
Procedure RefreshCD() ; If a (new) CD is inside
  ClearGadgetItems(#ListViewTracks)
  
  NbAudioTracks = AudioCDTracks()
  For k=1 To NbAudioTracks
    If k<10
      AddGadgetItem(#ListViewTracks, -1, "Track 0"+Str(k)+" :"+GetHourFormat(AudioCDTrackLength(k)))
    Else
      AddGadgetItem(#ListViewTracks, -1, "Track "+Str(k)+" :"+GetHourFormat(AudioCDTrackLength(k)))
    EndIf
  Next
  
  DisableGadget(#ButtonPause, 1)
  DisableGadget(#ButtonStop, 1)
  SetGadgetState(#ListViewTracks, 0)
  SetGadgetText(#TextCDLength, "Total: " + GetHourFormat(AudioCDLength()))
  SetGadgetText(#TextNbTracks, "Total Tracks: "+Str(AudioCDTracks()))
EndProcedure
;- 
;- ---------- Main Code ---------
;- Open a window
If OpenWindow(#Window0, 0, 0, 400, 470, "PureBasic - AudioCD Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  ButtonGadget(#ButtonPlay, 30, 20, 100, 25, "Play")
  ButtonGadget(#ButtonPause, 15, 20, 100, 25, "Pause")
  ButtonGadget(#ButtonStop, 270, 20, 100, 25, "Stop")
  TextGadget(#TextAudioCDDrive, 180, 60, 80, 25, "Device:", #PB_Text_Right)
  ComboBoxGadget(#ComboBoxDeviceCD, 270, 60, 100, 25)
  ButtonGadget(#ButtonEject, 30, 60, 100, 25, "Eject CD", #PB_Button_Toggle)
  ButtonGadget(#ButtonPreviousTrack, 30, 100, 170, 25, "Previous Track")
  ButtonGadget(#ButtonNextTrack, 210, 100, 160, 25, "Next Track")
  ListViewGadget(#ListViewTracks, 30, 130, 340, 270)
  TextGadget(#TextStatus, 30, 410, 240, 25, "Status: Stopped")
  TextGadget(#TextTime, 280, 410, 90, 25, "00:00", #PB_Text_Right)
  TextGadget(#TextCDLength, 30, 440, 190, 25, "")
  TextGadget(#TextNbTracks, 240, 440, 130, 25, "", #PB_Text_Right)
  
  
  For k=0 To NbCDDrives -1  ; Fullfill the ComboBox with CD devices' name
    UseAudioCD(k)
    AddGadgetItem(#ComboBoxDeviceCD, -1, Left(AudioCDName(),2))
  Next
  SetGadgetState(#ComboBoxDeviceCD, 0)
  UseAudioCD(0)
  
  
  RefreshCD() ; Fullfill the ListView with CD's tracks
  
  ;- Loop: 
  Repeat    
    Repeat
      ;- ->Management of the gadgets
      Event = WindowEvent()  ; This time we use the WindowEvent(), non-blocking command to allow time refreshing
      
      If Event = #PB_Event_Gadget
        Select EventGadget() 
            
          Case #ButtonPlay              ; Play
            If Pause=#True
              ResumeAudioCD()
              Pause=#False 
            Else
              CurrentTrack = GetGadgetState(#ListViewTracks)+1
              PlayAudioCD(CurrentTrack, AudioCDTracks())
            EndIf
            
          Case #ButtonPause             ; Pause
            Pause=#True            
            PauseAudioCD()
            
          Case #ButtonStop              ; Stop
            Pause=#False 
            StopAudioCD()
            
          Case #ButtonEject             ; Eject/Close
            ClearGadgetItems(#ListViewTracks)
            If GetGadgetState(#ButtonEject) = 1
              SetGadgetText(#ButtonEject, "Close")
              EjectAudioCD(1)
            Else
              SetGadgetText(#ButtonEject, "Eject CD")
              EjectAudioCD(0)
              RefreshCD()
            EndIf
            
          Case #ComboBoxDeviceCD        ; Choose your CD Device
            UseAudioCD(GetGadgetState(#ComboBoxDeviceCD))
            RefreshCD()
            
          Case #ButtonPreviousTrack     ; Play Previous Track
            CurrentTrack = CurrentTrack - 1
            If CurrentTrack < 1
              CurrentTrack=AudioCDTracks()              
            EndIf
            SetGadgetState(#ListViewTracks, CurrentTrack-1)
            PlayAudioCD(CurrentTrack, AudioCDTracks())
            
          Case #ButtonNextTrack         ; Play Next Track
            CurrentTrack = CurrentTrack + 1
            If CurrentTrack > AudioCDTracks()
              CurrentTrack=1              
            EndIf
            SetGadgetState(#ListViewTracks, CurrentTrack-1)
            PlayAudioCD(CurrentTrack, AudioCDTracks())
            
          Case #ListViewTracks           ; Click on Track = Play the Track
            If Pause=#True
              Pause=#False 
            EndIf
            CurrentTrack = GetGadgetState(#ListViewTracks)+1
            PlayAudioCD(CurrentTrack, AudioCDTracks())           
            
        EndSelect
        
      Else
        If Event = #PB_Event_CloseWindow ; Close the Window
          Quit = 1 
        EndIf   
      EndIf
    Until Event = 0
    
    Delay(20) ; Wait 20 ms, which is a long period for the processor, to don't steal the whole CPU power
              ; for our little application :)
    
    ;- ->Display informations
    CurrentTrack = AudioCDStatus()
    
    If CurrentTrack > 0 ; A track is playing...
      If AudioCDTrackSeconds() = 0  ; Update the ListView if a new track is played
        SetGadgetState(#ListViewTracks, CurrentTrack-1) 
      EndIf     
      SetGadgetText(#TextStatus, "Playing Track " + Str(CurrentTrack) + " (Length: " + GetHourFormat(AudioCDTrackLength(CurrentTrack)) + ")")
      SetGadgetText(#TextTime, "Time: " + GetHourFormat(AudioCDTrackSeconds()))
      DisableGadget(#ButtonPlay, 1)
      DisableGadget(#ButtonPause, 0)
      DisableGadget(#ButtonStop, 0)
      DisableGadget(#ListViewTracks, 0)
      
    ElseIf CurrentTrack = 0         ; The CD Drive is paused or stopped ?
      If Pause=#True                ; Pause
        SetGadgetText(#TextStatus, "Status: Pause.")
        DisableGadget(#ButtonPlay, 0)
        DisableGadget(#ButtonPause, 1)
        DisableGadget(#ButtonStop, 0)
        DisableGadget(#ListViewTracks, 0)
      Else                          ; Stopped
        SetGadgetText(#TextStatus, "Status: Stopped with a CD inside.")
        SetGadgetText(#TextTime, "")
        DisableGadget(#ButtonPlay, 0)
        DisableGadget(#ButtonPause, 1)
        DisableGadget(#ButtonStop, 1)
        DisableGadget(#ListViewTracks, 0)
        If GetGadgetState(#ButtonEject) = 1
          SetGadgetText(#ButtonEject, "Close")
          SetGadgetText(#ButtonEject, "Eject CD")
          SetGadgetState(#ButtonEject, 0)
          RefreshCD()
        EndIf
      EndIf
      
    ElseIf CurrentTrack = -1        ; CD Drive not ready
      DisableGadget(#ListViewTracks, 1)
      SetGadgetText(#TextStatus, "Status: No CD or Open.")
      SetGadgetText(#TextTime, "")
      DisableGadget(#ButtonPlay, 1)
      DisableGadget(#ButtonPause, 1)
      DisableGadget(#ButtonStop, 1)
      DisableGadget(#ListViewTracks, 1)
      
    Else
      DisableGadget(#ListViewTracks, 0)
      
    EndIf
    
  Until Quit = 1
  
EndIf
;- End Loop:
;-
;- ------------- End ------------
;- Free CD Drives
For k=0 To NbCDDrives-1 ; Stop all the CD drives, if some are playing together
  UseAudioCD(k)
  StopAudioCD()
Next
End 
Code : Tout sélectionner
NbCDDrives = InitAudioCD()
If NbCDDrives = 0
  MessageRequester("Error", "No CD Audio drives found...", 0)
  End
EndIf
Global Null$
Procedure.s GetHourFormat(LengthInSeconds)
  Minutes = LengthInSeconds/60
  Seconds = LengthInSeconds-Minutes*60
  If Seconds < 10 : Null$ = "0" : Else : Null$ = "" : EndIf
  ProcedureReturn Str(Minutes)+":"+Null$+Str(Seconds)
EndProcedure
; Initialize constants for easier code reading
;
#GADGET_Play   = 0
#GADGET_Stop   = 1
#GADGET_Eject  = 2
#GADGET_Close  = 3
#GADGET_Select = 4
#GADGET_Status = 5
#GADGET_Time   = 6
#GADGET_AudioCDDrive = 7
#GADGET_SelectDrive  = 8
If OpenWindow(0, 100, 200, 265, 125, "PureBasic - AudioCD Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget  (#GADGET_Play   ,  10, 10, 60 , 24, "Play")
  ButtonGadget  (#GADGET_Stop   ,  70, 10, 60 , 24, "Stop")
  ButtonGadget  (#GADGET_Eject  , 130, 10, 60 , 24, "Eject")
  ButtonGadget  (#GADGET_Close  , 190, 10, 60 , 24, "Close")
  ComboBoxGadget(#GADGET_Select ,  10, 43, 240, 21)
  TextGadget    (#GADGET_Status ,  10, 70, 180, 16, "Status: stopped")
  TextGadget    (#GADGET_Time   , 200, 70, 240, 16, "")
  TextGadget    (#GADGET_AudioCDDrive,  10, 94, 140,  24, "Select the CD-Audio drive :")
  ComboBoxGadget(#GADGET_SelectDrive , 150, 90,  40, 21)
  For k=1 To NbCDDrives
    UseAudioCD(k-1)
    AddGadgetItem(#GADGET_SelectDrive, -1, Left(AudioCDName(),2))
  Next
  SetGadgetState(#GADGET_SelectDrive, 0)
  UseAudioCD(0)
  If NbCDDrives = 1
    DisableGadget(#GADGET_SelectDrive, 1)
  EndIf
  Gosub RefreshCD
  Repeat
    Repeat
      Event = WindowEvent()  ; This time we use the WindowEvent(), non-blocking command to allow time refreshing
      If Event = #PB_Event_Gadget
        Select EventGadget() 
          Case #GADGET_Play
            CurrentTrack = GetGadgetState(4)+1
            PlayAudioCD(CurrentTrack, CurrentTrack)
            
          Case #GADGET_Stop
            StopAudioCD()
          Case #GADGET_Eject
            EjectAudioCD(1)
          Case #GADGET_Close
            EjectAudioCD(0)
          Case #GADGET_SelectDrive
            UseAudioCD(GetGadgetState(#GADGET_SelectDrive))
            Gosub RefreshCD
        EndSelect
      Else
        If Event = #PB_Event_CloseWindow : Quit = 1 : EndIf   
      EndIf
    Until Event = 0
    Delay(20) ; Wait 20 ms, which is a long period for the processor, to don't steal the whole CPU power
              ; for our little application :)
    CurrentTrack = AudioCDStatus()
    If CurrentTrack > 0
      SetGadgetText(#GADGET_Status, "Playing Track "+Str(CurrentTrack)+" (Length: "+GetHourFormat(AudioCDTrackLength(CurrentTrack))+")")
      SetGadgetText(#GADGET_Time, "Time: "+GetHourFormat(AudioCDTrackSeconds()))
      DisableGadget(#GADGET_Play, 1)
      DisableGadget(#GADGET_Stop, 0)
      DisableGadget(#GADGET_Select, 0)
    Else
      SetGadgetText(#GADGET_Status, "Status: Stopped")
      SetGadgetText(#GADGET_Time, "")
      DisableGadget(#GADGET_Play, 0)
      DisableGadget(#GADGET_Stop, 1)
      If CurrentTrack = -1 ; CD Drive not ready
        DisableGadget(#GADGET_Select, 1)
      Else
        DisableGadget(#GADGET_Select, 0)
      EndIf
    EndIf
  Until Quit = 1
EndIf
For k=0 To NbCDDrives-1    ; Stop all the CD drives, if some are playing together
  UseAudioCD(k)
  StopAudioCD()
Next
End 
;-----------------------------------------------------------------
;  SubRoutines
;
RefreshCD:
  ClearGadgetItems(#GADGET_Select)
  NbAudioTracks = AudioCDTracks()
  For k=1 To NbAudioTracks
    AddGadgetItem(#GADGET_Select, -1, "Track "+Str(k))
  Next
  SetGadgetState(#GADGET_Select, 0)
Return