Skip to content

Commit

Permalink
updated functions to the ffmpeg version 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mjoelnir committed May 16, 2018
1 parent 67b53c3 commit 01b2a85
Show file tree
Hide file tree
Showing 19 changed files with 263 additions and 137 deletions.
13 changes: 8 additions & 5 deletions README
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
author: Torsten Lehmann
date: 2018-02-01
mail: [email protected]

GNU clapl
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/license/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

This is 'clapl'. (CommandLine AudioPlayer with Lyricsupport)

Author: Torsten Lehmann
Contact:[email protected]


###### CONTROLS #####

Keybindings are vim like:
vim-like keybindings
navigating artist and album via 'j' and 'k'
navigating tracks via 'n' (next) and 'b' (previous)
start playing: 'p' or 'ENTER'
Expand Down
3 changes: 0 additions & 3 deletions cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,10 @@ void cache_close (cache *c)
free(c->tracks);
}

/*
if (c->lyrics_path)
free(c->lyrics_path);
if (c->sorting)
free(c->sorting);
* are freed during the freeing process of the configparser
*/

if (c->commands)
c->commands = cmd_table_free(c->commands);
Expand Down
48 changes: 12 additions & 36 deletions clapl.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void load_config (configparser *cp)
{
// loading the configuration file
LOGGER_FILE = stdout;
chdir(getenv("HOME")); // goto /home/user/
chdir(getenv("HOME")); // goto the home directory

int ret = mkdir(".config/clapl", 0700); // create '.config/clapl/ if it does not exits
if (ret != 0 && ret != -1)
Expand All @@ -17,6 +17,7 @@ void load_config (configparser *cp)
if (ret != 0)
{
fprintf(stderr, "could not load config file\ncheck ~/.config/clapl/config");
free(cp);
exit(1);
}

Expand All @@ -29,67 +30,42 @@ void load_config (configparser *cp)
int main (int argc, char **argv)
{
srand(time(NULL));

configparser *cp = malloc(sizeof(configparser));
load_config(cp); // load config file
load_config(cp);

//LOGGER_PATH = ".config/clapl/log.txt";
LOGGER_PATH = configparser_get_string(cp, "log_file"); // set path for log file
LOGGER_FILE = fopen(LOGGER_PATH, "w"); // open log file
LOGGER_FILE = fopen(LOGGER_PATH, "w");

playback_init(); // initialize libav and libao
sqlite3 *db = db_init();
ui_init(); // initialize userinterface
userinterface *ui = ui_create(db, cp); // create userinterface
userinterface *ui = ui_create(db, cp);

ui->c->commands = load_commands();

audio *a = audio_create();
ui_print_info(ui, a); // prints infos of the currently playing track
ui_print_info(ui, a);
ui_refresh(ui);
pthread_t thread;

char ch;
char running = 1;
while (1)
{
ch = getch();
input(ui, ui->c, a, &thread, ch);
if (ch == 'q')
if (ch == 'q' || ch == 'Q')
break;
}
/*
while ((ch = getch()) != 'q') // main loop
input(ui, ui->c, a, &thread, ch);
*/

/*
cache_entry_load_album(ui->c);
cache_entry_load_tracks(ui->c);
*/
/*
input(ui, ui->c, a, &thread, 'p');
input(ui, ui->c, a, &thread, 'q');
char running = 1;
char ch;
while (running)
{
ch = getchar();
getchar();
if (ch == 'q')
running = 0;
input(ui, ui->c, a, &thread, ch);
}
*/


endwin(); // close ncurses
a = audio_destroy(a);
configparser_delete(cp);
audio_free(&a);
configparser_free(&cp);
cache_close(ui->c);
free(ui);
db_close(db);

fclose(LOGGER_FILE); // close log file
return 0;
fclose(LOGGER_FILE);
return EXIT_SUCCESS;
}

28 changes: 28 additions & 0 deletions clapl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
/*
* This file is part of clapl.
*
* clapl stands for Command Line Audio Player with Lyrics.
* It is a free audio player designed for terminal applications under unix systems.
*
* Copyright (C) 2018 Torsten Lehmann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should habe recieved a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/**
* @file clapl.h
* @author Torsten Lehmann
* @date 2018-05-06
* @brief file containing the headers for the main program
*/

#ifndef _CLAPL_H_
#define _CLAPL_H_
Expand Down
14 changes: 11 additions & 3 deletions cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ int cmd_load (cmd_arg *args)
int cmd_sorting (cmd_arg *args)
{
userinterface *ui = args[0].v;
ui->c->sorting = copy_string(args[1].s);
ui->c->selectedTrack = 0;
ui_print_track(ui);
if (strcmp(args[1].s, "number") == 0 || strcmp(args[1].s, "title") == 0)
{
free(ui->c->sorting);
ui->c->sorting = copy_string(args[1].s);
ui->c->selectedTrack = 0;
cache_entry_load_tracks(ui->c);
ui_print_track(ui);
ui_refresh(ui);
}

return 0;
}
4 changes: 4 additions & 0 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

cmd_table *load_commands (void);

/*
* functions return either 1 or 0
* the return determines if a redraw of the whole userinterface is neccessary
*/

int cmd_add (cmd_arg *args);
int cmd_seek (cmd_arg *args);
Expand Down
20 changes: 0 additions & 20 deletions commandparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@

#include "commandtable.h"

/*
typedef union
{
int i;
float f;
char c;
char *s;
} arg_t;
typedef struct
{
char *name;
void (*func)(arg_t *args);
char *args;
char *docs;
} cmd_t;
*/


void commandparser_parse (const cmd_table *command_list, char *command);

Expand Down
26 changes: 20 additions & 6 deletions configparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,20 @@ void configparser_init (configparser *const cp, char *const file, const int size
{
cp->file = fopen(file, "r"); // open file
if (! cp->file)
logcmd(LOG_ERROR_MALLOC, "configparser: configparser_init: could not malloc cp->file");
logcmd(LOG_ERROR_IO, "configparser: configparser_init: could not open config file (check ~/.config/clapl/config");

cp->delimiter = delimiter;
cp->ht = ht_create(size); // create hashtable
if (! cp->ht)
logcmd(LOG_ERROR_MALLOC, "configparser: configparser_init: hashtable could not be created");
}


configparser *configparser_delete (configparser *cp)
void configparser_free (configparser **cp)
{
cp->ht = ht_free(cp->ht);
free(cp);
return NULL;
ht_free(&(*cp)->ht);
free(*cp);
*cp = NULL;
}


Expand All @@ -71,6 +73,8 @@ void configparser_init_file (configparser *const cp, FILE *file, const int size,
cp->file = file;
cp->delimiter = delimiter;
cp->ht = ht_create(size);
if (! cp->ht)
logcmd(LOG_ERROR_MALLOC, "configparser: configparser_init: hashtable could not be created");
}


Expand Down Expand Up @@ -139,6 +143,16 @@ int configparser_get_int (configparser *const cp, char *const key)

char *configparser_get_string (configparser *const cp, char *const key)
{
return ht_get(cp->ht, key);
char *value = ht_get(cp->ht, key);
if (value)
{
// copies the string in to a new block of memory
// this way the configparser never looses its data due to unexpected memory frees
char *ptr = malloc(sizeof(char) * (strlen(value) + 1));
strcpy(ptr, value);
return ptr;
}

return NULL;
}

2 changes: 1 addition & 1 deletion configparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct


void configparser_init (configparser *const cp, char *const file, const int size, const char delimiter);
configparser *configparser_delete (configparser *cp);
void configparser_free (configparser **cp);

void configparser_init_file (configparser *const cp, FILE *file, const int size, const char delimiter);

Expand Down
33 changes: 22 additions & 11 deletions hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ hashtable *ht_create (const int size)
if (!ht)
return NULL;
if (!ht_init(ht, size))
{
free(ht);
return NULL;
}
else
return ht;
}
Expand All @@ -36,30 +39,38 @@ int ht_init (hashtable *const ht, const int size)
}


void remove_entry (ht_entry *e)
void ht_entry_free (ht_entry *e)
{
if (e->next)
remove_entry(e->next);
ht_entry_free(e->next);

if (e->key)
{
free(e->key);
e->key = NULL;
}
if (e->value)
{
free(e->value);
e->value = NULL;
}

free(e);
}


hashtable *ht_free (hashtable *ht)
void ht_free (hashtable **ht)
{
for (int i = 0; i < ht->size; i++)
{
ht_entry *e = ht->entries[i];
for (int i = 0; i < (*ht)->size; i++)
{
ht_entry *e = (*ht)->entries[i];
if (e)
remove_entry(e);
ht_entry_free(e);

}
free(ht->entries);
free(ht);
return NULL;
free((*ht)->entries);
free(*ht);
*ht = NULL;
}


Expand Down
16 changes: 13 additions & 3 deletions hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ typedef struct


hashtable *ht_create (const int size);

/**
* @func
* @param[in] size of the hashtable
*
* \return pointer to the hashtable, NULL on failure
*/

int ht_init (hashtable *const ht, const int size);
/**
Expand All @@ -35,8 +40,13 @@ int ht_init (hashtable *const ht, const int size);
* \return 1 on success, 0 on failure
*/


hashtable *ht_free (hashtable *ht);
void ht_free (hashtable **ht);
/**
* @func
* frees the hashtable and sets it's pointer to NULL
*
* @param[in] pointer to the pointer to a hashtable
*/


int ht_hash (hashtable *const ht, char *const key);
Expand Down
5 changes: 2 additions & 3 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ void parse_command (char *command, userinterface *ui, audio *a)
if (*command == '\0')
return;


char *token = strtok(command, " ");
cmd *c = cmd_table_get(ui->c->commands, token);
logcmd(LOG_MSG, "token = %s", token);
Expand All @@ -18,7 +17,6 @@ void parse_command (char *command, userinterface *ui, audio *a)
return;
}


cmd_arg *args = cmdparser_get_args(command, c->args);
if (strcmp(token, "seek") == 0)
args[0].v = a;
Expand Down Expand Up @@ -114,7 +112,8 @@ void input (userinterface *ui, cache *c, audio *a, pthread_t *thread, const char
if (ch != 'q' && a && (a->threadstate == THREADSTATE_RUNNING || a->threadstate == THREADSTATE_PAUSE))
{
int duration = a->pb->ctx->duration / AV_TIME_BASE;
int pos = av_frame_get_best_effort_timestamp(a->pb->frame) / a->pb->ctx->streams[0]->time_base.den;
int pos = a->pb->frame->best_effort_timestamp / a->pb->ctx->streams[0]->time_base.den;
//int pos = av_frame_get_best_effort_timestamp(a->pb->frame) / a->pb->ctx->streams[0]->time_base.den;
char *spos = input_get_time(pos);
char *sdur = input_get_time(duration);
mvprintw(3, 2, "%s | %s", spos, sdur);
Expand Down
Loading

0 comments on commit 01b2a85

Please sign in to comment.