lyric prompter

Just starting out? Need help? Post your questions and find answers here.
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: lyric prompter

Post by Pot Noodle »

Thank's infratec, that's much better.
But i am still trying to get my head around this problem :oops:

Code: Select all

          ;- Load
          Case #Menu_Load
            If CountGadgetItems(0)
              Result = MessageRequester("Load Playlist", "Clear Current Playlist?", #PB_MessageRequester_YesNo)
            EndIf
            If Result = #PB_MessageRequester_Yes Or CountGadgetItems(0) = 0
              ClearGadgetItems(0)
              Filename$ = OpenFileRequester("Choose a Playlist", "Playlist", "", 0)
              If Len(Filename$)
                OpenFile(0, Filename$)
                If ReadFile(0, Filename$)
                  While Eof(0) = 0
                    Help = CountGadgetItems(0)
                    Line$ = ReadString(0)
                    AddGadgetItem(0, Help, GetFilePart(Line$, #PB_FileSystem_NoExtension))
                  Wend
                EndIf
              EndIf
            EndIf
            
          ;- Save
          Case #Menu_Save
            If CountGadgetItems(0)
              Savefile$ = SaveFileRequester("Choose file to save", "Playlist", "Text file | *.txt", 0)
              If CreateFile(0, Savefile$)
                For i=0 To Help
                  WriteStringN(0, *Buffer\Path$ + GetGadgetItemText(0, i) + ".txt")
                Next
                CloseFile(0)
              EndIf         
            EndIf
            EndSelect
P.N.
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: lyric prompter

Post by infratec »

Hi,

it looks like you didn't understand what's happening in my (short) program.
You have to study it.
Because without knowledge, you only make steps in the dark.

Since it is faster I swiched back to a right click popupmenu.
Load, Save and Delete is done.
What's missing is to set the speed when a file is added.

Code: Select all

EnableExplicit


Enumeration
  #ScreenWindow
  #ManageWindow
EndEnumeration


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, PlayFile, PlayFileNo, Help, LastTime, ActualTime, Buffer, Pitch, THeight, TWidth, YPos
Define.i DHeight, DWidth, MaxSprites, ActiveSprite, i, Sprite, Result, PlaylistFile, File
Define Filename$, Line$
Define *Ptr.FileStructure


InitSprite()

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


;DWidth = 800
;DHeight = 600

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

;SetWindowState(0, #PB_Window_Maximize)

OpenWindow(#ManageWindow, 0, 0, 250, 600, "Playlist", #PB_Window_SystemMenu|#PB_Window_ScreenCentered);|#PB_Window_Invisible)

CreatePopupMenu(0)
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(#ScreenWindow, #PB_Shortcut_Pause, #Menu_Pause)
AddKeyboardShortcut(#ScreenWindow, #PB_Shortcut_Down, #Menu_Down)
AddKeyboardShortcut(#ScreenWindow, #PB_Shortcut_Escape, #Menu_Escape)
AddKeyboardShortcut(#ScreenWindow, #PB_Shortcut_Space, #Menu_PopUp)

OpenWindowedScreen(WindowID(#ScreenWindow), 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
PlayFileNo = -1
Repeat
 
  Repeat
    Event = WindowEvent()
   
    Select EventWindow()
      Case #ScreenWindow
       
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_PopUp
                ;- ScreenPopup
                PauseFlag = #True
                If IsFile(PlayFile)
                  CloseFile(PlayFile)
                EndIf
                HideWindow(1, #False, #PB_Window_ScreenCentered)
             
              Case #Menu_Pause
                ;- ScreenPause
                If PauseFlag
                  PauseFlag = #False
                  If Not IsFile(PlayFile)
                    If GetGadgetState(0) = -1
                      If CountGadgetItems(0)
                        PlayFileNo = 0
                      EndIf
                    Else
                      If CountGadgetItems(0)
                        PlayFileNo + 1
                        If PlayFileNo = CountGadgetItems(0)
                          PlayFileNo = 0
                        EndIf
                      Else
                        PlayFileNo = - 1
                      EndIf
                    EndIf
                    ;Debug PlayFileNo
                    SetGadgetState(0, PlayFileNo)
                    *Ptr = GetGadgetItemData(0, PlayFileNo)
                    PlayFile = ReadFile(#PB_Any, *Ptr\Filename$)
                    YPos = THeight
                  EndIf
                Else
                  PauseFlag = #True
                EndIf
               
              Case #Menu_Down
                ;- ScreenDown
                ;Debug "DOWN"
                If CountGadgetItems(0)
                  If IsFile(PlayFile)
                    CloseFile(PlayFile)
                  EndIf
                  PlayFileNo + 1
                  If PlayFileNo = CountGadgetItems(0)
                    PlayFileNo = 0
                  EndIf
                  SetGadgetState(0, PlayFileNo)
                  *Ptr = GetGadgetItemData(0, PlayFileNo)
                  PlayFile = ReadFile(#PB_Any, *Ptr\Filename$)
                EndIf
               
              Case #Menu_Escape
                ;- ScreenEscape
                Exit = #True
               
            EndSelect
           
          Case #PB_Event_CloseWindow
            Exit = #True
        EndSelect
       
      Case #ManageWindow
        Select Event
          Case #PB_Event_Menu
            Select EventMenu()
              Case #Menu_Add
                ;- ManageAdd
                Filename$ = OpenFileRequester("Choose a file", Filename$, "Text|*.txt", 0)
                If Len(Filename$)
                  Help = CountGadgetItems(0)
                  AddGadgetItem(0, Help, GetFilePart(Filename$, #PB_FileSystem_NoExtension))
                  *Ptr = AllocateMemory(SizeOf(FileStructure))
                  SetGadgetItemData(0, Help, *Ptr)
                  *Ptr\Filename$ = Filename$
                  *Ptr\Speed = 10
                  SetGadgetState(0, Help)
                EndIf
                
              Case #Menu_Delete
                ;- ManageDelete
                Help = GetGadgetState(0)
                If Help <> -1
                  If MessageRequester("Playlist", "Delete file?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
                    *Ptr = GetGadgetItemData(0, Help)
                    If *Ptr
                      FreeMemory(*Ptr)
                    EndIf
                    RemoveGadgetItem(0, Help)
                    If Help < CountGadgetItems(0)
                      SetGadgetState(0, Help)
                    Else
                      SetGadgetState(0, 0)
                    EndIf
                  EndIf
                EndIf
                
              Case #Menu_Load
                ;-ManageLoad
                If CountGadgetItems(0)
                  Result = MessageRequester("Load Playlist", "Clear Current Playlist?", #PB_MessageRequester_YesNo)
                EndIf
                If Result = #PB_MessageRequester_Yes Or CountGadgetItems(0) = 0
                  
                  Help = CountGadgetItems(0) - 1
                  For i = 0 To Help
                    *Ptr = GetGadgetItemData(0, i)
                    If *Ptr
                      FreeMemory(*Ptr)
                    EndIf
                  Next i
                  
                  ClearGadgetItems(0)
                  
                  Filename$ = OpenFileRequester("Choose a Playlist", "Playlist.ppl", "PrompterPlayList | *.ppl", 0)
                  If Len(Filename$)
                    PlaylistFile = ReadFile(#PB_Any, Filename$)
                    If PlaylistFile
                      i = 0
                      While Not Eof(PlaylistFile)
                        Line$ = ReadString(PlaylistFile)
                        If Len(Line$)
                          *Ptr = AllocateMemory(SizeOf(FileStructure))
                          *Ptr\Filename$ = StringField(Line$, 1, ",")
                          *Ptr\Speed = Val(StringField(Line$, 2, ","))
                          
                          AddGadgetItem(0, i, GetFilePart(*Ptr\Filename$, #PB_FileSystem_NoExtension))
                          SetGadgetItemData(0, i, *Ptr)
                          
                          i + 1
                        EndIf
                      Wend
                      If CountGadgetItems(0)
                        SetGadgetState(0, 0)                        
                      EndIf
                      
                    EndIf
                  EndIf
                EndIf
                
              Case #Menu_Save
                ;- ManageSave
                Help = CountGadgetItems(0)
                If CountGadgetItems(0)
                  Filename$ = SaveFileRequester("Choose file to save", "Playlist.ppl", "PrompterPlayList | *.ppl", 0)
                  If Len(Filename$)
                    If GetExtensionPart(Filename$) = ""
                      Filename$ + ".ppl"
                    EndIf
                    PlaylistFile = CreateFile(#PB_Any, Filename$)
                    If PlaylistFile
                      Help - 1
                      For i = 0 To Help
                        *Ptr = GetGadgetItemData(0, i)
                        If *Ptr
                          WriteStringN(PlaylistFile, *Ptr\Filename$ + "," + Str(*Ptr\Speed))
                        EndIf
                      Next
                      CloseFile(PlaylistFile)
                    EndIf
                  EndIf
                EndIf
                
            EndSelect
           
          Case #PB_Event_Gadget
            Select EventGadget()
              Case 0
                If EventType() = #PB_EventType_RightClick
                  DisplayPopupMenu(0, WindowID(#ManageWindow))
                EndIf
            EndSelect
           
          Case #PB_Event_CloseWindow
            HideWindow(1, #True)
        EndSelect
       
    EndSelect
   
  Until Event = 0
 
 
  ActualTime = ElapsedMilliseconds()
  If Not PauseFlag
    If IsFile(PlayFile)
      If LastTime + *Ptr\Speed < ActualTime
        If YPos = THeight
          If Eof(PlayFile)
            CloseFile(PlayFile)
            PlayFileNo + 1
            If PlayFileNo = CountGadgetItems(0)
              PlayFileNo = 0
            EndIf
            SetGadgetState(0, PlayFileNo)
            *Ptr = GetGadgetItemData(0, PlayFileNo)
            PlayFile = ReadFile(#PB_Any, *Ptr\Filename$)
            PauseFlag = #True
          EndIf
          Line$ = ReadString(PlayFile)
          ;        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
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: lyric prompter

Post by Pot Noodle »

Hi infratec, having spent most of last night studying the code i understand the workings of it now but trying to implement features
to it still makes me scratch my head, I am trying to have it so when it starts it will show the name of the song and what key it is in and when it gets to the eof it scrolls so the screen is blank and then shows the name of the next song and so on.
My idea is to use the eof flag notify me so that it can clear the screen and then display the title and key and wait for the pause key to carry on.
Am i on the right path or not?, cheers.
P.N.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: lyric prompter

Post by Tenaja »

Regarding speed, if you use a fixed rate, then you are asking for frustration. Many songs change tempo throughout it.
Your best bet is to have a time for each line. At the least it could be a correction offset, so steady tempo songs wouldn't require entries.
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: lyric prompter

Post by Pot Noodle »

Good point i was thinking about the speed, i guess something in the song file would trigger the speed! :mrgreen:
P.N.
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: lyric prompter

Post by Pot Noodle »

Having managed to sort out most of the function i need there are still two that i just can't sort out.

(1) If a user click's outside the playlist dialog box the dialog box disappears and you can't get it back.
(2) When the lyric file comes to an end it pauses and when you hit the pause button the new lyric's appear strait under the old ones
You can't clear the screen as it is using sprites, is there a way to start every new song with a clean screen?

Thanks for any help
P.N.
Post Reply