OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
dlscollection.cpp
Go to the documentation of this file.
1#include "dlscollection.h"
2
3#include <Tempest/Log>
4#include <Tempest/MemWriter>
5#include <stdexcept>
6#include <fstream>
7
8#include "soundfont.h"
9
10using namespace Dx8;
11using namespace Tempest;
12
14 if(!input.is("LIST"))
15 throw std::runtime_error("not a riff");
16 input.readListId("rgn ");
17 input.read([this](Riff& c){
18 implRead(c);
19 });
20 }
21
22void DlsCollection::Region::implRead(Riff &input) {
23 if(input.is("rgnh")){
24 input.read(&head,sizeof(head));
25 }
26 else if(input.is("LIST") && input.isListId("lart")){
27 // articulators
28 }
29 else if(input.is("wlnk")){
30 input.read(&wlink,sizeof(wlink));
31 }
32 else if(input.is("wsmp")){
33 input.read(&waveSample,sizeof(waveSample));
34 loop.resize(waveSample.cSampleLoops);
35 for(auto& i:loop){
36 input.read(&i,sizeof(i));
37 input.skip(i.cbSize-sizeof(i));
38 }
39 }
40 }
41
42
44 if(!input.is("art1"))
45 throw std::runtime_error("not a riff");
46
47 uint32_t cbSize=0;
48 uint32_t size=0;
49
50 input.read(&cbSize,sizeof(cbSize));
51 input.read(&size,sizeof(size));
52 connectionBlocks.resize(size);
53
54 for(auto& i:connectionBlocks) {
55 input.read(&i,sizeof(i));
56 }
57 }
58
60 if(!input.is("LIST"))
61 throw std::runtime_error("not a list");
62 input.readListId("ins ");
63 input.read([this](Riff& c){
64 implRead(c);
65 });
66 }
67
68void DlsCollection::Instrument::implRead(Riff &input) {
69 if(input.is("LIST")){
70 if(input.isListId("lrgn")){
71 input.read([this](Riff& c){
72 regions.emplace_back(c);
73 });
74 }
75 else if(input.isListId("lart")){
76 input.read([this](Riff& c){
77 articulators.emplace_back(c);
78 });
79 }
80 else if(input.isListId("INFO")){
81 info = Info(input);
82 }
83 }
84 else if(input.is("insh")){
85 input.read(&header,sizeof(header));
86 }
87 }
88
90 if(!input.is("RIFF"))
91 throw std::runtime_error("not a riff");
92 input.readListId("DLS ");
93 input.read([this](Riff& c){
94 implRead(c);
95 });
96
97 shData = SoundFont::shared(*this,wave);
98 wave.clear();
99 }
100
101void DlsCollection::implRead(Riff &input) {
102 if(input.is("vers"))
103 input.read(&version,sizeof(version));
104 else if(input.is("dlid"))
105 input.read(&dlid,sizeof(dlid));
106 else if(input.is("LIST")){
107 if(input.isListId("wvpl")){
108 input.read([this](Riff& chunk){
109 Wave wx(chunk);
110 wave.emplace_back(std::move(wx));
111 });
112 }
113 else if(input.isListId("lins")){
114 input.read([this](Riff& chunk){
115 instrument.emplace_back(chunk);
116 });
117 }
118 }
119 }
120
121SoundFont DlsCollection::toSoundfont(uint32_t dwPatch) const {
122 return SoundFont(shData,dwPatch);
123 }
124
126 Log::i("__DLS__");
127
128 for(auto& i:instrument){
129 for(auto& r:i.regions) {
130 if(r.wlink.ulTableIndex<wave.size()) {
131 Log::i(" ",r.head.RangeKey.usLow,"-",r.head.RangeKey.usHigh," ",r.wlink.ulTableIndex);//," ",wave[r.wlink.ulTableIndex].info.inam);
132 } else {
133 Log::i(" ",r.wlink.ulTableIndex);
134 }
135 }
136 }
137 }
138
139const Wave* DlsCollection::findWave(uint8_t note) const {
140 for(auto& i:instrument){
141 for(auto& r:i.regions) {
142 if(r.head.RangeKey.usLow<=note && note<=r.head.RangeKey.usHigh) {
143 if(r.wlink.ulTableIndex<wave.size())
144 return &wave[r.wlink.ulTableIndex];
145 }
146 }
147 }
148 return nullptr;
149 }
std::vector< Instrument > instrument
DlsCollection(Riff &input)
const Wave * findWave(uint8_t note) const
SoundFont toSoundfont(uint32_t dwPatch) const
bool is(const char *idx) const
Definition riff.h:19
void read(std::u16string &str)
Definition riff.cpp:29
void readListId()
Definition riff.cpp:13
void skip(size_t sz)
Definition riff.cpp:76
bool isListId(const char *id)
Definition riff.cpp:24
static std::shared_ptr< Data > shared(const DlsCollection &dls, const std::vector< Wave > &wave)
Definition band.h:10