From 6b768c2f99d0d2592655c4ea341c8241219fed0d Mon Sep 17 00:00:00 2001 From: James Date: Tue, 20 Mar 2012 22:16:17 -0400 Subject: [PATCH] CC-3483: Live Stream: default fade in/out for live stream transition - done. changing fade value doesn't require LS to restart --- .../controllers/PreferenceController.php | 1 + .../forms/LiveStreamingPreferences.php | 15 +++++++++++++++ airtime_mvc/application/models/Preference.php | 12 ++++++++++++ .../scripts/form/preferences_livestream.phtml | 14 ++++++++++++++ .../pypo/liquidsoap_scripts/ls_lib.liq | 7 ++----- .../pypo/liquidsoap_scripts/ls_script.liq | 2 ++ python_apps/pypo/pypofetch.py | 19 +++++++++++++++++++ python_apps/pypo/pypomessagehandler.py | 3 +++ 8 files changed, 68 insertions(+), 5 deletions(-) diff --git a/airtime_mvc/application/controllers/PreferenceController.php b/airtime_mvc/application/controllers/PreferenceController.php index f78d31858..99d556807 100644 --- a/airtime_mvc/application/controllers/PreferenceController.php +++ b/airtime_mvc/application/controllers/PreferenceController.php @@ -211,6 +211,7 @@ class PreferenceController extends Zend_Controller_Action Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']); Application_Model_Preference::SetLiveSteamMasterUsername($values["master_username"]); Application_Model_Preference::SetLiveSteamMasterPassword($values["master_password"]); + Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]); // extra info that goes into cc_stream_setting Application_Model_StreamSetting::SetMasterLiveSteamPort($values["master_harbor_input_port"]); diff --git a/airtime_mvc/application/forms/LiveStreamingPreferences.php b/airtime_mvc/application/forms/LiveStreamingPreferences.php index 3a73ed166..d810fe587 100644 --- a/airtime_mvc/application/forms/LiveStreamingPreferences.php +++ b/airtime_mvc/application/forms/LiveStreamingPreferences.php @@ -5,6 +5,21 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm public function init() { + $defaultFade = Application_Model_Preference::GetDefaultTransitionFade(); + if($defaultFade == ""){ + $defaultFade = '00.000000'; + } + + //Default transition fade + $transition_fade = new Zend_Form_Element_Text("transition_fade"); + $transition_fade->setLabel("Switch Transition Fade (s)") + ->setFilters(array('StringTrim')) + ->addValidator('regex', false, array('/^[0-5][0-9](\.\d{1,6})?$/', + 'messages' => 'enter a time in seconds 00{.000000}')) + ->setValue($defaultFade) + ->setDecorators(array('ViewHelper')); + $this->addElement($transition_fade); + //Master username $master_username = new Zend_Form_Element_Text('master_username'); $master_username->setAttrib('autocomplete', 'off') diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index ce6a61d13..10dee81a0 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -153,6 +153,18 @@ class Application_Model_Preference public static function GetDefaultFade() { return self::GetValue("default_fade"); } + + public static function SetDefaultTransitionFade($fade) { + self::SetValue("default_transition_fade", $fade); + + $eventType = "update_transition_fade"; + $md = array("transition_fade"=>$fade); + Application_Model_RabbitMq::SendMessageToPypo($eventType, $md); + } + + public static function GetDefaultTransitionFade() { + return self::GetValue("default_transition_fade"); + } public static function SetStreamLabelFormat($type){ self::SetValue("stream_label_format", $type); diff --git a/airtime_mvc/application/views/scripts/form/preferences_livestream.phtml b/airtime_mvc/application/views/scripts/form/preferences_livestream.phtml index b94c4e2e0..93d5bc271 100644 --- a/airtime_mvc/application/views/scripts/form/preferences_livestream.phtml +++ b/airtime_mvc/application/views/scripts/form/preferences_livestream.phtml @@ -1,6 +1,20 @@
Input Stream Settings
+
+ +
+
+ element->getElement('transition_fade') ?> + element->getElement('transition_fade')->hasErrors()) : ?> +
    + element->getElement('transition_fade')->getMessages() as $error): ?> +
  • + +
+ +
diff --git a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq index cc515875a..eaee80605 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_lib.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_lib.liq @@ -15,15 +15,12 @@ def append_title(m) = end end -default_dj_fade_in = ref 5. -default_dj_fade_out = ref 5. - def transition(a,b) = log("transition called...") add(normalize=false, [ sequence([ blank(duration=2.), - fade.initial(duration=!default_dj_fade_in, b) ]), - fade.final(duration=!default_dj_fade_out, a) ]) + fade.initial(duration=!default_dj_fade, b) ]), + fade.final(duration=!default_dj_fade, a) ]) end def crossfade(s) diff --git a/python_apps/pypo/liquidsoap_scripts/ls_script.liq b/python_apps/pypo/liquidsoap_scripts/ls_script.liq index f0ec2b960..4a7f129cb 100644 --- a/python_apps/pypo/liquidsoap_scripts/ls_script.liq +++ b/python_apps/pypo/liquidsoap_scripts/ls_script.liq @@ -14,6 +14,7 @@ queue = cue_cut(queue) pypo_data = ref '0' web_stream_enabled = ref false stream_metadata_type = ref 0 +default_dj_fade = ref 0. station_name = ref '' show_name = ref '' @@ -37,6 +38,7 @@ server.register(namespace="vars", "show_name", fun (s) -> begin show_name := s s server.register(namespace="vars", "station_name", fun (s) -> begin station_name := s s end) server.register(namespace="vars", "bootup_time", fun (s) -> begin time := s s end) server.register(namespace="streams", "connection_status", fun (s) -> begin "1:#{!s1_connected},2:#{!s2_connected},3:#{!s3_connected}" end) +server.register(namespace="vars", "default_dj_fade", fun (s) -> begin default_dj_fade := float_of_string(s) s end) default = amplify(id="silence_src", 0.00001, noise()) diff --git a/python_apps/pypo/pypofetch.py b/python_apps/pypo/pypofetch.py index 67285c366..e7349a8ce 100644 --- a/python_apps/pypo/pypofetch.py +++ b/python_apps/pypo/pypofetch.py @@ -82,6 +82,9 @@ class PypoFetch(Thread): elif command == 'update_station_name': self.logger.info("Updating station name...") self.update_liquidsoap_station_name(m['station_name']) + elif command == 'update_transition_fade': + self.logger.info("Updating transition_fade...") + self.update_liquidsoap_transition_fade(m['transition_fade']) elif command == 'switch_source': self.logger.info("switch_on_source show command received...") self.switch_source(m['sourcename'], m['status']) @@ -317,6 +320,22 @@ class PypoFetch(Thread): finally: self.telnet_lock.release() + def update_liquidsoap_transition_fade(self, fade): + # Push stream metadata to liquidsoap + # TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!! + try: + self.telnet_lock.acquire() + tn = telnetlib.Telnet(LS_HOST, LS_PORT) + command = ('vars.default_dj_fade %s\n' % fade).encode('utf-8') + self.logger.info(command) + tn.write(command) + tn.write('exit\n') + tn.read_all() + except Exception, e: + self.logger.error("Exception %s", e) + finally: + self.telnet_lock.release() + def update_liquidsoap_station_name(self, station_name): # Push stream metadata to liquidsoap # TODO: THIS LIQUIDSOAP STUFF NEEDS TO BE MOVED TO PYPO-PUSH!!! diff --git a/python_apps/pypo/pypomessagehandler.py b/python_apps/pypo/pypomessagehandler.py index 2fa11af95..616107da1 100644 --- a/python_apps/pypo/pypomessagehandler.py +++ b/python_apps/pypo/pypomessagehandler.py @@ -73,6 +73,9 @@ class PypoMessageHandler(Thread): elif command == 'switch_source': self.logger.info("switch_source command received...") self.pypo_queue.put(message) + elif command == 'update_transition_fade': + self.logger.info("Updating trasition fade...") + self.pypo_queue.put(message) elif command == 'disconnect_source': self.logger.info("disconnect_source command received...") self.pypo_queue.put(message)