aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTakamichi Horikawa <takamichiho@gmail.com>2017-10-22 23:37:05 +0900
committerTakamichi Horikawa <takamichiho@gmail.com>2017-10-22 23:37:05 +0900
commitacb405ba36ec82511525f4f9e2a0775e2d85308e (patch)
tree6825ce49a631783b035b3613fa295d742e3254a2 /common
parentabba98ed83f59263c4b952d61ce9892f9270ee67 (diff)
Implemented filename and PCM filename display
Diffstat (limited to 'common')
-rw-r--r--common/fmplayer_file.c35
-rw-r--r--common/fmplayer_file.h10
-rw-r--r--common/fmplayer_file_gio.c32
-rw-r--r--common/fmplayer_file_win.c28
4 files changed, 88 insertions, 17 deletions
diff --git a/common/fmplayer_file.c b/common/fmplayer_file.c
index 3c05cab..ce7e1dc 100644
--- a/common/fmplayer_file.c
+++ b/common/fmplayer_file.c
@@ -5,6 +5,7 @@
void fmplayer_file_free(const struct fmplayer_file *fmfileptr) {
struct fmplayer_file *fmfile = (struct fmplayer_file *)fmfileptr;
if (!fmfile) return;
+ free((void *)fmfile->filename_sjis);
free(fmfile->path);
free(fmfile->buf);
free(fmfile->ppzbuf[0]);
@@ -109,6 +110,7 @@ struct fmplayer_file *fmplayer_file_alloc(const void *path, enum fmplayer_file_e
if (error) *error = FMPLAYER_FILE_ERR_NOMEM;
goto err;
}
+ fmfile->filename_sjis = fmplayer_path_filename_sjis(path);
size_t filesize;
fmfile->buf = fmplayer_fileread(path, 0, 0, 0xffff, &filesize, error);
if (!fmfile->buf) goto err;
@@ -139,17 +141,17 @@ static void loadppc(struct fmdriver_work *work, struct fmplayer_file *fmfile) {
}
}
-static bool loadppzpvi(struct fmdriver_work *work, struct fmplayer_file *fmfile, const char *name) {
+static bool loadppzpvi(struct fmdriver_work *work, struct fmplayer_file *fmfile, int bnum, const char *name) {
size_t filesize;
void *pvibuf = 0, *ppzbuf = 0;
pvibuf = fmplayer_fileread(fmfile->path, name, ".PVI", 0, &filesize, 0);
if (!pvibuf) goto err;
ppzbuf = calloc(ppz8_pvi_decodebuf_samples(filesize), 2);
if (!ppzbuf) goto err;
- if (!ppz8_pvi_load(work->ppz8, 0, pvibuf, filesize, ppzbuf)) goto err;
+ if (!ppz8_pvi_load(work->ppz8, bnum, pvibuf, filesize, ppzbuf)) goto err;
free(pvibuf);
- free(fmfile->ppzbuf[0]);
- fmfile->ppzbuf[0] = ppzbuf;
+ free(fmfile->ppzbuf[bnum]);
+ fmfile->ppzbuf[bnum] = ppzbuf;
return true;
err:
free(ppzbuf);
@@ -157,17 +159,17 @@ err:
return false;
}
-static bool loadppzpzi(struct fmdriver_work *work, struct fmplayer_file *fmfile, const char *name) {
+static bool loadppzpzi(struct fmdriver_work *work, struct fmplayer_file *fmfile, int bnum, const char *name) {
size_t filesize;
void *pzibuf = 0, *ppzbuf = 0;
pzibuf = fmplayer_fileread(fmfile->path, name, ".PZI", 0, &filesize, 0);
if (!pzibuf) goto err;
ppzbuf = calloc(ppz8_pzi_decodebuf_samples(filesize), 2);
if (!ppzbuf) goto err;
- if (!ppz8_pzi_load(work->ppz8, 0, pzibuf, filesize, ppzbuf)) goto err;
+ if (!ppz8_pzi_load(work->ppz8, bnum, pzibuf, filesize, ppzbuf)) goto err;
free(pzibuf);
- free(fmfile->ppzbuf[0]);
- fmfile->ppzbuf[0] = ppzbuf;
+ free(fmfile->ppzbuf[bnum]);
+ fmfile->ppzbuf[bnum] = ppzbuf;
return true;
err:
free(ppzbuf);
@@ -175,12 +177,13 @@ err:
return false;
}
-static void loadpmdppz(struct fmdriver_work *work, struct fmplayer_file *fmfile) {
- const char *ppzfile = fmfile->driver.pmd.ppzfile;
- if (!strlen(ppzfile)) return;
- if (!loadppzpvi(work, fmfile, ppzfile) && !loadppzpzi(work, fmfile, ppzfile)) {
- fmfile->pmd_ppz_err = true;
+// returns true if error
+static bool loadpmdppz(struct fmdriver_work *work, struct fmplayer_file *fmfile,int bnum, const char *ppzfile) {
+ if (!strlen(ppzfile)) false;
+ if (!loadppzpvi(work, fmfile, bnum, ppzfile) && !loadppzpzi(work, fmfile, bnum, ppzfile)) {
+ return true;
}
+ return false;
}
static void loadpvi(struct fmdriver_work *work, struct fmplayer_file *fmfile) {
@@ -199,7 +202,7 @@ static void loadpvi(struct fmdriver_work *work, struct fmplayer_file *fmfile) {
static void loadfmpppz(struct fmdriver_work *work, struct fmplayer_file *fmfile) {
const char *pvifile = fmfile->driver.fmp.ppz_name;
if (!strlen(pvifile)) return;
- fmfile->fmp_ppz_err = !loadppzpvi(work, fmfile, pvifile);
+ fmfile->fmp_ppz_err = !loadppzpvi(work, fmfile, 0, pvifile);
}
void fmplayer_file_load(struct fmdriver_work *work, struct fmplayer_file *fmfile, int loopcnt) {
@@ -219,9 +222,9 @@ void fmplayer_file_load(struct fmdriver_work *work, struct fmplayer_file *fmfile
}
pmd_init(work, &fmfile->driver.pmd);
loadppc(work, fmfile);
- loadpmdppz(work, fmfile);
+ work->pcmerror[1] = loadpmdppz(work, fmfile, 0, fmfile->driver.pmd.ppzfile);
+ work->pcmerror[2] = loadpmdppz(work, fmfile, 1, fmfile->driver.pmd.ppzfile2);
work->pcmerror[0] = fmfile->pmd_ppc_err;
- work->pcmerror[1] = fmfile->pmd_ppz_err;
break;
case FMPLAYER_FILE_TYPE_FMP:
{
diff --git a/common/fmplayer_file.h b/common/fmplayer_file.h
index 143c349..610a401 100644
--- a/common/fmplayer_file.h
+++ b/common/fmplayer_file.h
@@ -30,11 +30,15 @@ struct fmplayer_file {
struct driver_fmp fmp;
} driver;
bool pmd_ppc_err;
- bool pmd_ppz_err;
bool fmp_pvi_err;
bool fmp_ppz_err;
void *buf;
void *ppzbuf[2];
+ // for display with FMDSP
+ // might be NULL
+ // currently only supports sjis (CP932)
+ // string valid while file object valid
+ const char *filename_sjis;
};
struct fmplayer_file *fmplayer_file_alloc(const void *path, enum fmplayer_file_error *error);
void fmplayer_file_free(const struct fmplayer_file *fmfile);
@@ -49,6 +53,10 @@ const wchar_t *fmplayer_file_strerror_w(enum fmplayer_file_error error);
// fmplayer_fileread("/home/foo/bar.mz", "BAZ", ".PVI", &filesize);
void *fmplayer_fileread(const void *path, const char *pcmname, const char *extension, size_t maxsize, size_t *filesize, enum fmplayer_file_error *error);
+// allocates string in sjis
+// free with free()
+char *fmplayer_path_filename_sjis(const void *path);
+
void *fmplayer_path_dup(const void *path);
#endif // MYON_FMPLAYER_FILE_H_INCLUDED
diff --git a/common/fmplayer_file_gio.c b/common/fmplayer_file_gio.c
index a2b52d2..c690b15 100644
--- a/common/fmplayer_file_gio.c
+++ b/common/fmplayer_file_gio.c
@@ -1,5 +1,6 @@
#include "common/fmplayer_file.h"
#include <gio/gio.h>
+#include <glib.h>
#include <stdlib.h>
#include <string.h>
@@ -119,3 +120,34 @@ err:
void *fmplayer_path_dup(const void *path) {
return strdup(path);
}
+
+char *fmplayer_path_filename_sjis(const void *pathptr) {
+ const char *uri = pathptr;
+ GFile *file = 0;
+ GFileInfo *finfo = 0;
+ const char *filename = 0;
+ char *filenamesjis = 0, *filenamebuf = 0;
+ file = g_file_new_for_uri(uri);
+ if (!file) goto err;
+ finfo = g_file_query_info(
+ file,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ 0,
+ 0);
+ if (!finfo) goto err;
+ filename = g_file_info_get_attribute_string(
+ finfo, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+ filenamesjis = g_convert_with_fallback(
+ filename, -1,
+ "cp932", "utf-8", "?",
+ 0, 0, 0);
+ if (!filenamesjis) goto err;
+ filenamebuf = strdup(filenamesjis);
+err:
+ if (filenamesjis) g_free(filenamesjis);
+ if (finfo) g_object_unref(G_OBJECT(finfo));
+ if (file) g_object_unref(G_OBJECT(file));
+ return filenamebuf;
+}
+
diff --git a/common/fmplayer_file_win.c b/common/fmplayer_file_win.c
index 5ca57dc..71fb263 100644
--- a/common/fmplayer_file_win.c
+++ b/common/fmplayer_file_win.c
@@ -114,3 +114,31 @@ void *fmplayer_path_dup(const void *pathptr) {
return strdup(path);
#endif
}
+
+char *fmplayer_path_filename_sjis(const void *pathptr) {
+ wchar_t *u16_path = 0;
+ char *filename_sjis = 0;
+#if defined(FMPLAYER_FILE_WIN_UTF16)
+ const wchar_t *path = pathptr;
+ u16_path = wcsdup(path);
+#elif defined(FMPLAYER_FILE_WIN_UTF8)
+ const char *path = pathptr;
+ u16_path = u8tou16(path);
+#endif
+ if (!u16_path) goto err;
+ PathStripPath(u16_path);
+ int bufsize = WideCharToMultiByte(932, 0, u16_path, -1, 0, 0, 0, 0);
+ if (bufsize <= 0) goto err;
+ filename_sjis = malloc(bufsize);
+ if (!filename_sjis) goto err;
+ bufsize = WideCharToMultiByte(
+ 932, 0, u16_path, -1, filename_sjis, bufsize, 0, 0);
+ if (!bufsize) goto err;
+ free(u16_path);
+ return filename_sjis;
+
+err:
+ free(filename_sjis);
+ free(u16_path);
+ return 0;
+}