mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-28 00:20:47 +01:00
cleanup: cli stuff
This commit is contained in:
parent
b9bea931a8
commit
9b81496c77
@ -3,6 +3,7 @@
|
||||
*/
|
||||
#define POSIXLY_CORRECT
|
||||
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#ifdef WIN32
|
||||
@ -458,41 +459,24 @@ static bool is_valid_extension(cli_config_t* cfg) {
|
||||
return vgmstream_ctx_is_valid(cfg->infilename, &vcfg);
|
||||
}
|
||||
|
||||
|
||||
static bool convert_file(cli_config_t* cfg) {
|
||||
static VGMSTREAM* open_vgmstream(cli_config_t* cfg) {
|
||||
STREAMFILE* sf = NULL;
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
char outfilename_temp[PATH_LIMIT];
|
||||
int32_t len_samples;
|
||||
|
||||
|
||||
/* for plugin testing */
|
||||
if (!is_valid_extension(cfg))
|
||||
return false;
|
||||
|
||||
/* open streamfile and pass subsong */
|
||||
{
|
||||
STREAMFILE* sf = open_stdio_streamfile(cfg->infilename);
|
||||
sf = open_stdio_streamfile(cfg->infilename);
|
||||
if (!sf) {
|
||||
fprintf(stderr, "file %s not found\n", cfg->infilename);
|
||||
goto fail;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sf->stream_index = cfg->subsong_index;
|
||||
vgmstream = init_vgmstream_from_STREAMFILE(sf);
|
||||
close_streamfile(sf);
|
||||
|
||||
if (!vgmstream) {
|
||||
fprintf(stderr, "failed opening %s\n", cfg->infilename);
|
||||
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) */
|
||||
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_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)
|
||||
* (could simulate by seeking to last sample then to 0, too) */
|
||||
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);
|
||||
|
||||
cfg->outfilename = outfilename_reset;
|
||||
@ -653,6 +666,9 @@ int main(int argc, char** argv) {
|
||||
bool res, ok;
|
||||
|
||||
|
||||
vgmstream_set_log_stdout(VGM_LOG_LEVEL_ALL);
|
||||
|
||||
|
||||
/* read args */
|
||||
res = parse_config(&cfg, argc, argv);
|
||||
if (!res) goto fail;
|
||||
@ -660,8 +676,6 @@ int main(int argc, char** argv) {
|
||||
res = validate_config(&cfg);
|
||||
if (!res) goto fail;
|
||||
|
||||
vgmstream_set_log_stdout(VGM_LOG_LEVEL_ALL);
|
||||
|
||||
#ifdef WIN32
|
||||
/* make stdout output work with windows */
|
||||
if (cfg.play_sdtout) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "../src/api.h"
|
||||
#include "../src/vgmstream.h"
|
||||
|
||||
#define CLI_PATH_LIMIT 4096
|
||||
|
||||
typedef struct {
|
||||
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/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) */
|
||||
void replace_filename(char* dst, size_t dstsize, cli_config_t* cfg, VGMSTREAM* vgmstream) {
|
||||
int subsong;
|
||||
char stream_name[PATH_LIMIT];
|
||||
char buf[PATH_LIMIT];
|
||||
char tmp[PATH_LIMIT];
|
||||
char stream_name[CLI_PATH_LIMIT];
|
||||
char buf[CLI_PATH_LIMIT];
|
||||
char tmp[CLI_PATH_LIMIT];
|
||||
|
||||
|
||||
/* 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) {
|
||||
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->print_adxencd) {
|
||||
printf("adxencd");
|
||||
if (!cfg->print_metaonly)
|
||||
printf(" \"%s\"",cfg->outfilename);
|
||||
if (vgmstream->loop_flag)
|
||||
printf(" -lps%d -lpe%d", vgmstream->loop_start_sample, vgmstream->loop_end_sample);
|
||||
printf(" \"%s\"", cfg->outfilename);
|
||||
if (loop_flag)
|
||||
printf(" -lps%"PRId64" -lpe%"PRId64, loop_start, loop_end);
|
||||
printf("\n");
|
||||
}
|
||||
else if (cfg->print_oggenc) {
|
||||
printf("oggenc");
|
||||
if (!cfg->print_metaonly)
|
||||
printf(" \"%s\"", cfg->outfilename);
|
||||
if (vgmstream->loop_flag)
|
||||
printf(" -c LOOPSTART=%d -c LOOPLENGTH=%d", vgmstream->loop_start_sample, vgmstream->loop_end_sample-vgmstream->loop_start_sample);
|
||||
if (loop_flag)
|
||||
printf(" -c LOOPSTART=%"PRId64" -c LOOPLENGTH=%"PRId64, loop_start, loop_end - loop_start);
|
||||
printf("\n");
|
||||
}
|
||||
else if (cfg->print_batchvar) {
|
||||
if (!cfg->print_metaonly)
|
||||
printf("set fname=\"%s\"\n", cfg->outfilename);
|
||||
printf("set tsamp=%d\nset chan=%d\n", vgmstream->num_samples, channels);
|
||||
if (vgmstream->loop_flag)
|
||||
printf("set lstart=%d\nset lend=%d\nset loop=1\n", vgmstream->loop_start_sample, vgmstream->loop_end_sample);
|
||||
printf("set tsamp=%"PRId64"\nset chan=%d\n", num_samples, channels);
|
||||
if (loop_flag)
|
||||
printf("set lstart=%"PRId64"\nset lend=%"PRId64"\nset loop=1\n", loop_start, loop_end);
|
||||
else
|
||||
printf("set loop=0\n");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user