Skip to content

Commit

Permalink
Implemented 30 fps timecode.
Browse files Browse the repository at this point in the history
Updated version number.
  • Loading branch information
octaviospain committed Jan 2, 2017
1 parent d71216c commit 19e4d5f
Show file tree
Hide file tree
Showing 25 changed files with 393 additions and 35 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[![license](https://img.shields.io/badge/license-apache%202-brightgreen.svg)](https://github.com/octaviospain/TimecodeString/blob/master/LICENSE.txt)

Library that converts between frame counts and a [timecode](https://en.wikipedia.org/wiki/SMPTE_timecode) string representation.
The library supports multiple frame rates including 25fps and DF30 (29.97fps).
The library supports multiple frame rates including such as 24fps, 25fps, 30fps and DF30 (29.97fps).

# Usage
## Usage
You can use the TimecodeString library by two ways:

1. Instantiating the `TimecodeString.java` class in your java project
Expand Down Expand Up @@ -35,6 +35,6 @@ Options:
-o = <output_file> specify output file [default: output.txt]
```

### TO DO
## To do

* Implement 30Fps and other Timecodes
* Implement other Timecodes
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.transgressoft</groupId>
<artifactId>TimecodeString</artifactId>
<version>0.1</version>
<version>1.0</version>

<build>

Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/FrameRateType.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* rate given a string, and check if his value is valid.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public enum FrameRateType {
FPS24("24fps"),
Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/Timecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Interface for Timecodes.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
* @see <a href="https://en.wikipedia.org/wiki/SMPTE_timecode">SMPTE Timecode</a>
*/
public interface Timecode {
Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/TimecodeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Base class implementation of {@link Timecode}.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public abstract class TimecodeBase implements Timecode {

Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/TimecodeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Exception class for this {@link TimecodeString} library.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class TimecodeException extends Exception {

Expand Down
7 changes: 5 additions & 2 deletions src/com/transgressoft/timecode/TimecodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
import com.transgressoft.timecode.df30.*;
import com.transgressoft.timecode.fps24.*;
import com.transgressoft.timecode.fps25.*;
import com.transgressoft.timecode.fps30.*;

/**
* Abstract factory class of creation of {@link Timecode} objects.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public abstract class TimecodeFactory {

private static Fps25TimecodeFactory fps25TimecodeFactory = new Fps25TimecodeFactory();
private static Df30TimecodeFactory df30TimecodeFactory = new Df30TimecodeFactory();
private static Fps24TimecodeFactory fps24TimecodeFactory = new Fps24TimecodeFactory();
private static Fps30TimecodeFactory fps30TimecodeFactory = new Fps30TimecodeFactory();

public static Timecode createTimeCode(FrameRateType type, int hours, int minutes, int seconds, int frames) {
TimecodeFactory timecodeFactory = chooseFactory(type);
Expand All @@ -47,7 +49,8 @@ private static TimecodeFactory chooseFactory(FrameRateType type) {
timecodeFactory = fps25TimecodeFactory;
break;
case FPS30:
throw new UnsupportedOperationException("30fps frame rate is not supported yet"); // TODO implement
timecodeFactory = fps30TimecodeFactory;
break;
case DF30:
timecodeFactory = df30TimecodeFactory;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/TimecodeInputType.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Enumeration of different type of input formats of the value of a timecode.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public enum TimecodeInputType {

Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/TimecodeString.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Class that converts between frame counts and a timecode string representation.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class TimecodeString {

Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/TimecodeStringRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Uses {@link Docopt} library to parse command line arguments.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
* @see <a href="http://docopt.org">docopt.org</a>
* @see <a href="https://github.com/docopt/docopt.java">docopt for Java</a>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/df30/Df30Timecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* a Drop-Frame 30 (29.97 fps) video timecode.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
* @see <a href="https://en.wikipedia.org/wiki/SMPTE_timecode">SMPTE Timecode</a>
*/
public class Df30Timecode extends TimecodeBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Factory class that creates {@link Df30Timecode} objects.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class Df30TimecodeFactory extends TimecodeFactory {

Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/fps24/Fps24Timecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* a 24 fps video timecode.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
* @see <a href="https://en.wikipedia.org/wiki/SMPTE_timecode">SMPTE Timecode</a>
*/
public class Fps24Timecode extends TimecodeBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Factory class that creates {@link Fps24Timecode} objects.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class Fps24TimecodeFactory extends TimecodeFactory {

Expand Down
2 changes: 1 addition & 1 deletion src/com/transgressoft/timecode/fps25/Fps25Timecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* a 25 fps video timecode.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
* @see <a href="https://en.wikipedia.org/wiki/SMPTE_timecode">SMPTE Timecode</a>
*/
public class Fps25Timecode extends TimecodeBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Factory class that creates {@link Fps25Timecode} objects.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class Fps25TimecodeFactory extends TimecodeFactory {

Expand Down
91 changes: 91 additions & 0 deletions src/com/transgressoft/timecode/fps30/Fps30Timecode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2016, 2017 Octavio Calleya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.transgressoft.timecode.fps30;

import com.transgressoft.timecode.*;

import static com.transgressoft.timecode.TimecodeException.ErrorCase.*;

/**
* Class that represents a {@link Timecode} implementation of
* a 30 fps video timecode.
*
* @author Octavio Calleya
* @version 1.0
* @see <a href="https://en.wikipedia.org/wiki/SMPTE_timecode">SMPTE Timecode</a>
*/
public class Fps30Timecode extends TimecodeBase {

/**
* Maximum amount of frames accepted, since the maximum value
* of the Timecode can be 23:59:59:30:
*
* <p>24 * 60 * 60 * 30 = 2 592 000</p>
*/
private static final int FRAME_COUNT_LIMIT = 2592000;
private static final int FRAME_MAX = 30;

private Fps30Timecode(int hours, int minutes, int seconds, int frames) {
super(hours, minutes, seconds, frames);
countFrames(hours, minutes, seconds, frames);
}

private Fps30Timecode(int frameCount) {
super(frameCount);
countUnits(frameCount);
}

public static Fps30Timecode of(int hours, int minutes, int seconds, int frames) {
if (! FrameRateType.FPS30.areValidValues(hours, minutes, seconds, frames))
throw new IllegalArgumentException(INVALID_TIMECODE.getErrorMessage());
return new Fps30Timecode(hours, minutes, seconds, frames);
}

public static Fps30Timecode of(int frameCount) {
if (frameCount < 0)
throw new IllegalArgumentException(FRAME_COUNT_LESS_0.getErrorMessage());
if (frameCount >= FRAME_COUNT_LIMIT)
throw new IllegalArgumentException(FRAME_COUNT_GREATER_LIMIT.getErrorMessage() + " " + FRAME_COUNT_LIMIT);
return new Fps30Timecode(frameCount);
}

@Override
public Timecode add(Timecode timecode) throws TimecodeException {
if (! (timecode instanceof Fps30Timecode))
throw new TimecodeException(INVALID_ADDITION);
addition(timecode);
return this;
}

@Override
public Timecode subtract(Timecode timecode) throws TimecodeException {
if (! (timecode instanceof Fps30Timecode))
throw new TimecodeException(INVALID_SUBTRACTION);
subtraction(timecode);
return this;
}

@Override
protected int getFrameMax() {
return FRAME_MAX;
}

@Override
public int getFrameCountLimit() {
return FRAME_COUNT_LIMIT;
}
}
38 changes: 38 additions & 0 deletions src/com/transgressoft/timecode/fps30/Fps30TimecodeFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2016, 2017 Octavio Calleya
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.transgressoft.timecode.fps30;

import com.transgressoft.timecode.*;

/**
* Factory class that creates {@link Fps30Timecode} objects.
*
* @author Octavio Calleya
* @version 1.0
*/
public class Fps30TimecodeFactory extends TimecodeFactory {

@Override
public Timecode createTimeCode(int hours, int minutes, int seconds, int frames) {
return Fps30Timecode.of(hours, minutes, seconds, frames);
}

@Override
public Timecode createTimeCode(int frameCount) {
return Fps30Timecode.of(frameCount);
}
}
2 changes: 1 addition & 1 deletion test/com/transgressoft/timecode/AcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Acceptance tests for the given input and output cases with the problem.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
@RunWith(JUnitPlatform.class)
public class AcceptanceTest {
Expand Down
6 changes: 4 additions & 2 deletions test/com/transgressoft/timecode/TimecodeStringTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.transgressoft.timecode.df30.*;
import com.transgressoft.timecode.fps24.*;
import com.transgressoft.timecode.fps25.*;
import com.transgressoft.timecode.fps30.*;
import org.junit.runner.*;
import org.junit.runners.*;
import org.junit.runners.Suite.*;
Expand All @@ -11,15 +12,16 @@
* Test suite for the test classes
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
@RunWith(Suite.class)
@SuiteClasses ({
AcceptanceTest.class,
TimecodeStringTests.class,
Df30TimecodeTest.class,
Fps25TimecodeTest.class,
Fps24Timecode.class
Fps24Timecode.class,
Fps30TimecodeTest.class
})
public class TimecodeStringTestSuite {

Expand Down
10 changes: 1 addition & 9 deletions test/com/transgressoft/timecode/TimecodeStringTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* {@link TimecodeInputType} and {@link TimecodeBase}.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class TimecodeStringTests {

Expand Down Expand Up @@ -61,14 +61,6 @@ void testInvalidFrameRateType() {
assertEquals("Invalid frame rate format", exception.getMessage());
}

@Test
@DisplayName ("30FPS frame rate not supported")
void test30FpsTimecodeStringCreation() {
UnsupportedOperationException exception = expectThrows(UnsupportedOperationException.class,
() -> TimecodeString.of(FrameRateType.FPS30.toString(), 12345));
assertEquals("30fps frame rate is not supported yet", exception.getMessage());
}

@Test
@DisplayName ("DF30 Timecode with negative hours throws exception")
void testTimecodeStringWithNegativeHours() {
Expand Down
2 changes: 1 addition & 1 deletion test/com/transgressoft/timecode/df30/Df30TimecodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Unit tests for {@link Df30Timecode} class.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class Df30TimecodeTest extends TimecodeTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Unit tests for {@link Fps24Timecode} class.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class Fps24TimecodeTest extends TimecodeTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Unit tests for {@link Fps25Timecode} class.
*
* @author Octavio Calleya
* @version 0.1
* @version 1.0
*/
public class Fps25TimecodeTest extends TimecodeTestBase {

Expand Down
Loading

0 comments on commit 19e4d5f

Please sign in to comment.