fps-timecode 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/FPS/Timecode.html +83 -44
- data/doc/created.rid +3 -3
- data/doc/js/search_index.js +1 -1
- data/doc/js/search_index.js.gz +0 -0
- data/lib/fps-timecode.rb +67 -66
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 498b16edd03cf2f17e81c5fd10cbf2e4bb2f3e06ca0106a89c9ca2e622edb956
|
4
|
+
data.tar.gz: 9424a42bb0c1b461b5a830f45a63e0bca07ad6ea233cdf000beb3ae5c6df1e0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb1706e09d57528482fb0e917e068737e8b8b58adb1b3d2775a4c6c2701b7658d3b0c99e403ede8b36738ee8518ba03df31489914a5d8f3b98903b8f3711081
|
7
|
+
data.tar.gz: e1c3f57b40a82c1806a7e807494c3ff4f58b8babbc3e3101ff5f3f9d35fd5e1df5be1c832f4d10b3ff6eb04d47d52ca8b1fcab72aadabccb6d559659f24ed760
|
data/doc/FPS/Timecode.html
CHANGED
@@ -101,7 +101,45 @@
|
|
101
101
|
|
102
102
|
<section class="description">
|
103
103
|
|
104
|
-
<p>
|
104
|
+
<p>The Focal Point Systems timecode library has two main purposes.</p>
|
105
|
+
<ul><li>
|
106
|
+
<p>1.) Given the timecode address of the first frame of a sequence of frames,
|
107
|
+
and given n, what is the timecode address of the nth frame of a sequence?</p>
|
108
|
+
</li><li>
|
109
|
+
<p>2.) Given the timecode address of the first frame of a sequence, and given
|
110
|
+
the timecode address for the nth frame of the sequence, what is n?</p>
|
111
|
+
</li></ul>
|
112
|
+
|
113
|
+
<p>Example 1. A non-drop-frame 30 fps sequence starts at 00:01:00:00. What
|
114
|
+
is the timecode address of the 100th frame of the sequence? <a
|
115
|
+
href="Timecode.html#method-c-count_to_string">::count_to_string</a>(:fps_30_ndf,
|
116
|
+
<a
|
117
|
+
href="Timecode.html#method-c-string_to_count">::string_to_count</a>(:fps_30_ndf,“00:01:00:00”)
|
118
|
+
+ 100) => “00:01:03:10”</p>
|
119
|
+
|
120
|
+
<p>Example 2. A non-drop-frame 30 fps sequence starts at 00:01:00:00. What is
|
121
|
+
n for the frame with the address 00:01:03:10? <a
|
122
|
+
href="Timecode.html#method-c-string_to_count">::string_to_count</a>(:fps_30_ndf,“00:01:03:10”)
|
123
|
+
- <a
|
124
|
+
href="Timecode.html#method-c-string_to_count">::string_to_count</a>(:fps_30_ndf,“00:01:00:00”)
|
125
|
+
=> 100</p>
|
126
|
+
|
127
|
+
<p>An instance of the <a href="Timecode.html">Timecode</a> class represents
|
128
|
+
one timecode address. A timecode mode is always required to be given. The
|
129
|
+
mode determines the frame rate and the dropness (drop-frame or
|
130
|
+
non-drop-frame) of the timecode address. The mode must be one of
|
131
|
+
Timecode::Counts.keys. E.g. :fps_24, :fps_25, :fps_30_df, :fps_30_ndf</p>
|
132
|
+
|
133
|
+
<p>Create an instance of a <a href="Timecode.html">Timecode</a> using either a
|
134
|
+
string in the format “xx:xx:xx:xx” or a frame count. The frame count
|
135
|
+
represents n for the nth frame of a sequence that begins with timecode
|
136
|
+
address “00:00:00:00” (the zeroeth frame of the sequence).</p>
|
137
|
+
|
138
|
+
<p>When creating a timecode instance, the default is to use the string
|
139
|
+
argument ignoring the frame count argument and falling back to using the
|
140
|
+
frame count argument if the string is invalid.</p>
|
141
|
+
|
142
|
+
<p>Since there are many class methods, often there is no need to create an
|
105
143
|
instance of class <a href="Timecode.html">Timecode</a>.</p>
|
106
144
|
|
107
145
|
</section>
|
@@ -199,16 +237,15 @@ instance of class <a href="Timecode.html">Timecode</a>.</p>
|
|
199
237
|
|
200
238
|
<div class="method-description">
|
201
239
|
|
202
|
-
<p><a href="Timecode.html#method-c-count_to_string">::count_to_string</a
|
203
|
-
|
204
|
-
<p>Class method to compute a string from a frame count</p>
|
240
|
+
<p><a href="Timecode.html#method-c-count_to_string">::count_to_string</a>
|
241
|
+
Class method to produce a timecode string from a frame count</p>
|
205
242
|
|
206
243
|
|
207
244
|
|
208
245
|
|
209
246
|
<div class="method-source-code" id="count_to_string-source">
|
210
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
211
|
-
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">count_to_string</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_count</span>, <span class="ruby-identifier">duration</span> = <span class="ruby-keyword">false</span>)
|
247
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 56</span>
|
248
|
+
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">count_to_string</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_count</span>, <span class="ruby-identifier">duration</span> = <span class="ruby-keyword">false</span>)
|
212
249
|
<span class="ruby-identifier">tc_count</span> = <span class="ruby-constant">Timecode</span>.<span class="ruby-identifier">normalize</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_count</span>)
|
213
250
|
|
214
251
|
<span class="ruby-identifier">counts</span> = <span class="ruby-constant">Counts</span>[<span class="ruby-identifier">tc_mode</span>]
|
@@ -218,7 +255,7 @@ instance of class <a href="Timecode.html">Timecode</a>.</p>
|
|
218
255
|
<span class="ruby-identifier">rem</span> = <span class="ruby-identifier">rem</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">counts</span>[<span class="ruby-value">:fptm</span>]
|
219
256
|
<span class="ruby-identifier">units_mins</span> = <span class="ruby-identifier">rem</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">counts</span>[<span class="ruby-value">:fpm</span>]
|
220
257
|
<span class="ruby-identifier">rem</span> = <span class="ruby-identifier">rem</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">counts</span>[<span class="ruby-value">:fpm</span>]
|
221
|
-
|
258
|
+
|
222
259
|
<span class="ruby-keyword">if</span>(<span class="ruby-identifier">duration</span> <span class="ruby-operator">==</span> <span class="ruby-keyword">false</span>) <span class="ruby-comment"># not a duration, do drop-frame processing</span>
|
223
260
|
<span class="ruby-comment"># handle 30 fps drop frame</span>
|
224
261
|
<span class="ruby-keyword">if</span>(<span class="ruby-identifier">tc_mode</span> <span class="ruby-operator">==</span> <span class="ruby-value">:fps_30_df</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">units_mins</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">rem</span> <span class="ruby-operator"><=</span> <span class="ruby-value">1</span>)
|
@@ -231,10 +268,10 @@ instance of class <a href="Timecode.html">Timecode</a>.</p>
|
|
231
268
|
<span class="ruby-identifier">rem</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">counts</span>[<span class="ruby-value">:fpm</span>]
|
232
269
|
<span class="ruby-keyword">end</span>
|
233
270
|
<span class="ruby-keyword">end</span>
|
234
|
-
|
271
|
+
|
235
272
|
<span class="ruby-identifier">secs</span> = <span class="ruby-identifier">rem</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">counts</span>[<span class="ruby-value">:fps</span>]
|
236
273
|
<span class="ruby-identifier">frms</span> = <span class="ruby-identifier">rem</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">counts</span>[<span class="ruby-value">:fps</span>]
|
237
|
-
|
274
|
+
|
238
275
|
<span class="ruby-string">"%02d:%d%d:%02d:%02d"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">hours</span>, <span class="ruby-identifier">tens_mins</span>, <span class="ruby-identifier">units_mins</span>, <span class="ruby-identifier">secs</span>, <span class="ruby-identifier">frms</span>]
|
239
276
|
<span class="ruby-keyword">end</span></pre>
|
240
277
|
</div>
|
@@ -260,15 +297,18 @@ instance of class <a href="Timecode.html">Timecode</a>.</p>
|
|
260
297
|
|
261
298
|
<div class="method-description">
|
262
299
|
|
263
|
-
<p>initialize
|
264
|
-
|
265
|
-
|
300
|
+
<p>initialize</p>
|
301
|
+
|
302
|
+
<p>Construct a new instance of <a href="Timecode.html">FPS::Timecode</a>,
|
303
|
+
given a mode and either a timecode string or a frame count.</p>
|
304
|
+
|
305
|
+
<p>Raises ArgumentError</p>
|
266
306
|
|
267
307
|
|
268
308
|
|
269
309
|
|
270
310
|
<div class="method-source-code" id="new-source">
|
271
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
311
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 150</span>
|
272
312
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_string</span>, <span class="ruby-identifier">tc_count</span> = <span class="ruby-keyword">nil</span>)
|
273
313
|
<span class="ruby-comment"># tc_string and tc_count cannot both be nil</span>
|
274
314
|
<span class="ruby-keyword">if</span>(<span class="ruby-identifier">tc_string</span> <span class="ruby-operator">===</span> <span class="ruby-keyword">nil</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">tc_count</span> <span class="ruby-operator">===</span> <span class="ruby-keyword">nil</span>)
|
@@ -278,9 +318,9 @@ string or a frame count. Raises ArgumentError</p>
|
|
278
318
|
<span class="ruby-keyword">unless</span> <span class="ruby-constant">Counts</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">tc_mode</span>)
|
279
319
|
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">"invalid timecode mode"</span>
|
280
320
|
<span class="ruby-keyword">end</span>
|
281
|
-
|
321
|
+
|
282
322
|
<span class="ruby-ivar">@tc_mode</span> = <span class="ruby-identifier">tc_mode</span>
|
283
|
-
|
323
|
+
|
284
324
|
<span class="ruby-comment"># Try to use the string to construct the instance and fall back</span>
|
285
325
|
<span class="ruby-comment"># to the count if an exception is raised</span>
|
286
326
|
<span class="ruby-keyword">begin</span>
|
@@ -290,7 +330,7 @@ string or a frame count. Raises ArgumentError</p>
|
|
290
330
|
<span class="ruby-keyword">rescue</span>
|
291
331
|
<span class="ruby-ivar">@tc_count</span> = <span class="ruby-constant">Timecode</span>.<span class="ruby-identifier">normalize</span>(<span class="ruby-ivar">@tc_mode</span>, <span class="ruby-identifier">tc_count</span>)
|
292
332
|
<span class="ruby-ivar">@tc_string</span> = <span class="ruby-constant">Timecode</span>.<span class="ruby-identifier">count_to_string</span>(<span class="ruby-ivar">@tc_mode</span>, <span class="ruby-ivar">@tc_count</span>)
|
293
|
-
<span class="ruby-keyword">end</span>
|
333
|
+
<span class="ruby-keyword">end</span>
|
294
334
|
|
295
335
|
<span class="ruby-keyword">end</span></pre>
|
296
336
|
</div>
|
@@ -316,21 +356,21 @@ string or a frame count. Raises ArgumentError</p>
|
|
316
356
|
|
317
357
|
<div class="method-description">
|
318
358
|
|
319
|
-
<p>Class method to normalize a frame count >= 0 and < 24h
|
359
|
+
<p>Class method to normalize a frame count >= 0 and < 24h. Corrects 24
|
320
360
|
hour overflow or underflow</p>
|
321
361
|
|
322
362
|
|
323
363
|
|
324
364
|
|
325
365
|
<div class="method-source-code" id="normalize-source">
|
326
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
366
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 112</span>
|
327
367
|
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">normalize</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_count</span>)
|
328
368
|
<span class="ruby-comment"># tc_mode must be given and must be one of the known tc modes</span>
|
329
369
|
<span class="ruby-keyword">unless</span> <span class="ruby-constant">Counts</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">tc_mode</span>)
|
330
370
|
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">"invalid timecode mode"</span>
|
331
371
|
<span class="ruby-keyword">end</span>
|
332
372
|
|
333
|
-
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tc_count</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Fixnum</span>
|
373
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tc_count</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Fixnum</span>
|
334
374
|
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"invalid frame count #{tc_count}"</span>
|
335
375
|
<span class="ruby-keyword">end</span>
|
336
376
|
<span class="ruby-comment"># normalize to 24 hours</span>
|
@@ -362,17 +402,23 @@ hour overflow or underflow</p>
|
|
362
402
|
|
363
403
|
<div class="method-description">
|
364
404
|
|
365
|
-
<p>Class method to
|
366
|
-
|
405
|
+
<p>Class method to produce a timecode string as a duration from a frame count
|
406
|
+
The difference of two timecodes might be used as a duration. For non-drop
|
407
|
+
frame, the duration string does not differ from the string as a timecode
|
408
|
+
address. But for drop-frame, timecodes that don't exist as an address
|
409
|
+
can exist as a duration. One minute in drop frame is 1798 frames or
|
410
|
+
00:00:59:28. “00:01:00:00” as a drop-frame timecode address does not exist.
|
411
|
+
But the difference between 00:01:59:28 and 00:00:59:28 should be displayed
|
412
|
+
as “00:01:00:00” – one minute.</p>
|
367
413
|
|
368
414
|
|
369
415
|
|
370
416
|
|
371
417
|
<div class="method-source-code" id="string_as_duration-source">
|
372
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
418
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 138</span>
|
373
419
|
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">string_as_duration</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_count</span>)
|
374
|
-
|
375
|
-
<span class="ruby-keyword">end</span></pre>
|
420
|
+
<span class="ruby-constant">Timecode</span>.<span class="ruby-identifier">count_to_string</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_count</span>, <span class="ruby-keyword">true</span>)
|
421
|
+
<span class="ruby-keyword">end</span></pre>
|
376
422
|
</div>
|
377
423
|
|
378
424
|
</div>
|
@@ -397,18 +443,18 @@ href="Timecode.html#method-c-count_to_string">::count_to_string</a></p>
|
|
397
443
|
<div class="method-description">
|
398
444
|
|
399
445
|
<p><a href="Timecode.html#method-c-string_to_count">::string_to_count</a>
|
400
|
-
Class method to compute a count from a string</p>
|
446
|
+
Class method to compute a frame count from a timecode string</p>
|
401
447
|
|
402
448
|
|
403
449
|
|
404
450
|
|
405
451
|
<div class="method-source-code" id="string_to_count-source">
|
406
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
452
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 88</span>
|
407
453
|
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">string_to_count</span>(<span class="ruby-identifier">tc_mode</span>, <span class="ruby-identifier">tc_string</span>)
|
408
454
|
<span class="ruby-keyword">unless</span> <span class="ruby-constant">Counts</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">tc_mode</span>)
|
409
455
|
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">"invalid timecode mode"</span>
|
410
456
|
<span class="ruby-keyword">end</span>
|
411
|
-
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tc_string</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
457
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tc_string</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
|
412
458
|
<span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-string">"invalid timecode string"</span>
|
413
459
|
<span class="ruby-keyword">end</span>
|
414
460
|
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">tc_string</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\A(\d{2})[:;.](\d{2})[:;.](\d{2})[:;.](\d{2})\Z/</span>
|
@@ -456,13 +502,13 @@ Class method to compute a count from a string</p>
|
|
456
502
|
|
457
503
|
<div class="method-description">
|
458
504
|
|
459
|
-
<p>
|
505
|
+
<p>Compare two timecodes. Comparison (spaceship) operator does string compare</p>
|
460
506
|
|
461
507
|
|
462
508
|
|
463
509
|
|
464
510
|
<div class="method-source-code" id="3C-3D-3E-source">
|
465
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
511
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 196</span>
|
466
512
|
<span class="ruby-keyword">def</span> <span class="ruby-operator"><=></span>(<span class="ruby-identifier">other</span>)
|
467
513
|
<span class="ruby-ivar">@tc_string</span> <span class="ruby-operator"><=></span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">tc_string</span>
|
468
514
|
<span class="ruby-keyword">end</span></pre>
|
@@ -489,16 +535,15 @@ Class method to compute a count from a string</p>
|
|
489
535
|
|
490
536
|
<div class="method-description">
|
491
537
|
|
492
|
-
<p>
|
493
|
-
|
494
|
-
|
495
|
-
even though their modes and counts may be different.</p>
|
538
|
+
<p>Compare two timecodes for equality. Equality operator does string
|
539
|
+
comparison. Two timecodes may be considered equal even though their modes
|
540
|
+
and counts may be different.</p>
|
496
541
|
|
497
542
|
|
498
543
|
|
499
544
|
|
500
545
|
<div class="method-source-code" id="3D-3D-source">
|
501
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
546
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 190</span>
|
502
547
|
<span class="ruby-keyword">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">other</span>)
|
503
548
|
<span class="ruby-ivar">@tc_string</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">tc_string</span>
|
504
549
|
<span class="ruby-keyword">end</span></pre>
|
@@ -527,19 +572,13 @@ even though their modes and counts may be different.</p>
|
|
527
572
|
|
528
573
|
<p><a
|
529
574
|
href="Timecode.html#method-c-string_as_duration">::string_as_duration</a>
|
530
|
-
|
531
|
-
frame, the duration string does not differ from the string as a timecode
|
532
|
-
address. But for drop-frame, timecodes that don't exist as an address
|
533
|
-
can exist as a duration. One minute in drop frame is 1798 frames or
|
534
|
-
00:00:59:28. “00:01:00:00” as a drop-frame timecode address does not exist.
|
535
|
-
But the difference between 00:01:59:28 and 00:00:59:28 should be displayed
|
536
|
-
as “00:01:00:00” – one minute.</p>
|
575
|
+
instance method</p>
|
537
576
|
|
538
577
|
|
539
578
|
|
540
579
|
|
541
580
|
<div class="method-source-code" id="string_as_duration-source">
|
542
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
581
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 177</span>
|
543
582
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">string_as_duration</span>
|
544
583
|
<span class="ruby-constant">Timecode</span>.<span class="ruby-identifier">string_as_duration</span>(<span class="ruby-ivar">@tc_mode</span>, <span class="ruby-ivar">@tc_count</span>)
|
545
584
|
<span class="ruby-keyword">end</span></pre>
|
@@ -566,13 +605,13 @@ as “00:01:00:00” – one minute.</p>
|
|
566
605
|
|
567
606
|
<div class="method-description">
|
568
607
|
|
569
|
-
<p>
|
608
|
+
<p>Return the next timecode address in the sequence</p>
|
570
609
|
|
571
610
|
|
572
611
|
|
573
612
|
|
574
613
|
<div class="method-source-code" id="succ-source">
|
575
|
-
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line
|
614
|
+
<pre><span class="ruby-comment"># File lib/fps-timecode.rb, line 182</span>
|
576
615
|
<span class="ruby-keyword">def</span> <span class="ruby-identifier">succ</span>
|
577
616
|
<span class="ruby-constant">Timecode</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@tc_mode</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-ivar">@tc_count</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>)
|
578
617
|
<span class="ruby-keyword">end</span></pre>
|
data/doc/created.rid
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
1
|
+
Sat, 03 Feb 2018 13:50:01 -0800
|
2
2
|
./test/test_fps-timecode.rb Mon, 29 Jan 2018 14:20:36 -0800
|
3
3
|
./fps-timecode.gemspec Mon, 29 Jan 2018 14:25:07 -0800
|
4
|
-
./lib/fps-timecode.rb
|
5
|
-
./fps-timecode-0.0.3.gem Mon, 29 Jan 2018 15:
|
4
|
+
./lib/fps-timecode.rb Sat, 03 Feb 2018 13:49:54 -0800
|
5
|
+
./fps-timecode-0.0.3.gem Mon, 29 Jan 2018 15:36:06 -0800
|
data/doc/js/search_index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var search_data = {"index":{"searchIndex":["fps","timecode","testfpstimecode","<=>()","==()","count_to_string()","new()","normalize()","string_as_duration()","string_as_duration()","string_to_count()","succ()","test_class_methods()","test_comparison_works_on_strings_regardless_of_counts()","test_create_count_if_given_must_be_fixnum()","test_create_counts_greater_than_24_hours_will_be_normalized()","test_create_fall_back_to_count_when_string_is_invalid()","test_create_legally_doesnt_fail()","test_create_must_have_valid_tc_mode()","test_create_negative_counts_will_be_normalized()","test_create_nonexistent_drop_frame_times_will_be_corrected()","test_create_string_all_fields_must_be_within_bounds()","test_create_string_and_count_cannot_both_be_nil()","test_create_string_must_be_valid_if_no_count_given()","test_create_use_string_by_default()","test_dropframe_string_as_duration()","test_succ()","fps-timecode.gemspec"],"longSearchIndex":["fps","fps::timecode","testfpstimecode","fps::timecode#<=>()","fps::timecode#==()","fps::timecode::count_to_string()","fps::timecode::new()","fps::timecode::normalize()","fps::timecode::string_as_duration()","fps::timecode#string_as_duration()","fps::timecode::string_to_count()","fps::timecode#succ()","testfpstimecode#test_class_methods()","testfpstimecode#test_comparison_works_on_strings_regardless_of_counts()","testfpstimecode#test_create_count_if_given_must_be_fixnum()","testfpstimecode#test_create_counts_greater_than_24_hours_will_be_normalized()","testfpstimecode#test_create_fall_back_to_count_when_string_is_invalid()","testfpstimecode#test_create_legally_doesnt_fail()","testfpstimecode#test_create_must_have_valid_tc_mode()","testfpstimecode#test_create_negative_counts_will_be_normalized()","testfpstimecode#test_create_nonexistent_drop_frame_times_will_be_corrected()","testfpstimecode#test_create_string_all_fields_must_be_within_bounds()","testfpstimecode#test_create_string_and_count_cannot_both_be_nil()","testfpstimecode#test_create_string_must_be_valid_if_no_count_given()","testfpstimecode#test_create_use_string_by_default()","testfpstimecode#test_dropframe_string_as_duration()","testfpstimecode#test_succ()",""],"info":[["FPS","","FPS.html","","<p>Timecode library Implements Timecode class Version 0.0.2\n<p>Author: Loran Kary Copyright 2013 Focal Point …\n"],["FPS::Timecode","","FPS/Timecode.html","","<p>
|
1
|
+
var search_data = {"index":{"searchIndex":["fps","timecode","testfpstimecode","<=>()","==()","count_to_string()","new()","normalize()","string_as_duration()","string_as_duration()","string_to_count()","succ()","test_class_methods()","test_comparison_works_on_strings_regardless_of_counts()","test_create_count_if_given_must_be_fixnum()","test_create_counts_greater_than_24_hours_will_be_normalized()","test_create_fall_back_to_count_when_string_is_invalid()","test_create_legally_doesnt_fail()","test_create_must_have_valid_tc_mode()","test_create_negative_counts_will_be_normalized()","test_create_nonexistent_drop_frame_times_will_be_corrected()","test_create_string_all_fields_must_be_within_bounds()","test_create_string_and_count_cannot_both_be_nil()","test_create_string_must_be_valid_if_no_count_given()","test_create_use_string_by_default()","test_dropframe_string_as_duration()","test_succ()","fps-timecode.gemspec"],"longSearchIndex":["fps","fps::timecode","testfpstimecode","fps::timecode#<=>()","fps::timecode#==()","fps::timecode::count_to_string()","fps::timecode::new()","fps::timecode::normalize()","fps::timecode::string_as_duration()","fps::timecode#string_as_duration()","fps::timecode::string_to_count()","fps::timecode#succ()","testfpstimecode#test_class_methods()","testfpstimecode#test_comparison_works_on_strings_regardless_of_counts()","testfpstimecode#test_create_count_if_given_must_be_fixnum()","testfpstimecode#test_create_counts_greater_than_24_hours_will_be_normalized()","testfpstimecode#test_create_fall_back_to_count_when_string_is_invalid()","testfpstimecode#test_create_legally_doesnt_fail()","testfpstimecode#test_create_must_have_valid_tc_mode()","testfpstimecode#test_create_negative_counts_will_be_normalized()","testfpstimecode#test_create_nonexistent_drop_frame_times_will_be_corrected()","testfpstimecode#test_create_string_all_fields_must_be_within_bounds()","testfpstimecode#test_create_string_and_count_cannot_both_be_nil()","testfpstimecode#test_create_string_must_be_valid_if_no_count_given()","testfpstimecode#test_create_use_string_by_default()","testfpstimecode#test_dropframe_string_as_duration()","testfpstimecode#test_succ()",""],"info":[["FPS","","FPS.html","","<p>Timecode library Implements Timecode class Version 0.0.2\n<p>Author: Loran Kary Copyright 2013 Focal Point …\n"],["FPS::Timecode","","FPS/Timecode.html","","<p>The Focal Point Systems timecode library has two main purposes.\n<p>1.) Given the timecode address of the …\n"],["TestFpsTimecode","","TestFpsTimecode.html","",""],["<=>","FPS::Timecode","FPS/Timecode.html#method-i-3C-3D-3E","(other)","<p>Compare two timecodes. Comparison (spaceship) operator does string compare\n"],["==","FPS::Timecode","FPS/Timecode.html#method-i-3D-3D","(other)","<p>Compare two timecodes for equality. Equality operator does string\ncomparison. Two timecodes may be considered …\n"],["count_to_string","FPS::Timecode","FPS/Timecode.html#method-c-count_to_string","(tc_mode, tc_count, duration = false)","<p>count_to_string Class method to produce a timecode string from a frame\ncount\n"],["new","FPS::Timecode","FPS/Timecode.html#method-c-new","(tc_mode, tc_string, tc_count = nil)","<p>initialize\n<p>Construct a new instance of FPS::Timecode, given a mode and either a\ntimecode string or a frame …\n"],["normalize","FPS::Timecode","FPS/Timecode.html#method-c-normalize","(tc_mode, tc_count)","<p>Class method to normalize a frame count >= 0 and < 24h. Corrects 24\nhour overflow or underflow …\n"],["string_as_duration","FPS::Timecode","FPS/Timecode.html#method-c-string_as_duration","(tc_mode, tc_count)","<p>Class method to produce a timecode string as a duration from a frame count\nThe difference of two timecodes …\n"],["string_as_duration","FPS::Timecode","FPS/Timecode.html#method-i-string_as_duration","()","<p>string_as_duration instance method\n"],["string_to_count","FPS::Timecode","FPS/Timecode.html#method-c-string_to_count","(tc_mode, tc_string)","<p>string_to_count Class method to compute a frame count from a timecode\nstring\n"],["succ","FPS::Timecode","FPS/Timecode.html#method-i-succ","()","<p>Return the next timecode address in the sequence\n"],["test_class_methods","TestFpsTimecode","TestFpsTimecode.html#method-i-test_class_methods","()",""],["test_comparison_works_on_strings_regardless_of_counts","TestFpsTimecode","TestFpsTimecode.html#method-i-test_comparison_works_on_strings_regardless_of_counts","()",""],["test_create_count_if_given_must_be_fixnum","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_count_if_given_must_be_fixnum","()",""],["test_create_counts_greater_than_24_hours_will_be_normalized","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_counts_greater_than_24_hours_will_be_normalized","()",""],["test_create_fall_back_to_count_when_string_is_invalid","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_fall_back_to_count_when_string_is_invalid","()",""],["test_create_legally_doesnt_fail","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_legally_doesnt_fail","()",""],["test_create_must_have_valid_tc_mode","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_must_have_valid_tc_mode","()",""],["test_create_negative_counts_will_be_normalized","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_negative_counts_will_be_normalized","()",""],["test_create_nonexistent_drop_frame_times_will_be_corrected","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_nonexistent_drop_frame_times_will_be_corrected","()",""],["test_create_string_all_fields_must_be_within_bounds","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_string_all_fields_must_be_within_bounds","()",""],["test_create_string_and_count_cannot_both_be_nil","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_string_and_count_cannot_both_be_nil","()",""],["test_create_string_must_be_valid_if_no_count_given","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_string_must_be_valid_if_no_count_given","()",""],["test_create_use_string_by_default","TestFpsTimecode","TestFpsTimecode.html#method-i-test_create_use_string_by_default","()",""],["test_dropframe_string_as_duration","TestFpsTimecode","TestFpsTimecode.html#method-i-test_dropframe_string_as_duration","()",""],["test_succ","TestFpsTimecode","TestFpsTimecode.html#method-i-test_succ","()",""],["fps-timecode.gemspec","","fps-timecode_gemspec.html","","<p>Gem::Specification.new do |s|\n\n<pre>s.name = 'fps-timecode'\ns.version = '0.0.3'\ns.summary = 'Implements timecode ...</pre>\n"]]}}
|
data/doc/js/search_index.js.gz
CHANGED
Binary file
|
data/lib/fps-timecode.rb
CHANGED
@@ -7,35 +7,34 @@
|
|
7
7
|
|
8
8
|
module FPS # Focal Point Software
|
9
9
|
|
10
|
-
#
|
11
|
-
# 1.) Given the timecode address of the first frame of a sequence of frames,
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# given the timecode address for the nth frame of the sequence, what is n?
|
15
|
-
|
10
|
+
# The Focal Point Systems timecode library has two main purposes.
|
11
|
+
# * 1.) Given the timecode address of the first frame of a sequence of frames, and given n, what is the timecode address of the nth frame of a sequence?
|
12
|
+
# * 2.) Given the timecode address of the first frame of a sequence, and given the timecode address for the nth frame of the sequence, what is n?
|
13
|
+
#
|
16
14
|
# Example 1. A non-drop-frame 30 fps sequence starts at 00:01:00:00. What is
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
|
15
|
+
# the timecode address of the 100th frame of the sequence?
|
16
|
+
# FPS::Timecode.count_to_string(:fps_30_ndf,
|
17
|
+
# FPS::Timecode.string_to_count(:fps_30_ndf,"00:01:00:00") + 100) => "00:01:03:10"
|
18
|
+
#
|
22
19
|
# Example 2. A non-drop-frame 30 fps sequence starts at 00:01:00:00. What is n
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
|
20
|
+
# for the frame with the address 00:01:03:10?
|
21
|
+
# FPS::Timecode.string_to_count(:fps_30_ndf,"00:01:03:10") -
|
22
|
+
# FPS::Timecode.string_to_count(:fps_30_ndf,"00:01:00:00") => 100
|
23
|
+
#
|
28
24
|
# An instance of the Timecode class represents one timecode address.
|
29
25
|
# A timecode mode is always required to be given. The mode determines the frame
|
30
26
|
# rate and the dropness (drop-frame or non-drop-frame) of the timecode address.
|
31
|
-
# The mode must be one of Timecode::Counts.keys. E.g. :fps_24, :fps_25
|
27
|
+
# The mode must be one of Timecode::Counts.keys. E.g. :fps_24, :fps_25, :fps_30_df, :fps_30_ndf
|
28
|
+
#
|
32
29
|
# Create an instance of a Timecode using either a string in the format "xx:xx:xx:xx"
|
33
30
|
# or a frame count. The frame count represents n for the nth frame of a sequence
|
34
31
|
# that begins with timecode address "00:00:00:00" (the zeroeth frame of the sequence).
|
35
|
-
#
|
36
|
-
#
|
37
|
-
|
38
|
-
#
|
32
|
+
#
|
33
|
+
# When creating a timecode instance, the default is to use the string argument
|
34
|
+
# ignoring the frame count argument
|
35
|
+
# and falling back to using the frame count argument if the string is invalid.
|
36
|
+
#
|
37
|
+
# Since there are many class methods, often there is no need to create
|
39
38
|
# an instance of class Timecode.
|
40
39
|
|
41
40
|
class Timecode
|
@@ -44,17 +43,17 @@ class Timecode
|
|
44
43
|
|
45
44
|
Counts = { fps_24: { fp24h: 2073600, fph: 86400, fptm: 14400, fpm: 1440, fps: 24 },
|
46
45
|
fps_25: { fp24h: 2160000, fph: 90000, fptm: 15000, fpm: 1500, fps: 25 },
|
47
|
-
fps_30_df: { fp24h: 2589408, fph: 107892, fptm: 17982, fpm: 1798, fps: 30 },
|
46
|
+
fps_30_df: { fp24h: 2589408, fph: 107892, fptm: 17982, fpm: 1798, fps: 30 },
|
48
47
|
fps_30_ndf: { fp24h: 2592000, fph: 108000, fptm: 18000, fpm: 1800, fps: 30 },
|
49
48
|
fps_48: { fp24h: 4147200, fph: 172800, fptm: 28800, fpm: 2880, fps: 48 },
|
50
49
|
fps_50: { fp24h: 4320000, fph: 180000, fptm: 30000, fpm: 3000, fps: 50 },
|
51
50
|
fps_60_df: { fp24h: 5178816, fph: 215784, fptm: 35964, fpm: 3596, fps: 60 },
|
52
51
|
fps_60_ndf: { fp24h: 5184000, fph: 216000, fptm: 36000, fpm: 3600, fps: 60 },
|
53
52
|
}
|
54
|
-
|
55
|
-
# count_to_string
|
56
|
-
# Class method to
|
57
|
-
def self.count_to_string(tc_mode, tc_count, duration = false)
|
53
|
+
|
54
|
+
# count_to_string
|
55
|
+
# Class method to produce a timecode string from a frame count
|
56
|
+
def self.count_to_string(tc_mode, tc_count, duration = false)
|
58
57
|
tc_count = Timecode.normalize(tc_mode, tc_count)
|
59
58
|
|
60
59
|
counts = Counts[tc_mode]
|
@@ -64,7 +63,7 @@ class Timecode
|
|
64
63
|
rem = rem % counts[:fptm]
|
65
64
|
units_mins = rem / counts[:fpm]
|
66
65
|
rem = rem % counts[:fpm]
|
67
|
-
|
66
|
+
|
68
67
|
if(duration == false) # not a duration, do drop-frame processing
|
69
68
|
# handle 30 fps drop frame
|
70
69
|
if(tc_mode == :fps_30_df && units_mins > 0 && rem <= 1)
|
@@ -77,20 +76,20 @@ class Timecode
|
|
77
76
|
rem += counts[:fpm]
|
78
77
|
end
|
79
78
|
end
|
80
|
-
|
79
|
+
|
81
80
|
secs = rem / counts[:fps]
|
82
81
|
frms = rem % counts[:fps]
|
83
|
-
|
82
|
+
|
84
83
|
"%02d:%d%d:%02d:%02d" % [hours, tens_mins, units_mins, secs, frms]
|
85
84
|
end
|
86
|
-
|
85
|
+
|
87
86
|
# string_to_count
|
88
|
-
# Class method to compute a count from a string
|
87
|
+
# Class method to compute a frame count from a timecode string
|
89
88
|
def self.string_to_count(tc_mode, tc_string)
|
90
89
|
unless Counts.include?(tc_mode)
|
91
90
|
raise ArgumentError, "invalid timecode mode"
|
92
91
|
end
|
93
|
-
unless tc_string.is_a? String
|
92
|
+
unless tc_string.is_a? String
|
94
93
|
raise ArgumentError, "invalid timecode string"
|
95
94
|
end
|
96
95
|
unless tc_string =~ /\A(\d{2})[:;.](\d{2})[:;.](\d{2})[:;.](\d{2})\Z/
|
@@ -107,16 +106,16 @@ class Timecode
|
|
107
106
|
$3.to_i * counts[:fpm] +
|
108
107
|
$4.to_i * counts[:fps] + $5.to_i
|
109
108
|
end
|
110
|
-
|
111
|
-
# Class method to normalize a frame count >= 0 and < 24h
|
112
|
-
#
|
109
|
+
|
110
|
+
# Class method to normalize a frame count >= 0 and < 24h.
|
111
|
+
# Corrects 24 hour overflow or underflow
|
113
112
|
def self.normalize(tc_mode, tc_count)
|
114
113
|
# tc_mode must be given and must be one of the known tc modes
|
115
114
|
unless Counts.include?(tc_mode)
|
116
115
|
raise ArgumentError, "invalid timecode mode"
|
117
116
|
end
|
118
117
|
|
119
|
-
unless tc_count.is_a? Fixnum
|
118
|
+
unless tc_count.is_a? Fixnum
|
120
119
|
raise ArgumentError, "invalid frame count #{tc_count}"
|
121
120
|
end
|
122
121
|
# normalize to 24 hours
|
@@ -125,18 +124,29 @@ class Timecode
|
|
125
124
|
while tc_count >= _24h do tc_count -= _24h end
|
126
125
|
tc_count
|
127
126
|
end
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
|
128
|
+
# Class method to produce a timecode string as a duration from a frame count
|
129
|
+
# The difference of two timecodes might be used as a duration.
|
130
|
+
# For non-drop frame, the duration string does not differ from the
|
131
|
+
# string as a timecode address. But for drop-frame, timecodes
|
132
|
+
# that don't exist as an address can exist as a duration.
|
133
|
+
# One minute in drop frame is 1798 frames or 00:00:59:28.
|
134
|
+
# "00:01:00:00" as a drop-frame timecode address does not exist.
|
135
|
+
# But the difference between 00:01:59:28 and 00:00:59:28
|
136
|
+
# should be displayed as "00:01:00:00" -- one minute.
|
137
|
+
|
138
|
+
def self.string_as_duration(tc_mode, tc_count)
|
131
139
|
Timecode.count_to_string(tc_mode, tc_count, true)
|
132
140
|
end
|
133
141
|
|
134
142
|
|
135
143
|
|
136
144
|
# initialize
|
137
|
-
#
|
145
|
+
#
|
146
|
+
# Construct a new instance of FPS::Timecode, given a mode and either a
|
138
147
|
# timecode string or a frame count.
|
139
|
-
#
|
148
|
+
#
|
149
|
+
# Raises ArgumentError
|
140
150
|
def initialize(tc_mode, tc_string, tc_count = nil)
|
141
151
|
# tc_string and tc_count cannot both be nil
|
142
152
|
if(tc_string === nil && tc_count === nil)
|
@@ -146,9 +156,9 @@ class Timecode
|
|
146
156
|
unless Counts.include?(tc_mode)
|
147
157
|
raise ArgumentError, "invalid timecode mode"
|
148
158
|
end
|
149
|
-
|
159
|
+
|
150
160
|
@tc_mode = tc_mode
|
151
|
-
|
161
|
+
|
152
162
|
# Try to use the string to construct the instance and fall back
|
153
163
|
# to the count if an exception is raised
|
154
164
|
begin
|
@@ -158,40 +168,31 @@ class Timecode
|
|
158
168
|
rescue
|
159
169
|
@tc_count = Timecode.normalize(@tc_mode, tc_count)
|
160
170
|
@tc_string = Timecode.count_to_string(@tc_mode, @tc_count)
|
161
|
-
end
|
162
|
-
|
171
|
+
end
|
172
|
+
|
163
173
|
end #initialize
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
# For non-drop frame, the duration string does not differ from the
|
168
|
-
# string as a timecode address. But for drop-frame, timecodes
|
169
|
-
# that don't exist as an address can exist as a duration.
|
170
|
-
# One minute in drop frame is 1798 frames or 00:00:59:28.
|
171
|
-
# "00:01:00:00" as a drop-frame timecode address does not exist.
|
172
|
-
# But the difference between 00:01:59:28 and 00:00:59:28
|
173
|
-
# should be displayed as "00:01:00:00" -- one minute.
|
174
|
-
#
|
174
|
+
|
175
|
+
# string_as_duration
|
176
|
+
# instance method
|
175
177
|
def string_as_duration
|
176
178
|
Timecode.string_as_duration(@tc_mode, @tc_count)
|
177
179
|
end
|
178
|
-
|
179
|
-
#
|
180
|
-
# return the next timecode address in the sequence
|
180
|
+
|
181
|
+
# Return the next timecode address in the sequence
|
181
182
|
def succ
|
182
183
|
Timecode.new(@tc_mode, nil, @tc_count+1)
|
183
184
|
end
|
184
|
-
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
185
|
+
|
186
|
+
# Compare two timecodes for equality.
|
187
|
+
# Equality operator does string comparison.
|
188
|
+
# Two timecodes may be considered equal even though their modes and counts
|
188
189
|
# may be different.
|
189
190
|
def ==(other)
|
190
191
|
@tc_string == other.tc_string
|
191
192
|
end
|
192
|
-
|
193
|
-
#
|
194
|
-
#
|
193
|
+
|
194
|
+
# Compare two timecodes.
|
195
|
+
# Comparison (spaceship) operator does string compare
|
195
196
|
def <=>(other)
|
196
197
|
@tc_string <=> other.tc_string
|
197
198
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fps-timecode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Loran Kary
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library to support drop-frame and non-drop-frame timecodes
|
14
14
|
email: lkary@focalpnt.com
|