Skip to content

Commit 95a97a4

Browse files
authored
Merge pull request #157 from CodeF0x/missing-documentation-#152
Redid function documentation.
2 parents 89608e9 + 5ccf91a commit 95a97a4

3 files changed

Lines changed: 106 additions & 88 deletions

File tree

src/js/Index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/** Represents application itself */
12
class Main {
23
constructor() {
34
const { ipcRenderer } = require('electron');
@@ -39,9 +40,8 @@ class Main {
3940
}
4041

4142
/**
42-
* @function sort
43-
* @param {event} e
44-
* @description Sorts alphabetically either name, album, or artist.
43+
* Sorts alphabetically.
44+
* @param {Event} e
4545
*/
4646
sort(e) {
4747
const self = this;
@@ -72,8 +72,7 @@ class Main {
7272
}
7373

7474
/**
75-
* @function revertSorting
76-
* @description Reverts sorting to original order of files in directory.
75+
* Reverts sorted playlist to original state.
7776
*/
7877
revertSorting() {
7978
const self = this;
@@ -83,8 +82,7 @@ class Main {
8382
}
8483

8584
/**
86-
* @function backupFiles
87-
* @description Backups original files to revert sorting and shuffle play to original order.
85+
* Caches playlist.
8886
*/
8987
backupFiles() {
9088
const self = this;
@@ -94,8 +92,7 @@ class Main {
9492
}
9593

9694
/**
97-
* @function _createTitlebar
98-
* @description Creates the custom title bar on Windows and Linux.
95+
* Creates custom title bar instead of OS default.
9996
*/
10097
_createTitlebar() {
10198
const { Titlebar, Color } = require('custom-electron-titlebar');

src/js/Player.js

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
/** Representation of audio capabilities. */
12
module.exports = class Player {
3+
/**
4+
* Set up.
5+
* @param {Object} UI
6+
*/
27
constructor(UI) {
38
const self = this;
49

@@ -12,11 +17,10 @@ module.exports = class Player {
1217
}
1318

1419
/**
15-
* @function play
16-
* @param {String} path - path to music file
17-
* @param {instance} UI - instance of view class
18-
* @param {instance} Main - instance of main class
19-
* @description Plays music file.
20+
* Plays a given song.
21+
* @param {string} path
22+
* @param {Object} UI
23+
* @param {Object} Main
2024
*/
2125
play(path, UI, Main) {
2226
const self = this;
@@ -41,10 +45,9 @@ module.exports = class Player {
4145
}
4246

4347
/**
44-
* @function next
45-
* @param {instance} UI - instance of view class
46-
* @param {instance} Main - instance of main class
47-
* @description Play next song in order.
48+
* Plays next song in order.
49+
* @param {Object} UI
50+
* @param {Object} Main
4851
*/
4952
next(UI, Main) {
5053
const self = this;
@@ -63,13 +66,10 @@ module.exports = class Player {
6366
}
6467

6568
/**
66-
* @function previous
67-
* @param {instance} UI - instance of view class
68-
* @param {instance} Main - instance of main class
69-
* @description Plays previous song in order.
69+
* Plays previous song in order or resets current song.
70+
* @param {Object} UI
71+
* @param {Object} Main
7072
*/
71-
72-
// TODO test, seems to work inconsistently
7373
previous(UI, Main) {
7474
const self = this;
7575

@@ -87,19 +87,17 @@ module.exports = class Player {
8787
}
8888

8989
/**
90-
* @function setVolume
91-
* @param {number} value - the value to set
92-
* @description Sets the players volume.
90+
* Sets playback volume.
91+
* @param {number} value
9392
*/
9493
setVolume(value) {
9594
const self = this;
9695
self._audioPlayer.volume = value / 100;
9796
}
9897

9998
/**
100-
* @function stop
101-
* @param {instance} UI - instance of View class
102-
* @description Stops the playback.
99+
* Stops playback completely.
100+
* @param {Object} UI
103101
*/
104102
stop(UI) {
105103
const self = this;
@@ -108,6 +106,11 @@ module.exports = class Player {
108106
UI.resetUI();
109107
}
110108

109+
/**
110+
* Preloads first song of playlist.
111+
* @param {Object} UI
112+
* @param {Object} Main
113+
*/
111114
preloadHead(UI, Main) {
112115
const self = this;
113116
const cachedVolume = self._audioPlayer.volume;
@@ -126,12 +129,9 @@ module.exports = class Player {
126129
}
127130

128131
/**
129-
* @function playPause
130-
* @param {instance} Main - instance of main class
131-
* @param {instance} UI - instance of ui class
132-
* @description Toggles between play and pause of playback.
132+
* Either pauses or resumes playback.
133133
*/
134-
playPause(Main, UI) {
134+
playPause() {
135135
const self = this;
136136

137137
const isPaused = self.isPaused;
@@ -143,15 +143,19 @@ module.exports = class Player {
143143
}
144144

145145
/**
146-
* @function setProgress
147-
* @param {number} percent - current time in percent
148-
* @description Sets the current time to value of progress bar, when clicked on progress bar.
146+
* Sets playback step.
147+
* @param {number} percent
149148
*/
150149
setProgress(percent) {
151150
const self = this;
152151
self._audioPlayer.currentTime = percent * self._audioPlayer.duration;
153152
}
154153

154+
/**
155+
* Either shuffles or unshuffles the playlist.
156+
* @param {Object} Main
157+
* @param {Object} UI
158+
*/
155159
toggleShuffle(Main, UI) {
156160
const self = this;
157161
if (self.isShuffled) {
@@ -161,6 +165,10 @@ module.exports = class Player {
161165
}
162166
}
163167

168+
/**
169+
* Actual shuffle algorythm.
170+
* @param {Array<Object>} files
171+
*/
164172
_shuffleFiles(files) {
165173
for (let i = files.length - 1; i > 0; i--) {
166174
const j = Math.floor(Math.random() * (i + 1));
@@ -169,6 +177,11 @@ module.exports = class Player {
169177
return files;
170178
}
171179

180+
/**
181+
* Shuffles the playlist.
182+
* @param {Object} Main
183+
* @param {Object} UI
184+
*/
172185
_shuffle(Main, UI) {
173186
const self = this;
174187

@@ -195,6 +208,10 @@ module.exports = class Player {
195208
self.isShuffled = true;
196209
}
197210

211+
/**
212+
* Restores original playlist order.
213+
* @param {Object} Main
214+
*/
198215
_unshuffle(Main) {
199216
const self = this;
200217
Main.files = Main.originalFiles;
@@ -210,6 +227,12 @@ module.exports = class Player {
210227
self.isShuffled = false;
211228
}
212229

230+
/**
231+
* Shuffles the playlist, but keeps currently playing song as head.
232+
* @param {Object} Main
233+
* @param {Object} UI
234+
* @param {string} path
235+
*/
213236
reshuffleOnClick(Main, UI, path) {
214237
const self = this;
215238

0 commit comments

Comments
 (0)