### Development setup and test commands Source: https://github.com/anarkiwi/pygoattracker/blob/main/README.md Install the package in editable mode with development dependencies, then run the test suite (black, pylint, pytest with coverage gate). ```bash pip install -e ".[dev]" ./run_tests.sh # black + pylint + pytest with coverage gate ``` -------------------------------- ### Install and run oracle tests Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/oracle-testing.md Install the package with dev dependencies and run the oracle-marked tests. Requires Docker and the anarkiwi/sidtrace image. ```bash pip install -e ".[dev]" # needs Docker + the anarkiwi/sidtrace image pytest -m oracle -n auto ``` -------------------------------- ### Install pygoattracker with pip Source: https://github.com/anarkiwi/pygoattracker/blob/main/README.md Install the core package, which includes reading, writing, playing, register logs, .sid decompiling, and WAV rendering via pysidtracker. ```bash pip install pygoattracker ``` -------------------------------- ### Explain first difference with whydiff Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/oracle-testing.md Explains a subtune's first difference against the 6502 player, line by line, using the oracle_hvsc:player hook. ```bash PYTHONPATH=scripts python -m pysidtracker.whydiff $HVSC/.sid oracle_hvsc:player --song 1 --frames 1000 ``` -------------------------------- ### Player constructor with Build options Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Creates a Player instance with playback options. Options default to the editor's; a Build object or its field names as keywords can override them. ```APIDOC ## Player(song, build=..., **kwargs) ### Description Creates a Player instance with playback options. Options default to the editor's; a Build object or its field names as keywords can override them. ### Method Constructor ### Endpoint Player(song, build=None, **kwargs) ### Parameters - **song** (Song) - Required - The song object loaded via read_sng() - **build** (Build) - Optional - A Build object specifying playback options - **kwargs** - Optional - Field names of Build as keyword arguments to override options ### Example ```python from pygoattracker import Player, Build Player(song, build=Build(adparam=0x0F00, simplepulse=True)) Player(song, adparam=0x0F00, simplepulse=True) # the same player ``` ``` -------------------------------- ### Pre-fetch tunes for oracle tests Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/oracle-testing.md Downloads the HVSC tunes named by the test suite and the decompile test's corpus sample into the local cache. ```bash pysid-tune-fetch --tests tests --tests tests/data/hvsc_goattracker_sample.txt --tests tests/data/pathdiff.json ``` -------------------------------- ### Build a song from scratch with write_sng Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Creates a Song object with a wavetable, instrument, and pattern, then writes it to a .SNG file. The writer validates format limits and references before emitting. ```python from pygoattracker import ( Instrument, Pattern, Row, Song, write_sng, ) from pygoattracker.constants import note_value song = Song(name="DEMO", author="ME", copyright="2026") # A pulse waveform program: one wavetable row + stop. wave_ptr = song.wavetable.add(0x41, 0x00) song.wavetable.add(0xFF, 0x00) song.instruments.append( Instrument( attack_decay=0x09, sustain_release=0x00, wave_ptr=wave_ptr, gateoff_timer=2, first_wave=0x09, # test+gate on the init frame name="LEAD", ) ) pattern = Pattern.empty(16) pattern.rows[0] = Row(note=note_value("C-4"), instrument=1) pattern.rows[8] = Row(note=note_value("G-4"), instrument=1) song.patterns = [pattern] write_sng(song, "demo.sng") # loads in GoatTracker 2 ``` -------------------------------- ### pygoattracker command line usage Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Shows the available command-line subcommands: info, reglog, wav, nt2, and sid2sng. The info command also detects NinjaTracker 2 and GTS! files. ```bash pygoattracker info tune.sng # also detects NinjaTracker 2 and GTS! (GoatTracker 1.x) files pygoattracker reglog tune.sng tune.reglog --seconds 30 pygoattracker wav tune.sng tune.wav --seconds 30 --model 6581 pygoattracker nt2 tune.sng tune.nt2 --lenient pygoattracker sid2sng tune.sid tune.sng # decompile a packed GoatTracker .sid ``` -------------------------------- ### Recount HVSC coverage with gt1_versions.py Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/gt1.md Run the survey to find GoatTracker tunes and then classify them with gt1_versions.py using 64 jobs. Requires the HVSC path and an output CSV file. ```bash python -m pysidtracker.survey find $HVSC --player goattracker --out tunes.csv && python scripts/gt1_versions.py $HVSC tunes.csv --jobs 64 ``` -------------------------------- ### Build, rank, and prune pathdiff xfails Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/oracle-testing.md Regenerates or prunes fixed cases in tests/data/pathdiff.json after a survey run. The build command runs the survey with the oracle player, rank explains the top divergences, and xfails updates the manifest with format:auto as the right player, keeping existing ids and pruning fixed cases. ```bash python -m pysidtracker.pathdiff build $HVSC tunes.csv --work .hvsc-survey \ --right scripts/oracle_hvsc.py:player --jobs 28 --force ``` ```bash python -m pysidtracker.pathdiff rank --work .hvsc-survey \ --right scripts/oracle_hvsc.py:player --explain 10 ``` ```bash python -m pysidtracker.pathdiff xfails --work .hvsc-survey \ --right scripts/oracle_hvsc.py:player --as-right format:auto \ --manifest tests/data/pathdiff.json --top 15 --prune ``` -------------------------------- ### Select playback options with Build Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Shows how to override playback options using the Build class or its field names as keywords. The Build parameters (e.g., adparam, simplepulse) select alternative playback settings, defaulting to the editor's. ```python from pygoattracker import Build Player(song, build=Build(adparam=0x0F00, simplepulse=True)) Player(song, adparam=0x0F00, simplepulse=True) # the same player ``` -------------------------------- ### Read and write NinjaTracker 2 files Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Loads a NinjaTracker 2 song, prints its header parameters and commands, shows the first rows of the first pattern, and writes the song back to a new file. ```python from pygoattracker import read_nt2, write_nt2 song = read_nt2("tune") # files saved by the C64 editor print(song.hr_param, song.first_wave) for command in song.commands: # NT2 commands double as instruments print(command.name, hex(command.attack_decay)) for row in song.patterns[0].rows[:4]: print(row) # e.g. "C-2 01 08" write_nt2(song, "tune.out") ``` -------------------------------- ### Whole-HVSC survey commands Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/oracle-testing.md Runs a survey of GoatTracker tunes against the oracle, then triages, compares, and diffs results. Requires pysidtracker[survey]>=0.36.0 and the oracle_hvsc render/player hooks. ```bash python -m pysidtracker.survey find $HVSC --player 'goattracker|^\(gt' --out tunes.csv ``` ```bash PYTHONPATH=scripts python -m pysidtracker.survey run $HVSC tunes.csv --work .hvsc-survey --render oracle_hvsc:render ``` ```bash python -m pysidtracker.survey triage .hvsc-survey ``` ```bash python -m pysidtracker.survey compare .hvsc-survey/results.csv --base baseline/results.csv ``` ```bash PYTHONPATH=scripts python -m pysidtracker.survey diff $HVSC tunes.csv _ --work .hvsc-survey --render oracle_hvsc:render ``` -------------------------------- ### Read a GoatTracker .SNG song Source: https://github.com/anarkiwi/pygoattracker/blob/main/README.md Read a .SNG file and print its name, author, and copyright fields. ```python from pygoattracker import read_sng song = read_sng("tune.sng") print(song.name, song.author, song.copyright) ``` -------------------------------- ### pysidtracker command line usage Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Shows how to use the generic pysidtracker tools with GoatTracker formats. The format is auto-detected from the tune. ```bash pysidtracker info tune.sid # metadata, format, subtunes/patterns/instruments pysidtracker reglog tune.sid tune.reglog --seconds 30 pysidtracker wav tune.sid tune.wav --seconds 30 python -m pysidtracker.whydiff tune.sid --format auto # first divergence vs the 6502 player python -m pysidtracker.survey run HVSC TUNES --work DIR --format goattracker2 ``` -------------------------------- ### Recover a song from a .sid file Source: https://github.com/anarkiwi/pygoattracker/blob/main/README.md Decompile a .sid file (path, bytes, or binary file object) into a Song model and write it as a .SNG file that this library can read and play. ```python from pygoattracker import decompile_sid, write_sng result = decompile_sid("tune.sid") # path, bytes, or binary file object song = result.song # the parsed Song model write_sng(song, "tune.sng") # a .SNG this library reads and plays ``` -------------------------------- ### Render through an emulated SID Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Reads a GoatTracker song file and renders it to a WAV file using an emulated SID chip. The 'model' parameter selects the SID model (e.g., '8580'). ```python from pygoattracker import read_sng, render_wav render_wav(read_sng("tune.sng"), "tune.wav", seconds=60, model="8580") ``` -------------------------------- ### Write a SID register log Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Iterates register writes from a song and writes them to a .reglog file with a header. The until_loop=True option stops at the song loop. ```python from pygoattracker import iter_register_writes, write_reglog, read_sng from pygoattracker.reglog import REGLOG_HEADER song = read_sng("tune.sng") writes = iter_register_writes(song, until_loop=True) write_reglog(writes, "tune.reglog", header=REGLOG_HEADER) ``` -------------------------------- ### decompile_sid().player() Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Decompiles a .sid file and returns a Player instance that plays the song as its own player build (hard-restart ADSR, default tempo, init state, frequency table, pulse code). ```APIDOC ## decompile_sid().player() ### Description Decompiles a .sid file and returns a Player instance that plays the song as its own player build (hard-restart ADSR, default tempo, init state, frequency table, pulse code). ### Method player ### Endpoint decompile_sid(sid_file, subtune=0).player() ### Parameters - **sid_file** (str) - Required - Path to the .sid file - **subtune** (int) - Optional - Subtune index (default 0) ### Returns - **player** (Player) - A Player instance for the decompiled song ### Example ```python from pygoattracker import decompile_sid grid = decompile_sid("tune.sid", subtune=0).player().render_grid(250) ``` ``` -------------------------------- ### Player.render_grid() Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Renders a forward-filled grid of SID register values for a specified number of frames. The grid has 25 columns corresponding to registers $D400..$D418. ```APIDOC ## Player.render_grid() ### Description Renders a forward-filled grid of SID register values for a specified number of frames. The grid has 25 columns corresponding to registers $D400..$D418. ### Method render_grid ### Endpoint Player.render_grid(num_frames) ### Parameters - **num_frames** (int) - Required - Number of frames to render ### Returns - **grid** (list of lists) - 250 x 25 register grid (or num_frames x 25) ### Example ```python from pygoattracker import Player, read_sng grid = Player(read_sng("tune.sng")).render_grid(250) # 250 x 25 register grid ``` ``` -------------------------------- ### Song, Instrument, Pattern, Row, write_sng Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Classes and function for building a song from scratch and writing it to a .SNG file. ```APIDOC ## Song, Instrument, Pattern, Row, write_sng ### Description Classes and function for building a song from scratch and writing it to a .SNG file. ### Classes #### Song - **Constructor**: `Song(name, author, copyright)` - `name` (str) - Required - Song name. - `author` (str) - Required - Author name. - `copyright` (str) - Required - Copyright string. - **Attributes**: `wavetable` (Wavetable), `instruments` (list), `patterns` (list), `subtunes` (list) #### Instrument - **Constructor**: `Instrument(attack_decay, sustain_release, wave_ptr, gateoff_timer, first_wave, name)` - `attack_decay` (int) - Required - Attack/decay value. - `sustain_release` (int) - Required - Sustain/release value. - `wave_ptr` (int) - Required - Pointer to wavetable entry. - `gateoff_timer` (int) - Required - Gate-off timer. - `first_wave` (int) - Required - First wave value. - `name` (str) - Required - Instrument name. #### Pattern - **Constructor**: `Pattern.empty(rows)` - `rows` (int) - Required - Number of rows. - **Attributes**: `rows` (list of Row) #### Row - **Constructor**: `Row(note, instrument)` - `note` (int) - Required - Note value (from `note_value`). - `instrument` (int) - Required - Instrument index. ### Function #### write_sng - **Signature**: `write_sng(song, path)` - `song` (Song) - Required - The song object to write. - `path` (str) - Required - Output file path. - **Description**: Writes the song to a .SNG file. Validates format limits and references before writing. ### Example ```python from pygoattracker import ( Instrument, Pattern, Row, Song, write_sng, ) from pygoattracker.constants import note_value song = Song(name="DEMO", author="ME", copyright="2026") wave_ptr = song.wavetable.add(0x41, 0x00) song.wavetable.add(0xFF, 0x00) song.instruments.append( Instrument( attack_decay=0x09, sustain_release=0x00, wave_ptr=wave_ptr, gateoff_timer=2, first_wave=0x09, name="LEAD", ) ) pattern = Pattern.empty(16) pattern.rows[0] = Row(note=note_value("C-4"), instrument=1) pattern.rows[8] = Row(note=note_value("G-4"), instrument=1) song.patterns = [pattern] write_sng(song, "demo.sng") ``` ``` -------------------------------- ### Decompile and play GoatTracker V1.x packed tunes Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Decompiles a .sid file into a Gt1Player object, renders a grid of SID registers, and repacks the data. Requires a supported playroutine as documented in gt1.md. ```python from pygoattracker import Gt1Player, decompile_gt1 gt1 = decompile_gt1(open("tune.sid", "rb").read(), subtune=0) print(gt1.player, len(gt1.patterns), gt1.orderlists[0]) grid = Gt1Player(gt1, subtune=0).render_grid(500) # 25 SID registers per frame address, data = gt1.pack() # the packed bytes again ``` -------------------------------- ### Decompile a .sid and render its player grid Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Decompiles a .sid file and creates a player with its own build (hard-restart ADSR, default tempo, init state, frequency table, pulse code). The player's render_grid method produces a 250x25 register grid. ```python from pygoattracker import decompile_sid grid = decompile_sid("tune.sid", subtune=0).player().render_grid(250) ``` -------------------------------- ### read_sng Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Reads a GoatTracker .SNG song file from a path, bytes, or binary file object. Returns a Song object with metadata, instruments, patterns, and subtunes. ```APIDOC ## read_sng ### Description Reads a GoatTracker .SNG song file from a path, bytes, or binary file object. Returns a Song object with metadata, instruments, patterns, and subtunes. ### Method Function ### Signature `read_sng(source)` ### Parameters - **source** (str | bytes | file object) - Required - Path to the .SNG file, bytes content, or a binary file object. ### Returns - **Song** - The parsed song object with attributes: `name`, `author`, `copyright`, `instruments`, `patterns`, `subtunes`. ### Example ```python from pygoattracker import read_sng song = read_sng("tune.sng") print(song.name, song.author, song.copyright) for instrument in song.instruments: print(instrument.name, hex(instrument.attack_decay)) for row in song.patterns[0].rows[:4]: print(row) print(song.subtunes[0].channels[0].entries) ``` ``` -------------------------------- ### Play a song and render register grid Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Plays a GoatTracker 2 song using the Player class, iterating per-frame register writes and rendering a forward-filled register grid. The Player inherits from pysidtracker.MemPlayer, providing play_frame, render_grid, and iter_frames. ```python from pygoattracker import Player, read_sng player = Player(read_sng("tune.sng"), subtune=0) for _ in range(50 * 60): # one minute at 50 Hz for reg, value in player.play_frame(): print(f"${0xD400 + reg:04X} = ${value:02X}") grid = Player(read_sng("tune.sng")).render_grid(250) # 250 x 25 register grid ``` -------------------------------- ### read_reglog() Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Reads a reglog file and returns a list of RegWrite tuples. ```APIDOC ## read_reglog() ### Description Reads a reglog file and returns a list of RegWrite tuples. ### Method read_reglog ### Endpoint read_reglog(filename) ### Parameters - **filename** (str) - Required - Path to the reglog file ### Returns - **writes** (list of RegWrite) - List of RegWrite tuples ### Example ```python from pygoattracker import read_reglog writes = read_reglog("tune.reglog") ``` ``` -------------------------------- ### Load a register log into pandas Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Reads a .reglog file into a pandas DataFrame with columns clock, reg, and val. The file uses space separation and '#' comments. ```python import pandas as pd df = pd.read_csv( "tune.reglog", sep=" ", comment="#", names=["clock", "reg", "val"] ) ``` -------------------------------- ### Read a song with read_sng Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Reads a .SNG file and prints song metadata, instruments, pattern rows, and subtune entries. Accepts a path, bytes, or binary file object. ```python from pygoattracker import read_sng song = read_sng("tune.sng") print(song.name, song.author, song.copyright) for instrument in song.instruments: print(instrument.name, hex(instrument.attack_decay)) # Patterns are typed rows; orderlists are typed entries. for row in song.patterns[0].rows[:4]: print(row) # e.g. "C-4 01000" print(song.subtunes[0].channels[0].entries) ``` -------------------------------- ### Gt1Player.render_grid Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Renders a grid of SID register values for a given number of frames. Returns a list of register values per frame. ```APIDOC ## Gt1Player.render_grid ### Description Renders a grid of SID register values for a given number of frames. Returns a list of register values per frame. ### Method Method ### Signature `Gt1Player(gt1, subtune=0).render_grid(frames)` ### Parameters - **gt1** (Gt1) - Required - The decompiled tune object. - **subtune** (int) - Optional - The subtune index (default 0). - **frames** (int) - Required - Number of frames to render. ### Returns - **list** - A list of SID register values (25 registers per frame). ### Example ```python from pygoattracker import Gt1Player, decompile_gt1 gt1 = decompile_gt1(open("tune.sid", "rb").read(), subtune=0) grid = Gt1Player(gt1, subtune=0).render_grid(500) ``` ``` -------------------------------- ### decompile_gt1 Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Decompiles a GoatTracker V1.x packed tune from a .sid file. Returns a Gt1 object containing player, patterns, and orderlists. ```APIDOC ## decompile_gt1 ### Description Decompiles a GoatTracker V1.x packed tune from a .sid file. Returns a Gt1 object containing player, patterns, and orderlists. ### Method Function ### Signature `decompile_gt1(data, subtune=0)` ### Parameters - **data** (bytes) - Required - The binary content of the .sid file. - **subtune** (int) - Optional - The subtune index to decompile (default 0). ### Returns - **Gt1** - The decompiled tune object with attributes: `player`, `patterns`, `orderlists`, and methods `pack()`. ### Example ```python from pygoattracker import decompile_gt1 gt1 = decompile_gt1(open("tune.sid", "rb").read(), subtune=0) print(gt1.player, len(gt1.patterns), gt1.orderlists[0]) ``` ``` -------------------------------- ### Gt1.pack Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Packs the decompiled tune back into the original packed bytes. Returns a tuple of (address, data). ```APIDOC ## Gt1.pack ### Description Packs the decompiled tune back into the original packed bytes. Returns a tuple of (address, data). ### Method Method ### Signature `gt1.pack()` ### Parameters None ### Returns - **tuple** - A tuple `(address, data)` where `address` is the load address and `data` is the packed bytes. ### Example ```python from pygoattracker import decompile_gt1 gt1 = decompile_gt1(open("tune.sid", "rb").read(), subtune=0) address, data = gt1.pack() ``` ``` -------------------------------- ### write_reglog() Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Writes a SID register log to a file in the reglog format. The log can be loaded into pandas for analysis. ```APIDOC ## write_reglog() ### Description Writes a SID register log to a file in the reglog format. The log can be loaded into pandas for analysis. ### Method write_reglog ### Endpoint write_reglog(writes, filename, header=None) ### Parameters - **writes** (iterator) - Required - Iterator of register write events (from iter_register_writes) - **filename** (str) - Required - Path to the output file - **header** (str) - Optional - Header string to write at the top of the file (e.g., REGLOG_HEADER) ### Example ```python from pygoattracker import iter_register_writes, write_reglog, read_sng from pygoattracker.reglog import REGLOG_HEADER song = read_sng("tune.sng") writes = iter_register_writes(song, until_loop=True) write_reglog(writes, "tune.reglog", header=REGLOG_HEADER) ``` ``` -------------------------------- ### Convert GoatTracker songs to NinjaTracker 2 Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Converts a GoatTracker song to NinjaTracker 2 format, dropping features that cannot be expressed and collecting a report of dropped items. ```python from pygoattracker import gt_to_nt2, read_sng, write_nt2 song = read_sng("tune.sng") report = [] converted = gt_to_nt2(song, errors="drop", report=report) write_nt2(converted, "tune.nt2") print(report) # one line per feature NinjaTracker cannot express ``` -------------------------------- ### iter_register_writes() Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Iterates over SID register writes for a song, optionally until the song loops. Returns an iterator of register write events. ```APIDOC ## iter_register_writes() ### Description Iterates over SID register writes for a song, optionally until the song loops. Returns an iterator of register write events. ### Method iter_register_writes ### Endpoint iter_register_writes(song, until_loop=False) ### Parameters - **song** (Song) - Required - The song object loaded via read_sng() - **until_loop** (bool) - Optional - If True, iterate until the song loops (default False) ### Returns - **writes** (iterator) - Iterator of register write events ### Example ```python from pygoattracker import iter_register_writes, read_sng song = read_sng("tune.sng") writes = iter_register_writes(song, until_loop=True) ``` ``` -------------------------------- ### Player.play_frame() Source: https://github.com/anarkiwi/pygoattracker/blob/main/docs/usage.md Plays the next frame of the song and returns the changed SID register writes as (reg, value) tuples. This method is inherited from pysidtracker.MemPlayer and is used to iterate through the song frame by frame. ```APIDOC ## Player.play_frame() ### Description Plays the next frame of the song and returns the changed SID register writes as (reg, value) tuples. This method is inherited from pysidtracker.MemPlayer and is used to iterate through the song frame by frame. ### Method play_frame ### Endpoint Player.play_frame() ### Parameters None ### Returns - **reg** (int) - SID register number (0-24, corresponding to $D400..$D418) - **value** (int) - Value written to the register ### Example ```python from pygoattracker import Player, read_sng player = Player(read_sng("tune.sng"), subtune=0) for _ in range(50 * 60): # one minute at 50 Hz for reg, value in player.play_frame(): print(f"${0xD400 + reg:04X} = ${value:02X}") ``` ```