From af9a155965449629ae9607f3b89b01d7c9015ee9 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 2 Jan 2019 13:13:54 -0500 Subject: [PATCH] 2019-01-02 Fred Gleason * Added a 'lineNumber' parameter to the 'padUpdate' structure. * Added a 'FIELD_LINE_NUMBER' data value to PyPAD. * Defined the '%z' metadata wildcard to refer to log line number. * Added a 'lineId' parameter to the 'padUpdate' structure. * Added 'FIELD_LINE_ID' data value to PyPAD. * Defined the '%x' metadata wildcard to refer to log line ID. --- ChangeLog | 7 +++++++ apis/PyPAD/api/PyPAD.py | 8 ++++++-- apis/PyPAD/tests/now_and_next.py | 18 ++++++++++++------ apis/PyPAD/tests/pad_test.py | 4 ++++ docs/opsguide/metadata_wildcards.xml | 4 ++-- lib/rdlogplay.cpp | 15 +++++++++------ lib/rdlogplay.h | 2 +- lib/rdnownext.cpp | 8 ++++++-- lib/rdnownext.h | 4 ++-- lib/rdrlmhost.cpp | 2 +- lib/rdslotbox.cpp | 8 ++++---- rdairplay/loglinebox.cpp | 17 +++++++++-------- 12 files changed, 63 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3548572d..8e7bf42c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18259,3 +18259,10 @@ 2018-12-20 Fred Gleason * Added a 'pypad_serial.py' PyPAD script. * Removed the 'rlm_serial' RLM. +2019-01-02 Fred Gleason + * Added a 'lineNumber' parameter to the 'padUpdate' structure. + * Added a 'FIELD_LINE_NUMBER' data value to PyPAD. + * Defined the '%z' metadata wildcard to refer to log line number. + * Added a 'lineId' parameter to the 'padUpdate' structure. + * Added 'FIELD_LINE_ID' data value to PyPAD. + * Defined the '%x' metadata wildcard to refer to log line ID. diff --git a/apis/PyPAD/api/PyPAD.py b/apis/PyPAD/api/PyPAD.py index 44e189ec..64299db7 100644 --- a/apis/PyPAD/api/PyPAD.py +++ b/apis/PyPAD/api/PyPAD.py @@ -46,6 +46,8 @@ TYPE_NEXT='next' # Field Names # FIELD_START_DATETIME='startDateTime' +FIELD_LINE_NUMBER='lineNumber' +FIELD_LINE_ID='lineId' FIELD_CART_NUMBER='cartNumber' FIELD_CART_TYPE='cartType' FIELD_CUT_NUMBER='cutNumber' @@ -393,9 +395,9 @@ class Update(object): string=self.__replaceWildcardPair('u','userDefined',string,esc) #string=self.__replaceWildcardPair('v',sfield,string,esc) # Length, rounded down #string=self.__replaceWildcardPair('w',sfield,string,esc) # Unassigned - #string=self.__replaceWildcardPair('x',sfield,string,esc) # Unassigned + string=self.__replaceWildcardPair('x','lineId',string,esc) # Log Line ID string=self.__replaceWildcardPair('y','year',string,esc) - #string=self.__replaceWildcardPair('z',sfield,string,esc) # Unassigned + string=self.__replaceWildcardPair('z','lineNumber',string,esc) # Log Line # string=string.replace('\\b','\b') string=string.replace('\\f','\f') string=string.replace('\\n','\n') @@ -480,6 +482,8 @@ class Update(object): PyPAD.FIELD_ISCI - The 'ISCI' field (string) PyPAD.FIELD_LABEL - The 'Label' field (string) PyPAD.FIELD_LENGTH - The 'Length' field (integer) + PyPAD.FIELD_LINE_ID - The log line ID (integer) + PyPAD.FIELD_LINE_NUMBER - The log line number (integer) PyPAD.FIELD_OUTCUE - The 'Outcue' field (string) PyPAD.FIELD_PUBLISHER - The 'Publisher' field (string) PyPAD.FIELD_SONG_ID - The 'Song ID' field (string) diff --git a/apis/PyPAD/tests/now_and_next.py b/apis/PyPAD/tests/now_and_next.py index 9abc109a..ae0bc3b0 100755 --- a/apis/PyPAD/tests/now_and_next.py +++ b/apis/PyPAD/tests/now_and_next.py @@ -2,7 +2,7 @@ # now_and_next.py # -# Example PyPAD script for Rivendell +# Barebones example PyPAD script for Rivendell # # (C) Copyright 2018 Fred Gleason # @@ -35,15 +35,21 @@ import PyPAD # the PAD information is supplied as the single argument. # def ProcessPad(update): - print + print() if update.hasPadType(PyPAD.TYPE_NOW): - print("Log %03d NOW: " % update.machine()+update.resolvePadFields("%a - %t",PyPAD.ESCAPE_NONE)) + msg='%03d:' % update.machine() + msg+='%04d ' % update.padField(PyPAD.TYPE_NOW,PyPAD.FIELD_LINE_NUMBER) + msg+='NOW: '+update.resolvePadFields('%a - %t',PyPAD.ESCAPE_NONE) + print(msg) else: - print("Log %03d NOW: [none]" % update.machine()) + print("%03d:xxxx NOW: [none]" % update.machine()) if update.hasPadType(PyPAD.TYPE_NEXT): - print("Log %03d NEXT: " % update.machine()+update.resolvePadFields("%A - %T",PyPAD.ESCAPE_NONE)) + msg='%03d:' % update.machine() + msg+='%04d ' % update.padField(PyPAD.TYPE_NEXT,PyPAD.FIELD_LINE_NUMBER) + msg+='NEXT: '+update.resolvePadFields('%A - %T',PyPAD.ESCAPE_NONE) + print(msg) else: - print("Log %03d NEXT: [none]" % update.machine()) + print("%03d:xxxx NEXT: [none]" % update.machine()) # # Create an instance of 'PyPADReceiver' diff --git a/apis/PyPAD/tests/pad_test.py b/apis/PyPAD/tests/pad_test.py index 50e727e6..2f261805 100755 --- a/apis/PyPAD/tests/pad_test.py +++ b/apis/PyPAD/tests/pad_test.py @@ -59,6 +59,8 @@ def ProcessPad(update): print(' startDateTime(): '+update.startDateTime(PyPAD.TYPE_NOW).isoformat(' ')) except AttributeError: print(' startDateTime(): None') + print(' lineNumber(): '+str(update.padField(PyPAD.TYPE_NOW,PyPAD.FIELD_LINE_NUMBER))+'/'+update.resolvePadFields('%z',PyPAD.ESCAPE_NONE)) + print(' lineId(): '+str(update.padField(PyPAD.TYPE_NOW,PyPAD.FIELD_LINE_ID))+'/'+update.resolvePadFields('%x',PyPAD.ESCAPE_NONE)) print(' cartType(): '+update.padField(PyPAD.TYPE_NOW,PyPAD.FIELD_CART_TYPE)) print(' cartNumber(): %u / ' % update.padField(PyPAD.TYPE_NOW,PyPAD.FIELD_CART_NUMBER)+update.resolvePadFields("%n",PyPAD.ESCAPE_NONE)) print(' cutNumber(): %u / ' % update.padField(PyPAD.TYPE_NOW,PyPAD.FIELD_CUT_NUMBER)+update.resolvePadFields("%j",PyPAD.ESCAPE_NONE)) @@ -96,6 +98,8 @@ def ProcessPad(update): print(' startDateTime(): '+update.startDateTime(PyPAD.TYPE_NEXT).isoformat(' ')) except AttributeError: print(' startDateTime(): None') + print(' lineNumber(): '+str(update.padField(PyPAD.TYPE_NEXT,PyPAD.FIELD_LINE_NUMBER))+'/'+update.resolvePadFields('%Z',PyPAD.ESCAPE_NONE)) + print(' lineId(): '+str(update.padField(PyPAD.TYPE_NEXT,PyPAD.FIELD_LINE_ID))+'/'+update.resolvePadFields('%X',PyPAD.ESCAPE_NONE)) print(' cartType(): '+update.padField(PyPAD.TYPE_NEXT,PyPAD.FIELD_CART_TYPE)) print(' cartNumber(): %u / ' % update.padField(PyPAD.TYPE_NEXT,PyPAD.FIELD_CART_NUMBER)+update.resolvePadFields("%N",PyPAD.ESCAPE_NONE)) print(' cutNumber(): %u / ' % update.padField(PyPAD.TYPE_NEXT,PyPAD.FIELD_CUT_NUMBER)+update.resolvePadFields("%J",PyPAD.ESCAPE_NONE)) diff --git a/docs/opsguide/metadata_wildcards.xml b/docs/opsguide/metadata_wildcards.xml index e847c9a5..29663026 100644 --- a/docs/opsguide/metadata_wildcards.xml +++ b/docs/opsguide/metadata_wildcards.xml @@ -38,9 +38,9 @@ %u%UUser Definied %v%VEvent length (seconds, rounded down) %w%W[Unassigned] - %x%X[Unassigned] + %x%XLog line ID (numeric) %y%YRelease Year - %z%Z[Unassigned] + %z%ZLog line number (numeric) \r\rLiteral Carriage Return (ASCII 13) \n\nLiteral Linefeed (ASCII 10) diff --git a/lib/rdlogplay.cpp b/lib/rdlogplay.cpp index 47f9cf00..8265553a 100644 --- a/lib/rdlogplay.cpp +++ b/lib/rdlogplay.cpp @@ -3002,7 +3002,8 @@ void RDLogPlay::SendNowNext() QDateTime(QDate::currentDate(),logline[0]->startTime(RDLogLine::Actual)); } play_pad_socket-> - write(GetPadJson("now",logline[0],start_datetime,8,false).toUtf8()); + write(GetPadJson("now",logline[0],start_datetime,now_line,8,false). + toUtf8()); // // Next @@ -3012,7 +3013,7 @@ void RDLogPlay::SendNowNext() next_datetime=start_datetime.addSecs(logline[0]->forcedLength()/1000); } play_pad_socket->write(GetPadJson("next",logline[1], - next_datetime,8,true).toUtf8()); + next_datetime,nextLine(),8,true).toUtf8()); // // Commit the update @@ -3031,12 +3032,12 @@ void RDLogPlay::SendNowNext() // // Premordial integrated interface // - RDResolveNowNext(&cmd,logline,0); + RDResolveNowNext(&cmd,logline,now_line,0); play_nownext_socket-> writeBlock(cmd,cmd.length(),play_nownext_address,play_nownext_port); cmd=play_nownext_rml; - RDResolveNowNext(&cmd,logline,0); + RDResolveNowNext(&cmd,logline,now_line,0); play_event_player->exec(cmd); // @@ -3052,8 +3053,8 @@ void RDLogPlay::SendNowNext() QString RDLogPlay::GetPadJson(const QString &name,RDLogLine *ll, - const QDateTime &start_datetime,int padding, - bool final) const + const QDateTime &start_datetime,int line, + int padding,bool final) const { QString ret; @@ -3068,6 +3069,8 @@ QString RDLogPlay::GetPadJson(const QString &name,RDLogLine *ll, else { ret+=RDJsonNullField("startDateTime",4+padding); } + ret+=RDJsonField("lineNumber",line,4+padding); + ret+=RDJsonField("lineId",ll->id(),4+padding); ret+=RDJsonField("cartNumber",ll->cartNumber(),4+padding); ret+=RDJsonField("cartType",RDCart::typeText(ll->cartType()),4+padding); if(ll->cartType()==RDCart::Audio) { diff --git a/lib/rdlogplay.h b/lib/rdlogplay.h index 4cb69acd..dd3e214e 100644 --- a/lib/rdlogplay.h +++ b/lib/rdlogplay.h @@ -190,7 +190,7 @@ class RDLogPlay : public QObject,public RDLogEvent bool ClearBlock(int start_line); void SendNowNext(); QString GetPadJson(const QString &name,RDLogLine *ll, - const QDateTime &start_datetime,int padding, + const QDateTime &start_datetime,int line,int padding, bool final=false) const; void LogTraffic(RDLogLine *logline,RDLogLine::PlaySource src, RDAirPlayConf::TrafficAction action,bool onair_flag) const; diff --git a/lib/rdnownext.cpp b/lib/rdnownext.cpp index c0d1b670..173c6d95 100644 --- a/lib/rdnownext.cpp +++ b/lib/rdnownext.cpp @@ -73,7 +73,7 @@ QString RDResolveNowNextEncode(const QString &str,int encoding) return ret; } -void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding) +void RDResolveNowNext(QString *str,RDLogLine **loglines,int line,int encoding) { // // NOW PLAYING Event @@ -104,6 +104,7 @@ void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding) str->replace("%o",RDResolveNowNextEncode(loglines[0]->outcue(),encoding)); str->replace("%i",RDResolveNowNextEncode(loglines[0]->description(), encoding)); + str->replace("%x",QString().sprintf("%d",loglines[0]->id())); RDResolveNowNextDateTime(str,"%d(",loglines[0]->startDatetime()); } else { // No NOW PLAYING Event @@ -125,6 +126,7 @@ void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding) str->replace("%u",""); str->replace("%o",""); str->replace("%i",""); + str->replace("%z",""); RDResolveNowNextDateTime(str,"%d(",QDateTime()); } @@ -156,6 +158,7 @@ void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding) str->replace("%O",RDResolveNowNextEncode(loglines[1]->outcue(),encoding)); str->replace("%I",RDResolveNowNextEncode(loglines[1]->description(), encoding)); + str->replace("%X",QString().sprintf("%d",loglines[1]->id())); RDResolveNowNextDateTime(str,"%D(",loglines[1]->startDatetime()); } else { // No NEXT Event @@ -177,6 +180,7 @@ void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding) str->replace("%U",""); str->replace("%O",""); str->replace("%I",""); + str->replace("%X",""); RDResolveNowNextDateTime(str,"%D(",QDateTime()); } str->replace("%%","%"); @@ -185,7 +189,7 @@ void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding) } -QString RDResolveNowNext(const QString &pattern,RDLogLine *ll) +QString RDResolveNowNext(const QString &pattern,RDLogLine *ll,int line) { QString ret=pattern; diff --git a/lib/rdnownext.h b/lib/rdnownext.h index 7afd64b2..d58b71a1 100644 --- a/lib/rdnownext.h +++ b/lib/rdnownext.h @@ -24,8 +24,8 @@ #include #include "../apis/rlm/rlm.h" -void RDResolveNowNext(QString *str,RDLogLine **loglines,int encoding); -QString RDResolveNowNext(const QString &pattern,RDLogLine *ll); +void RDResolveNowNext(QString *str,RDLogLine **loglines,int line,int encoding); +QString RDResolveNowNext(const QString &pattern,RDLogLine *ll,int line); #endif // RDNOWNEXT_H diff --git a/lib/rdrlmhost.cpp b/lib/rdrlmhost.cpp index bd177259..011a7559 100644 --- a/lib/rdrlmhost.cpp +++ b/lib/rdrlmhost.cpp @@ -436,7 +436,7 @@ const char *RLMResolveNowNextEncoded(void *ptr,const struct rlm_pad *now, loglines[1]=new RDLogLine(); RDRLMHost::saveMetadata(now,loglines[0]); RDRLMHost::saveMetadata(next,loglines[1]); - RDResolveNowNext(&str,loglines,encoding); + RDResolveNowNext(&str,loglines,0,encoding); strncpy(host->plugin_value_string,str,1024); delete loglines[1]; delete loglines[0]; diff --git a/lib/rdslotbox.cpp b/lib/rdslotbox.cpp index 1e2744fa..fa4bf406 100644 --- a/lib/rdslotbox.cpp +++ b/lib/rdslotbox.cpp @@ -352,7 +352,7 @@ void RDSlotBox::setCart(RDLogLine *logline) (!line_logline->originDateTime().isValid())) { line_title_label-> setText(RDResolveNowNext(line_airplay_conf->titleTemplate(), - logline)); + logline,log_id+1)); } else { line_title_label->setText(line_logline->title()+" -- "+ @@ -362,10 +362,10 @@ void RDSlotBox::setCart(RDLogLine *logline) } line_description_label-> setText(RDResolveNowNext(line_airplay_conf->descriptionTemplate(), - logline)); + logline,log_id+1)); line_artist_label-> setText(RDResolveNowNext(line_airplay_conf->artistTemplate(), - logline)); + logline,log_id+1)); line_up_label-> setText(RDGetTimeLength(line_logline->playPosition(),true,true)); line_down_label-> @@ -378,7 +378,7 @@ void RDSlotBox::setCart(RDLogLine *logline) setText(QString().sprintf("%03u",logline->cutNumber())); line_outcue_label-> setText(RDResolveNowNext(line_airplay_conf->outcueTemplate(), - logline)); + logline,log_id+1)); line_position_bar->show(); line_up_label->show(); line_down_label->show(); diff --git a/rdairplay/loglinebox.cpp b/rdairplay/loglinebox.cpp index d29fa859..9830b84b 100644 --- a/rdairplay/loglinebox.cpp +++ b/rdairplay/loglinebox.cpp @@ -526,7 +526,7 @@ void LogLineBox::setEvent(int line,RDLogLine::TransType next_type, line_logline->originUser().isEmpty()|| (!line_logline->originDateTime().isValid())) { line_title_label-> - setText(RDResolveNowNext(line_title_template,line_logline)); + setText(RDResolveNowNext(line_title_template,line_logline,line)); } else { line_title_label->setText(line_logline->title()+" -- "+ @@ -535,9 +535,10 @@ void LogLineBox::setEvent(int line,RDLogLine::TransType next_type, toString("M/d hh:mm")); } line_description_label-> - setText(RDResolveNowNext(line_description_template,line_logline)); + setText(RDResolveNowNext(line_description_template,line_logline, + line)); line_artist_label-> - setText(RDResolveNowNext(line_artist_template,line_logline)); + setText(RDResolveNowNext(line_artist_template,line_logline,line)); line_up_label-> setText(RDGetTimeLength(line_logline->playPosition(),true,true)); line_down_label-> @@ -549,7 +550,7 @@ void LogLineBox::setEvent(int line,RDLogLine::TransType next_type, line_cut_label-> setText(QString().sprintf("%03u",logline->cutNumber())); line_outcue_label-> - setText(RDResolveNowNext(line_outcue_template,line_logline)); + setText(RDResolveNowNext(line_outcue_template,line_logline,line)); } else { setBackgroundColor(QColor(LOGLINEBOX_MISSING_COLOR)); @@ -664,13 +665,13 @@ void LogLineBox::setEvent(int line,RDLogLine::TransType next_type, false,false)); line_title_label-> - setText(RDResolveNowNext(line_title_template,line_logline)); + setText(RDResolveNowNext(line_title_template,line_logline,line)); line_description_label-> - setText(RDResolveNowNext(line_description_template,line_logline)); + setText(RDResolveNowNext(line_description_template,line_logline,line)); line_artist_label-> - setText(RDResolveNowNext(line_artist_template,line_logline)); + setText(RDResolveNowNext(line_artist_template,line_logline,line)); line_outcue_label-> - setText(RDResolveNowNext(line_outcue_template,line_logline)); + setText(RDResolveNowNext(line_outcue_template,line_logline,line)); delete cart; delete cut; setMode(line_mode);