diff options
Diffstat (limited to 'tools/tracker_compiler.cc')
| -rw-r--r-- | tools/tracker_compiler.cc | 58 |
1 files changed, 49 insertions, 9 deletions
diff --git a/tools/tracker_compiler.cc b/tools/tracker_compiler.cc index 9f0d6b4..b4c72b2 100644 --- a/tools/tracker_compiler.cc +++ b/tools/tracker_compiler.cc @@ -6,8 +6,18 @@ #include <string> #include <vector> +// Enum to differentiate between sample types +enum SampleType { + GENERATED, + ASSET +}; + struct Sample { std::string name; + SampleType type = GENERATED; // Default to GENERATED + std::string asset_id_name; // Store AssetId name for asset samples + + // Parameters for generated samples float freq, dur, amp, attack, harmonic_decay; int harmonics; }; @@ -68,10 +78,20 @@ int main(int argc, char** argv) { name.pop_back(); s.name = name; - // Very simple parsing: freq, dur, amp, attack, harmonics, harmonic_decay - char comma; - ss >> s.freq >> comma >> s.dur >> comma >> s.amp >> comma >> s.attack >> - comma >> s.harmonics >> comma >> s.harmonic_decay; + if (name.rfind("ASSET_", 0) == 0) { + s.type = ASSET; + s.asset_id_name = name; + // Parameters for asset samples are ignored, so we don't parse them here. + // However, we must consume the rest of the line to avoid issues if a comma is present. + std::string dummy; + while (ss >> dummy) {} // Consume rest of line + } else { + s.type = GENERATED; + // Very simple parsing: freq, dur, amp, attack, harmonics, harmonic_decay + char comma; + ss >> s.freq >> comma >> s.dur >> comma >> s.amp >> comma >> s.attack >> + comma >> s.harmonics >> comma >> s.harmonic_decay; + } sample_map[s.name] = samples.size(); samples.push_back(s); @@ -123,23 +143,43 @@ int main(int argc, char** argv) { } fprintf(out_file, "// Generated by tracker_compiler. Do not edit.\n\n"); fprintf(out_file, "#include \"audio/tracker.h\"\n\n"); + // Need to include assets.h for AssetId enum + fprintf(out_file, "#include \"generated/assets.h\"\n\n"); fprintf(out_file, "const NoteParams g_tracker_samples[] = {\n"); for (const auto& s : samples) { - fprintf(out_file, - " { %.1ff, %.2ff, %.1ff, %.2ff, 0.0f, 0.0f, 0.0f, %d, %.1ff, " - "0.0f, 0.0f }, // %s\n", - s.freq, s.dur, s.amp, s.attack, s.harmonics, s.harmonic_decay, - s.name.c_str()); + if (s.type == GENERATED) { + fprintf(out_file, + " { %.1ff, %.2ff, %.1ff, %.2ff, 0.0f, 0.0f, 0.0f, %d, %.1ff, " + "0.0f, 0.0f }, // %s\n", + s.freq, s.dur, s.amp, s.attack, s.harmonics, s.harmonic_decay, + s.name.c_str()); + } else { + fprintf(out_file, " { 0 }, // %s (ASSET)\n", s.name.c_str()); + } } fprintf(out_file, "};\n"); fprintf(out_file, "const uint32_t g_tracker_samples_count = %zu;\n\n", samples.size()); + fprintf(out_file, "const AssetId g_tracker_sample_assets[] = {\n"); + for (const auto& s : samples) { + if (s.type == ASSET) { + fprintf(out_file, " AssetId::%s,\n", s.asset_id_name.c_str()); + } else { + fprintf(out_file, " AssetId::ASSET_LAST_ID,\n"); + } + } + fprintf(out_file, "};\n\n"); + for (const auto& p : patterns) { fprintf(out_file, "static const TrackerEvent PATTERN_EVENTS_%s[] = {\n", p.name.c_str()); for (const auto& e : p.events) { + // When referencing a sample, we need to get its index or synth_id. + // If it's an asset, the name starts with ASSET_. + // For now, assume sample_map is used for both generated and asset samples. + // This will need refinement if asset samples are not in sample_map directly. fprintf(out_file, " { %.1ff, %d, %.1ff, %.1ff },\n", e.beat, sample_map[e.sample_name], e.volume, e.pan); } |
