by Guest » Wed Oct 15, 2008 6:45 pm
This is a GREAT script for those who rate songs. My problem was that I found myself distracted and not listening to the songs every time. I needed a replay button. So I eliminated the OK button and replaced it with a Replay Song button. Now if you click a rating, the song is rated and the form exits. If you click replay song, the song replays and the form exits.
I could have never done this from scratch, so thank you Steegy and others.
Code: Select all
'====================================================================================
' MEDIAMONKEY SCRIPT: RatePlayedSong v1.1 (last updated 2007-07-04) by Steegy
'
' Shows a dialog when a song is started, to rate the previous played song.
'====================================================================================
Option Explicit
Dim BtnCapt : BtnCapt = Array("5", "4½", "4", "3½", "3", "2½", "2", "1½", "1", "½", "0")
Dim Rpl
Dim PreviousSong
Dim DoneSettingRating
Dim MI
Sub OnStartup
If SDB.IniFile.StringValue("RatePlayedSong", "Enabled") = "" Then
SDB.IniFile.BoolValue("RatePlayedSong", "Enabled") = True
End If
Set MI = SDB.UI.AddMenuItem(SDB.UI.Menu_Scripts, 1, 1)
MI.Caption = "Rate Played Song"
MI.Hint = "Activate/deactivate dialog for rating played song"
MI.Checked = SDB.IniFile.BoolValue("RatePlayedSong", "Enabled")
Script.RegisterEvent MI, "OnClick", "MI_OnClick"
Script.RegisterEvent SDB, "OnPlay", "RatePlayedSong"
End Sub
Sub RatePlayedSong
If Rpl = 1 Then
Rpl = 0
Exit Sub
Else
If Not IsEmpty(PreviousSong) And MI.Checked Then
If PreviousSong.Rating = -1 Then
SDB.Player.Pause
SDB.Player.PlaybackTime = 0
Dim PreviousSongRating : PreviousSongRating = PreviousSong.Rating
Dim Ret : Ret = GetForm().ShowModal
If Ret <> 1 Then ' If Cancel or Rated
SDB.Player.Play
End If
End If
End If
End If
Set PreviousSong = SDB.Player.CurrentSong
End Sub
Function GetForm
Set GetForm = SDB.Objects("RatePlayedSong_Form")
' Initialize the two variables here because they will be used in both sides of the conditional
Dim lblTit
Dim lblArt
If GetForm Is Nothing Then
Dim bheight : bheight = 23
Dim bwidth : bwidth = 35
Set GetForm = SDB.UI.NewForm
GetForm.Common.SetRect 100, 100, 360, 190
GetForm.BorderStyle = 3 ' Resizable
GetForm.FormPosition = 4 ' Screen Center
GetForm.SavePositionName = "RatePlayedSong_Form"
GetForm.Caption = "Rate Previously Played Song"
Set SDB.Objects("RatePlayedSong_Form") = GetForm
Set lblTit = SDB.UI.NewLabel(GetForm)
lblTit.Caption = "Title: " & PreviousSong.Title
lblTit.Common.Left = 10
lblTit.Common.Top = 14
' Initialize a new named label object, so we can refer to it later
Set SDB.Objects("RatePlayedSong_Form_lblTit") = lblTit
Set lblArt = SDB.UI.NewLabel(GetForm)
lblArt.Caption = "Artist: " & PreviousSong.ArtistName
lblArt.Common.Left = 10
lblArt.Common.Top = lblTit.Common.Top + lblTit.Common.Height +7
' same as above
Set SDB.Objects("RatePlayedSong_Form_lblArt") = lblArt
Dim i, btnPcnt
For i = 0 To 10
Set btnPcnt = SDB.UI.NewButton(GetForm)
btnPcnt.Caption = BtnCapt(i)
btnPcnt.Common.MinHeight = i
btnPcnt.Common.Height = bheight
btnPcnt.Common.Width = bwidth
btnPcnt.Common.Top = lblArt.Common.Top + lblArt.Common.Height + 10 + (i MOD 2)*bheight
btnPcnt.Common.Left = 50 + i*(bwidth - bwidth/2 + 5)
btnPcnt.ModalResult = 3
Script.RegisterEvent btnPcnt.Common, "OnClick", "RateButton_OnClick"
Next
Dim btnrepl : Set btnrepl = SDB.UI.NewButton(GetForm)
btnrepl.Caption = "Replay Song"
btnrepl.Common.SetRect GetForm.Common.Width/2 - 155, lblArt.Common.Top + lblArt.Common.Height + 10 + 2*bheight + 10 + 5, 150, bheight
btnrepl.Default = True
btnrepl.ModalResult = 1
Script.RegisterEvent btnrepl.Common, "OnClick", "ReplaySong_OnClick"
Dim btnCancel : Set btnCancel = SDB.UI.NewButton(GetForm)
btnCancel.Caption = "Cancel Changes"
btnCancel.Common.SetRect GetForm.Common.Width/2 + 5, Btnrepl.Common.Top, 150, bheight
btnCancel.Cancel = True
btnCancel.ModalResult = 2
Else
' this bit is for when the form appears for not the first time
' capture the named label objects in lblTit and lblArt and update their content
Set lblTit = SDB.Objects("RatePlayedSong_Form_lblTit")
lblTit.Caption = "Title: " & PreviousSong.Title
Set lblArt = SDB.Objects("RatePlayedSong_Form_lblArt")
lblArt.Caption = "Artist: " & PreviousSong.ArtistName
End If
End Function
Sub RateButton_OnClick(RateButton)
PreviousSong.Rating = 100 - 10 * RateButton.Common.MinHeight
PreviousSong.UpdateDB
End Sub
Sub MI_OnClick(MI)
MI.Checked = Not MI.Checked
SDB.IniFile.BoolValue("RatePlayedSong", "Enabled") = MI.Checked
End Sub
'Add Replay Song Script
Sub ReplaySong_OnClick(ReplaySong)
Rpl = 1
SDB.Player.Previous
End Sub
This is a GREAT script for those who rate songs. My problem was that I found myself distracted and not listening to the songs every time. I needed a replay button. So I eliminated the OK button and replaced it with a Replay Song button. Now if you click a rating, the song is rated and the form exits. If you click replay song, the song replays and the form exits.
I could have never done this from scratch, so thank you Steegy and others.
[code]'====================================================================================
' MEDIAMONKEY SCRIPT: RatePlayedSong v1.1 (last updated 2007-07-04) by Steegy
'
' Shows a dialog when a song is started, to rate the previous played song.
'====================================================================================
Option Explicit
Dim BtnCapt : BtnCapt = Array("5", "4½", "4", "3½", "3", "2½", "2", "1½", "1", "½", "0")
Dim Rpl
Dim PreviousSong
Dim DoneSettingRating
Dim MI
Sub OnStartup
If SDB.IniFile.StringValue("RatePlayedSong", "Enabled") = "" Then
SDB.IniFile.BoolValue("RatePlayedSong", "Enabled") = True
End If
Set MI = SDB.UI.AddMenuItem(SDB.UI.Menu_Scripts, 1, 1)
MI.Caption = "Rate Played Song"
MI.Hint = "Activate/deactivate dialog for rating played song"
MI.Checked = SDB.IniFile.BoolValue("RatePlayedSong", "Enabled")
Script.RegisterEvent MI, "OnClick", "MI_OnClick"
Script.RegisterEvent SDB, "OnPlay", "RatePlayedSong"
End Sub
Sub RatePlayedSong
If Rpl = 1 Then
Rpl = 0
Exit Sub
Else
If Not IsEmpty(PreviousSong) And MI.Checked Then
If PreviousSong.Rating = -1 Then
SDB.Player.Pause
SDB.Player.PlaybackTime = 0
Dim PreviousSongRating : PreviousSongRating = PreviousSong.Rating
Dim Ret : Ret = GetForm().ShowModal
If Ret <> 1 Then ' If Cancel or Rated
SDB.Player.Play
End If
End If
End If
End If
Set PreviousSong = SDB.Player.CurrentSong
End Sub
Function GetForm
Set GetForm = SDB.Objects("RatePlayedSong_Form")
' Initialize the two variables here because they will be used in both sides of the conditional
Dim lblTit
Dim lblArt
If GetForm Is Nothing Then
Dim bheight : bheight = 23
Dim bwidth : bwidth = 35
Set GetForm = SDB.UI.NewForm
GetForm.Common.SetRect 100, 100, 360, 190
GetForm.BorderStyle = 3 ' Resizable
GetForm.FormPosition = 4 ' Screen Center
GetForm.SavePositionName = "RatePlayedSong_Form"
GetForm.Caption = "Rate Previously Played Song"
Set SDB.Objects("RatePlayedSong_Form") = GetForm
Set lblTit = SDB.UI.NewLabel(GetForm)
lblTit.Caption = "Title: " & PreviousSong.Title
lblTit.Common.Left = 10
lblTit.Common.Top = 14
' Initialize a new named label object, so we can refer to it later
Set SDB.Objects("RatePlayedSong_Form_lblTit") = lblTit
Set lblArt = SDB.UI.NewLabel(GetForm)
lblArt.Caption = "Artist: " & PreviousSong.ArtistName
lblArt.Common.Left = 10
lblArt.Common.Top = lblTit.Common.Top + lblTit.Common.Height +7
' same as above
Set SDB.Objects("RatePlayedSong_Form_lblArt") = lblArt
Dim i, btnPcnt
For i = 0 To 10
Set btnPcnt = SDB.UI.NewButton(GetForm)
btnPcnt.Caption = BtnCapt(i)
btnPcnt.Common.MinHeight = i
btnPcnt.Common.Height = bheight
btnPcnt.Common.Width = bwidth
btnPcnt.Common.Top = lblArt.Common.Top + lblArt.Common.Height + 10 + (i MOD 2)*bheight
btnPcnt.Common.Left = 50 + i*(bwidth - bwidth/2 + 5)
btnPcnt.ModalResult = 3
Script.RegisterEvent btnPcnt.Common, "OnClick", "RateButton_OnClick"
Next
Dim btnrepl : Set btnrepl = SDB.UI.NewButton(GetForm)
btnrepl.Caption = "Replay Song"
btnrepl.Common.SetRect GetForm.Common.Width/2 - 155, lblArt.Common.Top + lblArt.Common.Height + 10 + 2*bheight + 10 + 5, 150, bheight
btnrepl.Default = True
btnrepl.ModalResult = 1
Script.RegisterEvent btnrepl.Common, "OnClick", "ReplaySong_OnClick"
Dim btnCancel : Set btnCancel = SDB.UI.NewButton(GetForm)
btnCancel.Caption = "Cancel Changes"
btnCancel.Common.SetRect GetForm.Common.Width/2 + 5, Btnrepl.Common.Top, 150, bheight
btnCancel.Cancel = True
btnCancel.ModalResult = 2
Else
' this bit is for when the form appears for not the first time
' capture the named label objects in lblTit and lblArt and update their content
Set lblTit = SDB.Objects("RatePlayedSong_Form_lblTit")
lblTit.Caption = "Title: " & PreviousSong.Title
Set lblArt = SDB.Objects("RatePlayedSong_Form_lblArt")
lblArt.Caption = "Artist: " & PreviousSong.ArtistName
End If
End Function
Sub RateButton_OnClick(RateButton)
PreviousSong.Rating = 100 - 10 * RateButton.Common.MinHeight
PreviousSong.UpdateDB
End Sub
Sub MI_OnClick(MI)
MI.Checked = Not MI.Checked
SDB.IniFile.BoolValue("RatePlayedSong", "Enabled") = MI.Checked
End Sub
'Add Replay Song Script
Sub ReplaySong_OnClick(ReplaySong)
Rpl = 1
SDB.Player.Previous
End Sub[/code]