Skip to content

Commit

Permalink
Reconcile branches
Browse files Browse the repository at this point in the history
* cmus/master (cmus/cmus@23afab3)
* gavtroy/flat-library-view (gavtroy/cmus@7697e0a)
  • Loading branch information
pgaskin committed Nov 5, 2023
3 parents 45a5045 + 23afab3 + 7697e0a commit 2c5aafc
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 66 deletions.
16 changes: 11 additions & 5 deletions Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ and can be controlled externally using *cmus-remote*(1).
NOTE: Don't use this option to run multiple instances as the same user.
Doing so would corrupt the track metadata cache.

--passwd PASSWD
Set the password for TCP/IP connections. Required if listening on
host[:port]. Used in conjunction with --listen.

--plugins
List available plugins and exit.

Expand Down Expand Up @@ -498,13 +502,15 @@ mark <filter-expression>
mute
Toggles mute for the sound output.

passwd <password>
Set the password for TCP/IP connections. Required for connections if
bound to an IP address (see `--listen`).

pl-create <name>
Creates a new playlist.

pl-delete [-a] <name>
Deletes the playlist with the given name.

-a
Deletes all playlists

pl-export <filename>
Exports the currently selected playlist. The file will be overwritten if
it exists.
Expand Down Expand Up @@ -1334,8 +1340,8 @@ Special Keys:
%A %{albumartist} @br
%l %{album} @br
%D %{discnumber} @br
%T %{totaldiscs} @br
%n %{tracknumber} @br
%N %{albumtracks} @br
%X %{play_count} @br
%t %{title} @br
%g %{genre} @br
Expand Down
10 changes: 10 additions & 0 deletions command_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,15 @@ static void cmd_pl_rename(char *arg)
info_msg(":pl-rename only works in view 3");
}

static void cmd_pl_delete(char *arg)
{
int flag = parse_flags((const char **)&arg, "a");
if (flag == 'a')
pl_delete_all();
else
pl_delete_by_name(arg);
}

static void cmd_version(char *arg)
{
info_msg(VERSION);
Expand Down Expand Up @@ -2645,6 +2654,7 @@ struct command commands[] = {
{ "pl-export", cmd_pl_export, 1, -1, NULL, 0, 0 },
{ "pl-import", cmd_pl_import, 0, -1, NULL, 0, 0 },
{ "pl-rename", cmd_pl_rename, 1, -1, NULL, 0, 0 },
{ "pl-delete", cmd_pl_delete, 1, 1, NULL, 0, 0 },
{ "push", cmd_push, 0, -1, expand_commands, 0, 0 },
{ "pwd", cmd_pwd, 0, 0, NULL, 0, 0 },
{ "raise-vte", cmd_raise_vte, 0, 0, NULL, 0, 0 },
Expand Down
3 changes: 2 additions & 1 deletion comment.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int comments_get_date(const struct keyval *comments, const char *key)
}

static const char *interesting[] = {
"artist", "album", "title", "tracknumber", "discnumber", "genre",
"artist", "album", "title", "tracknumber", "discnumber", "totaldiscs", "genre",
"date", "compilation", "partofacompilation", "albumartist", "artistsort", "albumartistsort",
"albumsort",
"originaldate",
Expand All @@ -221,6 +221,7 @@ static struct {
{ "album_artist", "albumartist" },
{ "album artist", "albumartist" },
{ "disc", "discnumber" },
{ "dicstotal", "totaldiscs" },
{ "tempo", "bpm" },
{ "track", "tracknumber" },
{ "WM/Year", "date" },
Expand Down
62 changes: 51 additions & 11 deletions cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
struct cue_track_proto {
struct list_head node;

char *file;
uint32_t nr;
int32_t pregap;
int32_t postgap;
Expand All @@ -42,12 +43,18 @@ struct cue_track_proto {
struct cue_meta meta;
};

struct cue_track_file {
struct list_head node;

char *file;
};

struct cue_parser {
const char *src;
size_t len;
bool err;

char *file;
struct list_head files;
struct list_head tracks;
size_t num_tracks;

Expand Down Expand Up @@ -196,11 +203,33 @@ CUE_PARSE_STR(discnumber);

static void cue_parse_file(struct cue_parser *p)
{
cue_parse_str(p, &p->file);
struct cue_track_file *f = xnew(struct cue_track_file, 1);

f->file = NULL;
cue_parse_str(p, &f->file);

list_add_tail(&f->node, &p->files);
}

static char* cue_dup_current_file(struct cue_parser *p)
{
if (list_empty(&p->files))
return NULL;

struct list_head *tail = list_prev(&p->files);
char* file = list_entry(tail, struct cue_track_file, node)->file;
return cue_strdup(file, strlen(file));
}

static void cue_parse_track(struct cue_parser *p)
{
char *curr_file = cue_dup_current_file(p);

if (!curr_file) {
cue_set_err(p);
return;
}

const char *nr;
size_t len = cue_extract_token(p, &nr);

Expand All @@ -215,6 +244,7 @@ static void cue_parse_track(struct cue_parser *p)
.postgap = -1,
.index0 = -1,
.index1 = -1,
.file = curr_file,
};

list_add_tail(&t->node, &p->tracks);
Expand Down Expand Up @@ -346,7 +376,7 @@ static void cue_parse_line(struct cue_parser *p)

static void cue_post_process(struct cue_parser *p)
{
if (!p->file || p->num_tracks == 0) {
if (list_empty(&p->files) || p->num_tracks == 0) {
cue_set_err(p);
return;
}
Expand All @@ -364,6 +394,7 @@ static void cue_post_process(struct cue_parser *p)
}

last = -1;
char *last_file = NULL;

list_for_each_entry(t, &p->tracks, node) {
if (t->index0 == -1 && t->index1 == -1) {
Expand All @@ -377,12 +408,13 @@ static void cue_post_process(struct cue_parser *p)
else
t->index1 = t->index0 + pregap;
}
if (last != -1 && t->index0 < last) {
if (last != -1 && (t->file == last_file && t->index0 < last)) {
cue_set_err(p);
return;
}
int32_t postgap = t->postgap != -1 ? t->postgap : 0;
last = t->index1 + postgap;
last_file = t->file;
}
}

Expand All @@ -396,9 +428,6 @@ static struct cue_sheet *cue_parser_to_sheet(struct cue_parser *p)
{
struct cue_sheet *s = xnew(struct cue_sheet, 1);

s->file = p->file;
p->file = NULL;

s->tracks = xnew(struct cue_track, p->num_tracks);
s->num_tracks = p->num_tracks;
s->track_base = cue_last_proto(p)->nr + 1 - p->num_tracks;
Expand All @@ -408,6 +437,9 @@ static struct cue_sheet *cue_parser_to_sheet(struct cue_parser *p)
size_t idx = 0;
struct cue_track_proto *t, *prev;
list_for_each_entry(t, &p->tracks, node) {
s->tracks[idx].file = t->file;
t->file = NULL;

s->tracks[idx].offset = t->index1 / 75.0;
s->tracks[idx].length = -1;

Expand Down Expand Up @@ -440,12 +472,19 @@ static void cue_meta_free(struct cue_meta *m)
static void cue_parser_free(struct cue_parser *p)
{
struct cue_track_proto *t, *next;
struct cue_track_file *tf, *nexttf;

list_for_each_entry_safe(tf, nexttf, &p->files, node) {
free(tf->file);
free(tf);
}

list_for_each_entry_safe(t, next, &p->tracks, node) {
cue_meta_free(&t->meta);
free(t->file);
free(t);
}

free(p->file);
cue_meta_free(&p->meta);
}

Expand All @@ -458,6 +497,7 @@ struct cue_sheet *cue_parse(const char *src, size_t len)
.len = len,
};
list_init(&p.tracks);
list_init(&p.files);

while (p.len > 0 && !p.err)
cue_parse_line(&p);
Expand Down Expand Up @@ -498,10 +538,10 @@ struct cue_sheet *cue_from_file(const char *file)

void cue_free(struct cue_sheet *s)
{
free(s->file);

for (size_t i = 0; i < s->num_tracks; i++)
for (size_t i = 0; i < s->num_tracks; i++) {
cue_meta_free(&s->tracks[i].meta);
free(s->tracks[i].file);
}
free(s->tracks);

cue_meta_free(&s->meta);
Expand Down
3 changes: 1 addition & 2 deletions cue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ struct cue_meta {
};

struct cue_track {
char *file;
double offset;
double length;
struct cue_meta meta;
};

struct cue_sheet {
char *file;

struct cue_track *tracks;
size_t num_tracks;
size_t track_base;
Expand Down
11 changes: 1 addition & 10 deletions format_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,12 @@ static void print_num(int num)

#define DBL_MAX_LEN (20)

static int format_double(char *buf, int buflen, double num)
{
int l = snprintf(buf, buflen, "%f", num);
/* skip trailing zeros */
while (l > 0 && buf[l-1] == '0')
l--;
return l;
}

static void print_double(double num)
{
char stack[DBL_MAX_LEN], b[DBL_MAX_LEN];
int i, p = 0;

i = format_double(b, DBL_MAX_LEN, num) - 1;
i = snprintf(b, DBL_MAX_LEN, "%g", num) - 1;
while (i >= 0) {
stack[p++] = b[i];
i--;
Expand Down
5 changes: 3 additions & 2 deletions gbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ static int gbuf_mark_clipped_text(struct gbuf *buf)

void gbuf_add_ustr(struct gbuf *buf, const char *src, int *width)
{
gbuf_grow(buf, strlen(src));
int src_bytes = u_str_print_size(src) - 1;
gbuf_grow(buf, src_bytes);
size_t copy_bytes = u_copy_chars(buf->buffer + buf->len, src, width);
gbuf_used(buf, copy_bytes);
if (src[copy_bytes] != '\0') {
if (copy_bytes != src_bytes) {
gbuf_set(buf, ' ', *width);
*width = gbuf_mark_clipped_text(buf);
}
Expand Down
2 changes: 1 addition & 1 deletion ip/cue.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static int cue_open(struct input_plugin_data *ip_data)
goto cue_read_failed;
}

child_filename = _make_absolute_path(priv->cue_filename, cd->file);
child_filename = _make_absolute_path(priv->cue_filename, t->file);
priv->child = ip_new(child_filename);
free(child_filename);

Expand Down
27 changes: 22 additions & 5 deletions ip/ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct ffmpeg_output {
struct ffmpeg_private {
AVCodecContext *codec_context;
AVFormatContext *input_context;
AVCodec *codec;
AVCodec const *codec;
SwrContext *swr;

struct ffmpeg_input *input;
Expand Down Expand Up @@ -141,8 +141,7 @@ static int ffmpeg_open(struct input_plugin_data *ip_data)
int err = 0;
int i;
int stream_index = -1;
int64_t channel_layout = 0;
AVCodec *codec;
AVCodec const *codec;
AVCodecContext *cc = NULL;
AVFormatContext *ic = NULL;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
Expand Down Expand Up @@ -239,15 +238,26 @@ static int ffmpeg_open(struct input_plugin_data *ip_data)

/* Prepare for resampling. */
swr = swr_alloc();
#if LIBAVCODEC_VERSION_MAJOR >= 58
if (cc->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
av_channel_layout_default(&cc->ch_layout, cc->ch_layout.nb_channels);
av_opt_set_chlayout(swr, "in_chlayout", &cc->ch_layout, 0);
av_opt_set_chlayout(swr, "out_chlayout", &cc->ch_layout, 0);
#else
av_opt_set_int(swr, "in_channel_layout", av_get_default_channel_layout(cc->channels), 0);
av_opt_set_int(swr, "out_channel_layout", av_get_default_channel_layout(cc->channels), 0);
#endif
av_opt_set_int(swr, "in_sample_rate", cc->sample_rate, 0);
av_opt_set_int(swr, "out_sample_rate", cc->sample_rate, 0);
av_opt_set_sample_fmt(swr, "in_sample_fmt", cc->sample_fmt, 0);
priv->swr = swr;

ip_data->private = priv;
#if LIBAVCODEC_VERSION_MAJOR >= 58
ip_data->sf = sf_rate(cc->sample_rate) | sf_channels(cc->ch_layout.nb_channels);
#else
ip_data->sf = sf_rate(cc->sample_rate) | sf_channels(cc->channels);
#endif
switch (cc->sample_fmt) {
case AV_SAMPLE_FMT_U8:
ip_data->sf |= sf_bits(8) | sf_signed(0);
Expand All @@ -265,8 +275,11 @@ static int ffmpeg_open(struct input_plugin_data *ip_data)
}
swr_init(swr);
ip_data->sf |= sf_host_endian();
channel_layout = cc->channel_layout;
channel_map_init_waveex(cc->channels, channel_layout, ip_data->channel_map);
#if LIBAVCODEC_VERSION_MAJOR >= 58
channel_map_init_waveex(cc->ch_layout.nb_channels, cc->ch_layout.u.mask, ip_data->channel_map);
#else
channel_map_init_waveex(cc->channels, cc->channel_layout, ip_data->channel_map);
#endif
return 0;
}

Expand Down Expand Up @@ -378,7 +391,11 @@ static int ffmpeg_fill_buffer(AVFormatContext *ic, AVCodecContext *cc, struct ff
if (res < 0)
res = 0;
output->buffer_pos = output->buffer;
#if LIBAVCODEC_VERSION_MAJOR >= 58
output->buffer_used_len = res * cc->ch_layout.nb_channels * sizeof(int16_t);
#else
output->buffer_used_len = res * cc->channels * sizeof(int16_t);
#endif
#if LIBAVCODEC_VERSION_MAJOR >= 56
av_frame_free(&frame);
#else
Expand Down
2 changes: 1 addition & 1 deletion lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static void hash_add_to_views(void)
while (e) {
struct track_info *ti = e->ti;

if (!is_filtered(ti))
if (!is_filtered(ti) && !(ignore_duplicates && track_exists(ti)))
views_add_track(ti);
e = e->next;
}
Expand Down
1 change: 0 additions & 1 deletion lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ struct album {
int date;
/* min date of the tracks added to this album */
int min_date;
int num_tracks;
};

struct artist {
Expand Down
Loading

0 comments on commit 2c5aafc

Please sign in to comment.