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 "app/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 SPC memory space.
47 unsigned short len; // Length of the data buffer.
48 unsigned short relnum; // Number of relocation entries.
49 unsigned short relsz; // Allocated size of the relocation table.
50 unsigned short *relocs; // Table of offsets within 'buf' that are pointers and need to be relocated.
51 unsigned short bank; // The target sound bank.
52 unsigned short addr; // The final, relocated address of this block.
53 unsigned char *buf; // The raw binary data for this block.
54 int flag; // Flags for managing the block's state.
55};
56
62struct SongRange {
63 unsigned short start; // Start address of this range in the ROM.
64 unsigned short end; // End address of this range in the ROM.
65
66 short first; // Index of the first SpcCommand in this range.
67 short inst; // Instance count, for tracking usage.
68 short bank; // The ROM bank this range was loaded from.
69
70 unsigned char endtime; // Default time/duration for this block.
71 unsigned char filler;
72
73 int editor; // Window handle for an associated editor, if any.
74};
75
80struct SongPart {
81 uint8_t flag; // State flags for parsing and saving.
82 uint8_t inst; // Instance count.
83 short tbl[8]; // Pointers to the first SpcCommand for each of the 8 channels.
84 unsigned short addr; // The address of this part's data in the ROM.
85};
86
91struct Song {
92 unsigned char flag; // State flags.
93 unsigned char inst; // Instance count.
94 SongPart **tbl; // Table of pointers to the song's parts.
95 short numparts; // Number of parts in the song.
96 short lopst; // Loop start point.
97 unsigned short addr; // Address of the song's main data table in the ROM.
98 bool in_use; // Flag indicating if the song is currently loaded.
99};
100
105struct ZeldaWave {
106 int lopst; // Loop start point within the sample data.
107 int end; // End of the sample data.
108 short lflag; // Loop flag.
109 short copy; // Index of another wave this is a copy of, to save memory.
110 short *buf; // The buffer containing the decoded PCM sample data.
111};
112
118 unsigned short flag;
119 unsigned short init;
120 unsigned short editsamp;
121 int width;
123 int pageh;
124 int pagev;
125 int zoom;
127 int page;
128
130 int sell;
131
133 int selr;
134
136
138};
139
145 unsigned char samp; // Index of the sample (ZeldaWave) to use.
146 unsigned char ad; // Attack & Decay rates.
147 unsigned char sr; // Sustain Rate.
148 unsigned char gain; // Sustain Level & Gain.
149 unsigned char multhi; // Pitch multiplier (high byte).
150 unsigned char multlo; // Pitch multiplier (low byte).
151};
152
158 unsigned char voll;
159 unsigned char volr;
160 short freq;
161 unsigned char samp;
162 unsigned char ad;
163 unsigned char sr;
164 unsigned char gain;
165 unsigned char multhi;
166};
167
174 unsigned short addr; // The ROM address this command was loaded from.
175 short next; // Index of the next command in the list.
176 short prev; // Index of the previous command in the list.
177 unsigned char flag; // Bitfield for command properties (e.g., has duration).
178 unsigned char cmd; // The actual command/opcode.
179 unsigned char p1; // Parameter 1.
180 unsigned char p2; // Parameter 2.
181 unsigned char p3; // Parameter 3.
182 unsigned char b1; // Note duration or first byte of a multi-byte duration.
183 unsigned char b2; // Second byte of a multi-byte duration.
184 unsigned char tim2; // Calculated time/duration component.
185 unsigned short tim; // Calculated time/duration component.
186};
187
188class Tracker {
189 public:
190
191 SongSpcBlock *AllocSpcBlock(int len, int bank);
192
193 unsigned char *GetSpcAddr(Rom &rom, unsigned short addr, short bank);
194
195 short AllocSpcCommand();
196
197 short GetBlockTime(Rom &rom, short num, short prevtime);
198
199 short SaveSpcCommand(Rom &rom, short num, short songtime, short endtr);
200 short LoadSpcCommand(Rom &rom, unsigned short addr, short bank, int t);
201
202 void SaveSongs(Rom &rom);
203
204 void LoadSongs(Rom &rom);
205
206 int WriteSpcData(Rom &rom, void *buf, int len, int addr, int spc, int limit);
207
208 void EditTrack(Rom &rom, short i);
209
210 void NewSR(Rom &rom, int bank);
211
212 private:
213 // A "modified" flag
214 int modf;
215
217
222
226
227 int sndinit = 0;
228
231 int m_ofs;
233
236
237 char op_len[32];
238
239 char *snddat1;
240 char *snddat2; // more music stuff.
241
242 unsigned short ss_next = 0;
243 unsigned short spclen;
244 unsigned short numseg;
245
246 short spcbank;
247 short lastsr;
249 short srnum;
250 short srsize;
251 short numsong[3]; // ditto
252 short m_size;
253 short m_free;
254 short m_modf; // ???
255 short m_loaded;
256
257 short t_loaded;
258 short t_modf;
259 short withhead;
260
261 size_t t_number;
262
263 std::vector<Song> songs;
267
268 const SpcCommand& GetSpcCommand(short index) const {
269 return current_spc_command_[index];
270 }
271
273
277};
278
279} // namespace music
280} // namespace zelda3
281} // namespace yaze
282
283#endif
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
void EditTrack(Rom &rom, short i)
Opens an editor window for a specific track. (Legacy UI-related function)
Definition tracker.cc:1334
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:880
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:250
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:148
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:844
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:711
ZeldaSfxInstrument * sndinsts
Definition tracker.h:276
std::vector< Song > songs
Definition tracker.h:263
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:1390
SpcCommand * current_spc_command_
Definition tracker.h:266
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:431
const SpcCommand & GetSpcCommand(short index) const
Definition tracker.h:268
ZeldaInstrument * insts
Definition tracker.h:275
SongSpcBlock ** ssblt
Definition tracker.h:272
char[512] text_buf_ty
Definition tracker.h:38
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
constexpr int kDungeonMusicBank
Definition tracker.h:36
Main namespace for the application.
A state structure for a GUI sample editor.
Definition tracker.h:117
int selr
Right hand sample selection point.
Definition tracker.h:133
int sell
Left hand sample selection point.
Definition tracker.h:130
Represents one of the 8 channels (tracks) in a song.
Definition tracker.h:80
A metadata structure to keep track of parsed sections of the song data. Used to avoid re-parsing the ...
Definition tracker.h:62
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:91
unsigned char flag
Definition tracker.h:92
unsigned char inst
Definition tracker.h:93
unsigned short addr
Definition tracker.h:97
The core data structure representing a single command in a music track. A song track is a doubly-link...
Definition tracker.h:173
Defines an instrument for a song, mapping to a sample and ADSR settings.
Definition tracker.h:144
Defines an instrument for a sound effect.
Definition tracker.h:157
Represents a decoded instrument sample (a waveform).
Definition tracker.h:105