forked from Coppertino/cue-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheet.go
177 lines (158 loc) · 3.7 KB
/
sheet.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package cue
import (
"path/filepath"
"strings"
)
const (
framesPerSecond = 75
// Intel binary file (least significant byte first)
FileTypeBinary FileType = iota
// Motorola binary file (most significant byte first)
FileTypeMotorola
// Audio AIFF file
FileTypeAiff
// Audio WAVE file
FileTypeWave
// Audio MP3 file
FileTypeMp3
// AUDIO – Audio/Music (2352)
DataTypeAudio = iota
// CDG – Karaoke CD+G (2448)
DataTypeCdg
// MODE1/2048 – CDROM Mode1 Data (cooked)
DataTypeMode1_2048
// MODE1/2352 – CDROM Mode1 Data (raw)
DataTypeMode1_2352
// MODE2/2336 – CDROM-XA Mode2 Data
DataTypeMode2_2336
// MODE2/2352 – CDROM-XA Mode2 Data
DataTypeMode2_2352
// CDI/2336 – CDI Mode2 Data
DataTypeCdi_2336
// CDI/2352 – CDI Mode2 Data
DataTypeCdi_2352
// Digital copy permitted.
TrackFlagDcp = iota
// Four channel audio.
TrackFlag4ch
// Pre-emphasis enabled (audio tracks only).
TrackFlagPre
// Serial copy management system (not supported by all recorders).
TrackFlagScms
)
type (
// Cue sheet file representation.
Sheet struct {
// Disc's media catalog number.
Catalog string
// Name of a perfomer for a CD-TEXT enhanced disc
Performer string
// Specify a title for a CD-TEXT enhanced disc.
Title string
// Specify songwriter for disc.
Songwriter string
// Comments in the CUE SHEET file.
Comments []string
// Name of the file that contains the encoded CD-TEXT information for the disc.
CdTextFile string
// Data/audio files descibed byt the cue-file.
Files []*File
}
// Track datatype.
TrackDataType int
// Type of the audio file.
FileType int
// Additional decode information about track.
TrackFlag int
// Time point description type.
Time struct {
// Minutes.
Min int
// Minutes.
Sec int
// Frames.
Frames int
}
// Track index type
Index struct {
// Index number.
Number int
// Index starting time.
Time Time
}
Track struct {
// Track number (1-99).
Number int
// Track datatype.
DataType TrackDataType
// Track title.
Title string
// Track preformer.
Performer string
// Songwriter.
Songwriter string
// Track decode flags.
Flags []TrackFlag
// Internetional Standaard Recording Code.
Isrc string
// Track indexes.
Indexes []Index
// Length of the track pregap.
Pregap Time
// Length of the track postgap.
Postgap Time
StartPosition float64
EndPosition float64
}
// Audio file representation structure.
File struct {
// Name (path) of the file.
Name string
// Type of the audio file.
Type FileType
// List of present tracks in the file.
Tracks []*Track
// Total duration in seconds
Duration float64
}
)
// Seconds returns length in seconds.
func (time Time) Seconds() float64 {
return float64(time.Min*60) + float64(time.Sec) + float64(time.Frames)/framesPerSecond
}
// StartTime return track start time
func (t *Track) StartTime() (time Time) {
if len(t.Indexes) == 1 {
time = t.Indexes[0].Time
} else if len(t.Indexes) > 1 {
time = t.Indexes[1].Time
}
return
}
func (t *Track) Duration() float64 {
return t.EndPosition - t.StartPosition
}
func (s *Sheet) FileTrackCount(fileName string) int {
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
for _, f := range s.Files {
if strings.TrimSuffix(f.Name, filepath.Ext(f.Name)) == fileName {
return len(f.Tracks)
}
}
return 0
}
func (s *Sheet) FileTracks(fileName string) []*Track {
fileName = strings.TrimSuffix(fileName, filepath.Ext(fileName))
for _, f := range s.Files {
if strings.TrimSuffix(f.Name, filepath.Ext(f.Name)) == fileName {
return f.Tracks
}
}
return make([]*Track, 0)
}
func (s *Sheet) TracksCount() (c int) {
for _, f := range s.Files {
c += len(f.Tracks)
}
return
}