aboutsummaryrefslogtreecommitdiff
path: root/common/fmplayer_file.h
blob: 610a4017211d440ceadfd6c1dbccadb95be214f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef MYON_FMPLAYER_FILE_H_INCLUDED
#define MYON_FMPLAYER_FILE_H_INCLUDED

#include <stddef.h>
#include "fmdriver/fmdriver.h"
#include "fmdriver/fmdriver_pmd.h"
#include "fmdriver/fmdriver_fmp.h"
#include "libopna/opnadrum.h"

enum fmplayer_file_type {
  FMPLAYER_FILE_TYPE_PMD,
  FMPLAYER_FILE_TYPE_FMP
};

enum fmplayer_file_error {
  FMPLAYER_FILE_ERR_OK,
  FMPLAYER_FILE_ERR_NOMEM,
  FMPLAYER_FILE_ERR_FILEIO,
  FMPLAYER_FILE_ERR_BADFILE_SIZE,
  FMPLAYER_FILE_ERR_BADFILE,
  FMPLAYER_FILE_ERR_NOTFOUND,
  FMPLAYER_FILE_ERR_COUNT
};

struct fmplayer_file {
  void *path;
  enum fmplayer_file_type type;
  union {
    struct driver_pmd pmd;
    struct driver_fmp fmp;
  } driver;
  bool pmd_ppc_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);
void fmplayer_file_load(struct fmdriver_work *work, struct fmplayer_file *fmfile, int loopcnt);

const char *fmplayer_file_strerror(enum fmplayer_file_error error);
const wchar_t *fmplayer_file_strerror_w(enum fmplayer_file_error error);

// path: wchar_t* on windows, else char*
// examples:
//   fmplayer_fileread("/home/foo/bar.mz", 0, 0, &filesize); 
//   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