Nicely working now with several small javascript widgets.
[adorno.git] / inc / daemonInterface.php
blobc2849461738b5a6c0bc53547ec9d37732ab2350c
1 <?php
3 include_once('AwlQuery.php');
5 switch ( $c->daemon_type ) {
6 case 'mpd': include("mpdPlayer.php"); break;
7 case 'vlc': include("vlcPlayer.php"); break;
8 case 'xmms2': include("xmms2Player.php"); break;
9 default: include("adornoPlayer.php");
12 /**
13 * High level function to play a track
15 function PlayTrack( $path, $hash ) {
16 if ( isset($_GET['act']) && $_GET['act'] == 'no' && ( !isset($_POST['act']) || $_POST['act'] == 'no') ) {
17 error_log( sprintf("DBG: PlayTrack: *NOT* Queueing '%s' for playing", $path) );
18 return;
21 error_log( sprintf("DBG: PlayTrack: Queueing '%s' for playing", $path) );
23 if ( daemon_play_track($path) ) {
24 $qry = new AwlQuery( "SELECT track_played(?) ", $hash );
25 $qry->Exec("PlayTrack");
30 /**
31 * High level function to get the current track as a database object
33 function current_track() {
35 $current_track = daemon_current_track();
37 $query = "SELECT *, extract( EPOCH FROM duration)::int AS secs ";
38 if ( preg_match( '/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}/', $current_track->started ) ) {
39 $query .= ", extract( EPOCH FROM ('".$current_track->started."'::timestamp + duration))::int AS finishing ";
41 $query .= "FROM tracks WHERE path_name = ? ; ";
43 $qry = new AwlQuery( $query, $current_track->track );
44 if ( $qry->Exec('current_track') && $qry->rows() > 0 ) {
45 $track = $qry->Fetch();
46 $track->state = $current_track->state;
47 return $track;
49 return;
53 /**
54 * High level function to crudely display the current track
56 function show_queue() {
58 $queue = daemon_get_queue();
60 echo "<h3>Coming up...</h3>\n<p class=\"track_queue\">";
61 foreach( $queue AS $k => $v ) {
62 echo nice_track_name($v) . "<br>\n";
64 echo "</p>";
68 /**
69 * High level function to return an array of $track objects
71 function current_queue() {
73 $queue = daemon_get_queue();
75 $queue_pos = array();
76 $position = 0;
77 $in_list = '';
78 $params = array();
79 foreach( $queue AS $k => $track ) {
80 $in_list .= ($position == 0 ? '' : ', ') . ':t'.$position;
81 $params[':t'.$position] = $track;
82 $queue_pos[$track] = $position++;
85 $queue = array();
86 if ( $in_list == '' ) return $queue;
88 /**
89 * Select the track information from the database
91 $sql = sprintf("SELECT *, EXTRACT( 'epoch' FROM duration ) AS dur_secs FROM tracks WHERE path_name IN ( %s );", $in_list );
92 $qry = new AwlQuery( $sql, $params );
93 if ( $qry->Exec("current_queue",__LINE__,__FILE__) && $qry->rows() ) {
94 while( $track = $qry->Fetch() ) {
95 $position = $queue_pos[$track->path_name];
96 $queue[$position] = $track;
100 return $queue;