Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>. |
||
3 | * It is copyright by its individual contributors, as recorded in the |
||
4 | * project's Git history. See COPYING.txt at the top level for license |
||
5 | * terms and a link to the Git history. |
||
6 | */ |
||
7 | #ifndef __HMP_H |
||
8 | #define __HMP_H |
||
9 | |||
10 | #include <memory> |
||
11 | #include <vector> |
||
12 | #ifdef _WIN32 |
||
13 | #include <windows.h> |
||
14 | #include <mmsystem.h> |
||
15 | #endif |
||
16 | #include "physfsx.h" |
||
17 | |||
18 | #ifdef __cplusplus |
||
19 | namespace dcx { |
||
20 | |||
21 | #define HMP_TRACKS 32 |
||
22 | #ifdef _WIN32 |
||
23 | #define MIDI_VOLUME_SCALE 128 |
||
24 | #define HMP_BUFFERS 4 |
||
25 | #define HMP_BUFSIZE 1024 |
||
26 | #define HMP_INVALID_FILE -1 |
||
27 | #define HMP_OUT_OF_MEM -2 |
||
28 | #define HMP_MM_ERR -3 |
||
29 | #define HMP_EOF 1 |
||
30 | |||
31 | #define MIDI_CONTROL_CHANGE 0xB |
||
32 | #define MIDI_PROGRAM_CHANGE 0xC |
||
33 | |||
34 | #define MIDI_BANK_SELECT_MSB 0x00 |
||
35 | #define MIDI_BANK_SELECT_LSB 0x20 |
||
36 | #define MIDI_VOLUME 0x07 |
||
37 | #define MIDI_PANPOT 0x0A |
||
38 | #define MIDI_REVERB 0x5B |
||
39 | #define MIDI_CHORUS 0x5D |
||
40 | #define MIDI_ALL_SOUNDS_OFF 0x78 |
||
41 | #define MIDI_RESET_ALL_CONTROLLERS 0x79 |
||
42 | #define MIDI_ALL_NOTES_OFF 0x7B |
||
43 | |||
44 | #define HMP_LOOP_START 0x6E |
||
45 | #define HMP_LOOP_END 0x6F |
||
46 | #endif |
||
47 | |||
48 | #ifdef _WIN32 |
||
49 | struct event |
||
50 | { |
||
51 | unsigned int delta; |
||
52 | unsigned char msg[3]; |
||
53 | unsigned char *data; |
||
54 | unsigned int datalen; |
||
55 | }; |
||
56 | #endif |
||
57 | |||
58 | struct hmp_track |
||
59 | { |
||
60 | std::unique_ptr<uint8_t[]> data; |
||
61 | unsigned char *loop; |
||
62 | unsigned int len; |
||
63 | unsigned char *cur; |
||
64 | unsigned int left; |
||
65 | unsigned int cur_time; |
||
66 | unsigned int loop_start; |
||
67 | int loop_set; |
||
68 | }; |
||
69 | |||
70 | struct hmp_file |
||
71 | { |
||
72 | ~hmp_file(); |
||
73 | PHYSFS_sint64 filesize; |
||
74 | int num_trks; |
||
75 | std::array<hmp_track, HMP_TRACKS> trks; |
||
76 | unsigned int cur_time; |
||
77 | unsigned int loop_start; |
||
78 | unsigned int loop_end; |
||
79 | int looping; |
||
80 | int tempo; |
||
81 | #ifdef _WIN32 |
||
82 | MIDIHDR *evbuf; |
||
83 | HMIDISTRM hmidi; |
||
84 | UINT devid; |
||
85 | #endif |
||
86 | unsigned char *pending; |
||
87 | unsigned int pending_size; |
||
88 | unsigned int pending_event; |
||
89 | int stop; |
||
90 | int bufs_in_mm; |
||
91 | int bLoop; |
||
92 | unsigned int midi_division; |
||
93 | }; |
||
94 | |||
95 | std::unique_ptr<hmp_file> hmp_open(const char *filename); |
||
96 | void hmp2mid(const char *hmp_name, std::vector<uint8_t> &midbuf); |
||
97 | #ifdef _WIN32 |
||
98 | void hmp_setvolume(hmp_file *hmp, int volume); |
||
99 | int hmp_play(hmp_file *hmp, int bLoop); |
||
100 | void hmp_pause(hmp_file *hmp); |
||
101 | void hmp_resume(hmp_file *hmp); |
||
102 | void hmp_reset(); |
||
103 | #endif |
||
104 | |||
105 | } |
||
106 | #endif |
||
107 | |||
108 | #endif |