Track-start script behaviour difference in MM3 vs MM2

To get bugs in the current release fixed, please report them here.

Moderator: Gurus

rycher
Posts: 129
Joined: Mon Sep 11, 2006 8:24 pm

Track-start script behaviour difference in MM3 vs MM2

Post by rycher » Sat Jul 05, 2008 9:14 am

Hello,

A short while ago, while I was still using MM2, I saw this thread http://www.mediamonkey.com/forum/viewto ... &sk=t&sd=a where someone made a script to keep logical groups of track together. Basically, you put a common tag in a custom field for tracks that should run together (like whole sides (!) of Pink Floyd's albums, or songs that have an intro in a separate track). When such a track started playing, the script automatically added the following tracks from its group just after it in Now Playing.

I modified the script so it also added the previous track from its group before it, and started playing at the first track of the group. This way, I could use AutoDJ, and be sure that whatever track was added to Now Playing, it would always play complete logical groups that I tagged.

This worked well in MM2. But then I upgraded to MM3, and it does not behave the same.

What I see when MM3 starts playing a linked track, it's that the original track starts playing, and it takes at least 5 seconds before the other tracks are added to the playlist (in MM2 that was instantaneous). But they are added before and after the current track (and the current does not change), so the tracks before never play. More clearly, if 1, 2 and 3 are linked and only 2 is in Now Playing and starts to play, it takes 5 seconds before 1 is added before and 3 is added after. So 2 and 3 play, but not 1. With the same scenario in MM2, track 2 didn't have time to start playing, the other tracks were added and track 1 started playing without any audio glitch (like there would be if track 2 started playing before the manipulation was completed).

In my script, when the current track was linked, before adding the tracks I went to the previous track (using SDB.Player.Previous), then added the other linked tracks at the right position (before or after the original track), and then went to the next track (using SDB.Player.Next) which was now the first track of the linked group. But the next and previous commands now do nothing. It does not give any error message, it just does not do what it did in MM2. I even tried using Stop before the whole manipulation and then Play at the end, those do nothing either. I checked in the scripting documentation but did not see anything.

How come this does not work anymore? Is there another way to do what I want in MM3?

Just when I had the behaviour I wanted, I lose it... But there are other features only in MM3 that I want to keep, so I wouldn't want to have to go back to MM2.

Thanks in advance for your help,
Rycher

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Track-start script behaviour difference in MM3 vs MM2

Post by trixmoto » Wed Jul 09, 2008 3:10 am

I think this is the same issue I suffered with my "Previewer" script. It now takes a bit of time to start the playback because of the crossfading and stuff like that. The way to deal with this is...

Code: Select all

SDB.Player.Play
If SDB.VersionHi > 2 Then
  While SDB.Player.IsStartingPlayback
    SDB.ProcessMessages
  WEnd
End If
Once you've done this you can then change track or whatever it is that you're doing that is not working (I was changing the playback position of the track).
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

rycher
Posts: 129
Joined: Mon Sep 11, 2006 8:24 pm

Re: Track-start script behaviour difference in MM3 vs MM2

Post by rycher » Thu Jul 10, 2008 12:17 am

trixmoto wrote:I think this is the same issue I suffered with my "Previewer" script. It now takes a bit of time to start the playback because of the crossfading and stuff like that. The way to deal with this is...

Code: Select all

SDB.Player.Play
If SDB.VersionHi > 2 Then
  While SDB.Player.IsStartingPlayback
    SDB.ProcessMessages
  WEnd
End If
Once you've done this you can then change track or whatever it is that you're doing that is not working (I was changing the playback position of the track).
I've added your code just before where I go to the previous track and then add the others from the group at the proper place, and it doesn't work.

When arriving on a grouped track, the other tracks are not added at all, and if I pause the playback of the current track (i.e. the grouped track playing by itself) then I can't do anything else in MM anymore, I have to kill it with the task manager (and even this isn't instantaneous). IsStartingPlayback seems to always be true somehow...

Did I put it at the right place?

Rycher

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Track-start script behaviour difference in MM3 vs MM2

Post by trixmoto » Thu Jul 10, 2008 4:39 am

I don't know if you put it in the right place, post your code! :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.

rycher
Posts: 129
Joined: Mon Sep 11, 2006 8:24 pm

Re: Track-start script behaviour difference in MM3 vs MM2

Post by rycher » Thu Jul 10, 2008 2:58 pm

Ok, so it was a bit late yesterday, I didn't bother to cut&paste the whole thing, I just explained what I did...

Here is the code:

Code: Select all

'==========================================================================
'
' MediaMonkey Script
'
' NAME: TiedSongsGroups v1.0
' DESCRIPTION:
'  Lets you make groups of songs, so when one song of the group is played,
'   the next songs in the group are also played (in order).
'
' AUTHOR: Steegy aka RC (Ruben Castelein)
' DATE  : 28.02.2006
' UPDATE: 28.02.2006
'
'  16/06/2008: Modified by Tanguy Kervahut to put all the tracks from the same group (not just those after).
'
' INSTALL:
' - Copy script to MediaMonkey's "Scripts" folder
' - Add an script entry to file Scripts.ini (example shown below)
'
'    [TiedSongsGroups]
'    FileName=TiedSongsGroups.vbs
'    ProcName=OnSongStartsPlaying
'    Order=1
'    DisplayName=TiedSongsGroups
'    Description=TiedSongsGroups
'    Language=VBScript
'    ScriptType=2
'
' USE:
' For songs you want in one group, change the Custom3 field for these songs to
'  the same value, beginning with TG (this indicates a "tied group").
' E.g. for an album "Pink Floyd - Dark Side of the Moon" you can change the Custom3 field
'  for all tracks to "TG Pink Floyd - Dark Side of the Moon". (without quotation marks).
' Bear in mind that shorter values for the Custom3 field are faster (so better "TG PF-DSOTM")
' Order of tracks in a tied group is indicated using the standard Track Number field.
'
'==========================================================================
'>> ForumURL: http://www.mediamonkey.com/forum/viewtopic.php?t=8464
'>> ScriptName: TiedSongsGroups
'>> VersionNumber: 1.0
'>> Author: Steegy aka RC (Ruben Castelein)
'>>>>EndOfProperties


'##############################################################################################


Sub OnSongStartsPlaying

  If Left(SDB.Player.CurrentSong.Custom3, 2) = "LT" Then

    If Not SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "True" Then
      SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "True"
      SavePlayerStates
    End If

    If SDB.Player.CurrentSongIndex = SDB.Player.PlaylistCount - 1 Then
    'Last song in playlist
      PlayerStatesAsContinuous
      AddOtherTiedSongs
    Else
      If (SDB.Player.CurrentSongIndex = 0) Then
	  ' First song in playlist
        PlayerStatesAsContinuous
	  Else
         If (SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex - 1).Custom3 <> SDB.Player.CurrentSong.Custom3 OR SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex - 1).TrackOrder <> SDB.Player.CurrentSong.TrackOrder-1) AND (SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).Custom3 <> SDB.Player.CurrentSong.Custom3 OR SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).TrackOrder <> SDB.Player.CurrentSong.TrackOrder+1) Then
         'Non-tied song before and after
            AddOtherTiedSongs
         Else
         'Tied song 
            PlayerStatesAsContinuous
		End If
      End If

    End If

  Else

    If SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "True" Then
      SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "False"
      RestoreSavedPlayerStates
    End If

  End If

End Sub


Sub AddOtherTiedSongs

  Dim IndexForAdding, OriginalOrder
  IndexForAdding = SDB.Player.CurrentSongIndex
  OriginalOrder = SDB.Player.CurrentSong.TrackOrder
  
    Dim MySongs
' For MM2
'    Set MySongs = SDB.Database.QuerySongs("AND Songs.Custom3='" & DoubleUpSingleQuotes(SDB.Player.CurrentSong.Custom3) & "' ORDER BY Songs.SongOrder ASC")
' For MM3	
	Set MySongs = SDB.Database.QuerySongs("Songs.Custom3='" & DoubleUpSingleQuotes(SDB.Player.CurrentSong.Custom3) & "' ORDER BY Songs.TrackNumber ASC")

    If MySongs.EOF Then
      RestoreSavedPlayerStates
      Exit Sub
    End If

   SDB.Player.Play
   If SDB.VersionHi > 2 Then
     While SDB.Player.IsStartingPlayback
       SDB.ProcessMessages
     WEnd
   End If

    SDB.Player.Stop
    SDB.Player.Previous
	
    Do While Not MySongs.EOF
	  if MySongs.Item.TrackOrder < OriginalOrder then
         SDB.Player.PlaylistAddTrack MySongs.Item
         SDB.Player.PlaylistMoveTrack SDB.Player.PlaylistCount - 1, IndexForAdding
         IndexForAdding = IndexForAdding + 1
	  end if

	  if MySongs.Item.TrackOrder > OriginalOrder then
         IndexForAdding = IndexForAdding + 1
         SDB.Player.PlaylistAddTrack MySongs.Item
         SDB.Player.PlaylistMoveTrack SDB.Player.PlaylistCount - 1, IndexForAdding
	  end if
	  
      MySongs.Next
    Loop
	
    SDB.Player.Next
    SDB.Player.Play

End Sub


Sub RestoreSavedPlayerStates

  SDB.Player.isAutoDJ = StringToBool(SDB.IniFile.StringValue("Player", "saved_isAutoDJ"))
  SDB.Player.isShuffle = StringToBool(SDB.IniFile.StringValue("Player", "saved_isShuffle"))
  SDB.Player.isRepeat = StringToBool(SDB.IniFile.StringValue("Player", "saved_isRepeat"))

SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "False"

End Sub


Sub PlayerStatesAsContinuous

  SDB.Player.isAutoDJ = False
  SDB.Player.isShuffle = False
  SDB.Player.isRepeat = False

End Sub


Sub SavePlayerStates

  SDB.IniFile.StringValue("Player", "saved_isAutoDJ") = SDB.Player.isAutoDJ
  SDB.IniFile.StringValue("Player", "saved_isShuffle") = SDB.Player.isShuffle
  SDB.IniFile.StringValue("Player", "saved_isRepeat") = SDB.Player.isRepeat

End Sub


Function StringToBool(InpuString)

  If InpuString = "True" Then
    StringToBool = True
  Else
    StringToBool = False
  End If

End Function


' Doubles single quotes so SQL doesn't have problems with it anymore
Function DoubleUpSingleQuotes(strInput)
    DoubleUpSingleQuotes = Replace(strInput, "'", "''")
End Function
I also tried putting your code at the very beginning of "Sub OnSongStartsPlaying" instead, but it does not work either. As soon as it arrives on a linked track, nothing plays, the player is in play mode, and the CPU is maxed out (1 CPU, I have a Quad core).

rycher
Posts: 129
Joined: Mon Sep 11, 2006 8:24 pm

Re: Track-start script behaviour difference in MM3 vs MM2

Post by rycher » Thu Jul 10, 2008 4:36 pm

Also, a little note about the exact behaviour: in MM3 it does add the linked track before and after the current and goes on playing the current. But then, contrary to what I said, it jumps to the first of the group in the playlist and plays the whole group (so the current plays twice).

It's like the commands are on hold while the original track is playing, and the script completes at the end of play of the original track.

I don't know if there is a workaround or a new way to do this, but it sure looks like a bug to me.

rycher
Posts: 129
Joined: Mon Sep 11, 2006 8:24 pm

Re: Track-start script behaviour difference in MM3 vs MM2

Post by rycher » Wed Jul 16, 2008 8:06 pm

Just to specify that I'm using MM 3.0.3.1183 with MAD plug-in enabled, on a Quad Core 2.4GH with 2GB and XP SP2.

Rycher

Post Reply