Page 1 of 2

I need a gap! ~ How do I pause *after* a song?

Posted: Tue Jan 22, 2008 6:03 pm
by Soren Werk
I often DJ a tango "milonga" (argentine tango ball).

Tango dancers expect a short break between each song. Incredibly this is not an option in MM! So I started scripting, and this is what I've come up with so far.

Code: Select all

'======================================================================
'
' MediaMonkey AutoScript - GapPause.vbs
'
' Pauses a few seconds before each song thus creating a silent gap between songs.
' 
' 2008-01-22 - Soren Werk - www.tangoman.dk
'
' TODO:
'   Not ready for release
'   Should pause *after* song instead of before
'   Pauses before first song
'   Pauses just before prior song is finished - and finishes it after the pause
'   Pause time should be configurable in Options
'
'======================================================================

Option Explicit

Sub OnStartUp()
  Script.RegisterEvent SDB, "OnPlay", "PauseBefore"
End Sub

Sub PauseBefore()
  SDB.Player.Pause

  Dim Tmr : Set Tmr = SDB.CreateTimer(10000)
  Script.RegisterEvent Tmr, "OnTimer", "UnPause" 
End Sub

Sub UnPause(Timer)
  SDB.Player.Pause

  Script.UnregisterEvents Timer
End Sub
The latest version of this script can be found here

As you see, I pause before each song is played. But of course I want to pause after. How do I do that?

http://www.tangoman.dk

Posted: Tue Jan 22, 2008 6:15 pm
by Teknojnky
You can't, there is no event for song end.

see also these threads for more info

http://www.mediamonkey.com/forum/viewtopic.php?t=19476

http://www.mediamonkey.com/forum/viewtopic.php?t=24980

Posted: Wed Jan 23, 2008 5:06 am
by Soren Werk
Wow! That's hard to accept!

So I will join you in your quest to find a solution - even if it means learning about Winamp Plugin Architecture. :-?
I am inspired by your script "Stop After Current". But we must find a solution...

Posted: Wed Jan 23, 2008 6:21 am
by rovingcowboy
i believe winamp is only able to pause before a song.

i use the old plugin program called Djamp where it uses the Microsoft Agents to say the name of the song, and a stupid or some triva comment about it or anything you want it to say.

it will read the upcoming title when it is picked before it starts playing. and pause it then say what it has to and start it.

i know it is before the song plays because sometimes it does not catch the keyword it looks for at the start, and i hear about a second of the song before it pauses it.

so i don't think even winamp pauses after the song.
:-?

Posted: Wed Jan 23, 2008 9:06 am
by DaledeSilva
this is an ad hoc solution... but how acurate is a timerevent?

when a song starts, you could register an event for the songs length... when that time passes, the event fires (at the end of the song) and pauses.

could that work?

Posted: Wed Jan 23, 2008 9:24 am
by Teknojnky
I had considered doing that, but like you ask, I don't know the accuracy of the timer.. and further it would become more complex regarding files which are skipped or paused etc...

not to mention, that you would lose the playtime/playcount update..

Posted: Wed Jan 23, 2008 5:32 pm
by Soren Werk
I'm beginning to accept that, as there is no "OnPlayEnd" event, it is only possible to make a gap before a song - not after. And of course, there's nothing wrong with that, except that it makes a gap before the first song too, unless the feature is first turned on during song play.

So I have revised my script so you have to press a button to turn on the feature. I got that idea from Teknojnky's StopPause script. Thank you. :D

Code: Select all

'======================================================================
' MediaMonkey AutoScript - GapBefore.vbs
'
' Pauses a few seconds before each song, thus creating a gap between songs.
' Must be activated by the new PauseBefore button on the standard toolbar.
' Best activated during song play - or there will a pause before the first song too.
'
' 2008-01-23 - Soren Werk - www.tangoman.dk
'
' TODO:
'   Should pause *after* song instead of before
'   Pause time should be configurable in Options
'   Cuts off a bit of the prior song and plays it after the pause
'======================================================================

Option Explicit

Const GapSeconds = 5
Const OnIcon = 1
Const OffIcon = 2
Const OnCaption = "Turn off 'PauseBefore'"
Const OffCaption = "Turn on 'PauseBefore' (Pauses 5 seconds before each song)"

Sub OnStartUp()
  AddToolbarButton_PauseBefore
End Sub

Sub AddToolbarButton_PauseBefore ()
  Dim Button
  Set Button = SDB.UI.AddMenuItem(SDB.UI.Menu_TBStandard,0,0)
  Button.IconIndex = OffIcon
  Button.Caption = OffCaption
  Button.OnClickFunc = "OnClickPauseBefore"
  Button.UseScript = Script.ScriptPath
  SDB.Objects("ButtonPauseBefore") = Button
End Sub

Sub OnClickPauseBefore(Button)
  Button.Checked = not Button.Checked
  If Button.Checked Then
    SDB.Objects("ButtonPauseBefore").IconIndex = OnIcon
    SDB.Objects("ButtonPauseBefore").Caption = OnCaption
    Script.RegisterEvent SDB, "OnPlay", "PauseBefore"
  Else
    SDB.Objects("ButtonPauseBefore").IconIndex = OffIcon
    SDB.Objects("ButtonPauseBefore").Caption = OffCaption
    Script.UnRegisterEvents SDB
  End If
End Sub

Sub PauseBefore()
  SDB.Player.Pause
  Dim Timer : Set Timer = SDB.CreateTimer(1000 * GapSeconds)
  Script.RegisterEvent Timer, "OnTimer", "UnPause" 
End Sub

Sub UnPause(Timer)
  SDB.Player.Pause
  Script.UnregisterEvents Timer
End Sub
Thank you all! 8)

Countdown display?

Posted: Wed Jan 23, 2008 5:47 pm
by Soren Werk
Now I would like to display a countdown during the gap. 5 - 4 - 3 - 2 - 1
Any sugestions?

Posted: Wed Jan 23, 2008 6:01 pm
by Teknojnky
try this, should work (haven't tested)

Code: Select all

Sub PauseBefore() 
  SDB.Player.Pause 
  Dim Timer : Set Timer = SDB.CreateTimer(1000) 
  Script.RegisterEvent Timer, "OnTimer", "UnPause" 
  Dim Countdown : Set Countdown = SDB.Progress
  Countdown.Value = 0
  Countdown.MaxValue = GapSeconds+1
  Countdown.Text="Paused: " & Progress.Value & " of " Progress.MaxValue-1
End Sub 

Sub UnPause(Timer) 
  Countdown.Increase
  Countdown.Text="Paused: " & Countdown.Value & " of " Countdown.MaxValue-1

  If Coundown.Value = GapSeconds Then
    SDB.Player.Pause 
    Script.UnregisterEvents Timer 
  End If
End Sub 
edit: whoops fixed to countdown object not progress object :o

Posted: Thu Jan 24, 2008 6:27 pm
by Soren Werk
Thanks for the countdown bar Teknojnky - it works just fine!

Now I'm wondering why I can't turn off the PauseBefore effect? I thought Script.UnRegisterEvents SDB was supposed to take care of that - but it's not working! I guess I'll have to read more about Script.UnRegisterEvents and Script.UnRegisterAllEvents somewhere. It doesn't say much in the wiki.

By the way - I stopped using SDB.Objects as a container for my Button and I don't see any adverse effects of that.

Code: Select all

'======================================================================
' MediaMonkey AutoScript - GapBefore.vbs
'
' Pauses a few seconds before each song, thus creating a gap between songs.
' Must be activated by the new PauseBefore button on the standard toolbar.
' Should be activated during song play to avoid pause before the first song.
'
' 2008-01-24 - Soren Werk - www.tangoman.dk
'
' TODO:
'   PauseBefore cannot be turned off!!
'   Should pause *after* song instead of before
'   Pause time should be configurable in Options
'   Cuts off a bit of the prior song and plays it after the pause
'======================================================================

Option Explicit

Const GapSeconds = 10
Const OnIcon = 1
Const OffIcon = 2
Const OnCaption = "Turn off 'PauseBefore'"
Const OffCaption = "Turn on 'PauseBefore' (Pauses a few seconds before each song)"

Dim PauseProgress

Sub OnStartUp()
  AddToolbarButton_PauseBefore
End Sub

Sub AddToolbarButton_PauseBefore ()
  Dim Button : Set Button = SDB.UI.AddMenuItem(SDB.UI.Menu_TBStandard,0,0)
  Button.IconIndex = OffIcon
  Button.Caption = OffCaption
  Button.OnClickFunc = "OnClickPauseBefore"
  Button.UseScript = Script.ScriptPath
End Sub

Sub OnClickPauseBefore(Button)
  Button.Checked = not Button.Checked
  If Button.Checked Then
    Button.IconIndex = OnIcon
    Button.Caption = OnCaption
    Script.RegisterEvent SDB, "OnPlay", "PauseBefore"
  Else
    Button.IconIndex = OffIcon
    Button.Caption = OffCaption
    Script.UnRegisterEvents SDB
  End If
End Sub

Sub PauseBefore()
  SDB.Player.Pause
  Dim Timer : Set Timer = SDB.CreateTimer(1000)
  Script.RegisterEvent Timer, "OnTimer", "UnPause"

  Set PauseProgress = SDB.Progress
  PauseProgress.MaxValue = GapSeconds
  SetProgressText
End Sub

Sub UnPause(Timer)
  PauseProgress.Increase
  SetProgressText

  If PauseProgress.Value = PauseProgress.MaxValue Then
    If SDB.Player.isPaused Then
      SDB.Player.Pause ' Turn off pause
    End If
    
    Script.UnregisterEvents Timer
    Set Timer = nothing
    Set PauseProgress = nothing
  End If
End Sub

Sub SetProgressText
  PauseProgress.Text="Pause between songs " & GapSeconds - PauseProgress.Value & " seconds."
End Sub

Getting better all the time!

Posted: Thu Jan 31, 2008 4:39 pm
by Soren Werk
Getting better all the time!

Allright - so I learned some more about UnRegistrerEvents from this Topic by Teknojnky with very relevant postings by trixmoto and jiri. Thank you very much!

I have only one problem left: How do I turn off the progress indicator when I click (>) to manually start a song during the pause? How do I detect a click on the (>) button.

Code: Select all

'======================================================================
' MediaMonkey\Scripts\Auto\PauseBefore.vbs
'
' Pauses a few seconds before each song, thus creating a gap between songs.
' Must be activated by clicking the PauseBefore button on the standard toolbar.
' Activate during first song play to avoid pause before the first song.
'
' 2008-01-31 - Soren Werk - www.tangoman.dk
'
' ToDo:
'   Turn off progress indicator when pressing (>) during the pause.
'   Cuts off a bit of the prior song and plays it after the pause.
'   Pause time should be configurable in Options.
'   Should pause *after* song instead of before.
'======================================================================

Option Explicit

Const PauseBeforeSeconds = 15

Dim PauseBeforeOn
Dim PauseBeforeButton
Dim PauseBeforeProgress
Dim PauseBeforeTimer
Dim FirstSongStarted

Sub OnStartUp()
  InitButton
  InitOnPlay
  InitTimer
End Sub

Sub InitButton()
  Set PauseBeforeButton = SDB.UI.AddMenuItem(SDB.UI.Menu_TBStandard,0,0)
  PauseBeforeButton.IconIndex = 2
  PauseBeforeButton.Caption = "Turn 'PauseBefore' on and off"
  Script.RegisterEvent PauseBeforeButton, "OnClick", "OnPauseBeforeButtonClick"
  OnPauseBeforeButtonClick(PauseBeforeButton) ' Activate button
End Sub

Sub InitOnPlay()
  Script.RegisterEvent SDB, "OnPlay", "OnPlay"
End Sub

Sub InitTimer()
  Set PauseBeforeTimer = SDB.CreateTimer(1000)
  PauseBeforeTimer.Enabled = False
  Script.RegisterEvent PauseBeforeTimer, "OnTimer", "OnPauseBeforeTimer"
End Sub

'======================================================================

Sub OnPauseBeforeButtonClick(Button)
  Button.Checked = not Button.Checked
  PauseBeforeOn = Button.Checked
End Sub

Sub OnPlay()
  If PauseBeforeOn Then
    If FirstSongStarted Then
      SDB.Player.Pause
      Set PauseBeforeProgress = SDB.Progress
      PauseBeforeProgress.MaxValue = PauseBeforeSeconds
      PauseBeforeProgress.Text="Pause " & PauseBeforeSeconds & " seconds."
      PauseBeforeTimer.Enabled = True
    End If
  End If
  FirstSongStarted = True
End Sub

Sub OnPauseBeforeTimer(Timer)
  PauseBeforeProgress.Increase
  PauseBeforeProgress.Text="Pause " & PauseBeforeSeconds - PauseBeforeProgress.Value & " seconds."
  If PauseBeforeProgress.Value >= PauseBeforeProgress.MaxValue Then
    If SDB.Player.isPaused Then
      SDB.Player.Pause ' Start player again
    End If
    PauseBeforeTimer.Enabled = False
    Set PauseBeforeProgress = Nothing
  End If
End Sub

Same Script - New Name - New Method

Posted: Sat Feb 02, 2008 6:31 pm
by Soren Werk
Same Script - New Method - New Name

I am using Player.Stop now, instead of Player.Pause, because I have discovered that Player.Stop does not cut off a little bit of the prior song and play it after the gap, the way Player.Pause does. This is good! I also found out how to turn off the progress indicator when the user starts the next song manually (by pressing (>) during the gap). This is also good! The only thing I am missing now, is a way to suppress the gap when I manually start a new song or set of songs.

Any suggestions anyone?
Is there any way to detect changes to the next song of the now playing list?

I changed the name of the script, because the old name reflects the old method used to create the gap. I like the new name better.

Code: Select all

'======================================================================
' MediaMonkey\Scripts\Auto\Gap.vbs
'
' Creates a gap between each song.
' Can be turned on and off with a button on the toolbar.
'
' 2008-02-02 - Soren Werk - www.tangoman.dk
'
' ToDo:
'   Defaults configurable in Options.
'   No gap when manual start of new song or set of songs.
'   Gap after "this" song instead of before next.
'======================================================================

Option Explicit

Const GapSeconds = 15
Const GapDefaultOn = True

Dim GapButton
Dim GapProgress
Dim GapTimer
Dim FirstSong : FirstSong = True
Dim AfterGap : AfterGap = False

Sub OnStartUp()
  InitButton
  InitPlayer
  InitTimer
End Sub

Sub InitButton()
  Set GapButton = SDB.UI.AddMenuItem(SDB.UI.Menu_TBStandard,0,0)
  GapButton.IconIndex = 2
  GapButton.Caption = "Turn " & GapSeconds & " seconds gap on and off"
  Script.RegisterEvent GapButton, "OnClick", "GapButtonOnClick"
  If GapDefaultOn Then
    GapButtonOnClick(GapButton)
  End If
End Sub

Sub InitPlayer()
  Script.RegisterEvent SDB, "OnPlay", "PlayerOnPlay"
'  Script.RegisterEvent SDB, "WhichEvent??", "SetFirstSong"
End Sub

Sub InitTimer()
  Set GapTimer = SDB.CreateTimer(1000)
  GapTimer.Enabled = False
  Script.RegisterEvent GapTimer, "OnTimer", "GapOnTimer"
End Sub

'======================================================================

Sub GapButtonOnClick(Button)
  Button.Checked = not Button.Checked
End Sub

Sub PlayerOnPlay()
  GapTimer.Enabled = False
  Set GapProgress = Nothing
  If GapButton.Checked and not FirstSong and not AfterGap Then
    SDB.Player.Stop
    AfterGap = True
    Set GapProgress = SDB.Progress
    GapProgress.MaxValue = GapSeconds
    GapProgress.Text="Gap " & GapSeconds & " seconds."
    GapTimer.Enabled = True
  Else
    AfterGap = False
  End If
  FirstSong = False
End Sub

Sub SetFirstSong()
  FirstSong = True
End Sub

Sub GapOnTimer(Timer)
  GapProgress.Increase
  GapProgress.Text="Gap " & GapSeconds - GapProgress.Value & " seconds."
  If GapProgress.Value >= GapProgress.MaxValue Then
    If not SDB.Player.isPlaying Then
      SDB.Player.Play
    End If
    GapTimer.Enabled = False
    Set GapProgress = Nothing
  End If
End Sub

Posted: Tue Jun 03, 2008 9:56 pm
by Guest
Thanks for this script. Let us know if you come up with the features you're looking for. Incidentally I'm starting to have the problem you described--MM cuts off a little bit of the prior song and play it after the gap. This is happening even though I'm using your latest script, which uses Player.Stop rather than Player.Pause.

Posted: Wed Jun 04, 2008 12:01 am
by rovingcowboy
Anonymous wrote:Thanks for this script. Let us know if you come up with the features you're looking for. Incidentally I'm starting to have the problem you described--MM cuts off a little bit of the prior song and play it after the gap. This is happening even though I'm using your latest script, which uses Player.Stop rather than Player.Pause.
try going in to the plugin controls for the output plugin, and set the buffer or the crossfade to a different amount. or turn off remove silent space from the song. then if it does cut some of the song off it will only cut off the silent space. 8)



:)

Posted: Thu Jun 05, 2008 8:31 pm
by Guest
Thanks. I didn't see a buffer option in the output plugin that I was using (although I did see buffer options in the second output plugin, which was deselected).
I turned off "remove space between tracks" and that seems to have resolved my issue.