LMMS
Loading...
Searching...
No Matches
mus.h
Go to the documentation of this file.
1/*
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2005 Simon Peter <dn.tlp@gmx.net>, et al.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * mus.h - AdLib MIDI Music File Player by Stas'M <binarymaster@mail.ru>
20 *
21 * Based on PLAY.C by Marc Savary, Ad Lib Inc.
22 *
23 * REFERENCES:
24 * http://www.shikadi.net/moddingwiki/AdLib_MIDI_Format
25 * http://www.shikadi.net/moddingwiki/IMS_Format
26 * http://www.shikadi.net/moddingwiki/AdLib_Timbre_Bank_Format
27 * http://www.shikadi.net/moddingwiki/AdLib_Instrument_Bank_Format
28 * http://www.vgmpf.com/Wiki/index.php?title=MUS_(AdLib)
29 * http://www.vgmpf.com/Wiki/index.php?title=SND_(AdLib)
30 */
31
32#ifndef H_ADPLUG_MUSPLAYER
33#define H_ADPLUG_MUSPLAYER
34
35#include "player.h"
36#include "adlib.h"
37
38#define SYSTEM_XOR_BYTE 0xF0
39#define EOX_BYTE 0xF7
40#define OVERFLOW_BYTE 0xF8
41#define STOP_BYTE 0xFC
42
43#define NOTE_OFF_BYTE 0x80
44#define NOTE_ON_BYTE 0x90
45#define AFTER_TOUCH_BYTE 0xA0
46#define CONTROL_CHANGE_BYTE 0xB0
47#define PROG_CHANGE_BYTE 0xC0
48#define CHANNEL_PRESSURE_BYTE 0xD0
49#define PITCH_BEND_BYTE 0xE0
50
51#define ADLIB_CTRL_BYTE 0x7F /* for System exclusive */
52#define TEMPO_CTRL_BYTE 0
53
54#define TUNE_NAME_SIZE 30
55#define FILLER_SIZE 8
56#define TIMBRE_NAME_SIZE 9
57#define TIMBRE_DEF_LEN ADLIB_INST_LEN
58#define TIMBRE_DEF_SIZE (TIMBRE_DEF_LEN * sizeof(int16_t))
59#define OVERFLOW_TICKS 240
60#define MAX_SEC_DELAY 10.0f /* Wraithverge: changed this to float, to avoid casting */
61#define HEADER_LEN 70
62#define SND_HEADER_LEN 6
63#define IMS_SIGNATURE 0x7777
64
65#define BNK_HEADER_SIZE 28
66#define BNK_SIGNATURE_LEN 6
67#define BNK_NAME_SIZE 12
68#define BNK_INST_SIZE 30
69
70class CmusPlayer: public CPlayer
71{
72public:
73 static CPlayer *factory(Copl *newopl);
74
76 : CPlayer(newopl), data(0), insts(0)
77 { }
79 {
80 if (data) delete [] data;
81 if (insts) delete[] insts;
82 if (drv) drv->~CadlibDriver();
83 };
84
85 bool load(const std::string &filename, const CFileProvider &fp);
86 bool update();
87 void rewind(int subsong);
88
89 float getrefresh()
90 {
91 return timer;
92 };
93
94 std::string gettitle()
95 {
96 return std::string(tuneName);
97 };
98
99 std::string gettype();
100
101 unsigned int getinstruments()
102 {
103 return insts ? nrTimbre : 0;
104 };
105
106 std::string getinstrument(unsigned int n)
107 {
108 return insts && n < nrTimbre ? (insts[n].loaded ? std::string(insts[n].name) : std::string("[N/A] ").append(insts[n].name)) : std::string();
109 };
110
111private:
112 bool InstsLoaded();
113 bool LoadTimbreBank(const std::string fname, const CFileProvider &fp);
114 bool FetchTimbreData(const std::string fname, const CFileProvider &fp);
115 void SetTempo(uint16_t tempo, uint8_t tickBeat);
117 void executeCommand();
119
120protected:
121 /* variables for playback */
122 unsigned long pos;
124 float timer;
125
126 uint32_t counter; /* tick counter */
127 uint32_t ticks; /* ticks to wait for next event */
128 uint8_t status; /* running status byte */
129 uint8_t volume[MAX_VOICES]; /* actual volume of all voices */
130
131 /* header variables of .MUS file */
137 uint8_t soundMode; /* 0: melodic, 1: percussive */
138 uint8_t pitchBRange; /* 1 - 12 */
140
141 uint8_t * data; /* MIDI data */
142 bool isIMS; /* play as IMS format */
143
144 /* variables for timbre bank */
150
151 uint16_t nrTimbre; /* # of definitions in bank. */
152 mus_inst * insts; /* instrument definitions */
153};
154
155#endif
#define MAX_VOICES
Definition adlib.h:72
Definition fprovide.h:29
CPlayer(Copl *newopl)
Definition player.cpp:34
Definition adlib.h:92
std::string gettype()
Definition mus.cpp:48
uint8_t pitchBRange
Definition mus.h:138
uint32_t counter
Definition mus.h:126
bool songend
Definition mus.h:123
uint8_t majorVersion
Definition mus.h:132
uint16_t nrTimbre
Definition mus.h:151
uint8_t volume[MAX_VOICES]
Definition mus.h:129
~CmusPlayer()
Definition mus.h:78
CadlibDriver * drv
Definition mus.h:118
uint8_t tickBeat
Definition mus.h:135
void executeCommand()
Definition mus.cpp:437
static CPlayer * factory(Copl *newopl)
Definition mus.cpp:43
bool LoadTimbreBank(const std::string fname, const CFileProvider &fp)
Definition mus.cpp:235
void SetTempo(uint16_t tempo, uint8_t tickBeat)
Definition mus.cpp:411
uint32_t ticks
Definition mus.h:127
std::string gettitle()
Definition mus.h:94
uint8_t status
Definition mus.h:128
unsigned int getinstruments()
Definition mus.h:101
bool update()
Definition mus.cpp:575
mus_inst * insts
Definition mus.h:152
void rewind(int subsong)
Definition mus.cpp:392
unsigned long pos
Definition mus.h:122
bool load(const std::string &filename, const CFileProvider &fp)
Definition mus.cpp:59
bool isIMS
Definition mus.h:142
std::string getinstrument(unsigned int n)
Definition mus.h:106
char tuneName[TUNE_NAME_SIZE]
Definition mus.h:134
uint32_t GetTicks()
Definition mus.cpp:417
float timer
Definition mus.h:124
uint32_t dataSize
Definition mus.h:136
float getrefresh()
Definition mus.h:89
uint8_t * data
Definition mus.h:141
bool FetchTimbreData(const std::string fname, const CFileProvider &fp)
Definition mus.cpp:287
uint8_t minorVersion
Definition mus.h:133
uint16_t basicTempo
Definition mus.h:139
uint8_t soundMode
Definition mus.h:137
bool InstsLoaded()
Definition mus.cpp:226
CmusPlayer(Copl *newopl)
Definition mus.h:75
Definition opl.h:26
static char filename[]
Definition features.c:5
static const char * name
Definition pugl.h:1582
unsigned short uint16_t
Definition mid.cpp:99
unsigned int uint32_t
Definition mid.cpp:100
short int16_t
Definition mid.cpp:96
unsigned char uint8_t
Definition mid.cpp:98
#define TUNE_NAME_SIZE
Definition mus.h:54
#define TIMBRE_DEF_LEN
Definition mus.h:57
#define TIMBRE_NAME_SIZE
Definition mus.h:56
Definition mus.h:145
bool loaded
Definition mus.h:147
int16_t data[TIMBRE_DEF_LEN]
Definition mus.h:148
char name[TIMBRE_NAME_SIZE]
Definition mus.h:146
int n
Definition crypt.c:458