]> 4ch.mooo.com Git - 16.git/blob - 16/adplug/adplug-2.2.1/src/cmf.h
Please enter the commit message for your changes. Lines starting
[16.git] / 16 / adplug / adplug-2.2.1 / src / cmf.h
1 /*
2  * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3  * Copyright (C) 1999 - 2009 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * cmf.h - CMF player by Adam Nielsen <malvineous@shikadi.net>
20  */
21
22 #include <stdint.h> // for uintxx_t
23 #include "player.h"
24
25 typedef struct {
26         uint16_t iInstrumentBlockOffset;
27         uint16_t iMusicOffset;
28         uint16_t iTicksPerQuarterNote;
29         uint16_t iTicksPerSecond;
30         uint16_t iTagOffsetTitle;
31         uint16_t iTagOffsetComposer;
32         uint16_t iTagOffsetRemarks;
33         uint8_t iChannelsInUse[16];
34         uint16_t iNumInstruments;
35         uint16_t iTempo;
36 } CMFHEADER;
37
38 typedef struct {
39         uint8_t iCharMult;
40         uint8_t iScalingOutput;
41         uint8_t iAttackDecay;
42         uint8_t iSustainRelease;
43         uint8_t iWaveSel;
44 } OPERATOR;
45
46 typedef struct {
47         OPERATOR op[2]; // 0 == modulator, 1 == carrier
48         uint8_t iConnection;
49 } SBI;
50
51 typedef struct {
52         int iPatch; // MIDI patch for this channel
53         int iPitchbend; // Current pitchbend amount for this channel
54 } MIDICHANNEL;
55
56 typedef struct {
57         int iNoteStart;   // When the note started playing (longest notes get cut first, 0 == channel free)
58         int iMIDINote;    // MIDI note number currently being played on this OPL channel
59         int iMIDIChannel; // Source MIDI channel where this note came from
60         int iMIDIPatch;   // Current MIDI patch set on this OPL channel
61 } OPLCHANNEL;
62
63 class CcmfPlayer: public CPlayer
64 {
65         private:
66                 uint8_t *data; // song data (CMF music block)
67                 int iPlayPointer;               // Current location of playback pointer
68                 int iSongLen;       // Max value for iPlayPointer
69                 CMFHEADER cmfHeader;
70                 SBI *pInstruments;
71                 bool bPercussive; // are rhythm-mode instruments enabled?
72                 uint8_t iCurrentRegs[256]; // Current values in the OPL chip
73                 int iTranspose;  // Transpose amount for entire song (between -128 and +128)
74                 uint8_t iPrevCommand; // Previous command (used for repeated MIDI commands, as the seek and playback code need to share this)
75
76                 int iNoteCount;  // Used to count how long notes have been playing for
77                 MIDICHANNEL chMIDI[16];
78                 OPLCHANNEL chOPL[9];
79
80                 // Additions for AdPlug's design
81                 int iDelayRemaining;
82                 bool bSongEnd;
83                 std::string strTitle, strComposer, strRemarks;
84
85         public:
86                 static CPlayer *factory(Copl *newopl);
87
88                 CcmfPlayer(Copl *newopl);
89                 ~CcmfPlayer();
90
91                 bool load(const std::string &filename, const CFileProvider &fp);
92                 bool update();
93                 void rewind(int subsong);
94                 float getrefresh();
95
96                 std::string gettype()
97                         { return std::string("Creative Music File (CMF)"); };
98                 std::string gettitle();
99                 std::string getauthor();
100                 std::string getdesc();
101
102         protected:
103                 uint32_t readMIDINumber();
104                 void writeInstrumentSettings(uint8_t iChannel, uint8_t iOperatorSource, uint8_t iOperatorDest, uint8_t iInstrument);
105                 void writeOPL(uint8_t iRegister, uint8_t iValue);
106                 void cmfNoteOn(uint8_t iChannel, uint8_t iNote, uint8_t iVelocity);
107                 void cmfNoteOff(uint8_t iChannel, uint8_t iNote, uint8_t iVelocity);
108                 uint8_t getPercChannel(uint8_t iChannel);
109                 void MIDIchangeInstrument(uint8_t iOPLChannel, uint8_t iMIDIChannel, uint8_t iNewInstrument);
110                 void MIDIcontroller(uint8_t iChannel, uint8_t iController, uint8_t iValue);
111
112 };