mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-24 06:50:20 +01:00
cleanup: cli stuff
This commit is contained in:
parent
b9bea931a8
commit
9b81496c77
@ -3,6 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
#define POSIXLY_CORRECT
|
#define POSIXLY_CORRECT
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -458,41 +459,24 @@ static bool is_valid_extension(cli_config_t* cfg) {
|
|||||||
return vgmstream_ctx_is_valid(cfg->infilename, &vcfg);
|
return vgmstream_ctx_is_valid(cfg->infilename, &vcfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VGMSTREAM* open_vgmstream(cli_config_t* cfg) {
|
||||||
static bool convert_file(cli_config_t* cfg) {
|
STREAMFILE* sf = NULL;
|
||||||
VGMSTREAM* vgmstream = NULL;
|
VGMSTREAM* vgmstream = NULL;
|
||||||
char outfilename_temp[PATH_LIMIT];
|
|
||||||
int32_t len_samples;
|
|
||||||
|
|
||||||
|
sf = open_stdio_streamfile(cfg->infilename);
|
||||||
/* for plugin testing */
|
|
||||||
if (!is_valid_extension(cfg))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* open streamfile and pass subsong */
|
|
||||||
{
|
|
||||||
STREAMFILE* sf = open_stdio_streamfile(cfg->infilename);
|
|
||||||
if (!sf) {
|
if (!sf) {
|
||||||
fprintf(stderr, "file %s not found\n", cfg->infilename);
|
fprintf(stderr, "file %s not found\n", cfg->infilename);
|
||||||
goto fail;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sf->stream_index = cfg->subsong_index;
|
sf->stream_index = cfg->subsong_index;
|
||||||
vgmstream = init_vgmstream_from_STREAMFILE(sf);
|
vgmstream = init_vgmstream_from_STREAMFILE(sf);
|
||||||
close_streamfile(sf);
|
|
||||||
|
|
||||||
if (!vgmstream) {
|
if (!vgmstream) {
|
||||||
fprintf(stderr, "failed opening %s\n", cfg->infilename);
|
fprintf(stderr, "failed opening %s\n", cfg->infilename);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* force load total subsongs if signalled */
|
|
||||||
if (cfg->subsong_end == -1) {
|
|
||||||
cfg->subsong_end = vgmstream->num_streams;
|
|
||||||
close_vgmstream(vgmstream);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* modify the VGMSTREAM if needed (before printing file info) */
|
/* modify the VGMSTREAM if needed (before printing file info) */
|
||||||
apply_config(vgmstream, cfg);
|
apply_config(vgmstream, cfg);
|
||||||
|
|
||||||
@ -504,6 +488,35 @@ static bool convert_file(cli_config_t* cfg) {
|
|||||||
vgmstream_mixing_stereo_only(vgmstream, cfg->stereo_track - 1);
|
vgmstream_mixing_stereo_only(vgmstream, cfg->stereo_track - 1);
|
||||||
}
|
}
|
||||||
vgmstream_mixing_enable(vgmstream, cfg->sample_buffer_size, NULL, NULL);
|
vgmstream_mixing_enable(vgmstream, cfg->sample_buffer_size, NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
close_streamfile(sf);
|
||||||
|
return vgmstream;
|
||||||
|
fail:
|
||||||
|
close_streamfile(sf);
|
||||||
|
close_vgmstream(vgmstream);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool convert_file(cli_config_t* cfg) {
|
||||||
|
VGMSTREAM* vgmstream = NULL;
|
||||||
|
char outfilename_temp[CLI_PATH_LIMIT];
|
||||||
|
int32_t len_samples;
|
||||||
|
|
||||||
|
|
||||||
|
/* for plugin testing */
|
||||||
|
if (!is_valid_extension(cfg))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* open streamfile and pass subsong */
|
||||||
|
vgmstream = open_vgmstream(cfg);
|
||||||
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
|
/* force load total subsongs if signalled */
|
||||||
|
if (cfg->subsong_end == -1) {
|
||||||
|
cfg->subsong_end = vgmstream->num_streams;
|
||||||
|
close_vgmstream(vgmstream);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -593,7 +606,7 @@ static bool convert_file(cli_config_t* cfg) {
|
|||||||
/* try again with reset (for testing, simulates a seek to 0 after changing internal state)
|
/* try again with reset (for testing, simulates a seek to 0 after changing internal state)
|
||||||
* (could simulate by seeking to last sample then to 0, too) */
|
* (could simulate by seeking to last sample then to 0, too) */
|
||||||
if (cfg->test_reset) {
|
if (cfg->test_reset) {
|
||||||
char outfilename_reset[PATH_LIMIT];
|
char outfilename_reset[CLI_PATH_LIMIT];
|
||||||
snprintf(outfilename_reset, sizeof(outfilename_reset), "%s.reset.wav", cfg->outfilename);
|
snprintf(outfilename_reset, sizeof(outfilename_reset), "%s.reset.wav", cfg->outfilename);
|
||||||
|
|
||||||
cfg->outfilename = outfilename_reset;
|
cfg->outfilename = outfilename_reset;
|
||||||
@ -653,6 +666,9 @@ int main(int argc, char** argv) {
|
|||||||
bool res, ok;
|
bool res, ok;
|
||||||
|
|
||||||
|
|
||||||
|
vgmstream_set_log_stdout(VGM_LOG_LEVEL_ALL);
|
||||||
|
|
||||||
|
|
||||||
/* read args */
|
/* read args */
|
||||||
res = parse_config(&cfg, argc, argv);
|
res = parse_config(&cfg, argc, argv);
|
||||||
if (!res) goto fail;
|
if (!res) goto fail;
|
||||||
@ -660,8 +676,6 @@ int main(int argc, char** argv) {
|
|||||||
res = validate_config(&cfg);
|
res = validate_config(&cfg);
|
||||||
if (!res) goto fail;
|
if (!res) goto fail;
|
||||||
|
|
||||||
vgmstream_set_log_stdout(VGM_LOG_LEVEL_ALL);
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
/* make stdout output work with windows */
|
/* make stdout output work with windows */
|
||||||
if (cfg.play_sdtout) {
|
if (cfg.play_sdtout) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "../src/api.h"
|
#include "../src/api.h"
|
||||||
#include "../src/vgmstream.h"
|
#include "../src/vgmstream.h"
|
||||||
|
|
||||||
|
#define CLI_PATH_LIMIT 4096
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char** infilenames;
|
char** infilenames;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "vgmstream_cli.h"
|
#include <string.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "vgmstream_cli.h"
|
||||||
#include "../src/api.h"
|
#include "../src/api.h"
|
||||||
#include "../src/vgmstream.h"
|
#include "../src/vgmstream.h"
|
||||||
|
|
||||||
@ -23,9 +26,9 @@ static void clean_filename(char* dst, int clean_paths) {
|
|||||||
* ("?" was chosen since it's not a valid Windows filename char and hopefully nobody uses it on Linux) */
|
* ("?" was chosen since it's not a valid Windows filename char and hopefully nobody uses it on Linux) */
|
||||||
void replace_filename(char* dst, size_t dstsize, cli_config_t* cfg, VGMSTREAM* vgmstream) {
|
void replace_filename(char* dst, size_t dstsize, cli_config_t* cfg, VGMSTREAM* vgmstream) {
|
||||||
int subsong;
|
int subsong;
|
||||||
char stream_name[PATH_LIMIT];
|
char stream_name[CLI_PATH_LIMIT];
|
||||||
char buf[PATH_LIMIT];
|
char buf[CLI_PATH_LIMIT];
|
||||||
char tmp[PATH_LIMIT];
|
char tmp[CLI_PATH_LIMIT];
|
||||||
|
|
||||||
|
|
||||||
/* file has a "%" > temp replace for sprintf */
|
/* file has a "%" > temp replace for sprintf */
|
||||||
@ -100,29 +103,34 @@ void replace_filename(char* dst, size_t dstsize, cli_config_t* cfg, VGMSTREAM* v
|
|||||||
|
|
||||||
void print_info(VGMSTREAM* vgmstream, cli_config_t* cfg) {
|
void print_info(VGMSTREAM* vgmstream, cli_config_t* cfg) {
|
||||||
int channels = vgmstream->channels;
|
int channels = vgmstream->channels;
|
||||||
|
int64_t num_samples = vgmstream->num_samples;
|
||||||
|
bool loop_flag = vgmstream->loop_flag;
|
||||||
|
int64_t loop_start = vgmstream->loop_start_sample;
|
||||||
|
int64_t loop_end = vgmstream->loop_start_sample;
|
||||||
|
|
||||||
if (!cfg->play_sdtout) {
|
if (!cfg->play_sdtout) {
|
||||||
if (cfg->print_adxencd) {
|
if (cfg->print_adxencd) {
|
||||||
printf("adxencd");
|
printf("adxencd");
|
||||||
if (!cfg->print_metaonly)
|
if (!cfg->print_metaonly)
|
||||||
printf(" \"%s\"",cfg->outfilename);
|
printf(" \"%s\"", cfg->outfilename);
|
||||||
if (vgmstream->loop_flag)
|
if (loop_flag)
|
||||||
printf(" -lps%d -lpe%d", vgmstream->loop_start_sample, vgmstream->loop_end_sample);
|
printf(" -lps%"PRId64" -lpe%"PRId64, loop_start, loop_end);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
else if (cfg->print_oggenc) {
|
else if (cfg->print_oggenc) {
|
||||||
printf("oggenc");
|
printf("oggenc");
|
||||||
if (!cfg->print_metaonly)
|
if (!cfg->print_metaonly)
|
||||||
printf(" \"%s\"", cfg->outfilename);
|
printf(" \"%s\"", cfg->outfilename);
|
||||||
if (vgmstream->loop_flag)
|
if (loop_flag)
|
||||||
printf(" -c LOOPSTART=%d -c LOOPLENGTH=%d", vgmstream->loop_start_sample, vgmstream->loop_end_sample-vgmstream->loop_start_sample);
|
printf(" -c LOOPSTART=%"PRId64" -c LOOPLENGTH=%"PRId64, loop_start, loop_end - loop_start);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
else if (cfg->print_batchvar) {
|
else if (cfg->print_batchvar) {
|
||||||
if (!cfg->print_metaonly)
|
if (!cfg->print_metaonly)
|
||||||
printf("set fname=\"%s\"\n", cfg->outfilename);
|
printf("set fname=\"%s\"\n", cfg->outfilename);
|
||||||
printf("set tsamp=%d\nset chan=%d\n", vgmstream->num_samples, channels);
|
printf("set tsamp=%"PRId64"\nset chan=%d\n", num_samples, channels);
|
||||||
if (vgmstream->loop_flag)
|
if (loop_flag)
|
||||||
printf("set lstart=%d\nset lend=%d\nset loop=1\n", vgmstream->loop_start_sample, vgmstream->loop_end_sample);
|
printf("set lstart=%"PRId64"\nset lend=%"PRId64"\nset loop=1\n", loop_start, loop_end);
|
||||||
else
|
else
|
||||||
printf("set loop=0\n");
|
printf("set loop=0\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user