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’highlightis the variable which is limited. it keeps the index number of highligted song on the screengetMusicPhere is used to get the total number of music and getting the music filewindowis used to get the current height ofwindow[1].window[0]is the upper andwindow[1]is the lower windowmusicSDLholds the loaded music. So most of the SDL_mixer function is used using itvolumegets the current volumecurPlaying_musicholds the index number of music playing ofMUSIC_STRUCTelements(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)
compfnfunction is used insortList()function. it is a function not used in anywhere else thancompfn. it compares two string and helpqsortto sort thegetMusicP.
void sortList(getMusic_STRUCT* getMusicP)
sortLista function is used to sortgetMusicP
video.c
void printMusicList(WIN_STRUCT* window, getMusic_STRUCT* getMusicP,
int c, int* j, int* highlight, int* old_h1)
printMusicListfunction prints the list and display it inwindow[1]. It could simply print strings. But it converts it towchar_tjust 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)
printProgressbarprints 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