MonkeySqueeze Development V3.2

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: MonkeySqueeze Development V3.2

Re: MonkeySqueeze Development V3.2

by Gingernut63 » Thu Dec 01, 2016 11:29 pm

Re: MonkeySqueeze Development V3.2

by Gingernut63 » Mon Nov 21, 2016 4:37 am

Latest Beta release V3.2.161121

The current version of the script is optimised for MediaMonkey 4 and above.

If you haven't used a Beta just follow the instructions below, it's easy. Try a Beta, they're safe and you'll be helping with the development.

Release improvements:
- Add actual player names to the drop down box on the Option page, removing Player 1, Player 2 etc...
- Display name of selected Squeezebox Player after the MonkeySqueeze Enable/Disable button on the main menu
- Create a dockable panel for Squeezebox player control, accessible via "View" on the main menu.
- Add Squeezebox Player volume control to the dockable panel (See Known Issues)
- Add mute button to dockable panel (See Known Issues)


Known Issues:
- clicking the volume buttons rapidly will put the volume display out of sync with the player display. One click on any volume button will put it back into sync. Will look into time delay on button pressing
- Adjusting the volume on a synced player will put the volume display out of sync on the MM display. Again one click on any volume button will put it back into sync. Not a big issue, could ping the player volume level every few seconds for changes - low priority
- Mute button does not work with all players e.g. Boom and Duet. Does work with SqueezePlay and should work with piCorePlayer. Don't know about others
- Would like the player selection dropbox on the dockable panel, however, encountering some problems getting it working at this stage


Systems tested and working on:
PC (Win 10) + Windows Server 2008 (WHS 2011)

To use this version:
Copy the script to Notepad and save as MonkeySqueeze.vbs to one one of the following locations:
C:\Program Files\MediaMonkey\Scripts\Auto or C:\Program Files (x86)\MediaMonkey\Scripts\Auto

Make sure you disable or remove the existing MonkeySqueeze.vbs

If you use this script please report on this forum if it runs OK or if you had any issues. Feedback is appreciated so I can implement changes before any official release.

Code: Select all

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' MonkeySqueeze V3.2.161121Beta
'
' MOD DATE: 21.11.2016
'
' Script: Development has occurred in two distinct stages: As Squeezebox Controller from 2007 to 2009; and as MonkeySqueeze from 2011 on. 
' Major changes have occurred to the script since 2011 and it bears little resemblance to the original Squeezebox Controller.
' 
' DATE STARTED: 26.09.2007
'
' Squeezebox Controller: Todd Nemeth Mods: Baz, Big_Berny, Peke, trixmoto, debacle, mccstumble
' MonkeySqueeze: Gingernut63, booblers, Katteman
'
' COMMENT:
'  - You will also need Logitech Media Server installed and running
'  - Optional: Install and run SqueezePlay or SoftSqueeze
'  - After installation the options page for this script is located at Tools > Options > MonkeySqueeze
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit
Public EndOfTrack, LMScount, LMSpaths()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim onMonkeySqueezeIcon, offMonkeySqueezeIcon, Panel10, Label1, Mnu2, Mnu3, Sep, Btn14, Label2', Label4
'**************************************************************
Sub OnStartup
	Dim ind, Mnu1
	Dim UI : Set UI = SDB.UI
	
	onMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
	If onMonkeySqueezeIcon < 0 Then
		onMonkeySqueezeIcon = 74 'unlocked icon if it doesn't exist
	End If
	
	offMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
	If offMonkeySqueezeIcon < 0 Then
		offMonkeySqueezeIcon = 75 'locked icon if it doesn't exist
	End If
	
	Set Mnu1 = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
	Mnu1.Caption = "MonkeySqueeze"
	Mnu1.UseScript = Script.ScriptPath
	Mnu1.IconIndex = offMonkeySqueezeIcon
	Mnu1.Hint = "Enable/Disable MonkeySqueeze"
	Script.RegisterEvent Mnu1, "OnClick", "SyncToggle"
	
	Set Mnu2 = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
	If SDB.IniFile.BoolValue("MonkeySqueeze","MenuDisplay") = True Then
		Mnu2.Caption = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive")
	End If
	
	Set SDB.Objects("MonkeySqueezeIcon") = Mnu1  'save a reference to it so we can change the icon later.
	SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	ind = SDB.UI.AddOptionSheet("MonkeySqueeze",Script.ScriptPath,"InitSheet","SaveSheet",-2)
	
	Call PlayerControlPanel
	Call OnSelection

	Script.RegisterEvent SDB, "OnChangedSelection", "Volume_Level"
	Script.RegisterEvent SDB, "OnOptionsChange", "Volume_Level"
	'logme(slimRequest(formatCommand("""version"",""?""")))
	
End Sub
'**************************************************************	
Sub PlayerControlPanel
	Dim Btn10, Btn11, Btn12, Btn13', Combo10 
	Dim UI : Set UI = SDB.UI
	
	Set Panel10 = UI.NewDockablePersistentPanel("SqueezeboxPanel") 
	If Panel10.IsNew Then 
		Panel10.DockedTo = 1 
		Panel10.Common.Width = 250
	End If 
	Panel10.Caption = "Squeezebox Player" 
	Script.RegisterEvent Panel10, "OnClose", "ClosePanel10" 
	
	Set Label1 = UI.NewLabel(Panel10) 
	Label1.Autosize = True
	Label1.Common.SetRect 10, 10, 100, 20 'Panel10.Common.Width-20, Panel10.Common.Height-20 
	Label1.Common.Anchors = 3  '1+2
	
	'Set Combo10 = SDB.UI.NewDropdown(Panel10)
	'Combo10.Common.SetRect 10, 7, 100, 20
	'Combo10.Style = 1 'List style 1 or 2
	'Combo10.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	'Combo10.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	'Combo10.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	'Combo10.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
	'Combo10.Common.ControlName = "SqueezeBoxPlayerNo"
	'Combo10.ItemIndex = SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo")'Players 1 to 4 use integer values 0 to 3
	'Combo10.Common.Hint = "Click on the down arrow and select a player"
	'Combo10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","DDenable")= False'SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	'Script.RegisterEvent Combo10, "OnChange", "Test"
	
	'Set Label4 = UI.NewLabel(Panel10) 'Label used to display Squeezebox com strings - for development 
	'Label4.Autosize = True
	'Label4.Common.SetRect 10, 50, 250, 20 'Panel10.Common.Width-20, Panel10.Common.Height-20

	Set Btn10 = UI.NewButton(Panel10)
	Btn10.Common.ControlName = "Btn10"
	Btn10.Common.SetRect 110, 7, 20, 20
	Btn10.Caption = "<"
	Btn10.Common.FontBold = True
	Btn10.Common.FontColor = 50000	
	Btn10.Common.Hint = "Volume Softer 1%"
	'Btn10.Common.Anchors = 6
	Script.RegisterEvent Btn10, "OnClick", "Volume_Down1"
	
	Set Btn11 = UI.NewButton(Panel10)
	Btn11.Common.ControlName = "Btn11"
	Btn11.Common.SetRect 130, 7, 20, 20
	Btn11.Caption = "<<"
	Btn11.Common.FontBold = True
	Btn11.Common.FontColor = 50000	
	Btn11.Common.Hint = "Volume Softer 10%"
	'Btn11.Common.Anchors = 6
	Script.RegisterEvent Btn11, "OnClick", "Volume_Down10"
	
	Set Label2 = UI.NewLabel(Panel10) 
	Label2.Common.SetRect 153, 10, 30, 20
	Label2.Alignment = 1
	Label2.Common.Hint = "Player Volume"
	'Label2.Common.Anchors = 6
	
	Set Btn12 = UI.NewButton(Panel10)
	Btn12.Common.ControlName = "Btn12"
	Btn12.Common.SetRect 190, 7, 20, 20
	Btn12.Caption = ">>"
	Btn12.Common.FontBold = True
	Btn12.Common.FontColor = 50000
	Btn12.Common.Hint = "Volume Louder 10%"
	'Btn12.Common.Anchors = 6
	Script.RegisterEvent Btn12, "OnClick", "Volume_Up10"
	
	Set Btn13 = UI.NewButton(Panel10)
	Btn13.Common.ControlName = "Btn13"
	Btn13.Common.SetRect 210, 7, 20, 20
	Btn13.Caption = ">"
	Btn13.Common.FontBold = True
	Btn13.Common.FontColor = 50000
	Btn13.Common.Hint = "Volume Louder 1%"
	'Btn13.Common.Anchors = 6
	Script.RegisterEvent Btn13, "OnClick", "Volume_Up1"
	
	'This does work however not all players support mute
	Set Btn14 = UI.NewButton(Panel10)
	Btn14.Common.ControlName = "Btn14"
	Btn14.Common.SetRect 235, 7, 20, 20
	Btn14.Caption = "X"
	Btn14.Common.FontBold = True
	Btn14.Common.FontColor = 1
	Btn14.Common.Hint = "Mute"
	Script.RegisterEvent Btn14, "OnClick", "Volume_Mute"
	'Btn14.Common.Anchors = 6
	Btn14.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
	
	'Add menu item that shows panel after it is closed 
	Set Sep = SDB.UI.AddMenuItemSep(SDB.UI.Menu_View,0,0) 
	Set Mnu3 = SDB.UI.AddMenuItem(SDB.UI.Menu_View,0,0) 
	Mnu3.Caption = "Squeezebox Player Panel" 
	Mnu3.Checked = Panel10.Common.Visible 
	Script.RegisterEvent Mnu3, "OnClick", "ShowPanel10" 
	
	Call OnSelection

End Sub
'**************************************************************
Sub InitSheet(Sheet)
	Dim form, Panel1, Panel2, Panel3, Panel4, Btn1, Checkbox1, Checkbox2, Checkbox3, Checkbox4, CheckBox5, Edit1, Edit2, Edit3, Edit4, Edit5, Edit6, Edit7, Edit8, Edit9, Edit10, Edit11, Edit12, Edit13, Edit14, Combo1
	
	Set Panel1 = SDB.UI.NewGroupBox(Sheet)
	Panel1.Common.SetRect 10,5,780,55
	Panel1.Caption = "MonkeySqueeze V3.2.161121Beta -  General Settings"
	
	Set CheckBox1 = SDB.UI.NewCheckBox(Panel1)
	CheckBox1.Common.SetRect 15,20,150,20
	CheckBox1.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle")
	CheckBox1.Common.ControlName = "EnablePT"
	CheckBox1.Common.Hint = SDB.Localize("When selected if MonkeySqueeze is enabled, the primary Squeezebox device will power on, and on/off at startup/shutdown. When MonkeySqueeze is disabled, the selected Squeezebox player will power off.")
	CheckBox1.Caption = SDB.Localize("Power Toggle")
	
	Set CheckBox2 = SDB.UI.NewCheckBox(Panel1)
	CheckBox2.Common.SetRect 125,20,65,20
	CheckBox2.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Login")
	CheckBox2.Common.ControlName = "EnableLog"
	CheckBox2.Common.Hint = SDB.Localize("This will enable MonkeySqueeze to log into a password protected LMS/Squeezebox system.")
	CheckBox2.Caption = SDB.Localize("LMS Login")
	CheckBox2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	With SDB.UI.NewLabel(Panel1)
		.Common.SetRect 200,23,60,20
		.Caption = "Username:"
	End With
	
	Set Edit1 = SDB.UI.NewEdit(Panel1)
	Edit1.Common.ControlName = "SqueezeBoxUser"
	Edit1.Common.SetRect 255,19,95,25
	Edit1.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser")
	If Edit1.Text = "" Then
		Edit1.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = ""
	End If
	Edit1.Common.Hint = "Type the LMS username here"
	
	With SDB.UI.NewLabel(Panel1)
		.Common.SetRect 363,23,60,20
		.Caption = "Password:"
	End With
	Edit1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set Edit2 = SDB.UI.NewEdit(Panel1)
	Edit2.Common.ControlName = "SqueezeBoxPass"
	Edit2.Common.SetRect 415,19,95,25
	Edit2.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass")
	If Edit2.Text = "" Then
		Edit2.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = ""
	End If
	Edit2.PasswordChar = "*"
	Edit2.Common.Hint = "Type the LMS password here"
	Edit2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set Btn1 = SDB.UI.NewButton(Panel1)
	Btn1.Common.SetRect 700,17,65,25
	Btn1.Caption = "User Guide"
	Btn1.Common.Hint = "Click and then open MonkeySqueeze_UserGuide.pdf"
	Script.RegisterEvent Btn1, "OnClick", "UserGuide"
	
	Set Panel2 = SDB.UI.NewGroupBox(Sheet)
	Panel2.Common.SetRect 10,65,780,75
	Panel2.Caption = "LMS Communication Settings"
	
	With SDB.UI.NewLabel(Panel2)
		.Multiline = True
		.Common.SetRect 15,20,750,50
		.Caption = "Address/Hostname and port number located at the LMS Web page > Settings > Information tab"
	End With
	
	With SDB.UI.NewLabel(Panel2)
		.Common.SetRect 15,44,70,20
		.Caption = "IP Address:"
	End With
	
	Set Edit3 = SDB.UI.NewEdit(Panel2)
	Edit3.Common.ControlName = "SqueezeBoxIP"
	Edit3.Common.SetRect 75,40,220,25
	Edit3.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP")
	If Edit3.Text = "" Then
		Edit3.Text = "XXX.XXX.XXX.XXX"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = "XXX.XXX.XXX.XXX"
	End If
	Edit3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit3.Common.Hint = "Copy and paste the LMS IP Address or Hostname here"
	
	With SDB.UI.NewLabel(Panel2)
		.Common.SetRect 320,44,70,20
		.Caption = "HTTP Port No:"
	End With
	
	Set Edit4 = SDB.UI.NewEdit(Panel2)
	Edit4.Common.ControlName = "SqueezeBoxPort"
	Edit4.Common.SetRect 392,40,40,25
	Edit4.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort")
	If Edit4.Text = "" Then
		Edit4.Text = "9000"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = "9000"
	End If
	Edit4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit4.Common.Hint = "HTTP port default is 9000. View the port number in LMS: Web Control page > Settings > Information tab and change if required"
	
	Set Panel3 = SDB.UI.NewGroupBox(Sheet)
	Panel3.Common.SetRect 10,145,780,135
	Panel3.Caption = "Squeezebox Player Settings"
	
	With SDB.UI.NewLabel(Panel3)
		.Multiline = True
		.Common.SetRect 15,20,750,60
		.Caption = "The name and MAC address of the players (Touch, SqueezePlay, etc...) to connect to. Only one player connection per session."
	End With
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 15,45,70,20
		.Caption = "Select the active Squeezebox player:"
	End With
	
	Set Combo1 = SDB.UI.NewDropdown(Panel3)
	Combo1.Common.SetRect 198,42,250,25
	Combo1.Style = 1 'List style 1 or 2
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
	Combo1.Common.ControlName = "SqueezeBoxPlayerNo"
	Combo1.ItemIndex = SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo")'Players 1 to 4 use integer values 0 to 3
	Combo1.Common.Hint = "Click on the down arrow and select a player"
	Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set CheckBox5 = SDB.UI.NewCheckBox(Panel3)
	CheckBox5.Common.SetRect 500,42,300,20
	CheckBox5.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","MenuDisplay")
	CheckBox5.Common.ControlName = "EnableDisplay"
	CheckBox5.Common.Hint = SDB.Localize("Display selected Squeezebox Player next to MonkeySqueeze Enable/Disable button")
	CheckBox5.Caption = SDB.Localize("Player Displayed on Toolbar")
	'CheckBox5.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 15,79,60,20
		.Caption = "Player 1 Name:"
	End With
	
	Set Edit5 = SDB.UI.NewEdit(Panel3)
	Edit5.Common.ControlName = "SqueezeBoxPlayer1"
	Edit5.Common.SetRect 90,75,100,25
	Edit5.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	If Edit5.Text = "" Then
		Edit5.Text = " "
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = " "
	End If
	Edit5.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit5.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 15,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit6 = SDB.UI.NewEdit(Panel3)
	Edit6.Common.ControlName = "SqueezeBoxMAC"
	Edit6.Common.SetRect 90,98,100,25
	Edit6.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC")
	If Edit6.Text = "" Then
		Edit6.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit6.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 200,79,60,20
		.Caption = "Player 2 Name:"
	End With
	
	Set Edit7 = SDB.UI.NewEdit(Panel3)
	Edit7.Common.ControlName = "SqueezeBoxPlayer2"
	Edit7.Common.SetRect 275,75,100,25
	Edit7.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	If Edit7.Text = "" Then
		Edit7.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = ""
	End If
	Edit7.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit7.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 200,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit8 = SDB.UI.NewEdit(Panel3)
	Edit8.Common.ControlName = "SqueezeBoxMAC2"
	Edit8.Common.SetRect 275,98,100,25
	Edit8.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2")
	If Edit8.Text = "" Then
		Edit8.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit8.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 385,79,60,20
		.Caption = "Player 3 Name:"
	End With
	
	Set Edit9 = SDB.UI.NewEdit(Panel3)
	Edit9.Common.ControlName = "SqueezeBoxPlayer3"
	Edit9.Common.SetRect 460,75,110,25
	Edit9.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	If Edit9.Text = "" Then
		Edit9.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = ""
	End If
	Edit9.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit9.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 385,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit10 = SDB.UI.NewEdit(Panel3)
	Edit10.Common.ControlName = "SqueezeBoxMAC3"
	Edit10.Common.SetRect 460,98,110,25
	Edit10.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3")
	If Edit10.Text = "" Then
		Edit10.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit10.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 580,79,60,20
		.Caption = "Player 4 Name:"
	End With
	
	Set Edit11 = SDB.UI.NewEdit(Panel3)
	Edit11.Common.ControlName = "SqueezeBoxPlayer4"
	Edit11.Common.SetRect 655,75,110,25
	Edit11.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
	If Edit11.Text = "" Then
		Edit11.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = ""
	End If
	Edit11.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit11.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 580,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit12 = SDB.UI.NewEdit(Panel3)
	Edit12.Common.ControlName = "SqueezeBoxMAC4"
	Edit12.Common.SetRect 655,98,110,25
	Edit12.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4")
	If Edit12.Text = "" Then
		Edit12.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit12.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	Set Panel4 = SDB.UI.NewGroupBox(Sheet)
	Panel4.Common.SetRect 10,285,780,105
	Panel4.Caption = "LMS Server/NAS Systems"
	
	With SDB.UI.NewLabel(Panel4)
		.Multiline = True
		.Common.SetRect 15,20,750,60
		.Caption = "Used when LMS is installed on Server/NAS systems. Note: Linux systems use forward slashes (/) and Windows back slashes (\)"
	End With
	
	Set CheckBox3 = SDB.UI.NewCheckBox(Panel4)
	CheckBox3.Common.SetRect 15,43,110,20
	CheckBox3.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","NAS")
	CheckBox3.Common.ControlName = "EnableNAS"
	CheckBox3.Common.Hint = SDB.Localize("Select if using LMS on a Linux or Windows Server/NAS device. See user guide for more details")
	CheckBox3.Caption = SDB.Localize("LMS Server/NAS")
	CheckBox3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set CheckBox4 = SDB.UI.NewCheckBox(Panel4)
	CheckBox4.Common.SetRect 150,43,260,20
	CheckBox4.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Synology")
	CheckBox4.Common.ControlName = "EnableSynology"
	CheckBox4.Common.Hint = SDB.Localize("Select if using Squeezebox Server prior to v7.5.1. Tested on Synology devices only")
	CheckBox4.Caption = SDB.Localize("LMS is prior to v7.5.1 (Linux device only)")
	CheckBox4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	With SDB.UI.NewLabel(Panel4)
		.Common.SetRect 15,74,70,20
		.Caption = "MediaMonkey Music Folder:"
	End With
	
	Set Edit13 = SDB.UI.NewEdit(Panel4)
	Edit13.Common.ControlName = "MediaMonkeyMF"
	Edit13.Common.SetRect 148,70,250,25
	Edit13.Text = SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF")
	If Edit13.Text = "" Then
		Edit13.Text = "\\Server\folder or X:\__\__(mapped)"
		SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = "\\Server\folder or X:\__\__(mapped)"
	End If
	Edit13.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit13.Common.Hint = "Copy from MediaMonkey > Track Browser > right click on a song > Properties > Basic > FilePath and copy the first part of the track address"
	
	With SDB.UI.NewLabel(Panel4)
		.Common.SetRect 425,74,70,20
		.Caption = "LMS Media Folder:"
	End With
	
	Set Edit14 = SDB.UI.NewEdit(Panel4)
	Edit14.Common.ControlName = "SqueezeBoxMF"
	Edit14.Common.SetRect 515,70,250,25
	Edit14.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF")
	If Edit14.Text = "" Then
		Edit14.Text = "/___ /___ Linux, or \ ___\ ___ Windows"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = "/___ /___ Linux, or \ ___\ ___ Windows"
	End If
	Edit14.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit14.Common.Hint = "Copy from: LMS Web Page > Settings > Basic Settings tab > Music Folder"
	
	Script.RegisterEvent SDB, "OnOptionsChange", "OnSelection" 'Update the Squeezebox player display when the options window is closed
	Script.RegisterEvent SDB, "OnOptionsChange", "Volume_Level"
	
End Sub
'**************************************************************
Sub SaveSheet(Sheet)
	SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") = Sheet.Common.ChildControl( "EnablePT").Checked
	SDB.IniFile.BoolValue("MonkeySqueeze","Login") = Sheet.Common.ChildControl( "EnableLog").Checked
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = Sheet.Common.ChildControl("SqueezeBoxUser").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = Sheet.Common.ChildControl("SqueezeBoxPass").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = Sheet.Common.ChildControl("SqueezeBoxIP").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = Sheet.Common.ChildControl("SqueezeBoxPort").Text
	SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = Sheet.Common.ChildControl("SqueezeBoxPlayerNo").ItemIndex
	SDB.IniFile.BoolValue("MonkeySqueeze","MenuDisplay") = Sheet.Common.ChildControl( "EnableDisplay").Checked
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = Sheet.Common.ChildControl("SqueezeBoxPlayer1").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = Sheet.Common.ChildControl("SqueezeBoxMAC").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = Sheet.Common.ChildControl("SqueezeBoxPlayer2").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = Sheet.Common.ChildControl("SqueezeBoxMAC2").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = Sheet.Common.ChildControl("SqueezeBoxPlayer3").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = Sheet.Common.ChildControl("SqueezeBoxMAC3").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = Sheet.Common.ChildControl("SqueezeBoxPlayer4").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = Sheet.Common.ChildControl("SqueezeBoxMAC4").Text
	SDB.IniFile.BoolValue("MonkeySqueeze","NAS") = Sheet.Common.ChildControl( "EnableNAS").Checked
	SDB.IniFile.BoolValue("MonkeySqueeze","Synology") = Sheet.Common.ChildControl( "EnableSynology").Checked
	SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = Sheet.Common.ChildControl("MediaMonkeyMF").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = Sheet.Common.ChildControl("SqueezeBoxMF").Text
End Sub
'**************************************************************
Sub ShowPanel10(Item) 
	
	Panel10.Common.Visible = Not Panel10.Common.Visible 
	Mnu3.Checked = Panel10.Common.Visible 
End Sub 
'************************************************************** 
Sub ClosePanel10(Item)
	
	Mnu3.Checked = False 
End Sub 
'************************************************************** 
Sub OnSelection
	If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")			
	End If
	
	If SDB.IniFile.BoolValue("MonkeySqueeze","MenuDisplay") = True Then
		Mnu2.Caption = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive")
		Mnu2.Hint = "This is the selected Squeezebox player"
	ElseIf SDB.IniFile.BoolValue("MonkeySqueeze","MenuDisplay") = False Then
		Mnu2.Caption = ""
	End If
	Label1.Caption = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive")
End Sub
'**************************************************************
Sub UserGuide
	On Error Resume Next
	Dim OF, FolderToOpen
	
	Set OF = CreateObject("Shell.Application")
	FolderToOpen = sdb.ScriptsPath & "Auto\"
	OF.Explore FolderToOpen
	Set OF = Nothing
End Sub
'**************************************************************
Function SqueezeBoxMode
	Dim strRetVal
	
	On Error Resume Next
	SqueezeBoxMode = ""
	strRetVal = slimRequest(formatCommand("""mode"", ""?"""))
	If InStrRev(strRetVal, "play") > 0 Then
		SqueezeBoxMode = "play"
	ElseIf InStrRev(strRetVal, "stop") > 0 Then
		SqueezeBoxMode = "stop"
	ElseIf InStrRev(strRetVal, "pause") > 0 Then
		SqueezeBoxMode = "pause"
	End If
End Function
'**************************************************************
Sub ShowPlayerSettings
	Dim Plr, Warning, Res
	
	Warning = ""
	Set Plr = SDB.Player
	'If Plr.isAutoDJ    Then Warning = Warning & vbNewLine & "AutoDJ is on"
	If Plr.isCrossFade Then Warning = Warning & vbNewLine & "CrossFade is on"
	If Plr.isShuffle   Then Warning = Warning & vbNewLine & "Shuffle is on"
	If Plr.isEqualizer Then Warning = Warning & vbNewLine & "Equalizer is on"
	If Plr.isRepeat    Then Warning = Warning & vbNewLine & "Repeat is on"
	If Warning <> "" Then
		Res = SDB.MessageBox("Selected player settings:" & vbNewLine & _
		Warning, mtWarning, Array(mbOk))
	End If
End Sub
'**************************************************************
Function SyncToggle( itm )
	
	If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
		SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
		itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
		Call registerEvents
		If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""1"""))
		ShowPlayerSettings
		FillPlaylist
	Else
		SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
		itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
		Call Volume_Mute
		Call unregisterEvents
		slimRequest(formatCommand("""stop"""))
		If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
	End If
	
	'Mute Button colour and access
	If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True Then
		Btn14.Common.FontColor = 1000
	Else Btn14.Common.FontColor = 1
	End If
	Btn14.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
End Function
'**************************************************************
Sub Event_OnPlay
	Dim strRetVal, Idx
	
	If (SqueezeBoxMode = "play") And EndOfTrack Then
		'*** normal playlist continuation
		EndOfTrack = False
	Else
		'*** Squeezebox is not playing or new track out of order
		Idx = SDB.Player.CurrentSongIndex
		slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
	End If
End Sub
'**************************************************************
Sub Event_OnTrackEnd
	Dim strRetVal, idx, tim, dur
	
	'*** see if current track ended, then playing is not interrupted
	EndOfTrack = True
End Sub
'**************************************************************
Function CheckPath(SongValue)
	If Left(SongValue.Path,1) = "?" Then
		If SongValue.Cached Then
			CheckPath = SongValue.CachedPath
		Else
			CheckPath = SongValue.Path
		End If
	Else
		CheckPath = SongValue.Path
	End If
	If SDB.IniFile.BoolValue("MonkeySqueeze","NAS") Then
		If SDB.IniFile.BoolValue("MonkeySqueeze","Synology") Then CheckPath = Replace(CheckPath,"\","/")
		CheckPath = Replace(CheckPath,SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF"),SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF"))
	End If
End Function
'**************************************************************
Sub Event_OnStop
	slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnShutdown
	On Error Resume Next
	slimRequest(formatCommand("""stop"""))
	If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
End Sub
'**************************************************************
Sub Event_OnPause
	
	If SDB.Player.IsPaused Then
		slimRequest(formatCommand("""pause"""))
	Else
		slimRequest(formatCommand("""play"""))
	End If
End Sub
'**************************************************************
Sub Event_OnSeek
	Dim SBmode, Song, TrackPath, LMStime
	
	SBmode = SqueezeBoxMode
	If SBmode = "stop" Then
		Set Song = SDB.Player.CurrentSong
		TrackPath = CheckPath(Song)
		slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
	End If
	LMStime = 0.001 * SDB.Player.PlaybackTime
	slimRequest(formatCommand("""time"", """ + CStr(LMStime) + """"))
End Sub
'**************************************************************
Function slimRequest(params)
	'slimRequest accepts pre-formatted parameter string, returns string of the response'
	'logme "  >> slimRequest: Begin with " + params
	Dim url, prog, objHTTP
	Dim cnt : cnt = 0
	
	If SDB.IniFile.BoolValue("MonkeySqueeze","Login") = True Then
		url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") + "@" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
	Else
		url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
	End If
	
	'Set prog = SDB.Objects("LoadXMLBar")
	Set prog = SDB.Progress
	Set objHTTP = CreateObject("Microsoft.XMLHTTP")
	Call objHTTP.open("POST", url, True)
	objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	objHTTP.setRequestHeader "X-Requested-With", "XMLHttpRequest"
	objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
	objHTTP.send(params)
	
	Do While (objHTTP.readyState < 4) And (cnt < 300)
		Call SDB.Tools.Sleep(100)
		SDB.ProcessMessages
		cnt = cnt+1
		If prog.Terminate Then
			cnt = 300
		End If
	Loop
	
	If objHTTP.readyState < 4 Then
		Set slimRequest = Nothing
	Else
		slimRequest = objHTTP.responseText
	End If
End Function
'*************************************************************
'This is is a JSON RPC call - We're directly calling functions in the Slim::Request module in Perl. See here:
'http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm
'the addDispatch section tells you how to use the commands and what the RPC module is looking for in terms of formatting
Function formatCommand(str1)
	If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") + """,[" + str1 + "]]}"
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") + """,[" + str1 + "]]}"
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") + """,[" + str1 + "]]}"
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") + """,[" + str1 + "]]}"
	End If
	
End Function
'*************************************************************
'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
	Dim fso, logf
	
	On Error Resume Next
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
	logf.WriteLine Now() & ": " & msg
	Set fso = Nothing
	Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to Squeezebox)
Function perlEscape(str1)
	perlEscape = Replace(str1, "\", "\\")
End Function
'*************************************************************
Sub registerEvents
	Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
	Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
	Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
	Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
	Call Script.RegisterEvent(SDB,"OnTrackEnd","Event_OnTrackEnd")
	Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
	Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub
'*************************************************************
Sub Event_OnNowPlayingModified
	Dim MMcount
	
	MMcount = SDB.Player.CurrentPlayList.Count
	'logme("Now playing modified")
	'logme("Aantal MM tracks: " & Cstr(MMcount))
	'logme("Aantal LMS tracks: " & Cstr(LMScount))
	If SqueezeBoxMode = "stop" Then
		FillPlaylist
	ElseIf MMcount = 0 Then
		ResetPlaylist
	ElseIf MMcount < LMScount Then
		TracksDeleted(MMcount)
	ElseIf MMcount > LMScount Then
		TracksAdded(MMcount)
	Else
		TracksMoved
	End If
End Sub
'*************************************************************
Sub FillPlaylist
	'*** synchronize MM playlist with LMS playlist
	Dim tempStop, Idx
	
	'*** clear LMS playlist and stop shuffle!!
	slimRequest(formatCommand("""playlist"", ""clear"""))
	slimRequest(formatCommand("""playlist"", ""shuffle"", ""0"""))
	'*** copy MM playlist - if any - to LMS
	LMScount = SDB.Player.CurrentPlayList.Count
	ReDim LMSpaths(LMScount)
	'*** if playlist is empty we are done
	If LMScount > 0 Then
		tempStop = SDB.Player.isPlaying And (SDB.Player.PlayBackTime < 2000)
		If tempStop Then
			SDB.Player.pause
			slimRequest(formatCommand("""stop"""))
		End If
		SendPlaylist
		'*** jump to current song
		Idx = SDB.Player.CurrentSongIndex
		slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
		If tempStop Then
			'*** Start playback after filling playlist
			SDB.Player.Pause
		ElseIf SDB.Player.isPlaying Then
			'*** Synchronize LMS with current track
			slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001) + """"))
			If SDB.Player.isPaused Then SDB.Player.Pause
		Else
			'*** MediaMonkey is not playing
			slimRequest(formatCommand("""stop"""))
		End If
	End If
	EndOfTrack = False
End Sub
'**************************************************************
Sub SendPlaylist
	Dim Progr, TrackPath, Song, n
	
	'*** show progress bar
	Set Progr = SDB.Progress
	Progr.Text = SDB.Localize("Synchronising playlists...")
	Progr.MaxValue = LMScount
	'*** send playlist
	For n=0 To LMScount-1
		Set Song = SDB.Player.CurrentPlayList.Item(n)
		TrackPath = CheckPath(Song)
		LMSpaths(n) = TrackPath
		slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
		Progr.Value = n+1
	Next
End Sub
'**************************************************************
Sub ResetPlaylist
	
	SDB.Player.Stop
	slimRequest(formatCommand("""stop"""))
	slimRequest(formatCommand("""playlist"", ""clear"""))
	ReDim LMSpaths(0)
	LMScount = 0
End Sub
'**************************************************************
Sub TracksDeleted(MMcount)
	Dim n, m, Song, TrackPath
	
	'logme("Tracks deleted")
	n = 0
	Do While MMcount < LMScount
		If n = MMcount Then
			TrackPath = "***"
		Else
			Set Song = SDB.Player.CurrentPlayList.Item(n)
			TrackPath = CheckPath(Song)
		End If
		If (TrackPath = LMSpaths(n)) Then
			n = n+1
		Else
			LMScount = LMScount - 1
			For m = n To LMScount - 1
				LMSpaths(m) = LMSpaths(m+1)
			Next
			slimRequest(formatCommand("""playlist"", ""delete"", """ + CStr(n) + """"))
		End If
	Loop
End Sub
'*************************************************************
Sub TracksAdded(MMcount)
	Dim n, m, Song, TrackPath
	
	'logme("Tracks added")
	ReDim Preserve LMSpaths(MMcount)  'expand array, preserve content
	Do
		For n = 0 To MMcount -1
			Set Song = SDB.Player.CurrentPlayList.Item(n)
			TrackPath = CheckPath(Song)
			If (TrackPath <> LMSpaths(n)) Then
				slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
				If n < LMScount Then
					slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(LMScount) + """, """ + CStr(n) + """"))
					For m = LMScount To n+1 Step -1
						LMSpaths(m) = LMSpaths(m-1)
					Next
				End If
				LMSpaths(n) = TrackPath
				LMScount = LMScount + 1
			End If
		Next
	Loop While MMcount > LMScount
End Sub
'*************************************************************
Sub TracksMoved
	Dim n, m, i, Song, TrackPath, tempPath
	
	'logme("Tracks moved")
	For n=0 To LMScount-1
		Set Song = SDB.Player.CurrentPlayList.Item(n)
		TrackPath = CheckPath(Song)
		If TrackPath <> LMSpaths(n) Then
			For m=n+1 To LMScount-1
				If TrackPath = LMSpaths(m) Then Exit For
			Next
			For i=m To n+1 Step -1
				LMSpaths(i) = LMSpaths(i-1)
			Next
			LMSpaths(n) = TrackPath
			slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(m) + """, """ + CStr(n) + """"))
		End If
	Next
End Sub
'**************************************************************
Sub Volume_Up1
	
	slimRequest(formatCommand("""mixer"", ""volume"", ""+1"""))
	Call Volume_Level
End Sub
'**************************************************************
Sub Volume_Up10
	
	slimRequest(formatCommand("""mixer"", ""volume"", ""+10"""))
	Call Volume_Level
End Sub
'**************************************************************
Sub Volume_Down1

	slimRequest(formatCommand("""mixer"", ""volume"", ""-1"""))
	Call Volume_Level
End Sub
'**************************************************************
Sub Volume_Down10

	slimRequest(formatCommand("""mixer"", ""volume"", ""-10"""))
	Call Volume_Level
End Sub
'**************************************************************
Sub Volume_Level
	Dim strRetVal2, NewStr1, re, strRetVal4
	
'Request sent to Squeezebox - {""id"":1,""method"":""slim.request"",""params"":["""00:ff:f3:3f:72:84""",["""mixer"", ""volume"",""?"""]
'Reply from Squeezebox - {"params":["00:ff:f3:3f:72:84",["mixer","volume","?"]],"method":"slim.request","id":1,"result":{"_volume":"60"}}
'60 at the end of the above line represents 60%, the current volume setting from the selected player		
	
	strRetVal2 = slimRequest(formatCommand("""mixer"", ""volume"",""?"""))
	NewStr1 = Right(strRetVal2,6)
 	NewStr1 = Replace(NewStr1,"}}", "")
 	NewStr1 = Replace(NewStr1, Chr(34), "")
 	NewStr1 = Replace(NewStr1, ":", "")
 	strRetVal4 = slimRequest(formatCommand("""mixer"", ""muting"", ""?"""))
 	If InStrRev(strRetVal4,"1",-1) > 85 Then
 		Label2.Caption = "Mute"
 	Else
 	Label2.Caption = NewStr1 + "%"
 	End If

End Sub
'**************************************************************
Sub Volume_Mute
	Dim strRetVal3
	
'This does work however not all players support mute
	On Error Resume Next	
	strRetVal3 = slimRequest(formatCommand("""mixer"", ""muting"", ""?"""))
	If InStrRev(strRetVal3,"1",-1) > 85 Then
		slimRequest(formatCommand("""mixer"", ""muting"", ""0"""))
		Call Volume_Level
	ElseIf InStrRev(strRetVal3,"1",-1) > 85 And SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
		slimRequest(formatCommand("""mixer"", ""muting"", ""0"""))
		Call Volume_Level
	ElseIf InStrRev(strRetVal3,"0",-1) > 85 And SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True Then
		slimRequest(formatCommand("""mixer"", ""muting"", ""1"""))
	End If
	Call Volume_Level
End Sub
'*************************************************************
Sub unregisterEvents
	Script.UnregisterEvents SDB
End Sub
'*************************************************************
'These are what the full JSON strings look like that need to be sent to slimRequest()
'formatRequest() fills in the first part and all you have to do is pick the RPC commands from http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm

'Note: there are cleaner ways of doing this - but this is quick and dirty. It just means that you have to use a lot of """ and etc in vbscript.
'This entire script is much easier to write in jscript but I don't know jscript at all so, shrug.

'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:cgABbehldiqtyrSuoKLN"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:uB"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["playlist","index",28]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["pause"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",[""playlist"", ""play"", ""D:\\MP3\\filename.mp3""]]}


'You can do ANYTHING you can do from the web interface via this RPC engine because you are directly calling the methods in Perl
'so you could add whole playlists and etc see the docs. Sky's the limit.

MonkeySqueeze Development V3.1.1

by Gingernut63 » Sun Nov 13, 2016 4:24 am

Latest Beta release V3.1.1.161113

The current version of the script is optimised for MediaMonkey 4 and above.

If you haven't used a Beta just follow the instructions below, it's easy. Try a Beta, they're safe and you'll be helping with the development.

Release improvements:
- Add actual player names to the drop down box on the Option page, removing Player 1, Player 2 etc...
- Display name of selected Squeezebox Player after the MonkeySqueeze Enable/Disable button on the main menu
- As an alternative idea, display name of selected Squeezebox Player on a dock-able panel accessible via "View" on the main menu. Could also be used for Squeezebox player volume control - Anyone interested doing the coding?
- General tidy of the script


Systems tested and working on:
PC (Win 10) + Windows Server 2008 (WHS 2011)

Known Issues:
None at this stage

To use this version:
Copy the script to Notepad and save as MonkeySqueeze.vbs to one one of the following locations:
C:\Program Files\MediaMonkey\Scripts\Auto or C:\Program Files (x86)\MediaMonkey\Scripts\Auto

Make sure you disable or remove the existing MonkeySqueeze.vbs

If you use this script please report on this forum if it runs OK or if you had any issues. Feedback is appreciated so I can implement changes before any official release.

Code: Select all

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' MonkeySqueeze V3.1.1.161113Beta
'
' MOD DATE: 13.11.2016
'
' Script: Development has occurred in two distinct stages: As Squeezebox Controller from 2007 to 2009; and as MonkeySqueeze from 2011 on. 
' Major changes have occurred to the script since 2011 and it bears little resemblance to the original Squeezebox Controller.
' 
' DATE STARTED: 26.09.2007
'
' Squeezebox Controller: Todd Nemeth    Mods: Baz, Big_Berny, Peke, trixmoto, debacle, mccstumble
' MonkeySqueeze: Gingernut63, booblers, Katteman
'
' COMMENT:
'  - You will also need Logitech Media Server (Squeezebox Server) installed and running
'  - Optional: Install and run SqueezePlay or SoftSqueeze
'  - After installation the options page for this script is located at Tools > Options > MonkeySqueeze
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit
Public EndOfTrack, LMScount, LMSpaths()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim onMonkeySqueezeIcon, offMonkeySqueezeIcon, Panel10, Label1, Mnu2, Mnu3, Sep
'**************************************************************
Sub OnStartup
	Dim ind, Mnu1 
	Dim UI : Set UI = SDB.UI
	
	onMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
	If onMonkeySqueezeIcon < 0 Then
		onMonkeySqueezeIcon = 74 'unlocked icon if it doesn't exist
	End If
	
	offMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
	If offMonkeySqueezeIcon < 0 Then
		offMonkeySqueezeIcon = 75 'locked icon if it doesn't exist
	End If
	
	Set Mnu1 = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
	Mnu1.Caption = "MonkeySqueeze"
	Mnu1.UseScript = Script.ScriptPath
	Mnu1.OnClickFunc = "SyncToggle"
	Mnu1.IconIndex = offMonkeySqueezeIcon
	Mnu1.Hint = "Enable/Disable MonkeySqueeze"
	
	Set Mnu2 = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
	Mnu2.Caption = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive")
	Mnu2.Hint = "This is the selected Squeezebox player"
	
	Set Panel10 = UI.NewDockablePersistentPanel("SqueezeboxPanel") 
	If Panel10.IsNew Then 
		Panel10.DockedTo = 2 
		Panel10.Common.Width = 250 
	End If 
	Panel10.Caption = "Squeezebox Player" 
	Script.RegisterEvent Panel10, "OnClose", "ClosePanel10" 
	
	Set Label1 = UI.NewLabel(Panel10) 
	Label1.Autosize = False
	Label1.Multiline = True 
	Label1.Common.SetRect 10, 10, Panel10.Common.Width-20, Panel10.Common.Height-20 
	Label1.Common.Anchors = 15  '1+2+4+8 

	'Add menu item that shows panel after it is closed 
	Set Sep = SDB.UI.AddMenuItemSep(SDB.UI.Menu_View,0,0) 
	Set Mnu3 = SDB.UI.AddMenuItem(SDB.UI.Menu_View,0,0) 
	Mnu3.Caption = "Squeezebox Player Panel" 
	Mnu3.Checked = Panel10.Common.Visible 
	Script.RegisterEvent Mnu3, "OnClick", "ShowPanel10" 
	
	'Script.RegisterEvent SDB, "OnOptionsChange", "OnSelection" 'Update the Squeezebox player display when the Options window is closed
	Script.RegisterEvent SDB, "OnChangedSelection", "OnSelection"
	
	Set SDB.Objects("MonkeySqueezeIcon") = Mnu1  'save a reference to it so we can change the icon later.
	SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	ind = SDB.UI.AddOptionSheet("MonkeySqueeze",Script.ScriptPath,"InitSheet","SaveSheet",-2)
	
	'logme(slimRequest(formatCommand("""version"",""?""")))
	
End Sub
'**************************************************************
Sub InitSheet(Sheet)
	Dim form, Panel1, Panel2, Panel3, Panel4, Btn1, Checkbox1, Checkbox2, Checkbox3, Checkbox4, Edit1, Edit2, Edit3, Edit4, Edit5, Edit6, Edit7, Edit8, Edit9, Edit10, Edit11, Edit12, Edit13, Edit14, Combo1
	
	Set Panel1 = SDB.UI.NewGroupBox(Sheet)
	Panel1.Common.SetRect 10,5,780,55
	Panel1.Caption = "MonkeySqueeze V3.1.1.Beta -  General Settings"
	
	Set CheckBox1 = SDB.UI.NewCheckBox(Panel1)
	CheckBox1.Common.SetRect 15,20,150,20
	CheckBox1.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle")
	CheckBox1.Common.ControlName = "EnablePT"
	CheckBox1.Common.Hint = SDB.Localize("When selected if MonkeySqueeze is enabled, the primary Squeezebox device will power on, and on/off at startup/shutdown. When MonkeySqueeze is disabled, the selected Squeezebox player will power off.")
	CheckBox1.Caption = SDB.Localize("Power Toggle")
	
	Set CheckBox2 = SDB.UI.NewCheckBox(Panel1)
	CheckBox2.Common.SetRect 125,20,65,20
	CheckBox2.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Login")
	CheckBox2.Common.ControlName = "EnableLog"
	CheckBox2.Common.Hint = SDB.Localize("This will enable MonkeySqueeze to log into a password protected LMS/Squeezebox system.")
	CheckBox2.Caption = SDB.Localize("LMS Login")
	CheckBox2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	With SDB.UI.NewLabel(Panel1)
		.Common.SetRect 200,23,60,20
		.Caption = "Username:"
	End With
	
	Set Edit1 = SDB.UI.NewEdit(Panel1)
	Edit1.Common.ControlName = "SqueezeBoxUser"
	Edit1.Common.SetRect 255,19,95,25
	Edit1.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser")
	If Edit1.Text = "" Then
		Edit1.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = ""
	End If
	Edit1.Common.Hint = "Type the LMS username here"
	
	With SDB.UI.NewLabel(Panel1)
		.Common.SetRect 363,23,60,20
		.Caption = "Password:"
	End With
	Edit1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set Edit2 = SDB.UI.NewEdit(Panel1)
	Edit2.Common.ControlName = "SqueezeBoxPass"
	Edit2.Common.SetRect 415,19,95,25
	Edit2.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass")
	If Edit2.Text = "" Then
		Edit2.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = ""
	End If
	Edit2.PasswordChar = "*"
	Edit2.Common.Hint = "Type the LMS password here"
	Edit2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set Btn1 = SDB.UI.NewButton(Panel1)
	Btn1.Common.SetRect 700,17,65,25
	Btn1.Caption = "User Guide"
	Btn1.Common.Hint = "Click and then open MonkeySqueeze_UserGuide.pdf"
	Script.RegisterEvent Btn1, "OnClick", "UserGuide"
	
	Set Panel2 = SDB.UI.NewGroupBox(Sheet)
	Panel2.Common.SetRect 10,65,780,75
	Panel2.Caption = "LMS Communication Settings"
	
	With SDB.UI.NewLabel(Panel2)
		.Multiline = True
		.Common.SetRect 15,20,750,50
		.Caption = "Address/Hostname and port number located at the LMS Web page > Settings > Information tab"
	End With
	
	With SDB.UI.NewLabel(Panel2)
		.Common.SetRect 15,44,70,20
		.Caption = "IP Address:"
	End With
	
	Set Edit3 = SDB.UI.NewEdit(Panel2)
	Edit3.Common.ControlName = "SqueezeBoxIP"
	Edit3.Common.SetRect 75,40,220,25
	Edit3.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP")
	If Edit3.Text = "" Then
		Edit3.Text = "XXX.XXX.XXX.XXX"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = "XXX.XXX.XXX.XXX"
	End If
	Edit3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit3.Common.Hint = "Copy and paste the LMS IP Address or Hostname here"
	
	With SDB.UI.NewLabel(Panel2)
		.Common.SetRect 305,44,70,20
		.Caption = "HTTP Port No:"
	End With
	
	Set Edit4 = SDB.UI.NewEdit(Panel2)
	Edit4.Common.ControlName = "SqueezeBoxPort"
	Edit4.Common.SetRect 377,40,40,25
	Edit4.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort")
	If Edit4.Text = "" Then
		Edit4.Text = "9000"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = "9000"
	End If
	Edit4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit4.Common.Hint = "HTTP port default is 9000. View the port number in LMS: Web Control page > Settings > Information tab and change if required"
	
	Set Panel3 = SDB.UI.NewGroupBox(Sheet)
	Panel3.Common.SetRect 10,145,780,135
	Panel3.Caption = "Squeezebox Player Settings"
	
	With SDB.UI.NewLabel(Panel3)
		.Multiline = True
		.Common.SetRect 15,20,750,60
		.Caption = "The name and MAC address of the players (Touch, SqueezePlay, etc...) to connect to. Only one player connection per session."
	End With
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 15,45,70,20
		.Caption = "Select the active Squeezebox player:"
	End With
	
	Set Combo1 = SDB.UI.NewDropdown(Panel3)
	Combo1.Common.SetRect 198,42,250,25
	Combo1.Style = 1 'List style 1 or 2
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	Combo1.AddItem SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
	Combo1.Common.ControlName = "SqueezeBoxPlayerNo"
	Combo1.ItemIndex = SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo")'Players 1 to 4 use integer values 0 to 3
	Combo1.Common.Hint = "Click on the down arrow and select a player"
	Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 15,79,60,20
		.Caption = "Player 1 Name:"
	End With
	
	Set Edit5 = SDB.UI.NewEdit(Panel3)
	Edit5.Common.ControlName = "SqueezeBoxPlayer1"
	Edit5.Common.SetRect 90,75,100,25
	Edit5.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	If Edit5.Text = "" Then
		Edit5.Text = " "
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = " "
	End If
	Edit5.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit5.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 15,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit6 = SDB.UI.NewEdit(Panel3)
	Edit6.Common.ControlName = "SqueezeBoxMAC"
	Edit6.Common.SetRect 90,98,100,25
	Edit6.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC")
	If Edit6.Text = "" Then
		Edit6.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit6.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 200,79,60,20
		.Caption = "Player 2 Name:"
	End With
	
	Set Edit7 = SDB.UI.NewEdit(Panel3)
	Edit7.Common.ControlName = "SqueezeBoxPlayer2"
	Edit7.Common.SetRect 275,75,100,25
	Edit7.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	If Edit7.Text = "" Then
		Edit7.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = ""
	End If
	Edit7.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit7.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 200,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit8 = SDB.UI.NewEdit(Panel3)
	Edit8.Common.ControlName = "SqueezeBoxMAC2"
	Edit8.Common.SetRect 275,98,100,25
	Edit8.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2")
	If Edit8.Text = "" Then
		Edit8.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit8.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 385,79,60,20
		.Caption = "Player 3 Name:"
	End With
	
	Set Edit9 = SDB.UI.NewEdit(Panel3)
	Edit9.Common.ControlName = "SqueezeBoxPlayer3"
	Edit9.Common.SetRect 460,75,110,25
	Edit9.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	If Edit9.Text = "" Then
		Edit9.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = ""
	End If
	Edit9.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit9.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 385,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit10 = SDB.UI.NewEdit(Panel3)
	Edit10.Common.ControlName = "SqueezeBoxMAC3"
	Edit10.Common.SetRect 460,98,110,25
	Edit10.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3")
	If Edit10.Text = "" Then
		Edit10.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit10.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 580,79,60,20
		.Caption = "Player 4 Name:"
	End With
	
	Set Edit11 = SDB.UI.NewEdit(Panel3)
	Edit11.Common.ControlName = "SqueezeBoxPlayer4"
	Edit11.Common.SetRect 655,75,110,25
	Edit11.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
	If Edit11.Text = "" Then
		Edit11.Text = ""
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = ""
	End If
	Edit11.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit11.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
	
	With SDB.UI.NewLabel(Panel3)
		.Common.SetRect 580,102,55,20
		.Caption = "MAC Address:"
	End With
	
	Set Edit12 = SDB.UI.NewEdit(Panel3)
	Edit12.Common.ControlName = "SqueezeBoxMAC4"
	Edit12.Common.SetRect 655,98,110,25
	Edit12.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4")
	If Edit12.Text = "" Then
		Edit12.Text = "xx:xx:xx:xx:xx:xx"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = "xx:xx:xx:xx:xx:xx"
	End If
	Edit12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit12.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
	
	Set Panel4 = SDB.UI.NewGroupBox(Sheet)
	Panel4.Common.SetRect 10,285,780,105
	Panel4.Caption = "LMS Server/NAS Systems"
	
	With SDB.UI.NewLabel(Panel4)
		.Multiline = True
		.Common.SetRect 15,20,750,60
		.Caption = "Used when LMS is installed on Server/NAS systems. Note: Linux systems use forward slashes (/) and Windows back slashes (\)"
	End With
	
	Set CheckBox3 = SDB.UI.NewCheckBox(Panel4)
	CheckBox3.Common.SetRect 15,43,110,20
	CheckBox3.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","NAS")
	CheckBox3.Common.ControlName = "EnableNAS"
	CheckBox3.Common.Hint = SDB.Localize("Select if using LMS on a Linux or Windows Server/NAS device. See user guide for more details")
	CheckBox3.Caption = SDB.Localize("LMS Server/NAS")
	CheckBox3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	Set CheckBox4 = SDB.UI.NewCheckBox(Panel4)
	CheckBox4.Common.SetRect 150,43,260,20
	CheckBox4.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Synology")
	CheckBox4.Common.ControlName = "EnableSynology"
	CheckBox4.Common.Hint = SDB.Localize("Select if using Squeezebox Server prior to v7.5.1. Tested on Synology devices only")
	CheckBox4.Caption = SDB.Localize("LMS is prior to v7.5.1 (Linux device only)")
	CheckBox4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	
	With SDB.UI.NewLabel(Panel4)
		.Common.SetRect 15,74,70,20
		.Caption = "MediaMonkey Music Folder:"
	End With
	
	Set Edit13 = SDB.UI.NewEdit(Panel4)
	Edit13.Common.ControlName = "MediaMonkeyMF"
	Edit13.Common.SetRect 148,70,250,25
	Edit13.Text = SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF")
	If Edit13.Text = "" Then
		Edit13.Text = "\\Server\folder or X:\__\__(mapped)"
		SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = "\\Server\folder or X:\__\__(mapped)"
	End If
	Edit13.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit13.Common.Hint = "Copy from MediaMonkey > Track Browser > right click on a song > Properties > Basic > FilePath and copy the first part of the track address"
	
	With SDB.UI.NewLabel(Panel4)
		.Common.SetRect 425,74,70,20
		.Caption = "LMS Media Folder:"
	End With
	
	Set Edit14 = SDB.UI.NewEdit(Panel4)
	Edit14.Common.ControlName = "SqueezeBoxMF"
	Edit14.Common.SetRect 515,70,250,25
	Edit14.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF")
	If Edit14.Text = "" Then
		Edit14.Text = "/___ /___ Linux, or \ ___\ ___ Windows"
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = "/___ /___ Linux, or \ ___\ ___ Windows"
	End If
	Edit14.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
	Edit14.Common.Hint = "Copy from: LMS Web Page > Settings > Basic Settings tab > Music Folder"
	
	Script.RegisterEvent SDB, "OnOptionsChange", "OnSelection" 'Update the Squeezebox player display when the Options window is closed
	'Script.RegisterEvent SDB, "OnChangedSelection", "OnSelection"
	
End Sub
'**************************************************************
Sub SaveSheet(Sheet)
	SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") = Sheet.Common.ChildControl( "EnablePT").Checked
	SDB.IniFile.BoolValue("MonkeySqueeze","Login") = Sheet.Common.ChildControl( "EnableLog").Checked
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = Sheet.Common.ChildControl("SqueezeBoxUser").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = Sheet.Common.ChildControl("SqueezeBoxPass").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = Sheet.Common.ChildControl("SqueezeBoxIP").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = Sheet.Common.ChildControl("SqueezeBoxPort").Text
	SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = Sheet.Common.ChildControl("SqueezeBoxPlayerNo").ItemIndex
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = Sheet.Common.ChildControl("SqueezeBoxPlayer1").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = Sheet.Common.ChildControl("SqueezeBoxMAC").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = Sheet.Common.ChildControl("SqueezeBoxPlayer2").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = Sheet.Common.ChildControl("SqueezeBoxMAC2").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = Sheet.Common.ChildControl("SqueezeBoxPlayer3").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = Sheet.Common.ChildControl("SqueezeBoxMAC3").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = Sheet.Common.ChildControl("SqueezeBoxPlayer4").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = Sheet.Common.ChildControl("SqueezeBoxMAC4").Text
	SDB.IniFile.BoolValue("MonkeySqueeze","NAS") = Sheet.Common.ChildControl( "EnableNAS").Checked
	SDB.IniFile.BoolValue("MonkeySqueeze","Synology") = Sheet.Common.ChildControl( "EnableSynology").Checked
	SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = Sheet.Common.ChildControl("MediaMonkeyMF").Text
	SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = Sheet.Common.ChildControl("SqueezeBoxMF").Text
End Sub
'**************************************************************
Sub ShowPanel10(Item) 
	
	Panel10.Common.Visible = Not Panel10.Common.Visible 
	Mnu3.Checked = Panel10.Common.Visible 
End Sub 
'************************************************************** 
Sub ClosePanel10(Item)
	
	Mnu3.Checked = False 
End Sub 
'************************************************************** 
Sub OnSelection
	If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
		SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive") = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")			
	End If
	
	Mnu2.Caption = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive")
	Label1.Caption = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayerActive")
End Sub
'**************************************************************
Sub UserGuide
	On Error Resume Next
	Dim OF, FolderToOpen
	
	Set OF = CreateObject("Shell.Application")
	FolderToOpen = sdb.ScriptsPath & "Auto\"
	OF.Explore FolderToOpen
	Set OF = Nothing
End Sub
'**************************************************************
Function SqueezeBoxMode
	Dim strRetVal
	
	On Error Resume Next
	SqueezeBoxMode = ""
	strRetVal = slimRequest(formatCommand("""mode"", ""?"""))
	If InStrRev(strRetVal, "play") > 0 Then
		SqueezeBoxMode = "play"
	ElseIf InStrRev(strRetVal, "stop") > 0 Then
		SqueezeBoxMode = "stop"
	ElseIf InStrRev(strRetVal, "pause") > 0 Then
		SqueezeBoxMode = "pause"
	End If
End Function
'**************************************************************
Sub ShowPlayerSettings
	Dim Plr, Warning, Res
	
	Warning = ""
	Set Plr = SDB.Player
	'If Plr.isAutoDJ    Then Warning = Warning & vbNewLine & "AutoDJ is on"
	If Plr.isCrossFade Then Warning = Warning & vbNewLine & "CrossFade is on"
	If Plr.isShuffle   Then Warning = Warning & vbNewLine & "Shuffle is on"
	If Plr.isEqualizer Then Warning = Warning & vbNewLine & "Equalizer is on"
	If Plr.isRepeat    Then Warning = Warning & vbNewLine & "Repeat is on"
	If Warning <> "" Then
		Res = SDB.MessageBox("Selected player settings:" & vbNewLine & _
		Warning, mtWarning, Array(mbOk))
	End If
End Sub
'**************************************************************
Function SyncToggle( itm )
	
	If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
		SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
		itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
		Call registerEvents
		If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""1"""))
		ShowPlayerSettings
		FillPlaylist
	Else
		SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
		itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
		Call unregisterEvents
		slimRequest(formatCommand("""stop"""))
		If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
	End If
End Function
'**************************************************************
Sub Event_OnPlay
	Dim strRetVal, Idx
	
	If (SqueezeBoxMode = "play") And EndOfTrack Then
		'*** normal playlist continuation
		EndOfTrack = False
	Else
		'*** Squeezebox is not playing or new track out of order
		Idx = SDB.Player.CurrentSongIndex
		slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
	End If
End Sub
'**************************************************************
Sub Event_OnTrackEnd
	Dim strRetVal, idx, tim, dur
	
	'*** see if current track ended, then playing is not interrupted
	EndOfTrack = True
End Sub
'**************************************************************
Function CheckPath(SongValue)
	If Left(SongValue.Path,1) = "?" Then
		If SongValue.Cached Then
			CheckPath = SongValue.CachedPath
		Else
			CheckPath = SongValue.Path
		End If
	Else
		CheckPath = SongValue.Path
	End If
	If SDB.IniFile.BoolValue("MonkeySqueeze","NAS") Then
		If SDB.IniFile.BoolValue("MonkeySqueeze","Synology") Then CheckPath = Replace(CheckPath,"\","/")
		CheckPath = Replace(CheckPath,SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF"),SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF"))
	End If
End Function
'**************************************************************
Sub Event_OnStop
	slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnShutdown
	On Error Resume Next
	slimRequest(formatCommand("""stop"""))
	If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
End Sub
'**************************************************************
Sub Event_OnPause
	
	If SDB.Player.IsPaused Then
		slimRequest(formatCommand("""pause"""))
	Else
		slimRequest(formatCommand("""play"""))
	End If
End Sub
'**************************************************************
Sub Event_OnSeek
	Dim SBmode, Song, TrackPath, LMStime
	
	SBmode = SqueezeBoxMode
	If SBmode = "stop" Then
		Set Song = SDB.Player.CurrentSong
		TrackPath = CheckPath(Song)
		slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
	End If
	LMStime = 0.001 * SDB.Player.PlaybackTime
	slimRequest(formatCommand("""time"", """ + CStr(LMStime) + """"))
End Sub
'**************************************************************
Function slimRequest(params)
	'slimRequest accepts pre-formatted parameter string, returns string of the response'
	'logme "  >> slimRequest: Begin with " + params
	Dim url, prog, objHTTP
	Dim cnt : cnt = 0
	
	If SDB.IniFile.BoolValue("MonkeySqueeze","Login") = True Then
		url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") + "@" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
	Else
		url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
	End If
	
	'Set prog = SDB.Objects("LoadXMLBar")
	Set prog = SDB.Progress
	Set objHTTP = CreateObject("Microsoft.XMLHTTP")
	Call objHTTP.open("POST", url, True)
	objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	objHTTP.setRequestHeader "X-Requested-With", "XMLHttpRequest"
	objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
	objHTTP.send(params)
	
	Do While (objHTTP.readyState < 4) And (cnt < 300)
		Call SDB.Tools.Sleep(100)
		SDB.ProcessMessages
		cnt = cnt+1
		If prog.Terminate Then
			cnt = 300
		End If
	Loop
	
	If objHTTP.readyState < 4 Then
		Set slimRequest = Nothing
	Else
		slimRequest = objHTTP.responseText
	End If
End Function
'*************************************************************
'This is is a JSON RPC call - We're directly calling functions in the Slim::Request module in Perl. See here:
'http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm
'the addDispatch section tells you how to use the commands and what the RPC module is looking for in terms of formatting
Function formatCommand(str1)
	If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") + """,[" + str1 + "]]}"
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") + """,[" + str1 + "]]}"
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") + """,[" + str1 + "]]}"
	ElseIf SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
		formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") + """,[" + str1 + "]]}"
	End If
	
End Function
'*************************************************************
'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
	Dim fso, logf
	
	On Error Resume Next
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
	logf.WriteLine Now() & ": " & msg
	Set fso = Nothing
	Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to Squeezebox)
Function perlEscape(str1)
	perlEscape = Replace(str1, "\", "\\")
End Function
'*************************************************************
Sub registerEvents
	Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
	Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
	Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
	Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
	Call Script.RegisterEvent(SDB,"OnTrackEnd","Event_OnTrackEnd")
	Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
	Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub
'*************************************************************
Sub Event_OnNowPlayingModified
	Dim MMcount
	
	MMcount = SDB.Player.CurrentPlayList.Count
	'logme("Now playing modified")
	'logme("Aantal MM tracks: " & Cstr(MMcount))
	'logme("Aantal LMS tracks: " & Cstr(LMScount))
	If SqueezeBoxMode = "stop" Then
		FillPlaylist
	ElseIf MMcount = 0 Then
		ResetPlaylist
	ElseIf MMcount < LMScount Then
		TracksDeleted(MMcount)
	ElseIf MMcount > LMScount Then
		TracksAdded(MMcount)
	Else
		TracksMoved
	End If
End Sub
'*************************************************************
Sub FillPlaylist
	'*** synchronize MM playlist with LMS playlist
	Dim tempStop, Idx
	
	'*** clear LMS playlist and stop shuffle!!
	slimRequest(formatCommand("""playlist"", ""clear"""))
	slimRequest(formatCommand("""playlist"", ""shuffle"", ""0"""))
	'*** copy MM playlist - if any - to LMS
	LMScount = SDB.Player.CurrentPlayList.Count
	ReDim LMSpaths(LMScount)
	'*** if playlist is empty we are done
	If LMScount > 0 Then
		tempStop = SDB.Player.isPlaying And (SDB.Player.PlayBackTime < 2000)
		If tempStop Then
			SDB.Player.pause
			slimRequest(formatCommand("""stop"""))
		End If
		SendPlaylist
		'*** jump to current song
		Idx = SDB.Player.CurrentSongIndex
		slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
		If tempStop Then
			'*** Start playback after filling playlist
			SDB.Player.Pause
		ElseIf SDB.Player.isPlaying Then
			'*** Synchronize LMS with current track
			slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001) + """"))
			If SDB.Player.isPaused Then SDB.Player.Pause
		Else
			'*** MediaMonkey is not playing
			slimRequest(formatCommand("""stop"""))
		End If
	End If
	EndOfTrack = False
End Sub
'**************************************************************
Sub SendPlaylist
	Dim Progr, TrackPath, Song, n
	
	'*** show progress bar
	Set Progr = SDB.Progress
	Progr.Text = SDB.Localize("Synchronising playlists...")
	Progr.MaxValue = LMScount
	'*** send playlist
	For n=0 To LMScount-1
		Set Song = SDB.Player.CurrentPlayList.Item(n)
		TrackPath = CheckPath(Song)
		LMSpaths(n) = TrackPath
		slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
		Progr.Value = n+1
	Next
End Sub
'**************************************************************
Sub ResetPlaylist
	
	SDB.Player.Stop
	slimRequest(formatCommand("""stop"""))
	slimRequest(formatCommand("""playlist"", ""clear"""))
	ReDim LMSpaths(0)
	LMScount = 0
End Sub
'**************************************************************
Sub TracksDeleted(MMcount)
	Dim n, m, Song, TrackPath
	
	'logme("Tracks deleted")
	n = 0
	Do While MMcount < LMScount
		If n = MMcount Then
			TrackPath = "***"
		Else
			Set Song = SDB.Player.CurrentPlayList.Item(n)
			TrackPath = CheckPath(Song)
		End If
		If (TrackPath = LMSpaths(n)) Then
			n = n+1
		Else
			LMScount = LMScount - 1
			For m = n To LMScount - 1
				LMSpaths(m) = LMSpaths(m+1)
			Next
			slimRequest(formatCommand("""playlist"", ""delete"", """ + CStr(n) + """"))
		End If
	Loop
End Sub
'*************************************************************
Sub TracksAdded(MMcount)
	Dim n, m, Song, TrackPath
	
	'logme("Tracks added")
	ReDim Preserve LMSpaths(MMcount)  'expand array, preserve content
	Do
		For n = 0 To MMcount -1
			Set Song = SDB.Player.CurrentPlayList.Item(n)
			TrackPath = CheckPath(Song)
			If (TrackPath <> LMSpaths(n)) Then
				slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
				If n < LMScount Then
					slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(LMScount) + """, """ + CStr(n) + """"))
					For m = LMScount To n+1 Step -1
						LMSpaths(m) = LMSpaths(m-1)
					Next
				End If
				LMSpaths(n) = TrackPath
				LMScount = LMScount + 1
			End If
		Next
	Loop While MMcount > LMScount
End Sub
'*************************************************************
Sub TracksMoved
	Dim n, m, i, Song, TrackPath, tempPath
	
	'logme("Tracks moved")
	For n=0 To LMScount-1
		Set Song = SDB.Player.CurrentPlayList.Item(n)
		TrackPath = CheckPath(Song)
		If TrackPath <> LMSpaths(n) Then
			For m=n+1 To LMScount-1
				If TrackPath = LMSpaths(m) Then Exit For
			Next
			For i=m To n+1 Step -1
				LMSpaths(i) = LMSpaths(i-1)
			Next
			LMSpaths(n) = TrackPath
			slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(m) + """, """ + CStr(n) + """"))
		End If
	Next
End Sub
'*************************************************************
Sub unregisterEvents
	Script.UnregisterEvents SDB
End Sub
'*************************************************************
'These are what the full JSON strings look like that need to be sent to slimRequest()
'formatRequest() fills in the first part and all you have to do is pick the RPC commands from http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm

'Note: there are cleaner ways of doing this - but this is quick and dirty. It just means that you have to use a lot of """ and etc in vbscript.
'This entire script is much easier to write in jscript but I don't know jscript at all so, shrug.

'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:cgABbehldiqtyrSuoKLN"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:uB"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["playlist","index",28]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["pause"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",[""playlist"", ""play"", ""D:\\MP3\\filename.mp3""]]}


'You can do ANYTHING you can do from the web interface via this RPC engine because you are directly calling the methods in Perl
'so you could add whole playlists and etc see the docs. Sky's the limit.

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Sat May 30, 2015 10:40 pm

Offical release - 3.1.0

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Thu May 28, 2015 11:25 pm

oeyoeve wrote:Hi, I've tested 3.1.0 and it works! :-)
My only immediate reflections/comments are these;

Music is played both through LMS and through my local PC speakers simultaneously. I don't think previous versions did that. Since there is no way to make them play in sync (and for me that is not important either), so I mute my PC. But why have them both playing? Streaming in two directions only increases network traffic, and since it really doesn't make much sense, perhaps you should reconsider?
Nothing has changed in the script for this to occur. LMS is a server and cannot play music, it needs to be played by a Squeezebox player. Did you have SqueezePlay (or other SB software player) and MediaMonkey running at the same time?
oeyoeve wrote:I used some time to figure out what should be put in the field "Select the Squeezebox Player you wish to connect to". Since all you can really do, is to select between Player 1,2,3 or 4, the ability to edit the whole text field only increases the chance of error (typo). Perhaps you should only allow for a numeric field that only accepts the numbers 1 through 4 ?
The "Select the Squeezebox Player you wish to connect to:" box is a dropdown box and is not meant for text entry. You are meant to enter the Squeezebox player name and MAC address into the text boxes below and then select one of the players from the dropdown box.
oeyoeve wrote:Last and least, if I control playback using any other controller while MM is connected, it gets confused and fails to keep up :-)
When MediaMonkey is connected to the Squeezebox system all control needs to be done via MediaMonkey only, any attempt at control through LMS/Squeezebox will cause the issues explained.

I released the official version on Wednesday, so download and install it and read the fully revised and updated user guide to clarify any issues above.

Thanks for taking the time to provide the feedback.

Cheers
Gingernut63

Re: MonkeySqueeze Development V3.1.0

by oeyoeve » Thu May 28, 2015 1:42 pm

Hi, I've tested 3.1.0 and it works! :-)
My only immediate reflections/comments are these;

Music is played both through LMS and through my local PC speakers simultaneously. I don't think previous versions did that. Since there is no way to make them play in sync (and for me that is not important either), so I mute my PC. But why have them both playing? Streaming in two directions only increases network traffic, and since it really doesn't make much sense, perhaps you should reconsider?

I used some time to figure out what should be put in the field "Select the Squeezebox Player you wish to connect to". Since all you can really do, is to select between Player 1,2,3 or 4, the ability to edit the whole text field only increases the chance of error (typo). Perhaps you should only allow for a numeric field that only accepts the numbers 1 through 4 ?

Last and least, if I control playback using any other controller while MM is connected, it gets confused and fails to keep up :-)

In summary, good work!

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Mon May 25, 2015 5:18 am

oeyoeve wrote:Hi, I went back to V3.1.0.150518Beta as you suggested, and retyped the username:password and now it works :-)
You are a genious! Thanks you so much!

rgds
Viking
Fabulous! There is wonderful feeling when something works for the first time. :D

When you get a chance, could you give the latest beta a go and give me your opinion, no rush.

Cheers
Gingernut63

Re: MonkeySqueeze Development V3.1.0

by oeyoeve » Mon May 25, 2015 4:32 am

Hi, I went back to V3.1.0.150518Beta as you suggested, and retyped the username:password and now it works :-)
You are a genious! Thanks you so much!

rgds
Viking

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Mon May 25, 2015 12:18 am

Latest Beta release V3.1.0.150525

The current version of the script is optimised for MediaMonkey 4 and above.

If you haven't used a Beta just follow the instructions below, it's easy. Try a Beta, they're safe and you'll be helping with the development.

Release improvements:
- Complete redesign of the options page to reduce size for small screen use i.e. tablets
- Disable communication settings on the options page when MonkeySqueeze is enabled
- The ability to connect to one of four pre-configured SqueezeBox players each session - Connection info and selection on the Options page
- Added the ability to log into a password protected LMS/Squeezebox system. Data entered on the MonkeySqueeze Options page
- General tidy of the script
- Roll back to V3.0.1 - Changes in V3.0.1.120314Beta removed


Systems tested and working on:
PC (Win 7) - No server/NAS
PC (Win 7) + Windows Server 2008 (WHS 2011)
PC (Win 7) + Linux NAS (ReadyNAS Duo)
Tablet (Win 8.1) + Windows Server 2008 (WHS 2011)
Tablet (Win 8.1) + Linux NAS (ReadyNAS Duo)

Known Issues:

None at this stage

To use this version:

Copy the script to Notepad and save as MonkeySqueeze.vbs to one one of the following locations:
C:\Program Files\MediaMonkey\Scripts\Auto or C:\Program Files (x86)\MediaMonkey\Scripts\Auto

Make sure you disable or remove the existing MonkeySqueeze.vbs

If you use this script please report on this forum if it runs OK or if you had any issues. Feedback is appreciated so I can implement changes before any official release.

Code: Select all

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' MonkeySqueeze V3.1.0.150525Beta
'
' MOD DATE: 24.05.2015
'
' Script: Development has occurred in two distinct stages: As Squeezebox Controller from 2007 to 2009; and as MonkeySqueeze from 2011 on. 
' Major changes have occurred to the script since 2011 and it bears little resemblance to the original Squeezebox Controller.
' 
' DATE STARTED: 26.09.2007
'
' Squeezebox Controller: Todd Nemeth    Mods: Baz, Big_Berny, Peke, trixmoto, debacle, mccstumble
' MonkeySqueeze: Gingernut63, booblers, Katteman
'
' COMMENT:
'  - You will also need Logitech Media Server (Squeezebox Server) installed and running
'  - Optional: Install and run SqueezePlay or SoftSqueeze
'  - After installation the options page for this script is located at Tools > Options > MonkeySqueeze
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit
Public EndOfTrack, LMScount, LMSpaths()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim onMonkeySqueezeIcon
Dim offMonkeySqueezeIcon

'**************************************************************
Sub OnStartup
  Dim ind, Mnu
  Dim UI : Set UI = SDB.UI
  
  onMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
  If onMonkeySqueezeIcon < 0 Then
    onMonkeySqueezeIcon = 74 'unlocked icon if it doesn't exist
  End If
  
  offMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
  If offMonkeySqueezeIcon < 0 Then
    offMonkeySqueezeIcon = 75 'locked icon if it doesn't exist
  End If
  
  Set Mnu = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
  Mnu.Caption = "MonkeySqueeze"
  Mnu.UseScript = Script.ScriptPath
  Mnu.OnClickFunc = "SyncToggle"
  Mnu.IconIndex = offMonkeySqueezeIcon
  Mnu.Hint = "Enable/Disable MonkeySqueeze"
  
  Set SDB.Objects("MonkeySqueezeIcon") = Mnu  'save a reference to it so we can change the icon later.
  SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  ind = SDB.UI.AddOptionSheet("MonkeySqueeze",Script.ScriptPath,"InitSheet","SaveSheet",-2)
  
  'logme(slimRequest(formatCommand("""version"",""?""")))
End Sub

'**************************************************************
Sub InitSheet(Sheet)
  Dim form, Panel1, Panel2, Panel3, Panel4, Panel5, Btn1, Checkbox1, Checkbox2, Checkbox3, Checkbox4, Edit1, Edit2, Edit3, Edit4, Edit5, Edit6, Edit7, Edit8, Edit9, Edit10, Edit11, Edit12, Edit13, Edit14, Combo1
  
  Set Panel1 = SDB.UI.NewGroupBox(Sheet)
  Panel1.Common.SetRect 10,5,780,55
  Panel1.Caption = "MonkeySqueeze V3.1.0. -  General Settings"
  
  Set CheckBox1 = SDB.UI.NewCheckBox(Panel1)
  CheckBox1.Common.SetRect 15,20,150,20
  CheckBox1.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle")
  CheckBox1.Common.ControlName = "EnablePT"
  CheckBox1.Common.Hint = SDB.Localize("When selected if MonkeySqueeze is enabled, the primary Squeezebox device will power on, and on/off at startup/shutdown. When MonkeySqueeze is disabled, the selected Squeezebox player will power off.")
  CheckBox1.Caption = SDB.Localize("Power Toggle")
  
  Set CheckBox2 = SDB.UI.NewCheckBox(Panel1)
  CheckBox2.Common.SetRect 125,20,65,20
  CheckBox2.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Login")
  CheckBox2.Common.ControlName = "EnableLog"
  CheckBox2.Common.Hint = SDB.Localize("This will enable MonkeySqueeze to log into a password protected LMS/Squeezebox system.")
  CheckBox2.Caption = SDB.Localize("LMS Login")
  CheckBox2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
    
  With SDB.UI.NewLabel(Panel1)
    .Common.SetRect 200,23,60,20
    .Caption = "Username:"
  End With
  
  Set Edit1 = SDB.UI.NewEdit(Panel1)
  Edit1.Common.ControlName = "SqueezeBoxUser"
  Edit1.Common.SetRect 255,19,95,25
  Edit1.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser")
  If Edit1.Text = "" Then
    Edit1.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = ""
  End If
  Edit1.Common.Hint = "Type the LMS username here"
  
  With SDB.UI.NewLabel(Panel1)
    .Common.SetRect 363,23,60,20
    .Caption = "Password:"
  End With
  Edit1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  Set Edit2 = SDB.UI.NewEdit(Panel1)
  Edit2.Common.ControlName = "SqueezeBoxPass"
  Edit2.Common.SetRect 415,19,95,25
  Edit2.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass")
  If Edit2.Text = "" Then
    Edit2.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = ""
  End If
  Edit2.PasswordChar = "*"
  Edit2.Common.Hint = "Type the LMS password here"
  Edit2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
   
   Set Btn1 = SDB.UI.NewButton(Panel1)
  Btn1.Common.SetRect 700,17,65,25
  Btn1.Caption = "User Guide"
  Btn1.Common.Hint = "Click and then open MonkeySqueeze_UserGuide.pdf"
  Script.RegisterEvent Btn1, "OnClick", "UserGuide"
  
  Set Panel2 = SDB.UI.NewGroupBox(Sheet)
  Panel2.Common.SetRect 10,65,780,75
  Panel2.Caption = "LMS Communication Settings"
  
  With SDB.UI.NewLabel(Panel2)
    .Multiline = True
    .Common.SetRect 15,20,750,50
    .Caption = "Address/Hostname and port number located at the LMS Web page > Settings > Information tab"
  End With
  
  With SDB.UI.NewLabel(Panel2)
    .Common.SetRect 15,44,70,20
    .Caption = "IP Address:"
  End With
  
  Set Edit3 = SDB.UI.NewEdit(Panel2)
  Edit3.Common.ControlName = "SqueezeBoxIP"
  Edit3.Common.SetRect 75,40,110,25
  Edit3.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP")
  If Edit3.Text = "" Then
    Edit3.Text = "XXX.XXX.XXX.XXX"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = "XXX.XXX.XXX.XXX"
  End If
  Edit3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit3.Common.Hint = "Copy and paste the LMS IP Address or Hostname here"
  
  With SDB.UI.NewLabel(Panel2)
    .Common.SetRect 215,44,70,20
    .Caption = "HTTP Port No:"
  End With
  
  Set Edit4 = SDB.UI.NewEdit(Panel2)
  Edit4.Common.ControlName = "SqueezeBoxPort"
  Edit4.Common.SetRect 287,40,40,25
  Edit4.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort")
  If Edit4.Text = "" Then
    Edit4.Text = "9000"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = "9000"
  End If
  Edit4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit4.Common.Hint = "HTTP port default is 9000. View the port number in LMS: Web Control page > Settings > Information tab and change if required"
  
  Set Panel3 = SDB.UI.NewGroupBox(Sheet)
  Panel3.Common.SetRect 10,145,780,135
  Panel3.Caption = "Squeezebox Player Settings"
  
  With SDB.UI.NewLabel(Panel3)
    .Multiline = True
    .Common.SetRect 15,20,750,60
    .Caption = "The name and MAC address of the players (Touch, SqueezePlay, etc...) to connect to. Only one player connection per session."
  End With
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 15,45,100,20
    .Caption = "Select the Squeezebox Player you wish to connect to:"
  End With
  
  Set Combo1 = SDB.UI.NewDropdown(Panel3)
  Combo1.Common.SetRect 277,42,75,25
  Combo1.Style = 1     ' List style 1 or 2
  Combo1.AddItem "Player 1"
  Combo1.AddItem "Player 2"
  Combo1.AddItem "Player 3"
  Combo1.AddItem "Player 4"
  Combo1.Common.ControlName = "SqueezeBoxPlayerNo"
  Combo1.ItemIndex = SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo")'Players 1 to 4 use integer values 0 to 3
  Combo1.Common.Hint = "The players are listed below"
  Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 15,79,60,20
    .Caption = "Player 1 Name:"
  End With
  
  Set Edit5 = SDB.UI.NewEdit(Panel3)
  Edit5.Common.ControlName = "SqueezeBoxPlayer1"
  Edit5.Common.SetRect 90,75,100,25
  Edit5.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
  If Edit5.Text = "" Then
    Edit5.Text = " "
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = " "
  End If
  Edit5.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 15,102,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit6 = SDB.UI.NewEdit(Panel3)
  Edit6.Common.ControlName = "SqueezeBoxMAC"
  Edit6.Common.SetRect 90,98,100,25
  Edit6.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC")
  If Edit6.Text = "" Then
    Edit6.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit6.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 200,79,60,20
    .Caption = "Player 2 Name:"
  End With
  
  Set Edit7 = SDB.UI.NewEdit(Panel3)
  Edit7.Common.ControlName = "SqueezeBoxPlayer2"
  Edit7.Common.SetRect 275,75,100,25
  Edit7.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
  If Edit7.Text = "" Then
    Edit7.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = ""
  End If
  Edit7.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 200,102,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit8 = SDB.UI.NewEdit(Panel3)
  Edit8.Common.ControlName = "SqueezeBoxMAC2"
  Edit8.Common.SetRect 275,98,100,25
  Edit8.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2")
  If Edit8.Text = "" Then
    Edit8.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit8.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 385,79,60,20
    .Caption = "Player 3 Name:"
  End With
  
  Set Edit9 = SDB.UI.NewEdit(Panel3)
  Edit9.Common.ControlName = "SqueezeBoxPlayer3"
  Edit9.Common.SetRect 460,75,110,25
  Edit9.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
  If Edit9.Text = "" Then
    Edit9.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = ""
  End If
  Edit9.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 385,102,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit10 = SDB.UI.NewEdit(Panel3)
  Edit10.Common.ControlName = "SqueezeBoxMAC3"
  Edit10.Common.SetRect 460,98,110,25
  Edit10.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3")
  If Edit10.Text = "" Then
    Edit10.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit10.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 580,79,60,20
    .Caption = "Player 4 Name:"
  End With
  
  Set Edit11 = SDB.UI.NewEdit(Panel3)
  Edit11.Common.ControlName = "SqueezeBoxPlayer4"
  Edit11.Common.SetRect 655,75,110,25
  Edit11.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
  If Edit11.Text = "" Then
    Edit11.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = ""
  End If
  Edit11.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 580,102,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit12 = SDB.UI.NewEdit(Panel3)
  Edit12.Common.ControlName = "SqueezeBoxMAC4"
  Edit12.Common.SetRect 655,98,110,25
  Edit12.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4")
  If Edit12.Text = "" Then
    Edit12.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit12.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  Set Panel4 = SDB.UI.NewGroupBox(Sheet)
  Panel4.Common.SetRect 10,285,780,105
  Panel4.Caption = "LMS Server/NAS Systems"
  
  With SDB.UI.NewLabel(Panel4)
    .Multiline = True
    .Common.SetRect 15,20,750,60
    .Caption = "Used when LMS is installed on Server/NAS systems. Note: Linux systems use forward slashes (/) and Windows back slashes (\)"
  End With
  
  Set CheckBox3 = SDB.UI.NewCheckBox(Panel4)
  CheckBox3.Common.SetRect 15,43,110,20
  CheckBox3.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","NAS")
  CheckBox3.Common.ControlName = "EnableNAS"
  CheckBox3.Common.Hint = SDB.Localize("Select if using LMS on a Linux or Windows Server/NAS device. See user guide for more details")
  CheckBox3.Caption = SDB.Localize("LMS Server/NAS")
  CheckBox3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  Set CheckBox4 = SDB.UI.NewCheckBox(Panel4)
  CheckBox4.Common.SetRect 150,43,260,20
  CheckBox4.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Synology")
  CheckBox4.Common.ControlName = "EnableSynology"
  CheckBox4.Common.Hint = SDB.Localize("Select if using Squeezebox Server prior to v7.5.1. Tested on Synology devices only")
  CheckBox4.Caption = SDB.Localize("LMS is prior to v7.5.1 (Linux device only)")
  CheckBox4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,74,70,20
    .Caption = "MediaMonkey Music Folder:"
  End With
  
  Set Edit13 = SDB.UI.NewEdit(Panel4)
  Edit13.Common.ControlName = "MediaMonkeyMF"
  Edit13.Common.SetRect 148,70,250,25
  Edit13.Text = SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF")
  If Edit13.Text = "" Then
    Edit13.Text = "\\Server\folder or X:\__\__(mapped)"
    SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = "\\Server\folder or X:\__\__(mapped)"
  End If
  Edit13.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit13.Common.Hint = "Copy from MediaMonkey > File > Add/Rescan Folders or the Path column in the Track Browser section"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 425,74,70,20
    .Caption = "LMS Media Folder:"
  End With
  
  Set Edit14 = SDB.UI.NewEdit(Panel4)
  Edit14.Common.ControlName = "SqueezeBoxMF"
  Edit14.Common.SetRect 515,70,250,25
  Edit14.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF")
  If Edit14.Text = "" Then
    Edit14.Text = "/___ /___ Linux, or \ ___\ ___ Windows"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = "/___ /___ Linux, or \ ___\ ___ Windows"
  End If
  Edit14.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit14.Common.Hint = "Copy and Paste from: LMS Web Page > Settings > Basic Settings tab > Music Folder"
  
End Sub
'**************************************************************
Sub SaveSheet(Sheet)
  SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") = Sheet.Common.ChildControl( "EnablePT").Checked
  SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = Sheet.Common.ChildControl("SqueezeBoxPlayerNo").ItemIndex
  SDB.IniFile.BoolValue("MonkeySqueeze","Login") = Sheet.Common.ChildControl( "EnableLog").Checked
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = Sheet.Common.ChildControl("SqueezeBoxUser").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = Sheet.Common.ChildControl("SqueezeBoxPass").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = Sheet.Common.ChildControl("SqueezeBoxIP").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = Sheet.Common.ChildControl("SqueezeBoxPort").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = Sheet.Common.ChildControl("SqueezeBoxPlayer1").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = Sheet.Common.ChildControl("SqueezeBoxMAC").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = Sheet.Common.ChildControl("SqueezeBoxPlayer2").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = Sheet.Common.ChildControl("SqueezeBoxMAC2").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = Sheet.Common.ChildControl("SqueezeBoxPlayer3").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = Sheet.Common.ChildControl("SqueezeBoxMAC3").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = Sheet.Common.ChildControl("SqueezeBoxPlayer4").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = Sheet.Common.ChildControl("SqueezeBoxMAC4").Text
  SDB.IniFile.BoolValue("MonkeySqueeze","NAS") = Sheet.Common.ChildControl( "EnableNAS").Checked
  SDB.IniFile.BoolValue("MonkeySqueeze","Synology") = Sheet.Common.ChildControl( "EnableSynology").Checked
  SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = Sheet.Common.ChildControl("MediaMonkeyMF").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = Sheet.Common.ChildControl("SqueezeBoxMF").Text
End Sub
'**************************************************************
Sub UserGuide
  On Error Resume Next
  Dim OF, FolderToOpen
  
  Set OF = CreateObject("Shell.Application")
  FolderToOpen = sdb.ScriptsPath & "Auto\"
  OF.Explore FolderToOpen
  Set OF = Nothing
End Sub
'**************************************************************
Function SqueezeBoxMode
  Dim strRetVal
  
  On Error Resume Next
  SqueezeBoxMode = ""
  strRetVal = slimRequest(formatCommand("""mode"", ""?"""))
  If InStrRev(strRetVal, "play") > 0 Then
    SqueezeBoxMode = "play"
  ElseIf InStrRev(strRetVal, "stop") > 0 Then
    SqueezeBoxMode = "stop"
  ElseIf InStrRev(strRetVal, "pause") > 0 Then
    SqueezeBoxMode = "pause"
  End If
End Function
'**************************************************************
Sub ShowPlayerSettings
  Dim Plr, Warning, Res
  
  Warning = ""
  Set Plr = SDB.Player
  'If Plr.isAutoDJ    Then Warning = Warning & vbNewLine & "AutoDJ is on"
  If Plr.isCrossFade Then Warning = Warning & vbNewLine & "CrossFade is on"
  If Plr.isShuffle   Then Warning = Warning & vbNewLine & "Shuffle is on"
  If Plr.isEqualizer Then Warning = Warning & vbNewLine & "Equalizer is on"
  If Plr.isRepeat    Then Warning = Warning & vbNewLine & "Repeat is on"
  If Warning <> "" Then
    Res = SDB.MessageBox("Selected player settings:" & vbNewLine & _
    Warning, mtWarning, Array(mbOk))
  End If
End Sub
'**************************************************************
Function SyncToggle( itm )
  
  If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
    SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
    itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
    Call registerEvents
    If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""1"""))
    ShowPlayerSettings
    FillPlaylist
  Else
    SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
    itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
    Call unregisterEvents
    slimRequest(formatCommand("""stop"""))
    If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
  End If
End Function
'**************************************************************
Sub Event_OnPlay
  Dim strRetVal, Idx
  
  If (SqueezeBoxMode = "play") And EndOfTrack Then
    '*** normal playlist continuation
    EndOfTrack = False
  Else
    '*** Squeezebox is not playing or new track out of order
    Idx = SDB.Player.CurrentSongIndex
    slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
  End If
End Sub
'**************************************************************
Sub Event_OnTrackEnd
  Dim strRetVal, idx, tim, dur
  
  '*** see if current track ended, then playing is not interrupted
  EndOfTrack = True
End Sub
'**************************************************************
Function CheckPath(SongValue)
  If Left(SongValue.Path,1) = "?" Then
    If SongValue.Cached Then
      CheckPath = SongValue.CachedPath
    Else
      CheckPath = SongValue.Path
    End If
  Else
    CheckPath = SongValue.Path
  End If
  If SDB.IniFile.BoolValue("MonkeySqueeze","NAS") Then
    If SDB.IniFile.BoolValue("MonkeySqueeze","Synology") Then CheckPath = Replace(CheckPath,"\","/")
    CheckPath = Replace(CheckPath,SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF"),SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF"))
  End If
End Function
'**************************************************************
Sub Event_OnStop
  slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnShutdown
  On Error Resume Next
  slimRequest(formatCommand("""stop"""))
  If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
End Sub
'**************************************************************
Sub Event_OnPause
  
  If SDB.Player.IsPaused Then
    slimRequest(formatCommand("""pause"""))
  Else
    slimRequest(formatCommand("""play"""))
  End If
End Sub
'**************************************************************
Sub Event_OnSeek
  Dim SBmode, Song, TrackPath, LMStime
  
  SBmode = SqueezeBoxMode
  If SBmode = "stop" Then
    Set Song = SDB.Player.CurrentSong
    TrackPath = CheckPath(Song)
    slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
  End If
  LMStime = 0.001 * SDB.Player.PlaybackTime
  slimRequest(formatCommand("""time"", """ + CStr(LMStime) + """"))
End Sub
'**************************************************************
Function slimRequest(params)
  'slimRequest accepts pre-formatted parameter string, returns string of the response'
  'logme "  >> slimRequest: Begin with " + params
  Dim url, prog, objHTTP
  Dim cnt : cnt = 0
  
  If SDB.IniFile.BoolValue("MonkeySqueeze","Login") = True Then
    url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") + "@" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
  Else
    url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
  End If
  
  'Set prog = SDB.Objects("LoadXMLBar")
  Set prog = SDB.Progress
  Set objHTTP = CreateObject("Microsoft.XMLHTTP")
  Call objHTTP.open("POST", url, True)
  objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  objHTTP.setRequestHeader "X-Requested-With", "XMLHttpRequest"
  objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
  objHTTP.send(params)
  
  Do While (objHTTP.readyState < 4) And (cnt < 300)
    Call SDB.Tools.Sleep(100)
    SDB.ProcessMessages
    cnt = cnt+1
    If prog.Terminate Then
      cnt = 300
    End If
  Loop
  
  If objHTTP.readyState < 4 Then
    Set slimRequest = Nothing
  Else
    slimRequest = objHTTP.responseText
  End If
End Function
'*************************************************************
'This is is a JSON RPC call - We're directly calling functions in the Slim::Request module in Perl. See here:
'http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm
'the addDispatch section tells you how to use the commands and what the RPC module is looking for in terms of formatting
Function formatCommand(str1)
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") + """,[" + str1 + "]]}"
  End If
  
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") + """,[" + str1 + "]]}"
  End If
  
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") + """,[" + str1 + "]]}"
  End If
  
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") + """,[" + str1 + "]]}"
  End If
  
End Function
'*************************************************************
'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
  Dim fso, logf
  
  On Error Resume Next
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
  logf.WriteLine Now() & ": " & msg
  Set fso = Nothing
  Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to Squeezebox)
Function perlEscape(str1)
  perlEscape = Replace(str1, "\", "\\")
End Function
'*************************************************************
Sub registerEvents
  Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
  Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
  Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
  Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
  Call Script.RegisterEvent(SDB,"OnTrackEnd","Event_OnTrackEnd")
  Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
  Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub
'*************************************************************
Sub Event_OnNowPlayingModified
  Dim MMcount
  
  MMcount = SDB.Player.CurrentPlayList.Count
  'logme("Now playing modified")
  'logme("Aantal MM tracks: " & Cstr(MMcount))
  'logme("Aantal LMS tracks: " & Cstr(LMScount))
  If SqueezeBoxMode = "stop" Then
    FillPlaylist
  ElseIf MMcount = 0 Then
    ResetPlaylist
  ElseIf MMcount < LMScount Then
    TracksDeleted(MMcount)
  ElseIf MMcount > LMScount Then
    TracksAdded(MMcount)
  Else
    TracksMoved
  End If
End Sub
'*************************************************************
Sub FillPlaylist
  '*** synchronize MM playlist with LMS playlist
  Dim tempStop, Idx
  
  '*** clear LMS playlist and stop shuffle!!
  slimRequest(formatCommand("""playlist"", ""clear"""))
  slimRequest(formatCommand("""playlist"", ""shuffle"", ""0"""))
  '*** copy MM playlist - if any - to LMS
  LMScount = SDB.Player.CurrentPlayList.Count
  ReDim LMSpaths(LMScount)
  '*** if playlist is empty we are done
  If LMScount > 0 Then
    tempStop = SDB.Player.isPlaying And (SDB.Player.PlayBackTime < 2000)
    If tempStop Then
      SDB.Player.pause
      slimRequest(formatCommand("""stop"""))
    End If
    SendPlaylist
    '*** jump to current song
    Idx = SDB.Player.CurrentSongIndex
    slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
    If tempStop Then
      '*** Start playback after filling playlist
      SDB.Player.Pause
    ElseIf SDB.Player.isPlaying Then
      '*** Synchronize LMS with current track
      slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001) + """"))
      If SDB.Player.isPaused Then SDB.Player.Pause
    Else
      '*** MediaMonkey is not playing
      slimRequest(formatCommand("""stop"""))
    End If
  End If
  EndOfTrack = False
End Sub
'**************************************************************
Sub SendPlaylist
  Dim Progr, TrackPath, Song, n
  
  '*** show progress bar
  Set Progr = SDB.Progress
  Progr.Text = SDB.Localize("Synchronising playlists...")
  Progr.MaxValue = LMScount
  '*** send playlist
  For n=0 To LMScount-1
    Set Song = SDB.Player.CurrentPlayList.Item(n)
    TrackPath = CheckPath(Song)
    LMSpaths(n) = TrackPath
    slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
    Progr.Value = n+1
  Next
End Sub
'**************************************************************
Sub ResetPlaylist
  
  SDB.Player.Stop
  slimRequest(formatCommand("""stop"""))
  slimRequest(formatCommand("""playlist"", ""clear"""))
  ReDim LMSpaths(0)
  LMScount = 0
End Sub
'**************************************************************
Sub TracksDeleted(MMcount)
  Dim n, m, Song, TrackPath
  
  'logme("Tracks deleted")
  n = 0
  Do While MMcount < LMScount
    If n = MMcount Then
      TrackPath = "***"
    Else
      Set Song = SDB.Player.CurrentPlayList.Item(n)
      TrackPath = CheckPath(Song)
    End If
    If (TrackPath = LMSpaths(n)) Then
      n = n+1
    Else
      LMScount = LMScount - 1
      For m = n To LMScount - 1
        LMSpaths(m) = LMSpaths(m+1)
      Next
      slimRequest(formatCommand("""playlist"", ""delete"", """ + CStr(n) + """"))
    End If
  Loop
End Sub
'*************************************************************
Sub TracksAdded(MMcount)
  Dim n, m, Song, TrackPath
  
  'logme("Tracks added")
  ReDim Preserve LMSpaths(MMcount)  'expand array, preserve content
  Do
    For n = 0 To MMcount -1
      Set Song = SDB.Player.CurrentPlayList.Item(n)
      TrackPath = CheckPath(Song)
      If (TrackPath <> LMSpaths(n)) Then
        slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
        If n < LMScount Then
          slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(LMScount) + """, """ + CStr(n) + """"))
          For m = LMScount To n+1 Step -1
            LMSpaths(m) = LMSpaths(m-1)
          Next
        End If
        LMSpaths(n) = TrackPath
        LMScount = LMScount + 1
      End If
    Next
  Loop While MMcount > LMScount
End Sub
'*************************************************************
Sub TracksMoved
  Dim n, m, i, Song, TrackPath, tempPath
  
  'logme("Tracks moved")
  For n=0 To LMScount-1
    Set Song = SDB.Player.CurrentPlayList.Item(n)
    TrackPath = CheckPath(Song)
    If TrackPath <> LMSpaths(n) Then
      For m=n+1 To LMScount-1
        If TrackPath = LMSpaths(m) Then Exit For
      Next
      For i=m To n+1 Step -1
        LMSpaths(i) = LMSpaths(i-1)
      Next
      LMSpaths(n) = TrackPath
      slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(m) + """, """ + CStr(n) + """"))
    End If
  Next
End Sub
'*************************************************************
Sub unregisterEvents
  Script.UnregisterEvents SDB
End Sub
'*************************************************************
'These are what the full JSON strings look like that need to be sent to slimRequest()
'formatRequest() fills in the first part and all you have to do is pick the RPC commands from http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm

'Note: there are cleaner ways of doing this - but this is quick and dirty. It just means that you have to use a lot of """ and etc in vbscript.
'This entire script is much easier to write in jscript but I don't know jscript at all so, shrug.

'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:cgABbehldiqtyrSuoKLN"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:uB"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["playlist","index",28]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["pause"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",[""playlist"", ""play"", ""D:\\MP3\\filename.mp3""]]}


'You can do ANYTHING you can do from the web interface via this RPC engine because you are directly calling the methods in Perl
'so you could add whole playlists and etc see the docs. Sky's the limit.

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Sun May 24, 2015 6:19 am

Hi Viking

You are not obligated to help, however I appreciate your assistance. Maybe the best thing to do would be to use the beta :
http://www.mediamonkey.com/forum/viewto ... 45#p407942

That way we can concentrate on the login issue, without the multiple player issue. As stated before, the original code introduced a space in the username and password which stopped it from working (fixed in the above beta link). As you have used the problem code, the Username and password with the extra space are now stored in the MediaMonkey.ini file and will populate any new MonkeySqueeze beta file that you load. It is imperative that remove all characters (space included) in the username and password fields on the options page and then re-enter them for the code to work. I had to do this myself and the login has worked without issues for the last week at my home and at work.

Fault finding from a distance is fraught with miss communication issues etc... Do not continue if you find this process frustrating, however I thank you for your help so far. :wink:

Cheers
Gingernut63

Re: MonkeySqueeze Development V3.1.0

by oeyoeve » Sun May 24, 2015 4:51 am

I have now installed V3.1.0.150523Beta but still MM only plays through my local PC speaker when Login is activated.
I am somewhat confused as to what should be typed in the "MediaMonkey is connected to:" box.
First I left it saying "Player 1" which was the default, and then I entered the given name of my player. Still it refused to play except through my PC speaker, but I noticed that when I reopened the Options box, it now says "SqueezeBoxPlayerNo". I didn't type that in there, so I guess it must mean something is going on...?

Now what?

Rgds
Viking

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Sat May 23, 2015 3:23 am

Latest Beta release V3.1.0.150523

Further improvements to the script :D . Gee it would be nice if someone would test this for me. Feeling a little lonely at the moment :-?

The current version of the script is optimised for MediaMonkey 4 and above.

If you haven't used a Beta just follow the instructions below, it's easy. Try a Beta, they're safe and you'll be helping with the development.

Release improvements:
- Disable communication settings on the options page when MonkeySqueeze is enabled
- The ability to connect to one of four pre-configured SqueezeBox players each session - Connection info and selection on the Options page
- Added the ability to log into a password protected LMS/Squeezebox system. Data entered on the MonkeySqueeze Options page
- General tidy of the script
- Roll back to V3.0.1 - Changes in V3.0.1.120314Beta removed


Systems tested and working on:
PC (Win 7) - No server/NAS
PC (Win 7) + Windows Server 2008 (WHS 2011)
PC (Win 7) + Linux NAS (ReadyNAS Duo)

Known Issues:
None at this stage

To use this version:
Copy the script to Notepad and save as MonkeySqueeze.vbs to one one of the following locations:
C:\Program Files\MediaMonkey\Scripts\Auto or C:\Program Files (x86)\MediaMonkey\Scripts\Auto

Make sure you disable or remove the existing MonkeySqueeze.vbs

If you use this script please report on this forum if it runs OK or if you had any issues. Feedback is appreciated so I can implement changes before any official release.

Code: Select all

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' MonkeySqueeze V3.1.0.150523Beta
'
' MOD DATE: 23.05.2015
'
' Script: Development has occurred in two distinct stages: As Squeezebox Controller from 2007 to 2009; and as MonkeySqueeze from 2011 on. 
' Major changes have occurred to the script since 2011 and it bears little resemblance to the original Squeezebox Controller.
' 
' DATE STARTED: 26.09.2007
'
' Squeezebox Controller: Todd Nemeth    Mods: Baz, Big_Berny, Peke, trixmoto, debacle, mccstumble
' MonkeySqueeze: Gingernut63, booblers, Katteman
'
' COMMENT:
'  - You will also need Logitech Media Server (Squeezebox Server) installed and running
'  - Optional: Install and run SqueezePlay or SoftSqueeze
'  - After installation the options page for this script is located at Tools > Options > MonkeySqueeze
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit
Public EndOfTrack, LMScount, LMSpaths()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim onMonkeySqueezeIcon
Dim offMonkeySqueezeIcon

'**************************************************************
Sub OnStartup
  Dim ind, Mnu
  Dim UI : Set UI = SDB.UI
  
  onMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
  If onMonkeySqueezeIcon < 0 Then
    onMonkeySqueezeIcon = 74 'unlocked icon if it doesn't exist
  End If
  
  offMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
  If offMonkeySqueezeIcon < 0 Then
    offMonkeySqueezeIcon = 75 'locked icon if it doesn't exist
  End If
  
  Set Mnu = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
  Mnu.Caption = "MonkeySqueeze"
  Mnu.UseScript = Script.ScriptPath
  Mnu.OnClickFunc = "SyncToggle"
  Mnu.IconIndex = offMonkeySqueezeIcon
  Mnu.Hint = "Enable/Disable MonkeySqueeze"
  
  Set SDB.Objects("MonkeySqueezeIcon") = Mnu  'save a reference to it so we can change the icon later.
  SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  ind = SDB.UI.AddOptionSheet("MonkeySqueeze",Script.ScriptPath,"InitSheet","SaveSheet",-2)
  
  'logme(slimRequest(formatCommand("""version"",""?""")))
End Sub

'**************************************************************
Sub InitSheet(Sheet)
  Dim Panel1, Panel2, Panel3, Panel4, Panel5, Btn1, Checkbox1, Checkbox2, Checkbox3, Checkbox4, Edit1, Edit2, Edit3, Edit4, Edit5, Edit6, Edit7, Edit8, Edit9, Edit10, Edit11, Edit12, Edit13, Edit14, Combo1
  
  Set Panel1 = SDB.UI.NewGroupBox(Sheet)
  Panel1.Common.SetRect 10,10,450,50
  Panel1.Caption = "MonkeySqueeze v3.1.0.150523Beta."
  
  With SDB.UI.NewLabel(Panel1)
    .Common.SetRect 15,22,590,20
    .Caption = "This script allows MediaMonkey to play music on a Squeezebox system"
  End With
  
  Set Btn1 = SDB.UI.NewButton(Panel1)
  Btn1.Common.SetRect 370,15,65,25
  Btn1.Caption = "User Guide"
  Btn1.Common.Hint = "Click and then open MonkeySqueeze_UserGuide.pdf"
  Script.RegisterEvent Btn1, "OnClick", "UserGuide"
  
  Set Panel2 = SDB.UI.NewGroupBox(Sheet)
  Panel2.Common.SetRect 10,70,450,80
  Panel2.Caption = "General Settings"
  
  Set CheckBox1 = SDB.UI.NewCheckBox(Panel2)
  CheckBox1.Common.SetRect 15,20,150,20
  CheckBox1.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle")
  CheckBox1.Common.ControlName = "EnablePT"
  CheckBox1.Common.Hint = SDB.Localize("When selected if MonkeySqueeze is enabled, the primary Squeezebox device will power on, and on/off at startup/shutdown. When MonkeySqueeze is disabled, the selected Squeezebox player will power off.")
  CheckBox1.Caption = SDB.Localize("Enable Power Toggle")
  
  Set CheckBox2 = SDB.UI.NewCheckBox(Panel2)
  CheckBox2.Common.SetRect 15,47,80,20
  CheckBox2.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Login")
  CheckBox2.Common.ControlName = "EnableLog"
  CheckBox2.Common.Hint = SDB.Localize("This will enable MonkeySqueeze to log into a password protected LMS/Squeezebox system.")
  CheckBox2.Caption = SDB.Localize("Enable Login")
  CheckBox2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Script.RegisterEvent CheckBox2.Common, "OnClick", "LogClick"
  
  With SDB.UI.NewLabel(Panel2)
    .Common.SetRect 115,50,60,20
    .Caption = "Username:"
  End With
  
  Set Edit1 = SDB.UI.NewEdit(Panel2)
  Edit1.Common.ControlName = "SqueezeBoxUser"
  Edit1.Common.SetRect 172,47,95,25
  Edit1.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser")
  If Edit1.Text = "" Then
    Edit1.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = ""
  End If
  Edit1.Common.Hint = "Type the LMS username here"
  
  With SDB.UI.NewLabel(Panel2)
    .Common.SetRect 280,50,60,20
    .Caption = "Password:"
  End With
  Edit1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  Set Edit2 = SDB.UI.NewEdit(Panel2)
  Edit2.Common.ControlName = "SqueezeBoxPass"
  Edit2.Common.SetRect 334,47,95,25
  Edit2.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass")
  If Edit2.Text = "" Then
    Edit2.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = ""
  End If
  Edit2.PasswordChar = "*"
  Edit2.Common.Hint = "Type the LMS password here"
  Edit2.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  'Edit1.Common.Enabled = Checkbox2.Checked = False
  'Edit2.Common.Enabled = CheckBox2.Checked = False
  
  Set Panel3 = SDB.UI.NewGroupBox(Sheet)
  Panel3.Common.SetRect 10,160,450,90
  Panel3.Caption = "LMS Communication Settings"
  
  With SDB.UI.NewLabel(Panel3)
    .Multiline = True
    .Common.SetRect 15,20,420,50
    .Caption = "Address/Hostname and port number located at the LMS Web page > Settings > Information tab"
  End With
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 15,59,70,20
    .Caption = "IP Address:"
  End With
  
  Set Edit3 = SDB.UI.NewEdit(Panel3)
  Edit3.Common.ControlName = "SqueezeBoxIP"
  Edit3.Common.SetRect 75,55,95,25
  Edit3.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP")
  If Edit3.Text = "" Then
    Edit3.Text = "XXX.XXX.XXX.XXX"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = "XXX.XXX.XXX.XXX"
  End If
  'If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True Then
    'Edit3.Common.Enabled = False
  'End If
  Edit3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit3.Common.Hint = "Copy and paste the LMS IP Address or Hostname here"
  
  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 215,59,70,20
    .Caption = "HTTP Port No:"
  End With
  
  Set Edit4 = SDB.UI.NewEdit(Panel3)
  Edit4.Common.ControlName = "SqueezeBoxPort"
  Edit4.Common.SetRect 287,55,40,25
  Edit4.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort")
  If Edit4.Text = "" Then
    Edit4.Text = "9000"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = "9000"
  End If
  Edit4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit4.Common.Hint = "HTTP port default is 9000. View the port number in LMS: Web Control page > Settings > Information tab and change if required"
  
  Set Panel4 = SDB.UI.NewGroupBox(Sheet)
  Panel4.Common.SetRect 10,260,450,195
  Panel4.Caption = "Squeezebox Player Settings"
  
  With SDB.UI.NewLabel(Panel4)
    .Multiline = True
    .Common.SetRect 15,20,420,60
    .Caption = "The name and MAC address of the players (Touch, SqueezePlay, etc...) to connect to. Only one player connection per session."
  End With
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,59,100,20
    .Caption = "MediaMonkey is connected to:"
  End With
  
  Set Combo1 = SDB.UI.NewDropdown(Panel4)
  Combo1.Common.SetRect 162,56,75,20
  Combo1.Style = 1     ' List style 1 or 2
  Combo1.AddItem "Player 1"
  Combo1.AddItem "Player 2"
  Combo1.AddItem "Player 3"
  Combo1.AddItem "Player 4"
  Combo1.Common.ControlName = "SqueezeBoxPlayerNo"
  Combo1.ItemIndex = SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo")'Players 1 to 4 use integer values 0 to 3
  Combo1.Common.Hint = "Select the Squeezebox Player you wish to connect to"
  Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Script.RegisterEvent Combo1.Common, "OnClick", "PlayerSelect"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,89,60,20
    .Caption = "Player 1 Name:"
  End With
  
  Set Edit5 = SDB.UI.NewEdit(Panel4)
  Edit5.Common.ControlName = "SqueezeBoxPlayer1"
  Edit5.Common.SetRect 95,85,110,25
  Edit5.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
  If Edit5.Text = "" Then
    Edit5.Text = " "
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = " "
  End If
  Edit5.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,112,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit6 = SDB.UI.NewEdit(Panel4)
  Edit6.Common.ControlName = "SqueezeBoxMAC"
  Edit6.Common.SetRect 95,108,110,25
  Edit6.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC")
  If Edit6.Text = "" Then
    Edit6.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit6.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,89,60,20
    .Caption = "Player 2 Name:"
  End With
  
  Set Edit7 = SDB.UI.NewEdit(Panel4)
  Edit7.Common.ControlName = "SqueezeBoxPlayer2"
  Edit7.Common.SetRect 320,85,110,25
  Edit7.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
  If Edit7.Text = "" Then
    Edit7.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = ""
  End If
  Edit7.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,112,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit8 = SDB.UI.NewEdit(Panel4)
  Edit8.Common.ControlName = "SqueezeBoxMAC2"
  Edit8.Common.SetRect 320,108,110,25
  Edit8.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2")
  If Edit8.Text = "" Then
    Edit8.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit8.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,142,60,20
    .Caption = "Player 3 Name:"
  End With
  
  Set Edit9 = SDB.UI.NewEdit(Panel4)
  Edit9.Common.ControlName = "SqueezeBoxPlayer3"
  Edit9.Common.SetRect 95,138,110,25
  Edit9.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
  If Edit9.Text = "" Then
    Edit9.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = ""
  End If
  Edit9.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,165,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit10 = SDB.UI.NewEdit(Panel4)
  Edit10.Common.ControlName = "SqueezeBoxMAC3"
  Edit10.Common.SetRect 95,161,110,25
  Edit10.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3")
  If Edit10.Text = "" Then
    Edit10.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit10.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,142,60,20
    .Caption = "Player 4 Name:"
  End With
  
  Set Edit11 = SDB.UI.NewEdit(Panel4)
  Edit11.Common.ControlName = "SqueezeBoxPlayer4"
  Edit11.Common.SetRect 320,138,110,25
  Edit11.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
  If Edit11.Text = "" Then
    Edit11.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = ""
  End If
  Edit11.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,165,55,20
    .Caption = "MAC Address:"
  End With
  
  Set Edit12 = SDB.UI.NewEdit(Panel4)
  Edit12.Common.ControlName = "SqueezeBoxMAC4"
  Edit12.Common.SetRect 320,161,110,25
  Edit12.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4")
  If Edit12.Text = "" Then
    Edit12.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit12.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  'Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Edit6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Edit8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Edit10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Edit12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  Set Panel5 = SDB.UI.NewGroupBox(Sheet)
  Panel5.Common.SetRect 10,465,450,145
  Panel5.Caption = "LMS Server/NAS Systems"
  
  With SDB.UI.NewLabel(Panel5)
    .Multiline = True
    .Common.SetRect 15,20,420,60
    .Caption = "To be used for connection to Linux or Windows based Servers or NAS systems. Note: Linux uses forward slashes (/) and Windows uses back slashes (\) for all addresses"
  End With
  
  Set CheckBox3 = SDB.UI.NewCheckBox(Panel5)
  CheckBox3.Common.SetRect 15,53,120,20
  CheckBox3.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","NAS")
  CheckBox3.Common.ControlName = "EnableNAS"
  CheckBox3.Common.Hint = SDB.Localize("Select if using LMS on a Linux or Windows Server/NAS device. See user guide for more details")
  CheckBox3.Caption = SDB.Localize("Enable Server/NAS")
  CheckBox3.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  'Script.RegisterEvent CheckBox3.Common, "OnClick", "NASClick"
  
  Set CheckBox4 = SDB.UI.NewCheckBox(Panel5)
  CheckBox4.Common.SetRect 200,53,260,20
  CheckBox4.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Synology")
  CheckBox4.Common.ControlName = "EnableSynology"
  CheckBox4.Common.Hint = SDB.Localize("Select if using Squeezebox Server prior to v7.5.1. Tested on Synology devices only")
  CheckBox4.Caption = SDB.Localize("LMS is prior to v7.5.1 (Linux device only)")
  CheckBox4.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  With SDB.UI.NewLabel(Panel5)
    .Common.SetRect 15,84,70,20
    .Caption = "MediaMonkey Music Folder:"
  End With
  
  Set Edit13 = SDB.UI.NewEdit(Panel5)
  Edit13.Common.ControlName = "MediaMonkeyMF"
  Edit13.Common.SetRect 148,80,281,25
  Edit13.Text = SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF")
  If Edit13.Text = "" Then
    Edit13.Text = "\\Server\folder or X:\__\__(mapped)"
    SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = "\\Server\folder or X:\__\__(mapped)"
  End If
  Edit13.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit13.Common.Hint = "Copy from MediaMonkey > File > Add/Rescan Folders or the Path column in the Track Browser section"
  
  With SDB.UI.NewLabel(Panel5)
    .Common.SetRect 15,114,70,20
    .Caption = "LMS Media Folder:"
  End With
  
  Set Edit14 = SDB.UI.NewEdit(Panel5)
  Edit14.Common.ControlName = "SqueezeBoxMF"
  Edit14.Common.SetRect 105,110,281,25
  Edit14.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF")
  If Edit14.Text = "" Then
    Edit14.Text = "/___ /___ Linux, or \ ___\ ___ Windows"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = "/___ /___ Linux, or \ ___\ ___ Windows"
  End If
  Edit14.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit14.Common.Hint = "Copy and Paste from: LMS Web Page > Settings > Basic Settings tab > Music Folder"
  
  'CheckBox4.Common.Enabled = CheckBox3.Checked = False
  'Edit13.Common.Enabled = CheckBox3.Checked = False
  'Edit14.Common.Enabled = CheckBox3.Checked = False
  
End Sub
'**************************************************************
Sub LogClick(ChB)
  Dim Edt1, Edt2
  
  Set Edt1 = ChB.Common.TopParent.Common.ChildControl("SqueezeBoxUser")
  Set Edt2 = ChB.Common.TopParent.Common.ChildControl("SqueezeBoxPass")
  Edt1.Common.Enabled = ChB.Checked = False
  Edt2.Common.Enabled = ChB.Checked = False
End Sub
'**************************************************************
Sub PlayerSelect(DD)
  Dim Cmbo1, Edt6, Edt8, Edt10, Edt12
  
  Set Cmbo1 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxPlayerNo")
  Set Edt6 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC")
  Set Edt8 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC2")
  Set Edt10 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC3")
  Set Edt12 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC4")
  Cmbo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
End Sub
'**************************************************************
Sub NASClick(ChB)
  Dim ChB4, Edt13, Edt14
  
  Set ChB4 = ChB.Common.TopParent.Common.ChildControl("EnableSynology")
  Set Edt13 = ChB.Common.TopParent.Common.ChildControl("MediaMonkeyMF")
  Set Edt14 = ChB.Common.TopParent.Common.ChildControl("SqueezeBoxMF")
  ChB4.Common.Enabled = ChB.Checked = False
  Edt13.Common.Enabled = ChB.Checked = False
  Edt14.Common.Enabled = ChB.Checked = False
End Sub
'**************************************************************
Sub SaveSheet(Sheet)
  SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") = Sheet.Common.ChildControl( "EnablePT").Checked
  SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = Sheet.Common.ChildControl("SqueezeBoxPlayerNo").ItemIndex
  SDB.IniFile.BoolValue("MonkeySqueeze","Login") = Sheet.Common.ChildControl( "EnableLog").Checked
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = Sheet.Common.ChildControl("SqueezeBoxUser").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = Sheet.Common.ChildControl("SqueezeBoxPass").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = Sheet.Common.ChildControl("SqueezeBoxIP").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = Sheet.Common.ChildControl("SqueezeBoxPort").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = Sheet.Common.ChildControl("SqueezeBoxPlayer1").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = Sheet.Common.ChildControl("SqueezeBoxMAC").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = Sheet.Common.ChildControl("SqueezeBoxPlayer2").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = Sheet.Common.ChildControl("SqueezeBoxMAC2").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = Sheet.Common.ChildControl("SqueezeBoxPlayer3").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = Sheet.Common.ChildControl("SqueezeBoxMAC3").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = Sheet.Common.ChildControl("SqueezeBoxPlayer4").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = Sheet.Common.ChildControl("SqueezeBoxMAC4").Text
  SDB.IniFile.BoolValue("MonkeySqueeze","NAS") = Sheet.Common.ChildControl( "EnableNAS").Checked
  SDB.IniFile.BoolValue("MonkeySqueeze","Synology") = Sheet.Common.ChildControl( "EnableSynology").Checked
  SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = Sheet.Common.ChildControl("MediaMonkeyMF").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = Sheet.Common.ChildControl("SqueezeBoxMF").Text
End Sub
'**************************************************************
Sub UserGuide
  On Error Resume Next
  Dim OF, FolderToOpen
  
  Set OF = CreateObject("Shell.Application")
  FolderToOpen = sdb.ScriptsPath & "Auto\"
  OF.Explore FolderToOpen
  Set OF = Nothing
End Sub
'**************************************************************
Function SqueezeBoxMode
  Dim strRetVal
  
  On Error Resume Next
  SqueezeBoxMode = ""
  strRetVal = slimRequest(formatCommand("""mode"", ""?"""))
  If InStrRev(strRetVal, "play") > 0 Then
    SqueezeBoxMode = "play"
  ElseIf InStrRev(strRetVal, "stop") > 0 Then
    SqueezeBoxMode = "stop"
  ElseIf InStrRev(strRetVal, "pause") > 0 Then
    SqueezeBoxMode = "pause"
  End If
End Function
'**************************************************************
Sub ShowPlayerSettings
  Dim Plr, Warning, Res
  
  Warning = ""
  Set Plr = SDB.Player
  'If Plr.isAutoDJ    Then Warning = Warning & vbNewLine & "AutoDJ is on"
  If Plr.isCrossFade Then Warning = Warning & vbNewLine & "CrossFade is on"
  If Plr.isShuffle   Then Warning = Warning & vbNewLine & "Shuffle is on"
  If Plr.isEqualizer Then Warning = Warning & vbNewLine & "Equalizer is on"
  If Plr.isRepeat    Then Warning = Warning & vbNewLine & "Repeat is on"
  If Warning <> "" Then
    Res = SDB.MessageBox("Selected player settings:" & vbNewLine & _
    Warning, mtWarning, Array(mbOk))
  End If
End Sub
'**************************************************************
Function SyncToggle( itm )
  
  If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
    SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
    itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
    Call registerEvents
    If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""1"""))
    ShowPlayerSettings
    FillPlaylist
  Else
    SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
    itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
    Call unregisterEvents
    slimRequest(formatCommand("""stop"""))
    If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
  End If
End Function
'**************************************************************
Sub Event_OnPlay
  Dim strRetVal, Idx
  
  If (SqueezeBoxMode = "play") And EndOfTrack Then
    '*** normal playlist continuation
    EndOfTrack = False
  Else
    '*** Squeezebox is not playing or new track out of order
    Idx = SDB.Player.CurrentSongIndex
    slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
  End If
End Sub
'**************************************************************
Sub Event_OnTrackEnd
  Dim strRetVal, idx, tim, dur
  
  '*** see if current track ended, then playing is not interrupted
  EndOfTrack = True
End Sub
'**************************************************************
Function CheckPath(SongValue)
  If Left(SongValue.Path,1) = "?" Then
    If SongValue.Cached Then
      CheckPath = SongValue.CachedPath
    Else
      CheckPath = SongValue.Path
    End If
  Else
    CheckPath = SongValue.Path
  End If
  If SDB.IniFile.BoolValue("MonkeySqueeze","NAS") Then
    If SDB.IniFile.BoolValue("MonkeySqueeze","Synology") Then CheckPath = Replace(CheckPath,"\","/")
    CheckPath = Replace(CheckPath,SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF"),SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF"))
  End If
End Function
'**************************************************************
Sub Event_OnStop
  slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnShutdown
  On Error Resume Next
  slimRequest(formatCommand("""stop"""))
  If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
End Sub
'**************************************************************
Sub Event_OnPause
  
  If SDB.Player.IsPaused Then
    slimRequest(formatCommand("""pause"""))
  Else
    slimRequest(formatCommand("""play"""))
  End If
End Sub
'**************************************************************
Sub Event_OnSeek
  Dim SBmode, Song, TrackPath, LMStime
  
  SBmode = SqueezeBoxMode
  If SBmode = "stop" Then
    Set Song = SDB.Player.CurrentSong
    TrackPath = CheckPath(Song)
    slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
  End If
  LMStime = 0.001 * SDB.Player.PlaybackTime
  slimRequest(formatCommand("""time"", """ + CStr(LMStime) + """"))
End Sub
'**************************************************************
Function slimRequest(params)
  'slimRequest accepts pre-formatted parameter string, returns string of the response'
  'logme "  >> slimRequest: Begin with " + params
  Dim url, prog, objHTTP
  Dim cnt : cnt = 0
  
  If SDB.IniFile.BoolValue("MonkeySqueeze","Login") = True Then
    url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") + "@" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
  Else
    url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
  End If
  
  'Set prog = SDB.Objects("LoadXMLBar")
  Set prog = SDB.Progress
  Set objHTTP = CreateObject("Microsoft.XMLHTTP")
  Call objHTTP.open("POST", url, True)
  objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  objHTTP.setRequestHeader "X-Requested-With", "XMLHttpRequest"
  objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
  objHTTP.send(params)
  
  Do While (objHTTP.readyState < 4) And (cnt < 300)
    Call SDB.Tools.Sleep(100)
    SDB.ProcessMessages
    cnt = cnt+1
    If prog.Terminate Then
      cnt = 300
    End If
  Loop
  
  If objHTTP.readyState < 4 Then
    Set slimRequest = Nothing
  Else
    slimRequest = objHTTP.responseText
  End If
End Function
'*************************************************************
'This is is a JSON RPC call - We're directly calling functions in the Slim::Request module in Perl. See here:
'http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm
'the addDispatch section tells you how to use the commands and what the RPC module is looking for in terms of formatting
Function formatCommand(str1)
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") + """,[" + str1 + "]]}"
  End If
  
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") + """,[" + str1 + "]]}"
  End If
  
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") + """,[" + str1 + "]]}"
  End If
  
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") + """,[" + str1 + "]]}"
  End If
  
End Function
'*************************************************************
'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
  Dim fso, logf
  
  On Error Resume Next
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
  logf.WriteLine Now() & ": " & msg
  Set fso = Nothing
  Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to Squeezebox)
Function perlEscape(str1)
  perlEscape = Replace(str1, "\", "\\")
End Function
'*************************************************************
Sub registerEvents
  Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
  Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
  Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
  Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
  Call Script.RegisterEvent(SDB,"OnTrackEnd","Event_OnTrackEnd")
  Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
  Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub
'*************************************************************
Sub Event_OnNowPlayingModified
  Dim MMcount
  
  MMcount = SDB.Player.CurrentPlayList.Count
  'logme("Now playing modified")
  'logme("Aantal MM tracks: " & Cstr(MMcount))
  'logme("Aantal LMS tracks: " & Cstr(LMScount))
  If SqueezeBoxMode = "stop" Then
    FillPlaylist
  ElseIf MMcount = 0 Then
    ResetPlaylist
  ElseIf MMcount < LMScount Then
    TracksDeleted(MMcount)
  ElseIf MMcount > LMScount Then
    TracksAdded(MMcount)
  Else
    TracksMoved
  End If
End Sub
'*************************************************************
Sub FillPlaylist
  '*** synchronize MM playlist with LMS playlist
  Dim tempStop, Idx
  
  '*** clear LMS playlist and stop shuffle!!
  slimRequest(formatCommand("""playlist"", ""clear"""))
  slimRequest(formatCommand("""playlist"", ""shuffle"", ""0"""))
  '*** copy MM playlist - if any - to LMS
  LMScount = SDB.Player.CurrentPlayList.Count
  ReDim LMSpaths(LMScount)
  '*** if playlist is empty we are done
  If LMScount > 0 Then
    tempStop = SDB.Player.isPlaying And (SDB.Player.PlayBackTime < 2000)
    If tempStop Then
      SDB.Player.pause
      slimRequest(formatCommand("""stop"""))
    End If
    SendPlaylist
    '*** jump to current song
    Idx = SDB.Player.CurrentSongIndex
    slimRequest(formatCommand("""playlist"", ""index"", """ + CStr(Idx) + """"))
    If tempStop Then
      '*** Start playback after filling playlist
      SDB.Player.Pause
    ElseIf SDB.Player.isPlaying Then
      '*** Synchronize LMS with current track
      slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001) + """"))
      If SDB.Player.isPaused Then SDB.Player.Pause
    Else
      '*** MediaMonkey is not playing
      slimRequest(formatCommand("""stop"""))
    End If
  End If
  EndOfTrack = False
End Sub
'**************************************************************
Sub SendPlaylist
  Dim Progr, TrackPath, Song, n
  
  '*** show progress bar
  Set Progr = SDB.Progress
  Progr.Text = SDB.Localize("Synchronising playlists...")
  Progr.MaxValue = LMScount
  '*** send playlist
  For n=0 To LMScount-1
    Set Song = SDB.Player.CurrentPlayList.Item(n)
    TrackPath = CheckPath(Song)
    LMSpaths(n) = TrackPath
    slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
    Progr.Value = n+1
  Next
End Sub
'**************************************************************
Sub ResetPlaylist
  
  SDB.Player.Stop
  slimRequest(formatCommand("""stop"""))
  slimRequest(formatCommand("""playlist"", ""clear"""))
  ReDim LMSpaths(0)
  LMScount = 0
End Sub
'**************************************************************
Sub TracksDeleted(MMcount)
  Dim n, m, Song, TrackPath
  
  'logme("Tracks deleted")
  n = 0
  Do While MMcount < LMScount
    If n = MMcount Then
      TrackPath = "***"
    Else
      Set Song = SDB.Player.CurrentPlayList.Item(n)
      TrackPath = CheckPath(Song)
    End If
    If (TrackPath = LMSpaths(n)) Then
      n = n+1
    Else
      LMScount = LMScount - 1
      For m = n To LMScount - 1
        LMSpaths(m) = LMSpaths(m+1)
      Next
      slimRequest(formatCommand("""playlist"", ""delete"", """ + CStr(n) + """"))
    End If
  Loop
End Sub
'*************************************************************
Sub TracksAdded(MMcount)
  Dim n, m, Song, TrackPath
  
  'logme("Tracks added")
  ReDim Preserve LMSpaths(MMcount)  'expand array, preserve content
  Do
    For n = 0 To MMcount -1
      Set Song = SDB.Player.CurrentPlayList.Item(n)
      TrackPath = CheckPath(Song)
      If (TrackPath <> LMSpaths(n)) Then
        slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
        If n < LMScount Then
          slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(LMScount) + """, """ + CStr(n) + """"))
          For m = LMScount To n+1 Step -1
            LMSpaths(m) = LMSpaths(m-1)
          Next
        End If
        LMSpaths(n) = TrackPath
        LMScount = LMScount + 1
      End If
    Next
  Loop While MMcount > LMScount
End Sub
'*************************************************************
Sub TracksMoved
  Dim n, m, i, Song, TrackPath, tempPath
  
  'logme("Tracks moved")
  For n=0 To LMScount-1
    Set Song = SDB.Player.CurrentPlayList.Item(n)
    TrackPath = CheckPath(Song)
    If TrackPath <> LMSpaths(n) Then
      For m=n+1 To LMScount-1
        If TrackPath = LMSpaths(m) Then Exit For
      Next
      For i=m To n+1 Step -1
        LMSpaths(i) = LMSpaths(i-1)
      Next
      LMSpaths(n) = TrackPath
      slimRequest(formatCommand("""playlist"", ""move"", """ + CStr(m) + """, """ + CStr(n) + """"))
    End If
  Next
End Sub
'*************************************************************
Sub unregisterEvents
  Script.UnregisterEvents SDB
End Sub
'*************************************************************
'These are what the full JSON strings look like that need to be sent to slimRequest()
'formatRequest() fills in the first part and all you have to do is pick the RPC commands from http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm

'Note: there are cleaner ways of doing this - but this is quick and dirty. It just means that you have to use a lot of """ and etc in vbscript.
'This entire script is much easier to write in jscript but I don't know jscript at all so, shrug.

'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:cgABbehldiqtyrSuoKLN"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:uB"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["playlist","index",28]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["pause"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",[""playlist"", ""play"", ""D:\\MP3\\filename.mp3""]]}


'You can do ANYTHING you can do from the web interface via this RPC engine because you are directly calling the methods in Perl
'so you could add whole playlists and etc see the docs. Sky's the limit.

Re: MonkeySqueeze Development V3.1.0

by Gingernut63 » Thu May 21, 2015 2:41 pm

Latest Beta release V3.1.0.150521

Further major improvements to the script

The current version of the script is optimised for MediaMonkey 4 and above.

If you haven't used a Beta just follow the instructions below, it's easy. Try a Beta, they're safe and you'll be helping with the development.

Release improvements:
- The ability to connect to one of four pre-configured SqueezeBox players each session - Connection info and selection on the Options page
- Added the ability to log into a password protected LMS/Squeezebox system. Data entered on the MonkeySqueeze Options page
- General tidy of the script
- Roll back to V3.0.1 - Changes in V3.0.1.120314Beta removed


Known Issues:
None at this stage. Make sure you read the tool tips on the options page.

To use this version:
Copy the script to Notepad and save as MonkeySqueeze.vbs to one one of the following locations:
C:\Program Files\MediaMonkey\Scripts\Auto or C:\Program Files (x86)\MediaMonkey\Scripts\Auto

Make sure you disable or remove the existing MonkeySqueeze.vbs

If you use this script please report on this forum if it runs OK or if you had any issues. Feedback is appreciated so I can implement changes before any official release.

Code: Select all

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
' MonkeySqueeze V3.1.0.150521Beta
'
' MOD DATE: 21.05.2015
'
' Script: Development has occurred in two distinct stages: As Squeezebox Controller from 2007 to 2009; and as MonkeySqueeze from 2011 on. 
' Major changes have occurred to the script since 2011 and it bears little resemblance to the original Squeezebox Controller.
' 
' DATE STARTED: 26.09.2007
'
' Squeezebox Controller: Todd Nemeth    Mods: Baz, Big_Berny, Peke, trixmoto, debacle, mccstumble
' MonkeySqueeze: Gingernut63, booblers, Katteman
'
' COMMENT:
'  - You will also need Logitech Media Server (SqueezeBox Server) installed and running
'  - Optional: Install and run SqueezePlay or SoftSqueeze
'  - After installation the options page for this script is located at Tools > Options > MonkeySqueeze
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Option Explicit
Public EndOfTrack, LMScount, LMSpaths()
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim onMonkeySqueezeIcon
Dim offMonkeySqueezeIcon

'**************************************************************
Sub OnStartup
  Dim ind, Mnu
  Dim UI : Set UI = SDB.UI

  onMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
  If onMonkeySqueezeIcon < 0 Then
    onMonkeySqueezeIcon = 74 'unlocked icon if it doesn't exist
  End If

  offMonkeySqueezeIcon = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
  If offMonkeySqueezeIcon < 0 Then
    offMonkeySqueezeIcon = 75 'locked icon if it doesn't exist
  End If

  Set Mnu = UI.AddMenuItem( UI.Menu_TbStandard, 0, 0)
  Mnu.Caption = "MonkeySqueeze"
  Mnu.UseScript = Script.ScriptPath
  Mnu.OnClickFunc = "SyncToggle"
  Mnu.IconIndex = offMonkeySqueezeIcon
  Mnu.Hint = "Enable/Disable MonkeySqueeze"

  Set SDB.Objects("MonkeySqueezeIcon") = Mnu  'save a reference to it so we can change the icon later.
  SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False

  ind = SDB.UI.AddOptionSheet("MonkeySqueeze",Script.ScriptPath,"InitSheet","SaveSheet",-2)

  'logme(slimRequest(formatCommand("""version"",""?""")))
End Sub

'**************************************************************
Sub InitSheet(Sheet)
  Dim Panel1, Panel2, Panel3, Panel4, Panel5, Btn1, Checkbox1, Checkbox2, Checkbox3, Checkbox4, Edit1, Edit2, Edit3, Edit4, Edit5, Edit6, Edit7, Edit8, Edit9, Edit10, Edit11, Edit12, Edit13, Edit14, Combo1

  Set Panel1 = SDB.UI.NewGroupBox(Sheet)
  Panel1.Common.SetRect 10,10,450,50
  Panel1.Caption = "MonkeySqueeze v3.1.0.150521Beta."

  With SDB.UI.NewLabel(Panel1)
    .Common.SetRect 15,22,590,20
    .Caption = "This script allows MediaMonkey to play music on a SqueezeBox system"
  End With

  Set Btn1 = SDB.UI.NewButton(Panel1)
  Btn1.Common.SetRect 370,15,65,25
  Btn1.Caption = "User Guide"
  Btn1.Common.Hint = "Click and then open MonkeySqueeze_UserGuide.pdf"
  Script.RegisterEvent Btn1, "OnClick", "UserGuide"

  Set Panel2 = SDB.UI.NewGroupBox(Sheet)
  Panel2.Common.SetRect 10,70,450,80
  Panel2.Caption = "General Settings"

  Set CheckBox1 = SDB.UI.NewCheckBox(Panel2)
  CheckBox1.Common.SetRect 15,20,150,20
  CheckBox1.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle")
  CheckBox1.Common.ControlName = "EnablePT"
  CheckBox1.Common.Hint = SDB.Localize("When selected if MonkeySqueeze is enabled, the primary SqueezeBox device will power on, and on/off at startup/shutdown. When MonkeySqueeze is disabled, primary SqueezeBox device will power off. Does not work if SqueezePlay is the primary device.")
  CheckBox1.Caption = SDB.Localize("Enable Power Toggle")
    
  Set CheckBox2 = SDB.UI.NewCheckBox(Panel2)
  CheckBox2.Common.SetRect 15,47,80,20
  CheckBox2.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Login")
  CheckBox2.Common.ControlName = "EnableLog"
  CheckBox2.Common.Hint = SDB.Localize("This will enable MonkeySqueeze to log into a password protected LMS/SqueezeBox system.")
  CheckBox2.Caption = SDB.Localize("Enable Login")
  Script.RegisterEvent CheckBox2.Common, "OnClick", "LogClick"
    
  With SDB.UI.NewLabel(Panel2)
    .Common.SetRect 115,50,60,20
    .Caption = "Username:"
  End With

  Set Edit1 = SDB.UI.NewEdit(Panel2)
  Edit1.Common.ControlName = "SqueezeBoxUser"
  Edit1.Common.SetRect 172,47,95,25
  Edit1.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser")
  If Edit1.Text = "" Then
    Edit1.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = ""
  End If
  Edit1.Common.Hint = "Type the LMS username here"

  With SDB.UI.NewLabel(Panel2)
    .Common.SetRect 280,50,60,20
    .Caption = "Password:"
  End With

  Set Edit2 = SDB.UI.NewEdit(Panel2)
  Edit2.Common.ControlName = "SqueezeBoxPass"
  Edit2.Common.SetRect 334,47,95,25
  Edit2.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass")
  If Edit2.Text = "" Then
    Edit2.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = ""
  End If
  Edit2.PasswordChar = "*"
  Edit2.Common.Hint = "Type the LMS password here"

  Edit1.Common.Enabled = CheckBox2.Checked
  Edit2.Common.Enabled = CheckBox2.Checked
  
  Set Panel3 = SDB.UI.NewGroupBox(Sheet)
  Panel3.Common.SetRect 10,160,450,105
  Panel3.Caption = "LMS IP Address and HTTP Port"

  With SDB.UI.NewLabel(Panel3)
    .Multiline = True
    .Common.SetRect 15,20,420,50
    .Caption = "Open the LMS (SqueezeBox Server) Web Control page > Settings > Information tab and find the Server IP Address, e.g. 192.168.0.102 and enter below. The default HTTP Port number is 9000. See user guide if you wish to change it."
  End With

  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 15,74,70,20
    .Caption = "IP Address:"
  End With

  Set Edit3 = SDB.UI.NewEdit(Panel3)
  Edit3.Common.ControlName = "SqueezeBoxIP"
  Edit3.Common.SetRect 75,70,95,25
  Edit3.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP")
  If Edit3.Text = "" Then
    Edit3.Text = "XXX.XXX.XXX.XXX"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = "XXX.XXX.XXX.XXX"
  End If
  Edit3.Common.Hint = "Copy and paste the LMS IP Address or Hostname here"

  With SDB.UI.NewLabel(Panel3)
    .Common.SetRect 215,74,70,20
    .Caption = "HTTP Port No:"
  End With

  Set Edit4 = SDB.UI.NewEdit(Panel3)
  Edit4.Common.ControlName = "SqueezeBoxPort"
  Edit4.Common.SetRect 287,70,40,25
  Edit4.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort")
  If Edit4.Text = "" Then
    Edit4.Text = "9000"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = "9000"
  End If
  Edit4.Common.Hint = "HTTP port default is 9000. View the port number in LMS: Web Control page > Settings > Information tab and change if required"

  Set Panel4 = SDB.UI.NewGroupBox(Sheet)
  Panel4.Common.SetRect 10,275,450,195
  Panel4.Caption = "SqueezeBox Player Names and MAC Addresses"

  With SDB.UI.NewLabel(Panel4)
    .Multiline = True
    .Common.SetRect 15,20,420,60
    .Caption = "The Name and MAC address of the players (Touch, SqueezePlay, etc...) to connect to. Only one player connection per session."
  End With

  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,59,100,20
    .Caption = "MediaMonkey is connected to:"
  End With

  Set Combo1 = SDB.UI.NewDropdown(Panel4)
  Combo1.Common.SetRect 162,56,75,20
  Combo1.Style = 1     ' List style 1 or 2
  Combo1.AddItem "Player 1"
  Combo1.AddItem "Player 2"
  Combo1.AddItem "Player 3"
  Combo1.AddItem "Player 4"
  Combo1.Common.ControlName = "SqueezeBoxPlayerNo"
  Combo1.ItemIndex = SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo")'Players 1 to 4 use integer values 0 to 3
  Combo1.Common.Hint = "Select the SqueezeBox Player you wish to connect to"
  Script.RegisterEvent Combo1.Common, "OnClick", "PlayerSelect"
  
  Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,89,60,20
    .Caption = "Player 1 Name:"
  End With

  Set Edit5 = SDB.UI.NewEdit(Panel4)
  Edit5.Common.ControlName = "SqueezeBoxPlayer1"
  Edit5.Common.SetRect 95,85,110,25
  Edit5.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1")
  If Edit5.Text = "" Then
    Edit5.Text = " "
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = " "
  End If
  Edit5.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,112,55,20
    .Caption = "MAC Address:"
  End With

  Set Edit6 = SDB.UI.NewEdit(Panel4)
  Edit6.Common.ControlName = "SqueezeBoxMAC"
  Edit6.Common.SetRect 95,108,110,25
  Edit6.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC")
  If Edit6.Text = "" Then
    Edit6.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit6.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"

  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,89,60,20
    .Caption = "Player 2 Name:"
  End With

  Set Edit7 = SDB.UI.NewEdit(Panel4)
  Edit7.Common.ControlName = "SqueezeBoxPlayer2"
  Edit7.Common.SetRect 320,85,110,25
  Edit7.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2")
  If Edit7.Text = "" Then
    Edit7.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = ""
  End If
  Edit7.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,112,55,20
    .Caption = "MAC Address:"
  End With

  Set Edit8 = SDB.UI.NewEdit(Panel4)
  Edit8.Common.ControlName = "SqueezeBoxMAC2"
  Edit8.Common.SetRect 320,108,110,25
  Edit8.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2")
  If Edit8.Text = "" Then
    Edit8.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit8.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,142,60,20
    .Caption = "Player 3 Name:"
  End With
  
  Set Edit9 = SDB.UI.NewEdit(Panel4)
  Edit9.Common.ControlName = "SqueezeBoxPlayer3"
  Edit9.Common.SetRect 95,138,110,25
  Edit9.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3")
  If Edit9.Text = "" Then
    Edit9.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = ""
  End If
  Edit9.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 15,165,55,20
    .Caption = "MAC Address:"
  End With

  Set Edit10 = SDB.UI.NewEdit(Panel4)
  Edit10.Common.ControlName = "SqueezeBoxMAC3"
  Edit10.Common.SetRect 95,161,110,25
  Edit10.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3")
  If Edit10.Text = "" Then
    Edit10.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit10.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
      
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,142,60,20
    .Caption = "Player 4 Name:"
  End With

  Set Edit11 = SDB.UI.NewEdit(Panel4)
  Edit11.Common.ControlName = "SqueezeBoxPlayer4"
  Edit11.Common.SetRect 320,138,110,25
  Edit11.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4")
  If Edit11.Text = "" Then
    Edit11.Text = ""
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = ""
  End If
  Edit11.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the Player Name here"
  
  With SDB.UI.NewLabel(Panel4)
    .Common.SetRect 240,165,55,20
    .Caption = "MAC Address:"
  End With

  Set Edit12 = SDB.UI.NewEdit(Panel4)
  Edit12.Common.ControlName = "SqueezeBoxMAC4"
  Edit12.Common.SetRect 320,161,110,25
  Edit12.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4")
  If Edit12.Text = "" Then
    Edit12.Text = "xx:xx:xx:xx:xx:xx"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = "xx:xx:xx:xx:xx:xx"
  End If
  Edit12.Common.Hint = "Open the LMS Web Control page > Settings page > Information tab > copy & paste the MAC Address that matches the player selected above e.g.06:f4:20:1e:4a:43"
  
  Combo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edit12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  
  Set Panel5 = SDB.UI.NewGroupBox(Sheet)
  Panel5.Common.SetRect 10,480,450,145
  Panel5.Caption = "LMS on a Linux or Windows Server/NAS"

  With SDB.UI.NewLabel(Panel5)
    .Multiline = True
    .Common.SetRect 15,20,420,60
    .Caption = "For Linux devices the media folder address in LMS uses forward slashes. e.g. /media/Music. Windows devices use back slashes (\) for all addresses"
  End With

  Set CheckBox3 = SDB.UI.NewCheckBox(Panel5)
  CheckBox3.Common.SetRect 15,53,120,20
  CheckBox3.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","NAS")
  CheckBox3.Common.ControlName = "EnableNAS"
  CheckBox3.Common.Hint = SDB.Localize("Select if using LMS on a Linux or Windows Server/NAS device. See user guide for more details")
  CheckBox3.Caption = SDB.Localize("Enable Server/NAS")
  Script.RegisterEvent CheckBox3.Common, "OnClick", "NASClick"

  Set CheckBox4 = SDB.UI.NewCheckBox(Panel5)
  CheckBox4.Common.SetRect 200,53,260,20
  CheckBox4.Checked = SDB.IniFile.BoolValue("MonkeySqueeze","Synology")
  CheckBox4.Common.ControlName = "EnableSynology"
  CheckBox4.Common.Hint = SDB.Localize("Select if using Squeezebox Server prior to v7.5.1. Tested on Synology devices only")
  CheckBox4.Caption = SDB.Localize("LMS is prior to v7.5.1 (Linux device only)")

  With SDB.UI.NewLabel(Panel5)
    .Common.SetRect 15,84,70,20
    .Caption = "MediaMonkey Music Folder:"
  End With

  Set Edit13 = SDB.UI.NewEdit(Panel5)
  Edit13.Common.ControlName = "MediaMonkeyMF"
  Edit13.Common.SetRect 148,80,281,25
  Edit13.Text = SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF")
  If Edit13.Text = "" Then
    Edit13.Text = "\\Server\folder or X:\__\__(mapped)"
    SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = "\\Server\folder or X:\__\__(mapped)"
  End If
  Edit13.Common.Hint = "Copy from MediaMonkey > File > Add/Rescan Folders or the Path column in the Track Browser section"

  With SDB.UI.NewLabel(Panel5)
    .Common.SetRect 15,114,70,20
    .Caption = "LMS Media Folder:"
  End With

  Set Edit14 = SDB.UI.NewEdit(Panel5)
  Edit14.Common.ControlName = "SqueezeBoxMF"
  Edit14.Common.SetRect 105,110,281,25
  Edit14.Text = SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF")
  If Edit14.Text = "" Then
    Edit14.Text = "/___ /___ Linux, or \ ___\ ___ Windows"
    SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = "/___ /___ Linux, or \ ___\ ___ Windows"
  End If
  Edit14.Common.Hint = "Copy and Paste from: LMS Web Page > Settings > Basic Settings tab > Music Folder"

  CheckBox4.Common.Enabled = CheckBox1.Checked
  Edit13.Common.Enabled = CheckBox1.Checked
  Edit14.Common.Enabled = CheckBox1.Checked

End Sub
'**************************************************************
Sub LogClick(ChB)
  Dim Edt1, Edt2

  Set Edt1 = ChB.Common.TopParent.Common.ChildControl("SqueezeBoxUser")
  Set Edt2 = ChB.Common.TopParent.Common.ChildControl("SqueezeBoxPass")
  Edt1.Common.Enabled = ChB.Checked
  Edt2.Common.Enabled = ChB.Checked
End Sub
'**************************************************************
Sub PlayerSelect(DD)
  Dim Cmbo1, Edt6, Edt8, Edt10, Edt12

  Set Cmbo1 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxPlayerNo")
  Set Edt6 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC")
  Set Edt8 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC2")
  Set Edt10 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC3")
  Set Edt12 = DD.Common.TopParent.Common.ChildControl("SqueezeBoxMAC4")
  Cmbo1.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt6.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt8.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt10.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
  Edt12.Common.Enabled = SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
End Sub
'**************************************************************
Sub NASClick(ChB)
  Dim ChB4, Edt13, Edt14

  Set ChB4 = ChB.Common.TopParent.Common.ChildControl("EnableSynology")
  Set Edt13 = ChB.Common.TopParent.Common.ChildControl("MediaMonkeyMF")
  Set Edt14 = ChB.Common.TopParent.Common.ChildControl("SqueezeBoxMF")
  ChB4.Common.Enabled = ChB.Checked
  Edt13.Common.Enabled = ChB.Checked
  Edt14.Common.Enabled = ChB.Checked
End Sub
'**************************************************************
Sub SaveSheet(Sheet)
  SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") = Sheet.Common.ChildControl( "EnablePT").Checked
  SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = Sheet.Common.ChildControl("SqueezeBoxPlayerNo").ItemIndex
  SDB.IniFile.BoolValue("MonkeySqueeze","Login") = Sheet.Common.ChildControl( "EnableLog").Checked
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") = Sheet.Common.ChildControl("SqueezeBoxUser").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") = Sheet.Common.ChildControl("SqueezeBoxPass").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") = Sheet.Common.ChildControl("SqueezeBoxIP").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") = Sheet.Common.ChildControl("SqueezeBoxPort").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer1") = Sheet.Common.ChildControl("SqueezeBoxPlayer1").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") = Sheet.Common.ChildControl("SqueezeBoxMAC").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer2") = Sheet.Common.ChildControl("SqueezeBoxPlayer2").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") = Sheet.Common.ChildControl("SqueezeBoxMAC2").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer3") = Sheet.Common.ChildControl("SqueezeBoxPlayer3").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") = Sheet.Common.ChildControl("SqueezeBoxMAC3").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPlayer4") = Sheet.Common.ChildControl("SqueezeBoxPlayer4").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") = Sheet.Common.ChildControl("SqueezeBoxMAC4").Text
  SDB.IniFile.BoolValue("MonkeySqueeze","NAS") = Sheet.Common.ChildControl( "EnableNAS").Checked
  SDB.IniFile.BoolValue("MonkeySqueeze","Synology") = Sheet.Common.ChildControl( "EnableSynology").Checked
  SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF") = Sheet.Common.ChildControl("MediaMonkeyMF").Text
  SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF") = Sheet.Common.ChildControl("SqueezeBoxMF").Text
End Sub
'**************************************************************
Sub UserGuide
  On Error Resume Next
  Dim OF, FolderToOpen

  Set OF = CreateObject("Shell.Application")
  FolderToOpen = sdb.ScriptsPath & "Auto\"
  OF.Explore FolderToOpen
  Set OF = Nothing
End Sub
'**************************************************************
Function SqueezeBoxMode
  Dim strRetVal

  On Error Resume Next
  SqueezeBoxMode = ""
  strRetVal = slimRequest(formatCommand("""mode"", ""?"""))
  If InStrRev(strRetVal, "play") > 0 Then
    SqueezeBoxMode = "play"
  ElseIf InStrRev(strRetVal, "stop") > 0 Then
    SqueezeBoxMode = "stop"
  ElseIf InStrRev(strRetVal, "pause") > 0 Then
    SqueezeBoxMode = "pause"
  End If
End Function
'**************************************************************
Sub ShowPlayerSettings
  Dim Plr, Warning, Res

  Warning = ""
  Set Plr = SDB.Player
  'If Plr.isAutoDJ    Then Warning = Warning & vbNewLine & "AutoDJ is on"
  If Plr.isCrossFade Then Warning = Warning & vbNewLine & "CrossFade is on"
  If Plr.isShuffle   Then Warning = Warning & vbNewLine & "Shuffle is on"
  If Plr.isEqualizer Then Warning = Warning & vbNewLine & "Equalizer is on"
  If Plr.isRepeat    Then Warning = Warning & vbNewLine & "Repeat is on"
  If Warning <> "" Then
    Res = SDB.MessageBox("Selected player settings:" & vbNewLine & _
    Warning, mtWarning, Array(mbOk))
  End If
End Sub
'**************************************************************
Function SyncToggle( itm )

  If SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False Then
    SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = True
    itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOn.ico", 0)
    Call registerEvents
    If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""1"""))
    ShowPlayerSettings
    FillPlaylist
  Else
    SDB.IniFile.BoolValue("MonkeySqueeze","SyncToggle") = False
    itm.IconIndex = SDB.RegisterIcon("Scripts\Auto\MonkeySqueezeOff.ico", 0)
    Call unregisterEvents
    slimRequest(formatCommand("""stop"""))
    If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
  End If
End Function
'**************************************************************
Sub Event_OnPlay
  Dim strRetVal, Idx

  If (SqueezeBoxMode = "play") And EndOfTrack Then
      '*** normal playlist continuation
      EndOfTrack = False
  Else
    '*** SqueezeBox is not playing or new track out of order
    Idx = SDB.Player.CurrentSongIndex
    slimRequest(formatCommand("""playlist"", ""index"", """ + Cstr(Idx) + """"))
  End If
End Sub
'**************************************************************
Sub Event_OnTrackEnd
  Dim strRetVal, idx, tim, dur

  '*** see if current track ended, then playing is not interrupted
  EndOfTrack = True
End Sub
'**************************************************************
Function CheckPath(SongValue)
  If Left(SongValue.Path,1) = "?" Then
    If SongValue.Cached Then
      CheckPath = SongValue.CachedPath
    Else
      CheckPath = SongValue.Path
    End If
  Else
    CheckPath = SongValue.Path
  End If
  If SDB.IniFile.BoolValue("MonkeySqueeze","NAS") Then
    If SDB.IniFile.BoolValue("MonkeySqueeze","Synology") Then CheckPath = Replace(CheckPath,"\","/")
    CheckPath = Replace(CheckPath,SDB.IniFile.StringValue("MonkeySqueeze","MediaMonkeyMF"),SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMF"))
  End If
End Function
'**************************************************************
Sub Event_OnStop
  slimRequest(formatCommand("""stop"""))
End Sub
'**************************************************************
Sub Event_OnShutdown
  On Error Resume Next
  slimRequest(formatCommand("""stop"""))
  If SDB.IniFile.BoolValue("MonkeySqueeze","PowerToggle") Then slimRequest(formatCommand("""power"", ""0"""))
End Sub
'**************************************************************
Sub Event_OnPause

  If SDB.Player.IsPaused Then
    slimRequest(formatCommand("""pause"""))
  Else
    slimRequest(formatCommand("""play"""))
  End If
End Sub
'**************************************************************
Sub Event_OnSeek
  Dim SBmode, Song, TrackPath, LMStime

  SBmode = SqueezeBoxMode
  If SBmode = "stop" Then
    Set Song = SDB.Player.CurrentSong
    TrackPath = CheckPath(Song)
    slimRequest(formatCommand("""playlist"", ""play"", """ + perlEscape(TrackPath) + """"))
  End If
  LMStime = 0.001 * SDB.Player.PlaybackTime
  slimRequest(formatCommand("""time"", """ + CStr(LMStime) + """"))
End Sub
'**************************************************************
Function slimRequest(params)
  'slimRequest accepts pre-formatted parameter string, returns string of the response'
  'logme "  >> slimRequest: Begin with " + params
  Dim url, prog, objHTTP
  Dim cnt : cnt = 0

  If SDB.IniFile.BoolValue("MonkeySqueeze","Login") = True Then
    url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxUser") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPass") + "@" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
  Else
    url = "http://" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxIP") + ":" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxPort") + "/jsonrpc.js"
  End If
  
  'Set prog = SDB.Objects("LoadXMLBar")
  Set prog = SDB.Progress
  Set objHTTP = CreateObject("Microsoft.XMLHTTP")
  Call objHTTP.open("POST", url, True)
  objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
  objHTTP.setRequestHeader "X-Requested-With", "XMLHttpRequest"
  objHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1"
  objHTTP.send(params)

  Do While (objHTTP.readyState < 4) And (cnt < 300)
    Call SDB.Tools.Sleep(100)
    SDB.ProcessMessages
    cnt = cnt+1
    If prog.Terminate Then
      cnt = 300
    End If
  Loop

  If objHTTP.readyState < 4 Then
    Set slimRequest = Nothing
  Else
    slimRequest = objHTTP.responseText
  End If
End Function
'*************************************************************
'This is is a JSON RPC call - We're directly calling functions in the Slim::Request module in Perl. See here:
'http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm
'the addDispatch section tells you how to use the commands and what the RPC module is looking for in terms of formatting
Function formatCommand(str1)
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 0 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC") + """,[" + str1 + "]]}"
  End If

  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 1 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC2") + """,[" + str1 + "]]}"
  End If

  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 2 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC3") + """,[" + str1 + "]]}"
  End If
 
  If SDB.IniFile.IntValue("MonkeySqueeze","SqueezeBoxPlayerNo") = 3 Then
    formatCommand = "{""id"":1,""method"":""slim.request"",""params"":[""" + SDB.IniFile.StringValue("MonkeySqueeze","SqueezeBoxMAC4") + """,[" + str1 + "]]}"
  End If

End Function
'*************************************************************
'borrowed from a teknojunky - if you want the popups add them to this and then just call logme
Sub logme(msg)
  Dim fso, logf

  On Error Resume Next
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set logf = fso.OpenTextFile(Script.ScriptPath&".log",ForAppending,True)
  logf.WriteLine Now() & ": " & msg
  Set fso = Nothing
  Set logf = Nothing
End Sub
'*************************************************************
'Perl is taking the JSON strings directly into variables - "\" is a special character in perl to escape the following string
'wherever we have a "\" we need it to be "\\" in anything that goes to Perl (ie: anything that goes to SqueezeBox)
Function perlEscape(str1)
  perlEscape = Replace(str1, "\", "\\")
End Function
'*************************************************************
Sub registerEvents
  Call Script.RegisterEvent(SDB,"OnPlay","Event_OnPlay")
  Call Script.RegisterEvent(SDB,"OnPause","Event_OnPause")
  Call Script.RegisterEvent(SDB,"OnStop","Event_OnStop")
  Call Script.RegisterEvent(SDB,"OnSeek","Event_OnSeek")
  Call Script.RegisterEvent(SDB,"OnTrackEnd","Event_OnTrackEnd")
  Call Script.RegisterEvent(SDB,"OnShutdown","Event_OnShutdown")
  Call Script.RegisterEvent(SDB,"OnNowPlayingModified","Event_OnNowPlayingModified")
End Sub
'*************************************************************
Sub Event_OnNowPlayingModified
  Dim MMcount

  MMcount = SDB.Player.CurrentPlayList.Count
  'logme("Now playing modified")
  'logme("Aantal MM tracks: " & Cstr(MMcount))
  'logme("Aantal LMS tracks: " & Cstr(LMScount))
  If SqueezeBoxMode = "stop" Then
    FillPlaylist
  ElseIf MMcount = 0 Then
    ResetPlaylist
  ElseIf MMcount < LMScount Then
    TracksDeleted(MMcount)
  ElseIf MMcount > LMScount Then
    TracksAdded(MMcount)
  Else
    TracksMoved
  End If
End Sub
'*************************************************************
Sub FillPlaylist
  '*** synchronize MM playlist with LMS playlist
  Dim tempStop, Idx

  '*** clear LMS playlist and stop shuffle!!
  slimRequest(formatCommand("""playlist"", ""clear"""))
  slimRequest(formatCommand("""playlist"", ""shuffle"", ""0"""))
  '*** copy MM playlist - if any - to LMS
  LMScount = SDB.Player.CurrentPlayList.Count
  ReDim LMSpaths(LMScount)
  '*** if playlist is empty we are done
  If LMScount > 0 Then
    tempStop = SDB.Player.isPlaying And (SDB.Player.PlayBackTime < 2000)
    If tempStop Then
      SDB.Player.pause
      slimRequest(formatCommand("""stop"""))
    End If
    SendPlaylist
    '*** jump to current song
    Idx = SDB.Player.CurrentSongIndex
    slimRequest(formatCommand("""playlist"", ""index"", """ + Cstr(Idx) + """"))
    If tempStop Then
      '*** Start playback after filling playlist
      SDB.Player.Pause
    ElseIf SDB.Player.isPlaying Then
      '*** Synchronize LMS with current track
      slimRequest(formatCommand("""time"", """ + CStr(SDB.Player.PlaybackTime*0.001) + """"))
      If SDB.Player.isPaused Then SDB.Player.Pause
    Else
      '*** MediaMonkey is not playing
      slimRequest(formatCommand("""stop"""))
    End If
  End If
  EndOfTrack = False
End Sub
'**************************************************************
Sub SendPlaylist
  Dim Progr, TrackPath, Song, n

  '*** show progress bar
  Set Progr = SDB.Progress
  Progr.Text = SDB.Localize("Synchronising playlists...")
  Progr.MaxValue = LMScount
  '*** send playlist
  For n=0 To LMScount-1
    Set Song = SDB.Player.CurrentPlayList.Item(n)
    TrackPath = CheckPath(Song)
    LMSpaths(n) = TrackPath
    slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
    Progr.Value = n+1
  Next
End Sub
'**************************************************************
Sub ResetPlaylist

  SDB.Player.Stop
  slimRequest(formatCommand("""stop"""))
  slimRequest(formatCommand("""playlist"", ""clear"""))
  ReDim LMSpaths(0)
  LMScount = 0
End Sub
'**************************************************************
Sub TracksDeleted(MMcount)
  Dim n, m, Song, TrackPath

  'logme("Tracks deleted")
  n = 0
  Do While MMcount < LMScount
    If n = MMcount Then
      TrackPath = "***"
    Else
      Set Song = SDB.Player.CurrentPlayList.Item(n)
      TrackPath = CheckPath(Song)
    End If
    If (TrackPath = LMSpaths(n)) Then
      n = n+1
    Else
      LMScount = LMScount - 1
      For m = n To LMScount - 1
        LMSpaths(m) = LMSpaths(m+1)
      Next
      slimRequest(formatCommand("""playlist"", ""delete"", """ + Cstr(n) + """"))
    End If
  Loop
End Sub
'*************************************************************
Sub TracksAdded(MMcount)
  Dim n, m, Song, TrackPath

  'logme("Tracks added")
  ReDim Preserve LMSpaths(MMcount)  'expand array, preserve content
  Do
    For n = 0 to MMcount -1
      Set Song = SDB.Player.CurrentPlayList.Item(n)
      TrackPath = CheckPath(Song)
      If (TrackPath <> LMSpaths(n)) Then
        slimRequest(formatCommand("""playlist"", ""add"", """ + perlEscape(TrackPath) + """"))
        If n < LMScount Then
          slimRequest(formatCommand("""playlist"", ""move"", """ + Cstr(LMScount) + """, """ + Cstr(n) + """"))
          For m = LMScount To n+1 Step -1
            LMSpaths(m) = LMSpaths(m-1)
          Next
        End If
        LMSpaths(n) = TrackPath
        LMScount = LMScount + 1
      End If
    Next
  Loop While MMcount > LMScount
End Sub
'*************************************************************
Sub TracksMoved
  Dim n, m, i, Song, TrackPath, tempPath

  'logme("Tracks moved")
  For n=0 To LMScount-1
    Set Song = SDB.Player.CurrentPlayList.Item(n)
    TrackPath = CheckPath(Song)
    If TrackPath <> LMSpaths(n) Then
      For m=n+1 To LMScount-1
        If TrackPath = LMSpaths(m) Then Exit For
      Next
      For i=m To n+1 Step -1
        LMSpaths(i) = LMSpaths(i-1)
      Next
      LMSpaths(n) = TrackPath
      slimRequest(formatCommand("""playlist"", ""move"", """ + Cstr(m) + """, """ + Cstr(n) + """"))
    End If
  Next
End Sub
'*************************************************************
Sub unregisterEvents
  Script.UnregisterEvents SDB
End Sub
'*************************************************************
'These are what the full JSON strings look like that need to be sent to slimRequest()
'formatRequest() fills in the first part and all you have to do is pick the RPC commands from http://svn.slimdevices.com/repos/slim/7.5/trunk/server/Slim/Control/Request.pm

'Note: there are cleaner ways of doing this - but this is quick and dirty. It just means that you have to use a lot of """ and etc in vbscript.
'This entire script is much easier to write in jscript but I don't know jscript at all so, shrug.

'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:cgABbehldiqtyrSuoKLN"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["status","-",1,"tags:uB"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["playlist","index",28]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",["pause"]]}
'{"id":1,"method":"slim.request","params":["00:04:20:17:06:xx",[""playlist"", ""play"", ""D:\\MP3\\filename.mp3""]]}


'You can do ANYTHING you can do from the web interface via this RPC engine because you are directly calling the methods in Perl
'so you could add whole playlists and etc see the docs. Sky's the limit.

Re: MonkeySqueeze Development V3.0.2.

by Gingernut63 » Sun May 17, 2015 4:07 pm

oeyoeve wrote:Hi,
I loaded 3.0.1.150513Beta, and I receive no error messages what so ever. All seems to work just fine, but nothing plays although the progress bar is running normally, so obviously MM believes that the song is playing.
If I disable Logon in MonkeySqueeze and disable password protection in LMS, everything works just fine.

Any Ideas?
Yes, there is probably a space before or after the username and password that is there from the coding :oops: (now fixed in the beta). On the options page place the cursor to the far right of the username and password (including any space that may be there) and backspace as far as it will go and then enter them again.

Re: MonkeySqueeze Development V3.0.2.

by oeyoeve » Sun May 17, 2015 8:00 am

Hi,
I loaded 3.0.1.150513Beta, and I receive no error messages what so ever. All seems to work just fine, but nothing plays although the progress bar is running normally, so obviously MM believes that the song is playing.
If I disable Logon in MonkeySqueeze and disable password protection in LMS, everything works just fine.

Any Ideas?

Top