"DbName", "dc:creator" => "DbCreator", "dc:description" => "DbDescription", "dcterms:extent" => "length");
public function __construct()
{
}
/**
- * Convert playlist time value to float seconds
- *
- * @param string $plt
- * playlist time value (HH:mm:ss.dddddd)
- * @return int
- * seconds
- */
public static function playlistTimeToSeconds($plt)
{
$arr = preg_split('/:/', $plt);
if (isset($arr[2])) {
return (intval($arr[0])*60 + intval($arr[1]))*60 + floatval($arr[2]);
}
if (isset($arr[1])) {
return intval($arr[0])*60 + floatval($arr[1]);
}
return floatval($arr[0]);
}
/**
- * Convert float seconds value to playlist time format
- *
- * @param float $seconds
- * @return string
- * time in playlist time format (HH:mm:ss.dddddd)
- */
public static function secondsToPlaylistTime($p_seconds)
{
$seconds = $p_seconds;
$milliseconds = intval(($seconds - intval($seconds)) * 1000);
$milliStr = str_pad($milliseconds, 6, '0');
$hours = floor($seconds / 3600);
$seconds -= $hours * 3600;
$minutes = floor($seconds / 60);
$seconds -= $minutes * 60;
$res = sprintf("%02d:%02d:%02d.%s", $hours, $minutes, $seconds, $milliStr);
return $res;
}
public static function Insert($p_values)
{
// Create the StoredPlaylist object
$storedPlaylist = new Playlist();
$storedPlaylist->name = isset($p_values['filename']) ? $p_values['filename'] : date("H:i:s");
$storedPlaylist->mtime = new DateTime("now");
$pl = new CcPlaylist();
$pl->setDbName($storedPlaylist->name);
$pl->setDbState("incomplete");
$pl->setDbMtime($storedPlaylist->mtime);
$pl->save();
$storedPlaylist->id = $pl->getDbId();
$storedPlaylist->setState('ready');
return $storedPlaylist->id;
}
public static function Delete($id) {
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
$pl->delete();
return TRUE;
}
/**
* Delete the file from all playlists.
* @param string $p_fileId
*/
public static function DeleteFileFromAllPlaylists($p_fileId)
{
CcPlaylistcontentsQuery::create()->filterByDbFileId($p_fileId)->delete();
}
public static function findPlaylistByName($p_name)
{
$res = CcPlaylistQuery::create()->findByDbName($p_name);
return $res;
}
public static function findPlaylistMaxLength($p_length)
{
$con = Propel::getConnection("campcaster");
$sql = "SELECT * FROM cc_playlist LEFT JOIN cc_playlisttimes USING(id) WHERE length <= '{$p_length}' AND state != 'edited' ";
$r = $con->query($sql);
return $r->fetchAll();
}
/**
* Fetch instance of Playlist object.
*
* @param string $id
* DB id of file
* @return Playlist|FALSE
* Return FALSE if the object doesnt exist in the DB.
*/
public static function Recall($id) {
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
$storedPlaylist = new Playlist();
$storedPlaylist->id = $pl->getDbId();
$storedPlaylist->name = $pl->getDbName();
$storedPlaylist->state = $pl->getDbState();
$storedPlaylist->currentlyaccessing = $pl->getDbCurrentlyaccessing();
$storedPlaylist->editedby = $pl->getDbEditedby();
$storedPlaylist->mtime = $pl->getDbMtime();
return $storedPlaylist;
}
/**
* Rename stored virtual playlist
*
* @param string $p_newname
* @return TRUE|PEAR_Error
*/
public function setName($p_newname)
{
$pl = CcPlaylistQuery::create()->findPK($this->id);
if($pl === NULL)
return FALSE;
$pl->setDbName($p_newname);
$pl->setDbMtime(new DateTime("now"));
$pl->save();
$this->name = $p_newname;
return TRUE;
}
/**
* Get mnemonic playlist name
*
* @param string $p_gunid
* global unique id of playlist
* @return string
*/
public function getName($id=NULL)
{
if (is_null($id)) {
return $this->name;
}
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
return $pl->getDbName();
}
/**
* Set state of virtual playlist
*
* @param string $p_state
* 'empty'|'incomplete'|'ready'|'edited'
* @param int $p_editedby
* user id | 'NULL' for clear editedBy field
* @return TRUE|PEAR_Error
*/
public function setState($p_state, $p_editedby=NULL)
{
$pl = CcPlaylistQuery::create()->findPK($this->id);
if($pl === NULL)
return FALSE;
$pl->setDbState($p_state);
$pl->setDbMtime(new DateTime("now"));
$eb = (!is_null($p_editedby) ? $p_editedby : NULL);
$pl->setDbEditedby($eb);
$pl->save();
$this->state = $p_state;
$this->editedby = $p_editedby;
return TRUE;
}
/**
* Get storage-internal file state
*
* @param string $p_gunid
* global unique id of file
* @return string
* see install()
*/
public function getState($id=NULL)
{
if (is_null($id)) {
return $this->state;
}
$pl = CcPlaylistQuery::create()->findPK($id);
if($pl === NULL)
return FALSE;
return $pl->getDbState();
}
/**
* Returns true if virtual file is currently in use.
* Static or dynamic call is possible.
*
* @param string $p_gunid
* optional (for static call), global unique id
* @return boolean|PEAR_Error
*/
public function isAccessed($id=NULL)
{
if (is_null($id)) {
return ($this->currentlyaccessing > 0);
}
$pl = CcPlaylistQuery::create()->findPK($id);
if (is_null($pl)) {
return PEAR::raiseError(
"StoredPlaylist::isAccessed: invalid id ($id)",
GBERR_FOBJNEX
);
}
return ($pl->getDbCurrentlyaccessing() > 0);
}
/**
* Returns id of user editing playlist
*
* @param string $p_playlistId
* playlist global unique ID
* @return int id of user editing playlist
*/
public function isEdited() {
if($this->state === 'edited') {
return $this->editedby;
}
return FALSE;
}
/**
* Set playlist edit flag
*
* @param string $p_playlistId
* Playlist unique ID
* @param boolean $p_val
* Set/clear of edit flag
* @param string $p_sessid
* Session id
* @param int $p_subjid
* Subject id (if sessid is not specified)
* @return boolean
* TRUE on success.
*/
public function setEditFlag($p_subjid, $p_val=TRUE) {
if ($p_val) {
$r = $this->setState('edited', $p_subjid);
} else {
$r = $this->setState('ready');
}
if ($r === FALSE) {
return FALSE;
}
return TRUE;
}
/**
* Return local ID of virtual file.
*
* @return int
*/
public function getId() {
return $this->id;
}
private function getNextPos() {
$res = CcPlaylistQuery::create()
->findPK($this->id)
->computeLastPosition();
if(is_null($res))
return 0;
return $res + 1;
}
/**
* Get the entire playlist as a two dimentional array, sorted in order of play.
* @return array
*/
public function getContents() {
$files = array();
$rows = CcPlaylistcontentsQuery::create()
->joinWith('CcFiles')
->orderByDbPosition()
->filterByDbPlaylistId($this->id)
->find();
foreach ($rows as $row) {
$files[] = $row->toArray(BasePeer::TYPE_FIELDNAME, true, true);
}
return $files;
}
public function getLength() {
$res = CcPlaylistQuery::create()
->findPK($this->id)
->computeLength();
if(is_null($res))
return '00:00:00.000000';
return $res;
}
/**
* Create instance of Playlist object and insert empty file
*
* @param string $fname
* name of new file
* @return instance of Playlist object
*/
public function create($fname=NULL)
{
$values = array("filename" => $fname);
$pl_id = Playlist::Insert($values);
$this->id = $pl_id;
return $this->id;
}
/**
* Lock playlist for edit
*
* @param int $subjid
* local subject (user) id
* @param boolean $val
* if false do unlock
* @return boolean
* previous state or error object
*/
public function lock($subjid, $val=TRUE)
{
if ($val && $this->isEdited() !== FALSE) {
return PEAR::raiseError(
'Playlist::lock: playlist already locked'
);
}
$r = $this->setEditFlag($subjid, $val);
return $r;
}
/**
* Unlock playlist
*
* @return boolean
* previous state or error object
*/
public function unlock($subjid)
{
$r = $this->lock($subjid, FALSE);
return $r;
}
/**
* Add audio clip to the playlist
*
* @param string $p_id
* local ID of added file
* @param string $p_position
* optional, Which position in the playlist to insert the audio clip
* @param string $p_fadeIn
* optional, in time format hh:mm:ss.ssssss - total duration
* @param string $p_fadeOut
* optional, in time format hh:mm:ss.ssssss - total duration
* @param string $p_clipLength
* optional length in in time format hh:mm:ss.ssssss -
* for webstream (or for overrule length of audioclip)
* @return true|PEAR_Error
* TRUE on success
*/
public function addAudioClip($p_mediaId, $p_position=NULL, $p_fadeIn=NULL, $p_fadeOut=NULL, $p_clipLength=NULL, $p_cuein=NULL, $p_cueout=NULL)
{
//get audio clip.
$media = StoredFile::Recall($p_mediaId);
if (is_null($media) || PEAR::isError($media)) {
return $media;
}
$metadata = $media->getMetadata();
$length = $metadata["length"];
if (!is_null($p_clipLength)) {
$length = $p_clipLength;
}
// insert at end of playlist.
if (is_null($p_position))
$p_position = $this->getNextPos();
// insert default values if parameter was empty
$p_cuein = !is_null($p_cuein) ? $p_cuein : '00:00:00.000000';
$p_cueout = !is_null($p_cueout) ? $p_cueout : $length;
$con = Propel::getConnection("campcaster");
$sql = "SELECT INTERVAL '{$p_cueout}' - INTERVAL '{$p_cuein}'";
$r = $con->query($sql);
$p_cliplength = $r->fetchColumn(0);
$res = $this->insertPlaylistElement($this->id, $p_mediaId, $p_position, $p_cliplength, $p_cuein, $p_cueout, $p_fadeIn, $p_fadeOut);
return TRUE;
}
/**
* Remove audioClip from playlist
*
* @param int $position
* position of audioclip in the playlist.
* @return boolean
*/
public function delAudioClip($pos)
{
if($pos < 0 || $pos >= $this->getNextPos())
return FALSE;
$row = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
if(is_null($row))
return FALSE;
$row->delete();
return $row;
}
/**
* Move audioClip to the new position in the playlist
*
* @param int $oldPos
* old positioin in playlist
* @param int $newPos
* new position in playlist
* @return mixed
*/
public function moveAudioClip($oldPos, $newPos)
{
if($newPos < 0 || $newPos >= $this->getNextPos() || $oldPos < 0 || $oldPos >= $this->getNextPos())
return FALSE;
$row = $this->delAudioClip($oldPos);
if($row === FALSE)
return FALSE;
$res = $this->addAudioClip($row->getDbFileId(), $newPos, $row->getDbFadein(), $row->getDbFadeout(), $row->getDbCliplength(), $row->getDbCuein(), $row->getDbCueout());
if($res !== TRUE)
return FALSE;
return TRUE;
}
/**
* Change fadeIn and fadeOut values for playlist Element
*
* @param int $pos
* position of audioclip in playlist
* @param string $fadeIn
* new value in ss.ssssss or extent format
* @param string $fadeOut
* new value in ss.ssssss or extent format
* @return boolean
*/
public function changeFadeInfo($pos, $fadeIn, $fadeOut)
{
$errArray= array();
$con = Propel::getConnection("campcaster");
if(is_null($pos) || $pos < 0 || $pos >= $this->getNextPos()) {
$errArray["error"]="Invalid position.";
return $errArray;
}
$row = CcPlaylistcontentsQuery::create()
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
$clipLength = $row->getDbCliplength();
if(!is_null($fadeIn)) {
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$clipLength}'";
$r = $con->query($sql);
if($r->fetchColumn(0)) {
$errArray["error"]="Fade In can't be larger than overall playlength.";
return $errArray;
}
$row->setDbFadein($fadeIn);
}
if(!is_null($fadeOut)){
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$clipLength}'";
$r = $con->query($sql);
if($r->fetchColumn(0)) {
$errArray["error"]="Fade Out can't be larger than overall playlength.";
return $errArray;
}
$row->setDbFadeout($fadeOut);
}
$row->save();
return array("fadeIn"=>$fadeIn, "fadeOut"=>$fadeOut);
}
/**
* Change cueIn/cueOut values for playlist element
*
* @param int $pos
* position of audioclip in playlist
* @param string $cueIn
* new value in ss.ssssss or extent format
* @param string $cueOut
* new value in ss.ssssss or extent format
* @return boolean or pear error object
*/
public function changeClipLength($pos, $cueIn, $cueOut)
{
$errArray= array();
$con = Propel::getConnection("campcaster");
if(is_null($cueIn) && is_null($cueOut)) {
$errArray["error"]="Cue in and cue out are null.";
return $errArray;
}
if(is_null($pos) || $pos < 0 || $pos >= $this->getNextPos()) {
$errArray["error"]="Invalid position.";
return $errArray;
}
$row = CcPlaylistcontentsQuery::create()
->joinWith(CcFilesPeer::OM_CLASS)
->filterByDbPlaylistId($this->id)
->filterByDbPosition($pos)
->findOne();
$oldCueIn = $row->getDBCuein();
$oldCueOut = $row->getDbCueout();
$fadeIn = $row->getDbFadein();
$fadeOut = $row->getDbFadeout();
$file = $row->getCcFiles();
$origLength = $file->getDbLength();
if(!is_null($cueIn) && !is_null($cueOut)){
if($cueOut === ""){
$cueOut = $origLength;
}
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$cueOut}'";
$r = $con->query($sql);
if($r->fetchColumn(0)) {
$errArray["error"]= "Can't set cue in to be larger than cue out.";
return $errArray;
}
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'";
$r = $con->query($sql);
if($r->fetchColumn(0)){
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$cueIn}'";
$r = $con->query($sql);
$cliplength = $r->fetchColumn(0);
$row->setDbCuein($cueIn);
$row->setDbCueout($cueOut);
$row->setDBCliplength($cliplength);
}
else if(!is_null($cueIn)) {
$sql = "SELECT INTERVAL '{$cueIn}' > INTERVAL '{$oldCueOut}'";
$r = $con->query($sql);
if($r->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
$sql = "SELECT INTERVAL '{$oldCueOut}' - INTERVAL '{$cueIn}'";
$r = $con->query($sql);
$cliplength = $r->fetchColumn(0);
$row->setDbCuein($cueIn);
$row->setDBCliplength($cliplength);
}
else if(!is_null($cueOut)) {
if($cueOut === ""){
$cueOut = $origLength;
}
$sql = "SELECT INTERVAL '{$cueOut}' < INTERVAL '{$oldCueIn}'";
$r = $con->query($sql);
if($r->fetchColumn(0)) {
$errArray["error"] ="Can't set cue out to be smaller than cue in.";
return $errArray;
}
$sql = "SELECT INTERVAL '{$cueOut}' > INTERVAL '{$origLength}'";
$r = $con->query($sql);
if($r->fetchColumn(0)){
$errArray["error"] ="Can't set cue out to be greater than file length.";
return $errArray;
}
$sql = "SELECT INTERVAL '{$cueOut}' - INTERVAL '{$oldCueIn}'";
$r = $con->query($sql);
$cliplength = $r->fetchColumn(0);
$row->setDbCueout($cueOut);
$row->setDBCliplength($cliplength);
}
$cliplength = $row->getDbCliplength();
$sql = "SELECT INTERVAL '{$fadeIn}' > INTERVAL '{$cliplength}'";
$r = $con->query($sql);
if($r->fetchColumn(0)){
$fadeIn = $cliplength;
$row->setDbFadein($fadeIn);
}
$sql = "SELECT INTERVAL '{$fadeOut}' > INTERVAL '{$cliplength}'";
$r = $con->query($sql);
if($r->fetchColumn(0)){
$fadeOut = $cliplength;
$row->setDbFadein($fadeOut);
}
$row->save();
return array("cliplength"=>$cliplength, "cueIn"=>$cueIn, "cueOut"=>$cueOut, "length"=>$this->getLength(),
"fadeIn"=>$fadeIn, "fadeOut"=>$fadeOut);
}
/**
* Find info about clip at specified offset in playlist.
*
* @param string $offset
* current playtime (hh:mm:ss.ssssss)
* @param int $distance
* 0=current clip; 1=next clip ...
* @return array of matching clip info:
*