Tabula Sonora 0.1.0
A native C++20 implementation of the Roland Sound Canvas VA synth voice
Loading...
Searching...
No Matches
patch_directory.hpp
Go to the documentation of this file.
1#pragma once
2
6
7#include <cstdint>
8#include <optional>
9#include <string>
10#include <string_view>
11#include <utility>
12#include <vector>
13
14namespace ts {
15
22enum class ToneMap {
23 sc55 = 1,
24 sc88 = 2,
26 sc8820 = 4,
27 xg = 0x77,
28};
29
35[[nodiscard]] const std::vector<std::pair<std::string, int>>& tone_map_choices() noexcept;
36
38[[nodiscard]] std::string_view tone_map_name(ToneMap map) noexcept;
39
41struct ToneZone {
43 int velocity_low = 0;
45 int key_low = 0;
46 int key_high = 0;
47 int wave = 0;
49};
50
53 int map = 0;
54 int bank = 0;
55 int program = 0;
56};
57
69
77public:
79 static constexpr int melodic_space_end = 0x4000;
80
82 static constexpr int drum_space_start = 0x4000;
83
85 static constexpr int alternate_space_start = 0x6000;
86
88 static constexpr int indirect_only_flag = 0x8000;
89
91 static constexpr int multisample_stride = 0x8C;
92
94 static constexpr int alternate_stride = 0x18;
95
97 static constexpr int unassigned = 0xFFFF;
98
100 explicit PatchDirectory(const TableSet& tables);
101
103 [[nodiscard]] int tone_count() const noexcept { return tone_count_; }
104
106 [[nodiscard]] int multisample_count() const noexcept { return multisample_count_; }
107
109 [[nodiscard]] int wave_count() const noexcept { return wave_count_; }
110
112 [[nodiscard]] int alternate_count() const noexcept { return alternate_count_; }
113
115 [[nodiscard]] std::optional<WaveDescriptor> wave(int wave_number) const;
116
118 [[nodiscard]] std::optional<Tone> tone(int tone_number) const;
119
121 [[nodiscard]] int tone_level(int tone_number) const;
122
128 [[nodiscard]] bool half_damper(int tone_number) const;
129
134 [[nodiscard]] PartialParameters partial_by_slot(int tone_number, int slot) const;
135
142 [[nodiscard]] std::optional<int> multisample_wave(int multisample, int transposed_key) const;
143
145 [[nodiscard]] int zone_level(int multisample, int key, int key_center) const;
146
148 [[nodiscard]] std::vector<MultisampleZone> multisample_zones(int multisample) const;
149
155 [[nodiscard]] std::optional<std::string> tone_zones(int tone_number,
156 std::vector<ToneZone>& zones) const;
157
163 [[nodiscard]] std::optional<int> lut3_raw(int program, ToneMap map, int bank) const;
164
172 [[nodiscard]] std::optional<int> lut3_resolved(int program, ToneMap map, int bank) const;
173
175 [[nodiscard]] std::optional<AlternateEntry> alternate(int index) const;
176
182 [[nodiscard]] std::vector<int> program_tones(int program, ToneMap map, int bank) const;
183
187 [[nodiscard]] int alternate_tone(int program, ToneMap map, int bank) const;
188
190 [[nodiscard]] int program_to_tone(int program, ToneMap map, int bank) const;
191
193 [[nodiscard]] ResolvedTone resolve(int tone_number, int note, int velocity) const;
194
196 [[nodiscard]] ResolvedTone
197 resolve_midi(int program, int note, int velocity, ToneMap map, int bank) const;
198
199private:
200 [[nodiscard]] int dereference(const ProgramReference& reference) const;
201
202 const TableSet* tables_;
203 std::span<const std::uint8_t> tone_;
204 std::span<const std::uint8_t> multisample_;
205 std::span<const std::uint8_t> wavedesc_;
206 std::span<const std::uint8_t> layered_;
207
208 int tone_count_ = 0;
209 int multisample_count_ = 0;
210 int wave_count_ = 0;
211 int alternate_count_ = 0;
212};
213
214} // namespace ts
A zero-copy typed view over one 0x6e-byte partial parameter block inside a tone record.
Definition partial_parameters.hpp:20
int alternate_tone(int program, ToneMap map, int bank) const
The mono/solo alternate-articulation tone for a program, or -1.
int alternate_count() const noexcept
Number of alternate-articulation records.
Definition patch_directory.hpp:112
std::optional< WaveDescriptor > wave(int wave_number) const
Reads a wave descriptor, or nothing if the number is out of range.
PatchDirectory(const TableSet &tables)
Creates a directory over a loaded table set, which must outlive it.
static constexpr int multisample_stride
Bytes per multisample record.
Definition patch_directory.hpp:91
bool half_damper(int tone_number) const
Whether a tone responds to half-damper (continuous CC64).
std::vector< int > program_tones(int program, ToneMap map, int bank) const
Resolves a program change to the tone numbers that sound for an ordinary poly note.
ResolvedTone resolve_midi(int program, int note, int velocity, ToneMap map, int bank) const
Resolves a MIDI program change and played note in one step.
int multisample_count() const noexcept
Number of multisample records.
Definition patch_directory.hpp:106
static constexpr int indirect_only_flag
Tone numbers at or above this are reachable only indirectly.
Definition patch_directory.hpp:88
std::optional< Tone > tone(int tone_number) const
Reads a tone record, or nothing if the number is out of range.
ResolvedTone resolve(int tone_number, int note, int velocity) const
Resolves a played note against a tone.
int program_to_tone(int program, ToneMap map, int bank) const
Resolves a program change to a single tone number, or -1 when unassigned.
int tone_count() const noexcept
Number of tone records in the melodic table.
Definition patch_directory.hpp:103
static constexpr int melodic_space_end
Highest tone number in the melodic space, exclusive.
Definition patch_directory.hpp:79
int zone_level(int multisample, int key, int key_center) const
Reads the per-key-zone level, the second attenuation in the TVA base-level chain.
static constexpr int drum_space_start
First tone number in the drum space.
Definition patch_directory.hpp:82
std::optional< int > multisample_wave(int multisample, int transposed_key) const
Selects the wave a multisample yields for a transposed key, or nothing when silent.
std::optional< std::string > tone_zones(int tone_number, std::vector< ToneZone > &zones) const
Builds the full static zone map for a tone, with key bounds converted back to MIDI notes.
int wave_count() const noexcept
Number of wave descriptors.
Definition patch_directory.hpp:109
int tone_level(int tone_number) const
Reads a tone's master level from its header.
std::optional< int > lut3_resolved(int program, ToneMap map, int bank) const
The three-level lookup with the GS capital-tone fallback applied.
std::optional< int > lut3_raw(int program, ToneMap map, int bank) const
The raw unsigned word the three-level program lookup yields.
std::vector< MultisampleZone > multisample_zones(int multisample) const
Lists a multisample's key zones in transposed-key space, low to high.
PartialParameters partial_by_slot(int tone_number, int slot) const
Reads a partial block by its slot rather than its position among the present partials.
static constexpr int alternate_stride
Bytes per alternate-articulation record.
Definition patch_directory.hpp:94
static constexpr int alternate_space_start
First tone number in the alternate-articulation space.
Definition patch_directory.hpp:85
static constexpr int unassigned
Value meaning "unassigned" in the third lookup level.
Definition patch_directory.hpp:97
std::optional< AlternateEntry > alternate(int index) const
Decodes an entry of the alternate-articulation table, indexed by tone# - 0x6000.
The static tables the engine needs, loaded from SCCore.dll or from a directory of extracted ....
Definition table_set.hpp:30
Definition control_decode.hpp:7
ToneMap
Which vintage's tone map a program change resolves against.
Definition patch_directory.hpp:22
@ sc55
Definition patch_directory.hpp:23
@ sc88
Definition patch_directory.hpp:24
@ sc88pro
Definition patch_directory.hpp:25
@ xg
Definition patch_directory.hpp:27
@ sc8820
Definition patch_directory.hpp:26
const std::vector< std::pair< std::string, int > > & tone_map_choices() noexcept
The tone maps a command line accepts, by name and by the module's own selector value.
@ bank
Definition control_decode.hpp:26
std::string_view tone_map_name(ToneMap map) noexcept
The name of a tone map, for a UI to display. Empty for a value that names none.
An entry of the alternate-articulation table.
Definition patch_directory.hpp:59
int threshold
Inter-note timing threshold that gates the alternate.
Definition patch_directory.hpp:63
std::string name
The entry's ASCII name.
Definition patch_directory.hpp:61
ProgramReference alternate
The alternate articulation, reachable only in mono/solo mode.
Definition patch_directory.hpp:67
ProgramReference primary
The tone reference that normally sounds.
Definition patch_directory.hpp:65
A (map, bank, program) triple that resolves through the same three-level lookup.
Definition patch_directory.hpp:52
int bank
Definition patch_directory.hpp:54
int program
Definition patch_directory.hpp:55
int map
Definition patch_directory.hpp:53
The waves that sound for one tone at a given note and velocity.
Definition tone.hpp:78
One key zone of a tone, expressed in MIDI note numbers.
Definition patch_directory.hpp:41
int key_low
Definition patch_directory.hpp:45
int partial_index
Definition patch_directory.hpp:42
int wave
Definition patch_directory.hpp:47
int velocity_high
Definition patch_directory.hpp:44
WaveDescriptor descriptor
Definition patch_directory.hpp:48
int velocity_low
Definition patch_directory.hpp:43
int key_high
Definition patch_directory.hpp:46
One entry of the wave-descriptor table: where a sample lives in the wave ROM, how it is tuned,...
Definition wave_descriptor.hpp:14