https://github.com/8amiul/termus
Video Demo: https://youtu.be/GzHTSfeRQZU
Description:
Termus is a terminal based music player written in C using SDL_mixer and ncurses library.
Files:
main.c
: initialize libraries and functions are calledtermus.c
: Manage keystrokes, free up memory and helping functionsfile.c
: Manages directories, scan music and prepares music files for playingvideo.c
: Functions regarding displaying windows and playing musictermes.h
: A header file containing functon declaration and structs
Used Libraries
SDL2 & SDL2_mixer
: SDL2_mixer is used for audio and music managementncurses
: For displaying windows and text
Functions
termus.c
void controls(int c, int *highlight, int* j, getMusic_STRUCT* getMusicP,
WIN_STRUCT* window, Mix_Music** musicSDL, int* volume, int* curPlaying_music)
c
: takes user key press. every key input is saved in ‘c’highlight
is the variable which is limited. it keeps the index number of highligted song on the screengetMusicP
here is used to get the total number of music and getting the music filewindow
is used to get the current height ofwindow[1]
.window[0]
is the upper andwindow[1]
is the lower windowmusicSDL
holds the loaded music. So most of the SDL_mixer function is used using itvolume
gets the current volumecurPlaying_music
holds the index number of music playing ofMUSIC_STRUCT
elements(getMusicP->mus[*curPlaying_music].path)
void freeTermus(getMusic_STRUCT* getMusicP)
- freeTerumus function frees all the allocated memory using malloc. Most of the work is connected with
getMusic_STRUCT
int compfn(const void* m1, const void* m2)
compfn
function is used insortList()
function. it is a function not used in anywhere else thancompfn
. it compares two string and helpqsort
to sort thegetMusicP
.
void sortList(getMusic_STRUCT* getMusicP)
sortList
a function is used to sortgetMusicP
video.c
void printMusicList(WIN_STRUCT* window, getMusic_STRUCT* getMusicP,
int c, int* j, int* highlight, int* old_h1)
printMusicList
function prints the list and display it inwindow[1]
. It could simply print strings. But it converts it towchar_t
just to print wide characters. It wrap text so changing display size would wrap those lines which are larger then screen size.
void playbackDuration(WIN_STRUCT* window, Mix_Music* musicSDL)
- It prints the progress time and duration in
window[0]
.
void printProgressbar(WIN_STRUCT* window, Mix_Music* musicSDL)
printProgressbar
prints the progress bar inwindow[0]
.
void display(WIN_STRUCT* window, getMusic_STRUCT* getMusicP, Mix_Music* musicSDL)
- main loop for display and run operate video and music task
WIN_STRUCT* initScreen()
- initialize curses and return
WIN_STRUCT*
file.c
getMusic_STRUCT* getMusic(void)
- getMusic function gets all the information needed for loading music
int getDIR(char** listDIR)
- this function read config file for directories or check the program arguments
void concat(char* dir, char* musicFile, char* path)
- Merging music file with the path so that it can be used while loading music
int scanMusic(char** DIRs, int totalDIR, MUSIC_STRUCT* music)
- scan for music files on directories
How to use this program?
First it has to compile for the system. using make
this program can be compiled on linux.
For windows SDL2 library and ncurses is necessary for compiling. One can provide directories to scan by giving it to the program argument or putting it in
termus.conf
file. After that running that program will start the program and a menu should be visible.
Known bugs/Todo
- Resizing terminal the selection bar goes out of the screen.
- On windows resizing terminal breaks the screen.
- Volume isn’t capped at 100