LibraryPanes: Library panes like these in Winamp, iRiver, ..

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

LibraryPanes: Library panes like these in Winamp, iRiver, ..

Post by Steegy »

Functionality now built-in in MediaMonkey.
This script should not be necessary anymore.


:: LibraryPanes' own forum post.

Note: MediaMonkey v3 and above will have something similar included natively.

Preview version: Only works without problems on MM 2.5.3 RC4 or newer.

If anyone is getting error messages about line 184 or 192, send a blank email to fixlp@trixmoto.net and you should recieve the fix instantly!
(This address is not checked and the emails are deleted, an auto response is sent with the fix!)

Description:

The LibraryPanes script adds a dockable panel with Library Panes (browse library like in Winamp, iTunes, JRiverMC, ...) to the user interface.

The panel consists of a Custom pane, an Artists and an Albums pane. The custom pane's function can be chooses between: Genre, Tempo, Mood, Occasion, Quality. It can be toggled on or off. The panel can be closed/reopened (e.g. menu View item), docked, ... and all controls automaticly resize.
A top tree node "Library Panes" is added and remembers the previous browse position.

A screenshot is added at the end of the post.

The script needs MediaMonkey version 2.5.3 or above.


Installing manually:

The script below is an auto-script. The Faq "How do I install scripts?" http://faq.mediamonkey.com/index.php?ac ... artlang=en explains how to install it.
Quicky: Copy the code below to a plain text file (e.g. using NotePad) and save it as LibraryPanes.vbs. Put that file un MediaMonkey's Scripts\Auto folder and (re)start MediaMonkey.


The script consists of 1 standalone script file ("LibraryPanes.vbs")

LibraryPanes.vbs (for the Scripts\Auto folder)

Code: Select all

'========================================================================== 
' 
' MediaMonkey Script 
' 
' NAME: LibraryPanes v0.1.1
' DESCRIPTION: 
'  Adds a dockable panel with Library Panes (browse library like in Winamp, iTunes, JRiverMC, ...) to the user interface.
'   The panel consists of a Custom pane, an Artists and an Albums pane. The custom pane's function can be chooses between:
'    Genre, Tempo, Mood, Occasion, Quality. It can be toggled on or off.
'  The panel can be closed/reopened (e.g. menu View item), docked, ... and all controls automaticly resize.
'  A top tree node "Library Panes" is added and remembers the previous browse position
' 
' AUTHOR: Steegy aka RC (Ruben Castelein)
' DATE  : 04/06/2006
' UPDATE: 05/06/2006
' 
' INSTALL: 
' - Copy script to MediaMonkey's "Scripts\Auto" folder
' 
' The script needs MediaMonkey version 2.5.3 or above. 
' 
'========================================================================== 
'>> ForumURL:
'>> ScriptName: LibraryPanes 
'>> VersionNumber: 0.1 
'>> Author: Steegy aka RC (Ruben Castelein)
'>>>>EndOfProperties 


' By design, selecting genres, artists and albums don't go to the corresponding nodes in the main tree
' Reasons are speed, flexibility, consistency, separate "library panes" node for easy memory of previous selection (like the search node, so e.g. also is saved in the tree history) and no useless mess with the tree node
' For more info, just ask me


' TODO:
' =====
'  - Add option panel (to set the above options + to enable/disable "EnsureVisible")
'  - Add option to not automaticly fill the tracks list (e.g. only fill it with explicit click in the albums pane)
'  - Add ability to use Alt+Enter, Shift+Ctrl+Enter, Ctrl+Enter on the selected item
'  - Add option to only show accessible tracks
'  - Update listviews when tags have been changed (subscribe to SDB's OnTrackProperties event)
'  - Add option to ignore prefixes like "The"
'  - Add option to only show accessible artists/genres
'  - Make entries editable (Now they "seem" editable, because of an issue with the listview control. They are not editable.)

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


'*****************************************************
'****             GLOBAL DECLARATIONS             ****
'*****************************************************

Option Explicit

'Dim LV : Set LV = CreateObject("COMCTL.ListViewCtrl")    'Only necessary for help functions


Const ForegroundColor = &H000000
Const BackgroundColor = &HEFEFEF


Dim TreeNode, ViewMenuItem, Panel
Dim lvCustom, lvArtists, lvAlbums
Dim chkShowCustomPane, ddnCustomPaneKind
Dim lblArtists, lblAlbums

Dim CustomPaneVisible, CustomPaneKind

Dim PreviousCustomItem, PreviousArtistsItem, PreviousAlbumsItem
Dim LastSelection


' ListView Constants
Const lvwReport = 3        'Show listview in "Report" view
Const lvwAutomatic = 0     'Only allow Automatic editing of labels (don't allow manual editing)


' Alignment constants (alignment of the control in its parent control)
Const alNone = 0	 'No alignment is applied
Const alTop = 1 	 'Control is aligned to the top
Const alBottom = 2	 'Control is aligned to the bottom
Const alLeft = 3	 'Control is aligned to the left
Const alRight = 4	 'Control is aligned to the right
Const alClient = 5	 'Control completely covers its parent


' Anchors constants (control to which borders of the parent control the control is sticked)
Const akLeft = 1 	 'Distance from the left border of the parent is constant
Const akTop = 2		 'Distance from the top border of the parent is constant
Const akRight = 4	 'Distance from the right border of the parent is constant
Const akBottom = 8	 'Distance from the bottom border of the parent is constant


'*****************************************************
'****                 ENTRY POINT                 ****
'*****************************************************

Sub OnStartup

    Set PreviousArtistsItem = Nothing
    Set PreviousAlbumsItem = Nothing
    LastSelection = " "

	Call Initialise_LicenseFix
	Call Initialise_TreeNode
	Call Initialise_Panel    'Create the Panel before creating the ViewMenuItem (the ViewMenuItem Checked state depends on the Panel's Visible state)
    Call Initialise_ViewMenuItem
	Call Initialise_lvCustom
	Call Initialise_lvArtists
	Call Initialise_lvAlbums
	Call Initialise_chkShowCustomPane
	Call Initialise_ddnCustomPaneKind


    If CustomPaneVisible Then
        Call FilllvCustom
    End If
    

    lvCustom.Interf.ListItems(1).Selected = True
    Call DoCustom
    
    
    Call OnPanelResize(Panel)
    If SDB.IniFile.StringValue("LibraryPanes", "PanelVisible") = "False" Then
	    Panel.Common.Visible = False
	Else
	    Panel.Common.Visible = True
	End If
	Script.RegisterEvent Panel.Common, "OnResize", "OnPanelResize"
	
	Script.RegisterEvent SDB, "OnChangedSelection", "OnChangedSelection"
	
End Sub


'*****************************************************
'****            INITIALISATION METHODS           ****
'*****************************************************

Sub Initialise_LicenseFix



End Sub


Sub Initialise_TreeNode

    Set TreeNode = SDB.MainTree.CreateNode
    Set SDB.Objects("LibraryPanes_TreeNode") = TreeNode
    TreeNode.Caption = "Library Panes"
    TreeNode.IconIndex = 46    
    SDB.MainTree.AddNode SDB.MainTree.Node_MyComputer, TreeNode, 1
    
	Script.RegisterEvent TreeNode, "OnFillTracks", "OnFillTracks"
	

End Sub


Sub Initialise_Panel

    Set Panel = SDB.UI.NewDockablePersistentPanel("LibraryPanes_Panel")
	Set SDB.Objects("LibraryPanes_Panel") = Panel
	If Panel.IsNew Then
		Panel.DockedTo = 2
		Panel.Common.Width = 430
		Panel.Common.Height = 30
	End If
	Panel.Caption = "LibraryPanes"
		
	Script.RegisterEvent Panel, "OnClose", "OnPanelClose"
	
End Sub


Sub Initialise_ViewMenuItem

	Set ViewMenuItem = SDB.UI.AddMenuItem(SDB.UI.Menu_View, 1, -3)
	ViewMenuItem.Caption = "Show Library Panes"
	ViewMenuItem.Checked = Panel.Common.Visible
	ViewMenuItem.Hint = "Show the extra library panes"
	
	Script.RegisterEvent ViewMenuItem, "OnClick", "MIClick"

End Sub


Sub Initialise_lvCustom

	Set lvCustom = SDB.UI.NewActiveX(Panel, "COMCTL.ListViewCtrl")
    lvCustom.Common.Left = 0
    lvCustom.Common.Top = 20
    'lvCustom.Common.Width = Panel.Common.Width / 2    'Also automatcily set by the panel's OnResize event handler
    lvCustom.Common.Height = Panel.Common.ClientHeight - 20
    lvCustom.Common.Anchors = 1+2+8

    lvCustom.Interf.View = lvwReport
    lvCustom.Interf.LabelEdit = lvwAutomatic
    lvCustom.Interf.HideSelection = False
    lvCustom.Interf.HideColumnHeaders = True
    lvCustom.Interf.BackColor = BackgroundColor
    lvCustom.Interf.ForeColor = ForegroundColor
    
    Call lvCustom.Interf.ColumnHeaders.Add(, , "Custom", lvCustom.Common.Width - 50)
    
    Call lvCustom.Interf.ListItems.Add( , , "<< All >>")
    lvCustom.Interf.ListItems(1).Tag = "ALL"

	Script.RegisterEvent lvCustom.Interf, "ItemClick", "OnCustomSelect"

End Sub


Sub Initialise_lvArtists

    Set lblArtists = CreateLabel(Panel, "Artists", 0, 5, 50, 20)
    lblArtists.Common.Anchors = 2
    
	Set lvArtists = SDB.UI.NewActiveX(Panel, "COMCTL.ListViewCtrl")
    'lvArtists.Common.Left = 0    'Also automatcily set by the panel's OnResize event handler
    lvArtists.Common.Top = 20
    'lvArtists.Common.Width = Panel.Common.Width / 2    'Also automatcily set by the panel's OnResize event handler
    lvArtists.Common.Height = Panel.Common.ClientHeight - 20
    lvArtists.Common.Anchors = 2+8

    lvArtists.Interf.View = lvwReport
    lvArtists.Interf.LabelEdit = lvwAutomatic
    lvArtists.Interf.HideSelection = False
    lvArtists.Interf.HideColumnHeaders = True
    lvArtists.Interf.BackColor = BackgroundColor
    lvArtists.Interf.ForeColor = ForegroundColor
    
    Call lvArtists.Interf.ColumnHeaders.Add(, , "Artists", lvArtists.Common.Width - 50)
        
	Script.RegisterEvent lvArtists.Interf, "ItemClick", "OnArtistSelect"

End Sub


Sub Initialise_lvAlbums

    Set lblAlbums = CreateLabel(Panel, "Albums", 0, 5, 50, 20)
    lblAlbums.Common.Anchors = 2

	Set lvAlbums = SDB.UI.NewActiveX(Panel, "COMCTL.ListViewCtrl")
    'lvAlbums.Common.Left = lvArtists.Common.Width
    lvAlbums.Common.Top = 20
    'lvAlbums.Common.Width = lvArtists.Common.Width - 15    'Also automatcily set by the panel's OnResize event handler
    lvAlbums.Common.Height = Panel.Common.ClientHeight - 20
    lvAlbums.Common.Anchors = 2+8

    lvAlbums.Interf.View = lvwReport
    lvAlbums.Interf.LabelEdit = lvwAutomatic
    lvAlbums.Interf.HideSelection = False
    lvAlbums.Interf.HideColumnHeaders = True
    lvAlbums.Interf.BackColor = BackgroundColor
    lvAlbums.Interf.ForeColor = ForegroundColor

    Call lvAlbums.Interf.ColumnHeaders.Add(, , "Albums", lvAlbums.Common.Width - 50)
	
	Script.RegisterEvent lvAlbums.Interf, "ItemClick", "OnAlbumSelect"

End Sub


Sub Initialise_chkShowCustomPane

    Set chkShowCustomPane = CreateCheckBox(Panel, "Xtra", 0, 1, 40, 20, "chkShowCustomPane")
    
    If SDB.IniFile.StringValue("LibraryPanes", "CustomPaneVisible") = "" Then
        CustomPaneVisible = False
    Else
        CustomPaneVisible = SDB.IniFile.StringValue("LibraryPanes", "CustomPaneVisible")
    End If
    chkShowCustomPane.Checked = CustomPaneVisible
    lvCustom.Common.Visible = CustomPaneVisible
    
	Script.RegisterEvent chkShowCustomPane.Common, "OnClick", "OnchkShowCustomPaneClick"

End Sub


Sub Initialise_ddnCustomPaneKind
	
    Set ddnCustomPaneKind = CreateDropDown(Panel, 0, 0, 200, 20, "ddnCustomPaneKind")
    ddnCustomPaneKind.Style = csDropDownList
    Dim CustomList : CustomList = Array("Genres", "Tempo", "Mood", "Occasion", "Quality")
    Call FillDropDownFromArray(ddnCustomPaneKind, CustomList)
    
    CustomPaneKind = SDB.IniFile.StringValue("LibraryPanes", "CustomPaneKind")
    If CustomPaneKind = "" Then
        CustomPaneKind = "Genres"
	End If
    Call SelectDropDownText(ddnCustomPaneKind, CustomPaneKind)
	ddnCustomPaneKind.Common.Visible = CustomPaneVisible
    
	Script.RegisterEvent ddnCustomPaneKind, "OnSelect", "OnddnCustomPaneKindSelect"

End Sub


'*****************************************************
'****            EVENT HANDLING METHODS           ****
'*****************************************************

Sub MIClick(ViewMenuItem) 

	ViewMenuItem.Checked = Not ViewMenuItem.Checked
	Panel.Common.Visible = ViewMenuItem.Checked
	SDB.IniFile.StringValue("LibraryPanes", "PanelVisible") = ViewMenuItem.Checked

End Sub


Sub OnddnCustomPaneKindSelect(ddnCustomPaneKind)

	Call SDB.ProcessMessages
	
    CustomPaneKind = ddnCustomPaneKind.Text
    SDB.IniFile.StringValue("LibraryPanes", "CustomPaneKind") = CustomPaneKind
    
    Call lvCustom.Interf.ListItems.Clear
    Call lvCustom.Interf.ListItems.Add( , , "<< All >>")
    lvCustom.Interf.ListItems(1).Tag = "ALL"
    Call FilllvCustom
    Call DoCustom

End Sub


Sub OnchkShowCustomPaneClick(chkShowCustomPane)
	
	Call SDB.ProcessMessages
	
    CustomPaneVisible = chkShowCustomPane.Checked
    SDB.IniFile.StringValue("LibraryPanes", "CustomPaneVisible") = CustomPaneVisible
    ddnCustomPaneKind.Common.Visible = CustomPaneVisible
    
    lvCustom.Common.Visible = CustomPaneVisible
    Call OnPanelResize(Panel)

    If lvCustom.Interf.ListItems.Count = 1 Then
        Call FilllvCustom
    End If

    lvCustom.Interf.ListItems(1).Selected = True
    If PreviousCustomItem Is Nothing Then

        Call DoCustom
    Else
        If lvCustom.Interf.SelectedItem.Tag <> PreviousCustomItem.Tag Then

            Call DoCustom
        End If
    End If

End Sub


Sub OnPanelClose(Panel) 
    
    ViewMenuItem.Checked = False
	SDB.IniFile.StringValue("LibraryPanes", "PanelVisible") = "False"

End Sub


Sub OnFillTracks(TreeNode)

    Call SDB.ProcessMessages
    
    If Not Panel.Common.Visible Then
	    Panel.Common.Visible = True
	    ViewMenuItem.Checked = True
	    SDB.IniFile.StringValue("LibraryPanes", "PanelVisible") = "True"
    End If

    Select Case LastSelection
        Case "Custom": Call DoCustom
        Case "Artists": Call DoArtists
        Case "Albums", "": Call DoAlbums
        Case " ":
            Call DoAlbums
            If Not lvArtists.Interf.SelectedItem Is Nothing Then
                lvArtists.Interf.SelectedItem.Selected = True
                Call lvArtists.Interf.SelectedItem.EnsureVisible
            End If
            If Not lvAlbums.Interf.SelectedItem Is Nothing Then
                lvAlbums.Interf.SelectedItem.Selected = True
                Call lvAlbums.Interf.SelectedItem.EnsureVisible
            End If
    End Select

End Sub


Sub OnCustomSelect(ListItem)

    Call SDB.ProcessMessages
    
    If EqualNodes(SDB.MainTree.CurrentNode, TreeNode) Then
        If Not PreviousCustomItem Is Nothing Then
            If lvCustom.Interf.SelectedItem.Tag = PreviousCustomItem.Tag Then Exit Sub
        End If
        LastSelection = "Custom"
        Call SDB.MainTracksWindow.Refresh
    Else
        LastSelection = "Custom"
        Set SDB.MainTree.CurrentNode = TreeNode
    End If

End Sub


Sub OnArtistSelect(ListItem)

    Call SDB.ProcessMessages
    
    If EqualNodes(SDB.MainTree.CurrentNode, TreeNode) Then
        If Not PreviousArtistsItem Is Nothing Then
            If lvArtists.Interf.SelectedItem.Tag = PreviousArtistsItem.Tag Then Exit Sub
        End If
        LastSelection = "Artists"
        Call SDB.MainTracksWindow.Refresh
    Else
        LastSelection = "Artists"
        Set SDB.MainTree.CurrentNode = TreeNode
    End If
            
End Sub


Sub OnAlbumSelect(ListItem)

    Call SDB.ProcessMessages
    
    If EqualNodes(SDB.MainTree.CurrentNode, TreeNode) Then
        If Not PreviousAlbumsItem Is Nothing Then
            If lvAlbums.Interf.SelectedItem.Tag = PreviousAlbumsItem.Tag Then Exit Sub
        End If
        LastSelection = "Albums"
        Call SDB.MainTracksWindow.Refresh
    Else
        LastSelection = "Albums"
        Set SDB.MainTree.CurrentNode = TreeNode
    End If
    
End Sub


Sub OnPanelResize(Panel)

    If Panel.DockedTo = 0 Then Exit Sub    ' Don't do anything when the panel is being (un)docked

    Dim NumberOfPanes
    If CustomPaneVisible Then
        NumberOfPanes = 3
    Else
        NumberOfPanes = 2
    End If

    Dim PaneWidth : PaneWidth = Panel.Common.ClientWidth / NumberOfPanes

    lvCustom.Common.Width = PaneWidth
    If CustomPaneVisible Then
        lvArtists.Common.Left = PaneWidth
    Else
        lvArtists.Common.Left = 0
    End If
    lvArtists.Common.Width = PaneWidth
    lvAlbums.Common.Width = (Panel.Common.ClientWidth - (lvArtists.Common.Left + PaneWidth))
    lvAlbums.Common.Left = lvArtists.Common.Left + PaneWidth
    
    Dim HeaderWidth : HeaderWidth = Cond(0 > PaneWidth - 45, 0, PaneWidth - 45)
    lvCustom.Interf.ColumnHeaders(1).Width = HeaderWidth
    lvArtists.Interf.ColumnHeaders(1).Width = HeaderWidth
    lvAlbums.Interf.ColumnHeaders(1).Width = HeaderWidth
    
    ddnCustomPaneKind.Common.Width = lvCustom.Common.Width
    lblArtists.Common.Width = lvArtists.Common.Width - 3
    lblArtists.Common.Left = lvArtists.Common.Left + 5
    lblAlbums.Common.Width = lvAlbums.Common.Width - 3
    lblAlbums.Common.Left = lvAlbums.Common.Left + 5
    chkShowCustomPane.Common.Left = Panel.Common.ClientWidth - chkShowCustomPane.Common.Width

End Sub


Sub OnChangedSelection
    
    If Not EqualNodes(SDB.MainTree.CurrentNode, TreeNode) Then
        Call DeselectListViews
    End If
    
End Sub


'*****************************************************
'****                WORKER METHODS               ****
'*****************************************************

Sub DoCustom

    Call lvArtists.Interf.ListItems.Clear
    Call lvAlbums.Interf.ListItems.Clear
    Call SDB.ProcessMessages
    
    Call lvArtists.Interf.ListItems.Add( , , "<< All >>")
    lvArtists.Interf.ListItems(1).Selected = True
    
    Dim RecordCount
    If CustomTag = "ALL" Then
        RecordCount = AddItemsFromQuery(lvArtists, "" _
            + "SELECT Artist, ID " _
            + "FROM Artists " _
            + "ORDER BY Artist")
    Else
        If CustomPaneKind = "Genres" Then
            RecordCount = AddItemsFromQuery(lvArtists, "" _
                + "SELECT DISTINCTROW Artists.Artist, Artists.ID " _
                + "FROM Artists INNER JOIN (Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre) ON Artists.ID = Songs.IDArtist " _
                + "WHERE Genres.IDGenre=" + CustomTag + " " _
                + "ORDER BY Artists.Artist")
        Else
            RecordCount = AddItemsFromQuery(lvArtists, "" _
                + "SELECT DISTINCT Artists.Artist, Artists.ID " _
                + "FROM Lists INNER JOIN ((Artists INNER JOIN Songs ON Artists.ID = Songs.IDArtist) INNER JOIN AddSongInfoInt ON Songs.ID = AddSongInfoInt.IDSong) ON Lists.ID = AddSongInfoInt.IntData " _
                + "WHERE Lists.ID=" + CustomTag + " AND AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind))
        End If
    End If
    
    lvArtists.Interf.ListItems(1).Text = "<< All (" & RecordCount & ") >>"
    lvArtists.Interf.ListItems(1).Tag = "ALL"
    
    Set PreviousCustomItem = lvCustom.Interf.SelectedItem
    Set PreviousArtistsItem = lvArtists.Interf.SelectedItem
    Set PreviousAlbumsItem = lvAlbums.Interf.SelectedItem
    
    Call SDB.ProcessMessages
    Call DoArtists
            
End Sub


Sub DoArtists

    Call lvAlbums.Interf.ListItems.Clear
    Call SDB.ProcessMessages
    
    Call lvAlbums.Interf.ListItems.Add( , , "<< All >>")
    lvAlbums.Interf.ListItems(1).Selected = True

    Dim RecordCount
    If CustomTag = "ALL" Then
        If ArtistsTag = "ALL" Then
            RecordCount = AddItemsFromQuery(lvAlbums, "" _
                + "SELECT Album, ID " _
                + "FROM Albums " _
                + "ORDER BY Album")
        Else
            RecordCount = AddItemsFromQuery(lvAlbums, "" _
                + "SELECT DISTINCTROW Albums.Album, Albums.ID " _
                + "FROM (Albums INNER JOIN Songs ON Albums.ID = Songs.IDAlbum) INNER JOIN Artists ON Songs.IDArtist = Artists.ID " _
                + "WHERE Artists.ID=" + ArtistsTag + " " _
                + "ORDER BY Albums.Album")
        End If
    Else
        If CustomPaneKind = "Genres" Then
            If ArtistsTag = "ALL" Then
                RecordCount = AddItemsFromQuery(lvAlbums, "" _
                    + "SELECT DISTINCTROW Albums.Album, Albums.ID " _
                    + "FROM Albums INNER JOIN (Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre) ON Albums.ID = Songs.IDAlbum " _
                    + "WHERE Genres.IDGenre=" + CustomTag + " " _
                    + "ORDER BY Albums.Album")
            Else
                RecordCount = AddItemsFromQuery(lvAlbums, "" _
                    + "SELECT DISTINCTROW Albums.Album, Albums.ID " _
                    + "FROM Artists INNER JOIN (Albums INNER JOIN (Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre) ON Albums.ID = Songs.IDAlbum) ON Artists.ID = Songs.IDArtist " _
                    + "WHERE (Genres.IDGenre=" + CustomTag + " AND Artists.ID=" + ArtistsTag + ") " _
                    + "ORDER BY Albums.Album")
            End If
        Else
            If ArtistsTag = "ALL" Then
                RecordCount = AddItemsFromQuery(lvAlbums, "" _
                    + "SELECT DISTINCT Albums.Album, Albums.ID " _
                    + "FROM Albums INNER JOIN (Lists INNER JOIN (AddSongInfoInt INNER JOIN Songs ON AddSongInfoInt.IDSong = Songs.ID) ON Lists.ID = AddSongInfoInt.IntData) ON Albums.ID = Songs.IDAlbum " _
                    + "WHERE AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind) & " AND Lists.ID=" + CustomTag)
            Else
                RecordCount = AddItemsFromQuery(lvAlbums, "" _
                    + "SELECT DISTINCT Albums.Album, Albums.ID " _
                    + "FROM (Albums INNER JOIN (Artists INNER JOIN Songs ON Artists.ID = Songs.IDArtist) ON (Songs.IDAlbum = Albums.ID)) INNER JOIN (Lists INNER JOIN AddSongInfoInt ON Lists.ID = AddSongInfoInt.IntData) ON Songs.ID = AddSongInfoInt.IDSong " _
                    + "WHERE Artists.ID=" + ArtistsTag + " AND AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind) & " AND Lists.ID=" + CustomTag)
            End If
        End If
    End If
    
    lvAlbums.Interf.ListItems(1).Text = "<< All (" & RecordCount & ") >>"
    lvAlbums.Interf.ListItems(1).Tag = "ALL"
    
    Set PreviousArtistsItem = lvArtists.Interf.SelectedItem
    Set PreviousAlbumsItem = lvAlbums.Interf.SelectedItem
    
    Call SDB.ProcessMessages
    Call DoAlbums
    
End Sub


Sub DoAlbums

    If lvAlbums.Interf.SelectedItem Is Nothing Then Exit Sub
    Call SDB.ProcessMessages

    If CustomTag = "ALL" Then
        If ArtistsTag = "ALL" Then
            If AlbumsTag = "ALL" Then
                Call SDB.MainTracksWindow.AddTracksFromQuery("")
            Else
                Call SDB.MainTracksWindow.AddTracksFromQuery("" _
                    + "AND Albums.ID=" + AlbumsTag)
            End If
        Else
            If AlbumsTag = "ALL" Then
                Call SDB.MainTracksWindow.AddTracksFromQuery("" _
                    + "AND Artists.ID=" + ArtistsTag)
            Else
                Call SDB.MainTracksWindow.AddTracksFromQuery("" _
                    + "AND Artists.ID=" + ArtistsTag + " AND Albums.ID=" + AlbumsTag)
            End If
        End If
    Else
        If CustomPaneKind = "Genres" Then
            If ArtistsTag = "ALL" Then
                If AlbumsTag = "ALL" Then
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT Songs.ID " _
                        + "FROM Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre " _
                        + "WHERE Genres.IDGenre=" + CustomTag)
                Else
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT Songs.ID " _
                        + "FROM (Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre) INNER JOIN Albums ON Songs.IDAlbum = Albums.ID " _
                        + "WHERE (Genres.IDGenre=" + CustomTag + " AND Albums.ID=" + AlbumsTag + ")")
                End If
            Else
                If AlbumsTag = "ALL" Then
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT Songs.ID " _
                        + "FROM Artists INNER JOIN (Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre) ON Artists.ID = Songs.IDArtist " _
                        + "WHERE (Genres.IDGenre=" + CustomTag + " AND Artists.ID=" + ArtistsTag + ")")
                Else
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT Songs.ID " _
                        + "FROM (Artists INNER JOIN (Genres INNER JOIN Songs ON Genres.IDGenre = Songs.Genre) ON Artists.ID = Songs.IDArtist) INNER JOIN Albums ON Songs.IDAlbum = Albums.ID " _
                        + "WHERE (Genres.IDGenre=" + CustomTag + " AND Artists.ID=" + ArtistsTag + " AND Albums.ID=" + AlbumsTag + ")")
                End If
            End If
        Else
            If ArtistsTag = "ALL" Then
                If AlbumsTag = "ALL" Then                      
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT DISTINCT Songs.ID " _
                        + "FROM Lists INNER JOIN (AddSongInfoInt INNER JOIN Songs ON AddSongInfoInt.IDSong = Songs.ID) ON Lists.ID = AddSongInfoInt.IntData " _
                        + "WHERE AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind) & " AND Lists.ID=" + CustomTag)
                Else
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT DISTINCT Songs.ID " _
                        + "FROM Albums INNER JOIN (Lists INNER JOIN (AddSongInfoInt INNER JOIN Songs ON AddSongInfoInt.IDSong = Songs.ID) ON Lists.ID = AddSongInfoInt.IntData) ON Albums.ID = Songs.IDAlbum " _
                        + "WHERE AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind) & " AND Albums.ID=" + AlbumsTag + " AND Lists.ID=" + CustomTag)
                End If
            Else
                If AlbumsTag = "ALL" Then
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT Songs.ID " _
                        + "FROM Artists INNER JOIN (Albums INNER JOIN (Lists INNER JOIN (AddSongInfoInt INNER JOIN Songs ON AddSongInfoInt.IDSong = Songs.ID) ON Lists.ID = AddSongInfoInt.IntData) ON Albums.ID = Songs.IDAlbum) ON (Artists.ID = Songs.IDArtist) " _
                        + "WHERE AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind) & " AND Lists.ID=" + CustomTag + " AND Artists.ID=" + ArtistsTag)
                Else
                    Call AddTracksFromQueryAdvanced("" _
                        + "SELECT Songs.ID " _
                        + "FROM (Albums INNER JOIN (Artists INNER JOIN Songs ON Artists.ID = Songs.IDArtist) ON (Songs.IDAlbum = Albums.ID)) INNER JOIN (Lists INNER JOIN AddSongInfoInt ON Lists.ID = AddSongInfoInt.IntData) ON Songs.ID = AddSongInfoInt.IDSong " _
                        + "WHERE Albums.ID=" + AlbumsTag + " AND Artists.ID=" + ArtistsTag + " AND AddSongInfoInt.DataType=1010" & GetIDListType(CustomPaneKind) & " AND Lists.ID=" + CustomTag)
                End If
            End If
        End If
    End If
    
    Set PreviousAlbumsItem = lvAlbums.Interf.SelectedItem
    Call SDB.ProcessMessages
    
    LastSelection = " "
    
End Sub


Function CustomTag
    CustomTag = lvCustom.Interf.SelectedItem.Tag
End Function
Function ArtistsTag
    ArtistsTag = lvArtists.Interf.SelectedItem.Tag
End Function
Function AlbumsTag
    AlbumsTag = lvAlbums.Interf.SelectedItem.Tag
End Function

Function CustomTextDQ
    CustomTextDQ = DoubleUpSingleQuotes(lvCustom.Interf.SelectedItem.Text)
End Function
Function ArtistsTextDQ
    ArtistsTextDQ = DoubleUpSingleQuotes(lvArtists.Interf.SelectedItem.Text)
End Function
Function AlbumsTextDQ
    AlbumsTextDQ = DoubleUpSingleQuotes(lvAlbums.Interf.SelectedItem.Text)
End Function


Function AddItemsFromQuery(ListView, FullQuery)

    AddItemsFromQuery = 0
    
    Dim Iter : Set Iter = SDB.Database.OpenSQL(FullQuery)
    Do While Not Iter.EOF
        Call ListView.Interf.ListItems.Add(, , Cond(Iter.StringByIndex(0) <> "", Iter.StringByIndex(0), "<< Empty >>"))
        ListView.Interf.ListItems(AddItemsFromQuery + 2).Tag = Iter.StringByIndex(1)
        Iter.Next
        AddItemsFromQuery = AddItemsFromQuery + 1
    Loop

End Function


Sub AddTracksFromQueryAdvanced(FullQuery)

    Call SDB.MainTracksWindow.AddTracksFromQuery("AND Songs.ID IN (" & FullQuery & ")")

End Sub


Sub FilllvCustom

    Dim RecordCount
    If CustomPaneKind = "Genres" Then
        RecordCount = AddItemsFromQuery(lvCustom, "" _
            + "SELECT DISTINCTROW Genres.GenreName, Genres.IDGenre " _
            + "FROM Songs INNER JOIN Genres ON Songs.Genre = Genres.IDGenre " _
            + "ORDER BY GenreName")
    Else
        RecordCount = AddItemsFromQuery(lvCustom, "" _
            + "SELECT Lists.TextData, Lists.ID " _
            + "FROM Lists " _
            + "WHERE Lists.IDListType=" & GetIDListType(CustomPaneKind) & " " _
            + "ORDER BY Lists.TextData")
    End If

    lvCustom.Interf.ListItems(1).Text = "<< All (" & RecordCount & ") >>"
    
    'Call lvArtists.Interf.ListItems.Clear
    'Call lvAlbums.Interf.ListItems.Clear
    Call SDB.ProcessMessages

End Sub


Function GetIDListType(Kind)

    Select Case Kind
        Case "Tempo": GetIDListType = 1
        Case "Mood": GetIDListType = 2
        Case "Occasion": GetIDListType = 3
        Case "Quality": GetIDListType = 4
    End Select
    
End Function


Sub DeselectListViews

    If Not lvArtists.Interf.SelectedItem Is Nothing Then
        lvArtists.Interf.SelectedItem.Selected = False
    End If
    If Not lvAlbums.Interf.SelectedItem Is Nothing Then
        lvAlbums.Interf.SelectedItem.Selected = False
    End If
        
End Sub


'*****************************************************
'****           GENERAL UTILITY METHODS           ****
'*****************************************************

Function EqualNodes(Node1, Node2)

    EqualNodes = False
    
    If Not Node1 Is Nothing Then
        If Not Node2 Is Nothing Then
            If Node1.NodeType = Node2.NodeType Then
                If Node1.Caption = Node2.Caption Then
                    EqualNodes = True
                End If
            End If
        End If
    End If
    
End Function


Function Cond(Test, ResultTrue, ResultFalse)

  If Test Then
    Cond = ResultTrue
  Else
    Cond = ResultFalse
  End If

End Function


Function DoubleUpSingleQuotes(strInput)

    DoubleUpSingleQuotes = Replace(strInput, "'", "''")
    
End Function


'*****************************************************
'****          CONTROLS UTILITY METHODS           ****
'*****************************************************

' Most methods are taken from "Utility_Controls.vbs" (see Utility Scripts on http://www.mediamonkey.com/forum/viewtopic.php?t=7980)


' DropDown Style constants
Const csDropDown = 0 	 'DropDown can be edited
Const csDropDownList = 2 'DropDown cannot be edited (user can only select from a list of values)


Function CreateLabel(Owner, Caption, X, Y, Width, Height)

    Set CreateLabel = SDB.UI.NewLabel(Owner)
    CreateLabel.Caption = Caption
    CreateLabel.Common.SetRect X, Y, Width, Height

End Function


Function CreateCheckBox(Owner, Caption, X, Y, Width, Height, ControlName)

    Set CreateCheckBox = SDB.UI.NewCheckBox(Owner)
    CreateCheckBox.Caption = Caption
    CreateCheckBox.Common.SetRect X, Y, Width, Height
    CreateCheckBox.Common.ControlName = ControlName
    
End Function


Function CreateEdit(Owner, Text, X, Y, Width, Height, ControlName)

    Set CreateEdit = SDB.UI.NewEdit(Owner)
    CreateEdit.Text = Text
    CreateEdit.Common.SetRect X, Y, Width, Height
    CreateEdit.Common.ControlName = ControlName

End Function


Function CreateButton(Owner, Caption, X, Y, Width, Height, OnClickHandler)

    Set CreateButton = SDB.UI.NewButton(Owner)
    CreateButton.Caption = Caption
    CreateButton.Common.SetRect X, Y, Width, Height
    If OnClickHandler <> "" Then
        Script.RegisterEvent CreateButton.Common, "OnClick", OnClickHandler
    End If

End Function


Function CreateDropDown(Owner, X, Y, Width, Height, ControlName)

    Set CreateDropDown = SDB.UI.NewDropDown(Owner)
    CreateDropDown.Common.SetRect X, Y, Width, Height
    CreateDropDown.Common.ControlName = ControlName

End Function


Sub FillDropDownFromArray(DropDown, SourceArray)

    Dim i
    For i = 0 To UBound(SourceArray)
        DropDown.AddItem SourceArray(i)
    Next

End Sub


Sub SelectDropDownText(DropDown, Text)

    Dim i
    For i = 0 To DropDown.ItemCount - 1
        If DropDown.ItemText(i) = Text Then
            DropDown.ItemIndex = i
            DropDown.Text = Text
            Exit For
        End If
    Next
    
End Sub


Sub ClearDropDown(DropDown)

    Dim i
    For i = DropDown.ItemCount - 1 To 0 Step -1
        DropDown.DeleteItem i
    Next

    DropDown.Text = ""

End Sub

In-depth information:

The script uses configuration entries in MediaMonkey's ini file.
(normally under folder My Documents\My Music\MediaMonkey)


The colors of the ListViews can be set at the beginning of the script as hex values:

Code: Select all

Const ForegroundColor = &H000000
Const BackgroundColor = &HEFEFEF

Don't worry. This is a preview version. More features will come, including an option panel.
You need MM 2.5.3 RC4 or newer to be able to run the script without problems.

Image
Last edited by Steegy on Sat Jun 18, 2011 4:29 pm, edited 11 times in total.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
pah68
Posts: 1504
Joined: Wed Apr 07, 2004 5:26 pm
Location: Sydney, Australia

Post by pah68 »

That is very very cool. 8)
Thanks for this one, I love it. :D :D :wink:
Image
Image
pah68
Posts: 1504
Joined: Wed Apr 07, 2004 5:26 pm
Location: Sydney, Australia

Post by pah68 »

I have some Custom Occasions.
Kids & Radio Mix

The Kids listing shows my Radio Mix occasion. Confirmed by checking the tags

The Radio Mix occasion does show the Radio Mix Occasion
Image
Image
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

Have you checked if the tracks are correctly listed under the Library > Classification node? Are all values in MM's Lists database table as they should be? (e.g. "Kids" and "Radio Mix" mustn't have the same SortOrder).
I'll do some more testing on this to see if the script has some bug in that area.


If you have any ideas about future additions (new todo's), "looks", ... please let me know.
E.g. some people maybe never change/show the Custom pane (leftmost of pane the three panes) and don't need the labels "Artists", "Albums" above the panes. If so, an option to hide this stuff can be added in the future option panel (so it's still accessible, but not so easily). This is just an example. If someone asks this, then it will probably be added.



Before anyone asks: there are some inconsistencies in the SQL queries (between Albums, Artists and Album Artists). Maybe these can give "unexpected" listings as result. One reason for that is that I'm not really sure what the best solution is (when use Album ARtist, when use Artist). But it will be fixed.

Cheers & Thanks
Steegy
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
pah68
Posts: 1504
Joined: Wed Apr 07, 2004 5:26 pm
Location: Sydney, Australia

Post by pah68 »

Steegy wrote:Have you checked if the tracks are correctly listed under the Library > Classification node?
Yep, all good there :-?

Steegy wrote:Are all values in MM's Lists database table as they should be? (e.g. "Kids" and "Radio Mix" mustn't have the same SortOrder).
I'll do some more testing on this to see if the script has some bug in that area.
Not sure I understand. If you need me to go into MS Access, I'll have to do it at home this afternoon (Sydney / Australia) time.
Image
Image
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

If you need me to go into MS Access
Yes please, if that's possible.

Your "Lists" table should look a bit like this:

Code: Select all

ID    IDListType    TextData    SortOrder
-----------------------------------------
...
35        3           Kids          9
36        3         Radio Mix      10
...
with:
ID ---> Unique id for the record in the table
IDListType = 3 ---> It's an occasion
TextData ---> Name of the occasion
SortOrder ---> Sort order within the same IDListType group

SortOrder should not be the same for 2 items in the same IDListType group (but MM should work fine if that's not correct).
Please check if both SortOrder values are different for "Kids" and "Radio Mix".
If it seems that SortOrder can't be relied on to be unique, I'll use the unique ID instead (what I did in the beginning).

Cheers
Steegy
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post by Teknojnky »

That is awesome Steegy, it seems work just like MIP and very fast too!

Now if we could just hide the tree panel...
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

This looks like a great script. I can't run it though :(

Image

Presumably this is because I don't have "COMCTL.ListViewCtrl"?

ADDITION: I have the appropriate file "C:\WINDOWS\system32\comctl32.ocx" and have registered it. I think I need to have VS6 or something to have the correct licenses though?

:o Anyone suffering from this problem, send an email to fixlp@trixmoto.net and you'll get an auto response with the fix! :o
Last edited by trixmoto on Tue Oct 03, 2006 6:40 am, edited 2 times in total.
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.
psyXonova
Posts: 785
Joined: Fri May 20, 2005 3:57 am
Location: Nicosia, Cyprus
Contact:

Post by psyXonova »

XXXXXelent!!!!!!
I love it. Really cool and usefull script.
Also as a scripter i think it opens a new path to MM scripting since (from what i can recall) this is the first time that an COM object other that IE is used inside MM. Definetely a script that needs studying.

BTW, i was also glad to see Detailed Song Info panel inside your screenshoot. I noticed that is a modified version, does it solves the issues you mentioned in the Detailed Song Info topic (about refresh etc???).
I would really like you to email me the modified version of this script..
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

One word: Impressiv!

Really nice work Steegy!

/Bex
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
Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post by Big_Berny »

I have the same problem mentioned above. But the screen looks great! :D

Big_Berny
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

Thanks to all!


I'd like to solve the line 184 error as soon as possible. For that, I need someone with the "Licensing ..." problem that want to test something for me. Please PM me.
I can't test this myself because all my available pc's have already been used as VC development pc and seem to have the necessary licenses.


@pah68: There's a small error in your db, but it's not necessary to fix it. I will change the script (to what it was originally) what should prevent this problem to happen again.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

I noticed by accident that I actually could get into edit mode with a slow dubbel click in the pane. So i tried to edit a artist but it wasn't reflected in the DB or tag?

/Bex
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
Steegy
Posts: 3452
Joined: Sat Nov 05, 2005 7:17 pm

Post by Steegy »

TODO wrote:- Make entries editable (Now they "seem" editable, because of an issue with the listview control. They are not editable.)
Yes, that's (I think) an issue with the ListView control: setting it no non-editable doesn't change anything.


@EVERYONE:
People that couldn't run the script properly (everyone who never used MSVisualStudio or similar on that system): The new version of the script now handles this, so you won't have these problems again.
Minime wrote:A friend of a friend of a friend of a friend of mine told me that it's a bug and he gave me a bugfix. I don't know why this bug is still present in the current systems.
Extensions: ExternalTools, ExtractFields, SongPreviewer, LinkedTracks, CleanImport, and some other scripts (Need Help with Addons > List of All Scripts).
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto »

The new version works perfectly - excellent script! :)
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.
Post Reply