commit/StationPlaylist: josephsl: Track Tally (6.0-dev): Given a range of track indecies, calculate total running time.

  • From: commits-noreply@xxxxxxxxxxxxx
  • To: nvda-addons-commits@xxxxxxxxxxxxx
  • Date: Mon, 15 Jun 2015 23:25:35 -0000

1 new commit in StationPlaylist:

https://bitbucket.org/nvdaaddonteam/stationplaylist/commits/9454a67e6473/
Changeset: 9454a67e6473
Branch: 6.0/trackTally
User: josephsl
Date: 2015-06-15 23:25:13+00:00
Summary: Track Tally (6.0-dev): Given a range of track indecies, calculate
total running time.

In order for this to be done, announceTime function was split into two
functions. For backwards compatibility, announceTime will now output
human-readable time string coming from the new milliseconds to time (ms2time)
function.
The track tally output isn't polished yet, but we now have enough foundation to
tweak the output a little. This will be available in 6.0 due to API change.

Affected #: 1 file

diff --git a/addon/appModules/splstudio/__init__.py
b/addon/appModules/splstudio/__init__.py
index af5b771..4017d35 100755
--- a/addon/appModules/splstudio/__init__.py
+++ b/addon/appModules/splstudio/__init__.py
@@ -502,20 +502,23 @@ class AppModule(appModuleHandler.AppModule):
}

# Specific to time scripts using Studio API.
+ # 6.0: Split this into two functions: the announcer (below) and
formatter.
def announceTime(self, t, offset = None):
if t <= 0:
ui.message("00:00")
else:
+ ui.message(self._ms2time(t, offset = offset))
+
+ # Formatter: given time in milliseconds, convert it to human-readable
format.
+ def _ms2time(self, t, offset = None):
+ if t <= 0:
+ return "00:00"
+ else:
tm = (t/1000) if not offset else (t/1000)+offset
- if tm < 60:
- tm1, tm2 = "00", tm
- else:
- tm1, tm2 = divmod(tm, 60)
- if tm1 < 10:
- tm1 = "0" + str(tm1)
- if tm2 < 10:
- tm2 = "0" + str(tm2)
- ui.message("{a}:{b}".format(a = tm1, b = tm2))
+ timeComponents = divmod(tm, 60)
+ tm1 = str(timeComponents[0]).zfill(2)
+ tm2 = str(timeComponents[1]).zfill(2)
+ return ":".join([tm1, tm2])

# Scripts which rely on API.
def script_sayRemainingTime(self, gesture):
@@ -1239,6 +1242,37 @@ class AppModule(appModuleHandler.AppModule):
# Translators: Presented when library scan is already
in progress.
ui.message(_("Scanning is in progress"))

+ # Track time analysis: return total length of the selected tracks upon
request.
+ # Analysis command will be assignable.
+ _analysisMarker = None
+
+ def script_markTrackForAnalysis(self, gesture):
+ focus = api.getFocusObject()
+ if focus.role == controlTypes.ROLE_LIST:
+ ui.message("No tracks were added, cannot perform track
time analysis")
+ return
+ self._analysisMarker = focus.IAccessibleChildID-1
+ ui.message("Track time analysis activated")
+
+ def script_trackTimeAnalysis(self, gesture):
+ if self._analysisMarker is None:
+ ui.message("No track selected as start of analysis
marker, cannot perform time analysis")
+ return
+ trackPos = api.getFocusObject().IAccessibleChildID-1
+ if self._analysisMarker == trackPos:
+ filename = statusAPI(self._analysisMarker, 211,
ret=True)
+ statusAPI(filename, 30, func=self.announceTime)
+ else:
+ analysisBegin = min(self._analysisMarker, trackPos)
+ analysisEnd = max(self._analysisMarker, trackPos)
+ analysisRange = analysisEnd-analysisBegin+1
+ ui.message("Tracks:
{numberOfSelectedTracks}".format(numberOfSelectedTracks = analysisRange))
+ totalLength = 0
+ for track in xrange(analysisBegin, analysisEnd+1):
+ filename = statusAPI(track, 211, ret=True)
+ totalLength+=statusAPI(filename, 30, ret=True)
+ ui.message(self.announceTime(totalLength))
+
def script_layerHelp(self, gesture):
# Translators: The title for SPL Assistant help dialog.
wx.CallAfter(gui.messageBox, SPLAssistantHelp, _("SPL Assistant
help"))
@@ -1262,6 +1296,8 @@ class AppModule(appModuleHandler.AppModule):
"kb:s":"sayScheduledTime",
"kb:shift+p":"sayTrackPitch",
"kb:shift+r":"libraryScanMonitor",
+ "kb:f9":"markTrackForAnalysis",
+ "kb:f10":"trackTimeAnalysis",
"kb:f1":"layerHelp",
}

Repository URL: https://bitbucket.org/nvdaaddonteam/stationplaylist/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.

Other related posts:

  • » commit/StationPlaylist: josephsl: Track Tally (6.0-dev): Given a range of track indecies, calculate total running time. - commits-noreply