Remote Control

SnackAmp provides a built-in web server that is primarily used to allow other clients to control play. This is useful if you stereo is connected to one computer and you happen to be at another. There is an example of a remote control web page here. The left hand side holds the play control interface, the right hand side holds the remote playlist.

From the play control interface you can:

On the remote playlist you will get a current detailed view of the queued  track, its play status, and a list of the next N tracks (N being selectable in the settings). For each queued track you can get more details , play it, or remove it from the queue.

Remote Control Settings

From the Web/Browser tab of the settings form you can enable/disable the remote control, set the port number to use and adjust the refresh rate client browsers will use to get play updates. As mentioned above, you can also set the number of tracks displayed in the playlist. There is also additional information shown such as URL and file locations.

The remote control is disabled by default.

Tcl Macro Language (TML) Files

The built it web server provides special handling of files ending in the .tml extension. These files receive an initial substitution by the Tcl parser which allows you to embed tcl code which can expand into dynamic html. If you are familiar with php, this is very similar. The play control interface uses this build up the various choices for playlists and AutoPlaylists.

Included tml macros

Macro Description
[HTH::aplFiles] Returns a list of AutoPlaylist files without the folder pre-pended or file extension. Used to fill in a combo box.
[HTH::plFiles] Returns a list of Playlist files without the folder pre-pended or file extension. Used to fill in a combo box.
[remote/control::sndInfo] Return a formatted table showing details on the currently playing track.
[remote/control::nextToPlay showButton, N] Return the next N tracks in the playlist, and optionally add Play and Remove buttons if showButton=1.

Extending the Remote Control Interface

Another option from the Web/Browser tab of the settings form allows you set the local folder to map /local to. You can use this to mount a local web site to the /local url on the built in web browser. Doing so, you can build your own remote control user interface or create additional SnackAmp interfaces. The example below is a file called queued.tml that can be placed in the user mapped local folder and when processed by SnackAmp will show the current track and next N tracks.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<LINK REL="StyleSheet" HREF="../snackamp.css" TYPE="text/css" MEDIA="screen">
<title>SnackAmp Playing</title>
</head>
<body>
<table width="100%">
<tr>
<td width = "30%">
<p align="left">
<img border="0" src="../user_manual/images/sa_logo.png" width="292" height="83">
</p>
</td>
<td>
<hr color="blue">
</td>
</tr>
</table>
[set remote/search::close_window] 
[remote/control::sndInfo] 
[remote/control::nextToPlay 1 $::snackAmpSettings(httpNextLength)]
</body>
</html>

Built in url Functions

In addition to tml macro expansion, you can create additional pure tcl dynamic web pages such that a reference to a specific url calls a tcl function which dynamically generates web content. The remote playlist uses this entirely.

URL Description and parameters
/display Read only display of the playlist, you can post this to users who won't have any control over your player (e.g. on the WWW). It takes no parameters.
/control Main control URL used to control the player. Parameters include:

?bt_Control=cmd, run a SnackAmp macro where cmd is some existing SnackAmp macro such as Play, next, Prev, Stop.
?bt_Level=n, where n is some pos/neg integer which is used to bump the volume up or down.
?play=track, where track is some complete path name to a sound file that will be played immediately.
?delete=index, removes a track from the playlist where index is a numerical position.
?cmd_APL=aplfile, applies a AutoPlaylist file where aplfile is the file name without the folder prefixed or the .tafs file extension.
?cmd_Sort=sortMode, sorts the playlist either "sort tracks", "shuffle tracks", "shuflesort" or "shuffleShuffle".
?filter_text=text&filter_what=what&search_replace=how, modifies the playlist either appending or replacing it with tracks that meet the search criteria. "text" can be any url formatted text, what can be "allfiles", "playlist" or "autoplaylist" to denote where to search. "how" can be either "append" or "replace" to denote what to do with the existing playlist.
?cmb_PL=file&PL_search_replace=how, processes an existing playlist file. "file" is the playlist file without the folder or .taf file extension. "how" can be either "append" or "replace" to denote what to do with the existing playlist.
/control?Status=Refresh+Data, will refresh the page making the call with the current track, and the next N tracks.

/remote/search Jukebox interface to search for files and provide user with interface to add them to the playlist. The parameters include:

?jb_search=text&search_what=what, searches for tracks matching the "text" search criteria and brings up a html page allowing you to individually select tracks for addition to the playlist. "what" is one of "allfiles", "playlist" or "autoplaylist".
?play=track, where track is some complete path name to a sound file that will be played immediately.
?delete=index, removes a track from the playlist where index is a numerical position.
?question=file, pop-us a web page showing details on the "file".

To create your own url functions, create a namespace with the name of the url (e.g. display:: for /yourcommand). Then create a function within the namespaces called process (e.g. yourcommand::process) which will handle all of the processing for this URL. You must also create a init function with when called, should return a 1. This enables the use of that url. The HttpD.tcl script file has the above built-in url functions.

The format for the process function is shown below:

namespace eval ::yourcommand {
    proc init { } {
        return 1
    }
}
proc yourcommand::process {sock {params ""}} {
    # output to the socket some head info
    puts $sock [remote/control::leader "SnackAmp yourcommand"]
    foreach param [split $params &] {
        foreach {CmdType Cmd} [split $param =] {break}
        set Cmd [HttpD::Decode $Cmd]
        switch -- $CmdType {
            cmd1 {
                #process cmd, passed as /yourcommand?cmd1=stuff (Cmd=stuff)
                puts $sock "<p>$Cmd</p>"
            }
            cmd2 {
                #process cmd, passed as /yourcommand?cmd2=stuff (Cmd=stuff)
                puts $sock "<p>$Cmd</p>"
            }
        }

        default {}
        } ;# End Switch
    }
    # close the page and send a socketdone
    puts $sock "</body>\n</html>"
    HttpD::SocketDone $sock 1
    return 0
}