Help with script

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey.

Moderator: Gurus

k_r_eriksson
Posts: 185
Joined: Mon Aug 14, 2006 4:26 pm
Location: Gotland, Sweden

Help with script

Post by k_r_eriksson » Sun Aug 23, 2009 5:39 am

Hi!

I need help with a scirpt i'm working on (Song Information Panel).

Code: Select all

'-------------------------------------------------------------------------
' This script is based on Gege's Lyrics and Comment Viewer v2.1 script
' (http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=22624)
' It also uses code from trixmoto's MonkeyRok script
' (http://www.mediamonkey.com/forum/viewtopic.php?t=14494)
' Icons made by DreadM. Thank you!
'-------------------------------------------------------------------------
' THIS SCRIPT:
' Version: 1.3.0.1
' Last Modified: Aug 22, 2009
' By k_r_eriksson (c)
'-------------------------------------------------------------------------


Sub OnStartup
  Dim ini : set ini = SDB.IniFile

  Call VerifyConfig
  Dim OSi : OSi=SDB.UI.AddOptionSheet("Song Information Settings",Script.ScriptPath,"InitSheet1","SaveSheet1",-2)
  Dim OSj : OSj=SDB.UI.AddOptionSheet("More",Script.ScriptPath,"InitSheet2","SaveSheet2",OSi)
  Call LoadTranslation(ini.StringValue("SongInfo","LanguageFile"))

  Set MSI=SDB.UI.AddMenuItem(SDB.UI.Menu_View,1,0)
  MSI.Caption=Translate("MenuCaption")
  MSI.ShortCut=Translate("MenuShortcut")
  MSI.UseScript=Script.ScriptPath
  MSI.OnClickFunc="ShowPanel"

  SetSongInfoPanel
  MSI.Checked=SDB.Objects("PSI").Common.ChildControl("SongInfo").Common.Visible
  SDB.Objects("MSI")=MSI

  SetIconStatus(MSI.Checked)
  If MSI.Checked Then 
    Start
  End If
End Sub


Sub FirstRun
  ' When the script is run after install, the panel will always start visible
  ' Thus we need this separate "startup" sub
  Dim ini : set ini = SDB.IniFile

  Call VerifyConfig
  Dim OSi : OSi=SDB.UI.AddOptionSheet("Song Information Settings",Script.ScriptPath,"InitSheet1","SaveSheet1",-2)
  Dim OSj : OSj=SDB.UI.AddOptionSheet("More",Script.ScriptPath,"InitSheet2","SaveSheet2",OSi)
  Call LoadTranslation(ini.StringValue("SongInfo","LanguageFile"))

  Set MSI=SDB.UI.AddMenuItem(SDB.UI.Menu_View,1,0)
  MSI.Caption=Translate("MenuCaption")
  MSI.ShortCut=Translate("MenuShortcut")
  MSI.UseScript=Script.ScriptPath
  MSI.OnClickFunc="ShowPanel"

  SetSongInfoPanel
  SDB.Objects("PSI").Common.ChildControl("SongInfo").Common.Visible=True
  MSI.Checked=True
  SDB.Objects("MSI")=MSI

  SetIconStatus(MSI.Checked)
  Start
End Sub


Private Prv


Sub ShowPanel(o)
  If SDB.Objects("MSI").Checked Then
    SDB.Objects("PSI").Common.ChildControl("SongInfo").Common.Visible=False
    SDB.Objects("MSI").Checked=False
  Else
    SDB.Objects("PSI").Common.ChildControl("SongInfo").Common.Visible=True
    SDB.Objects("MSI").Checked=True
    Start
  End If
  SetIconStatus(SDB.Objects("MSI").Checked)
End Sub


Sub Start
    Set SITmr=SDB.CreateTimer(1000)
    Script.RegisterEvent SITmr,"OnTimer","Check"
End Sub


Sub SetSongInfoPanel
  Dim ini : set ini = SDB.IniFile

  If SDB.Objects("PSI") Is Nothing Then
    Set Pnl=SDB.UI.NewDockablePersistentPanel("SongInfo")
    Pnl.Caption=Translate("PanelTitle")
    If ini.BoolValue("SongInfo","BorderlessMode") Then
      ON ERROR RESUME NEXT
      Pnl.showcaption = False
      ON ERROR GOTO 0
    End If

    If Pnl.IsNew Then
      Pnl.Common.Width=250
      Pnl.DockedTo=2
    End If

    Set Sxp=SDB.UI.NewActiveX(Pnl,"Shell.Explorer")
    Sxp.Common.ClientWidth = Pnl.Common.ClientWidth      ' ZvezdanD's trick #1 for 
    Sxp.Common.ClientHeight = Pnl.Common.ClientHeight    ' borderless dockable panel
    Sxp.Common.Anchors = 15                              ' 
    Sxp.Common.ControlName="SXP"
    SDB.Objects("PSI")=Pnl
  End If
End Sub

Sub SetIconStatus(PanelVisible)
  'Icons can have three states: ON, OFF, HIDDEN
   Dim ini : set ini = SDB.IniFile
   ShowIcon = ini.BoolValue("SongInfo","ShowIcon")

   If ShowIcon Then
     If SDB.Objects("SIicon") Is Nothing Then  'creating icon, if it doesn't exist
       Set SIicon = SDB.UI.AddMenuItem(SDB.UI.Menu_TbStandard, 0, 0)
       SIicon.UseScript=Script.ScriptPath
       SIicon.OnClickFunc = "ShowPanel"
       SDB.Objects("SIicon")=SIicon
     End If
     SDB.Objects("SIicon").Visible = True

     'setting icon state
     If PanelVisible Then      'Icon should be in ON state
       SDB.Objects("SIicon").IconIndex = SDB.RegisterIcon("Scripts\SongInformation\iconsipon.ico", 0)
     Else                      'Icon should be in OFF state
       SDB.Objects("SIicon").IconIndex = SDB.RegisterIcon("Scripts\SongInformation\iconsipoff.ico", 0)
     End If

     'translating captions. Language may have been changed in OptionSheet...
     SDB.Objects("SIicon").Caption = Translate("MenuCaption")
     SDB.Objects("SIicon").Hint = Translate("MenuCaption")

    Else      'Icon should be HIDDEN
      If Not SDB.Objects("SIicon") Is Nothing Then
        SDB.Objects("SIicon").Visible = False  'hiding icon
      End If
    End If
End Sub


Sub Check(SITmr)
  If SDB.Player.IsPlaying Then
     Set Sng = SDB.Player.CurrentSong
  Else
     Dim list : Set list = SDB.CurrentSongList
     If (Not list.Count = 0) Then
        Set Sng = list.Item(0)
     Else
        If Not SDB.Player.CurrentSong is Nothing Then
           Set Sng = SDB.Player.CurrentSong
        Else
           Exit Sub
        End if
     End if
  End if

  If SDB.Objects("PSI").Common.ChildControl("SongInfo").Common.Visible Then
      X=Len(Sng.Lyrics)&"-"&Len(Sng.Comment)
      Y=Sng.ID
      If Y="-1" Then      ' If song isn't in Library, we need a workaround...
         Y=Sng.ArtistName&"-"&Sng.Title
      End If
      Z="ID"&Y&"v"&X
      If Prv<>Z Then
         Prv= Z
         Refresh
      End If
  Else
      Script.UnregisterEvents SITmr
      SDB.Objects("MSI").Checked=False
  End If

End Sub


Sub Refresh
Set Doc=SDB.Objects("PSI").Common.ChildControl("SXP").Interf.Document
    Doc.Write SongInfo
    Doc.Close
End Sub


Function SongInfo
  Dim ini
  Set ini = SDB.IniFile

  ShowTrackNumber = ini.BoolValue("SongInfo","ShowTrackNumber")
  showTitle = ini.BoolValue("SongInfo","ShowTitle")
  showArtist = ini.BoolValue("SongInfo","ShowArtist")
  ShowAlbum = ini.BoolValue("SongInfo","ShowAlbum")
  showYear = ini.BoolValue("SongInfo","ShowYear")
  showComposer = ini.BoolValue("SongInfo","ShowComposer")
  showAlbumArtist = ini.BoolValue("SongInfo","ShowAlbumArtist")
  ShowPublisher = ini.BoolValue("SongInfo","ShowPublisher")
  ShowOriginalArtist = ini.BoolValue("SongInfo","ShowOriginalArtist")
  ShowOriginalAlbum = ini.BoolValue("SongInfo","ShowOriginalAlbum")
  ShowOriginalYear = ini.BoolValue("SongInfo","ShowOriginalYear")
  ShowOriginalLyricist = ini.BoolValue("SongInfo","ShowOriginalLyricist")
  ShowCustom1 = ini.BoolValue("SongInfo","ShowCustom1")
  ShowCustom2 = ini.BoolValue("SongInfo","ShowCustom2")
  ShowCustom3 = ini.BoolValue("SongInfo","ShowCustom3")
  ShowCustom4 = ini.BoolValue("SongInfo","ShowCustom4")
  ShowCustom5 = ini.BoolValue("SongInfo","ShowCustom5")
  ShowTempo = ini.BoolValue("SongInfo","ShowTempo")
  ShowMood = ini.BoolValue("SongInfo","ShowMood")
  ShowOccasion = ini.BoolValue("SongInfo","ShowOccasion")
  ShowQuality = ini.BoolValue("SongInfo","ShowQuality")
  ShowLength = ini.BoolValue("SongInfo","ShowLength")
  ShowBitrate = ini.BoolValue("SongInfo","ShowBitrate")
  ShowRating = ini.BoolValue("SongInfo","ShowRating")
  ShowDisc = ini.BoolValue("SongInfo","ShowDisc")
  ShowPlayCounter = ini.BoolValue("SongInfo","ShowPlayCounter")
  ShowBPM = ini.BoolValue("SongInfo","ShowBPM")
  ShowLastPlayed = ini.BoolValue("SongInfo","ShowLastPlayed")
  ShowAdded = ini.BoolValue("SongInfo","ShowAdded")
  ShowType = ini.BoolValue("SongInfo","ShowType")
  ShowConductor = ini.BoolValue("SongInfo","ShowConductor")
  ShowGrouping = ini.BoolValue("SongInfo","ShowGrouping")
  ShowInvolved = ini.BoolValue("SongInfo","ShowInvolved")
  ShowGenre = ini.Boolvalue("SongInfo","ShowGenre")
  ShowFileName = ini.Boolvalue("SongInfo","ShowFileName")
  ShowIDMedia = ini.Boolvalue("SongInfo","ShowIDMedia")
  ShowSongID = ini.Boolvalue("SongInfo","ShowSongID")
  ShowTrackMod = ini.Boolvalue("SongInfo","ShowTrackMod")
  ShowFileMod = ini.Boolvalue("SongInfo","ShowFileMod")
  ShowISRC = ini.Boolvalue("SongInfo","ShowISRC")
  ShowTrackLvl = ini.Boolvalue("SongInfo","ShowTrackLvl")
  ShowAlbumLvl = ini.Boolvalue("SongInfo","ShowAlbumLvl")
  ShowMediaSerialNumber = ini.Boolvalue("SongInfo","ShowMediaSerialNumber")
  ShowPlaylists = ini.Boolvalue("SongInfo","ShowPlaylists")
  ShowAutoPlaylists = ini.Boolvalue("SongInfo","ShowAutoPlaylists")
  ShowPlaying = ini.Boolvalue("SongInfo","ShowPlaying")
  InSep1 = ini.stringvalue("SongInfo","InSep1")
  InSep2 = ini.stringvalue("SongInfo","InSep2")
  borderlessMode=ini.BoolValue("SongInfo","BorderlessMode")
  cssTheme = ini.stringvalue("SongInfo","ThemeName") 

  themePath=Replace("file:///" & SDB.ApplicationPath & "Scripts\SongInformation\themes\" & cssTheme & "\style.css", "\", "/")


  If SDB.Player.IsPlaying Then
     Set Sng = SDB.Player.CurrentSong
  Else
     Dim list : Set list = SDB.CurrentSongList
     If (Not list.Count = 0) Then
        Set Sng = list.Item(0)
     Else
         If Not SDB.Player.CurrentSong is Nothing Then
            Set Sng = SDB.Player.CurrentSong
         End if
     End if
  End if

  CSSstyle = " style=""overflow:auto; border:none"""   'ZvezdanD's trick #2 for borderless ActiveX

  Set Doc=New Page
  ' Doc.Add "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"" ""http://www.w3.org/TR/html4/loose.dtd"">"
  Doc.Add "<html>"
  Doc.Add " <head>"
  Doc.Add "<link href=""" & themePath & """ rel=""stylesheet"" type=""text/css"">"
  Doc.Add " </head>"
  Doc.Add " <body" & CSSstyle & ">"
  Doc.Add ""
  Doc.Add "   <div class=""wrapper"">"
  Doc.Add "      <span class=""wrapper_t""><span></span></span>"
  Doc.Add ""
  Doc.Add "      <div class=""header"">"
  Doc.Add "          <span class=""header_t""><span></span></span>"
  Doc.Add ""
  Doc.Add "          <div class=""header_content""><div>"

  TrackNumber = ""
  If ShowTrackNumber = True Then
    If Not Sng.TrackOrder = "" Then 
      TrackNumber = Sng.TrackOrder & ". "
    End If
  End If

  AlbumYear = ""
  If ShowYear = True Then
    If Sng.Year > 0 Then
      tmpMonth = ""
      tmpDay = ""
      If Not Sng.Month = 0 Then
        tmpMonth = "-" & Sng.Month
      End If
      If Not Sng.Day = 0 Then  
        tmpDay = "-" & Sng.Day
      End If
      AlbumYear = " [" & Sng.Year & tmpMonth & tmpDay & "]"
    End If
  End If

  If ShowTitle = True Then
    Doc.Add "             <span class=""title"">    <h1>" & TrackNumber & Sng.Title & "</h1></span>"
  End If

  If ShowArtist = True Then
    If Not sng.ArtistName = "" Then
      Doc.Add "             <span class=""artist"">   <h2>" & FixMultipleValues(Sng.ArtistName) & "</h2></span>"
    End If
  End If

  If ShowAlbum = True Then
    If Not sng.AlbumName = "" Then
      Doc.Add "             <span class=""album"">    <h3>" & Sng.AlbumName & AlbumYear & "</h3></span>"
    End If
  ElseIf Not AlbumYear = "" Then
    Doc.Add "             <span class=""album"">    <h3>" & AlbumYear & "</h3></span>"
  End If

  If ShowAlbumArtist = True Then
    If Not sng.AlbumArtistName = "" Then
      Doc.Add "             <span class=""albumartist"">   <h3>" & Translate("By") & " " & FixMultipleValues(Sng.AlbumArtistName) & "</h3></span>"
    End If
  End If

  If ShowGenre = True Then
    If Not sng.Genre = "" Then
      Doc.Add "             <span class=""genre"">   <h3>" & FixMultipleValues(Sng.Genre) & "</h3></span>"
    End If
  End If

  If ShowPublisher = True Then
    If Not sng.Publisher = "" Then
      Doc.Add "             <span class=""publisher"">   <h3>" & Sng.Publisher & "</h3></span>"
    End If
  End If

  If showComposer = True Then
    If Not Sng.Author & Sng.Lyricist = "" Then
      If Sng.Author="" Then
        w=Sng.Lyricist
      ElseIf Sng.Lyricist="" Then
        w=Sng.Author
      Else:w=Sng.Author & ";" & Sng.Lyricist
      End If
      Doc.Add "             <span class=""composer""> <h5>(" & FixMultipleValues(w) & ")</h5></span>"
    End If
  End If

  Doc.Add "          </div></div>  <!-- class=""header_content"" -->"
  Doc.Add ""
  Doc.Add "      <span class=""header_b""><span></span></span>"
  Doc.Add "      </div>  <!-- class=""header"" -->"
  Doc.Add ""


'------------------------------------------------------------------------------
  If ShowOriginalArtist = True OR ShowOriginalAlbum = True OR ShowOriginalYear = True OR ShowOriginalLyricist = True Then
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add "<p>" 

    ShowSeparator = False

    If ShowOriginalArtist = True Then
      If Not sng.OriginalArtist = "" Then
        Doc.Add "             <span class=""originalartist"">" & Sng.OriginalArtist & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowOriginalAlbum = True Then
      If Not sng.OriginalTitle = "" Then
        Doc.Add "             <span class=""originalalbum"">" & Sng.OriginalTitle & "</span><br />"
        ShowSeparator = True
      End If
    End If


    If ShowOriginalYear = True Then
      If Not Sng.Year = "" Then
        tmpMonth = ""
        tmpDay = ""
        If Not Sng.Month = 0 Then
          tmpMonth = "-" & Sng.Month
        End If
        If Not Sng.Day = 0 Then  
          tmpDay = "-" & Sng.Day
        End If
        AlbumYear = " [" & Sng.Year & tmpMonth & tmpDay & "]"
      End If
    End If

    OriginalAlbumYear = ""
    If ShowOriginalYear = True Then
      If Sng.OriginalYear > 0 Then
        tmpMonth = ""
        tmpDay = ""
        If Not Sng.OriginalMonth = 0 Then
          tmpMonth = "-" & Sng.OriginalMonth
        End If
        If Not Sng.OriginalDay = 0 Then  
          tmpDay = "-" & Sng.OriginalDay
        End If
        OriginalAlbumYear = " [" & Sng.OriginalYear & tmpMonth & tmpDay & "]"
        Doc.Add "             <span class=""originalyear"">" & OriginalAlbumYear & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowOriginalLyricist = True Then
      If Not Sng.OriginalLyricist = "" Then
        Doc.Add "             <span class=""originallyricist"">(" & Sng.OriginalLyricist & ")</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowSeparator = True Then
      Doc.Add "      <span class=""separator""><span></span></span>"
    End If

    Doc.Add "</p>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '----------------------------------Original recording tags


'------------------------------------------------------------------------------
  If ShowGrouping = True OR ShowConductor = True OR ShowInvolved = True Then
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add "<p>"

    ShowSeparator = False

    If ShowGrouping = True Then
      If Not Sng.Grouping = "" Then
        Doc.Add "             <span class=""grouping"">" & Sng.Grouping & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowInvolved = True Then
      arrInvolvedPeople = Split(Sng.InvolvedPeople,InSep1)
      for counter = 0 to UBound(arrInvolvedPeople)
        tmpArray = Split(arrInvolvedPeople(counter),InSep2)
        tmpType = tmpArray(0)
        tmpName = tmpArray(1)
        tmpType=Replace(tmpType,"  "," ")
        tmpName=Replace(tmpName,"  "," ")
        Doc.Add "      <span class=""involvedpeople"">" & tmpType & ": " & tmpName & "</span><br />"
      next
      If Not Sng.InvolvedPeople = "" Then
        ShowSeparator = True
      End If
    End If

    If ShowConductor = True Then
      If Not Sng.Conductor = "" Then
        Doc.Add "             <span class=""conductor"">" & Translate("Conductor") & ": " & Sng.Conductor & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowSeparator = True Then
      Doc.Add "      <span class=""separator""><span></span></span>"
    End If

    Doc.Add "</p>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '---------------------------------------------Classical music tags


'------------------------------------------------------------------------------
  If ShowCustom1 = True OR ShowCustom2 = True OR ShowCustom3 = True OR ShowCustom4 = True OR ShowCustom5 = True Then
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add "<p>"

    ShowSeparator = False

    If ShowCustom1 = True Then
      If Not Sng.Custom1 = "" Then
        Doc.Add "             <span class=""custom1"">" & ini.StringValue("CustomFields","Fld1Name") & ": " & Sng.Custom1 & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowCustom2 = True Then
      If Not Sng.Custom2 = "" Then
        Doc.Add "             <span class=""custom2"">" & ini.StringValue("CustomFields","Fld2Name") & ": " & Sng.Custom2 & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowCustom3 = True Then
      If Not Sng.Custom3 = "" Then
        Doc.Add "             <span class=""custom3"">" & ini.StringValue("CustomFields","Fld3Name") & ": " & Sng.Custom3 & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowCustom4 = True Then
      If Not Sng.Custom4 = "" Then
        Doc.Add "             <span class=""custom4"">" & ini.StringValue("CustomFields","Fld4Name") & ": " & Sng.Custom4 & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowCustom5 = True Then
      If Not Sng.Custom5 = "" Then
        Doc.Add "             <span class=""custom5"">" & ini.StringValue("CustomFields","Fld5Name") & ": " & Sng.Custom5 & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowSeparator = True Then
      Doc.Add "      <span class=""separator""><span></span></span>"
    End If

    Doc.Add "</p>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '------------------------------------------------Personal tags


'------------------------------------------------------------------------------
  If ShowTempo = True OR ShowMood = True OR ShowOccasion = True OR ShowQuality = True Then
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add "<p>"

    ShowSeparator = False

    If ShowTempo = True Then
      If Not Sng.Tempo = "" Then
        Doc.Add "             <span class=""tempo"">" & Sng.Tempo & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowMood = True Then
      If Not Sng.Mood = "" Then
        Doc.Add "             <span class=""mood"">" & Sng.Mood & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowOccasion = True Then
      If Not Sng.Occasion = "" Then
        Doc.Add "             <span class=""occasion"">" & Sng.Occasion & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowQuality = True Then
      If Not Sng.Quality = "" Then
        Doc.Add "             <span class=""quality"">" & Sng.Quality & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowSeparator = True Then
      Doc.Add "      <span class=""separator""><span></span></span>"
    End If

    Doc.Add "</p>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '----------------------------------------------Classifications tags


'------------------------------------------------------------------------------
  If ShowLength = True OR ShowRating = True OR ShowDisc = True OR ShowPlayCounter = True OR ShowLastPlayed = True OR ShowAdded = True OR ShowSongID = True OR ShowTrackMod = True OR ShowISRC = True OR ShowTrackLvl = True OR ShowAlbumLvl = True Then
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add "<p>"

    ShowSeparator = False

    SongID = ""
    If Not Sng.ID = "-1" Then
      SongID = Sng.ID
    Else
      SongID = Translate("NotInDatabase")
    End If

    If ShowSongID = True Then
      Doc.Add "             <span class=""songid"">" & Translate("SongID") & ": " & SongID & "</span><br />"
      ShowSeparator = True
    End If

    If ShowLength = True Then
      Doc.Add "             <span class=""length"">" & Translate("Length") & ": " & sng.SongLengthString & "</span><br />"
      ShowSeparator = True
    End If

    If ShowRating = True Then
      Doc.Add "             <span class=""rating"">" & RatingStar(sng.Rating) & "</span><br />"
      ShowSeparator = True
    End If

    If ShowDisc = True Then
      If Not Sng.DiscNumberStr = "" Then
        Doc.Add "             <span class=""disc"">" & Translate("Disc") & " " & Sng.DiscNumberStr & "/" & DiscNr(Sng.Album.ID,Sng.ID) & "</span><br />"
      End If
    End If

    PlayCounter = ""
    If ShowPlayCounter = True Then
      If sng.PlayCounter = "0" Then
        PlayCounter = Translate("FirstPlay")
      ElseIf sng.PlayCounter = "1" Then
        PlayCounter = Translate("Played") & " " & Sng.PlayCounter & " " & Translate("Time")
      Else
        PlayCounter = Translate("Played") & " " & Sng.PlayCounter & " " & Translate("Times")
      End If
    End If

    If ShowPlayCounter = True Then
      Doc.Add "             <span class=""playcounter"">" & PlayCounter & "</span><br />"
      ShowSeparator = True
    End If

    LastPlayed = ""
    If ShowLastPlayed = True Then
      If Not sng.LastPlayed = "00:00:00" Then
        LastPlayed = Translate("LastPlayed") & ": " & Sng.LastPlayed
        ShowSeparator = True
      End If
    End If

    If ShowLastPlayed = True Then
      If Not LastPlayed = "" Then
        Doc.Add "             <span class=""lastplayed"">" & LastPlayed & "</span><br />"
      End If
    End If

    If ShowAdded = True Then
      If Not sng.DateAdded = "00:00:00" Then
        Doc.Add "             <span class=""added"">" & Translate("Added") & ": " & Sng.DateAdded & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowTrackLvl = True Then
      Doc.Add "             <span class=""trackvolume"">" & Translate("TrackVol") & ": " & Leveling(Sng.Leveling) & "</span><br />"
      ShowSeparator = True
    End If

    If ShowAlbumLvl = True Then
      Doc.Add "             <span class=""albumvolume"">" & Translate("AlbumVol") & ": " & Leveling(Sng.LevelingAlbum) & "</span><br />"
      ShowSeparator = True
    End If

    If ShowISRC = True Then
      If Not Sng.ISRC = "" Then
        Doc.Add "             <span class=""isrc"">" & Sng.ISRC & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowTrackMod = True Then
      If Not sng.ID = "-1" Then
        Doc.Add "             <span class=""trackmod"">" & Translate("TrackMod") & ": " & TrackMod(Sng.ID) & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowSeparator= True Then
      Doc.Add "      <span class=""separator""><span></span></span>"
    End If

    Doc.Add "</p>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '--------------------------------------------Statistical tags


'------------------------------------------------------------------------------
  If ShowFileName = True OR ShowIDMedia = True OR ShowMediaSerialNumber = True OR ShowType = True OR ShowBitrate = True OR ShowBPM = True OR ShowFileMod = True Then
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add "<p>"

    ShowSeparator = False

    If ShowFileName = True Then
      Doc.Add "             <span class=""filepath"">" & Sng.Path & "</span><br />"
      ShowSeparator = True
    End If

    If ShowIDMedia = True Then
      If Not sng.ID = "-1" Then
        Doc.Add "             <span class=""idmedia"">" & Translate("IDMedia") & ": " & IDMedia(Sng.ID) & "</span><br />"
        ShowSeparator = True
      End If
    End If

    If ShowMediaSerialNumber = True Then
      If Not sng.ID = "-1" Then
        Doc.Add "             <span class=""mediaserialnumber"">" & Translate("MediaSerNmr") & ": " & MediaSerNmr(IDMedia(Sng.ID),Sng.ID) & "</span><br />"
        ShowSeparator = True
      End If
    End If
    
    BPM = ""
    If ShowBPM = True Then
      If Not sng.BPM = "-1" Then
        BPM = sng.BPM & " BPM"
      End If
    End If

    BitRate = ""
    If ShowBitrate = True Then
      If Not sng.Bitrate = "" Then
        BitRate = round(sng.Bitrate/1000) & " kbps&nbsp&nbsp"
      End If
    End If

    strType = ""
    If ShowType = True Then
      tmpPath = sng.Path
      tmpLen = Len(tmpPath) - InStrRev(tmpPath,".")
      strType = Right(tmpPath,tmpLen) & "&nbsp&nbsp"
    End If

    If Not BPM = "" OR Not BitRate = "" OR Not strType = "" Then
      Doc.Add "             <span class=""bitrate"">" & strType & BitRate & BPM & "</span><br />"
      ShowSeparator = True
    End If

    If ShowFileMod = True Then
      Doc.Add "             <span class=""filemod"">" & Translate("FileMod") & ": " & sng.FileModified & "</span><br />"
      ShowSeparator = True
    End If

    If ShowSeparator = True Then
      Doc.Add "      <span class=""separator""><span></span></span>"
    End If

    Doc.Add "</p>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '--------------------------------------------------------File tags


'------------------------------------------------------------------------------
  If ShowPlaylists = True Or ShowAutoPlaylists = True Then
    If ShowPlaylists = True Then
      tmpPlaylists = Playlists(Sng.ID)
      If Not tmpPlaylists = "" Then
        tmpPlaylists = "<p>" & Translate("Playlists") & ":<br />" & tmpPlaylists & "</p>"
      End If
    End If

    If ShowAutoPlaylists = True Then
      tmpAutoPlaylists = AutoPlaylists(Sng.ID)
      If Not tmpAutoPlaylists = "" Then
        tmpAutoPlaylists = "<p>" & Translate("AutoPlaylists") & ":<br />" & tmpAutoPlaylists & "</p>"
        If ShowPlaylists = True Then
          tmpAutoPlaylists = "<br />" & tmpAutoPlaylists
        End If
      End If
    End If

    If tmpPlaylists = "" AND tmpAutoPlaylists = "" Then
      PlaylistCombo = "<p>" & Translate("NoPlaylist") & "</p>"
    Else
      PlaylistCombo = tmpPlaylists & tmpAutoPlaylists
    End If

    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
    Doc.Add PlaylistCombo
    Doc.Add "      <span class=""separator""><span></span></span>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
  End If '--------------------------------------------------------Playlists


'------------------------------------------------------------------------------
    Doc.Add "      <div class=""lvbody"">"
    Doc.Add ""
  If ShowPlaying = True Then
    Doc.Add "<p><a href="""" onClick=""ChangePlaying"">Now playing</a></p>"
  Else
    Doc.Add "<p><a href="""" onClick=""ChangePlaying"">Selected track</a></p>"
  End If
    Doc.Add "      <span class=""separator""><span></span></span>"
    Doc.Add "      </div>  <!-- class=""lvbody"" -->"
'------------------------------------------------------------------Buttons


  Doc.Add "      <span class=""wrapper_b""><span></span></span>"
  Doc.Add "   </div>  <!-- class=""wrapper"" -->"
  Doc.Add ""

  Doc.Add " </body>"
  Doc.Add "</html>"
  SongInfo=Doc.Content
End Function


Class Page
  Dim ATable,AddRows,Row
  Private Sub Class_Initialize()
    AddRows=50
    Row=0
    ReDim ATable(AddRows)
  End Sub
  Public Sub Add(Line)
    If Row>UBound(ATable) Then ReDim Preserve ATable(UBound(ATable)+AddRows)
    ATable(Row)=Line
    Row=Row+1
  End Sub
  Public Function Content
    Content=Join(ATable,vbNewLine)
  End Function
End Class


Function FixMultipleValues(MultValue)
   '  This function does this type of transformation:
   '  Bob Marley;Steven Tyler;Joe Perry     ==> Bob Marley, Steven Tyler & Joe Perry
   '  Santana; Lauryn Hill; Cee-Lo          ==> Santana, Lauryn Hill & Cee-Lo
   '  Christina Aguilera;Pink;Mya;Lil' Kim  ==> Christina Aguilera, Pink, Mya & Lil' Kim

  MultValue=Replace(StrReverse(MultValue),";"," & ",1,1,1)    ' First, we'll replace the last ";" by " & "
  MultValue=Replace(StrReverse(MultValue),";",", ")           ' Now we replace the others, if any, by ", "
  MultValue=Replace(MultValue,"  "," ")                       ' Now we just trim...
  MultValue=Replace(MultValue," ,",",")                       ' ...unneeded spaces
  MultValue=Replace(MultValue,"  "," ")                       ' This one is just to make sure...
  FixMultipleValues=MultValue
End Function


Function RatingStar(starRating)

  If starRating >= 96 Then
    RatingStar = Translate ("Rating") & " 5 " & Translate("Stars")
  ElseIf starRating >=86 Then
    RatingStar = Translate ("Rating") & " 4½ " & Translate("Stars")
  ElseIf starRating >=76 Then
    RatingStar = Translate ("Rating") & " 4 " & Translate("Stars")
  ElseIf starRating >=66 Then
    RatingStar = Translate ("Rating") & " 3½ " & Translate("Stars")
  ElseIf starRating >=56 Then
    RatingStar = Translate ("Rating") & " 3 " & Translate("Stars")
  ElseIf starRating >=46 Then
    RatingStar = Translate ("Rating") & " 2½ " & Translate("Stars")
  ElseIf starRating >=36 Then
    RatingStar = Translate ("Rating") & " 2 " & Translate("Stars")
  ElseIf starRating >=26 Then
    RatingStar = Translate ("Rating") & " 1½ " & Translate("Star")
  ElseIf starRating >=16 Then
    RatingStar = Translate ("Rating") & " 1 " & Translate("Star")
  ElseIf starRating >=6 Then
    RatingStar = Translate ("Rating") & " ½ " & Translate("Star")
  ElseIf starRating >=0 Then
    RatingStar = Translate ("Rating") & " " & Translate("Bomb")
  ElseIf starRating <0 Then
    RatingStar = Translate ("Rating") & " " & Translate("Unknown")
  End If

End Function



Function DiscNr(intIDAlbum,intID)

  If Not intID = "-1" Then
    Dim sql : sql = "SELECT DiscNumber FROM Songs WHERE IDAlbum = "&intIDAlbum&" ORDER BY DiscNumber DESC"
    Dim dbit : Set dbit = SDB.Database.OpenSQL(sql)
    If Not dbit.EOF Then
      DiscNr = dbit.StringByIndex(0)
    End If            
    Set dbit = Nothing
  End If

End Function


Function Playlists(intID)
  Playlists = ""
  If Not intID = "-1" Then
    Dim sql : sql = "SELECT Playlists.PlaylistName FROM Playlists, PlaylistSongs WHERE PlaylistSongs.IDSong = " & intID & " AND Playlists.IDPlaylist = PlaylistSongs.IDPlaylist"
    Dim dbit : Set dbit = SDB.Database.OpenSQL(sql)
    If Not dbit.EOF Then
      While Not dbit.EOF
        Playlists = Playlists & "<span class=""playlists"">" & dbit.StringByIndex(0) & "</span><br />" 
        dbit.Next
      Wend 
    End If  
       
    Set dbit = Nothing

  End If

End Function


Function AutoPlaylists(intID)
  AutoPlaylists = ""
  If Not intID = "-1" Then
    Dim sql  : sql = "SELECT PlaylistName FROM Playlists Where IsAutoPlaylist = 1"
    Dim dbit : Set dbit = SDB.Database.OpenSQL(sql)
      If Not dbit.EOF Then
        While Not dbit.EOF
          Set PList = SDB.PlaylistByTitle(dbit.StringByIndex(0))
          Set List = Plist.Tracks
          For i = 0 To List.Count - 1
            If List.Item(i).ID = intID Then
              AutoPlaylists = AutoPlaylists & "<span class=""autoplaylists"">" & PList.Title & "</span><br />"
            End If
          Next
          dbit.Next
        Wend
      End If

    Set dbit = Nothing

  End If

End Function


Function IDMedia(intIDSong)

  If Not intIDSong = "-1" Then
    Dim sql : sql = "SELECT IDMedia FROM Songs WHERE ID = "&intIDSong
    Dim dbit : Set dbit = SDB.Database.OpenSQL(sql)
    If Not dbit.EOF Then
      IDMedia = dbit.StringByIndex(0)
    End If            
    Set dbit = Nothing
  End If

End Function


Function MediaSerNmr(intIDMedia,intID)

  If Not intID = "-1" Then
    Dim sql : sql = "SELECT SerialNumber FROM Medias WHERE IDMedia = "&intIDMedia
    Dim dbit : Set dbit = SDB.Database.OpenSQL(sql)
    If Not dbit.EOF Then
      MediaSerNmr = dbit.StringByIndex(0)
    End If            
    Set dbit = Nothing
  End If

End Function


Function TrackMod(intIDSong)

  If Not intIDSong = "-1" Then
    Dim sql : sql = "SELECT TrackModified FROM Songs WHERE ID = "&intIDSong
    Dim dbit : Set dbit = SDB.Database.OpenSQL(sql)
    If Not dbit.EOF Then
      tmpTrackMod = dbit.StringByIndex(0)
      tmpLen = InStr(tmpTrackMod,".")
      tmpDate = CDate(Left(tmpTrackMod,tmpLen - 1))
      strLocale = GetLocale
      SetLocale "en-us"
      tmpTime = "0" & MID(tmpTrackMod,tmpLen, Len(tmpTrackMod) - tmpLen)
      tmpTime = ROUND(tmpTime * 86400)
      tmpHour = INT(tmpTime/3600)
      tmpTime = tmpTime - 3600 * tmpHour
      If LEN(tmpHour) = 1 Then
        tmpHour = "0" & tmpHour
      End If
      tmpMinute = Int(tmpTime/60)
      tmpSecond = tmpTime - 60 * tmpMinute
      If Len(tmpMinute) = 1 Then
        tmpMinute = "0" & tmpMinute
      End If
      If Len(tmpSecond) = 1 Then
        tmpSecond = "0" & tmpSecond
      End If
      SetLocale strLocale
      TrackMod = tmpDate & " " & tmpHour & ":" & tmpMinute & ":" & tmpSecond
    End If            
    Set dbit = Nothing
  End If

End Function


Function Leveling(tmpLevel)

  If Not tmpLevel = "-999999" Then
    tmpLevel = Round(tmpLevel,1)
    Leveling = tmpLevel & " dB"
  Else
    Leveling = Translate("NotLeveled")
  End If

I've edited the code to be able to post this message.

In line 778 I have a link. If the link is pressed I want to send information to the script but I don't know how. What I mean is that I can send information to the web-content of the panel but how do I send information back to the script?

I've tried to learn from MR but it is so large.

/Rickard

onenonymous
Posts: 374
Joined: Sat Feb 02, 2008 1:09 pm
Location: Texas

Re: Help with script

Post by onenonymous » Sun Aug 23, 2009 8:57 am

Try this:

Change the Sub Refresh to:

Code: Select all

Sub Refresh
	Set Doc=SDB.Objects("PSI").Common.ChildControl("SXP").Interf.Document
	Doc.Write SongInfo

	Dim cntrl : Set cntrl = Doc.getElementById("ChangePlaying")
	Script.RegisterEvent cntrl, "onclick", "ChangePlaying"
	Set cntrl = Nothing

	Doc.Close
End Sub
Change the section around line 779 to:

Code: Select all

    '------------------------------------------------------------------------------
        Doc.Add "      <div class=""lvbody"">"
        Doc.Add ""
      If ShowPlaying = True Then
        Doc.Add "<p><a id=" & """" & "ChangePlaying" & """" & " href="""" >Now playing</a></p>"
      Else
        Doc.Add "<p><a id=" & """" & "ChangePlaying" & """" & " href="""" >Selected track</a></p>"
      End If
	  
        Doc.Add "      <span class=""separator""><span></span></span>"
        Doc.Add "      </div>  <!-- class=""lvbody"" -->"
    '------------------------------------------------------------------Buttons
And add this procedure:

Code: Select all

sub ChangePlaying()
	msgbox "Change Playing clicked"
end sub

k_r_eriksson
Posts: 185
Joined: Mon Aug 14, 2006 4:26 pm
Location: Gotland, Sweden

Re: Help with script

Post by k_r_eriksson » Sun Aug 23, 2009 9:16 am

It worked. Thank you so very much!!!!

k_r_eriksson
Posts: 185
Joined: Mon Aug 14, 2006 4:26 pm
Location: Gotland, Sweden

Re: Help with script

Post by k_r_eriksson » Thu Sep 17, 2009 3:53 pm

Do I have to register an event for every link that I have or can I have one "Script.RegisterEvent cntrl, "onclick", "ChangePlaying"" and post which link that has been click on to the "ChangePlaying"-sub?

onenonymous
Posts: 374
Joined: Sat Feb 02, 2008 1:09 pm
Location: Texas

Re: Help with script

Post by onenonymous » Fri Sep 18, 2009 8:19 am

I think you have to register an event for each control that you want to monitor. They can all trigger the same procedure if you want - but I'm not aware of a way to tell in that procedure which control was clicked. You could maybe have a different procedure called for each control, that each then calls the common procedure you want to run and passes it a variable to indicate what to do. So for example something like (I'm coding this from memory, so the syntax might be slightly off, but you get the picture:-):

Code: Select all

sub Link1_Click()
   call changePlaying(link1)
end sub

sub Link2_Click()
   call changePlaying(link2)
end sub

sub changePlaying(sString)
   select case sString
     case "link1"
        msgbox "link1 control was clicked"
     case "link2"
        msgbox "link2 control was clicked"
    end select
end sub

k_r_eriksson
Posts: 185
Joined: Mon Aug 14, 2006 4:26 pm
Location: Gotland, Sweden

Re: Help with script

Post by k_r_eriksson » Fri Sep 18, 2009 9:59 am

Ok that what was I thought but the problem is that I don't know how many controls a user will use. I can't make a sub for each control. Maybe I have to limit the number of controls but that is nothing I want to do.

Post Reply