Page 1 of 2

lyric prompter

Posted: Wed Jul 29, 2015 8:39 pm
by Pot Noodle
Hi all, i am thinking of writing my own lyric prompter program but there is a couple of things i need to know.
how would i read the lyrics files in to the program as there will be a lot of them and secondly how would i scroll the lyrics up the screen.
I have thought about using an Array to store the line's of text but not sure if this is over kill or not.
here is a lyric prompter in action if you need more info.

https://www.youtube.com/watch?v=DfNLSVlRgzk

I am building my own lyric prompter for my band.
so any help would be great :)

Re: lyric prompter

Posted: Wed Jul 29, 2015 9:34 pm
by Keya
karaoke and programming, youre just missing the champagne! :)
a string array with each line of text sounds sensible to me! and song lyrics are small and dont take up much memory so just read the whole file in the one go at the start, then you have quick and easy access to any line at any time.
And maybe have a second array but of Longs, with the same number of elements as the lyrics array, where each value represents the interval to wait before displaying the next lyric, to allow for a "display one line at a time" view as well as scrolling. You could automatically generate a rough value for these by counting the number of characters or words in each lyric sentence

Re: lyric prompter

Posted: Wed Jul 29, 2015 9:37 pm
by Tenaja
To me, a string list seems like it would be less work than an array. Just iterate the list...

Re: lyric prompter

Posted: Wed Jul 29, 2015 9:39 pm
by Keya
sorry im new to Purebasic but whats the difference between a string list and an array of strings? thanks

Re: lyric prompter

Posted: Wed Jul 29, 2015 10:38 pm
by Tenaja
Keya wrote:sorry im new to Purebasic but whats the difference between a string list and an array of strings?
Look it up in the help file, also, but this is a lightweight description.

A list is a random number of elements, which are stored in the order they are added. To add one, call AddElement(mylist()), then mylist() = "lyric line". (I often make a macro to add and assign.) To iterate, just use foreach--this is the easiest part. There are never any counters to increment, unless you want one for another reason. If there is other data, you can use a structure, also. Finally, for clearing for a new song it is just one command, ClearList().

An array is a fixed size. You have to guess at the size, which would presumably be bigger than the longest song you would ever want. That's not so bad with songs, because it is still small enough to fit any pc from the past 2-3 decades. However, to add you require an incrementing counter. To iterate, you have to use a For-Next loop, and then also a test to see if the data is blank, unless you store the number of lines in another variable--which is an unnecessary step with Lists.

The list was designed for tasks like these. The array can be made to do the job. Both will work, and they are not a lot different, but the list is a tiny bit easier, once you do it.

Re: lyric prompter

Posted: Wed Jul 29, 2015 10:44 pm
by infratec
A rough proof of concept:

Code: Select all

EnableExplicit

Enumeration
  #Menu_Add
  #Menu_Delete
  #Menu_Load
  #Menu_Save
 
  #Menu_Pause
  #Menu_Down
  #Menu_Escape
EndEnumeration


Structure FileStructure
  Filename$
  Speed.i
EndStructure


;- Main
Define.i Event, Exit, PauseFlag, File, FileNo, Help, LastTime, ActualTime, Buffer, Pitch, THeight, TWidth, YPos
Define Filename$, Line$
Define *Buffer.FileStructure, *Ptr.FileStructure


InitSprite()


OpenWindow(0, 0, 0, 1024, 768, "Prompter", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

ListIconGadget(0, 800, 0, 224, 768, "File", 150, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Speed", 50)

CreatePopupMenu(0)
MenuItem(#Menu_Add, "Add")
MenuItem(#Menu_Delete, "Delete")
MenuItem(#Menu_Load, "Load")
MenuItem(#Menu_Save, "Save")



AddKeyboardShortcut(0, #PB_Shortcut_Pause, #Menu_Pause)
AddKeyboardShortcut(0, #PB_Shortcut_Down, #Menu_Down)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #Menu_Escape)

OpenWindowedScreen(WindowID(0), 0, 0, 800, 768)

StartDrawing(ScreenOutput())
THeight = TextHeight(" ")
StopDrawing()

CreateImage(0, 800, THeight)

PauseFlag = #True
FileNo = -1
Repeat
 
  Repeat
    Event = WindowEvent()
   
    Select Event
      Case #PB_Event_Menu
        Select EventMenu()
          Case #Menu_Add
            Filename$ = OpenFileRequester("Choose a file", Filename$, "Text|*.txt", 0)
            If Len(Filename$)
              Help = CountGadgetItems(0)
              AddGadgetItem(0, Help, GetFilePart(Filename$, #PB_FileSystem_NoExtension))
              *Buffer = AllocateMemory(SizeOf(FileStructure))
              SetGadgetItemData(0, Help, *Buffer)
              *Buffer\Filename$ = Filename$
              *Buffer\Speed = 25
              SetGadgetState(0, Help)
            EndIf
          Case #Menu_Delete
          Case #Menu_Load
          Case #Menu_Save
          Case #Menu_Pause
            If PauseFlag
              PauseFlag = #False
              If Not IsFile(File)
                If GetGadgetState(0) = -1
                  If CountGadgetItems(0)
                    FileNo = 0
                  EndIf
                Else
                  If CountGadgetItems(0)
                    FileNo + 1
                    If FileNo = CountGadgetItems(0)
                      FileNo = 0
                    EndIf
                  Else
                    FileNo = - 1
                  EndIf
                EndIf
                Debug FileNo
                SetGadgetState(0, FileNo)
                *Ptr = GetGadgetItemData(0, FileNo)
                File = ReadFile(#PB_Any, *Ptr\Filename$)
              EndIf
            Else
              PauseFlag = #True
            EndIf
           
          Case #Menu_Down
            Debug "DOWN"
            If CountGadgetItems(0)
              If IsFile(File)
                CloseFile(File)
              EndIf
              FileNo + 1
              If FileNo = CountGadgetItems(0)
                FileNo = 0
              EndIf
              SetGadgetState(0, FileNo)
              *Ptr = GetGadgetItemData(0, FileNo)
              File = ReadFile(#PB_Any, *Ptr\Filename$)
            EndIf
           
          Case #Menu_Escape
            Exit = #True
           
        EndSelect
       
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            If EventType() = #PB_EventType_RightClick
              DisplayPopupMenu(0, WindowID(0))
            EndIf
        EndSelect
       
      Case #PB_Event_CloseWindow
        Exit = #True
    EndSelect
  Until Event = 0
 
 
  ActualTime = ElapsedMilliseconds()
  If Not PauseFlag
    If IsFile(File)
      If LastTime + *Ptr\Speed < ActualTime
        If YPos = THeight
          If Eof(File)
            CloseFile(File)
            FileNo + 1
            If FileNo = CountGadgetItems(0)
              FileNo = 0
            EndIf
            SetGadgetState(0, FileNo)
            *Ptr = GetGadgetItemData(0, FileNo)
            File = ReadFile(#PB_Any, *Ptr\Filename$)
          EndIf
          Line$ = ReadString(File)
          ;        Debug Line$
          StartDrawing(ImageOutput(0))
          Box(0, 0, 800, THeight, 0)
          TWidth = TextWidth(Line$)
          DrawText(400 - (TWidth >> 1), 0, Line$)
          StopDrawing()
          YPos = 0
        EndIf
        
        StartDrawing(ScreenOutput())
          
        Buffer = DrawingBuffer()
        Pitch = DrawingBufferPitch()
       
        MoveMemory(Buffer + Pitch, Buffer, 767 * Pitch)
        
        GrabImage(0, 1, 0, YPos, 800, 1)
        YPos + 1
        DrawImage(ImageID(1), 0, 767)
        FreeImage(1)
        StopDrawing()
       
        LastTime = ActualTime
      EndIf
    EndIf
  EndIf
 
  FlipBuffers()
 
Until Exit

It's no problem to make the scrolling 'smooth'.
Also the missing menu stuff should be no problem.
Load and Save are planned to save and load the 'playlist'.
It's also possible to add drag'n drop to sort the files in the list.

Bernd

Re: lyric prompter

Posted: Thu Jul 30, 2015 7:57 am
by infratec
Smooth scrolling implemented :mrgreen:

And small bug fixes.

Re: lyric prompter

Posted: Thu Jul 30, 2015 6:41 pm
by Pot Noodle
would it be possible to have it stop scrolling when it gets to EOF?
and to have the black area full screen!

Re: lyric prompter

Posted: Thu Jul 30, 2015 7:01 pm
by infratec
Sure, everything is possible.

Fullscreen?
And where do you want to place the 'Playlist' ?

Re: lyric prompter

Posted: Thu Jul 30, 2015 7:13 pm
by Pot Noodle
It would be good to have an option to switch to full screen and hide the play list.
I am having problems with adjusting Font size and the speed :mrgreen:

Re: lyric prompter

Posted: Thu Jul 30, 2015 8:30 pm
by infratec

Code: Select all

EnableExplicit

Enumeration
  #Menu_Add
  #Menu_Delete
  #Menu_Load
  #Menu_Save
 
  #Menu_Pause
  #Menu_Down
  #Menu_Escape
  #Menu_PopUp
EndEnumeration


Structure FileStructure
  Filename$
  Speed.i
EndStructure


;- Main
Define.i Event, Exit, PauseFlag, File, FileNo, Help, LastTime, ActualTime, Buffer, Pitch, THeight, TWidth, YPos
Define.i DHeight, DWidth
Define Filename$, Line$
Define *Buffer.FileStructure, *Ptr.FileStructure


InitSprite()

ExamineDesktops()
DHeight = DesktopHeight(0)
DWidth = DesktopWidth(0)

OpenWindow(0, 0, 0, DWidth, DHeight, "", #PB_Window_BorderLess)


OpenWindow(1, 0, 0, 250, 600, "Playlist", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateMenu(0, WindowID(1))
MenuTitle("File")
MenuItem(#Menu_Add, "Add")
MenuItem(#Menu_Delete, "Delete")
MenuItem(#Menu_Load, "Load")
MenuItem(#Menu_Save, "Save")

ListIconGadget(0, 0, 0, 250, 600, "Name", 180, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Speed", 50)





AddKeyboardShortcut(0, #PB_Shortcut_Pause, #Menu_Pause)
AddKeyboardShortcut(0, #PB_Shortcut_Down, #Menu_Down)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #Menu_Escape)
AddKeyboardShortcut(0, #PB_Shortcut_Space, #Menu_PopUp)

OpenWindowedScreen(WindowID(0), 0, 0, DWidth, DHeight)

LoadFont(0, "Arial", 20, #PB_Font_Bold)


StartDrawing(ScreenOutput())
DrawingFont(FontID(0))
THeight = TextHeight(" ")
StopDrawing()

CreateImage(0, DWidth, THeight)

PauseFlag = #True
FileNo = -1
Repeat
 
  Repeat
    Event = WindowEvent()
    
    Select EventWindow()
      Case 0
        
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_PopUp
                HideWindow(1, #False, #PB_Window_ScreenCentered)
              
              Case #Menu_Pause
                If PauseFlag
                  PauseFlag = #False
                  If Not IsFile(File)
                    If GetGadgetState(0) = -1
                      If CountGadgetItems(0)
                        FileNo = 0
                      EndIf
                    Else
                      If CountGadgetItems(0)
                        FileNo + 1
                        If FileNo = CountGadgetItems(0)
                          FileNo = 0
                        EndIf
                      Else
                        FileNo = - 1
                      EndIf
                    EndIf
                    ;Debug FileNo
                    SetGadgetState(0, FileNo)
                    *Ptr = GetGadgetItemData(0, FileNo)
                    File = ReadFile(#PB_Any, *Ptr\Filename$)
                    YPos = THeight
                  EndIf
                Else
                  PauseFlag = #True
                EndIf
               
              Case #Menu_Down
                ;Debug "DOWN"
                If CountGadgetItems(0)
                  If IsFile(File)
                    CloseFile(File)
                  EndIf
                  FileNo + 1
                  If FileNo = CountGadgetItems(0)
                    FileNo = 0
                  EndIf
                  SetGadgetState(0, FileNo)
                  *Ptr = GetGadgetItemData(0, FileNo)
                  File = ReadFile(#PB_Any, *Ptr\Filename$)
                EndIf
                
              Case #Menu_Escape
                Exit = #True
                
            EndSelect
            
          
           
          Case #PB_Event_CloseWindow
            Exit = #True
        EndSelect
        
      Case 1
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_Add
                Filename$ = OpenFileRequester("Choose a file", Filename$, "Text|*.txt", 0)
                If Len(Filename$)
                  Help = CountGadgetItems(0)
                  AddGadgetItem(0, Help, GetFilePart(Filename$, #PB_FileSystem_NoExtension))
                  *Buffer = AllocateMemory(SizeOf(FileStructure))
                  SetGadgetItemData(0, Help, *Buffer)
                  *Buffer\Filename$ = Filename$
                  *Buffer\Speed = 10
                  SetGadgetState(0, Help)
                EndIf
              Case #Menu_Delete
              Case #Menu_Load
              Case #Menu_Save
            EndSelect
            
          Case #PB_Event_Gadget
            Select EventGadget()
              
            EndSelect
            
          Case #PB_Event_CloseWindow
            HideWindow(1, #True)
        EndSelect
        
    EndSelect
    
  Until Event = 0
 
 
  ActualTime = ElapsedMilliseconds()
  If Not PauseFlag
    If IsFile(File)
      If LastTime + *Ptr\Speed < ActualTime
        If YPos = THeight
          If Eof(File)
            CloseFile(File)
            FileNo + 1
            If FileNo = CountGadgetItems(0)
              FileNo = 0
            EndIf
            SetGadgetState(0, FileNo)
            *Ptr = GetGadgetItemData(0, FileNo)
            File = ReadFile(#PB_Any, *Ptr\Filename$)
            PauseFlag = #True
          EndIf
          Line$ = ReadString(File)
          ;        Debug Line$
          StartDrawing(ImageOutput(0))
          DrawingFont(FontID(0))
          Box(0, 0, DWidth, THeight, 0)
          TWidth = TextWidth(Line$)
          DrawText((DWidth >> 1) - (TWidth >> 1), 0, Line$)
          StopDrawing()
          YPos = 0
        EndIf
        
        If Not PauseFlag
          StartDrawing(ScreenOutput())
          
          Buffer = DrawingBuffer()
          Pitch = DrawingBufferPitch()
          
          MoveMemory(Buffer + Pitch, Buffer, (DHeight - 1) * Pitch)
          
          GrabImage(0, 1, 0, YPos, DWidth, 1)
          YPos + 1
          DrawImage(ImageID(1), 0, DHeight - 1)
          FreeImage(1)
          StopDrawing()
          
          LastTime = ActualTime
        EndIf
      EndIf
    EndIf
  EndIf
  
  FlipBuffers()
  
Until Exit
This reaches the speed limit.
Too many data to copy.

But I have no time at the moment.

Bernd

Re: lyric prompter

Posted: Thu Jul 30, 2015 9:54 pm
by Pot Noodle
Shame as i was just getting in to this it's great, shame about the speed :cry:
Back to the drawing board then ...
Thanks for your help at least it gives me a head start.

Re: lyric prompter

Posted: Fri Jul 31, 2015 5:54 am
by wilbert
Pot Noodle wrote:Shame as i was just getting in to this it's great, shame about the speed :cry:
Back to the drawing board then ...
Thanks for your help at least it gives me a head start.
You might consider using sprites to display the song.
That should be much faster.

Re: lyric prompter

Posted: Fri Jul 31, 2015 7:15 am
by infratec
Small Trick:

Code: Select all

EnableExplicit

Enumeration
  #Menu_Add
  #Menu_Delete
  #Menu_Load
  #Menu_Save
 
  #Menu_Pause
  #Menu_Down
  #Menu_Escape
  #Menu_PopUp
EndEnumeration


Structure FileStructure
  Filename$
  Speed.i
EndStructure


;- Main
Define.i Event, Exit, PauseFlag, File, FileNo, Help, LastTime, ActualTime, Buffer, Pitch, THeight, TWidth, YPos
Define.i DHeight, DWidth
Define Filename$, Line$
Define *Buffer.FileStructure, *Ptr.FileStructure


InitSprite()

; ExamineDesktops()
; DWidth = DesktopWidth(0)
; DHeight = DesktopHeight(0)


DWidth = 800
DHeight = 600

OpenWindow(0, 0, 0, DWidth, DHeight, "", #PB_Window_BorderLess)

SetWindowState(0, #PB_Window_Maximize)

OpenWindow(1, 0, 0, 250, 600, "Playlist", #PB_Window_SystemMenu|#PB_Window_ScreenCentered);|#PB_Window_Invisible)
CreateMenu(0, WindowID(1))
MenuTitle("File")
MenuItem(#Menu_Add, "Add")
MenuItem(#Menu_Delete, "Delete")
MenuItem(#Menu_Load, "Load")
MenuItem(#Menu_Save, "Save")

ListIconGadget(0, 0, 0, 250, 600, "Name", 180, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Speed", 50)





AddKeyboardShortcut(0, #PB_Shortcut_Pause, #Menu_Pause)
AddKeyboardShortcut(0, #PB_Shortcut_Down, #Menu_Down)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #Menu_Escape)
AddKeyboardShortcut(0, #PB_Shortcut_Space, #Menu_PopUp)

OpenWindowedScreen(WindowID(0), 0, 0, DWidth, DHeight, 1, 0, 0)





LoadFont(0, "Arial", 20, #PB_Font_Bold)


StartDrawing(ScreenOutput())
DrawingFont(FontID(0))
THeight = TextHeight(" ")
StopDrawing()

CreateImage(0, DWidth, THeight)

PauseFlag = #True
FileNo = -1
Repeat
 
  Repeat
    Event = WindowEvent()
   
    Select EventWindow()
      Case 0
       
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_PopUp
                HideWindow(1, #False, #PB_Window_ScreenCentered)
             
              Case #Menu_Pause
                If PauseFlag
                  PauseFlag = #False
                  If Not IsFile(File)
                    If GetGadgetState(0) = -1
                      If CountGadgetItems(0)
                        FileNo = 0
                      EndIf
                    Else
                      If CountGadgetItems(0)
                        FileNo + 1
                        If FileNo = CountGadgetItems(0)
                          FileNo = 0
                        EndIf
                      Else
                        FileNo = - 1
                      EndIf
                    EndIf
                    ;Debug FileNo
                    SetGadgetState(0, FileNo)
                    *Ptr = GetGadgetItemData(0, FileNo)
                    File = ReadFile(#PB_Any, *Ptr\Filename$)
                    YPos = THeight
                  EndIf
                Else
                  PauseFlag = #True
                EndIf
               
              Case #Menu_Down
                ;Debug "DOWN"
                If CountGadgetItems(0)
                  If IsFile(File)
                    CloseFile(File)
                  EndIf
                  FileNo + 1
                  If FileNo = CountGadgetItems(0)
                    FileNo = 0
                  EndIf
                  SetGadgetState(0, FileNo)
                  *Ptr = GetGadgetItemData(0, FileNo)
                  File = ReadFile(#PB_Any, *Ptr\Filename$)
                EndIf
               
              Case #Menu_Escape
                Exit = #True
               
            EndSelect
           
         
           
          Case #PB_Event_CloseWindow
            Exit = #True
        EndSelect
       
      Case 1
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_Add
                Filename$ = OpenFileRequester("Choose a file", Filename$, "Text|*.txt", 0)
                If Len(Filename$)
                  Help = CountGadgetItems(0)
                  AddGadgetItem(0, Help, GetFilePart(Filename$, #PB_FileSystem_NoExtension))
                  *Buffer = AllocateMemory(SizeOf(FileStructure))
                  SetGadgetItemData(0, Help, *Buffer)
                  *Buffer\Filename$ = Filename$
                  *Buffer\Speed = 10
                  SetGadgetState(0, Help)
                EndIf
              Case #Menu_Delete
              Case #Menu_Load
              Case #Menu_Save
            EndSelect
           
          Case #PB_Event_Gadget
            Select EventGadget()
             
            EndSelect
           
          Case #PB_Event_CloseWindow
            HideWindow(1, #True)
        EndSelect
       
    EndSelect
   
  Until Event = 0
 
 
  ActualTime = ElapsedMilliseconds()
  If Not PauseFlag
    If IsFile(File)
      If LastTime + *Ptr\Speed < ActualTime
        If YPos = THeight
          If Eof(File)
            CloseFile(File)
            FileNo + 1
            If FileNo = CountGadgetItems(0)
              FileNo = 0
            EndIf
            SetGadgetState(0, FileNo)
            *Ptr = GetGadgetItemData(0, FileNo)
            File = ReadFile(#PB_Any, *Ptr\Filename$)
            PauseFlag = #True
          EndIf
          Line$ = ReadString(File)
          ;        Debug Line$
          StartDrawing(ImageOutput(0))
          DrawingFont(FontID(0))
          Box(0, 0, DWidth, THeight, 0)
          TWidth = TextWidth(Line$)
          DrawText((DWidth >> 1) - (TWidth >> 1), 0, Line$)
          StopDrawing()
          YPos = 0
        EndIf
       
        If Not PauseFlag
          StartDrawing(ScreenOutput())
         
          Buffer = DrawingBuffer()
          Pitch = DrawingBufferPitch()
         
          MoveMemory(Buffer + Pitch, Buffer, (DHeight - 1) * Pitch)
         
          GrabImage(0, 1, 0, YPos, DWidth, 1)
          YPos + 1
          DrawImage(ImageID(1), 0, DHeight - 1)
          FreeImage(1)
          StopDrawing()
         
          LastTime = ActualTime
        EndIf
      EndIf
    EndIf
  EndIf
 
  FlipBuffers()
 
Until Exit

But I think you should try it with Sprites.

Bernd

Re: lyric prompter

Posted: Fri Jul 31, 2015 7:54 am
by infratec
Now with Sprites:

Code: Select all

EnableExplicit

Enumeration
  #Menu_Add
  #Menu_Delete
  #Menu_Load
  #Menu_Save
 
  #Menu_Pause
  #Menu_Down
  #Menu_Escape
  #Menu_PopUp
EndEnumeration


Structure FileStructure
  Filename$
  Speed.i
EndStructure


;- Main
Define.i Event, Exit, PauseFlag, File, FileNo, Help, LastTime, ActualTime, Buffer, Pitch, THeight, TWidth, YPos
Define.i DHeight, DWidth, MaxSprites, ActiveSprite, i, Sprite
Define Filename$, Line$
Define *Buffer.FileStructure, *Ptr.FileStructure


InitSprite()

ExamineDesktops()
DWidth = DesktopWidth(0)
DHeight = DesktopHeight(0)


;DWidth = 800
;DHeight = 600

OpenWindow(0, 0, 0, DWidth, DHeight, "", #PB_Window_BorderLess)

;SetWindowState(0, #PB_Window_Maximize)

OpenWindow(1, 0, 0, 250, 600, "Playlist", #PB_Window_SystemMenu|#PB_Window_ScreenCentered);|#PB_Window_Invisible)
CreateMenu(0, WindowID(1))
MenuTitle("File")
MenuItem(#Menu_Add, "Add")
MenuItem(#Menu_Delete, "Delete")
MenuItem(#Menu_Load, "Load")
MenuItem(#Menu_Save, "Save")

ListIconGadget(0, 0, 0, 250, 600, "Name", 180, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Speed", 50)





AddKeyboardShortcut(0, #PB_Shortcut_Pause, #Menu_Pause)
AddKeyboardShortcut(0, #PB_Shortcut_Down, #Menu_Down)
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #Menu_Escape)
AddKeyboardShortcut(0, #PB_Shortcut_Space, #Menu_PopUp)

OpenWindowedScreen(WindowID(0), 0, 0, DWidth, DHeight, 1, 0, 0, #PB_Screen_NoSynchronization)





LoadFont(0, "Arial", 20, #PB_Font_Bold)


StartDrawing(ScreenOutput())
DrawingFont(FontID(0))
THeight = TextHeight(" ")
StopDrawing()


MaxSprites = DHeight / THeight
For i = 0 To MaxSprites
  CreateSprite(i, DWidth, THeight)
Next i
ActiveSprite = MaxSprites


PauseFlag = #True
FileNo = -1
Repeat
 
  Repeat
    Event = WindowEvent()
   
    Select EventWindow()
      Case 0
       
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_PopUp
                HideWindow(1, #False, #PB_Window_ScreenCentered)
             
              Case #Menu_Pause
                If PauseFlag
                  PauseFlag = #False
                  If Not IsFile(File)
                    If GetGadgetState(0) = -1
                      If CountGadgetItems(0)
                        FileNo = 0
                      EndIf
                    Else
                      If CountGadgetItems(0)
                        FileNo + 1
                        If FileNo = CountGadgetItems(0)
                          FileNo = 0
                        EndIf
                      Else
                        FileNo = - 1
                      EndIf
                    EndIf
                    ;Debug FileNo
                    SetGadgetState(0, FileNo)
                    *Ptr = GetGadgetItemData(0, FileNo)
                    File = ReadFile(#PB_Any, *Ptr\Filename$)
                    YPos = THeight
                  EndIf
                Else
                  PauseFlag = #True
                EndIf
               
              Case #Menu_Down
                ;Debug "DOWN"
                If CountGadgetItems(0)
                  If IsFile(File)
                    CloseFile(File)
                  EndIf
                  FileNo + 1
                  If FileNo = CountGadgetItems(0)
                    FileNo = 0
                  EndIf
                  SetGadgetState(0, FileNo)
                  *Ptr = GetGadgetItemData(0, FileNo)
                  File = ReadFile(#PB_Any, *Ptr\Filename$)
                EndIf
               
              Case #Menu_Escape
                Exit = #True
               
            EndSelect
           
         
           
          Case #PB_Event_CloseWindow
            Exit = #True
        EndSelect
       
      Case 1
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_Add
                Filename$ = OpenFileRequester("Choose a file", Filename$, "Text|*.txt", 0)
                If Len(Filename$)
                  Help = CountGadgetItems(0)
                  AddGadgetItem(0, Help, GetFilePart(Filename$, #PB_FileSystem_NoExtension))
                  *Buffer = AllocateMemory(SizeOf(FileStructure))
                  SetGadgetItemData(0, Help, *Buffer)
                  *Buffer\Filename$ = Filename$
                  *Buffer\Speed = 10
                  SetGadgetState(0, Help)
                EndIf
              Case #Menu_Delete
              Case #Menu_Load
              Case #Menu_Save
            EndSelect
           
          Case #PB_Event_Gadget
            Select EventGadget()
             
            EndSelect
           
          Case #PB_Event_CloseWindow
            HideWindow(1, #True)
        EndSelect
       
    EndSelect
   
  Until Event = 0
 
 
  ActualTime = ElapsedMilliseconds()
  If Not PauseFlag
    If IsFile(File)
      If LastTime + *Ptr\Speed < ActualTime
        If YPos = THeight
          If Eof(File)
            CloseFile(File)
            FileNo + 1
            If FileNo = CountGadgetItems(0)
              FileNo = 0
            EndIf
            SetGadgetState(0, FileNo)
            *Ptr = GetGadgetItemData(0, FileNo)
            File = ReadFile(#PB_Any, *Ptr\Filename$)
            PauseFlag = #True
          EndIf
          Line$ = ReadString(File)
          ;        Debug Line$
          
          StartDrawing(SpriteOutput(ActiveSprite))
          DrawingFont(FontID(0))
          Box(0, 0, DWidth, THeight, 0)
          TWidth = TextWidth(Line$)
          DrawText((DWidth >> 1) - (TWidth >> 1), 0, Line$)
          StopDrawing()
          YPos = 0
          
          ActiveSprite + 1
          If ActiveSprite > MaxSprites
            ActiveSprite = 0
          EndIf
        EndIf
        
        If Not PauseFlag
          Sprite = ActiveSprite
          For i = 0 To MaxSprites
            DisplaySprite(Sprite, 0, i * THeight - YPos)
            Sprite + 1
            If Sprite > MaxSprites
              Sprite = 0
            EndIf
          Next i
          
          YPos + 1
          
          LastTime = ActualTime
        EndIf
      EndIf
    EndIf
  EndIf
 
  FlipBuffers()
 
Until Exit
Bernd