-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from GanymedeNil/feature/v2.1
Feature/v2.1
- Loading branch information
Showing
23 changed files
with
747 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package Common | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"srt2fcpxml/lib" | ||
) | ||
|
||
func FrameMapString(frameRate interface{}) (string, error) { | ||
switch v := frameRate.(type) { | ||
case float64: | ||
return fmt.Sprintf("%d/%d", 1001, int64(lib.Round(v, 0)*1000)), nil | ||
case int: | ||
return fmt.Sprintf("%d/%d", 100, v*100), nil | ||
default: | ||
return "", errors.New("frameRate is int or float") | ||
} | ||
} | ||
|
||
func FrameMap(frameRate interface{}) (float64, error) { | ||
switch v := frameRate.(type) { | ||
case float64: | ||
return 1001 / (lib.Round(v, 0) * 1000), nil | ||
case int: | ||
return 100 / float64(v*100), nil | ||
default: | ||
return 0, errors.New("frameRate is int or float") | ||
} | ||
} | ||
|
||
func FrameDuration(frameRate interface{}) float64 { | ||
switch v := frameRate.(type) { | ||
case float64: | ||
return v | ||
case int: | ||
return float64(v) | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
func FrameDurationFormat(frameRate interface{}) (float64, float64, error) { | ||
switch v := frameRate.(type) { | ||
case float64: | ||
return 1001, lib.Round(v, 0) * 1000, nil | ||
case int: | ||
return 100, float64(v * 100), nil | ||
default: | ||
return 0, 0, errors.New("frameRate is int or float") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package Common | ||
|
||
import ( | ||
"log" | ||
"srt2fcpxml/lib" | ||
"testing" | ||
) | ||
|
||
func TestFrameMap(t *testing.T) { | ||
type args struct { | ||
frameRate interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want float64 | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "23.98", | ||
args: struct{ frameRate interface{} }{frameRate: 23.98}, | ||
want: 1001 / float64(24000), | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "24", | ||
args: struct{ frameRate interface{} }{frameRate: 24}, | ||
want: 100 / float64(2400), | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "err", | ||
args: struct{ frameRate interface{} }{frameRate: "ad"}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := FrameMap(tt.args.frameRate) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("FrameMap() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
f := lib.Floater{Accuracy: 0.000000000001} | ||
log.Print(got) | ||
log.Print(tt.want) | ||
if !f.IsEqual(got, tt.want) { | ||
t.Errorf("FrameMap() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestFrameMapString(t *testing.T) { | ||
type args struct { | ||
frameRate interface{} | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "23.98", | ||
args: struct{ frameRate interface{} }{frameRate: 23.98}, | ||
want: "1001/24000", | ||
}, | ||
{ | ||
name: "24", | ||
args: struct{ frameRate interface{} }{frameRate: 24}, | ||
want: "100/2400", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "err", | ||
args: struct{ frameRate interface{} }{frameRate: "ad"}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := FrameMapString(tt.args.frameRate) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("FrameMapString() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("FrameMapString() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package FcpXML | ||
|
||
import ( | ||
"encoding/xml" | ||
"srt2fcpxml/core/FcpXML/Library" | ||
"srt2fcpxml/core/FcpXML/Resources" | ||
) | ||
|
||
type FcpXML struct { | ||
XMLName xml.Name `xml:"fcpxml"` | ||
Text string `xml:",chardata"` | ||
Version string `xml:"version,attr"` | ||
Resources *Resources.Resources `xml:"resources"` | ||
Library *Library.Library `xml:"library"` | ||
} | ||
|
||
func New() *FcpXML { | ||
return &FcpXML{ | ||
XMLName: xml.Name{}, | ||
Text: "", | ||
Version: "1.7", | ||
Resources: &Resources.Resources{}, | ||
Library: &Library.Library{}, | ||
} | ||
} | ||
|
||
func (fcp *FcpXML) SetVersion(version string) *FcpXML { | ||
fcp.Version = version | ||
return fcp | ||
} | ||
|
||
func (fcp *FcpXML) SetResources(resources *Resources.Resources) *FcpXML { | ||
fcp.Resources = resources | ||
return fcp | ||
} | ||
|
||
func (fcp *FcpXML) SetLibrary(library *Library.Library) *FcpXML { | ||
fcp.Library = library | ||
return fcp | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package FcpXML | ||
|
||
import ( | ||
"encoding/xml" | ||
"srt2fcpxml/core/FcpXML/Library" | ||
"srt2fcpxml/core/FcpXML/Library/Event" | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project" | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project/Sequence" | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project/Sequence/Spine" | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project/Sequence/Spine/Gap" | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project/Sequence/Spine/Gap/Title" | ||
"srt2fcpxml/core/FcpXML/Resources" | ||
"testing" | ||
) | ||
|
||
func TestFcpXML_SetVersion(t *testing.T) { | ||
fcpxml := New() | ||
res := Resources.NewResources() | ||
res.SetEffect(Resources.NewEffect()) | ||
format := Resources.NewFormat(). | ||
SetWidth(1440). | ||
SetHeight(1080). | ||
SetFrameRate(23.98).Render() | ||
res.SetFormat(format) | ||
fcpxml.SetResources(res) | ||
|
||
gap := Gap.NewGap(180.2) | ||
|
||
textStyleDef := Title.NewTextStyleDef(1) | ||
text := Title.NewContent(1, "4:00") | ||
title := Title.NewTitle("4:00 - 基本字幕", 4.0, 7.8).SetTextStyleDef(textStyleDef).SetText(text) | ||
title.AddParam(Title.NewParams("位置", "9999/999166631/999166633/1/100/101", "0 -450")) | ||
title.AddParam(Title.NewParams("对齐", "9999/999166631/999166633/2/354/999169573/401", "1 (居中)")) | ||
title.AddParam(Title.NewParams("展平", "9999/999166631/999166633/2/351", "1")) | ||
gap.AddTitle(title) | ||
|
||
spine := Spine.NewSpine().SetGap(gap) | ||
|
||
seq := Sequence.NewSequence(180.2).SetSpine(spine) | ||
|
||
project := Project.NewProject("ceshi").SetSequence(seq) | ||
|
||
event := Event.NewEvent().SetProject(project) | ||
|
||
lib := Library.NewLibrary("未命名 1").SetEvent(event) | ||
|
||
fcpxml.SetLibrary(lib) | ||
|
||
e, _ := xml.MarshalIndent(&fcpxml, "", " ") | ||
t.Log(string(e)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package Event | ||
|
||
import ( | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project" | ||
"time" | ||
|
||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
type Event struct { | ||
Text string `xml:",chardata"` | ||
Name string `xml:"name,attr"` | ||
Uid string `xml:"uid,attr"` | ||
Project *Project.Project `xml:"project"` | ||
} | ||
|
||
func NewEvent() *Event { | ||
return &Event{ | ||
Name: time.Now().Format("2006-01-02"), | ||
Uid: uuid.NewV4().String(), | ||
Project: &Project.Project{}, | ||
} | ||
} | ||
|
||
func (e *Event) SetProject(project *Project.Project) *Event { | ||
e.Project = project | ||
return e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package Project | ||
|
||
import ( | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project/Sequence" | ||
"time" | ||
|
||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
type Project struct { | ||
Text string `xml:",chardata"` | ||
Name string `xml:"name,attr"` | ||
Uid string `xml:"uid,attr"` | ||
ModDate string `xml:"modDate,attr"` | ||
Sequence *Sequence.Sequence `xml:"sequence"` | ||
} | ||
|
||
func NewProject(projectName string) *Project { | ||
modDate := time.Now().Format("2006-01-02 15:04:05 -0700") | ||
return &Project{ | ||
Name: projectName, | ||
Uid: uuid.NewV4().String(), | ||
ModDate: modDate, | ||
Sequence: &Sequence.Sequence{}, | ||
} | ||
} | ||
|
||
func (p *Project) SetSequence(sequence *Sequence.Sequence) *Project { | ||
p.Sequence = sequence | ||
return p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package Sequence | ||
|
||
import ( | ||
"fmt" | ||
"srt2fcpxml/core/FcpXML/Common" | ||
"srt2fcpxml/core/FcpXML/Library/Event/Project/Sequence/Spine" | ||
"srt2fcpxml/core/FcpXML/Resources" | ||
"srt2fcpxml/lib" | ||
) | ||
|
||
type Sequence struct { | ||
Text string `xml:",chardata"` | ||
Duration string `xml:"duration,attr"` | ||
Format string `xml:"format,attr"` | ||
TcStart string `xml:"tcStart,attr"` | ||
TcFormat string `xml:"tcFormat,attr"` | ||
AudioLayout string `xml:"audioLayout,attr"` | ||
AudioRate string `xml:"audioRate,attr"` | ||
Spine *Spine.Spine `xml:"spine"` | ||
} | ||
|
||
func NewSequence(duration float64) *Sequence { | ||
frameRate := Resources.GetFrameRate() | ||
frameRateR := Common.FrameDuration(frameRate) | ||
frameDurationMolecular, frameDurationDenominator, _ := Common.FrameDurationFormat(frameRate) | ||
return &Sequence{ | ||
Text: "", | ||
Duration: fmt.Sprintf("%.f/%.fs", lib.Round(duration*frameRateR, 0)*frameDurationMolecular, frameDurationDenominator), | ||
Format: "r1", | ||
TcStart: "0s", | ||
TcFormat: "NDF", | ||
AudioLayout: "stereo", | ||
AudioRate: "48k", | ||
Spine: &Spine.Spine{}, | ||
} | ||
} | ||
|
||
func (s *Sequence) SetSpine(spine *Spine.Spine) *Sequence { | ||
s.Spine = spine | ||
return s | ||
} |
Oops, something went wrong.