forked from PossumInABox/simple-cuesheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
album.js
73 lines (57 loc) · 1.49 KB
/
album.js
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
class Album {
constructor(artist, title, duration) {
if (artist !== '') {
this.artist = artist;
} else {
throw {name:'InvalidInputException', message:'Invalid artist name'};
}
if (title !== '') {
this.title = title;
} else {
throw {name:'InvalidInputException', message:'Invalid album name'};
}
if (duration.match('[0-9][0-9]:[0-9][0-9]:[0-9][0-9]')) {
this.duration = duration;
} else {
throw {name:'InvalidInputException', message:'Invalid duration'};
}
this.tracks = [];
}
addTrack(artist, title, cuePoint) {
this.tracks.push(new Track(artist, title, cuePoint));
}
deleteTrack(title) {
let formerCuePoint;
if (this.tracks[0]) {
formerCuePoint = this.tracks[0].cuePoint;
}
for (let i = 0; i < this.tracks.length; i++) {
if (this.tracks[i].title === title) {
this.tracks.splice(i, 1);
}
}
if (this.tracks[0]) {
this.tracks[0].cuePoint = formerCuePoint;
}
}
clearTracks() {
this.tracks = [];
}
toString() {
let returnString = 'PERFORMER "' + this.artist + '"\n';
returnString += 'TITLE "' + this.title + '"\n';
returnString += 'FILE "' + this.artist + ' - ' + this.title + '" WAVE\n';
for (let k = 0; k < this.tracks.length; k++) {
let trackCounter = 0
if ((k + 1) < 10) {
trackCounter = ('0' + (k + 1));
} else {
trackCounter = (k + 1);
}
returnString += 'TRACK ' + trackCounter + ' AUDIO\n';
returnString += this.tracks[k].toString();
returnString += '\n';
}
return returnString;
}
}