Skip to content

Commit

Permalink
Add Timecode.rebase (#13)
Browse files Browse the repository at this point in the history
Timecode.rebase and other misc friends
  • Loading branch information
peake100 authored Mar 6, 2023
1 parent 489b87c commit 7cd6bdb
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 285 deletions.
210 changes: 210 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# This file contains the configuration for Credo and you are probably reading
# this after creating it with `mix credo.gen.config`.
#
# If you find anything wrong or unclear in this file, please report an
# issue on GitHub: https://github.com/rrrene/credo/issues
#
%{
#
# You can have as many configs as you like in the `configs:` field.
configs: [
%{
#
# Run any config using `mix credo -C <name>`. If no config name is given
# "default" is used.
#
name: "default",
#
# These are the files included in the analysis:
files: %{
#
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: [
"lib/",
"src/",
"test/",
"web/",
"apps/*/lib/",
"apps/*/src/",
"apps/*/test/",
"apps/*/web/"
],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
# Load and configure plugins here:
#
plugins: [],
#
# If you create your own checks, you must specify the source files for
# them here, so they can be loaded by Credo before running the analysis.
#
requires: [],
#
# If you want to enforce a style guide and need a more traditional linting
# experience, you can change `strict` to `true` below:
#
strict: false,
#
# To modify the timeout for parsing files, change this value:
#
parse_timeout: 5000,
#
# If you want to use uncolored output by default, you can change `color`
# to `false` below:
#
color: true,
#
# You can customize the parameters of any check by adding a second element
# to the tuple.
#
# To disable a check put `false` as second element:
#
# {Credo.Check.Design.DuplicatedCode, false}
#
checks: %{
enabled: [
#
## Consistency Checks
#
{Credo.Check.Consistency.ExceptionNames, []},
{Credo.Check.Consistency.LineEndings, []},
{Credo.Check.Consistency.ParameterPatternMatching, []},
{Credo.Check.Consistency.SpaceAroundOperators, []},
{Credo.Check.Consistency.SpaceInParentheses, []},
{Credo.Check.Consistency.TabsOrSpaces, []},

#
## Design Checks
#
# You can customize the priority of any check
# Priority values are: `low, normal, high, higher`
#
{Credo.Check.Design.AliasUsage,
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero).
#
{Credo.Check.Design.TagTODO, [exit_status: 2]},
{Credo.Check.Design.TagFIXME, []},

#
## Readability Checks
#
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.WithSingleClause, []},

#
## Refactoring Opportunities
#
{Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},
{Credo.Check.Refactor.FilterFilter, []},
{Credo.Check.Refactor.RejectReject, []},
{Credo.Check.Refactor.RedundantWithClauseResult, []},

#
## Warnings
#
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.SpecWithStruct, []},
{Credo.Check.Warning.WrongTestFileExtension, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.UnsafeExec, []}
],
disabled: [
#
# Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`)

#
# Controversial and experimental checks (opt-in, just move the check to `:enabled`
# and be sure to use `mix credo --strict` to see low priority checks)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
{Credo.Check.Design.DuplicatedCode, []},
{Credo.Check.Design.SkipTestWithoutComment, []},
{Credo.Check.Readability.AliasAs, []},
{Credo.Check.Readability.BlockPipe, []},
{Credo.Check.Readability.ImplTrue, []},
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.NestedFunctionCalls, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
{Credo.Check.Refactor.ABCSize, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.FilterReject, []},
{Credo.Check.Refactor.IoPuts, []},
{Credo.Check.Refactor.MapMap, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.RejectFilter, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.UnsafeToAtom, []}

# {Credo.Check.Refactor.MapInto, []},

#
# Custom checks can be created using `mix credo.gen.check`.
#
]
}
}
]
}
13 changes: 6 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
"emeraldwalk.runonsave": {
"commands": [
{
"match": "*.ex",
"cmd": "mix format ${relativeFile}"
},
{
"match": "*.exs",
"cmd": "mix format ${relativeFile}"
"match": "\\.exs$|\\.ex$",
"cmd": "mix format ${file}"
}
]
},
"elixir.credo.credoConfiguration": "config/.credo.exs",
"elixirLinter.useStrict": true,
"elixir.credo.executePath": "/Users/bpeake/.asdf/shims/mix",
"elixir.credo.credoConfiguration": "/Users/bpeake/code/opencinema/vtc-ex/.credo.exs",
"elixir.credo.strictMode": true,
"githubPullRequests.ignoredPullRequestBranches": [
"qa"
]
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test:
lint:
-mix format --check-formatted
-mix dialyzer
-mix credo --strict
-find . -type f | grep -e "\.ex$$" -e "\.exs$$" | grep -v zdevelop/ | grep -v _build | grep -v deps | xargs misspell -error

.PHONY: format
Expand Down
16 changes: 8 additions & 8 deletions lib/consts.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule Vtc.Private.Consts do
@moduledoc false

@spec seconds_per_minute() :: integer
def seconds_per_minute(), do: 60
@spec seconds_per_minute() :: integer()
def seconds_per_minute, do: 60

@spec seconds_per_hour() :: integer
def seconds_per_hour(), do: seconds_per_minute() * 60
@spec seconds_per_hour() :: integer()
def seconds_per_hour, do: seconds_per_minute() * 60

@spec ppro_tick_per_second() :: integer
def ppro_tick_per_second(), do: 254_016_000_000
@spec ppro_tick_per_second() :: integer()
def ppro_tick_per_second, do: 254_016_000_000

@spec frames_per_foot() :: integer
def frames_per_foot(), do: 16
@spec frames_per_foot() :: integer()
def frames_per_foot, do: 16
end
2 changes: 1 addition & 1 deletion lib/drop_frame.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule Vtc.Private.DropFrame do
@moduledoc false
alias Vtc.Framerate
alias Vtc.Utils.Rational
alias Vtc.Timecode
alias Vtc.Utils.Rational

# Adjusts the frame number based on drop-frame TC conventions.
#
Expand Down
25 changes: 11 additions & 14 deletions lib/framerate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Vtc.Framerate do
@typedoc """
Enum of `Ntsc` types.
# Values
## Values
- `nil`: Not an NTSC value
- `:non_drop` A non-drop NTSC value.
Expand All @@ -27,12 +27,12 @@ defmodule Vtc.Framerate do
@typedoc """
Type of `Framerate`
# Fields
## Fields
- `:playback`: The rational representation of the real-world playback speed as a
- **playback**: The rational representation of the real-world playback speed as a
fraction in frames-per-second.
- `:ntsc`: Atom representing which, if any, NTSC convention this framerate adheres to.
- **ntsc**: Atom representing which, if any, NTSC convention this framerate adheres to.
"""
@type t :: %__MODULE__{playback: Rational.t(), ntsc: ntsc()}

Expand All @@ -53,9 +53,9 @@ defmodule Vtc.Framerate do
@typedoc """
Type of `ParseError`
# Fields
## Fields
- `:reason`: The reason the error occurred must be one of the following:
- **reason**: The reason the error occurred must be one of the following:
- `:bad_drop_rate`: Returned when the playback speed of a framerate with an ntsc
value of :drop is not divisible by 3000/1001 (29.97), for more on why drop-frame
Expand Down Expand Up @@ -93,16 +93,14 @@ defmodule Vtc.Framerate do
end

@typedoc """
Type returned by `Framerate.new/2`
`Framerate.new!/2` raises the error value instead.
Type returned by `new/2`
"""
@type parse_result() :: {:ok, t()} | {:error, ParseError.t()}

@doc """
Creates a new Framerate with a playback speed or timebase.
# Arguments
## Arguments
- **rate**: Either the playback rate or timebase. For NTSC framerates, the value will
be rounded to the nearest correct value.
Expand Down Expand Up @@ -151,7 +149,7 @@ defmodule Vtc.Framerate do
end

@doc """
As `Framerate.new/2` but raises an error instead.
As `new/2` but raises an error instead.
"""
@spec new!(Rational.t() | float() | String.t(), ntsc(), boolean()) :: t()
def new!(rate, ntsc, coerce_seconds_per_frame? \\ true) do
Expand Down Expand Up @@ -221,9 +219,8 @@ defmodule Vtc.Framerate do
end

@doc """
Returns true if the value represents and NTSC framerate.
So will return true on `:non_drop` and `:drop`.
Returns true if the value represents and NTSC framerate, therefore will return true
on a Framerate with an `:ntsc` value of `:non_drop` and `:drop`.
"""
@spec ntsc?(t()) :: boolean()
def ntsc?(%__MODULE__{ntsc: nil}), do: false
Expand Down
Loading

0 comments on commit 7cd6bdb

Please sign in to comment.