Skip to content

Commit 636d313

Browse files
committed
Rename the ranges to cuts to tie everything back
1 parent 3cf201c commit 636d313

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

‎markut.go‎

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (context *EvalContext) typeCheckArgs(loc Loc, signature ...TokenKind) (args
140140
return
141141
}
142142

143-
type Range struct {
143+
type Cut struct {
144144
startLoc Loc
145145
startOffset Millis
146146
startChunk int
@@ -160,7 +160,7 @@ type EvalContext struct {
160160
chunks []Chunk
161161
chunksDefinedForCurrentInput int
162162
chapters []Chapter
163-
ranges []Range
163+
cuts []Cut
164164

165165
argsStack []Token
166166
chapStack []Chapter
@@ -548,9 +548,9 @@ func (context *EvalContext) finishEval() bool {
548548
ok = false
549549
}
550550

551-
for i := range context.ranges {
552-
if !context.ranges[i].closed {
553-
fmt.Printf("%s: ERROR: unclosed range\n", context.ranges[i].startLoc);
551+
for i := range context.cuts {
552+
if !context.cuts[i].closed {
553+
fmt.Printf("%s: ERROR: unclosed cut\n", context.cuts[i].startLoc);
554554
ok = false
555555
}
556556
}
@@ -771,8 +771,8 @@ var Subcommands = map[string]Subcommand{
771771
return true
772772
},
773773
},
774-
"range": {
775-
Description: "Render a specific range of the final video",
774+
"cut": {
775+
Description: "Render all cuts of the final video",
776776
Run: func(name string, args []string) bool {
777777
subFlag := flag.NewFlagSet(name, flag.ContinueOnError)
778778
markutPtr := subFlag.String("markut", "MARKUT", "Path to the MARKUT file")
@@ -798,78 +798,78 @@ var Subcommands = map[string]Subcommand{
798798
return false;
799799
}
800800

801-
for i, r := range context.ranges {
802-
startChunk := r.startChunk
803-
startOffset := r.startOffset
801+
for i, cut := range context.cuts {
802+
startChunk := cut.startChunk
803+
startOffset := cut.startOffset
804804
if startChunk < 0 {
805805
startChunk = 0
806806
startOffset = context.chunks[startChunk].Duration();
807807
}
808808
if startOffset > context.chunks[startChunk].Duration() {
809-
fmt.Printf("%s: TODO: overflowing start offset is not implemented yet\n", r.startLoc)
809+
fmt.Printf("%s: TODO: overflowing start offset is not implemented yet\n", cut.startLoc)
810810
return false
811811
}
812-
endChunk := r.endChunk
813-
endOffset := r.endOffset
812+
endChunk := cut.endChunk
813+
endOffset := cut.endOffset
814814
if endChunk >= len(context.chunks) {
815815
endChunk := len(context.chunks)-1
816816
endOffset = context.chunks[endChunk].Duration();
817817
}
818818
if endOffset > context.chunks[endChunk].Duration() {
819-
fmt.Printf("%s: TODO: overflowing end offset is not implemented yet\n", r.endLoc)
819+
fmt.Printf("%s: TODO: overflowing end offset is not implemented yet\n", cut.endLoc)
820820
return false
821821
}
822822
if startChunk >= endChunk {
823-
fmt.Printf("%s: TODO: we don't handle overlapping start and end chunks\n", r.endLoc);
824-
fmt.Printf("%s: TODO: start is here\n", r.startLoc);
823+
fmt.Printf("%s: TODO: we don't handle overlapping start and end chunks\n", cut.endLoc);
824+
fmt.Printf("%s: TODO: start is here\n", cut.startLoc);
825825
return false;
826826
// I think this may happen like this
827827
// ```markut
828-
// 5 range_start
828+
// 5 cut_start
829829
// 69 420 chunk
830-
// 5 range_end
830+
// 5 cut_end
831831
// ```
832832
}
833-
var rangeChunks []Chunk
834-
rangeChunks = append(rangeChunks, Chunk{
833+
var cutChunks []Chunk
834+
cutChunks = append(cutChunks, Chunk{
835835
Start: context.chunks[startChunk].End - startOffset,
836836
End: context.chunks[startChunk].End,
837837
InputPath: context.chunks[startChunk].InputPath,
838838
// TODO: this should probably copy the rest of the properties of the original chunk
839839
})
840840
for chunk := startChunk + 1; chunk <= endChunk - 1; chunk += 1 {
841-
rangeChunks = append(rangeChunks, context.chunks[chunk]);
841+
cutChunks = append(cutChunks, context.chunks[chunk]);
842842
}
843-
rangeChunks = append(rangeChunks, Chunk{
843+
cutChunks = append(cutChunks, Chunk{
844844
Start: context.chunks[endChunk].Start,
845845
End: context.chunks[endChunk].Start + endOffset,
846846
InputPath: context.chunks[endChunk].InputPath,
847847
// TODO: this should probably copy the rest of the properties of the original chunk
848848
})
849849

850-
for _, chunk := range rangeChunks {
850+
for _, chunk := range cutChunks {
851851
err := ffmpegCutChunk(context, chunk)
852852
if err != nil {
853853
fmt.Printf("WARNING: Failed to cut chunk %s: %s\n", chunk.Name(), err)
854854
}
855855
}
856856

857-
listPath := fmt.Sprintf("range-%02d-list.txt", i)
858-
err = ffmpegGenerateConcatList(rangeChunks, listPath)
857+
listPath := fmt.Sprintf("cut-%02d-list.txt", i)
858+
err = ffmpegGenerateConcatList(cutChunks, listPath)
859859
if err != nil {
860-
fmt.Printf("ERROR: Could not generate not generate range concat list %s: %s\n", listPath, err)
860+
fmt.Printf("ERROR: Could not generate not generate concat list %s: %s\n", listPath, err)
861861
return false
862862
}
863863

864-
rangeOutputPath := fmt.Sprintf("range-%02d.mp4", i)
865-
err = ffmpegConcatChunks(listPath, rangeOutputPath)
864+
cutOutputPath := fmt.Sprintf("cut-%02d.mp4", i)
865+
err = ffmpegConcatChunks(listPath, cutOutputPath)
866866
if err != nil {
867-
fmt.Printf("ERROR: Could not generate range output file %s: %s\n", rangeOutputPath, err)
867+
fmt.Printf("ERROR: Could not generate output file %s: %s\n", cutOutputPath, err)
868868
return false
869869
}
870870

871-
fmt.Printf("Generated %s\n", rangeOutputPath)
872-
fmt.Printf("%s: NOTE: range is defined in here\n", context.chunks[i].Loc)
871+
fmt.Printf("Generated %s\n", cutOutputPath)
872+
fmt.Printf("%s: NOTE: cut is defined in here\n", context.cuts[i].endLoc)
873873
}
874874

875875
return true
@@ -1853,8 +1853,8 @@ func main() {
18531853
return true
18541854
},
18551855
},
1856-
"range_end": {
1857-
Description: "Define range end for `markut range` command.",
1856+
"cut_end": {
1857+
Description: "Define cut end for `markut cut` command.",
18581858
Category: "Misc",
18591859
Signature: "<end:Timestamp> --",
18601860
Run: func(context *EvalContext, command string, token Token) bool {
@@ -1866,28 +1866,28 @@ func main() {
18661866
}
18671867
offset := args[0]
18681868

1869-
if len(context.ranges) == 0 {
1870-
fmt.Printf("%s: ERROR: no ranges to close\n", token.Loc);
1869+
if len(context.cuts) == 0 {
1870+
fmt.Printf("%s: ERROR: no cuts to close\n", token.Loc);
18711871
return false;
18721872
}
18731873

1874-
previousRange := &context.ranges[len(context.ranges)-1];
1875-
if previousRange.closed {
1876-
fmt.Printf("%s: ERROR: no ranges to close\n", token.Loc);
1877-
fmt.Printf("%s: NOTE: previous range was closed here\n", previousRange.endLoc);
1874+
previousCut := &context.cuts[len(context.cuts)-1];
1875+
if previousCut.closed {
1876+
fmt.Printf("%s: ERROR: no cuts to close\n", token.Loc);
1877+
fmt.Printf("%s: NOTE: previous cut was closed here\n", previousCut.endLoc);
18781878
return false;
18791879
}
18801880

1881-
previousRange.closed = true;
1882-
previousRange.endLoc = token.Loc;
1883-
previousRange.endChunk = len(context.chunks);
1884-
previousRange.endOffset = offset.Timestamp;
1881+
previousCut.closed = true;
1882+
previousCut.endLoc = token.Loc;
1883+
previousCut.endChunk = len(context.chunks);
1884+
previousCut.endOffset = offset.Timestamp;
18851885

18861886
return true
18871887
},
18881888
},
1889-
"range_start": {
1890-
Description: "Define range start for `markut range` command.",
1889+
"cut_start": {
1890+
Description: "Define cut start for `markut cut` command.",
18911891
Category: "Misc",
18921892
Signature: "<start:Timestamp> --",
18931893
Run: func(context *EvalContext, command string, token Token) bool {
@@ -1899,16 +1899,16 @@ func main() {
18991899
}
19001900
offset := args[0]
19011901

1902-
if len(context.ranges) > 0 {
1903-
previousRange := context.ranges[len(context.ranges)-1];
1904-
if !previousRange.closed {
1905-
fmt.Printf("%s: ERROR: you are starting a new range before closing the previous one", token.Loc);
1906-
fmt.Printf("%s: NOTE: the previous range is started here", previousRange.startLoc);
1902+
if len(context.cuts) > 0 {
1903+
previousCut := context.cuts[len(context.cuts)-1];
1904+
if !previousCut.closed {
1905+
fmt.Printf("%s: ERROR: you are starting a new cut before closing the previous one", token.Loc);
1906+
fmt.Printf("%s: NOTE: the previous cut is started here", previousCut.startLoc);
19071907
return false;
19081908
}
19091909
}
19101910

1911-
context.ranges = append(context.ranges, Range{
1911+
context.cuts = append(context.cuts, Cut{
19121912
startLoc: token.Loc,
19131913
startChunk: len(context.chunks) - 1,
19141914
startOffset: offset.Timestamp,
@@ -1917,7 +1917,7 @@ func main() {
19171917
},
19181918
},
19191919
"cut": {
1920-
Description: "Equivalent to `<offset> range_start <offset> range_end`.",
1920+
Description: "Equivalent to `<offset> cut_start <offset> cut_end`.",
19211921
Category: "Misc",
19221922
Signature: "<offset:Timestamp> --",
19231923
Run: func(context *EvalContext, command string, token Token) bool {
@@ -1928,7 +1928,7 @@ func main() {
19281928
return false
19291929
}
19301930
offset := args[0]
1931-
context.ranges = append(context.ranges, Range{
1931+
context.cuts = append(context.cuts, Cut{
19321932
startLoc: token.Loc,
19331933
startOffset: offset.Timestamp,
19341934
startChunk: len(context.chunks) - 1,

0 commit comments

Comments
 (0)