yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::zelda3::music::Tracker Class Reference

#include <tracker.h>

Public Member Functions

SongSpcBlockAllocSpcBlock (int len, int bank)
 Allocates a new SongSpcBlock for holding generated SPC data. These blocks are the building blocks for the final binary output that will be written to the ROM and eventually loaded into the APU.
 
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. It correctly resolves a virtual SPC address and bank into a physical offset within the loaded ROM file, handling the game's specific sound bank mapping.
 
short AllocSpcCommand ()
 Allocates a new SpcCommand from a pre-allocated pool. This uses a classic free-list implementation for efficient memory management without repeated malloc/free calls.
 
short GetBlockTime (Rom &rom, short num, short prevtime)
 Calculates the total time (duration) of a block of SpcCommands. This is essential for synchronization and editor display. It works backwards from the end of a command list, calculating and caching the duration.
 
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, the inverse of LoadSpcCommand. It walks the linked list of commands and writes the corresponding bytes into a new SongSpcBlock.
 
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 stream from the ROM and converts it into a doubly-linked list of SpcCommand structs.
 
void SaveSongs (Rom &rom)
 High-level function to save all modified song data back to the ROM. (Currently commented out, but this would orchestrate the entire save process.) This function would be responsible for taking all the edited, in-memory SongSpcBlocks, arranging them into a final binary layout, patching all the relocated pointers, and writing the result back into the ROM file using WriteSpcData.
 
void LoadSongs (Rom &rom)
 High-level function to load all song data from the ROM. (Currently commented out, but this would be the main entry point for parsing.) It would iterate through the main song table in the ROM, and for each song, recursively load all its parts and commands using LoadSpcCommand. It would also load instrument and sample data.
 
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 with a header containing the length and target SPC address.
 
void EditTrack (Rom &rom, short i)
 Opens an editor window for a specific track. (Legacy UI-related function)
 
void NewSR (Rom &rom, int bank)
 Creates a new, empty song range (SongRange) and opens it for editing. (Legacy UI-related function)
 

Private Member Functions

const SpcCommandGetSpcCommand (short index) const
 

Private Attributes

int modf
 
int mark_sr
 
int mark_start
 
int mark_end
 
int mark_first
 
int mark_last
 
int numwave
 
int numinst
 
int numsndinst
 
int sndinit = 0
 
int sndlen1
 
int sndlen2
 
int m_ofs
 
int w_modf
 
int ss_num
 
int ss_size
 
char op_len [32]
 
char * snddat1
 
char * snddat2
 
unsigned short ss_next = 0
 
unsigned short spclen
 
unsigned short numseg
 
short spcbank
 
short lastsr
 
short ss_lasttime
 
short srnum
 
short srsize
 
short numsong [3]
 
short m_size
 
short m_free
 
short m_modf
 
short m_loaded
 
short t_loaded
 
short t_modf
 
short withhead
 
size_t t_number
 
std::vector< Songsongs
 
SongPartsp_mark
 
SongRangesong_range_
 
SpcCommandcurrent_spc_command_
 
SongSpcBlock ** ssblt
 
ZeldaWavewaves
 
ZeldaInstrumentinsts
 
ZeldaSfxInstrumentsndinsts
 

Detailed Description

Definition at line 188 of file tracker.h.

Member Function Documentation

◆ AllocSpcBlock()

SongSpcBlock * yaze::zelda3::music::Tracker::AllocSpcBlock ( int  len,
int  bank 
)

Allocates a new SongSpcBlock for holding generated SPC data. These blocks are the building blocks for the final binary output that will be written to the ROM and eventually loaded into the APU.

Parameters
lenThe size of the data buffer to allocate for this block.
bankThe target sound bank for this block.
Returns
A pointer to the newly allocated SongSpcBlock.

Definition at line 42 of file tracker.cc.

References yaze::zelda3::music::SongSpcBlock::bank, yaze::zelda3::music::SongSpcBlock::buf, yaze::zelda3::music::SongSpcBlock::flag, yaze::zelda3::music::SongSpcBlock::len, yaze::zelda3::music::SongSpcBlock::relnum, yaze::zelda3::music::SongSpcBlock::relocs, yaze::zelda3::music::SongSpcBlock::relsz, ss_next, ss_num, ss_size, ssblt, and yaze::zelda3::music::SongSpcBlock::start.

Referenced by SaveSpcCommand().

◆ GetSpcAddr()

unsigned char * yaze::zelda3::music::Tracker::GetSpcAddr ( Rom rom,
unsigned short  addr,
short  bank 
)

Gets a direct pointer to music data within the ROM. This function is critical for parsing. It correctly resolves a virtual SPC address and bank into a physical offset within the loaded ROM file, handling the game's specific sound bank mapping.

Parameters
romThe ROM object.
addrThe 16-bit virtual address of the data.
bankThe sound bank where the data resides.
Returns
A pointer to the data within the ROM buffer, or nullptr if not found.

Definition at line 75 of file tracker.cc.

References yaze::Rom::mutable_data(), spcbank, and spclen.

Referenced by LoadSpcCommand().

Here is the call graph for this function:

◆ AllocSpcCommand()

short yaze::zelda3::music::Tracker::AllocSpcCommand ( )

Allocates a new SpcCommand from a pre-allocated pool. This uses a classic free-list implementation for efficient memory management without repeated malloc/free calls.

Returns
The index of the newly allocated command.

Definition at line 115 of file tracker.cc.

References current_spc_command_, m_free, m_size, yaze::zelda3::music::SpcCommand::next, and yaze::zelda3::music::SpcCommand::prev.

Referenced by NewSR().

◆ GetBlockTime()

short yaze::zelda3::music::Tracker::GetBlockTime ( Rom rom,
short  num,
short  prevtime 
)

Calculates the total time (duration) of a block of SpcCommands. This is essential for synchronization and editor display. It works backwards from the end of a command list, calculating and caching the duration.

Parameters
romThe ROM object.
numThe starting command index.
prevtimeThe duration of the subsequent block.
Returns
The total duration in ticks.

Definition at line 148 of file tracker.cc.

References yaze::zelda3::music::SpcCommand::b1, yaze::zelda3::music::SpcCommand::cmd, current_spc_command_, yaze::zelda3::music::SpcCommand::flag, GetBlockTime(), m_modf, m_size, yaze::zelda3::music::SpcCommand::next, yaze::zelda3::music::SpcCommand::p1, yaze::zelda3::music::SpcCommand::p3, yaze::zelda3::music::SpcCommand::prev, ss_lasttime, yaze::zelda3::music::SpcCommand::tim, and yaze::zelda3::music::SpcCommand::tim2.

Referenced by GetBlockTime(), LoadSpcCommand(), and SaveSpcCommand().

Here is the call graph for this function:

◆ SaveSpcCommand()

short yaze::zelda3::music::Tracker::SaveSpcCommand ( Rom rom,
short  num,
short  songtime,
short  endtr 
)

Saves a block of edited SpcCommands back into a binary format. This is the serializer, the inverse of LoadSpcCommand. It walks the linked list of commands and writes the corresponding bytes into a new SongSpcBlock.

Parameters
romThe ROM object.
numThe index of the first command to save.
songtimeThe total duration of the song, used for padding.
endtrFlag indicating if this is the end of a track.
Returns
The new virtual address of the saved block.

Definition at line 711 of file tracker.cc.

References yaze::zelda3::music::SpcCommand::addr, AllocSpcBlock(), yaze::zelda3::music::SpcCommand::b1, yaze::zelda3::music::SpcCommand::b2, yaze::zelda3::music::SongSpcBlock::buf, yaze::zelda3::music::SpcCommand::cmd, current_spc_command_, yaze::zelda3::music::SpcCommand::flag, GetBlockTime(), m_modf, m_size, yaze::zelda3::music::SpcCommand::next, op_len, yaze::zelda3::music::SpcCommand::p1, yaze::zelda3::music::SpcCommand::p2, yaze::zelda3::music::SpcCommand::p3, yaze::zelda3::music::SpcCommand::prev, SaveSpcCommand(), song_range_, srnum, and yaze::zelda3::music::SongSpcBlock::start.

Referenced by SaveSpcCommand().

Here is the call graph for this function:

◆ LoadSpcCommand()

short yaze::zelda3::music::Tracker::LoadSpcCommand ( Rom rom,
unsigned short  addr,
short  bank,
int  t 
)

◆ SaveSongs()

void yaze::zelda3::music::Tracker::SaveSongs ( Rom rom)

High-level function to save all modified song data back to the ROM. (Currently commented out, but this would orchestrate the entire save process.) This function would be responsible for taking all the edited, in-memory SongSpcBlocks, arranging them into a final binary layout, patching all the relocated pointers, and writing the result back into the ROM file using WriteSpcData.

Definition at line 880 of file tracker.cc.

◆ LoadSongs()

void yaze::zelda3::music::Tracker::LoadSongs ( Rom rom)

High-level function to load all song data from the ROM. (Currently commented out, but this would be the main entry point for parsing.) It would iterate through the main song table in the ROM, and for each song, recursively load all its parts and commands using LoadSpcCommand. It would also load instrument and sample data.

Definition at line 431 of file tracker.cc.

Referenced by yaze::editor::MusicEditor::DrawToolset().

◆ WriteSpcData()

int yaze::zelda3::music::Tracker::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 with a header containing the length and target SPC address.

Parameters
romThe ROM object.
bufThe data to write.
lenThe length of the data.
addrThe ROM address to write to.
spcThe target SPC address for this data.
limitThe upper bound for writing in the ROM.
Returns
The next available ROM address after writing.

Definition at line 844 of file tracker.cc.

References m_modf, and yaze::Rom::mutable_data().

Here is the call graph for this function:

◆ EditTrack()

void yaze::zelda3::music::Tracker::EditTrack ( Rom rom,
short  i 
)

Opens an editor window for a specific track. (Legacy UI-related function)

Parameters
romThe ROM object.
iThe index of the first command of the track to edit.

Definition at line 1334 of file tracker.cc.

References current_spc_command_, yaze::zelda3::music::SongRange::first, m_size, song_range_, and srnum.

Referenced by NewSR().

◆ NewSR()

void yaze::zelda3::music::Tracker::NewSR ( Rom rom,
int  bank 
)

Creates a new, empty song range (SongRange) and opens it for editing. (Legacy UI-related function)

Parameters
romThe ROM object.
bankThe target bank for the new song.

Definition at line 1390 of file tracker.cc.

References AllocSpcCommand(), yaze::zelda3::music::SongRange::bank, yaze::zelda3::music::SpcCommand::cmd, current_spc_command_, yaze::zelda3::music::SongRange::editor, EditTrack(), yaze::zelda3::music::SongRange::first, yaze::zelda3::music::SpcCommand::flag, yaze::zelda3::music::SpcCommand::next, yaze::zelda3::music::SpcCommand::prev, song_range_, srnum, and srsize.

Here is the call graph for this function:

◆ GetSpcCommand()

const SpcCommand & yaze::zelda3::music::Tracker::GetSpcCommand ( short  index) const
inlineprivate

Definition at line 268 of file tracker.h.

References current_spc_command_.

Member Data Documentation

◆ modf

int yaze::zelda3::music::Tracker::modf
private

Definition at line 214 of file tracker.h.

◆ mark_sr

int yaze::zelda3::music::Tracker::mark_sr
private

Definition at line 216 of file tracker.h.

◆ mark_start

int yaze::zelda3::music::Tracker::mark_start
private

Definition at line 218 of file tracker.h.

◆ mark_end

int yaze::zelda3::music::Tracker::mark_end
private

Definition at line 219 of file tracker.h.

◆ mark_first

int yaze::zelda3::music::Tracker::mark_first
private

Definition at line 220 of file tracker.h.

◆ mark_last

int yaze::zelda3::music::Tracker::mark_last
private

Definition at line 221 of file tracker.h.

◆ numwave

int yaze::zelda3::music::Tracker::numwave
private

Definition at line 223 of file tracker.h.

◆ numinst

int yaze::zelda3::music::Tracker::numinst
private

Definition at line 224 of file tracker.h.

◆ numsndinst

int yaze::zelda3::music::Tracker::numsndinst
private

Definition at line 225 of file tracker.h.

◆ sndinit

int yaze::zelda3::music::Tracker::sndinit = 0
private

Definition at line 227 of file tracker.h.

◆ sndlen1

int yaze::zelda3::music::Tracker::sndlen1
private

Definition at line 229 of file tracker.h.

◆ sndlen2

int yaze::zelda3::music::Tracker::sndlen2
private

Definition at line 230 of file tracker.h.

◆ m_ofs

int yaze::zelda3::music::Tracker::m_ofs
private

Definition at line 231 of file tracker.h.

◆ w_modf

int yaze::zelda3::music::Tracker::w_modf
private

Definition at line 232 of file tracker.h.

◆ ss_num

int yaze::zelda3::music::Tracker::ss_num
private

Definition at line 234 of file tracker.h.

Referenced by AllocSpcBlock().

◆ ss_size

int yaze::zelda3::music::Tracker::ss_size
private

Definition at line 235 of file tracker.h.

Referenced by AllocSpcBlock().

◆ op_len

char yaze::zelda3::music::Tracker::op_len[32]
private

Definition at line 237 of file tracker.h.

Referenced by LoadSpcCommand(), and SaveSpcCommand().

◆ snddat1

char* yaze::zelda3::music::Tracker::snddat1
private

Definition at line 239 of file tracker.h.

◆ snddat2

char* yaze::zelda3::music::Tracker::snddat2
private

Definition at line 240 of file tracker.h.

◆ ss_next

unsigned short yaze::zelda3::music::Tracker::ss_next = 0
private

Definition at line 242 of file tracker.h.

Referenced by AllocSpcBlock().

◆ spclen

unsigned short yaze::zelda3::music::Tracker::spclen
private

Definition at line 243 of file tracker.h.

Referenced by GetSpcAddr().

◆ numseg

unsigned short yaze::zelda3::music::Tracker::numseg
private

Definition at line 244 of file tracker.h.

◆ spcbank

short yaze::zelda3::music::Tracker::spcbank
private

Definition at line 246 of file tracker.h.

Referenced by GetSpcAddr(), and LoadSpcCommand().

◆ lastsr

short yaze::zelda3::music::Tracker::lastsr
private

Definition at line 247 of file tracker.h.

Referenced by LoadSpcCommand().

◆ ss_lasttime

short yaze::zelda3::music::Tracker::ss_lasttime
private

Definition at line 248 of file tracker.h.

Referenced by GetBlockTime().

◆ srnum

short yaze::zelda3::music::Tracker::srnum
private

Definition at line 249 of file tracker.h.

Referenced by EditTrack(), LoadSpcCommand(), NewSR(), and SaveSpcCommand().

◆ srsize

short yaze::zelda3::music::Tracker::srsize
private

Definition at line 250 of file tracker.h.

Referenced by LoadSpcCommand(), and NewSR().

◆ numsong

short yaze::zelda3::music::Tracker::numsong[3]
private

Definition at line 251 of file tracker.h.

◆ m_size

short yaze::zelda3::music::Tracker::m_size
private

Definition at line 252 of file tracker.h.

Referenced by AllocSpcCommand(), EditTrack(), GetBlockTime(), LoadSpcCommand(), and SaveSpcCommand().

◆ m_free

short yaze::zelda3::music::Tracker::m_free
private

Definition at line 253 of file tracker.h.

Referenced by AllocSpcCommand(), and LoadSpcCommand().

◆ m_modf

short yaze::zelda3::music::Tracker::m_modf
private

Definition at line 254 of file tracker.h.

Referenced by GetBlockTime(), SaveSpcCommand(), and WriteSpcData().

◆ m_loaded

short yaze::zelda3::music::Tracker::m_loaded
private

Definition at line 255 of file tracker.h.

◆ t_loaded

short yaze::zelda3::music::Tracker::t_loaded
private

Definition at line 257 of file tracker.h.

◆ t_modf

short yaze::zelda3::music::Tracker::t_modf
private

Definition at line 258 of file tracker.h.

◆ withhead

short yaze::zelda3::music::Tracker::withhead
private

Definition at line 259 of file tracker.h.

◆ t_number

size_t yaze::zelda3::music::Tracker::t_number
private

Definition at line 261 of file tracker.h.

◆ songs

std::vector<Song> yaze::zelda3::music::Tracker::songs
private

Definition at line 263 of file tracker.h.

◆ sp_mark

SongPart* yaze::zelda3::music::Tracker::sp_mark
private

Definition at line 264 of file tracker.h.

◆ song_range_

SongRange* yaze::zelda3::music::Tracker::song_range_
private

Definition at line 265 of file tracker.h.

Referenced by EditTrack(), LoadSpcCommand(), NewSR(), and SaveSpcCommand().

◆ current_spc_command_

SpcCommand* yaze::zelda3::music::Tracker::current_spc_command_
private

◆ ssblt

SongSpcBlock** yaze::zelda3::music::Tracker::ssblt
private

Definition at line 272 of file tracker.h.

Referenced by AllocSpcBlock().

◆ waves

ZeldaWave* yaze::zelda3::music::Tracker::waves
private

Definition at line 274 of file tracker.h.

◆ insts

ZeldaInstrument* yaze::zelda3::music::Tracker::insts
private

Definition at line 275 of file tracker.h.

◆ sndinsts

ZeldaSfxInstrument* yaze::zelda3::music::Tracker::sndinsts
private

Definition at line 276 of file tracker.h.


The documentation for this class was generated from the following files: