Debian Codegraph @

BambooTracker/io/instrument_io.cpp

raw
1 /*
2 * Copyright (C) 2019-2020 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 #include "instrument_io.hpp"
27 #include "file_io_error.hpp"
28 #include "bti_io.hpp"
29 #include "dmp_io.hpp"
30 #include "tfi_io.hpp"
31 #include "vgi_io.hpp"
32 #include "opni_io.hpp"
33 #include "y12_io.hpp"
34 #include "ins_io.hpp"
35 #include "raw_adpcm_io.hpp"
36
37 namespace io
38 {
39 AbstractInstrument* AbstractInstrumentIO::load(const BinaryContainer& ctr, const std::string& fileName,
40 std::weak_ptr<InstrumentsManager> instMan,
41 int instNum) const
42 {
43 (void)ctr;
44 (void)fileName;
45 (void)instMan;
46 (void)instNum;
47 throw FileUnsupportedError(FileType::Inst);
48 }
49
50 void AbstractInstrumentIO::save(BinaryContainer& ctr,
51 const std::weak_ptr<InstrumentsManager> instMan, int instNum) const
52 {
53 (void)ctr;
54 (void)instMan;
55 (void)instNum;
56 throw FileUnsupportedError(FileType::Inst);
57 }
58
59 //------------------------------------------------------------
60
61 std::unique_ptr<InstrumentIO> InstrumentIO::instance_;
62
63 InstrumentIO::InstrumentIO()
64 {
65 handler_.add(new BtiIO);
66 handler_.add(new DmpIO);
67 handler_.add(new TfiIO);
68 handler_.add(new VgiIO);
69 handler_.add(new OpniIO);
70 handler_.add(new Y12IO);
71 handler_.add(new InsIO);
72 handler_.add(new RawAdpcmIO);
73 }
74
75 InstrumentIO& InstrumentIO::getInstance()
76 {
77 if (!instance_) instance_.reset(new InstrumentIO);
78 return *instance_;
79 }
80
81 void InstrumentIO::saveInstrument(BinaryContainer& ctr,
82 const std::weak_ptr<InstrumentsManager> instMan, int instNum)
83 {
84 handler_.at("bti")->save(ctr, instMan, instNum);
85 }
86
87 AbstractInstrument* InstrumentIO::loadInstrument(const BinaryContainer& ctr, const std::string& path,
88 std::weak_ptr<InstrumentsManager> instMan,
89 int instNum)
90 {
91 size_t fnpos = path.find_last_of("/");
92 std::string name = path.substr(fnpos + 1, path.find_last_of(".") - fnpos - 1);
93 return handler_.at(getExtension(path))->load(ctr, name, instMan, instNum);
94 }
95 }