CC-2301 : testing default crossfade settings
This commit is contained in:
parent
2b5a8b0d4b
commit
517bb7557a
6 changed files with 137 additions and 24 deletions
|
@ -43,6 +43,7 @@ class PreferenceController extends Zend_Controller_Action
|
||||||
if ($form->isValid($values)) {
|
if ($form->isValid($values)) {
|
||||||
|
|
||||||
Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view);
|
Application_Model_Preference::SetHeadTitle($values["stationName"], $this->view);
|
||||||
|
Application_Model_Preference::SetDefaultCrossfadeDuration($values["stationDefaultCrossfadeDuration"]);
|
||||||
Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]);
|
Application_Model_Preference::SetDefaultFadeIn($values["stationDefaultFadeIn"]);
|
||||||
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
|
Application_Model_Preference::SetDefaultFadeOut($values["stationDefaultFadeOut"]);
|
||||||
Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]);
|
Application_Model_Preference::SetAllow3rdPartyApi($values["thirdPartyApi"]);
|
||||||
|
|
|
@ -27,6 +27,25 @@ class Application_Form_GeneralPreferences extends Zend_Form_SubForm
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
//Default station fade in
|
||||||
|
$this->addElement('text', 'stationDefaultCrossfadeDuration', array(
|
||||||
|
'class' => 'input_text',
|
||||||
|
'label' => _('Default Crossfade Duration (s):'),
|
||||||
|
'required' => true,
|
||||||
|
'filters' => array('StringTrim'),
|
||||||
|
'validators' => array(
|
||||||
|
array(
|
||||||
|
$rangeValidator,
|
||||||
|
$notEmptyValidator,
|
||||||
|
'regex', false, array('/^[0-9]{1,2}(\.\d{1})?$/', 'messages' => _('enter a time in seconds 0{.0}'))
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'value' => Application_Model_Preference::GetDefaultCrossfadeDuration(),
|
||||||
|
'decorators' => array(
|
||||||
|
'ViewHelper'
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
//Default station fade in
|
//Default station fade in
|
||||||
$this->addElement('text', 'stationDefaultFadeIn', array(
|
$this->addElement('text', 'stationDefaultFadeIn', array(
|
||||||
'class' => 'input_text',
|
'class' => 'input_text',
|
||||||
|
|
|
@ -36,6 +36,7 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
|
||||||
"cueout" => "00:00:00",
|
"cueout" => "00:00:00",
|
||||||
"fadein" => "0.0",
|
"fadein" => "0.0",
|
||||||
"fadeout" => "0.0",
|
"fadeout" => "0.0",
|
||||||
|
"crossfadeDuration" => 0
|
||||||
);
|
);
|
||||||
|
|
||||||
//using propel's phpNames.
|
//using propel's phpNames.
|
||||||
|
@ -62,6 +63,7 @@ class Application_Model_Playlist implements Application_Model_LibraryEditable
|
||||||
|
|
||||||
$this->plItem["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
$this->plItem["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
||||||
$this->plItem["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
$this->plItem["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
||||||
|
$this->plItem["crossfadeDuration"] = Application_Model_Preference::GetDefaultCrossfadeDuration();
|
||||||
|
|
||||||
$this->con = isset($con) ? $con : Propel::getConnection(CcPlaylistPeer::DATABASE_NAME);
|
$this->con = isset($con) ? $con : Propel::getConnection(CcPlaylistPeer::DATABASE_NAME);
|
||||||
$this->id = $this->pl->getDbId();
|
$this->id = $this->pl->getDbId();
|
||||||
|
|
|
@ -195,6 +195,23 @@ class Application_Model_Preference
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function SetDefaultCrossfadeDuration($duration)
|
||||||
|
{
|
||||||
|
self::setValue("default_crossfade_duration", $duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function GetDefaultCrossfadeDuration()
|
||||||
|
{
|
||||||
|
$duration = self::getValue("default_crossfade_duration");
|
||||||
|
|
||||||
|
if ($duration === "") {
|
||||||
|
// the default value of the fade is 00.5
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $duration;
|
||||||
|
}
|
||||||
|
|
||||||
public static function SetDefaultFadeIn($fade)
|
public static function SetDefaultFadeIn($fade)
|
||||||
{
|
{
|
||||||
self::setValue("default_fade_in", $fade);
|
self::setValue("default_fade_in", $fade);
|
||||||
|
|
|
@ -18,6 +18,8 @@ class Application_Model_Scheduler
|
||||||
private $nowDT;
|
private $nowDT;
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
private $crossfadeDuration;
|
||||||
|
|
||||||
private $checkUserPermissions = true;
|
private $checkUserPermissions = true;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
@ -38,6 +40,8 @@ class Application_Model_Scheduler
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->user = Application_Model_User::getCurrentUser();
|
$this->user = Application_Model_User::getCurrentUser();
|
||||||
|
|
||||||
|
$this->crossfadeDuration = Application_Model_Preference::GetDefaultCrossfadeDuration();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCheckUserPermissions($value)
|
public function setCheckUserPermissions($value)
|
||||||
|
@ -201,12 +205,9 @@ class Application_Model_Scheduler
|
||||||
$data["cuein"] = $file->getDbCuein();
|
$data["cuein"] = $file->getDbCuein();
|
||||||
$data["cueout"] = $file->getDbCueout();
|
$data["cueout"] = $file->getDbCueout();
|
||||||
|
|
||||||
$defaultFade = Application_Model_Preference::GetDefaultFade();
|
|
||||||
if (isset($defaultFade)) {
|
|
||||||
//fade is in format SS.uuuuuu
|
//fade is in format SS.uuuuuu
|
||||||
$data["fadein"] = $defaultFade;
|
$data["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
||||||
$data["fadeout"] = $defaultFade;
|
$data["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
||||||
}
|
|
||||||
|
|
||||||
$files[] = $data;
|
$files[] = $data;
|
||||||
}
|
}
|
||||||
|
@ -260,12 +261,11 @@ class Application_Model_Scheduler
|
||||||
$cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]);
|
$cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]);
|
||||||
$cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]);
|
$cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]);
|
||||||
$data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
|
$data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
|
||||||
$defaultFade = Application_Model_Preference::GetDefaultFade();
|
|
||||||
if (isset($defaultFade)) {
|
|
||||||
//fade is in format SS.uuuuuu
|
//fade is in format SS.uuuuuu
|
||||||
$data["fadein"] = $defaultFade;
|
$data["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
||||||
$data["fadeout"] = $defaultFade;
|
$data["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
||||||
}
|
|
||||||
$data["type"] = 0;
|
$data["type"] = 0;
|
||||||
$files[] = $data;
|
$files[] = $data;
|
||||||
}
|
}
|
||||||
|
@ -286,12 +286,9 @@ class Application_Model_Scheduler
|
||||||
$data["cueout"] = $stream->getDbLength();
|
$data["cueout"] = $stream->getDbLength();
|
||||||
$data["type"] = 1;
|
$data["type"] = 1;
|
||||||
|
|
||||||
$defaultFade = Application_Model_Preference::GetDefaultFade();
|
|
||||||
if (isset($defaultFade)) {
|
|
||||||
//fade is in format SS.uuuuuu
|
//fade is in format SS.uuuuuu
|
||||||
$data["fadein"] = $defaultFade;
|
$data["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
||||||
$data["fadeout"] = $defaultFade;
|
$data["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
||||||
}
|
|
||||||
|
|
||||||
$files[] = $data;
|
$files[] = $data;
|
||||||
}
|
}
|
||||||
|
@ -321,12 +318,11 @@ class Application_Model_Scheduler
|
||||||
$cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]);
|
$cuein = Application_Common_DateHelper::calculateLengthInSeconds($data["cuein"]);
|
||||||
$cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]);
|
$cueout = Application_Common_DateHelper::calculateLengthInSeconds($data["cueout"]);
|
||||||
$data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
|
$data["cliplength"] = Application_Common_DateHelper::secondsToPlaylistTime($cueout - $cuein);
|
||||||
$defaultFade = Application_Model_Preference::GetDefaultFade();
|
|
||||||
if (isset($defaultFade)) {
|
|
||||||
//fade is in format SS.uuuuuu
|
//fade is in format SS.uuuuuu
|
||||||
$data["fadein"] = $defaultFade;
|
$data["fadein"] = Application_Model_Preference::GetDefaultFadeIn();
|
||||||
$data["fadeout"] = $defaultFade;
|
$data["fadeout"] = Application_Model_Preference::GetDefaultFadeOut();
|
||||||
}
|
|
||||||
$data["type"] = 0;
|
$data["type"] = 0;
|
||||||
$files[] = $data;
|
$files[] = $data;
|
||||||
}
|
}
|
||||||
|
@ -337,6 +333,31 @@ class Application_Model_Scheduler
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param DateTime startDT in UTC
|
||||||
|
* @param string duration
|
||||||
|
* in format H:i:s.u (could be more that 24 hours)
|
||||||
|
*
|
||||||
|
* @return DateTime endDT in UTC
|
||||||
|
*/
|
||||||
|
private function findTimeDifference($p_startDT, $p_seconds)
|
||||||
|
{
|
||||||
|
$startEpoch = $p_startDT->format("U.u");
|
||||||
|
|
||||||
|
//add two float numbers to 6 subsecond precision
|
||||||
|
//DateTime::createFromFormat("U.u") will have a problem if there is no decimal in the resulting number.
|
||||||
|
$newEpoch = bcsub($startEpoch , (string) $p_seconds, 6);
|
||||||
|
|
||||||
|
$dt = DateTime::createFromFormat("U.u", $newEpoch, new DateTimeZone("UTC"));
|
||||||
|
|
||||||
|
if ($dt === false) {
|
||||||
|
//PHP 5.3.2 problem
|
||||||
|
$dt = DateTime::createFromFormat("U", intval($newEpoch), new DateTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $dt;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param DateTime startDT in UTC
|
* @param DateTime startDT in UTC
|
||||||
* @param string duration
|
* @param string duration
|
||||||
|
@ -394,6 +415,43 @@ class Application_Model_Scheduler
|
||||||
return $nextDT;
|
return $nextDT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param int $showInstance
|
||||||
|
* This function recalculates the start/end times of items in a gapless show to
|
||||||
|
* account for crossfade durations.
|
||||||
|
*/
|
||||||
|
private function calculateCrossfades($showInstance)
|
||||||
|
{
|
||||||
|
Logging::info("adjusting start, end times of scheduled items to account for crossfades show instance #".$showInstance);
|
||||||
|
|
||||||
|
$instance = CcShowInstancesQuery::create()->findPK($showInstance, $this->con);
|
||||||
|
if (is_null($instance)) {
|
||||||
|
throw new OutDatedScheduleException(_("The schedule you're viewing is out of date!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemStartDT = $instance->getDbStarts(null);
|
||||||
|
$itemEndDT = null;
|
||||||
|
|
||||||
|
$schedule = CcScheduleQuery::create()
|
||||||
|
->filterByDbInstanceId($showInstance)
|
||||||
|
->orderByDbStarts()
|
||||||
|
->find($this->con);
|
||||||
|
|
||||||
|
foreach ($schedule as $item) {
|
||||||
|
|
||||||
|
$itemEndDT = $item->getDbEnds(null);
|
||||||
|
|
||||||
|
$item
|
||||||
|
->setDbStarts($itemStartDT)
|
||||||
|
->setDbEnds($itemEndDT);
|
||||||
|
|
||||||
|
$itemStartDT = $this->findTimeDifference($itemEndDT, $this->crossfadeDuration);
|
||||||
|
$itemEndDT = $this->findEndTime($itemStartDT, $item->getDbClipLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
$schedule->save($this->con);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param int $showInstance
|
* @param int $showInstance
|
||||||
* @param array $exclude
|
* @param array $exclude
|
||||||
|
@ -648,6 +706,8 @@ class Application_Model_Scheduler
|
||||||
$pend = microtime(true);
|
$pend = microtime(true);
|
||||||
Logging::debug("adjusting all following items.");
|
Logging::debug("adjusting all following items.");
|
||||||
Logging::debug(floatval($pend) - floatval($pstart));
|
Logging::debug(floatval($pend) - floatval($pstart));
|
||||||
|
|
||||||
|
$this->calculateCrossfades($instance->getDbId());
|
||||||
}
|
}
|
||||||
}//for each instance
|
}//for each instance
|
||||||
|
|
||||||
|
@ -929,6 +989,7 @@ class Application_Model_Scheduler
|
||||||
|
|
||||||
foreach ($showInstances as $instance) {
|
foreach ($showInstances as $instance) {
|
||||||
$this->removeGaps($instance);
|
$this->removeGaps($instance);
|
||||||
|
$this->calculateCrossfades($instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,19 @@
|
||||||
</ul>
|
</ul>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt id="stationDefaultCrossfadeDuration-label" class="block-display">
|
||||||
|
<label class="optional" for="stationDefaultCrossfadeDuration"><?php echo $this->element->getElement('stationDefaultCrossfadeDuration')->getLabel() ?></label>
|
||||||
|
</dt>
|
||||||
|
<dd id="stationDefaultCrossfadeDuration-element" class="block-display">
|
||||||
|
<?php echo $this->element->getElement('stationDefaultCrossfadeDuration') ?>
|
||||||
|
<?php if($this->element->getElement('stationDefaultCrossfadeDuration')->hasErrors()) : ?>
|
||||||
|
<ul class='errors'>
|
||||||
|
<?php foreach($this->element->getElement('stationDefaultCrossfadeDuration')->getMessages() as $error): ?>
|
||||||
|
<li><?php echo $error; ?></li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
</dd>
|
||||||
<dt id="thirdPartyApi-label" class="block-display">
|
<dt id="thirdPartyApi-label" class="block-display">
|
||||||
<label class="optional"><?php echo $this->element->getElement('thirdPartyApi')->getLabel() ?></label>
|
<label class="optional"><?php echo $this->element->getElement('thirdPartyApi')->getLabel() ?></label>
|
||||||
</dt>
|
</dt>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue