/*
- * Copyright (C) 2007-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2009 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
#include "vss.h"
#include "fd.h"
#include "ipc.h"
+#include "portable_io.h"
static struct osl_table *audio_file_table;
unsigned short duration_width;
/** size of the num played field. */
unsigned short num_played_width;
+ /** size of the amp field. */
+ unsigned short amp_width;
};
/** Data passed from the ls command handler to its callback function. */
static int save_afd(struct audio_file_data *afd)
{
size_t size = sizeof(*afd) + sizeof_chunk_table(&afd->afhi);
-
- PARA_DEBUG_LOG("size: %zu\n", size);
int shmid, ret = shm_new(size);
void *shm_afd;
char *buf;
#define GET_NUM_DIGITS(x, num) { \
typeof((x)) _tmp = PARA_ABS(x); \
*num = 1; \
- if ((x)) \
+ if ((_tmp)) \
while ((_tmp) > 9) { \
(_tmp) /= 10; \
(*num)++; \
ret = para_printf(b,
"%s" /* score */
"%s " /* attributes */
+ "%*u " /* amp */
"%*d " /* image_id */
"%*d " /* lyrics_id */
"%*d " /* bitrate */
"%s\n", /* path */
score_buf,
att_buf,
+ w->amp_width, afsi->amp,
w->image_id_width, afsi->image_id,
w->lyrics_id_width, afsi->lyrics_id,
w->bitrate_width, afhi->bitrate,
"%s: %lu\n" /* seconds total */
"%s: %s\n" /* last played time */
"%s: %d\n" /* num_played */
+ "%s: %u\n" /* ampplification */
"%s" /* tag info */
"%s: %lu\n" /* chunk time */
"%s: %lu\n", /* num chunks */
status_item_list[SI_SECONDS_TOTAL], afhi->seconds_total,
status_item_list[SI_LAST_PLAYED], last_played_time,
status_item_list[SI_NUM_PLAYED], afsi->num_played,
+ status_item_list[SI_AMPLIFICATION], afsi->amp,
afhi->info_string,
status_item_list[SI_CHUNK_TIME], tv2ms(&afhi->chunk_tv),
status_item_list[SI_NUM_CHUNKS], afhi->chunks_total
return ret;
}
+/**
+ * Write a list of audio-file related status items with empty values.
+ *
+ * \param buf Result pointer.
+ *
+ * This is used by vss when currently no audio file is open.
+ */
void make_empty_status_items(char *buf)
{
sprintf(buf,
"%s: \n" /* seconds total */
"%s: \n" /* num played */
"%s: \n" /* last played */
+ "%s: \n" /* audio file info */
+ "%s: \n" /* taginfo1 */
+ "%s: \n" /* taginfo2 */
+ "%s: \n" /* amplification */
,
status_item_list[SI_PATH],
status_item_list[SI_DIRECTORY],
status_item_list[SI_DURATION],
status_item_list[SI_SECONDS_TOTAL],
status_item_list[SI_NUM_PLAYED],
- status_item_list[SI_LAST_PLAYED]
+ status_item_list[SI_LAST_PLAYED],
+ status_item_list[SI_AUDIO_FILE_INFO],
+ status_item_list[SI_TAGINFO1],
+ status_item_list[SI_TAGINFO2],
+ status_item_list[SI_AMPLIFICATION]
);
}
GET_NUM_DIGITS(d->afsi.num_played, &num_digits);
w->num_played_width = PARA_MAX(w->num_played_width, num_digits);
/* get the number of chars to print this amount of time */
- tmp = get_duration_width(d->afhi.seconds_total);
- w->duration_width = PARA_MAX(w->duration_width, tmp);
+ num_digits = get_duration_width(d->afhi.seconds_total);
+ w->duration_width = PARA_MAX(w->duration_width, num_digits);
+ GET_NUM_DIGITS(d->afsi.amp, &num_digits);
+ w->amp_width = PARA_MAX(w->amp_width, num_digits);
if (options->flags & LS_FLAG_ADMISSIBLE_ONLY) {
GET_NUM_DIGITS(score, &num_digits);
num_digits++; /* add one for the sign (space or "-") */
prepare_ls_row);
if (ret < 0)
goto out;
- ret = opts->num_patterns? -E_NO_MATCH : 0;
if (!opts->num_matching_paths)
goto out;
ret = sort_matching_paths(opts);
struct afs_info default_afsi = {.last_played = 0};
struct para_buffer msg = {.max_size = SHMMAX,
.max_size_handler = pass_buffer_as_shm, .private_data = &fd};
+ uint16_t afhi_offset, chunks_offset;
hash = (HASH_TYPE *)buf + CAB_HASH_OFFSET;
hash_to_asc(hash, asc);;
goto out;
}
/* no hs or force mode, child must have sent afhi */
- uint16_t afhi_offset = read_u16(buf + CAB_AFHI_OFFSET_POS);
- uint16_t chunks_offset = read_u16(buf + CAB_CHUNKS_OFFSET_POS);
+ afhi_offset = read_u16(buf + CAB_AFHI_OFFSET_POS);
+ chunks_offset = read_u16(buf + CAB_CHUNKS_OFFSET_POS);
objs[AFTCOL_AFHI].data = buf + afhi_offset;
objs[AFTCOL_AFHI].size = chunks_offset - afhi_offset;
afs_event(AUDIO_FILE_ADD, &msg, aft_row);
out:
if (ret < 0)
- ret = para_printf(&msg, "%s\n", para_strerror(-ret));
+ para_printf(&msg, "%s\n", para_strerror(-ret));
if (msg.offset)
pass_buffer_as_shm(msg.buf, msg.offset, &fd);
free(msg.buf);
afhi_ptr = &afhi;
}
munmap(map.data, map.size);
+ close(fd);
if (pad->flags & ADD_FLAG_VERBOSE) {
send_ret = send_va_buffer(pad->fd, "adding %s\n", path);
if (send_ret < 0)
int32_t num_played;
/** New last played count. */
int64_t last_played;
- /** new lyrics id. */
+ /** New lyrics id. */
int32_t lyrics_id;
- /** new image id. */
+ /** New image id. */
int32_t image_id;
- /** command line flags (see \ref touch_flags). */
+ /** New amplification value. */
+ int32_t amp;
+ /** Command line flags (see \ref touch_flags). */
unsigned flags;
};
struct osl_object obj;
struct afs_info old_afsi, new_afsi;
int ret, no_options = tad->cto->num_played < 0 && tad->cto->last_played < 0 &&
- tad->cto->lyrics_id < 0 && tad->cto->image_id < 0;
+ tad->cto->lyrics_id < 0 && tad->cto->image_id < 0 && tad->cto->amp < 0;
struct afsi_change_event_data aced;
ret = get_afsi_object_of_row(row, &obj);
new_afsi.num_played = tad->cto->num_played;
if (tad->cto->last_played >= 0)
new_afsi.last_played = tad->cto->last_played;
+ if (tad->cto->amp >= 0)
+ new_afsi.amp = tad->cto->amp;
}
tad->num_matches++;
save_afsi(&new_afsi, &obj); /* in-place update */
.num_played = -1,
.last_played = -1,
.lyrics_id = -1,
- .image_id = -1
+ .image_id = -1,
+ .amp = -1,
};
struct osl_object query = {.data = &cto, .size = sizeof(cto)};
int i, ret;
return ret;
continue;
}
+ if (!strncmp(arg, "-a", 2)) {
+ int32_t val;
+ ret = para_atoi32(arg + 2, &val);
+ if (ret < 0)
+ return ret;
+ if (val < 0 || val > 255)
+ return -ERRNO_TO_PARA_ERROR(EINVAL);
+ cto.amp = val;
+ continue;
+ }
if (!strcmp(arg, "-p")) {
cto.flags |= TOUCH_FLAG_FNM_PATHNAME;
continue;
struct osl_row *row, const char *name, void *data)
{
struct com_rm_action_data *crd = data;
- int ret, ret2;
+ int ret;
if (crd->flags & RM_FLAG_VERBOSE) {
ret = para_printf(&crd->pb, "removing %s\n", name);
afs_event(AUDIO_FILE_REMOVE, &crd->pb, row);
ret = osl_del_row(audio_file_table, row);
if (ret < 0)
- ret2 = para_printf(&crd->pb, "%s: %s\n", name,
- para_strerror(-ret));
+ para_printf(&crd->pb, "%s: %s\n", name, para_strerror(-ret));
else
crd->num_removed++;
return ret;
pmd.fnmatch_flags |= FNM_PATHNAME;
ret = for_each_matching_row(&pmd);
if (ret < 0) {
- ret = para_printf(&crd.pb, "%s\n", para_strerror(-ret));
+ para_printf(&crd.pb, "%s\n", para_strerror(-ret));
return;
}
if (!crd.num_removed && !(crd.flags & RM_FLAG_FORCE))
};
int ret;
char *source_path = (char *)query->data + sizeof(cad.flags);
-
- ret = get_afsi_of_path(source_path, &cad.source_afsi);
- if (ret < 0)
- goto out;
struct pattern_match_data pmd = {
.table = audio_file_table,
.loop_col_num = AFTCOL_HASH,
.data = &cad,
.action = copy_selector_info
};
+
+ ret = get_afsi_of_path(source_path, &cad.source_afsi);
+ if (ret < 0)
+ goto out;
ret = for_each_matching_row(&pmd);
out:
if (ret < 0)
- ret = para_printf(&cad.pb, "%s\n", para_strerror(-ret));
+ para_printf(&cad.pb, "%s\n", para_strerror(-ret));
else if (cad.flags & CPSI_FLAG_VERBOSE) {
if (cad.num_copied)
- ret = para_printf(&cad.pb, "copied requested afsi from %s "
- "to %u files\n",
- source_path, cad.num_copied);
+ para_printf(&cad.pb, "copied requested afsi from %s "
+ "to %u files\n", source_path, cad.num_copied);
else
- ret = para_printf(&cad.pb, "nothing copied\n");
+ para_printf(&cad.pb, "nothing copied\n");
}
if (cad.pb.offset)
pass_buffer_as_shm(cad.pb.buf, cad.pb.offset, &fd);