| 1 |
/* |
| 2 |
* Copyright (C) 2018-2021 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include <memory> |
| 29 |
#include <vector> |
| 30 |
#include <string> |
| 31 |
#include "io/binary_container.hpp" |
| 32 |
|
| 33 |
class AbstractInstrument; |
| 34 |
class InstrumentsManager; |
| 35 |
struct WOPNFile; |
| 36 |
|
| 37 |
class AbstractBank |
| 38 |
{ |
| 39 |
public: |
| 40 |
virtual ~AbstractBank() = default; |
| 41 |
|
| 42 |
virtual size_t getNumInstruments() const = 0; |
| 43 |
virtual std::string getInstrumentIdentifier(size_t index) const = 0; |
| 44 |
virtual std::string getInstrumentName(size_t index) const = 0; |
| 45 |
virtual AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const = 0; |
| 46 |
}; |
| 47 |
|
| 48 |
class BtBank final : public AbstractBank |
| 49 |
{ |
| 50 |
public: |
| 51 |
BtBank(const std::vector<int>& ids, const std::vector<std::string>& names); |
| 52 |
BtBank(const std::vector<int>& ids, const std::vector<std::string>& names, |
| 53 |
const std::vector<io::BinaryContainer>& instSecs, const io::BinaryContainer& propSec, uint32_t version); |
| 54 |
|
| 55 |
size_t getNumInstruments() const override; |
| 56 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 57 |
std::string getInstrumentName(size_t index) const override; |
| 58 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 59 |
|
| 60 |
private: |
| 61 |
std::vector<io::BinaryContainer> instCtrs_; |
| 62 |
io::BinaryContainer propCtr_; |
| 63 |
std::vector<int> ids_; |
| 64 |
std::vector<std::string> names_; |
| 65 |
uint32_t version_; |
| 66 |
}; |
| 67 |
|
| 68 |
class WopnBank final : public AbstractBank |
| 69 |
{ |
| 70 |
public: |
| 71 |
explicit WopnBank(WOPNFile *wopn); |
| 72 |
|
| 73 |
size_t getNumInstruments() const override; |
| 74 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 75 |
std::string getInstrumentName(size_t index) const override; |
| 76 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 77 |
|
| 78 |
private: |
| 79 |
struct WOPNDeleter { |
| 80 |
void operator()(WOPNFile *x); |
| 81 |
}; |
| 82 |
std::unique_ptr<WOPNFile, WOPNDeleter> wopn_; |
| 83 |
|
| 84 |
struct InstEntry; |
| 85 |
std::vector<InstEntry> entries_; |
| 86 |
}; |
| 87 |
|
| 88 |
class FfBank final : public AbstractBank |
| 89 |
{ |
| 90 |
public: |
| 91 |
FfBank(const std::vector<int>& ids, const std::vector<std::string>& names, const std::vector<io::BinaryContainer>& ctrs); |
| 92 |
|
| 93 |
size_t getNumInstruments() const override; |
| 94 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 95 |
std::string getInstrumentName(size_t index) const override; |
| 96 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 97 |
|
| 98 |
void setInstrumentName(size_t index, const std::string& name); |
| 99 |
|
| 100 |
private: |
| 101 |
std::vector<int> ids_; |
| 102 |
std::vector<std::string> names_; |
| 103 |
std::vector<io::BinaryContainer> instCtrs_; |
| 104 |
}; |
| 105 |
|
| 106 |
class PpcBank final : public AbstractBank |
| 107 |
{ |
| 108 |
public: |
| 109 |
PpcBank(const std::vector<int>& ids, const std::vector<std::vector<uint8_t>>& samples); |
| 110 |
|
| 111 |
size_t getNumInstruments() const override; |
| 112 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 113 |
std::string getInstrumentName(size_t) const override; |
| 114 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 115 |
|
| 116 |
private: |
| 117 |
std::vector<int> ids_; |
| 118 |
std::vector<std::vector<uint8_t>> samples_; |
| 119 |
}; |
| 120 |
|
| 121 |
class P86Bank final : public AbstractBank |
| 122 |
{ |
| 123 |
public: |
| 124 |
P86Bank(const std::vector<int>& ids, const std::vector<std::vector<uint8_t>>& samples); |
| 125 |
|
| 126 |
size_t getNumInstruments() const override; |
| 127 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 128 |
std::string getInstrumentName(size_t) const override; |
| 129 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 130 |
|
| 131 |
private: |
| 132 |
std::vector<int> ids_; |
| 133 |
std::vector<std::vector<uint8_t>> samples_; |
| 134 |
}; |
| 135 |
|
| 136 |
class PpsBank final : public AbstractBank |
| 137 |
{ |
| 138 |
public: |
| 139 |
PpsBank(const std::vector<int>& ids, const std::vector<std::vector<uint8_t>>& samples); |
| 140 |
|
| 141 |
size_t getNumInstruments() const override; |
| 142 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 143 |
std::string getInstrumentName(size_t) const override; |
| 144 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 145 |
|
| 146 |
private: |
| 147 |
std::vector<int> ids_; |
| 148 |
std::vector<std::vector<uint8_t>> samples_; |
| 149 |
}; |
| 150 |
|
| 151 |
class PviBank final : public AbstractBank |
| 152 |
{ |
| 153 |
public: |
| 154 |
PviBank(const std::vector<int>& ids, uint16_t deltaN, const std::vector<std::vector<uint8_t>>& samples); |
| 155 |
|
| 156 |
size_t getNumInstruments() const override; |
| 157 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 158 |
std::string getInstrumentName(size_t) const override; |
| 159 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 160 |
|
| 161 |
private: |
| 162 |
std::vector<int> ids_; |
| 163 |
uint16_t deltaN_; |
| 164 |
std::vector<std::vector<uint8_t>> samples_; |
| 165 |
}; |
| 166 |
|
| 167 |
class PziBank final : public AbstractBank |
| 168 |
{ |
| 169 |
public: |
| 170 |
PziBank(const std::vector<int>& ids, const std::vector<int>& deltaNs, |
| 171 |
const std::vector<bool>& isRepeatedList, const std::vector<std::vector<uint8_t>>& samples); |
| 172 |
|
| 173 |
size_t getNumInstruments() const override; |
| 174 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 175 |
std::string getInstrumentName(size_t) const override; |
| 176 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 177 |
|
| 178 |
private: |
| 179 |
std::vector<int> ids_; |
| 180 |
std::vector<int> deltaNs_; |
| 181 |
std::vector<bool> isRepeatedList_; |
| 182 |
std::vector<std::vector<uint8_t>> samples_; |
| 183 |
}; |
| 184 |
|
| 185 |
class Mucom88Bank final : public AbstractBank |
| 186 |
{ |
| 187 |
public: |
| 188 |
Mucom88Bank(const std::vector<int>& ids, const std::vector<std::string>& names, const std::vector<io::BinaryContainer>& ctrs); |
| 189 |
|
| 190 |
size_t getNumInstruments() const override; |
| 191 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 192 |
std::string getInstrumentName(size_t index) const override; |
| 193 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 194 |
|
| 195 |
void setInstrumentName(size_t index, const std::string& name); |
| 196 |
|
| 197 |
private: |
| 198 |
std::vector<int> ids_; |
| 199 |
std::vector<std::string> names_; |
| 200 |
std::vector<io::BinaryContainer> instCtrs_; |
| 201 |
}; |
| 202 |
|
| 203 |
class PmbBank final : public AbstractBank |
| 204 |
{ |
| 205 |
public: |
| 206 |
PmbBank(const std::vector<int>& ids, const std::vector<std::string>& names, |
| 207 |
const std::vector<std::vector<uint8_t>>& samples); |
| 208 |
|
| 209 |
size_t getNumInstruments() const override; |
| 210 |
std::string getInstrumentIdentifier(size_t index) const override; |
| 211 |
std::string getInstrumentName(size_t) const override; |
| 212 |
AbstractInstrument* loadInstrument(size_t index, std::weak_ptr<InstrumentsManager> instMan, int instNum) const override; |
| 213 |
|
| 214 |
void setInstrumentName(size_t index, const std::string& name); |
| 215 |
|
| 216 |
private: |
| 217 |
std::vector<int> ids_; |
| 218 |
std::vector<std::string> names_; |
| 219 |
std::vector<std::vector<uint8_t>> samples_; |
| 220 |
}; |