Posted: Sat Apr 29, 2006 6:24 am
Where is the new draft?
The Music Manager for Serious Collectors
http://www.mediamonkey.com/forum/
Code: Select all
' a simple Show lyrics script by BEGGES
' just adds a docking panel with lyrics inside
'thanks to all forum members for their code snippets!!!!
'
'put this script into the Auto-Folder
'no ini-settings necessary
Option Explicit
Dim Tmr, strOldsong
Dim strPath
Dim lyrPanel
DIM LyricsPanelMNU, LyricsPanelForm
'Autoexec
Sub OnStartup
'######################################
'Set the Path o the temporary HTML-File
strPath=sdb.applicationpath
strPath=strPath & "~~SimpleLyricsTemp.html"
'######################################
'CreatePanel to show Lyrics
CreatePanel
'Add the Lyricspanel to the View-Menu
Set LyricsPanelMNU = SDB.UI.AddMenuItem(SDB.UI.Menu_View,1,-1)
LyricsPanelMNU.Caption = "LyricsPanel"
LyricsPanelMNU.shortcut = "Ctrl+Alt+Y"
'Check the laststatus of the Lyricspanel
CheckIni
LyricsPanelMNU.Checked = LyricsPanelForm.Common.Visible
'Register events
'
'TIMER:
'Check with timer If new song is played
LyricsTimer
'MENU:
Script.RegisterEvent LyricsPanelMNU, "OnClick", "ShowPanel"
'SHUTDOWN
Script.RegisterEvent SDB, "OnShutdown", "SDBShutdown"
End Sub
Sub LyricsTimer
Set Tmr = SDB.CreateTimer(1000)
Script.RegisterEvent Tmr, "OnTimer", "SongUpdate"
End Sub
Sub CreatePanel
'Creates the panel
'But makes it not visible --> this is done after checking the ini-File
Set LyricsPanelForm = SDB.Objects("LyricPanel")
If LyricsPanelForm is Nothing Then
Set LyricsPanelForm = SDB.UI.NewDockablePersistentPanel("LyricPanel")
LyricsPanelForm.Common.Width = 250
LyricsPanelForm.Caption = "Lyrics"
Set lyrPanel = SDB.UI.NewActiveX(LyricsPanelForm, "Shell.Explorer")
lyrPanel.Common.Align = 5
lyrPanel.Interf.Navigate strpath ' open the temp-lyric-file
SDB.Objects("LyricPanel") = LyricsPanelForm
SDB.Objects("LyricX") = lyrPanel.Interf
Script.RegisterEvent LyricsPanelForm, "OnClose", "FormClose"
End If
End Sub
Sub CheckIni
If sdb.inifile.stringvalue("LyricsPanel","DockedTo") <> "" then
LyricsPanelForm.Dockedto = sdb.inifile.stringvalue("LyricsPanel","DockedTo")
Else
LyricsPanelForm.Dockedto = 4
End If
If sdb.inifile.stringvalue("LyricsPanel","Show")="True" then
LyricsPanelForm.Common.Visible = True
Else
LyricsPanelForm.Common.Visible = False
End if
End Sub
Sub ExportLyrics
Dim Song, strLyrics, strHeader
Dim TmpFile
'exports the lyrics to the temporary html file
Set Song = SDB.Player.CurrentSong
If Song is Nothing Then
strlyrics = "start player to view Lyrics"
Else
strLyrics = Song.lyrics
End If
If StrLyrics = "" Then
StrLyrics ="No id3V2 Lyric Tag found in" & CHR(10) & Song.path
End If
If Song is Nothing Then
strOldsong ="no song"
Else
strOldsong = song.path
End If
strheader = "<table><tr><td><plaintext style=""font-family:Arial,sans-serIf; font-size:10px;"">"
strlyrics = strheader & strlyrics '&"</table></tr></td></plaintext>"
Set tmpFile = sdb.tools.filesystem.CreateTextFile (strPath, true)
tmpFile.WriteLine strLyrics
End Sub
Sub SDBShutDown
sdb.inifile.stringvalue("LyricsPanel","Show")=LyricsPanelForm.Common.Visible
sdb.inifile.stringvalue("LyricsPanel","DockedTo")=LyricsPanelForm.DockedTo
End Sub
Sub ShowPanel(Item)
LyricsPanelForm.Common.Visible = not LyricsPanelForm.Common.Visible
LyricsPanelMNU.Checked = LyricsPanelForm.Common.Visible
If LyricsPanelForm.Common.Visible = True then
LyricsTimer
Else
Set Tmr = Nothing
Script.UnRegisterEvents Tmr
End If
End Sub
Sub SongUpdate(Timer)
Dim NewSong
Set NewSong = SDB.Player.CurrentSong
If Not NewSong is Nothing Then
If strOldsong <> NewSong.path Then
ExportLyrics 'export new lyrics
lyrPanel.Interf.Navigate strpath 'open the temp-lyric-file again
End If
End If
End Sub
Sub FormClose(Node)
LyricsPanelMNU.Checked = LyricsPanelForm.Common.Visible
Set Tmr = Nothing
Script.UnRegisterEvents Tmr
End Sub
Events have to be unregistered, objects have to be set to Nothing, when you don't need them anymore.one question:
is it necessary to unregister the other events, too (not only the timer)? Maybe because of performance issues?
Code: Select all
Sub Blabla
Dim MyObject
Set MyObject = SDB
'...
Set MyObject = Nothing
End Sub
Code: Select all
Sub CloseDown
Set SDB.Objects("MyObject") = Nothing
End Sub
Code: Select all
body{font:8pt 'Trebuchet MS', Arial, sans serif;margin:0;padding:17px 14px;background:#fff url('lyrics_panel_bg.gif') no-repeat}
plaintext{font:8pt 'Trebuchet MS', Arial, sans serif;margin:0;padding:5px}
h1{margin:5px;clear:both;font-size:150%;font-style:italic;color:#222}
h2{margin:5px;clear:both;font-size:130%;font-weight:normal;padding:0 0 12px 0}
Code: Select all
' a simple Show lyrics script by BEGGES
' modded by gege
' just adds a docking panel with lyrics inside
' thanks to all forum members for their code snippets!!!!
'
' put this script into the Auto-Folder
' no ini-settings necessary
Option Explicit
Dim Tmr, strOldsong
Dim strPath
Dim lyrPanel
Dim LyricsPanelMNU, LyricsPanelForm
Dim stringsMenuCaption
Dim stringsMenuShortcut
Dim stringsPanelCaption
Dim stringsMsgStartPlayer
Dim stringsMsgNoLyrics
'Autoexec
Sub OnStartup
'######################################
'Set the Path o the temporary HTML-File
strPath=sdb.applicationpath
strPath=strPath & "~~SimpleLyricsTemp.html"
'Localizable strings
stringsMenuCaption = "LyricsPanel"
stringsMenuShortcut = "Ctrl+Alt+Y"
stringsPanelCaption = "Lyrics"
stringsMsgStartPlayer = "start player to view Lyrics"
stringsMsgNoLyrics = "No id3V2 Lyric Tag found in"
'######################################
'CreatePanel to show Lyrics
CreatePanel
'Add the Lyricspanel to the View-Menu
Set LyricsPanelMNU = SDB.UI.AddMenuItem(SDB.UI.Menu_View,1,-1)
LyricsPanelMNU.Caption = stringsMenuCaption
LyricsPanelMNU.shortcut = stringsMenuShortcut
'Check the laststatus of the Lyricspanel
CheckIni
LyricsPanelMNU.Checked = LyricsPanelForm.Common.Visible
'Register events
'
'TIMER:
'Check with timer If new song is played
LyricsTimer
'MENU:
Script.RegisterEvent LyricsPanelMNU, "OnClick", "ShowPanel"
'SHUTDOWN
Script.RegisterEvent SDB, "OnShutdown", "SDBShutdown"
End Sub
Sub LyricsTimer
Set Tmr = SDB.CreateTimer(1000)
Script.RegisterEvent Tmr, "OnTimer", "SongUpdate"
End Sub
Sub CreatePanel
'Creates the panel
'But makes it not visible --> this is done after checking the ini-File
Set LyricsPanelForm = SDB.Objects("LyricPanel")
If LyricsPanelForm is Nothing Then
Set LyricsPanelForm = SDB.UI.NewDockablePersistentPanel("LyricPanel")
LyricsPanelForm.Common.Width = 250
LyricsPanelForm.Caption = stringsPanelCaption
Set lyrPanel = SDB.UI.NewActiveX(LyricsPanelForm, "Shell.Explorer")
lyrPanel.Common.Align = 5
lyrPanel.Interf.Navigate strpath ' open the temp-lyric-file
SDB.Objects("LyricPanel") = LyricsPanelForm
SDB.Objects("LyricX") = lyrPanel.Interf
Script.RegisterEvent LyricsPanelForm, "OnClose", "FormClose"
End If
End Sub
Sub CheckIni
If sdb.inifile.stringvalue("LyricsPanel","DockedTo") <> "" then
LyricsPanelForm.Dockedto = sdb.inifile.stringvalue("LyricsPanel","DockedTo")
Else
LyricsPanelForm.Dockedto = 4
End If
If sdb.inifile.stringvalue("LyricsPanel","Show")="True" then
LyricsPanelForm.Common.Visible = True
Else
LyricsPanelForm.Common.Visible = False
End If
End Sub
Sub ExportLyrics
Dim Song, strLyrics, strCompleteLyrics, strHeaderBegin, strHeaderEnd, strSongTitle, strArtistName
Dim strQueryArtist, strQueryMusic, strHttpPath
Dim TmpFile
'exports the lyrics to the temporary html file
Set Song = SDB.Player.CurrentSong
If Song is Nothing Then
strLyrics = stringsMsgStartPlayer
Else
strLyrics = Song.lyrics
End If
If StrLyrics = "" Then
StrLyrics = stringsMsgNoLyrics & CHR(10) & Song.path
End If
If Song is Nothing Then
strOldsong ="no song"
Else
strOldsong = song.path
End If
strHeaderBegin = "<html><head><link href=""lyrics_panel.css"" rel=""stylesheet"" type=""text/css""></head><body><div id=""bg"">"
strSongTitle = "<h1>" & song.Title & "</h1>"
strArtistName = "<h2>" & song.ArtistName & "</h2>"
strHeaderEnd = "<plaintext>"
strCompleteLyrics = strHeaderBegin & strSongTitle & strArtistName & strHeaderEnd & strLyrics
Set tmpFile = sdb.tools.filesystem.CreateTextFile (strPath, true)
tmpFile.WriteLine strCompleteLyrics
End Sub
Sub SDBShutDown
sdb.inifile.stringvalue("LyricsPanel","Show")=LyricsPanelForm.Common.Visible
sdb.inifile.stringvalue("LyricsPanel","DockedTo")=LyricsPanelForm.DockedTo
End Sub
Sub ShowPanel(Item)
LyricsPanelForm.Common.Visible = not LyricsPanelForm.Common.Visible
LyricsPanelMNU.Checked = LyricsPanelForm.Common.Visible
If LyricsPanelForm.Common.Visible = True then
LyricsTimer
Else
Set Tmr = Nothing
Script.UnRegisterEvents Tmr
End If
End Sub
Sub SongUpdate(Timer)
Dim NewSong
Set NewSong = SDB.Player.CurrentSong
If Not NewSong is Nothing Then
If strOldsong <> NewSong.path Then
ExportLyrics 'export new lyrics
lyrPanel.Interf.Navigate strpath 'open the temp-lyric-file again
End If
End If
End Sub
Sub FormClose(Node)
LyricsPanelMNU.Checked = LyricsPanelForm.Common.Visible
Set Tmr = Nothing
Script.UnRegisterEvents Tmr
End Sub
Code: Select all
body{font:8pt Verdana, Arial, sans serif;margin:0;padding:17px 14px;background:#bed7f4 url('lyrics_panel_bg.gif') no-repeat}
plaintext{font:8pt Verdana, Arial, sans serif;margin:0;padding:15px 5px}
h1{margin:5px;clear:both;font-size:150%;font-style:italic;color:#222}
h2{margin:5px;clear:both;font-size:130%;font-weight:normal;padding:0 0 12px 0}