yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
tracker.h
Go to the documentation of this file.
1#ifndef YAZE_APP_ZELDA3_TRACKER_H
2#define YAZE_APP_ZELDA3_TRACKER_H
3
4#include <vector>
5
6#include "rom/rom.h"
7#include "util/macro.h"
8
9namespace yaze {
10namespace zelda3 {
11
21namespace music {
22
23// Length of each SPC700 command opcode (0xE0-0xFF). Used for parsing.
24constexpr char op_len[32] = {1, 1, 2, 3, 0, 1, 2, 1, 2, 1, 1, 3, 0, 1, 2, 3,
25 1, 3, 3, 0, 1, 3, 0, 3, 3, 3, 1, 2, 0, 0, 0, 0};
26
27// Default ROM offsets for specific sound banks.
28static int sbank_ofs[] = {0xc8000, 0, 0xd8000, 0};
29
30// Filter coefficients for BRR sample decoding.
31constexpr char fil1[4] = {0, 15, 61, 115};
32constexpr char fil2[4] = {0, 4, 5, 6};
33constexpr char fil3[4] = {0, 0, 15, 13};
34
35constexpr int kOverworldMusicBank = 0x0D0000;
36constexpr int kDungeonMusicBank = 0x0D8000;
37
38using text_buf_ty = char[512];
39
46 unsigned short start; // The starting address of this block in the virtual
47 // SPC memory space.
48 unsigned short len; // Length of the data buffer.
49 unsigned short relnum; // Number of relocation entries.
50 unsigned short relsz; // Allocated size of the relocation table.
51 unsigned short* relocs; // Table of offsets within 'buf' that are pointers
52 // and need to be relocated.
53 unsigned short bank; // The target sound bank.
54 unsigned short addr; // The final, relocated address of this block.
55 unsigned char* buf; // The raw binary data for this block.
56 int flag; // Flags for managing the block's state.
57};
58
64struct SongRange {
65 unsigned short start; // Start address of this range in the ROM.
66 unsigned short end; // End address of this range in the ROM.
67
68 short first; // Index of the first SpcCommand in this range.
69 short inst; // Instance count, for tracking usage.
70 short bank; // The ROM bank this range was loaded from.
71
72 unsigned char endtime; // Default time/duration for this block.
73 unsigned char filler;
74
75 int editor; // Window handle for an associated editor, if any.
76};
77
82struct SongPart {
83 uint8_t flag; // State flags for parsing and saving.
84 uint8_t inst; // Instance count.
85 short tbl[8]; // Pointers to the first SpcCommand for each of the 8 channels.
86 unsigned short addr; // The address of this part's data in the ROM.
87};
88
93struct Song {
94 unsigned char flag; // State flags.
95 unsigned char inst; // Instance count.
96 SongPart** tbl; // Table of pointers to the song's parts.
97 short numparts; // Number of parts in the song.
98 short lopst; // Loop start point.
99 unsigned short addr; // Address of the song's main data table in the ROM.
100 bool in_use; // Flag indicating if the song is currently loaded.
101};
102
107struct ZeldaWave {
108 int lopst; // Loop start point within the sample data.
109 int end; // End of the sample data.
110 short lflag; // Loop flag.
111 short copy; // Index of another wave this is a copy of, to save memory.
112 short* buf; // The buffer containing the decoded PCM sample data.
113};
114
120 unsigned short flag;
121 unsigned short init;
122 unsigned short editsamp;
123 int width;
125 int pageh;
126 int pagev;
127 int zoom;
129 int page;
130
132 int sell;
133
135 int selr;
136
138
140};
141
148 unsigned char samp; // Index of the sample (ZeldaWave) to use.
149 unsigned char ad; // Attack & Decay rates.
150 unsigned char sr; // Sustain Rate.
151 unsigned char gain; // Sustain Level & Gain.
152 unsigned char multhi; // Pitch multiplier (high byte).
153 unsigned char multlo; // Pitch multiplier (low byte).
154};
155
161 unsigned char voll;
162 unsigned char volr;
163 short freq;
164 unsigned char samp;
165 unsigned char ad;
166 unsigned char sr;
167 unsigned char gain;
168 unsigned char multhi;
169};
170
177 unsigned short addr; // The ROM address this command was loaded from.
178 short next; // Index of the next command in the list.
179 short prev; // Index of the previous command in the list.
180 unsigned char flag; // Bitfield for command properties (e.g., has duration).
181 unsigned char cmd; // The actual command/opcode.
182 unsigned char p1; // Parameter 1.
183 unsigned char p2; // Parameter 2.
184 unsigned char p3; // Parameter 3.
185 unsigned char b1; // Note duration or first byte of a multi-byte duration.
186 unsigned char b2; // Second byte of a multi-byte duration.
187 unsigned char tim2; // Calculated time/duration component.
188 unsigned short tim; // Calculated time/duration component.
189};
190
191class Tracker {
192 public:
193 SongSpcBlock* AllocSpcBlock(int len, int bank);
194
195 unsigned char* GetSpcAddr(Rom& rom, unsigned short addr, short bank);
196
197 short AllocSpcCommand();
198
199 short GetBlockTime(Rom& rom, short num, short prevtime);
200
201 short SaveSpcCommand(Rom& rom, short num, short songtime, short endtr);
202 short LoadSpcCommand(Rom& rom, unsigned short addr, short bank, int t);
203
204 void SaveSongs(Rom& rom);
205
206 void LoadSongs(Rom& rom);
207
208 int WriteSpcData(Rom& rom, void* buf, int len, int addr, int spc, int limit);
209
210 void EditTrack(Rom& rom, short i);
211
212 void NewSR(Rom& rom, int bank);
213
214 private:
215 // A "modified" flag
216 int modf;
217
219
224
228
229 int sndinit = 0;
230
233 int m_ofs;
235
238
239 char op_len[32];
240
241 char* snddat1;
242 char* snddat2; // more music stuff.
243
244 unsigned short ss_next = 0;
245 unsigned short spclen;
246 unsigned short numseg;
247
248 short spcbank;
249 short lastsr;
251 short srnum;
252 short srsize;
253 short numsong[3]; // ditto
254 short m_size;
255 short m_free;
256 short m_modf; // ???
257 short m_loaded;
258
259 short t_loaded;
260 short t_modf;
261 short withhead;
262
263 size_t t_number;
264
265 std::vector<Song> songs;
269
270 const SpcCommand& GetSpcCommand(short index) const {
271 return current_spc_command_[index];
272 }
273
275
279};
280
281} // namespace music
282} // namespace zelda3
283} // namespace yaze
284
285#endif
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:24
void EditTrack(Rom &rom, short i)
Opens an editor window for a specific track. (Legacy UI-related function)
Definition tracker.cc:1375
unsigned char * GetSpcAddr(Rom &rom, unsigned short addr, short bank)
Gets a direct pointer to music data within the ROM. This function is critical for parsing....
Definition tracker.cc:75
short AllocSpcCommand()
Allocates a new SpcCommand from a pre-allocated pool. This uses a classic free-list implementation fo...
Definition tracker.cc:115
SongSpcBlock * AllocSpcBlock(int len, int bank)
Allocates a new SongSpcBlock for holding generated SPC data. These blocks are the building blocks for...
Definition tracker.cc:42
void SaveSongs(Rom &rom)
High-level function to save all modified song data back to the ROM. (Currently commented out,...
Definition tracker.cc:919
short LoadSpcCommand(Rom &rom, unsigned short addr, short bank, int t)
Loads a block of music data from a given ROM address. This is the main parser. It reads the raw byte ...
Definition tracker.cc:258
short GetBlockTime(Rom &rom, short num, short prevtime)
Calculates the total time (duration) of a block of SpcCommands. This is essential for synchronization...
Definition tracker.cc:151
int WriteSpcData(Rom &rom, void *buf, int len, int addr, int spc, int limit)
Writes a prepared data block into the ROM file. This is a utility for SaveSongs, formatting the data ...
Definition tracker.cc:881
short SaveSpcCommand(Rom &rom, short num, short songtime, short endtr)
Saves a block of edited SpcCommands back into a binary format. This is the serializer,...
Definition tracker.cc:731
ZeldaSfxInstrument * sndinsts
Definition tracker.h:278
std::vector< Song > songs
Definition tracker.h:265
void NewSR(Rom &rom, int bank)
Creates a new, empty song range (SongRange) and opens it for editing. (Legacy UI-related function)
Definition tracker.cc:1432
SpcCommand * current_spc_command_
Definition tracker.h:268
void LoadSongs(Rom &rom)
High-level function to load all song data from the ROM. (Currently commented out, but this would be t...
Definition tracker.cc:451
const SpcCommand & GetSpcCommand(short index) const
Definition tracker.h:270
ZeldaInstrument * insts
Definition tracker.h:277
SongSpcBlock ** ssblt
Definition tracker.h:274
constexpr char fil3[4]
Definition tracker.h:33
constexpr char fil1[4]
Definition tracker.h:31
constexpr int kOverworldMusicBank
Definition tracker.h:35
constexpr char fil2[4]
Definition tracker.h:32
constexpr char op_len[32]
Definition tracker.h:24
char[512] text_buf_ty
Definition tracker.h:38
constexpr int kDungeonMusicBank
Definition tracker.h:36
A state structure for a GUI sample editor.
Definition tracker.h:119
int selr
Right hand sample selection point.
Definition tracker.h:135
int sell
Left hand sample selection point.
Definition tracker.h:132
Represents one of the 8 channels (tracks) in a song.
Definition tracker.h:82
A metadata structure to keep track of parsed sections of the song data. Used to avoid re-parsing the ...
Definition tracker.h:64
Represents a block of binary data destined for the APU (SPC700) RAM. This is the intermediate format ...
Definition tracker.h:45
Represents a complete song, which is a collection of SongParts.
Definition tracker.h:93
unsigned char flag
Definition tracker.h:94
unsigned char inst
Definition tracker.h:95
unsigned short addr
Definition tracker.h:99
The core data structure representing a single command in a music track. A song track is a doubly-link...
Definition tracker.h:176
Defines an instrument for a song, mapping to a sample and ADSR settings.
Definition tracker.h:147
Defines an instrument for a sound effect.
Definition tracker.h:160
Represents a decoded instrument sample (a waveform).
Definition tracker.h:107