Tabula Sonora 0.1.0
A native C++20 implementation of the Roland Sound Canvas VA synth voice
Loading...
Searching...
No Matches
drum_kit_table.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <array>
7#include <cstdint>
8#include <optional>
9#include <string>
10#include <vector>
11
12namespace ts {
13
15struct DrumKey {
17 int tone = 0;
19 int level = 0;
21 int pitch = 0;
23 int group = 0;
25 int pan = 0;
36 bool receives_note_off = false;
37
43 bool receives_note_on = true;
44};
45
58public:
60 static constexpr int kit_stride = 0x50C;
61
63 static constexpr int key_count = 128;
64
75 static constexpr int map_row_count = 6;
76
81 static constexpr std::int64_t kit_index_offset = 0x19F21B0;
82
84 explicit DrumKitTable(const RomImage& rom);
85
87 [[nodiscard]] int kit_count() const noexcept { return kit_count_; }
88
100 [[nodiscard]] static std::optional<int> row_for_map(ToneMap map) noexcept;
101
103 [[nodiscard]] int map_row(int internal_bank) const noexcept;
104
109 [[nodiscard]] std::optional<int> kit_for_program(int program, int row = 0) const noexcept;
110
130 [[nodiscard]] std::string kit_name(int kit) const;
131
135 [[nodiscard]] DrumKey key(int note, int kit = 0) const;
136
144 [[nodiscard]] static double coarse_pitch_ratio(int pitch) noexcept;
145
151 [[nodiscard]] static constexpr double level_gain(int level) noexcept
152 {
153 return (level / 127.0) * (level / 127.0);
154 }
155
156private:
157 // Plane offsets within a kit record.
158 static constexpr int tone_plane = 0x000; // 128 x u16
159 static constexpr int level_plane = 0x100;
160 static constexpr int pitch_plane = 0x180;
161 static constexpr int group_plane = 0x200;
162 static constexpr int pan_plane = 0x280;
163 // 0x300 reverb depth, 0x380 chorus depth, 0x400 delay depth — per key, and not yet wired.
165 static constexpr int receive_plane = 0x480;
167 static constexpr int name_plane = 0x500;
168 static constexpr int name_length = 12;
169
170 std::int64_t kit_base_ = 0;
171 std::vector<std::uint8_t> bank_row_;
172 std::vector<std::uint8_t> program_map_;
173 std::array<std::uint16_t, 256> kit_index_{};
174 std::vector<std::uint8_t> kits_;
175 int kit_count_ = 0;
176};
177
178} // namespace ts
static constexpr int key_count
Keys per kit.
Definition drum_kit_table.hpp:63
DrumKitTable(const RomImage &rom)
Creates the table by reading the drum regions out of the ROM image.
std::string kit_name(int kit) const
The kit's name, as the ROM record carries it, trimmed of trailing spaces.
static constexpr double level_gain(int level) noexcept
The gain the kit level contributes, as amplitude.
Definition drum_kit_table.hpp:151
DrumKey key(int note, int kit=0) const
Reads one key's settings from a kit; kit 0 is GM Standard.
std::optional< int > kit_for_program(int program, int row=0) const noexcept
Resolves a drum program to its kit record index, or nothing for an undefined program.
static constexpr int map_row_count
Rows in the drum program map.
Definition drum_kit_table.hpp:75
static constexpr std::int64_t kit_index_offset
File offset of the table mapping a level-two index to a kit record index.
Definition drum_kit_table.hpp:81
static constexpr int kit_stride
Bytes per kit record.
Definition drum_kit_table.hpp:60
static std::optional< int > row_for_map(ToneMap map) noexcept
The drum map row a vintage's tone map selects, or nothing where no measurement pins one.
int kit_count() const noexcept
Number of kit records reachable through the program map.
Definition drum_kit_table.hpp:87
static double coarse_pitch_ratio(int pitch) noexcept
The playback ratio the kit's coarse-pitch plane implies.
int map_row(int internal_bank) const noexcept
Maps an internal bank code to a drum map row; standard GM/GS drum parts use 0x04.
Read-only access to SCCore.dll as a data file.
Definition rom_image.hpp:39
Definition control_decode.hpp:7
ToneMap
Which vintage's tone map a program change resolves against.
Definition patch_directory.hpp:22
@ pitch
Pitch, in milli-semitones.
Definition lfo_engine.hpp:18
One drum key's settings within a kit.
Definition drum_kit_table.hpp:15
int group
Mute/assign group; keys sharing a non-zero group cut each other off.
Definition drum_kit_table.hpp:23
bool receives_note_on
Whether this key responds to note-on — GS Rx.Note On, bit 4 of the same plane.
Definition drum_kit_table.hpp:43
int pan
Pan position, per key.
Definition drum_kit_table.hpp:25
int tone
Tone number. Drum sounds are ordinary melodic tones.
Definition drum_kit_table.hpp:17
bool receives_note_off
Whether this key responds to note-off at all — GS Rx.Note Off, per key.
Definition drum_kit_table.hpp:36
int level
Kit level for this key. Applies downstream as (level / 127)^2.
Definition drum_kit_table.hpp:19
int pitch
Coarse pitch, 60 being the tone's natural pitch.
Definition drum_kit_table.hpp:21