aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/soundlib/tuningcollection.h
blob: bf0b3327a4d4c90e2d71e6b2b7cd057f4db5560c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * tuningCollection.h
 * ------------------
 * Purpose: Alternative sample tuning collection class.
 * Notes  : (currently none)
 * Authors: OpenMPT Devs
 * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
 */


#pragma once

#include "openmpt/all/BuildSettings.hpp"

#include "tuning.h"
#include <vector>
#include <string>


OPENMPT_NAMESPACE_BEGIN


namespace Tuning {


class CTuningCollection
{

public:

	static constexpr char s_FileExtension[4] = ".tc";

	// OpenMPT <= 1.26 had to following limits:
	//  *  255 built-in tunings (only 2 were ever actually provided)
	//  *  255 local tunings
	//  *  255 tune-specific tunings
	// As 1.27 copies all used tunings into the module, the limit of 255 is no
	// longer sufficient. In the worst case scenario, the module contains 255
	// unused tunings and uses 255 local ones. In addition to that, allow the
	// user to additionally import both built-in tunings.
	// Older OpenMPT versions will silently skip loading tunings beyond index
	// 255.
	static constexpr size_t s_nMaxTuningCount = 255 + 255 + 2 ;

public:

	// returns observer ptr if successful
	CTuning* AddTuning(std::unique_ptr<CTuning> pT);
	CTuning* AddTuning(std::istream &inStrm, mpt::Charset defaultCharset);
	
	bool Remove(const std::size_t i);
	bool Remove(const CTuning *pT);

	std::size_t GetNumTunings() const
	{
		return m_Tunings.size();
	}

	CTuning* GetTuning(std::size_t i)
	{
		if(i >= m_Tunings.size())
		{
			return nullptr;
		}
		return m_Tunings[i].get();
	}
	const CTuning* GetTuning(std::size_t i) const
	{
		if (i >= m_Tunings.size())
		{
			return nullptr;
		}
		return m_Tunings[i].get();
	}
	
	CTuning* GetTuning(const mpt::ustring &name);
	const CTuning* GetTuning(const mpt::ustring &name) const;


	Tuning::SerializationResult Serialize(std::ostream &oStrm, const mpt::ustring &name) const;
	Tuning::SerializationResult Deserialize(std::istream &iStrm, mpt::ustring &name, mpt::Charset defaultCharset);

	auto begin() { return m_Tunings.begin(); }
	auto begin() const { return m_Tunings.begin(); }
	auto cbegin() { return m_Tunings.cbegin(); }
	auto end() { return m_Tunings.end(); }
	auto end() const { return m_Tunings.end(); }
	auto cend() { return m_Tunings.cend(); }

private:

	std::vector<std::unique_ptr<CTuning> > m_Tunings;

private:

	Tuning::SerializationResult DeserializeOLD(std::istream &inStrm, mpt::ustring &uname, mpt::Charset defaultCharset);

};


#ifdef MODPLUG_TRACKER
bool UnpackTuningCollection(const CTuningCollection &tc, const mpt::PathString &prefix);
#endif


} // namespace Tuning


typedef Tuning::CTuningCollection CTuningCollection;


OPENMPT_NAMESPACE_END