Auto Beats DJ 1.4 - Updated 12/07/2012

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Auto Beats DJ 1.4 - Updated 12/07/2012

Postby trixmoto » Mon Mar 29, 2010 12:05 pm

This is a new "Auto DJ" style script which selects tracks based on the BPM (Beats Per Minute). Once installed the option "Auto Beats DJ" will appear in the dropdown of sources in the Auto DJ options sheet. Selecting this as the source will allow you to choose a filter and the tolerance.

Please note that you should only run this script if you have tracks where the BPM has been calculated. If you do not have any (in the filter selected) then this will cause Auto DJ to cease functioning. However, they do not all need to have BPM values, the tracks without will simply be ignored and never selected.

As always, the installer can be downloaded from my website, which is linked to in my signature. And here is the code...

Code: Select all
'
' MediaMonkey Script
'
' NAME: AutoBeatsDJ 1.4
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 12/07/2012
'
' INSTALL: Copy to Scripts directory
'
' FIXES: Added option to not favour unplayed tracks 
'        Added option to exclude last X played tracks
'

Option Explicit
Dim Filters()
Dim Debug : Debug = False
Dim FilterName : FilterName = "- No Filter -"
Dim FilterSQL : FilterSQL = ""
Dim Tolerance : Tolerance = 10
Dim Wandering : Wandering = 1
Dim Unplayed : Unplayed = True
Dim History : History = 50

Sub Install()
  'set default values
  Dim ini : Set ini = SDB.IniFile     
  If ini.StringValue("AutoBeatsDJ","FilterName") = "" Then
    ini.StringValue("AutoBeatsDJ","FilterName") = FilterName
  End If 
  If ini.StringValue("AutoBeatsDJ","Tolerance") = "" Then
    ini.IntValue("AutoBeatsDJ","Tolerance") = Tolerance
  End If
  If ini.StringValue("AutoBeatsDJ","Wandering") = "" Then
    ini.IntValue("AutoBeatsDJ","Wandering") = Wandering
  End If   
  If ini.StringValue("AutoBeatsDJ","Unplayed") = "" Then
    ini.BoolValue("AutoBeatsDJ","Unplayed") = Unplayed
  End If   
  If ini.StringValue("AutoBeatsDJ","History") = "" Then
    ini.IntValue("AutoBeatsDJ","History") = History
  End If 

  'add ini entries
  Set ini = SDB.Tools.IniFileByPath(SDB.ApplicationPath&"Scripts\Scripts.ini")
  If Not (ini Is Nothing) Then
    ini.StringValue("AutoBeatsDJ","Filename") = "AutoBeatsDJ.vbs"
    ini.StringValue("AutoBeatsDJ","DisplayName") = "Auto Beats DJ"
    ini.StringValue("AutoBeatsDJ","Description") = "An AutoDJ which selects similar BPM"
    ini.StringValue("AutoBeatsDJ","Language") = "VBScript"
    ini.StringValue("AutoBeatsDJ","ScriptType") = "4"
    SDB.RefreshScriptItems
  End If     

  If Debug Then
    Call clear()
  End If 
  Set SDB.Objects("AutoBeatsData") = Nothing
End Sub

Sub InitConfigSheet(Sheet)
  Dim ui : Set ui = SDB.UI
  Dim ini : Set ini = SDB.IniFile
  FilterName = ini.StringValue("AutoBeatsDJ","FilterName")
  Tolerance = ini.IntValue("AutoBeatsDJ","Tolerance")
  Wandering = ini.IntValue("AutoBeatsDJ","Wandering")   
  Unplayed = ini.BoolValue("AutoBeatsDJ","Unplayed")
  History = ini.IntValue("AutoBeatsDJ","History") 
 
  Dim edt : Set edt = ui.NewLabel(Sheet)
  edt.Common.SetRect 0, 6, 50, 20
  edt.Caption = "Filter:"
  edt.Autosize = False
 
  Set edt = ui.NewDropDown(Sheet)
  edt.Common.SetRect 34, 3, 150, 20
  edt.Style = 2
  edt.Common.ControlName = "ABDJFilterName"
  Call CreateFiltersArray()
  Call FillDropDownFromArray(edt,Filters)
  edt.ItemIndex = GetFiltersArrayID(FilterName)

  Set edt = ui.NewLabel(Sheet)
  edt.Common.SetRect 194, 6, 50, 20
  edt.Caption = "±BPM:"
  edt.Autosize = False

  Set edt = ui.NewSpinEdit(Sheet)
  edt.Common.SetRect 232, 3, 40, 20
  edt.Common.ControlName = "ABDJTolerance"
  edt.MinValue = 0
  edt.MaxValue = 99
  edt.Value = Tolerance
 
  Set edt = ui.NewLabel(Sheet)
  edt.Common.SetRect 283, 6, 50, 20
  edt.Caption = "Wandering:"
  edt.Autosize = False

  Set edt = ui.NewSpinEdit(Sheet)
  edt.Common.SetRect 345, 3, 40, 20
  edt.Common.ControlName = "ABDJWandering"
  edt.MinValue = 1
  edt.MaxValue = 99
  edt.Value = Wandering 
 
  Set edt = ui.NewLabel(Sheet)
  edt.Common.SetRect 397, 6, 150, 20
  edt.Caption = "Exclude last played:"
  edt.Autosize = False

  Set edt = ui.NewSpinEdit(Sheet)
  edt.Common.SetRect 500, 3, 40, 20
  edt.Common.ControlName = "ABDJHistory"
  edt.MinValue = 1
  edt.MaxValue = 99
  edt.Value = History 
 
  Set edt = ui.NewCheckbox(Sheet)
  edt.Common.SetRect 0, 25, 110, 20
  edt.Common.ControlName = "ABDJUnplayed"
  edt.Caption = "Favour unplayed?"
  edt.Checked = Unplayed 
End Sub
 
Sub CloseConfigSheet(Sheet,SaveConfig)
  If SaveConfig Then
    Dim ini : Set ini = SDB.IniFile
    Dim edt : Set edt = Sheet.Common.ChildControl("ABDJFilterName")
    ini.StringValue("AutoBeatsDJ","FilterName") = edt.ItemText(edt.ItemIndex)
    ini.IntValue("AutoBeatsDJ","Tolerance") = Sheet.Common.ChildControl("ABDJTolerance").Value
    ini.IntValue("AutoBeatsDJ","Wandering") = Sheet.Common.ChildControl("ABDJWandering").Value
   ini.BoolValue("AutoBeatsDJ","Unplayed") = Sheet.Common.ChildControl("ABDJUnplayed").Checked
   ini.IntValue("AutoBeatsDJ","History") = Sheet.Common.ChildControl("ABDJHistory").Value
    Set SDB.Objects("AutoBeatsData") = Nothing
    If Debug Then
      Call clear()
    End If
  End If
End Sub

Function GenerateNewTrack()
  Set GenerateNewTrack = Nothing
  If Debug Then
    Call out("GenerateNewTrack")
  End If     
  Dim iter : Set iter = Nothing
  Dim dic : Set dic = SDB.Objects("AutoBeatsData")
  If dic Is Nothing Then
    Set dic = CreateObject("Scripting.Dictionary")
    dic.Item("cur") = 0
    dic.Item("dir") = 0
    dic.Item("tol") = SDB.IniFile.IntValue("AutoBeatsDJ","Tolerance")
    dic.Item("wan") = SDB.IniFile.IntValue("AutoBeatsDJ","Wandering")
   dic.Item("unp") = SDB.IniFile.IntValue("AutoBeatsDJ","Unplayed")
   dic.Item("lst") = SDB.IniFile.IntValue("AutoBeatsDJ","History")
    dic.Item("sql") = GetFilterSQL()
    Set iter = SDB.Database.OpenSQL("SELECT MIN(Songs.BPM),MAX(Songs.BPM) FROM Songs WHERE Songs.ID>0 "&dic.Item("sql"))
    dic.Item("min") = Int(iter.ValueByIndex(0))
    dic.Item("max") = Int(iter.ValueByIndex(1))
    Set iter = Nothing   
    If Debug Then
      Call out("Tolerance="&dic.Item("tol"))
      Call out("Wandering="&dic.Item("wan"))
     Call out("Unplayed= "&dic.Item("wan"))
     Call out("History=  "&dic.Item("wan"))
      Call out("Min BPM=  "&dic.Item("min"))
      Call out("Max BPM=  "&dic.Item("max"))
    End If   
  End If
  Randomize
  Dim cur : cur = Int(dic.Item("cur"))
  Dim dir : dir = Int(dic.Item("dir"))
  If cur = 0 Then
    cur = Int(Int(dic.Item("wan"))*Rnd)+1
    dir = 0
  End If
  If dir = 0 Then
    dir = Int(3*Rnd)-1
    dic.Item("dir") = dir
  End If
  If Debug Then
    Call out("Current=  "&cur)
    Call out("Direction="&dir)
  End If     
  Dim tol : tol = Int(dic.Item("tol"))
  Dim lst : lst = Int(dic.Item("lst"))
  Dim sql : sql = "SELECT Songs.ID FROM Songs WHERE Songs.ID NOT IN (0"
  Dim list : Set list = SDB.Player.CurrentSongList
  Dim itm : Set itm = Nothing
  Dim i : i = 0
  Dim j : j = 0
  If list.Count > lst Then
    j = list.Count-lst-1
  End If
  For i = j To list.Count-1
    Set itm = list.Item(i)
    sql = sql&","&itm.ID
  Next   
  sql = sql&") "&dic.Item("sql")
  While (tol < 100)
    Dim sql2 : sql2 = ""
    If Not (itm Is Nothing) Then
      If Debug Then
        Call out("Cur BPM=  "&itm.BPM)
      End If       
      If itm.BPM < 0 Then
        sql2 = sql2&" AND Songs.BPM>-1"
      Else
        Dim bpm : bpm = itm.BPM+Int(dir*(tol/2)) 'apply direction
        If tol = 0 Then
          sql2 = sql2&" AND Songs.BPM="&bpm
        Else
          sql2 = sql2&" AND Songs.BPM>="&(bpm-tol)&" AND Songs.BPM<="&(bpm+(tol/2))
        End If   
      End If
    End If
   If Int(dic.Item("unp")) = 1 Then
      sql2 = sql&sql2&" ORDER BY PlayCounter,Random() LIMIT 1"   
   Else
     sql2 = sql&sql2&" ORDER BY Random() LIMIT 1"
   End If
    If Debug Then
      Call out("#"&sql2)
    End If                 
    Set iter = SDB.Database.OpenSQL(sql2)
    If iter.EOF Then
      If itm.BPM < 0 Then
        tol = 100
      Else
        tol = tol+Int(dic.Item("tol")) 'increase tolerance
      End If
    Else
      Set iter = SDB.Database.QuerySongs("Songs.ID="&iter.ValueByIndex(0))
      Set GenerateNewTrack = iter.Item
      tol = 100 'exit while
    End If
    Set iter = Nothing
  WEnd
  If GenerateNewTrack Is Nothing Then
   If Int(dic.Item("unp")) = 1 Then
      sql = sql&" ORDER BY PlayCounter,Random() LIMIT 1"   
   Else
     sql = sql&" ORDER BY Random() LIMIT 1"
   End If 
    If Debug Then
      Call out("#"&sql)
    End If                   
    Set iter = SDB.Database.OpenSQL(sql)
    If Not (iter.EOF) Then
      Set iter = SDB.Database.QuerySongs("Songs.ID="&iter.ValueByIndex(0))
      Set GenerateNewTrack = iter.Item
    End If
    Set iter = Nothing
  End If
  If Debug Then
    If GenerateNewTrack Is Nothing Then
      Call out(">Nothing")
    Else
      Call out(">"&GenerateNewTrack.ID&"="&GenerateNewTrack.BPM)
    End If
  End If 
  dic.Item("cur") = cur-1
  Set SDB.Objects("AutoBeatsData") = dic
End Function

Function GetFilterID(Name)
  Dim nam : nam = Replace(Name,"'","''")
  If SDB.Database.OpenSQL("SELECT COUNT(*) FROM Filters WHERE Name='"&nam&"'").ValueByIndex(0) = 0 Then
    FilterName = "- No Filter -"
    SDB.IniFile.StringValue("AdvancedReport","FilterName") = FilterName
    GetFilterID = -1
  Else
    GetFilterID = SDB.Database.OpenSQL("SELECT ID FROM Filters WHERE Name='"&name&"'").ValueByIndex(0)
  End If
End Function

Sub FillDropDownFromArray(DropDown,SourceArray)
  Dim i : i = 0
  For i = 0 To UBound(SourceArray)
    Call DropDown.AddItem(SourceArray(i))
  Next
End Sub

Sub CreateFiltersArray()
  Redim Filters(SDB.Database.OpenSQL("SELECT COUNT(*) FROM Filters").ValueByIndex(0)+1)
  Filters(0) = "- No Filter -"
  Filters(1) = "- Active Filter -"
  Dim i : i = 2
  Dim iter : Set iter = SDB.Database.OpenSQL("SELECT Name FROM Filters ORDER BY Pos")
  Do While Not iter.EOF
    Filters(i) = iter.StringByIndex(0)
    i = i+1
    iter.Next
  Loop
  Set iter = Nothing
End Sub

Function GetFiltersArrayID(Name)
  GetFiltersArrayID = 0
  Dim i : i = 0
  For i = 0 To UBound(Filters)
    If Filters(i) = Name Then
      GetFiltersArrayID = i
      Exit For
    End If
  Next
End Function

Function GetFilterSQL()
  Dim Name : Name = SDB.IniFile.StringValue("AutoBeatsDJ","FilterName")
  Select Case Name
    Case "- No Filter -"
      GetFilterSQL = ""
    Case "- Active Filter -"
      GetFilterSQL = SDB.Database.ActiveFilterQuery
    Case Else
      Dim id : id = GetFilterID(Name)
      If id = -1 Then
        GetFilterSQL = ""
      Else
        GetFilterSQL = SDB.Database.GetFilterQuery(id)
      End If
  End Select
  If Not (GetFilterSQL = "") Then
    GetFilterSQL = "AND "&GetFilterSQL
  End If   
End Function

Sub clear()
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim loc : loc = SDB.TemporaryFolder&"\AutoBeatsDJ.log"
  Dim logf : Set logf = fso.CreateTextFile(loc,True)
  Call logf.Close()
End Sub

Sub out(txt)
  Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim loc : loc = SDB.TemporaryFolder&"\AutoBeatsDJ.log"
  Dim logf : Set logf = fso.OpenTextFile(loc,8,True)
  Call logf.WriteLine(SDB.ToAscii(txt))
  Call logf.Close()
End Sub
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Vyper » Mon Mar 29, 2010 2:27 pm

Can a function be built in for it to ignore tracks without a BPM? Or give you some kind of indication? 'Cause you just know someone is gonna do it and then complain about it. ;)
Stop Button Freak
Vyper
 
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby trixmoto » Mon Mar 29, 2010 2:29 pm

It will only ever select a track which has a BPM value. If the last track in the Now Playing list doesn't have a BPM then it will randomly select any track with a BPM value and then stick to that value. Or is the script behaving in a way you would not expect?
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Vyper » Mon Mar 29, 2010 2:31 pm

Oh, I haven't tried it yet (but I will!). I misunderstood your initial post then. I got the impression if someone selected tracks without a BPM this script would hang up and not work anymore. :oops:
Stop Button Freak
Vyper
 
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby trixmoto » Mon Mar 29, 2010 2:38 pm

Ok, I have added a sentence to the first post which hopefully clarifies this. I was trying to warn that someone with no BPM values at all would have problems.
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Vyper » Tue Mar 30, 2010 5:26 am

Much clearer. Thanks. Image
Stop Button Freak
Vyper
 
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby MusicBringer » Tue Mar 30, 2010 7:17 am

trixmoto wrote:This is a new "Auto DJ" style script which selects tracks based on the BPM (Beats Per Minute).

Umm, I think you'd better instruct me in BPM :oops:
How do I assign BPMs to some of the tracks in My Library.
Thanks,
MediaMonkey user since 2006
MusicBringer
 
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Vyper » Tue Mar 30, 2010 11:29 am

Go here:


Clicky


And get that. Then simply run it and navigate to your music folders. You can do them in batches if you want or do the whole shebang which would probably take quite awhile depending on your music library size.


Then rescan the folders with MM and you're done. :)
Stop Button Freak
Vyper
 
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby MusicBringer » Tue Mar 30, 2010 11:40 am

Hello Vyper, thanks for that :)
Umm, I am a bit nervous with all this - why on earth does the site want my email address before they will allow me to download a Freebie - it is free. Y/N?
And then what will it do to my MP3s and Flacs - cannot say I like the sound of all this tweaking precious music files. :cry:
Perhaps you can clarify things for me please.
MediaMonkey user since 2006
MusicBringer
 
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby trixmoto » Tue Mar 30, 2010 12:34 pm

It is free - I think I downloaded it about 2-3 years ago and have had about that many emails from them since. It analyses your files to calculate the beats per minute and then writes this into the relevant tag so that MM can read the value out of the file. I think you can ask it not to update the tags and just write to a file, but then you'd need another way of importing this into MM. It's been a while, but I certainly analysed a few thousand MP3s without any problems - can't comment on FLACs though.
Download my scripts at trixmoto.net.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Send me BTC: 34VQPVsf9mCeR4nfhFvvBYZqQ7LkqNZ8Mn
Send me LTC: 3P1mzrfbyscdhbxRpXLgKz7tufGAU3SrEG
Send me DOGE: 9xPpYSqgF7P5yQiqvE1VqWb4UjxVCCLFJ6
Check out these great cryptocurrency faucets... BTC / LTC / DOGE
trixmoto
 
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Barton, UK

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby MusicBringer » Tue Mar 30, 2010 4:11 pm

trixmoto, thanks for the reassurance :)
On the recommendation of you MM folk I shall give it a try.
Thanks again,
MediaMonkey user since 2006
MusicBringer
 
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby rrfpacker » Tue Mar 30, 2010 4:58 pm

Please let us know how it turns out. I, too, am a bit concerned with how it works.
rrfpacker
 
Posts: 1037
Joined: Sat Jul 12, 2008 5:47 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Eyal » Tue Mar 30, 2010 6:35 pm

BTW you can download it from other sources. Ex.: http://download.cnet.com/MixMeister-BPM ... 90906.html

I found an interresting list of related BPM software: http://www.mmartins.com/mmartins/bpmdet ... ection.asp
and downloaded Abyssmedia's freeware one, which is supposedly better: http://www.abyssmedia.com/bpmcounter/

I did a comparison test with a downtempo album, "Laika - Good Looking Blues" : http://www.amazon.com/Good-Looking-Blue ... B000026I92

Screenshot:
Image

Using BPM.tapper script for MM ( viewtopic.php?f=2&t=15474 ) I verified the beat accuracy.

Result: All MixMeister BPM data is correct except for track 5 "Good Looking Blues" (140 BPM)... which is correct in Abyssmedia.
Strange...

---------------

Thank you Trixmoto for this useful DJ script.


Eyal :~)
Skins for MediaMonkey: Cafe, Carbon, Helium, Spotify, Zekton. [ Wiki Zone ].
Eyal
 
Posts: 3099
Joined: Sun Jun 26, 2005 9:27 am
Location: Québec

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Vyper » Tue Mar 30, 2010 6:51 pm

MusicBringer wrote:Hello Vyper, thanks for that :)
Umm, I am a bit nervous with all this - why on earth does the site want my email address before they will allow me to download a Freebie - it is free. Y/N?

There's no verification of what you put in those boxes, if you get my meaning. ;)
Stop Button Freak
Vyper
 
Posts: 845
Joined: Tue May 23, 2006 5:53 pm

Re: Auto Beats DJ 1.0 - Created 29/03/2010

Postby Bex » Tue Mar 30, 2010 7:29 pm

Mixshare's Rapid Evolution claims to detect BPM, and it works on FLAC as well:
"Rapid Evolution" is an advanced harmonic music library tool for DJs, designed to be used while you mix. It helps profile your songs by saving important properties, such as the BPM, key, time signature, styles, comments, and more. You can then instantly see which songs are within BPM range, in key harmonically and in similar styles. More importantly, it lets you save comments and information about each individual mix you come up with. It aims to help properly utilizing music knowledge and harmonic mixing theory to create better mixes. Use it to enhance your knowledge of your own music and remember the important details of what you do. The software includes automatic BPM and key detection, as well as tools to determine this information yourself--a BPM tapper and a MIDI keyboard. It also lets you share song and mix information with other DJs. Use it and start evolving! :-)

http://www.mixshare.com/software.html
I haven't tested it yet though.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Bex
 
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Next

Return to Need Help with Addons?

Who is online

Users browsing this forum: No registered users and 18 guests