'Sorts by playcount. Easily modified to sort on other meta data.
x = playlist.getselection()
 
if ubound(x,1) > 1 Then
 Quicksort x, 1, ubound(x,1)
End if
 
quit
 
Sub QuickSort(ByRef vec,loBound,hiBound)
  Dim pivot,loSwap,hiSwap,temp
 
  '== Two items to sort
  if hiBound - loBound = 1 then
    if vec(loBound).playcount > vec(hiBound).playcount then
	SwapPls vec(loBound), vec(hiBound)
    End If
  End If
 
  '== Three or more items to sort
  set pivot = vec(int((loBound + hiBound) / 2))
  SwapPls vec(int((loBound + hiBound) / 2)), vec(loBound)
 
  loSwap = loBound + 1
  hiSwap = hiBound
  
  do
    '== Find the right loSwap
    while loSwap < hiSwap and vec(loSwap).playcount <= pivot.playcount
      loSwap = loSwap + 1
    wend
    '== Find the right hiSwap
    while vec(hiSwap).playcount > pivot.playcount
      hiSwap = hiSwap - 1
    wend
    '== Swap values if loSwap is less then hiSwap
 
    if loSwap < hiSwap then
	SwapPls vec(loSwap), vec(hiSwap)
    End If
  loop while loSwap < hiSwap
  
  SwapPls vec(loBound), vec(hiSwap)
  SwapPls pivot, vec(hiSwap)
 
  '== Recursively call function .. the beauty of Quicksort
  '== 2 or more items in first section
  if loBound < (hiSwap - 1) then Call QuickSort(vec,loBound,hiSwap-1)
  '== 2 or more items in second section
  if hiSwap + 1 < hibound then Call QuickSort(vec,hiSwap+1,hiBound)
 
End Sub  'QuickSort
 
'A swap that also changes the .position property of a mediaitem
'And positions in the playlist
Sub SwapPls (ByRef val1, ByRef val2)
	tmpos  = val1.position
	tmpos2 = val2.position
 
	'Update new positions
	val1.position   = tmpos2
	val2.position   = tmpos
 
	'Swap items
	set temp   = val2
	set val2   = val1
	set val1   = temp
 
	'Swap positions in the playlist
	playlist.swapindex tmpos2, tmpos
End Sub
 
examples/general/sort_items.txt · Last modified: 2006/11/06 15:44
 
Recent changes RSS feed Creative Commons License Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Music Plugins