OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
directmusic.cpp
Go to the documentation of this file.
1#include "directmusic.h"
2
3#include <stdexcept>
4
5#include <Tempest/File>
6#include <utils/fileutil.h>
7#include <system_error>
8#include <stdexcept>
9
10using namespace Dx8;
11
14
16 return PatternList(s,*this);
17 }
18
19PatternList DirectMusic::load(const char16_t *fsgt) {
20 Tempest::RFile fin = implOpen(fsgt);
21 std::vector<uint8_t> v(size_t(fin.size()));
22 fin.read(v.data(), v.size());
23
24 auto r = Dx8::Riff(v.data(), v.size());
25 auto sgt = Dx8::Segment(r);
26 return load(sgt);
27 }
28
29void DirectMusic::addPath(std::u16string p) {
30 path.emplace_back(std::move(p));
31 }
32
34 for(auto& i:styles){
35 if(i.first==id.file)
36 return i.second;
37 }
38
39 Tempest::RFile fin = implOpen(id.file.c_str());
40 const size_t length = fin.size();
41
42 std::vector<uint8_t> data(length);
43 fin.read(&data[0],data.size());
44
45 Riff r{data.data(),data.size()};
46 Style stl(r);
47
48 styles.emplace_back(id.file,std::move(stl));
49 return styles.back().second;
50 }
51
53 return dlsCollection(id.file);
54 }
55
56const DlsCollection &DirectMusic::dlsCollection(const std::u16string &file) {
57 for(auto& i:dls){
58 if(i->first==file)
59 return i->second;
60 }
61 Tempest::RFile fin = implOpen(file.c_str());
62 const size_t length = fin.size();
63
64 std::vector<uint8_t> data(length);
65 fin.read(reinterpret_cast<char*>(&data[0]),data.size());
66
67 Riff r{data.data(),data.size()};
68 DlsCollection stl(r);
69
70 dls.emplace_back(new std::pair<std::u16string,DlsCollection>(file,std::move(stl)));
71 return dls.back()->second;
72 }
73
74Tempest::RFile DirectMusic::implOpen(const char16_t *file) {
75 for(auto& pt:path) {
76 try {
77 std::u16string filepath = FileUtil::nestedPath(pt, {file}, Tempest::Dir::FT_File);
78 Tempest::RFile fin(filepath);
79 return fin;
80 }
81 catch(std::system_error&){
82 }
83 }
84 throw std::runtime_error("file not found");
85 }
PatternList load(const Segment &s)
const DlsList & dlsCollection()
Definition directmusic.h:33
const Style & style(const Reference &id)
void addPath(std::u16string path)
Definition band.h:10
std::u16string nestedPath(std::u16string_view gpath, const std::initializer_list< const char16_t * > &name, Tempest::Dir::FileType type)