Initial commit
This commit is contained in:
commit
acadc92e68
780 files changed
+468285
No files matched your search
@@ -0,0 +1,168 @@
|
||||
# clang-format 13
|
||||
|
||||
Language: Cpp
|
||||
Standard: c++20
|
||||
|
||||
AccessModifierOffset: -4 #?
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveBitFields: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveMacros: true
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: true
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: true
|
||||
AfterControlStatement: Always
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
#AfterObjCDeclaration
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: true
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
#BreakAfterJavaFieldAnnotations
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: '' #?
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 4 #?
|
||||
ContinuationIndentWidth: 4 #?
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
EmptyLineAfterAccessModifier: Leave
|
||||
EmptyLineBeforeAccessModifier: Leave
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros: []
|
||||
IfMacros: ['MPT_MAYBE_CONSTANT_IF']
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories: [] #?
|
||||
IncludeIsMainRegex: '' #?
|
||||
IncludeIsMainSourceRegex: '' #?
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: NoIndent
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
#IndentRequiresClause: true
|
||||
#BeforeHash
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: true
|
||||
InsertTrailingCommas: None
|
||||
#JavaImportGroups
|
||||
#JavaScriptQuotes
|
||||
#JavaScriptWrapImports
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
LambdaBodyIndentation: OuterScope
|
||||
MacroBlockBegin: '^MPT_TEST_GROUP_BEGIN|BEGIN_MESSAGE_MAP$' #?
|
||||
MacroBlockEnd: '^MPT_TEST_GROUP_END|END_MESSAGE_MAP$' #?
|
||||
MaxEmptyLinesToKeep: 5
|
||||
NamespaceIndentation: None
|
||||
NamespaceMacros: [] #?
|
||||
#ObjCBinPackProtocolList
|
||||
#ObjCBlockIndentWidth
|
||||
#ObjCBreakBeforeNestedBlockParam
|
||||
#ObjCSpaceAfterProperty
|
||||
#ObjCSpaceBeforeProtocolList
|
||||
PackConstructorInitializers: Never
|
||||
#PenaltyBreakAssignment
|
||||
#PenaltyBreakBeforeFirstCallParameter
|
||||
#PenaltyBreakComment
|
||||
#PenaltyBreakFirstLessLess
|
||||
#PenaltyBreakOpenParenthesis
|
||||
#PenaltyBreakString
|
||||
#PenaltyBreakTemplateDeclaration
|
||||
#PenaltyExcessCharacter
|
||||
#PenaltyIndentedWhitespace
|
||||
#PenaltyReturnTypeOnItsOwnLine
|
||||
PointerAlignment: Right
|
||||
PPIndentWidth: -1
|
||||
QualifierAlignment: Leave
|
||||
#QualifierOrder: ['static', 'inline', 'constexpr', 'volatile', 'const', 'restrict', 'type']
|
||||
#RawStringFormats
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: false
|
||||
RemoveBracesLLVM: false
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: false
|
||||
#SortJavaStaticImport
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: Never
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: false
|
||||
AfterForeachMacros: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterIfMacros: false
|
||||
AfterOverloadedOperator: false
|
||||
#AfterRequiresInClause: false
|
||||
#AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
StatementAttributeLikeMacros: []
|
||||
StatementMacros: [ 'OPENMPT_NAMESPACE_BEGIN', 'OPENMPT_NAMESPACE_END', 'MPT_MSVC_WORKAROUND_LNK4221', 'MPT_WARNING', 'MPT_TEST_GROUP_INLINE_IDENTIFIER', 'MPT_TEST_GROUP_INLINE', 'MPT_TEST_GROUP_STATIC' ] #?
|
||||
TabWidth: 4
|
||||
TypenameMacros: [] #?
|
||||
UseCRLF: false
|
||||
UseTab: ForContinuationAndIndentation
|
||||
WhitespaceSensitiveMacros:
|
||||
- MPT_PP_STRINGIFY
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,25 @@
|
||||
Copyright (c) 2004-2026, OpenMPT Project Developers and Contributors
|
||||
Copyright (c) 1997-2003, Olivier Lapicque
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the OpenMPT project nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,731 @@
|
||||
ACLOCAL_AMFLAGS = -I m4 --install
|
||||
EXTRA_DIST =
|
||||
EXTRA_DIST += .clang-format
|
||||
EXTRA_DIST += m4/emptydir
|
||||
EXTRA_DIST += libopenmpt/libopenmpt.pc.in
|
||||
EXTRA_DIST += LICENSE
|
||||
EXTRA_DIST += README.md
|
||||
EXTRA_DIST += Doxyfile.in
|
||||
EXTRA_DIST += doc/contributing.md
|
||||
EXTRA_DIST += doc/libopenmpt_styleguide.md
|
||||
EXTRA_DIST += doc/libopenmpt/changelog.md
|
||||
EXTRA_DIST += doc/libopenmpt/dependencies.md
|
||||
EXTRA_DIST += doc/libopenmpt/gettingstarted.md
|
||||
EXTRA_DIST += doc/libopenmpt/index.dox
|
||||
EXTRA_DIST += doc/libopenmpt/packaging.md
|
||||
EXTRA_DIST += doc/libopenmpt/tests.md
|
||||
EXTRA_DIST += doc/module_formats.md
|
||||
EXTRA_DIST += doc/openmpt_styleguide.md
|
||||
EXTRA_DIST += libopenmpt/.clang-format
|
||||
EXTRA_DIST += libopenmpt/libopenmpt_version.mk
|
||||
EXTRA_DIST += openmpt123/.clang-format
|
||||
EXTRA_DIST += src/mpt/.clang-format
|
||||
EXTRA_DIST += src/mpt/LICENSE.BSD-3-Clause.txt
|
||||
EXTRA_DIST += src/mpt/LICENSE.BSL-1.0.txt
|
||||
EXTRA_DIST += test/test.xm
|
||||
EXTRA_DIST += test/test.s3m
|
||||
EXTRA_DIST += test/test.mod
|
||||
EXTRA_DIST += test/test.mptm
|
||||
EXTRA_DIST += man/openmpt123.1
|
||||
EXTRA_DIST += examples/.clang-format
|
||||
EXTRA_DIST += libopenmpt/bindings/freebasic/libopenmpt.bi
|
||||
EXTRA_DIST += libopenmpt/bindings/freebasic/libopenmpt_ext.bi
|
||||
MOSTLYCLEANFILES =
|
||||
|
||||
dist_doc_DATA =
|
||||
dist_doc_DATA += LICENSE
|
||||
dist_doc_DATA += README.md
|
||||
nobase_dist_doc_DATA =
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_cxx.cpp
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_c_mem.c
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_c_unsafe.c
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_c.c
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_c_pipe.c
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_c_probe.c
|
||||
nobase_dist_doc_DATA += examples/libopenmpt_example_c_stdout.c
|
||||
|
||||
bin_PROGRAMS =
|
||||
check_PROGRAMS =
|
||||
lib_LTLIBRARIES =
|
||||
if ENABLE_TESTS
|
||||
TESTS = libopenmpttest
|
||||
endif
|
||||
|
||||
if ENABLE_EXAMPLES
|
||||
|
||||
check_PROGRAMS += libopenmpt_example_c_pipe
|
||||
check_PROGRAMS += libopenmpt_example_c_probe
|
||||
check_PROGRAMS += libopenmpt_example_c_stdout
|
||||
if HAVE_PORTAUDIO
|
||||
check_PROGRAMS += libopenmpt_example_c
|
||||
check_PROGRAMS += libopenmpt_example_c_mem
|
||||
check_PROGRAMS += libopenmpt_example_c_unsafe
|
||||
endif
|
||||
if HAVE_PORTAUDIOCPP
|
||||
check_PROGRAMS += libopenmpt_example_cxx
|
||||
endif
|
||||
|
||||
libopenmpt_example_c_pipe_SOURCES = examples/libopenmpt_example_c_pipe.c
|
||||
libopenmpt_example_c_probe_SOURCES = examples/libopenmpt_example_c_probe.c
|
||||
libopenmpt_example_c_stdout_SOURCES = examples/libopenmpt_example_c_stdout.c
|
||||
if HAVE_PORTAUDIO
|
||||
libopenmpt_example_c_SOURCES = examples/libopenmpt_example_c.c
|
||||
libopenmpt_example_c_mem_SOURCES = examples/libopenmpt_example_c_mem.c
|
||||
libopenmpt_example_c_unsafe_SOURCES = examples/libopenmpt_example_c_unsafe.c
|
||||
endif
|
||||
if HAVE_PORTAUDIOCPP
|
||||
libopenmpt_example_cxx_SOURCES = examples/libopenmpt_example_cxx.cpp
|
||||
endif
|
||||
|
||||
libopenmpt_example_c_pipe_CPPFLAGS = $(WIN32_CPPFLAGS)
|
||||
libopenmpt_example_c_probe_CPPFLAGS = $(WIN32_CPPFLAGS)
|
||||
libopenmpt_example_c_stdout_CPPFLAGS = $(WIN32_CPPFLAGS)
|
||||
if HAVE_PORTAUDIO
|
||||
libopenmpt_example_c_CPPFLAGS = $(WIN32_CPPFLAGS) $(PORTAUDIO_CFLAGS)
|
||||
libopenmpt_example_c_mem_CPPFLAGS = $(WIN32_CPPFLAGS) $(PORTAUDIO_CFLAGS)
|
||||
libopenmpt_example_c_unsafe_CPPFLAGS = $(WIN32_CPPFLAGS) $(PORTAUDIO_CFLAGS)
|
||||
endif
|
||||
if HAVE_PORTAUDIOCPP
|
||||
libopenmpt_example_cxx_CPPFLAGS = $(WIN32_CPPFLAGS) $(PORTAUDIOCPP_CFLAGS)
|
||||
endif
|
||||
|
||||
libopenmpt_example_c_pipe_CFLAGS = $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
libopenmpt_example_c_probe_CFLAGS = $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
libopenmpt_example_c_stdout_CFLAGS = $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
if HAVE_PORTAUDIO
|
||||
libopenmpt_example_c_CFLAGS = $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
libopenmpt_example_c_mem_CFLAGS = $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
libopenmpt_example_c_unsafe_CFLAGS = $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
endif
|
||||
if HAVE_PORTAUDIOCPP
|
||||
libopenmpt_example_cxx_CXXFLAGS = $(GLOBAL_CXXFLAGS) $(WIN32_CXXFLAGS) $(WIN32_CONSOLE_CXXFLAGS)
|
||||
endif
|
||||
|
||||
libopenmpt_example_c_pipe_LDADD = $(lib_LTLIBRARIES)
|
||||
libopenmpt_example_c_probe_LDADD = $(lib_LTLIBRARIES)
|
||||
libopenmpt_example_c_stdout_LDADD = $(lib_LTLIBRARIES)
|
||||
if HAVE_PORTAUDIO
|
||||
libopenmpt_example_c_LDADD = $(lib_LTLIBRARIES) $(PORTAUDIO_LIBS)
|
||||
libopenmpt_example_c_mem_LDADD = $(lib_LTLIBRARIES) $(PORTAUDIO_LIBS)
|
||||
libopenmpt_example_c_unsafe_LDADD = $(lib_LTLIBRARIES) $(PORTAUDIO_LIBS)
|
||||
endif
|
||||
if HAVE_PORTAUDIOCPP
|
||||
libopenmpt_example_cxx_LDADD = $(lib_LTLIBRARIES) $(PORTAUDIOCPP_LIBS)
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA =
|
||||
includelibopenmptdir = $(includedir)/libopenmpt
|
||||
includelibopenmpt_HEADERS =
|
||||
|
||||
MPT_FILES_SRC_MPT =
|
||||
MPT_FILES_SRC_MPT += src/mpt/arch/arch.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/arch/feature_fence.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/arch/feature_flags.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/arch/x86_amd64.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/audio/sample.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/audio/span.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/algorithm.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/aligned_array.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/alloc.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/arithmetic_shift.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/array.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/bit.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/check_platform.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/compiletime_warning.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/constexpr_throw.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/debugging.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect_arch.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect_compiler.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect_libc.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect_libcxx.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect_os.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/detect_quirks.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/float.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/integer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/macros.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/math.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/memory.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/namespace.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/numbers.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/numeric.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/pointer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/preprocessor.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/saturate_cast.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/saturate_round.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/secure.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/semantic_version.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/size.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/source_location.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/span.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/type_traits.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/utility.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/version.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/wrapping_divide.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/binary/base64.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/binary/base64url.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/binary/hex.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/check/compiler.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/check/libc.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/check/libcxx.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/check/mfc.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/check/windows.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/crc/crc.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/crypto/exception.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/crypto/hash.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/crypto/jwk.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/detect/dl.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/detect/ltdl.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/detect/mfc.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/detect/nlohmann_json.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/floatingpoint.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/int24.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/integer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/type_traits.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/environment/environment.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/exception/exception.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/exception/exception_text.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/exception/logic_error.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/exception/runtime_error.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/concat.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/default_floatingpoint.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/default_formatter.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/default_integer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/default_string.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/helpers.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/join.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/message.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/message_macros.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/simple.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/simple_floatingpoint.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/simple_integer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/simple_spec.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/fs/common_directories.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/fs/fs.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io/base.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io/io.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io/io_span.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io/io_stdstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io/io_virtual_wrapper.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file/fileref.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file/fstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file/inputfile.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file/outputfile.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file_adapter/fileadapter.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file_read/inputfile_filecursor.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file_unique/unique_basename.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_file_unique/unique_tempfilename.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/callbackstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor_callbackstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor_filename_traits.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor_memory.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor_stdstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor_traits_filedata.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filecursor_traits_memory.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_base.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_base_buffered.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_base_seekable.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_base_unseekable.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_base_unseekable_buffer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_callbackstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_memory.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filedata_stdstream.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_read/filereader.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io_write/buffer.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/json/json.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/library/library.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/main/main.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/mutex/mutex.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/osinfo/class.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/osinfo/dos_memory.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/osinfo/dos_version.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/osinfo/windows_version.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/osinfo/windows_wine_version.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/out_of_memory/out_of_memory.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/parse/parse.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/parse/split.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/path/basic_path.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/path/native_path.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/path/path.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/path/os_path.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/path/os_path_long.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/any_engine.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/crand.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/default_engines.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/device.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/engine.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/engine_lcg.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/random.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/seed.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string/buffer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string/types.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string/utility.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string_transcode/transcode.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string_transcode/macros.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/system_error/system_error.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/test/test.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/test/test_macros.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/uuid/guid.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/uuid/uuid.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/uuid_namespace/uuid_namespace.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_arithmetic_shift.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_bit.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_math.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_numeric.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_saturate_cast.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_saturate_round.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/base/tests/tests_base_wrapping_divide.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/binary/tests/tests_binary.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/crc/tests/tests_crc.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/crypto/tests/tests_crypto.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/tests/tests_endian_floatingpoint.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/tests/tests_endian_int24.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/endian/tests/tests_endian_integer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/tests/tests_format_message.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/format/tests/tests_format_simple.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/io/tests/tests_io.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/parse/tests/tests_parse.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/random/tests/tests_random.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string/tests/tests_string_buffer.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string/tests/tests_string_utility.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/string_transcode/tests/tests_string_transcode.hpp
|
||||
MPT_FILES_SRC_MPT += src/mpt/uuid/tests/tests_uuid.hpp
|
||||
#MPT_FILES_SRC_MPT += src/mpt/uuid_namespace/tests/tests_uuid_namespace.hpp
|
||||
MPT_FILES_SRC_OPENMPT =
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/all/BuildSettings.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/all/PlatformFixes.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/base/Endian.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/base/FlagSet.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/base/Int24.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/base/Types.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/fileformat_base/magic.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/logging/Logger.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/random/ModPlug.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/Copy.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/CopyMix.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/Dither.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/DitherModPlug.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/DitherNone.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/DitherSimple.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/MixSample.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/MixSampleConvert.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleClip.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleClipFixedPoint.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleConvert.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleConvertFixedPoint.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleDecode.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleEncode.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundbase/SampleFormat.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundfile_data/tags.hpp
|
||||
MPT_FILES_SRC_OPENMPT += src/openmpt/soundfile_data/wav.hpp
|
||||
MPT_FILES_SRC_OPENMPT_SOUNDFILE_WRITE =
|
||||
MPT_FILES_SRC_OPENMPT_SOUNDFILE_WRITE += src/openmpt/soundfile_write/wav_write.cpp
|
||||
MPT_FILES_SRC_OPENMPT_SOUNDFILE_WRITE += src/openmpt/soundfile_write/wav_write.hpp
|
||||
MPT_FILES_COMMON =
|
||||
MPT_FILES_COMMON += common/BuildSettings.h
|
||||
MPT_FILES_COMMON += common/BuildSettingsCompiler.h
|
||||
MPT_FILES_COMMON += common/ComponentManager.cpp
|
||||
MPT_FILES_COMMON += common/ComponentManager.h
|
||||
MPT_FILES_COMMON += common/FileReader.h
|
||||
MPT_FILES_COMMON += common/FileReaderFwd.h
|
||||
MPT_FILES_COMMON += common/GzipWriter.h
|
||||
MPT_FILES_COMMON += common/Logging.cpp
|
||||
MPT_FILES_COMMON += common/Logging.h
|
||||
MPT_FILES_COMMON += common/misc_util.h
|
||||
MPT_FILES_COMMON += common/mptAssert.h
|
||||
MPT_FILES_COMMON += common/mptBaseMacros.h
|
||||
MPT_FILES_COMMON += common/mptBaseTypes.h
|
||||
MPT_FILES_COMMON += common/mptBaseUtils.h
|
||||
MPT_FILES_COMMON += common/mptCPU.h
|
||||
MPT_FILES_COMMON += common/mptFileIO.h
|
||||
MPT_FILES_COMMON += common/mptFileTemporary.h
|
||||
MPT_FILES_COMMON += common/mptFileType.cpp
|
||||
MPT_FILES_COMMON += common/mptFileType.h
|
||||
MPT_FILES_COMMON += common/mptPathString.cpp
|
||||
MPT_FILES_COMMON += common/mptPathString.h
|
||||
MPT_FILES_COMMON += common/mptRandom.cpp
|
||||
MPT_FILES_COMMON += common/mptRandom.h
|
||||
MPT_FILES_COMMON += common/mptString.h
|
||||
MPT_FILES_COMMON += common/mptStringBuffer.cpp
|
||||
MPT_FILES_COMMON += common/mptStringBuffer.h
|
||||
MPT_FILES_COMMON += common/mptStringFormat.h
|
||||
MPT_FILES_COMMON += common/mptTime.cpp
|
||||
MPT_FILES_COMMON += common/mptTime.h
|
||||
MPT_FILES_COMMON += common/Profiler.cpp
|
||||
MPT_FILES_COMMON += common/Profiler.h
|
||||
MPT_FILES_COMMON += common/serialization_utils.cpp
|
||||
MPT_FILES_COMMON += common/serialization_utils.h
|
||||
MPT_FILES_COMMON += common/stdafx.h
|
||||
MPT_FILES_COMMON += common/version.cpp
|
||||
MPT_FILES_COMMON += common/version.h
|
||||
MPT_FILES_COMMON += common/versionNumber.h
|
||||
MPT_FILES_SOUNDLIB =
|
||||
MPT_FILES_SOUNDLIB += soundlib/AudioCriticalSection.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/AudioCriticalSection.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/AudioReadTarget.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/BitReader.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ContainerMMCMP.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ContainerPP20.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ContainerUMX.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ContainerXPK.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Container.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Dlsbank.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Dlsbank.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Fastmix.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/FloatMixer.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/InstrumentExtensions.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/InstrumentSynth.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/InstrumentSynth.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/IntMixer.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ITCompression.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ITCompression.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ITTools.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ITTools.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_667.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_669.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_amf.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_ams.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_c67.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_cba.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_dbm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_digi.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_dmf.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_dsm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_dsym.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_dtm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Loaders.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_etx.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_far.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_fc.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_fmt.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_ftm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_gdm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_gmc.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_gt2.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_ice.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_imf.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_ims.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_it.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_itp.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/load_j2b.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_kris.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mdl.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_med.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mid.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mo3.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mod.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mt2.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mtm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_mus_km.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_okt.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_plm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_psm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_pt36.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_ptm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_puma.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_rtm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_s3m.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_sfx.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_stk.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_stm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_stp.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_symmod.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_tcb.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_uax.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_ult.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_unic.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_wav.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_xm.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Load_xmf.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Message.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Message.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MIDIEvents.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MIDIEvents.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MIDIMacroParser.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MIDIMacroParser.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MIDIMacros.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MIDIMacros.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Mixer.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixerInterface.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixerLoops.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixerLoops.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixerSettings.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixerSettings.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixFuncTable.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MixFuncTable.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModChannel.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModChannel.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/modcommand.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/modcommand.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModInstrument.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModInstrument.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModSample.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModSample.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModSampleCopy.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModSequence.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/ModSequence.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/modsmp_ctrl.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/modsmp_ctrl.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/mod_specifications.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/mod_specifications.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MODTools.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MODTools.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/MPEGFrame.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/MPEGFrame.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/OggStream.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/OggStream.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/opal.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/OPL.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/OPL.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Paula.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Paula.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/patternContainer.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/patternContainer.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/pattern.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/pattern.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/PlaybackTest.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/PlaybackTest.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/PlayState.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/PlayState.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Resampler.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/RowVisitor.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/RowVisitor.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/S3MTools.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/S3MTools.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleCopy.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormats.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatBRR.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatFLAC.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatMediaFoundation.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatMP3.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatOpus.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatSFZ.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleFormatVorbis.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleIO.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleIO.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/SampleNormalize.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Snd_defs.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Sndfile.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Sndfile.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Snd_flt.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Snd_fx.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Sndmix.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SoundFilePlayConfig.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/SoundFilePlayConfig.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Tables.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Tables.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/Tagging.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/Tagging.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/TinyFFT.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/TinyFFT.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/tuningbase.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/tuningCollection.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/tuningcollection.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/tuning.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/tuning.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/UMXTools.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/UMXTools.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/UpgradeModule.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/WAVTools.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/WAVTools.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/WindowedFIR.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/WindowedFIR.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/XMTools.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/XMTools.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/DMOPlugin.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/DMOPlugin.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/DMOUtils.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/DMOUtils.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Chorus.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Chorus.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Compressor.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Compressor.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Distortion.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Distortion.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Echo.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Echo.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Flanger.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Flanger.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Gargle.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/Gargle.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/I3DL2Reverb.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/I3DL2Reverb.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/ParamEq.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/ParamEq.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/WavesReverb.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/dmo/WavesReverb.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/DigiBoosterEcho.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/DigiBoosterEcho.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/LFOPlugin.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/LFOPlugin.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/PluginManager.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/PluginManager.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/PluginMixBuffer.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/PluginStructs.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/PlugInterface.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/PlugInterface.h
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/SymMODEcho.cpp
|
||||
MPT_FILES_SOUNDLIB += soundlib/plugins/SymMODEcho.h
|
||||
MPT_FILES_SOUNDDSP =
|
||||
MPT_FILES_SOUNDDSP += sounddsp/AGC.cpp
|
||||
MPT_FILES_SOUNDDSP += sounddsp/AGC.h
|
||||
MPT_FILES_SOUNDDSP += sounddsp/DSP.cpp
|
||||
MPT_FILES_SOUNDDSP += sounddsp/DSP.h
|
||||
MPT_FILES_SOUNDDSP += sounddsp/EQ.cpp
|
||||
MPT_FILES_SOUNDDSP += sounddsp/EQ.h
|
||||
MPT_FILES_SOUNDDSP += sounddsp/Reverb.cpp
|
||||
MPT_FILES_SOUNDDSP += sounddsp/Reverb.h
|
||||
|
||||
pkgconfig_DATA += libopenmpt/libopenmpt.pc
|
||||
lib_LTLIBRARIES += libopenmpt.la
|
||||
libopenmpt_la_LDFLAGS = -version-info $(LIBOPENMPT_LTVER_CURRENT):$(LIBOPENMPT_LTVER_REVISION):$(LIBOPENMPT_LTVER_AGE) -no-undefined
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt.hpp
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_version.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_config.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_buffer.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_fd.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_file.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_file_mingw.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_file_posix.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_ext.h
|
||||
includelibopenmpt_HEADERS += libopenmpt/libopenmpt_ext.hpp
|
||||
libopenmpt_la_CPPFLAGS =
|
||||
libopenmpt_la_CPPFLAGS += $(GLOBAL_CPPFLAGS) $(WIN32_CPPFLAGS) -DLIBOPENMPT_BUILD -I$(srcdir)/ -I$(srcdir)/src -I$(srcdir)/common $(ZLIB_CFLAGS) $(MPG123_CFLAGS) $(OGG_CFLAGS) $(VORBIS_CFLAGS) $(VORBISFILE_CFLAGS)
|
||||
libopenmpt_la_CXXFLAGS =
|
||||
libopenmpt_la_CXXFLAGS += $(GLOBAL_CXXFLAGS) $(WIN32_CXXFLAGS) $(ZLIB_CFLAGS) $(MPG123_CFLAGS) $(OGG_CFLAGS) $(VORBIS_CFLAGS) $(VORBISFILE_CFLAGS)
|
||||
libopenmpt_la_CFLAGS =
|
||||
libopenmpt_la_CFLAGS += $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(ZLIB_CFLAGS) $(MPG123_CFLAGS) $(OGG_CFLAGS) $(VORBIS_CFLAGS) $(VORBISFILE_CFLAGS)
|
||||
libopenmpt_la_LIBADD =
|
||||
libopenmpt_la_LIBADD += $(ZLIB_LIBS) $(MPG123_LIBS) $(OGG_LIBS) $(VORBIS_LIBS) $(VORBISFILE_LIBS) $(LIBOPENMPT_WIN32_LIBS)
|
||||
libopenmpt_la_SOURCES =
|
||||
libopenmpt_la_SOURCES += build/svn_version/svn_version.h
|
||||
libopenmpt_la_SOURCES += $(MPT_FILES_SRC_MPT)
|
||||
libopenmpt_la_SOURCES += $(MPT_FILES_SRC_OPENMPT)
|
||||
libopenmpt_la_SOURCES += $(MPT_FILES_COMMON)
|
||||
libopenmpt_la_SOURCES += $(MPT_FILES_SOUNDBASE)
|
||||
libopenmpt_la_SOURCES += $(MPT_FILES_SOUNDLIB)
|
||||
libopenmpt_la_SOURCES += $(MPT_FILES_SOUNDDSP)
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_c.cpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_cxx.cpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_ext_impl.cpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_impl.cpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_config.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_ext.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_ext.hpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_ext_impl.hpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt.hpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_impl.hpp
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_internal.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_buffer.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_fd.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_mingw.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_posix.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h
|
||||
libopenmpt_la_SOURCES += libopenmpt/libopenmpt_version.h
|
||||
|
||||
if ENABLE_TESTS
|
||||
check_PROGRAMS += libopenmpttest
|
||||
libopenmpttest_CPPFLAGS =
|
||||
libopenmpttest_CPPFLAGS += $(GLOBAL_CPPFLAGS) $(WIN32_CPPFLAGS) -DLIBOPENMPT_BUILD -DLIBOPENMPT_BUILD_TEST -I$(srcdir)/ -I$(srcdir)/src -I$(srcdir)/common $(ZLIB_CFLAGS) $(MPG123_CFLAGS) $(OGG_CFLAGS) $(VORBIS_CFLAGS) $(VORBISFILE_CFLAGS)
|
||||
libopenmpttest_CXXFLAGS =
|
||||
libopenmpttest_CXXFLAGS += $(GLOBAL_CXXFLAGS) $(WIN32_CXXFLAGS) $(ZLIB_CFLAGS) $(MPG123_CFLAGS) $(OGG_CFLAGS) $(VORBIS_CFLAGS) $(VORBISFILE_CFLAGS) $(WIN32_CONSOLE_CXXFLAGS)
|
||||
libopenmpttest_CFLAGS =
|
||||
libopenmpttest_CFLAGS += $(GLOBAL_CFLAGS) $(WIN32_CFLAGS) $(ZLIB_CFLAGS) $(MPG123_CFLAGS) $(OGG_CFLAGS) $(VORBIS_CFLAGS) $(VORBISFILE_CFLAGS) $(WIN32_CONSOLE_CFLAGS)
|
||||
libopenmpttest_LDADD =
|
||||
libopenmpttest_LDADD += $(ZLIB_LIBS) $(MPG123_LIBS) $(OGG_LIBS) $(VORBIS_LIBS) $(VORBISFILE_LIBS) $(LIBOPENMPT_WIN32_LIBS) $(LIBOPENMPTTEST_WIN32_LIBS)
|
||||
libopenmpttest_SOURCES =
|
||||
libopenmpttest_SOURCES += test/mpt_tests_base.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_binary.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_crc.cpp
|
||||
#libopenmpttest_SOURCES += test/mpt_tests_crypto.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_endian.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_format.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_io.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_parse.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_random.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_string.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_string_transcode.cpp
|
||||
libopenmpttest_SOURCES += test/mpt_tests_uuid.cpp
|
||||
#libopenmpttest_SOURCES += test/mpt_tests_uuid_namespace.cpp
|
||||
libopenmpttest_SOURCES += test/test.cpp
|
||||
libopenmpttest_SOURCES += test/test.h
|
||||
libopenmpttest_SOURCES += test/TestTools.h
|
||||
libopenmpttest_SOURCES += test/TestToolsLib.cpp
|
||||
libopenmpttest_SOURCES += test/TestToolsLib.h
|
||||
libopenmpttest_SOURCES += test/TestToolsTracker.h
|
||||
libopenmpttest_SOURCES += build/svn_version/svn_version.h
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_SRC_MPT)
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_SRC_OPENMPT)
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_SRC_OPENMPT_SOUNDFILE_WRITE)
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_COMMON)
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_SOUNDBASE)
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_SOUNDLIB)
|
||||
libopenmpttest_SOURCES += $(MPT_FILES_SOUNDDSP)
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_c.cpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_cxx.cpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_ext_impl.cpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_impl.cpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_config.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_ext.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_ext.hpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_ext_impl.hpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt.hpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_impl.hpp
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_internal.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_buffer.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_fd.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_mingw.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_posix.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_version.h
|
||||
libopenmpttest_SOURCES += libopenmpt/libopenmpt_test/libopenmpt_test.cpp
|
||||
endif
|
||||
|
||||
if ENABLE_OPENMPT123
|
||||
|
||||
bin_PROGRAMS += bin/openmpt123
|
||||
bin_openmpt123_CPPFLAGS =
|
||||
bin_openmpt123_CPPFLAGS += $(GLOBAL_CPPFLAGS) $(WIN32_CPPFLAGS) -I$(srcdir)/src $(PORTAUDIO_CFLAGS) $(PULSEAUDIO_CFLAGS) $(SDL2_CFLAGS) $(SNDFILE_CFLAGS) $(FLAC_CFLAGS)
|
||||
bin_openmpt123_CXXFLAGS =
|
||||
bin_openmpt123_CXXFLAGS += $(GLOBAL_CXXFLAGS) $(WIN32_CXXFLAGS) $(WIN32_CONSOLE_CXXFLAGS)
|
||||
bin_openmpt123_LDADD = libopenmpt.la $(PORTAUDIO_LIBS) $(PULSEAUDIO_LIBS) $(SDL2_LIBS) $(SNDFILE_LIBS) $(FLAC_LIBS) $(OPENMPT123_WIN32_LIBS)
|
||||
bin_openmpt123_SOURCES =
|
||||
bin_openmpt123_SOURCES += $(MPT_FILES_SRC_MPT)
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_allegro42.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_config.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123.cpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_exception.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_flac.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_mmio.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_portaudio.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_pulseaudio.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_raw.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_sdl2.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_sndfile.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_stdio.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_stdout.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_terminal.hpp
|
||||
bin_openmpt123_SOURCES += openmpt123/openmpt123_waveout.hpp
|
||||
|
||||
man1_MANS = man/openmpt123.1
|
||||
|
||||
endif
|
||||
|
||||
@DX_RULES@
|
||||
|
||||
MOSTLYCLEANFILES += $(DX_CLEANFILES)
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,81 @@
|
||||
|
||||
README
|
||||
======
|
||||
|
||||
|
||||
OpenMPT and libopenmpt
|
||||
======================
|
||||
|
||||
This repository contains OpenMPT, a free Windows/Wine-based
|
||||
[tracker](https://en.wikipedia.org/wiki/Music_tracker) and libopenmpt,
|
||||
a library to render tracker music (MOD, XM, S3M, IT MPTM and dozens of other
|
||||
legacy formats) to a PCM audio stream. libopenmpt is directly based on OpenMPT,
|
||||
offering the same playback quality and format support, and development of the
|
||||
two happens in parallel.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
The OpenMPT/libopenmpt project is distributed under the *BSD-3-Clause* License.
|
||||
See [LICENSE](LICENSE) for the full license text.
|
||||
|
||||
Files below the `include/` (external projects) and `contrib/` (related assets
|
||||
not directly considered integral part of the project) folders may be subject to
|
||||
other licenses. See the respective subfolders for license information. These
|
||||
folders are not distributed in all source packages, and in particular they are
|
||||
not distributed in the Autotools packages.
|
||||
|
||||
|
||||
How to compile
|
||||
--------------
|
||||
|
||||
|
||||
### OpenMPT
|
||||
|
||||
- Supported Visual Studio versions:
|
||||
|
||||
- Visual Studio 2019, and 2022 Community/Professional/Enterprise
|
||||
|
||||
To compile the project, open `build/vsVERSIONwin7/OpenMPT.sln` (VERSION
|
||||
being 2019, or 2022) and hit the compile button. Other target systems
|
||||
can be found in the `vs2019*`, and `vs2022*` sibling folders.
|
||||
|
||||
Note that you have to build the `PluginBridge` and `PluginBridgeLegacy`
|
||||
projects manually for architectures other than the one you are building
|
||||
OpenMPT for, as Visual Studio only builds one architecture configuration
|
||||
at a time.
|
||||
|
||||
Please note that we do not support building with a later Visual Studio
|
||||
installation with an earlier compiler version. This is because, while
|
||||
later Visual Studio versions allow installing earlier compilers to be
|
||||
available via the later version's environment, in this configuration,
|
||||
the earlier compiler will still use the later C and C++ runtime's
|
||||
headers and implementation, which significantly increases the matrix of
|
||||
possible configurations to test.
|
||||
|
||||
- Visual Studio 2017 XP targeting toolset
|
||||
|
||||
- OpenMPT requires the compile host system to be Windows 8.1 (or later) on
|
||||
amd64 for VS2019 and VS2017, Windows 10 (or later) on amd64 for VS2022, or
|
||||
Windows 11 (or later) ARM64.
|
||||
|
||||
- In order to build OpenMPT for Windows XP, the Visual Studio 2017 XP
|
||||
targeting toolset as well as the Windows 8.1 SDK need to be installed. The
|
||||
SDK is optionally included with Visual Studio 2017.
|
||||
|
||||
- Microsoft Foundation Classes (MFC) are required to build OpenMPT.
|
||||
|
||||
|
||||
### libopenmpt and openmpt123
|
||||
|
||||
See [Dependencies](doc/libopenmpt/dependencies.md) and
|
||||
[Getting Started](doc/libopenmpt/gettingstarted.md).
|
||||
|
||||
|
||||
Contributing to OpenMPT/libopenmpt
|
||||
----------------------------------
|
||||
|
||||
|
||||
See [contributing](doc/contributing.md).
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Vendored
+1226
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,450 @@
|
||||
# This file was generated by Autom4te 2.71.
|
||||
# It contains the lists of macros which have been traced.
|
||||
# It can be safely removed.
|
||||
|
||||
@request = (
|
||||
bless( [
|
||||
'0',
|
||||
1,
|
||||
[
|
||||
'/usr/share/autoconf'
|
||||
],
|
||||
[
|
||||
'/usr/share/autoconf/autoconf/autoconf.m4f',
|
||||
'/usr/share/aclocal-1.16/internal/ac-config-macro-dirs.m4',
|
||||
'/usr/share/aclocal/ltargz.m4',
|
||||
'/usr/share/aclocal/ltdl.m4',
|
||||
'/usr/share/aclocal-1.16/amversion.m4',
|
||||
'/usr/share/aclocal-1.16/ar-lib.m4',
|
||||
'/usr/share/aclocal-1.16/auxdir.m4',
|
||||
'/usr/share/aclocal-1.16/cond.m4',
|
||||
'/usr/share/aclocal-1.16/depend.m4',
|
||||
'/usr/share/aclocal-1.16/depout.m4',
|
||||
'/usr/share/aclocal-1.16/init.m4',
|
||||
'/usr/share/aclocal-1.16/install-sh.m4',
|
||||
'/usr/share/aclocal-1.16/lead-dot.m4',
|
||||
'/usr/share/aclocal-1.16/make.m4',
|
||||
'/usr/share/aclocal-1.16/missing.m4',
|
||||
'/usr/share/aclocal-1.16/options.m4',
|
||||
'/usr/share/aclocal-1.16/prog-cc-c-o.m4',
|
||||
'/usr/share/aclocal-1.16/runlog.m4',
|
||||
'/usr/share/aclocal-1.16/sanity.m4',
|
||||
'/usr/share/aclocal-1.16/silent.m4',
|
||||
'/usr/share/aclocal-1.16/strip.m4',
|
||||
'/usr/share/aclocal-1.16/substnot.m4',
|
||||
'/usr/share/aclocal-1.16/tar.m4',
|
||||
'm4/ax_cflags_warn_all.m4',
|
||||
'm4/ax_check_compile_flag.m4',
|
||||
'm4/ax_compiler_vendor.m4',
|
||||
'm4/ax_cxx_compile_stdcxx.m4',
|
||||
'm4/ax_cxx_exceptions.m4',
|
||||
'm4/ax_cxx_rtti.m4',
|
||||
'm4/ax_prepend_flag.m4',
|
||||
'm4/ax_prog_doxygen.m4',
|
||||
'm4/ax_pthread.m4',
|
||||
'm4/ax_require_defined.m4',
|
||||
'm4/libtool.m4',
|
||||
'm4/ltoptions.m4',
|
||||
'm4/ltsugar.m4',
|
||||
'm4/ltversion.m4',
|
||||
'm4/lt~obsolete.m4',
|
||||
'm4/pkg.m4',
|
||||
'configure.ac'
|
||||
],
|
||||
{
|
||||
'AU_DEFUN' => 1,
|
||||
'_LT_COMPILER_OPTION' => 1,
|
||||
'_LT_REQUIRED_DARWIN_CHECKS' => 1,
|
||||
'AC_LIBTOOL_LANG_C_CONFIG' => 1,
|
||||
'_PKG_SHORT_ERRORS_SUPPORTED' => 1,
|
||||
'AC_PATH_TOOL_PREFIX' => 1,
|
||||
'_LTDL_SETUP' => 1,
|
||||
'_AC_PROG_LIBTOOL' => 1,
|
||||
'LT_AC_PROG_SED' => 1,
|
||||
'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1,
|
||||
'AC_LIBTOOL_CONFIG' => 1,
|
||||
'_LT_AC_LANG_C_CONFIG' => 1,
|
||||
'AM_PROG_NM' => 1,
|
||||
'LT_CMD_MAX_LEN' => 1,
|
||||
'DX_FEATURE_chi' => 1,
|
||||
'AM_SET_LEADING_DOT' => 1,
|
||||
'AX_FCFLAGS_WARN_ALL' => 1,
|
||||
'_LT_AC_SYS_LIBPATH_AIX' => 1,
|
||||
'AC_LIBTOOL_LANG_RC_CONFIG' => 1,
|
||||
'_LT_AC_PROG_ECHO_BACKSLASH' => 1,
|
||||
'AC_LIBTOOL_F77' => 1,
|
||||
'AC_LIBTOOL_POSTDEP_PREDEP' => 1,
|
||||
'AC_LTDL_DLSYM_USCORE' => 1,
|
||||
'AC_PROG_NM' => 1,
|
||||
'AM_MISSING_PROG' => 1,
|
||||
'LTSUGAR_VERSION' => 1,
|
||||
'_LT_AC_SYS_COMPILER' => 1,
|
||||
'LT_PROG_RC' => 1,
|
||||
'_LT_AC_LANG_F77' => 1,
|
||||
'AC_DISABLE_STATIC' => 1,
|
||||
'DX_PS_FEATURE' => 1,
|
||||
'_AM_SUBST_NOTMAKE' => 1,
|
||||
'AC_CHECK_LIBM' => 1,
|
||||
'AC_LIBTOOL_DLOPEN_SELF' => 1,
|
||||
'AC_LIBTOOL_LINKER_OPTION' => 1,
|
||||
'LT_PATH_LD' => 1,
|
||||
'LT_SYS_MODULE_PATH' => 1,
|
||||
'_AM_CONFIG_MACRO_DIRS' => 1,
|
||||
'LT_WITH_LTDL' => 1,
|
||||
'AX_CHECK_COMPILE_FLAG' => 1,
|
||||
'_LT_PROG_F77' => 1,
|
||||
'AC_PROG_LD_RELOAD_FLAG' => 1,
|
||||
'AM_DISABLE_STATIC' => 1,
|
||||
'DX_RTF_FEATURE' => 1,
|
||||
'LT_FUNC_ARGZ' => 1,
|
||||
'AC_CXX_EXCEPTIONS' => 1,
|
||||
'_LT_COMPILER_BOILERPLATE' => 1,
|
||||
'AC_LIBTOOL_PICMODE' => 1,
|
||||
'DX_CURRENT_DESCRIPTION' => 1,
|
||||
'm4_pattern_allow' => 1,
|
||||
'AX_CXXFLAGS_WARN_ALL' => 1,
|
||||
'DX_FEATURE_ps' => 1,
|
||||
'LT_SYS_DLOPEN_SELF' => 1,
|
||||
'AC_CXX_RTTI' => 1,
|
||||
'AC_DISABLE_FAST_INSTALL' => 1,
|
||||
'DX_DOT_FEATURE' => 1,
|
||||
'_AM_PROG_TAR' => 1,
|
||||
'AC_LTDL_SYMBOL_USCORE' => 1,
|
||||
'AM_MAKE_INCLUDE' => 1,
|
||||
'LTVERSION_VERSION' => 1,
|
||||
'AM_AUX_DIR_EXPAND' => 1,
|
||||
'AM_SILENT_RULES' => 1,
|
||||
'AC_LTDL_SHLIBEXT' => 1,
|
||||
'AX_FLAGS_WARN_ALL' => 1,
|
||||
'LT_SUPPORTED_TAG' => 1,
|
||||
'DX_XML_FEATURE' => 1,
|
||||
'DX_REQUIRE_PROG' => 1,
|
||||
'PKG_HAVE_WITH_MODULES' => 1,
|
||||
'PKG_INSTALLDIR' => 1,
|
||||
'AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
|
||||
'_LT_AC_TAGCONFIG' => 1,
|
||||
'DX_CHM_FEATURE' => 1,
|
||||
'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1,
|
||||
'DX_CURRENT_FEATURE' => 1,
|
||||
'AM_DISABLE_SHARED' => 1,
|
||||
'AM_SUBST_NOTMAKE' => 1,
|
||||
'DX_FEATURE_doc' => 1,
|
||||
'AC_LIBTOOL_PROG_CC_C_O' => 1,
|
||||
'LTOBSOLETE_VERSION' => 1,
|
||||
'AC_ENABLE_STATIC' => 1,
|
||||
'LTDL_INSTALLABLE' => 1,
|
||||
'DX_INIT_DOXYGEN' => 1,
|
||||
'AC_PATH_MAGIC' => 1,
|
||||
'AX_CFLAGS_WARN_ALL' => 1,
|
||||
'_LT_PATH_TOOL_PREFIX' => 1,
|
||||
'_LT_AC_LANG_F77_CONFIG' => 1,
|
||||
'_AM_SET_OPTIONS' => 1,
|
||||
'AC_LIBTOOL_DLOPEN' => 1,
|
||||
'AC_DISABLE_SHARED' => 1,
|
||||
'AC_LIB_LTDL' => 1,
|
||||
'AM_MISSING_HAS_RUN' => 1,
|
||||
'LT_PROG_GO' => 1,
|
||||
'm4_include' => 1,
|
||||
'_LT_CC_BASENAME' => 1,
|
||||
'AM_ENABLE_STATIC' => 1,
|
||||
'AC_LIBTOOL_SYS_MAX_CMD_LEN' => 1,
|
||||
'AC_LIBTOOL_SYS_LIB_STRIP' => 1,
|
||||
'DX_ARG_ABLE' => 1,
|
||||
'AC_LIBTOOL_LANG_F77_CONFIG' => 1,
|
||||
'_LT_AC_PROG_CXXCPP' => 1,
|
||||
'LT_SYS_DLSEARCH_PATH' => 1,
|
||||
'_LT_PROG_ECHO_BACKSLASH' => 1,
|
||||
'AC_WITH_LTDL' => 1,
|
||||
'AC_LTDL_SYSSEARCHPATH' => 1,
|
||||
'_AM_MANGLE_OPTION' => 1,
|
||||
'LT_FUNC_DLSYM_USCORE' => 1,
|
||||
'AX_CXX_RTTI' => 1,
|
||||
'AC_LIBLTDL_INSTALLABLE' => 1,
|
||||
'AC_ENABLE_SHARED' => 1,
|
||||
'_LT_AC_SHELL_INIT' => 1,
|
||||
'_LT_DLL_DEF_P' => 1,
|
||||
'AM_INIT_AUTOMAKE' => 1,
|
||||
'DX_TEST_FEATURE' => 1,
|
||||
'DX_DIRNAME_EXPR' => 1,
|
||||
'AM_PROG_CC_C_O' => 1,
|
||||
'DX_IF_FEATURE' => 1,
|
||||
'AX_PTHREAD' => 1,
|
||||
'DX_CHECK_DEPEND' => 1,
|
||||
'DX_PDF_FEATURE' => 1,
|
||||
'_LT_AC_LANG_RC_CONFIG' => 1,
|
||||
'DX_HTML_FEATURE' => 1,
|
||||
'LT_LIB_DLLOAD' => 1,
|
||||
'AX_COMPILER_VENDOR' => 1,
|
||||
'AC_LIBTOOL_WIN32_DLL' => 1,
|
||||
'AM_AUTOMAKE_VERSION' => 1,
|
||||
'_AM_AUTOCONF_VERSION' => 1,
|
||||
'AM_ENABLE_SHARED' => 1,
|
||||
'AC_LIBTOOL_FC' => 1,
|
||||
'AC_LIBTOOL_CXX' => 1,
|
||||
'AC_LIBTOOL_PROG_LD_SHLIBS' => 1,
|
||||
'ACX_PTHREAD' => 1,
|
||||
'DX_FEATURE_dot' => 1,
|
||||
'AC_CONFIG_MACRO_DIR_TRACE' => 1,
|
||||
'AC_LIBTOOL_GCJ' => 1,
|
||||
'_AM_PROG_CC_C_O' => 1,
|
||||
'AC_LIBTOOL_LANG_CXX_CONFIG' => 1,
|
||||
'_LT_PROG_FC' => 1,
|
||||
'_LT_PROG_LTMAIN' => 1,
|
||||
'AC_PROG_LD_GNU' => 1,
|
||||
'_LT_AC_LANG_CXX_CONFIG' => 1,
|
||||
'AX_PREPEND_FLAG' => 1,
|
||||
'AM_DEP_TRACK' => 1,
|
||||
'DX_DOXYGEN_FEATURE' => 1,
|
||||
'DX_MAN_FEATURE' => 1,
|
||||
'LTOPTIONS_VERSION' => 1,
|
||||
'AM_CONDITIONAL' => 1,
|
||||
'AC_DEPLIBS_CHECK_METHOD' => 1,
|
||||
'_AM_IF_OPTION' => 1,
|
||||
'DX_ENV_APPEND' => 1,
|
||||
'DX_FEATURE_pdf' => 1,
|
||||
'AM_PROG_LIBTOOL' => 1,
|
||||
'DX_FEATURE_rtf' => 1,
|
||||
'AX_REQUIRE_DEFINED' => 1,
|
||||
'LT_CONFIG_LTDL_DIR' => 1,
|
||||
'_LT_LINKER_BOILERPLATE' => 1,
|
||||
'AC_LIBTOOL_COMPILER_OPTION' => 1,
|
||||
'LT_LANG' => 1,
|
||||
'_LT_AC_LANG_GCJ_CONFIG' => 1,
|
||||
'AC_LIBTOOL_SETUP' => 1,
|
||||
'DX_FEATURE_man' => 1,
|
||||
'AC_LIBTOOL_RC' => 1,
|
||||
'AC_PROG_LIBTOOL' => 1,
|
||||
'_LT_LINKER_OPTION' => 1,
|
||||
'AC_PROG_EGREP' => 1,
|
||||
'LT_OUTPUT' => 1,
|
||||
'DX_FEATURE_html' => 1,
|
||||
'_AM_SET_OPTION' => 1,
|
||||
'LT_AC_PROG_RC' => 1,
|
||||
'AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH' => 1,
|
||||
'LT_LIB_M' => 1,
|
||||
'AC_LTDL_ENABLE_INSTALL' => 1,
|
||||
'AC_DEFUN_ONCE' => 1,
|
||||
'PKG_NOARCH_INSTALLDIR' => 1,
|
||||
'PKG_CHECK_EXISTS' => 1,
|
||||
'_LT_PROG_CXX' => 1,
|
||||
'_LT_AC_TRY_DLOPEN_SELF' => 1,
|
||||
'PKG_WITH_MODULES' => 1,
|
||||
'AC_PROG_LD' => 1,
|
||||
'_m4_warn' => 1,
|
||||
'LT_SYS_SYMBOL_USCORE' => 1,
|
||||
'LT_PROG_GCJ' => 1,
|
||||
'_AC_AM_CONFIG_HEADER_HOOK' => 1,
|
||||
'LT_INIT' => 1,
|
||||
'AC_LIBTOOL_LANG_GCJ_CONFIG' => 1,
|
||||
'PKG_PROG_PKG_CONFIG' => 1,
|
||||
'LT_AC_PROG_EGREP' => 1,
|
||||
'AM_RUN_LOG' => 1,
|
||||
'_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
|
||||
'AC_LIBTOOL_OBJDIR' => 1,
|
||||
'AM_PROG_LD' => 1,
|
||||
'AC_LTDL_SHLIBPATH' => 1,
|
||||
'PKG_CHECK_MODULES' => 1,
|
||||
'PKG_CHECK_MODULES_STATIC' => 1,
|
||||
'AM_SANITY_CHECK' => 1,
|
||||
'_AM_DEPENDENCIES' => 1,
|
||||
'DX_FEATURE_chm' => 1,
|
||||
'm4_pattern_forbid' => 1,
|
||||
'AC_CONFIG_MACRO_DIR' => 1,
|
||||
'_LT_AC_CHECK_DLFCN' => 1,
|
||||
'AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE' => 1,
|
||||
'AC_LTDL_PREOPEN' => 1,
|
||||
'AX_CXX_COMPILE_STDCXX' => 1,
|
||||
'PKG_HAVE_DEFINE_WITH_MODULES' => 1,
|
||||
'AC_LIBLTDL_CONVENIENCE' => 1,
|
||||
'AC_LIBTOOL_PROG_COMPILER_NO_RTTI' => 1,
|
||||
'LTDL_CONVENIENCE' => 1,
|
||||
'_LT_PREPARE_SED_QUOTE_VARS' => 1,
|
||||
'_LT_AC_LOCK' => 1,
|
||||
'AC_LTDL_SYS_DLOPEN_DEPLIBS' => 1,
|
||||
'PKG_CHECK_VAR' => 1,
|
||||
'_LT_AC_LANG_GCJ' => 1,
|
||||
'LT_AC_PROG_GCJ' => 1,
|
||||
'LT_SYS_DLOPEN_DEPLIBS' => 1,
|
||||
'DX_CHI_FEATURE' => 1,
|
||||
'DX_CLEAR_DEPEND' => 1,
|
||||
'AM_PROG_INSTALL_STRIP' => 1,
|
||||
'_LT_WITH_SYSROOT' => 1,
|
||||
'_LT_LIBOBJ' => 1,
|
||||
'AC_LTDL_DLLIB' => 1,
|
||||
'_LT_AC_TAGVAR' => 1,
|
||||
'AC_ENABLE_FAST_INSTALL' => 1,
|
||||
'AC_LTDL_OBJDIR' => 1,
|
||||
'AC_LIBTOOL_SYS_HARD_LINK_LOCKS' => 1,
|
||||
'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
|
||||
'LT_PATH_NM' => 1,
|
||||
'LTDL_INIT' => 1,
|
||||
'_LT_AC_LANG_CXX' => 1,
|
||||
'include' => 1,
|
||||
'AX_CXX_EXCEPTIONS' => 1,
|
||||
'AM_SET_DEPDIR' => 1,
|
||||
'LT_SYS_MODULE_EXT' => 1,
|
||||
'_LT_AC_FILE_LTDLL_C' => 1,
|
||||
'AM_PROG_AR' => 1,
|
||||
'AC_LIBTOOL_PROG_COMPILER_PIC' => 1,
|
||||
'AC_DEFUN' => 1,
|
||||
'AM_PROG_INSTALL_SH' => 1,
|
||||
'DX_FEATURE_xml' => 1
|
||||
}
|
||||
], 'Autom4te::Request' ),
|
||||
bless( [
|
||||
'1',
|
||||
1,
|
||||
[
|
||||
'/usr/share/autoconf'
|
||||
],
|
||||
[
|
||||
'/usr/share/autoconf/autoconf/autoconf.m4f',
|
||||
'aclocal.m4',
|
||||
'configure.ac'
|
||||
],
|
||||
{
|
||||
'AM_ENABLE_MULTILIB' => 1,
|
||||
'AC_CONFIG_SUBDIRS' => 1,
|
||||
'AC_CONFIG_FILES' => 1,
|
||||
'_AM_COND_IF' => 1,
|
||||
'AM_NLS' => 1,
|
||||
'AC_FC_PP_SRCEXT' => 1,
|
||||
'LT_SUPPORTED_TAG' => 1,
|
||||
'AM_AUTOMAKE_VERSION' => 1,
|
||||
'AC_FC_FREEFORM' => 1,
|
||||
'AC_CONFIG_HEADERS' => 1,
|
||||
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
|
||||
'GTK_DOC_CHECK' => 1,
|
||||
'AM_MAINTAINER_MODE' => 1,
|
||||
'AM_PATH_GUILE' => 1,
|
||||
'AM_PROG_FC_C_O' => 1,
|
||||
'AM_PROG_MOC' => 1,
|
||||
'AC_CONFIG_AUX_DIR' => 1,
|
||||
'_AM_COND_ENDIF' => 1,
|
||||
'_LT_AC_TAGCONFIG' => 1,
|
||||
'm4_pattern_forbid' => 1,
|
||||
'AC_CONFIG_LINKS' => 1,
|
||||
'AC_CONFIG_MACRO_DIR_TRACE' => 1,
|
||||
'AM_XGETTEXT_OPTION' => 1,
|
||||
'AM_PROG_CXX_C_O' => 1,
|
||||
'AM_PROG_CC_C_O' => 1,
|
||||
'AC_FC_PP_DEFINE' => 1,
|
||||
'AM_PROG_F77_C_O' => 1,
|
||||
'AM_INIT_AUTOMAKE' => 1,
|
||||
'AC_FC_SRCEXT' => 1,
|
||||
'AC_CANONICAL_BUILD' => 1,
|
||||
'IT_PROG_INTLTOOL' => 1,
|
||||
'AM_SILENT_RULES' => 1,
|
||||
'AM_EXTRA_RECURSIVE_TARGETS' => 1,
|
||||
'AC_SUBST_TRACE' => 1,
|
||||
'LT_INIT' => 1,
|
||||
'AC_REQUIRE_AUX_FILE' => 1,
|
||||
'_m4_warn' => 1,
|
||||
'sinclude' => 1,
|
||||
'm4_include' => 1,
|
||||
'include' => 1,
|
||||
'AM_POT_TOOLS' => 1,
|
||||
'LT_CONFIG_LTDL_DIR' => 1,
|
||||
'AM_PROG_MKDIR_P' => 1,
|
||||
'AC_LIBSOURCE' => 1,
|
||||
'_AM_COND_ELSE' => 1,
|
||||
'm4_pattern_allow' => 1,
|
||||
'AM_PROG_AR' => 1,
|
||||
'AC_DEFINE_TRACE_LITERAL' => 1,
|
||||
'AC_CANONICAL_TARGET' => 1,
|
||||
'AM_MAKEFILE_INCLUDE' => 1,
|
||||
'AC_PROG_LIBTOOL' => 1,
|
||||
'AC_INIT' => 1,
|
||||
'_AM_MAKEFILE_INCLUDE' => 1,
|
||||
'AM_CONDITIONAL' => 1,
|
||||
'_AM_SUBST_NOTMAKE' => 1,
|
||||
'AC_CANONICAL_HOST' => 1,
|
||||
'AM_GNU_GETTEXT' => 1,
|
||||
'AM_PROG_LIBTOOL' => 1,
|
||||
'm4_sinclude' => 1,
|
||||
'AC_SUBST' => 1,
|
||||
'AH_OUTPUT' => 1,
|
||||
'AC_CONFIG_LIBOBJ_DIR' => 1,
|
||||
'AC_CANONICAL_SYSTEM' => 1
|
||||
}
|
||||
], 'Autom4te::Request' ),
|
||||
bless( [
|
||||
'2',
|
||||
1,
|
||||
[
|
||||
'/usr/share/autoconf'
|
||||
],
|
||||
[
|
||||
'/usr/share/autoconf/autoconf/autoconf.m4f',
|
||||
'aclocal.m4',
|
||||
'/usr/share/autoconf/autoconf/trailer.m4',
|
||||
'configure.ac'
|
||||
],
|
||||
{
|
||||
'AM_PROG_MOC' => 1,
|
||||
'AC_CONFIG_AUX_DIR' => 1,
|
||||
'_AM_COND_ENDIF' => 1,
|
||||
'_LT_AC_TAGCONFIG' => 1,
|
||||
'm4_pattern_forbid' => 1,
|
||||
'AC_CONFIG_LINKS' => 1,
|
||||
'AC_CONFIG_MACRO_DIR_TRACE' => 1,
|
||||
'AM_XGETTEXT_OPTION' => 1,
|
||||
'AM_PROG_CXX_C_O' => 1,
|
||||
'AM_ENABLE_MULTILIB' => 1,
|
||||
'AC_CONFIG_SUBDIRS' => 1,
|
||||
'AC_CONFIG_FILES' => 1,
|
||||
'AM_NLS' => 1,
|
||||
'_AM_COND_IF' => 1,
|
||||
'AC_FC_PP_SRCEXT' => 1,
|
||||
'LT_SUPPORTED_TAG' => 1,
|
||||
'AM_AUTOMAKE_VERSION' => 1,
|
||||
'AC_CONFIG_HEADERS' => 1,
|
||||
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
|
||||
'AC_FC_FREEFORM' => 1,
|
||||
'AM_MAINTAINER_MODE' => 1,
|
||||
'GTK_DOC_CHECK' => 1,
|
||||
'AM_PATH_GUILE' => 1,
|
||||
'AM_PROG_FC_C_O' => 1,
|
||||
'AM_SILENT_RULES' => 1,
|
||||
'AM_EXTRA_RECURSIVE_TARGETS' => 1,
|
||||
'AC_SUBST_TRACE' => 1,
|
||||
'AC_REQUIRE_AUX_FILE' => 1,
|
||||
'LT_INIT' => 1,
|
||||
'_m4_warn' => 1,
|
||||
'sinclude' => 1,
|
||||
'AM_PROG_CC_C_O' => 1,
|
||||
'AC_FC_PP_DEFINE' => 1,
|
||||
'AM_PROG_F77_C_O' => 1,
|
||||
'AM_INIT_AUTOMAKE' => 1,
|
||||
'AC_FC_SRCEXT' => 1,
|
||||
'AC_CANONICAL_BUILD' => 1,
|
||||
'IT_PROG_INTLTOOL' => 1,
|
||||
'AC_LIBSOURCE' => 1,
|
||||
'_AM_COND_ELSE' => 1,
|
||||
'm4_pattern_allow' => 1,
|
||||
'AM_PROG_AR' => 1,
|
||||
'AC_DEFINE_TRACE_LITERAL' => 1,
|
||||
'AC_CANONICAL_TARGET' => 1,
|
||||
'AM_MAKEFILE_INCLUDE' => 1,
|
||||
'AC_PROG_LIBTOOL' => 1,
|
||||
'AC_INIT' => 1,
|
||||
'm4_include' => 1,
|
||||
'include' => 1,
|
||||
'AM_POT_TOOLS' => 1,
|
||||
'AM_PROG_MKDIR_P' => 1,
|
||||
'LT_CONFIG_LTDL_DIR' => 1,
|
||||
'AC_CANONICAL_HOST' => 1,
|
||||
'AM_GNU_GETTEXT' => 1,
|
||||
'AM_PROG_LIBTOOL' => 1,
|
||||
'm4_sinclude' => 1,
|
||||
'AC_SUBST' => 1,
|
||||
'AH_OUTPUT' => 1,
|
||||
'AC_CONFIG_LIBOBJ_DIR' => 1,
|
||||
'AC_CANONICAL_SYSTEM' => 1,
|
||||
'_AM_MAKEFILE_INCLUDE' => 1,
|
||||
'AM_CONDITIONAL' => 1,
|
||||
'_AM_SUBST_NOTMAKE' => 1
|
||||
}
|
||||
], 'Autom4te::Request' )
|
||||
);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,271 @@
|
||||
#! /bin/sh
|
||||
# Wrapper for Microsoft lib.exe
|
||||
|
||||
me=ar-lib
|
||||
scriptversion=2019-07-04.01; # UTC
|
||||
|
||||
# Copyright (C) 2010-2021 Free Software Foundation, Inc.
|
||||
# Written by Peter Rosin <[email protected]>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <[email protected]> or send patches to
|
||||
# <[email protected]>.
|
||||
|
||||
|
||||
# func_error message
|
||||
func_error ()
|
||||
{
|
||||
echo "$me: $1" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
file_conv=
|
||||
|
||||
# func_file_conv build_file
|
||||
# Convert a $build file to $host form and store it in $file
|
||||
# Currently only supports Windows hosts.
|
||||
func_file_conv ()
|
||||
{
|
||||
file=$1
|
||||
case $file in
|
||||
/ | /[!/]*) # absolute file, and not a UNC file
|
||||
if test -z "$file_conv"; then
|
||||
# lazily determine how to convert abs files
|
||||
case `uname -s` in
|
||||
MINGW*)
|
||||
file_conv=mingw
|
||||
;;
|
||||
CYGWIN* | MSYS*)
|
||||
file_conv=cygwin
|
||||
;;
|
||||
*)
|
||||
file_conv=wine
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
case $file_conv in
|
||||
mingw)
|
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||
;;
|
||||
cygwin | msys)
|
||||
file=`cygpath -m "$file" || echo "$file"`
|
||||
;;
|
||||
wine)
|
||||
file=`winepath -w "$file" || echo "$file"`
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# func_at_file at_file operation archive
|
||||
# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
|
||||
# for each of them.
|
||||
# When interpreting the content of the @FILE, do NOT use func_file_conv,
|
||||
# since the user would need to supply preconverted file names to
|
||||
# binutils ar, at least for MinGW.
|
||||
func_at_file ()
|
||||
{
|
||||
operation=$2
|
||||
archive=$3
|
||||
at_file_contents=`cat "$1"`
|
||||
eval set x "$at_file_contents"
|
||||
shift
|
||||
|
||||
for member
|
||||
do
|
||||
$AR -NOLOGO $operation:"$member" "$archive" || exit $?
|
||||
done
|
||||
}
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
func_error "no command. Try '$0 --help' for more information."
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<EOF
|
||||
Usage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]
|
||||
|
||||
Members may be specified in a file named with @FILE.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "$me, version $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
|
||||
if test $# -lt 3; then
|
||||
func_error "you must specify a program, an action and an archive"
|
||||
fi
|
||||
|
||||
AR=$1
|
||||
shift
|
||||
while :
|
||||
do
|
||||
if test $# -lt 2; then
|
||||
func_error "you must specify a program, an action and an archive"
|
||||
fi
|
||||
case $1 in
|
||||
-lib | -LIB \
|
||||
| -ltcg | -LTCG \
|
||||
| -machine* | -MACHINE* \
|
||||
| -subsystem* | -SUBSYSTEM* \
|
||||
| -verbose | -VERBOSE \
|
||||
| -wx* | -WX* )
|
||||
AR="$AR $1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
action=$1
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
orig_archive=$1
|
||||
shift
|
||||
func_file_conv "$orig_archive"
|
||||
archive=$file
|
||||
|
||||
# strip leading dash in $action
|
||||
action=${action#-}
|
||||
|
||||
delete=
|
||||
extract=
|
||||
list=
|
||||
quick=
|
||||
replace=
|
||||
index=
|
||||
create=
|
||||
|
||||
while test -n "$action"
|
||||
do
|
||||
case $action in
|
||||
d*) delete=yes ;;
|
||||
x*) extract=yes ;;
|
||||
t*) list=yes ;;
|
||||
q*) quick=yes ;;
|
||||
r*) replace=yes ;;
|
||||
s*) index=yes ;;
|
||||
S*) ;; # the index is always updated implicitly
|
||||
c*) create=yes ;;
|
||||
u*) ;; # TODO: don't ignore the update modifier
|
||||
v*) ;; # TODO: don't ignore the verbose modifier
|
||||
*)
|
||||
func_error "unknown action specified"
|
||||
;;
|
||||
esac
|
||||
action=${action#?}
|
||||
done
|
||||
|
||||
case $delete$extract$list$quick$replace,$index in
|
||||
yes,* | ,yes)
|
||||
;;
|
||||
yesyes*)
|
||||
func_error "more than one action specified"
|
||||
;;
|
||||
*)
|
||||
func_error "no action specified"
|
||||
;;
|
||||
esac
|
||||
|
||||
if test -n "$delete"; then
|
||||
if test ! -f "$orig_archive"; then
|
||||
func_error "archive not found"
|
||||
fi
|
||||
for member
|
||||
do
|
||||
case $1 in
|
||||
@*)
|
||||
func_at_file "${1#@}" -REMOVE "$archive"
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$1"
|
||||
$AR -NOLOGO -REMOVE:"$file" "$archive" || exit $?
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
elif test -n "$extract"; then
|
||||
if test ! -f "$orig_archive"; then
|
||||
func_error "archive not found"
|
||||
fi
|
||||
if test $# -gt 0; then
|
||||
for member
|
||||
do
|
||||
case $1 in
|
||||
@*)
|
||||
func_at_file "${1#@}" -EXTRACT "$archive"
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$1"
|
||||
$AR -NOLOGO -EXTRACT:"$file" "$archive" || exit $?
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
$AR -NOLOGO -LIST "$archive" | tr -d '\r' | sed -e 's/\\/\\\\/g' \
|
||||
| while read member
|
||||
do
|
||||
$AR -NOLOGO -EXTRACT:"$member" "$archive" || exit $?
|
||||
done
|
||||
fi
|
||||
|
||||
elif test -n "$quick$replace"; then
|
||||
if test ! -f "$orig_archive"; then
|
||||
if test -z "$create"; then
|
||||
echo "$me: creating $orig_archive"
|
||||
fi
|
||||
orig_archive=
|
||||
else
|
||||
orig_archive=$archive
|
||||
fi
|
||||
|
||||
for member
|
||||
do
|
||||
case $1 in
|
||||
@*)
|
||||
func_file_conv "${1#@}"
|
||||
set x "$@" "@$file"
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$1"
|
||||
set x "$@" "$file"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
shift
|
||||
done
|
||||
|
||||
if test -n "$orig_archive"; then
|
||||
$AR -NOLOGO -OUT:"$archive" "$orig_archive" "$@" || exit $?
|
||||
else
|
||||
$AR -NOLOGO -OUT:"$archive" "$@" || exit $?
|
||||
fi
|
||||
|
||||
elif test -n "$list"; then
|
||||
if test ! -f "$orig_archive"; then
|
||||
func_error "archive not found"
|
||||
fi
|
||||
$AR -NOLOGO -LIST "$archive" || exit $?
|
||||
fi
|
||||
@@ -0,0 +1,348 @@
|
||||
#! /bin/sh
|
||||
# Wrapper for compilers which do not understand '-c -o'.
|
||||
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
# Written by Tom Tromey <[email protected]>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <[email protected]> or send patches to
|
||||
# <[email protected]>.
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
# We need space, tab and new line, in precisely that order. Quoting is
|
||||
# there to prevent tools from complaining about whitespace usage.
|
||||
IFS=" "" $nl"
|
||||
|
||||
file_conv=
|
||||
|
||||
# func_file_conv build_file lazy
|
||||
# Convert a $build file to $host form and store it in $file
|
||||
# Currently only supports Windows hosts. If the determined conversion
|
||||
# type is listed in (the comma separated) LAZY, no conversion will
|
||||
# take place.
|
||||
func_file_conv ()
|
||||
{
|
||||
file=$1
|
||||
case $file in
|
||||
/ | /[!/]*) # absolute file, and not a UNC file
|
||||
if test -z "$file_conv"; then
|
||||
# lazily determine how to convert abs files
|
||||
case `uname -s` in
|
||||
MINGW*)
|
||||
file_conv=mingw
|
||||
;;
|
||||
CYGWIN* | MSYS*)
|
||||
file_conv=cygwin
|
||||
;;
|
||||
*)
|
||||
file_conv=wine
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
case $file_conv/,$2, in
|
||||
*,$file_conv,*)
|
||||
;;
|
||||
mingw/*)
|
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||
;;
|
||||
cygwin/* | msys/*)
|
||||
file=`cygpath -m "$file" || echo "$file"`
|
||||
;;
|
||||
wine/*)
|
||||
file=`winepath -w "$file" || echo "$file"`
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# func_cl_dashL linkdir
|
||||
# Make cl look for libraries in LINKDIR
|
||||
func_cl_dashL ()
|
||||
{
|
||||
func_file_conv "$1"
|
||||
if test -z "$lib_path"; then
|
||||
lib_path=$file
|
||||
else
|
||||
lib_path="$lib_path;$file"
|
||||
fi
|
||||
linker_opts="$linker_opts -LIBPATH:$file"
|
||||
}
|
||||
|
||||
# func_cl_dashl library
|
||||
# Do a library search-path lookup for cl
|
||||
func_cl_dashl ()
|
||||
{
|
||||
lib=$1
|
||||
found=no
|
||||
save_IFS=$IFS
|
||||
IFS=';'
|
||||
for dir in $lib_path $LIB
|
||||
do
|
||||
IFS=$save_IFS
|
||||
if $shared && test -f "$dir/$lib.dll.lib"; then
|
||||
found=yes
|
||||
lib=$dir/$lib.dll.lib
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/$lib.lib"; then
|
||||
found=yes
|
||||
lib=$dir/$lib.lib
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/lib$lib.a"; then
|
||||
found=yes
|
||||
lib=$dir/lib$lib.a
|
||||
break
|
||||
fi
|
||||
done
|
||||
IFS=$save_IFS
|
||||
|
||||
if test "$found" != yes; then
|
||||
lib=$lib.lib
|
||||
fi
|
||||
}
|
||||
|
||||
# func_cl_wrapper cl arg...
|
||||
# Adjust compile command to suit cl
|
||||
func_cl_wrapper ()
|
||||
{
|
||||
# Assume a capable shell
|
||||
lib_path=
|
||||
shared=:
|
||||
linker_opts=
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.[oO][bB][jJ])
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fo"$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fe"$file"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
-I)
|
||||
eat=1
|
||||
func_file_conv "$2" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-I*)
|
||||
func_file_conv "${1#-I}" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-l)
|
||||
eat=1
|
||||
func_cl_dashl "$2"
|
||||
set x "$@" "$lib"
|
||||
shift
|
||||
;;
|
||||
-l*)
|
||||
func_cl_dashl "${1#-l}"
|
||||
set x "$@" "$lib"
|
||||
shift
|
||||
;;
|
||||
-L)
|
||||
eat=1
|
||||
func_cl_dashL "$2"
|
||||
;;
|
||||
-L*)
|
||||
func_cl_dashL "${1#-L}"
|
||||
;;
|
||||
-static)
|
||||
shared=false
|
||||
;;
|
||||
-Wl,*)
|
||||
arg=${1#-Wl,}
|
||||
save_ifs="$IFS"; IFS=','
|
||||
for flag in $arg; do
|
||||
IFS="$save_ifs"
|
||||
linker_opts="$linker_opts $flag"
|
||||
done
|
||||
IFS="$save_ifs"
|
||||
;;
|
||||
-Xlinker)
|
||||
eat=1
|
||||
linker_opts="$linker_opts $2"
|
||||
;;
|
||||
-*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
|
||||
func_file_conv "$1"
|
||||
set x "$@" -Tp"$file"
|
||||
shift
|
||||
;;
|
||||
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
|
||||
func_file_conv "$1" mingw
|
||||
set x "$@" "$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
if test -n "$linker_opts"; then
|
||||
linker_opts="-link$linker_opts"
|
||||
fi
|
||||
exec "$@" $linker_opts
|
||||
exit 1
|
||||
}
|
||||
|
||||
eat=
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: compile [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Wrapper for compilers which do not understand '-c -o'.
|
||||
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
|
||||
arguments, and rename the output as expected.
|
||||
|
||||
If you are trying to build a whole package this is not the
|
||||
right script to run: please start by reading the file 'INSTALL'.
|
||||
|
||||
Report bugs to <[email protected]>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "compile $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \
|
||||
icl | *[/\\]icl | icl.exe | *[/\\]icl.exe )
|
||||
func_cl_wrapper "$@" # Doesn't return...
|
||||
;;
|
||||
esac
|
||||
|
||||
ofile=
|
||||
cfile=
|
||||
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
# So we strip '-o arg' only if arg is an object.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.obj)
|
||||
ofile=$2
|
||||
;;
|
||||
*)
|
||||
set x "$@" -o "$2"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.c)
|
||||
cfile=$1
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if test -z "$ofile" || test -z "$cfile"; then
|
||||
# If no '-o' option was seen then we might have been invoked from a
|
||||
# pattern rule where we don't need one. That is ok -- this is a
|
||||
# normal compilation that the losing compiler can handle. If no
|
||||
# '.c' file was seen then we are probably linking. That is also
|
||||
# ok.
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Name of file we expect compiler to create.
|
||||
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
|
||||
|
||||
# Create the lock directory.
|
||||
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
|
||||
# that we are using for the .o file. Also, base the name on the expected
|
||||
# object file name, since that is what matters with a parallel build.
|
||||
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
|
||||
while true; do
|
||||
if mkdir "$lockdir" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
# FIXME: race condition here if user kills between mkdir and trap.
|
||||
trap "rmdir '$lockdir'; exit 1" 1 2 15
|
||||
|
||||
# Run the compile.
|
||||
"$@"
|
||||
ret=$?
|
||||
|
||||
if test -f "$cofile"; then
|
||||
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
|
||||
elif test -f "${cofile}bj"; then
|
||||
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
|
||||
fi
|
||||
|
||||
rmdir "$lockdir"
|
||||
exit $ret
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
Vendored
+1754
File diff suppressed because it is too large.
Load diff
Vendored
+1890
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,791 @@
|
||||
#! /bin/sh
|
||||
# depcomp - compile a program generating dependencies as side-effects
|
||||
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# Originally written by Alexandre Oliva <[email protected]>.
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: depcomp [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Run PROGRAMS ARGS to compile a file, generating dependencies
|
||||
as side-effects.
|
||||
|
||||
Environment variables:
|
||||
depmode Dependency tracking mode.
|
||||
source Source file read by 'PROGRAMS ARGS'.
|
||||
object Object file output by 'PROGRAMS ARGS'.
|
||||
DEPDIR directory where to store dependencies.
|
||||
depfile Dependency file to output.
|
||||
tmpdepfile Temporary file to use when outputting dependencies.
|
||||
libtool Whether libtool is used (yes/no).
|
||||
|
||||
Report bugs to <[email protected]>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "depcomp $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get the directory component of the given path, and save it in the
|
||||
# global variables '$dir'. Note that this directory component will
|
||||
# be either empty or ending with a '/' character. This is deliberate.
|
||||
set_dir_from ()
|
||||
{
|
||||
case $1 in
|
||||
*/*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;;
|
||||
*) dir=;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Get the suffix-stripped basename of the given path, and save it the
|
||||
# global variable '$base'.
|
||||
set_base_from ()
|
||||
{
|
||||
base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'`
|
||||
}
|
||||
|
||||
# If no dependency file was actually created by the compiler invocation,
|
||||
# we still have to create a dummy depfile, to avoid errors with the
|
||||
# Makefile "include basename.Plo" scheme.
|
||||
make_dummy_depfile ()
|
||||
{
|
||||
echo "#dummy" > "$depfile"
|
||||
}
|
||||
|
||||
# Factor out some common post-processing of the generated depfile.
|
||||
# Requires the auxiliary global variable '$tmpdepfile' to be set.
|
||||
aix_post_process_depfile ()
|
||||
{
|
||||
# If the compiler actually managed to produce a dependency file,
|
||||
# post-process it.
|
||||
if test -f "$tmpdepfile"; then
|
||||
# Each line is of the form 'foo.o: dependency.h'.
|
||||
# Do two passes, one to just change these to
|
||||
# $object: dependency.h
|
||||
# and one to simply output
|
||||
# dependency.h:
|
||||
# which is needed to avoid the deleted-header problem.
|
||||
{ sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile"
|
||||
sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile"
|
||||
} > "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
else
|
||||
make_dummy_depfile
|
||||
fi
|
||||
}
|
||||
|
||||
# A tabulation character.
|
||||
tab=' '
|
||||
# A newline character.
|
||||
nl='
|
||||
'
|
||||
# Character ranges might be problematic outside the C locale.
|
||||
# These definitions help.
|
||||
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
lower=abcdefghijklmnopqrstuvwxyz
|
||||
digits=0123456789
|
||||
alpha=${upper}${lower}
|
||||
|
||||
if test -z "$depmode" || test -z "$source" || test -z "$object"; then
|
||||
echo "depcomp: Variables source, object and depmode must be set" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
|
||||
depfile=${depfile-`echo "$object" |
|
||||
sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
|
||||
tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
|
||||
|
||||
rm -f "$tmpdepfile"
|
||||
|
||||
# Avoid interferences from the environment.
|
||||
gccflag= dashmflag=
|
||||
|
||||
# Some modes work just like other modes, but use different flags. We
|
||||
# parameterize here, but still list the modes in the big case below,
|
||||
# to make depend.m4 easier to write. Note that we *cannot* use a case
|
||||
# here, because this file can only contain one case statement.
|
||||
if test "$depmode" = hp; then
|
||||
# HP compiler uses -M and no extra arg.
|
||||
gccflag=-M
|
||||
depmode=gcc
|
||||
fi
|
||||
|
||||
if test "$depmode" = dashXmstdout; then
|
||||
# This is just like dashmstdout with a different argument.
|
||||
dashmflag=-xM
|
||||
depmode=dashmstdout
|
||||
fi
|
||||
|
||||
cygpath_u="cygpath -u -f -"
|
||||
if test "$depmode" = msvcmsys; then
|
||||
# This is just like msvisualcpp but w/o cygpath translation.
|
||||
# Just convert the backslash-escaped backslashes to single forward
|
||||
# slashes to satisfy depend.m4
|
||||
cygpath_u='sed s,\\\\,/,g'
|
||||
depmode=msvisualcpp
|
||||
fi
|
||||
|
||||
if test "$depmode" = msvc7msys; then
|
||||
# This is just like msvc7 but w/o cygpath translation.
|
||||
# Just convert the backslash-escaped backslashes to single forward
|
||||
# slashes to satisfy depend.m4
|
||||
cygpath_u='sed s,\\\\,/,g'
|
||||
depmode=msvc7
|
||||
fi
|
||||
|
||||
if test "$depmode" = xlc; then
|
||||
# IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.
|
||||
gccflag=-qmakedep=gcc,-MF
|
||||
depmode=gcc
|
||||
fi
|
||||
|
||||
case "$depmode" in
|
||||
gcc3)
|
||||
## gcc 3 implements dependency tracking that does exactly what
|
||||
## we want. Yay! Note: for some reason libtool 1.4 doesn't like
|
||||
## it if -MD -MP comes after the -MF stuff. Hmm.
|
||||
## Unfortunately, FreeBSD c89 acceptance of flags depends upon
|
||||
## the command line argument order; so add the flags where they
|
||||
## appear in depend2.am. Note that the slowdown incurred here
|
||||
## affects only configure: in makefiles, %FASTDEP% shortcuts this.
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;;
|
||||
*) set fnord "$@" "$arg" ;;
|
||||
esac
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
done
|
||||
"$@"
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
mv "$tmpdepfile" "$depfile"
|
||||
;;
|
||||
|
||||
gcc)
|
||||
## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.
|
||||
## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.
|
||||
## (see the conditional assignment to $gccflag above).
|
||||
## There are various ways to get dependency output from gcc. Here's
|
||||
## why we pick this rather obscure method:
|
||||
## - Don't want to use -MD because we'd like the dependencies to end
|
||||
## up in a subdir. Having to rename by hand is ugly.
|
||||
## (We might end up doing this anyway to support other compilers.)
|
||||
## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
|
||||
## -MM, not -M (despite what the docs say). Also, it might not be
|
||||
## supported by the other compilers which use the 'gcc' depmode.
|
||||
## - Using -M directly means running the compiler twice (even worse
|
||||
## than renaming).
|
||||
if test -z "$gccflag"; then
|
||||
gccflag=-MD,
|
||||
fi
|
||||
"$@" -Wp,"$gccflag$tmpdepfile"
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
# The second -e expression handles DOS-style file names with drive
|
||||
# letters.
|
||||
sed -e 's/^[^:]*: / /' \
|
||||
-e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
|
||||
## This next piece of magic avoids the "deleted header file" problem.
|
||||
## The problem is that when a header file which appears in a .P file
|
||||
## is deleted, the dependency causes make to die (because there is
|
||||
## typically no way to rebuild the header). We avoid this by adding
|
||||
## dummy dependencies for each header file. Too bad gcc doesn't do
|
||||
## this for us directly.
|
||||
## Some versions of gcc put a space before the ':'. On the theory
|
||||
## that the space means something, we add a space to the output as
|
||||
## well. hp depmode also adds that space, but also prefixes the VPATH
|
||||
## to the object. Take care to not repeat it in the output.
|
||||
## Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
## correctly. Breaking it into two sed invocations is a workaround.
|
||||
tr ' ' "$nl" < "$tmpdepfile" \
|
||||
| sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \
|
||||
| sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
hp)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
sgi)
|
||||
if test "$libtool" = yes; then
|
||||
"$@" "-Wp,-MDupdate,$tmpdepfile"
|
||||
else
|
||||
"$@" -MDupdate "$tmpdepfile"
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
|
||||
if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files
|
||||
echo "$object : \\" > "$depfile"
|
||||
# Clip off the initial element (the dependent). Don't try to be
|
||||
# clever and replace this with sed code, as IRIX sed won't handle
|
||||
# lines with more than a fixed number of characters (4096 in
|
||||
# IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines;
|
||||
# the IRIX cc adds comments like '#:fec' to the end of the
|
||||
# dependency line.
|
||||
tr ' ' "$nl" < "$tmpdepfile" \
|
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \
|
||||
| tr "$nl" ' ' >> "$depfile"
|
||||
echo >> "$depfile"
|
||||
# The second pass generates a dummy entry for each header file.
|
||||
tr ' ' "$nl" < "$tmpdepfile" \
|
||||
| sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
|
||||
>> "$depfile"
|
||||
else
|
||||
make_dummy_depfile
|
||||
fi
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
xlc)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
aix)
|
||||
# The C for AIX Compiler uses -M and outputs the dependencies
|
||||
# in a .u file. In older versions, this file always lives in the
|
||||
# current directory. Also, the AIX compiler puts '$object:' at the
|
||||
# start of each line; $object doesn't have directory information.
|
||||
# Version 6 uses the directory in both cases.
|
||||
set_dir_from "$object"
|
||||
set_base_from "$object"
|
||||
if test "$libtool" = yes; then
|
||||
tmpdepfile1=$dir$base.u
|
||||
tmpdepfile2=$base.u
|
||||
tmpdepfile3=$dir.libs/$base.u
|
||||
"$@" -Wc,-M
|
||||
else
|
||||
tmpdepfile1=$dir$base.u
|
||||
tmpdepfile2=$dir$base.u
|
||||
tmpdepfile3=$dir$base.u
|
||||
"$@" -M
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
aix_post_process_depfile
|
||||
;;
|
||||
|
||||
tcc)
|
||||
# tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26
|
||||
# FIXME: That version still under development at the moment of writing.
|
||||
# Make that this statement remains true also for stable, released
|
||||
# versions.
|
||||
# It will wrap lines (doesn't matter whether long or short) with a
|
||||
# trailing '\', as in:
|
||||
#
|
||||
# foo.o : \
|
||||
# foo.c \
|
||||
# foo.h \
|
||||
#
|
||||
# It will put a trailing '\' even on the last line, and will use leading
|
||||
# spaces rather than leading tabs (at least since its commit 0394caf7
|
||||
# "Emit spaces for -MD").
|
||||
"$@" -MD -MF "$tmpdepfile"
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
# Each non-empty line is of the form 'foo.o : \' or ' dep.h \'.
|
||||
# We have to change lines of the first kind to '$object: \'.
|
||||
sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile"
|
||||
# And for each line of the second kind, we have to emit a 'dep.h:'
|
||||
# dummy dependency, to avoid the deleted-header problem.
|
||||
sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
## The order of this option in the case statement is important, since the
|
||||
## shell code in configure will try each of these formats in the order
|
||||
## listed in this file. A plain '-MD' option would be understood by many
|
||||
## compilers, so we must ensure this comes after the gcc and icc options.
|
||||
pgcc)
|
||||
# Portland's C compiler understands '-MD'.
|
||||
# Will always output deps to 'file.d' where file is the root name of the
|
||||
# source file under compilation, even if file resides in a subdirectory.
|
||||
# The object file name does not affect the name of the '.d' file.
|
||||
# pgcc 10.2 will output
|
||||
# foo.o: sub/foo.c sub/foo.h
|
||||
# and will wrap long lines using '\' :
|
||||
# foo.o: sub/foo.c ... \
|
||||
# sub/foo.h ... \
|
||||
# ...
|
||||
set_dir_from "$object"
|
||||
# Use the source, not the object, to determine the base name, since
|
||||
# that's sadly what pgcc will do too.
|
||||
set_base_from "$source"
|
||||
tmpdepfile=$base.d
|
||||
|
||||
# For projects that build the same source file twice into different object
|
||||
# files, the pgcc approach of using the *source* file root name can cause
|
||||
# problems in parallel builds. Use a locking strategy to avoid stomping on
|
||||
# the same $tmpdepfile.
|
||||
lockdir=$base.d-lock
|
||||
trap "
|
||||
echo '$0: caught signal, cleaning up...' >&2
|
||||
rmdir '$lockdir'
|
||||
exit 1
|
||||
" 1 2 13 15
|
||||
numtries=100
|
||||
i=$numtries
|
||||
while test $i -gt 0; do
|
||||
# mkdir is a portable test-and-set.
|
||||
if mkdir "$lockdir" 2>/dev/null; then
|
||||
# This process acquired the lock.
|
||||
"$@" -MD
|
||||
stat=$?
|
||||
# Release the lock.
|
||||
rmdir "$lockdir"
|
||||
break
|
||||
else
|
||||
# If the lock is being held by a different process, wait
|
||||
# until the winning process is done or we timeout.
|
||||
while test -d "$lockdir" && test $i -gt 0; do
|
||||
sleep 1
|
||||
i=`expr $i - 1`
|
||||
done
|
||||
fi
|
||||
i=`expr $i - 1`
|
||||
done
|
||||
trap - 1 2 13 15
|
||||
if test $i -le 0; then
|
||||
echo "$0: failed to acquire lock after $numtries attempts" >&2
|
||||
echo "$0: check lockdir '$lockdir'" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
# Each line is of the form `foo.o: dependent.h',
|
||||
# or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
|
||||
# Do two passes, one to just change these to
|
||||
# `$object: dependent.h' and one to simply `dependent.h:'.
|
||||
sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
|
||||
# Some versions of the HPUX 10.20 sed can't process this invocation
|
||||
# correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \
|
||||
| sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
hp2)
|
||||
# The "hp" stanza above does not work with aCC (C++) and HP's ia64
|
||||
# compilers, which have integrated preprocessors. The correct option
|
||||
# to use with these is +Maked; it writes dependencies to a file named
|
||||
# 'foo.d', which lands next to the object file, wherever that
|
||||
# happens to be.
|
||||
# Much of this is similar to the tru64 case; see comments there.
|
||||
set_dir_from "$object"
|
||||
set_base_from "$object"
|
||||
if test "$libtool" = yes; then
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir.libs/$base.d
|
||||
"$@" -Wc,+Maked
|
||||
else
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir$base.d
|
||||
"$@" +Maked
|
||||
fi
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
if test -f "$tmpdepfile"; then
|
||||
sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile"
|
||||
# Add 'dependent.h:' lines.
|
||||
sed -ne '2,${
|
||||
s/^ *//
|
||||
s/ \\*$//
|
||||
s/$/:/
|
||||
p
|
||||
}' "$tmpdepfile" >> "$depfile"
|
||||
else
|
||||
make_dummy_depfile
|
||||
fi
|
||||
rm -f "$tmpdepfile" "$tmpdepfile2"
|
||||
;;
|
||||
|
||||
tru64)
|
||||
# The Tru64 compiler uses -MD to generate dependencies as a side
|
||||
# effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.
|
||||
# At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
|
||||
# dependencies in 'foo.d' instead, so we check for that too.
|
||||
# Subdirectories are respected.
|
||||
set_dir_from "$object"
|
||||
set_base_from "$object"
|
||||
|
||||
if test "$libtool" = yes; then
|
||||
# Libtool generates 2 separate objects for the 2 libraries. These
|
||||
# two compilations output dependencies in $dir.libs/$base.o.d and
|
||||
# in $dir$base.o.d. We have to check for both files, because
|
||||
# one of the two compilations can be disabled. We should prefer
|
||||
# $dir$base.o.d over $dir.libs/$base.o.d because the latter is
|
||||
# automatically cleaned when .libs/ is deleted, while ignoring
|
||||
# the former would cause a distcleancheck panic.
|
||||
tmpdepfile1=$dir$base.o.d # libtool 1.5
|
||||
tmpdepfile2=$dir.libs/$base.o.d # Likewise.
|
||||
tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504
|
||||
"$@" -Wc,-MD
|
||||
else
|
||||
tmpdepfile1=$dir$base.d
|
||||
tmpdepfile2=$dir$base.d
|
||||
tmpdepfile3=$dir$base.d
|
||||
"$@" -MD
|
||||
fi
|
||||
|
||||
stat=$?
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
exit $stat
|
||||
fi
|
||||
|
||||
for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3"
|
||||
do
|
||||
test -f "$tmpdepfile" && break
|
||||
done
|
||||
# Same post-processing that is required for AIX mode.
|
||||
aix_post_process_depfile
|
||||
;;
|
||||
|
||||
msvc7)
|
||||
if test "$libtool" = yes; then
|
||||
showIncludes=-Wc,-showIncludes
|
||||
else
|
||||
showIncludes=-showIncludes
|
||||
fi
|
||||
"$@" $showIncludes > "$tmpdepfile"
|
||||
stat=$?
|
||||
grep -v '^Note: including file: ' "$tmpdepfile"
|
||||
if test $stat -ne 0; then
|
||||
rm -f "$tmpdepfile"
|
||||
exit $stat
|
||||
fi
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
# The first sed program below extracts the file names and escapes
|
||||
# backslashes for cygpath. The second sed program outputs the file
|
||||
# name when reading, but also accumulates all include files in the
|
||||
# hold buffer in order to output them again at the end. This only
|
||||
# works with sed implementations that can handle large buffers.
|
||||
sed < "$tmpdepfile" -n '
|
||||
/^Note: including file: *\(.*\)/ {
|
||||
s//\1/
|
||||
s/\\/\\\\/g
|
||||
p
|
||||
}' | $cygpath_u | sort -u | sed -n '
|
||||
s/ /\\ /g
|
||||
s/\(.*\)/'"$tab"'\1 \\/p
|
||||
s/.\(.*\) \\/\1:/
|
||||
H
|
||||
$ {
|
||||
s/.*/'"$tab"'/
|
||||
G
|
||||
p
|
||||
}' >> "$depfile"
|
||||
echo >> "$depfile" # make sure the fragment doesn't end with a backslash
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvc7msys)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
#nosideeffect)
|
||||
# This comment above is used by automake to tell side-effect
|
||||
# dependency tracking mechanisms from slower ones.
|
||||
|
||||
dashmstdout)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout, regardless of -o.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
# Remove '-o $object'.
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
test -z "$dashmflag" && dashmflag=-M
|
||||
# Require at least two characters before searching for ':'
|
||||
# in the target name. This is to cope with DOS-style filenames:
|
||||
# a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.
|
||||
"$@" $dashmflag |
|
||||
sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
cat < "$tmpdepfile" > "$depfile"
|
||||
# Some versions of the HPUX 10.20 sed can't process this sed invocation
|
||||
# correctly. Breaking it into two sed invocations is a workaround.
|
||||
tr ' ' "$nl" < "$tmpdepfile" \
|
||||
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
|
||||
| sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
dashXmstdout)
|
||||
# This case only exists to satisfy depend.m4. It is never actually
|
||||
# run, as this mode is specially recognized in the preamble.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
makedepend)
|
||||
"$@" || exit $?
|
||||
# Remove any Libtool call
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
# X makedepend
|
||||
shift
|
||||
cleared=no eat=no
|
||||
for arg
|
||||
do
|
||||
case $cleared in
|
||||
no)
|
||||
set ""; shift
|
||||
cleared=yes ;;
|
||||
esac
|
||||
if test $eat = yes; then
|
||||
eat=no
|
||||
continue
|
||||
fi
|
||||
case "$arg" in
|
||||
-D*|-I*)
|
||||
set fnord "$@" "$arg"; shift ;;
|
||||
# Strip any option that makedepend may not understand. Remove
|
||||
# the object too, otherwise makedepend will parse it as a source file.
|
||||
-arch)
|
||||
eat=yes ;;
|
||||
-*|$object)
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"; shift ;;
|
||||
esac
|
||||
done
|
||||
obj_suffix=`echo "$object" | sed 's/^.*\././'`
|
||||
touch "$tmpdepfile"
|
||||
${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
|
||||
rm -f "$depfile"
|
||||
# makedepend may prepend the VPATH from the source file name to the object.
|
||||
# No need to regex-escape $object, excess matching of '.' is harmless.
|
||||
sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile"
|
||||
# Some versions of the HPUX 10.20 sed can't process the last invocation
|
||||
# correctly. Breaking it into two sed invocations is a workaround.
|
||||
sed '1,2d' "$tmpdepfile" \
|
||||
| tr ' ' "$nl" \
|
||||
| sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \
|
||||
| sed -e 's/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile" "$tmpdepfile".bak
|
||||
;;
|
||||
|
||||
cpp)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
# Remove '-o $object'.
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case $arg in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift # fnord
|
||||
shift # $arg
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
"$@" -E \
|
||||
| sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||
-e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
|
||||
| sed '$ s: \\$::' > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
cat < "$tmpdepfile" >> "$depfile"
|
||||
sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvisualcpp)
|
||||
# Important note: in order to support this mode, a compiler *must*
|
||||
# always write the preprocessed file to stdout.
|
||||
"$@" || exit $?
|
||||
|
||||
# Remove the call to Libtool.
|
||||
if test "$libtool" = yes; then
|
||||
while test "X$1" != 'X--mode=compile'; do
|
||||
shift
|
||||
done
|
||||
shift
|
||||
fi
|
||||
|
||||
IFS=" "
|
||||
for arg
|
||||
do
|
||||
case "$arg" in
|
||||
-o)
|
||||
shift
|
||||
;;
|
||||
$object)
|
||||
shift
|
||||
;;
|
||||
"-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
|
||||
set fnord "$@"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set fnord "$@" "$arg"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
"$@" -E 2>/dev/null |
|
||||
sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile"
|
||||
rm -f "$depfile"
|
||||
echo "$object : \\" > "$depfile"
|
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile"
|
||||
echo "$tab" >> "$depfile"
|
||||
sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile"
|
||||
rm -f "$tmpdepfile"
|
||||
;;
|
||||
|
||||
msvcmsys)
|
||||
# This case exists only to let depend.m4 do its work. It works by
|
||||
# looking at the text of this script. This case will never be run,
|
||||
# since it is checked for above.
|
||||
exit 1
|
||||
;;
|
||||
|
||||
none)
|
||||
exec "$@"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown depmode $depmode" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
@@ -0,0 +1,541 @@
|
||||
#!/bin/sh
|
||||
# install - install a program, script, or datafile
|
||||
|
||||
scriptversion=2020-11-14.01; # UTC
|
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
# following copyright and license.
|
||||
#
|
||||
# Copyright (C) 1994 X Consortium
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
# Except as contained in this notice, the name of the X Consortium shall not
|
||||
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||
# ings in this Software without prior written authorization from the X Consor-
|
||||
# tium.
|
||||
#
|
||||
#
|
||||
# FSF changes to this file are in the public domain.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# 'make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch.
|
||||
|
||||
tab=' '
|
||||
nl='
|
||||
'
|
||||
IFS=" $tab$nl"
|
||||
|
||||
# Set DOITPROG to "echo" to test this script.
|
||||
|
||||
doit=${DOITPROG-}
|
||||
doit_exec=${doit:-exec}
|
||||
|
||||
# Put in absolute file names if you don't have them in your path;
|
||||
# or use environment vars.
|
||||
|
||||
chgrpprog=${CHGRPPROG-chgrp}
|
||||
chmodprog=${CHMODPROG-chmod}
|
||||
chownprog=${CHOWNPROG-chown}
|
||||
cmpprog=${CMPPROG-cmp}
|
||||
cpprog=${CPPROG-cp}
|
||||
mkdirprog=${MKDIRPROG-mkdir}
|
||||
mvprog=${MVPROG-mv}
|
||||
rmprog=${RMPROG-rm}
|
||||
stripprog=${STRIPPROG-strip}
|
||||
|
||||
posix_mkdir=
|
||||
|
||||
# Desired mode of installed file.
|
||||
mode=0755
|
||||
|
||||
# Create dirs (including intermediate dirs) using mode 755.
|
||||
# This is like GNU 'install' as of coreutils 8.32 (2020).
|
||||
mkdir_umask=22
|
||||
|
||||
backupsuffix=
|
||||
chgrpcmd=
|
||||
chmodcmd=$chmodprog
|
||||
chowncmd=
|
||||
mvcmd=$mvprog
|
||||
rmcmd="$rmprog -f"
|
||||
stripcmd=
|
||||
|
||||
src=
|
||||
dst=
|
||||
dir_arg=
|
||||
dst_arg=
|
||||
|
||||
copy_on_change=false
|
||||
is_target_a_directory=possibly
|
||||
|
||||
usage="\
|
||||
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||
or: $0 [OPTION]... -d DIRECTORIES...
|
||||
|
||||
In the 1st form, copy SRCFILE to DSTFILE.
|
||||
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||
In the 4th, create DIRECTORIES.
|
||||
|
||||
Options:
|
||||
--help display this help and exit.
|
||||
--version display version info and exit.
|
||||
|
||||
-c (ignored)
|
||||
-C install only if different (preserve data modification time)
|
||||
-d create directories instead of installing files.
|
||||
-g GROUP $chgrpprog installed files to GROUP.
|
||||
-m MODE $chmodprog installed files to MODE.
|
||||
-o USER $chownprog installed files to USER.
|
||||
-p pass -p to $cpprog.
|
||||
-s $stripprog installed files.
|
||||
-S SUFFIX attempt to back up existing files, with suffix SUFFIX.
|
||||
-t DIRECTORY install into DIRECTORY.
|
||||
-T report an error if DSTFILE is a directory.
|
||||
|
||||
Environment variables override the default commands:
|
||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||
RMPROG STRIPPROG
|
||||
|
||||
By default, rm is invoked with -f; when overridden with RMPROG,
|
||||
it's up to you to specify -f if you want it.
|
||||
|
||||
If -S is not specified, no backups are attempted.
|
||||
|
||||
Email bug reports to [email protected].
|
||||
Automake home page: https://www.gnu.org/software/automake/
|
||||
"
|
||||
|
||||
while test $# -ne 0; do
|
||||
case $1 in
|
||||
-c) ;;
|
||||
|
||||
-C) copy_on_change=true;;
|
||||
|
||||
-d) dir_arg=true;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift;;
|
||||
|
||||
--help) echo "$usage"; exit $?;;
|
||||
|
||||
-m) mode=$2
|
||||
case $mode in
|
||||
*' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*)
|
||||
echo "$0: invalid mode: $mode" >&2
|
||||
exit 1;;
|
||||
esac
|
||||
shift;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift;;
|
||||
|
||||
-p) cpprog="$cpprog -p";;
|
||||
|
||||
-s) stripcmd=$stripprog;;
|
||||
|
||||
-S) backupsuffix="$2"
|
||||
shift;;
|
||||
|
||||
-t)
|
||||
is_target_a_directory=always
|
||||
dst_arg=$2
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $dst_arg in
|
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||
esac
|
||||
shift;;
|
||||
|
||||
-T) is_target_a_directory=never;;
|
||||
|
||||
--version) echo "$0 $scriptversion"; exit $?;;
|
||||
|
||||
--) shift
|
||||
break;;
|
||||
|
||||
-*) echo "$0: invalid option: $1" >&2
|
||||
exit 1;;
|
||||
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# We allow the use of options -d and -T together, by making -d
|
||||
# take the precedence; this is for compatibility with GNU install.
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
if test -n "$dst_arg"; then
|
||||
echo "$0: target directory not allowed when installing a directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||
# When -d is used, all remaining arguments are directories to create.
|
||||
# When -t is used, the destination is already specified.
|
||||
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||
for arg
|
||||
do
|
||||
if test -n "$dst_arg"; then
|
||||
# $@ is not empty: it contains at least $arg.
|
||||
set fnord "$@" "$dst_arg"
|
||||
shift # fnord
|
||||
fi
|
||||
shift # arg
|
||||
dst_arg=$arg
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $dst_arg in
|
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
if test $# -eq 0; then
|
||||
if test -z "$dir_arg"; then
|
||||
echo "$0: no input file specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
# It's OK to call 'install-sh -d' without argument.
|
||||
# This can happen when creating conditional directories.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -z "$dir_arg"; then
|
||||
if test $# -gt 1 || test "$is_target_a_directory" = always; then
|
||||
if test ! -d "$dst_arg"; then
|
||||
echo "$0: $dst_arg: Is not a directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -z "$dir_arg"; then
|
||||
do_exit='(exit $ret); exit $ret'
|
||||
trap "ret=129; $do_exit" 1
|
||||
trap "ret=130; $do_exit" 2
|
||||
trap "ret=141; $do_exit" 13
|
||||
trap "ret=143; $do_exit" 15
|
||||
|
||||
# Set umask so as not to create temps with too-generous modes.
|
||||
# However, 'strip' requires both read and write access to temps.
|
||||
case $mode in
|
||||
# Optimize common cases.
|
||||
*644) cp_umask=133;;
|
||||
*755) cp_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw='% 200'
|
||||
fi
|
||||
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||
*)
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw=,u+rw
|
||||
fi
|
||||
cp_umask=$mode$u_plus_rw;;
|
||||
esac
|
||||
fi
|
||||
|
||||
for src
|
||||
do
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $src in
|
||||
-* | [=\(\)!]) src=./$src;;
|
||||
esac
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
dst=$src
|
||||
dstdir=$dst
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
# Don't chown directories that already exist.
|
||||
if test $dstdir_status = 0; then
|
||||
chowncmd=""
|
||||
fi
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
if test ! -f "$src" && test ! -d "$src"; then
|
||||
echo "$0: $src does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$dst_arg"; then
|
||||
echo "$0: no destination specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
dst=$dst_arg
|
||||
|
||||
# If destination is a directory, append the input filename.
|
||||
if test -d "$dst"; then
|
||||
if test "$is_target_a_directory" = never; then
|
||||
echo "$0: $dst_arg: Is a directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
dstdir=$dst
|
||||
dstbase=`basename "$src"`
|
||||
case $dst in
|
||||
*/) dst=$dst$dstbase;;
|
||||
*) dst=$dst/$dstbase;;
|
||||
esac
|
||||
dstdir_status=0
|
||||
else
|
||||
dstdir=`dirname "$dst"`
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
case $dstdir in
|
||||
*/) dstdirslash=$dstdir;;
|
||||
*) dstdirslash=$dstdir/;;
|
||||
esac
|
||||
|
||||
obsolete_mkdir_used=false
|
||||
|
||||
if test $dstdir_status != 0; then
|
||||
case $posix_mkdir in
|
||||
'')
|
||||
# With -d, create the new directory with the user-specified mode.
|
||||
# Otherwise, rely on $mkdir_umask.
|
||||
if test -n "$dir_arg"; then
|
||||
mkdir_mode=-m$mode
|
||||
else
|
||||
mkdir_mode=
|
||||
fi
|
||||
|
||||
posix_mkdir=false
|
||||
# The $RANDOM variable is not portable (e.g., dash). Use it
|
||||
# here however when possible just to lower collision chance.
|
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||
|
||||
trap '
|
||||
ret=$?
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null
|
||||
exit $ret
|
||||
' 0
|
||||
|
||||
# Because "mkdir -p" follows existing symlinks and we likely work
|
||||
# directly in world-writeable /tmp, make sure that the '$tmpdir'
|
||||
# directory is successfully created first before we actually test
|
||||
# 'mkdir -p'.
|
||||
if (umask $mkdir_umask &&
|
||||
$mkdirprog $mkdir_mode "$tmpdir" &&
|
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1
|
||||
then
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
test_tmpdir="$tmpdir/a"
|
||||
ls_ld_tmpdir=`ls -ld "$test_tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
d????-?r-*) different_mode=700;;
|
||||
d????-?--*) different_mode=755;;
|
||||
*) false;;
|
||||
esac &&
|
||||
$mkdirprog -m$different_mode -p -- "$test_tmpdir" && {
|
||||
ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"`
|
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||
}
|
||||
}
|
||||
then posix_mkdir=:
|
||||
fi
|
||||
rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir"
|
||||
else
|
||||
# Remove any dirs left behind by ancient mkdir implementations.
|
||||
rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null
|
||||
fi
|
||||
trap '' 0;;
|
||||
esac
|
||||
|
||||
if
|
||||
$posix_mkdir && (
|
||||
umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||
)
|
||||
then :
|
||||
else
|
||||
|
||||
# mkdir does not conform to POSIX,
|
||||
# or it failed possibly due to a race condition. Create the
|
||||
# directory the slow way, step by step, checking for races as we go.
|
||||
|
||||
case $dstdir in
|
||||
/*) prefix='/';;
|
||||
[-=\(\)!]*) prefix='./';;
|
||||
*) prefix='';;
|
||||
esac
|
||||
|
||||
oIFS=$IFS
|
||||
IFS=/
|
||||
set -f
|
||||
set fnord $dstdir
|
||||
shift
|
||||
set +f
|
||||
IFS=$oIFS
|
||||
|
||||
prefixes=
|
||||
|
||||
for d
|
||||
do
|
||||
test X"$d" = X && continue
|
||||
|
||||
prefix=$prefix$d
|
||||
if test -d "$prefix"; then
|
||||
prefixes=
|
||||
else
|
||||
if $posix_mkdir; then
|
||||
(umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||
# Don't fail if two instances are running concurrently.
|
||||
test -d "$prefix" || exit 1
|
||||
else
|
||||
case $prefix in
|
||||
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||
*) qprefix=$prefix;;
|
||||
esac
|
||||
prefixes="$prefixes '$qprefix'"
|
||||
fi
|
||||
fi
|
||||
prefix=$prefix/
|
||||
done
|
||||
|
||||
if test -n "$prefixes"; then
|
||||
# Don't fail if two instances are running concurrently.
|
||||
(umask $mkdir_umask &&
|
||||
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||
test -d "$dstdir" || exit 1
|
||||
obsolete_mkdir_used=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||
else
|
||||
|
||||
# Make a couple of temp file names in the proper directory.
|
||||
dsttmp=${dstdirslash}_inst.$$_
|
||||
rmtmp=${dstdirslash}_rm.$$_
|
||||
|
||||
# Trap to clean up those temp files at exit.
|
||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||
|
||||
# Copy the file name to the temp name.
|
||||
(umask $cp_umask &&
|
||||
{ test -z "$stripcmd" || {
|
||||
# Create $dsttmp read-write so that cp doesn't create it read-only,
|
||||
# which would cause strip to fail.
|
||||
if test -z "$doit"; then
|
||||
: >"$dsttmp" # No need to fork-exec 'touch'.
|
||||
else
|
||||
$doit touch "$dsttmp"
|
||||
fi
|
||||
}
|
||||
} &&
|
||||
$doit_exec $cpprog "$src" "$dsttmp") &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits.
|
||||
#
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||
#
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
||||
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
||||
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||
|
||||
# If -C, don't bother to copy if it wouldn't change the file.
|
||||
if $copy_on_change &&
|
||||
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
||||
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
||||
set -f &&
|
||||
set X $old && old=:$2:$4:$5:$6 &&
|
||||
set X $new && new=:$2:$4:$5:$6 &&
|
||||
set +f &&
|
||||
test "$old" = "$new" &&
|
||||
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
||||
then
|
||||
rm -f "$dsttmp"
|
||||
else
|
||||
# If $backupsuffix is set, and the file being installed
|
||||
# already exists, attempt a backup. Don't worry if it fails,
|
||||
# e.g., if mv doesn't support -f.
|
||||
if test -n "$backupsuffix" && test -f "$dst"; then
|
||||
$doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null
|
||||
fi
|
||||
|
||||
# Rename the file to the real destination.
|
||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||
|
||||
# The rename failed, perhaps because mv can't rename something else
|
||||
# to itself, or perhaps because mv is so ancient that it does not
|
||||
# support -f.
|
||||
{
|
||||
# Now remove or move aside any old file at destination location.
|
||||
# We try this two ways since rm can't unlink itself on some
|
||||
# systems and the destination file might be busy for other
|
||||
# reasons. In this case, the final cleanup might fail but the new
|
||||
# file should still install successfully.
|
||||
{
|
||||
test ! -f "$dst" ||
|
||||
$doit $rmcmd "$dst" 2>/dev/null ||
|
||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||
{ $doit $rmcmd "$rmtmp" 2>/dev/null; :; }
|
||||
} ||
|
||||
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||
(exit 1); exit 1
|
||||
}
|
||||
} &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
$doit $mvcmd "$dsttmp" "$dst"
|
||||
}
|
||||
fi || exit 1
|
||||
|
||||
trap '' 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,215 @@
|
||||
#! /bin/sh
|
||||
# Common wrapper for a few potentially missing GNU programs.
|
||||
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
|
||||
# Originally written by Fran,cois Pinard <[email protected]>, 1996.
|
||||
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
if test $# -eq 0; then
|
||||
echo 1>&2 "Try '$0 --help' for more information"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
|
||||
--is-lightweight)
|
||||
# Used by our autoconf macros to check whether the available missing
|
||||
# script is modern enough.
|
||||
exit 0
|
||||
;;
|
||||
|
||||
--run)
|
||||
# Back-compat with the calling convention used by older automake.
|
||||
shift
|
||||
;;
|
||||
|
||||
-h|--h|--he|--hel|--help)
|
||||
echo "\
|
||||
$0 [OPTION]... PROGRAM [ARGUMENT]...
|
||||
|
||||
Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
|
||||
to PROGRAM being missing or too old.
|
||||
|
||||
Options:
|
||||
-h, --help display this help and exit
|
||||
-v, --version output version information and exit
|
||||
|
||||
Supported PROGRAM values:
|
||||
aclocal autoconf autoheader autom4te automake makeinfo
|
||||
bison yacc flex lex help2man
|
||||
|
||||
Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
|
||||
'g' are ignored when checking the name.
|
||||
|
||||
Send bug reports to <[email protected]>."
|
||||
exit $?
|
||||
;;
|
||||
|
||||
-v|--v|--ve|--ver|--vers|--versi|--versio|--version)
|
||||
echo "missing $scriptversion (GNU Automake)"
|
||||
exit $?
|
||||
;;
|
||||
|
||||
-*)
|
||||
echo 1>&2 "$0: unknown '$1' option"
|
||||
echo 1>&2 "Try '$0 --help' for more information"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
# Run the given program, remember its exit status.
|
||||
"$@"; st=$?
|
||||
|
||||
# If it succeeded, we are done.
|
||||
test $st -eq 0 && exit 0
|
||||
|
||||
# Also exit now if we it failed (or wasn't found), and '--version' was
|
||||
# passed; such an option is passed most likely to detect whether the
|
||||
# program is present and works.
|
||||
case $2 in --version|--help) exit $st;; esac
|
||||
|
||||
# Exit code 63 means version mismatch. This often happens when the user
|
||||
# tries to use an ancient version of a tool on a file that requires a
|
||||
# minimum version.
|
||||
if test $st -eq 63; then
|
||||
msg="probably too old"
|
||||
elif test $st -eq 127; then
|
||||
# Program was missing.
|
||||
msg="missing on your system"
|
||||
else
|
||||
# Program was found and executed, but failed. Give up.
|
||||
exit $st
|
||||
fi
|
||||
|
||||
perl_URL=https://www.perl.org/
|
||||
flex_URL=https://github.com/westes/flex
|
||||
gnu_software_URL=https://www.gnu.org/software
|
||||
|
||||
program_details ()
|
||||
{
|
||||
case $1 in
|
||||
aclocal|automake)
|
||||
echo "The '$1' program is part of the GNU Automake package:"
|
||||
echo "<$gnu_software_URL/automake>"
|
||||
echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
|
||||
echo "<$gnu_software_URL/autoconf>"
|
||||
echo "<$gnu_software_URL/m4/>"
|
||||
echo "<$perl_URL>"
|
||||
;;
|
||||
autoconf|autom4te|autoheader)
|
||||
echo "The '$1' program is part of the GNU Autoconf package:"
|
||||
echo "<$gnu_software_URL/autoconf/>"
|
||||
echo "It also requires GNU m4 and Perl in order to run:"
|
||||
echo "<$gnu_software_URL/m4/>"
|
||||
echo "<$perl_URL>"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
give_advice ()
|
||||
{
|
||||
# Normalize program name to check for.
|
||||
normalized_program=`echo "$1" | sed '
|
||||
s/^gnu-//; t
|
||||
s/^gnu//; t
|
||||
s/^g//; t'`
|
||||
|
||||
printf '%s\n' "'$1' is $msg."
|
||||
|
||||
configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
|
||||
case $normalized_program in
|
||||
autoconf*)
|
||||
echo "You should only need it if you modified 'configure.ac',"
|
||||
echo "or m4 files included by it."
|
||||
program_details 'autoconf'
|
||||
;;
|
||||
autoheader*)
|
||||
echo "You should only need it if you modified 'acconfig.h' or"
|
||||
echo "$configure_deps."
|
||||
program_details 'autoheader'
|
||||
;;
|
||||
automake*)
|
||||
echo "You should only need it if you modified 'Makefile.am' or"
|
||||
echo "$configure_deps."
|
||||
program_details 'automake'
|
||||
;;
|
||||
aclocal*)
|
||||
echo "You should only need it if you modified 'acinclude.m4' or"
|
||||
echo "$configure_deps."
|
||||
program_details 'aclocal'
|
||||
;;
|
||||
autom4te*)
|
||||
echo "You might have modified some maintainer files that require"
|
||||
echo "the 'autom4te' program to be rebuilt."
|
||||
program_details 'autom4te'
|
||||
;;
|
||||
bison*|yacc*)
|
||||
echo "You should only need it if you modified a '.y' file."
|
||||
echo "You may want to install the GNU Bison package:"
|
||||
echo "<$gnu_software_URL/bison/>"
|
||||
;;
|
||||
lex*|flex*)
|
||||
echo "You should only need it if you modified a '.l' file."
|
||||
echo "You may want to install the Fast Lexical Analyzer package:"
|
||||
echo "<$flex_URL>"
|
||||
;;
|
||||
help2man*)
|
||||
echo "You should only need it if you modified a dependency" \
|
||||
"of a man page."
|
||||
echo "You may want to install the GNU Help2man package:"
|
||||
echo "<$gnu_software_URL/help2man/>"
|
||||
;;
|
||||
makeinfo*)
|
||||
echo "You should only need it if you modified a '.texi' file, or"
|
||||
echo "any other file indirectly affecting the aspect of the manual."
|
||||
echo "You might want to install the Texinfo package:"
|
||||
echo "<$gnu_software_URL/texinfo/>"
|
||||
echo "The spurious makeinfo call might also be the consequence of"
|
||||
echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
|
||||
echo "want to install GNU make:"
|
||||
echo "<$gnu_software_URL/make/>"
|
||||
;;
|
||||
*)
|
||||
echo "You might have modified some files without having the proper"
|
||||
echo "tools for further handling them. Check the 'README' file, it"
|
||||
echo "often tells you about the needed prerequisites for installing"
|
||||
echo "this package. You may also peek at any GNU archive site, in"
|
||||
echo "case some other package contains this missing '$1' program."
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
give_advice "$1" | sed -e '1s/^/WARNING: /' \
|
||||
-e '2,$s/^/ /' >&2
|
||||
|
||||
# Propagate the correct exit status (expected to be 127 for a program
|
||||
# not found, 63 for a program that failed due to version mismatch).
|
||||
exit $st
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
@@ -0,0 +1,153 @@
|
||||
#! /bin/sh
|
||||
# test-driver - basic testsuite driver script.
|
||||
|
||||
scriptversion=2018-03-07.03; # UTC
|
||||
|
||||
# Copyright (C) 2011-2021 Free Software Foundation, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <[email protected]> or send patches to
|
||||
# <[email protected]>.
|
||||
|
||||
# Make unconditional expansion of undefined variables an error. This
|
||||
# helps a lot in preventing typo-related bugs.
|
||||
set -u
|
||||
|
||||
usage_error ()
|
||||
{
|
||||
echo "$0: $*" >&2
|
||||
print_usage >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
print_usage ()
|
||||
{
|
||||
cat <<END
|
||||
Usage:
|
||||
test-driver --test-name NAME --log-file PATH --trs-file PATH
|
||||
[--expect-failure {yes|no}] [--color-tests {yes|no}]
|
||||
[--enable-hard-errors {yes|no}] [--]
|
||||
TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS]
|
||||
|
||||
The '--test-name', '--log-file' and '--trs-file' options are mandatory.
|
||||
See the GNU Automake documentation for information.
|
||||
END
|
||||
}
|
||||
|
||||
test_name= # Used for reporting.
|
||||
log_file= # Where to save the output of the test script.
|
||||
trs_file= # Where to save the metadata of the test run.
|
||||
expect_failure=no
|
||||
color_tests=no
|
||||
enable_hard_errors=yes
|
||||
while test $# -gt 0; do
|
||||
case $1 in
|
||||
--help) print_usage; exit $?;;
|
||||
--version) echo "test-driver $scriptversion"; exit $?;;
|
||||
--test-name) test_name=$2; shift;;
|
||||
--log-file) log_file=$2; shift;;
|
||||
--trs-file) trs_file=$2; shift;;
|
||||
--color-tests) color_tests=$2; shift;;
|
||||
--expect-failure) expect_failure=$2; shift;;
|
||||
--enable-hard-errors) enable_hard_errors=$2; shift;;
|
||||
--) shift; break;;
|
||||
-*) usage_error "invalid option: '$1'";;
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
missing_opts=
|
||||
test x"$test_name" = x && missing_opts="$missing_opts --test-name"
|
||||
test x"$log_file" = x && missing_opts="$missing_opts --log-file"
|
||||
test x"$trs_file" = x && missing_opts="$missing_opts --trs-file"
|
||||
if test x"$missing_opts" != x; then
|
||||
usage_error "the following mandatory options are missing:$missing_opts"
|
||||
fi
|
||||
|
||||
if test $# -eq 0; then
|
||||
usage_error "missing argument"
|
||||
fi
|
||||
|
||||
if test $color_tests = yes; then
|
||||
# Keep this in sync with 'lib/am/check.am:$(am__tty_colors)'.
|
||||
red='[0;31m' # Red.
|
||||
grn='[0;32m' # Green.
|
||||
lgn='[1;32m' # Light green.
|
||||
blu='[1;34m' # Blue.
|
||||
mgn='[0;35m' # Magenta.
|
||||
std='[m' # No color.
|
||||
else
|
||||
red= grn= lgn= blu= mgn= std=
|
||||
fi
|
||||
|
||||
do_exit='rm -f $log_file $trs_file; (exit $st); exit $st'
|
||||
trap "st=129; $do_exit" 1
|
||||
trap "st=130; $do_exit" 2
|
||||
trap "st=141; $do_exit" 13
|
||||
trap "st=143; $do_exit" 15
|
||||
|
||||
# Test script is run here. We create the file first, then append to it,
|
||||
# to ameliorate tests themselves also writing to the log file. Our tests
|
||||
# don't, but others can (automake bug#35762).
|
||||
: >"$log_file"
|
||||
"$@" >>"$log_file" 2>&1
|
||||
estatus=$?
|
||||
|
||||
if test $enable_hard_errors = no && test $estatus -eq 99; then
|
||||
tweaked_estatus=1
|
||||
else
|
||||
tweaked_estatus=$estatus
|
||||
fi
|
||||
|
||||
case $tweaked_estatus:$expect_failure in
|
||||
0:yes) col=$red res=XPASS recheck=yes gcopy=yes;;
|
||||
0:*) col=$grn res=PASS recheck=no gcopy=no;;
|
||||
77:*) col=$blu res=SKIP recheck=no gcopy=yes;;
|
||||
99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;;
|
||||
*:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;;
|
||||
*:*) col=$red res=FAIL recheck=yes gcopy=yes;;
|
||||
esac
|
||||
|
||||
# Report the test outcome and exit status in the logs, so that one can
|
||||
# know whether the test passed or failed simply by looking at the '.log'
|
||||
# file, without the need of also peaking into the corresponding '.trs'
|
||||
# file (automake bug#11814).
|
||||
echo "$res $test_name (exit status: $estatus)" >>"$log_file"
|
||||
|
||||
# Report outcome to console.
|
||||
echo "${col}${res}${std}: $test_name"
|
||||
|
||||
# Register the test result, and other relevant metadata.
|
||||
echo ":test-result: $res" > $trs_file
|
||||
echo ":global-test-result: $res" >> $trs_file
|
||||
echo ":recheck: $recheck" >> $trs_file
|
||||
echo ":copy-in-global-log: $gcopy" >> $trs_file
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'before-save-hook 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC0"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(MPT_PACKAGE)
|
||||
#define OPENMPT_VERSION_IS_PACKAGE 1
|
||||
#else
|
||||
#define OPENMPT_VERSION_IS_PACKAGE 0
|
||||
#endif
|
||||
|
||||
#if defined(MPT_SVNURL)
|
||||
#define OPENMPT_VERSION_URL MPT_SVNURL
|
||||
#endif
|
||||
|
||||
#if defined(MPT_SVNVERSION)
|
||||
#define OPENMPT_VERSION_SVNVERSION MPT_SVNVERSION
|
||||
#endif
|
||||
|
||||
#if defined(MPT_SVNDATE)
|
||||
#define OPENMPT_VERSION_DATE MPT_SVNDATE
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
/*
|
||||
* BuildSettings.h
|
||||
* ---------------
|
||||
* Purpose: Global, user settable compile time flags (and some global system header configuration)
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#include "BuildSettingsCompiler.h"
|
||||
|
||||
|
||||
|
||||
#include "mpt/base/detect_arch.hpp"
|
||||
#include "mpt/base/detect_compiler.hpp"
|
||||
#include "mpt/base/detect_os.hpp"
|
||||
#include "mpt/base/detect_quirks.hpp"
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && defined(LIBOPENMPT_BUILD)
|
||||
#error "either MODPLUG_TRACKER or LIBOPENMPT_BUILD has to be defined"
|
||||
#elif defined(MODPLUG_TRACKER)
|
||||
// nothing
|
||||
#define MPT_INLINE_NS mptx
|
||||
#elif defined(LIBOPENMPT_BUILD)
|
||||
// nothing
|
||||
#define MPT_INLINE_NS mpt_libopenmpt
|
||||
#else
|
||||
#error "either MODPLUG_TRACKER or LIBOPENMPT_BUILD has to be defined"
|
||||
#endif // MODPLUG_TRACKER || LIBOPENMPT_BUILD
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
#if defined(MPT_BUILD_RETRO)
|
||||
#define OPENMPT_BUILD_VARIANT "Retro"
|
||||
#define OPENMPT_BUILD_VARIANT_MONIKER " RETRO"
|
||||
#else
|
||||
#if MPT_OS_WINDOWS
|
||||
#if MPT_WINNT_AT_LEAST(MPT_WIN_10)
|
||||
#define OPENMPT_BUILD_VARIANT "Standard"
|
||||
#define OPENMPT_BUILD_VARIANT_MONIKER ""
|
||||
#else
|
||||
#define OPENMPT_BUILD_VARIANT "Legacy"
|
||||
#define OPENMPT_BUILD_VARIANT_MONIKER ""
|
||||
#endif
|
||||
#else
|
||||
#define OPENMPT_BUILD_VARIANT "Unknown"
|
||||
#define OPENMPT_BUILD_VARIANT_MONIKER ""
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define MPT_WITH_DMO
|
||||
|
||||
#define MPT_WITH_VST
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
#if MPT_WINNT_AT_LEAST(MPT_WIN_7)
|
||||
#define MPT_WITH_MEDIAFOUNDATION
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
#if MPT_WINNT_AT_LEAST(MPT_WIN_10)
|
||||
#define MPT_WITH_WINDOWS10
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
// Enable built-in test suite.
|
||||
#if defined(MPT_BUILD_DEBUG) || defined(MPT_BUILD_CHECKED)
|
||||
#define ENABLE_TESTS
|
||||
#endif
|
||||
|
||||
// Enable generation and verification of playback traces
|
||||
#define MPT_ENABLE_PLAYBACK_TRACE
|
||||
|
||||
// Disable any file saving functionality (not really useful except for the player library)
|
||||
//#define MODPLUG_NO_FILESAVE
|
||||
|
||||
// Disable any debug logging
|
||||
#if !defined(MPT_BUILD_DEBUG) && !defined(MPT_BUILD_CHECKED) && !defined(MPT_BUILD_WINESUPPORT)
|
||||
#define MPT_LOG_GLOBAL_LEVEL_STATIC
|
||||
#define MPT_LOG_GLOBAL_LEVEL 0
|
||||
#endif
|
||||
|
||||
// Enable all individual logging macros and MPT_LOG calls
|
||||
//#define MPT_ALL_LOGGING
|
||||
|
||||
// Disable all runtime asserts
|
||||
#if !defined(MPT_BUILD_DEBUG) && !defined(MPT_BUILD_CHECKED) && !defined(MPT_BUILD_WINESUPPORT)
|
||||
#define NO_ASSERTS
|
||||
#endif
|
||||
|
||||
// Enable global ComponentManager
|
||||
#define MPT_COMPONENT_MANAGER 1
|
||||
|
||||
// Support for externally linked samples e.g. in MPTM files
|
||||
#define MPT_EXTERNAL_SAMPLES
|
||||
|
||||
// Support mpt::CharsetLocale
|
||||
#define MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
// Use architecture-specific intrinsics
|
||||
#define MPT_ENABLE_ARCH_INTRINSICS
|
||||
|
||||
#define MPT_ENABLE_UPDATE
|
||||
|
||||
#if defined(MPT_BUILD_DEBUG)
|
||||
#define MPT_ENABLE_PLAYBACK_TEST_MENU
|
||||
#endif
|
||||
|
||||
// Disable unarchiving support
|
||||
//#define NO_ARCHIVE_SUPPORT
|
||||
|
||||
// Disable the built-in reverb effect
|
||||
//#define NO_REVERB
|
||||
|
||||
// Disable built-in miscellaneous DSP effects (surround, mega bass, noise reduction)
|
||||
//#define NO_DSP
|
||||
|
||||
// Disable the built-in equalizer.
|
||||
//#define NO_EQ
|
||||
|
||||
// Disable the built-in automatic gain control
|
||||
//#define NO_AGC
|
||||
|
||||
// (HACK) Define to build without any plugin support
|
||||
//#define NO_PLUGINS
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
#if defined(LIBOPENMPT_BUILD)
|
||||
|
||||
#ifdef MPT_WITH_FLAC
|
||||
#error "Building libopenmpt with FLAC is useless and not a supported configuration. Please fix your build system to not list libflac as a dependency for libopenmpt itself. It is only a dependency of openmpt123."
|
||||
#endif
|
||||
|
||||
#ifndef LIBOPENMPT_NO_DEPRECATE
|
||||
#define LIBOPENMPT_NO_DEPRECATE
|
||||
#endif
|
||||
|
||||
#if (defined(_DEBUG) || defined(DEBUG)) && !defined(MPT_BUILD_DEBUG)
|
||||
#define MPT_BUILD_DEBUG
|
||||
#endif
|
||||
|
||||
#if defined(LIBOPENMPT_BUILD_TEST)
|
||||
#define ENABLE_TESTS
|
||||
#define MPT_ENABLE_PLAYBACK_TRACE
|
||||
#else
|
||||
#define MODPLUG_NO_FILESAVE
|
||||
#endif
|
||||
#if defined(MPT_BUILD_ANALZYED) || defined(MPT_BUILD_DEBUG) || defined(MPT_BUILD_CHECKED) || defined(ENABLE_TESTS)
|
||||
// enable asserts
|
||||
#else
|
||||
#define NO_ASSERTS
|
||||
#endif
|
||||
//#define MPT_ALL_LOGGING
|
||||
#define MPT_COMPONENT_MANAGER 0
|
||||
//#define MPT_EXTERNAL_SAMPLES
|
||||
#if defined(ENABLE_TESTS) || defined(MPT_BUILD_HACK_ARCHIVE_SUPPORT)
|
||||
#define MPT_ENABLE_CHARSET_LOCALE
|
||||
#else
|
||||
//#define MPT_ENABLE_CHARSET_LOCALE
|
||||
#endif
|
||||
// Do not use architecture-specifid intrinsics in library builds. There is just about no codepath which would use it anyway.
|
||||
//#define MPT_ENABLE_ARCH_INTRINSICS
|
||||
#if defined(MPT_BUILD_HACK_ARCHIVE_SUPPORT)
|
||||
//#define NO_ARCHIVE_SUPPORT
|
||||
#else
|
||||
#define NO_ARCHIVE_SUPPORT
|
||||
#endif
|
||||
//#define NO_REVERB
|
||||
#define NO_DSP
|
||||
#define NO_EQ
|
||||
#define NO_AGC
|
||||
//#define NO_PLUGINS
|
||||
|
||||
#endif // LIBOPENMPT_BUILD
|
||||
|
||||
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
#ifndef MPT_ENABLE_CHARSET_LOCALE
|
||||
#define MPT_ENABLE_CHARSET_LOCALE
|
||||
#endif
|
||||
|
||||
#elif MPT_OS_LINUX
|
||||
|
||||
#elif MPT_OS_ANDROID
|
||||
|
||||
#elif MPT_OS_EMSCRIPTEN
|
||||
|
||||
#elif MPT_OS_MACOSX_OR_IOS
|
||||
|
||||
#elif MPT_OS_DJGPP
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define MPT_TIME_UTC_ON_DISK 0
|
||||
#define MPT_TIME_UTC_ON_DISK_VERSION MPT_V("1.31.00.13")
|
||||
|
||||
|
||||
|
||||
// fixing stuff up
|
||||
|
||||
#if defined(MPT_BUILD_ANALYZED) || defined(MPT_BUILD_CHECKED)
|
||||
#ifdef NO_ASSERTS
|
||||
#undef NO_ASSERTS // static or dynamic analyzers want assertions on
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MPT_BUILD_FUZZER)
|
||||
#ifndef MPT_FUZZ_TRACKER
|
||||
#define MPT_FUZZ_TRACKER
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MPT_ENABLE_ARCH_INTRINSICS)
|
||||
#if MPT_ARCH_X86
|
||||
|
||||
#define MPT_ENABLE_ARCH_X86
|
||||
|
||||
#define MPT_WANT_ARCH_INTRINSICS_X86_SSE
|
||||
#define MPT_WANT_ARCH_INTRINSICS_X86_SSE2
|
||||
|
||||
#elif MPT_ARCH_AMD64
|
||||
|
||||
#define MPT_ENABLE_ARCH_AMD64
|
||||
|
||||
#define MPT_WANT_ARCH_INTRINSICS_X86_SSE
|
||||
#define MPT_WANT_ARCH_INTRINSICS_X86_SSE2
|
||||
|
||||
#endif // arch
|
||||
#endif // MPT_ENABLE_ARCH_INTRINSICS
|
||||
|
||||
#if defined(ENABLE_TESTS) && defined(MODPLUG_NO_FILESAVE)
|
||||
#undef MODPLUG_NO_FILESAVE // tests recommend file saving
|
||||
#endif
|
||||
|
||||
#if defined(MPT_WITH_ZLIB) && defined(MPT_WITH_MINIZ)
|
||||
// Only one deflate implementation should be used. Prefer zlib.
|
||||
#undef MPT_WITH_MINIZ
|
||||
#endif
|
||||
|
||||
#if !MPT_OS_WINDOWS && defined(MPT_WITH_MEDIAFOUNDATION)
|
||||
#undef MPT_WITH_MEDIAFOUNDATION // MediaFoundation requires Windows
|
||||
#endif
|
||||
|
||||
#if !MPT_COMPILER_MSVC && !MPT_COMPILER_CLANG && defined(MPT_WITH_MEDIAFOUNDATION)
|
||||
#undef MPT_WITH_MEDIAFOUNDATION // MediaFoundation requires MSVC or Clang due to ATL (no MinGW support)
|
||||
#endif
|
||||
|
||||
#if (defined(MPT_WITH_MPG123) || defined(MPT_WITH_MINIMP3)) && !defined(MPT_ENABLE_MP3_SAMPLES)
|
||||
#define MPT_ENABLE_MP3_SAMPLES
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_TESTS)
|
||||
#define MPT_ENABLE_FILEIO // Test suite requires PathString for file loading.
|
||||
#endif
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_ENABLE_FILEIO)
|
||||
#define MPT_ENABLE_FILEIO // Tracker requires disk file io
|
||||
#endif
|
||||
|
||||
#if defined(MPT_EXTERNAL_SAMPLES) && !defined(MPT_ENABLE_FILEIO)
|
||||
#define MPT_ENABLE_FILEIO // External samples require disk file io
|
||||
#endif
|
||||
|
||||
#if defined(NO_PLUGINS)
|
||||
// Any plugin type requires NO_PLUGINS to not be defined.
|
||||
#if defined(MPT_WITH_VST)
|
||||
#undef MPT_WITH_VST
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT) && !defined(MPT_BUILD_WINESUPPORT_WRAPPER)
|
||||
#ifndef MPT_NO_NAMESPACE
|
||||
#define MPT_NO_NAMESPACE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MPT_NO_NAMESPACE)
|
||||
|
||||
#ifdef OPENMPT_NAMESPACE
|
||||
#undef OPENMPT_NAMESPACE
|
||||
#endif
|
||||
#define OPENMPT_NAMESPACE
|
||||
|
||||
#ifdef OPENMPT_NAMESPACE_BEGIN
|
||||
#undef OPENMPT_NAMESPACE_BEGIN
|
||||
#endif
|
||||
#define OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
#ifdef OPENMPT_NAMESPACE_END
|
||||
#undef OPENMPT_NAMESPACE_END
|
||||
#endif
|
||||
#define OPENMPT_NAMESPACE_END
|
||||
|
||||
#else
|
||||
|
||||
#ifndef OPENMPT_NAMESPACE
|
||||
#define OPENMPT_NAMESPACE OpenMPT
|
||||
#endif
|
||||
|
||||
#ifndef OPENMPT_NAMESPACE_BEGIN
|
||||
#define OPENMPT_NAMESPACE_BEGIN namespace OPENMPT_NAMESPACE {
|
||||
#endif
|
||||
#ifndef OPENMPT_NAMESPACE_END
|
||||
#define OPENMPT_NAMESPACE_END }
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define MPT_CONFIGURATION_IO_READ_FILEDATA_NO_64BIT
|
||||
|
||||
|
||||
|
||||
// platform configuration
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
||||
// windows.h excludes
|
||||
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX // Macros min(a,b) and max(a,b)
|
||||
#endif
|
||||
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
||||
#define NOCOMM // COMM driver routines
|
||||
#define NOKANJI // Kanji support stuff.
|
||||
#define NOPROFILER // Profiler interface.
|
||||
#define NOMCX // Modem Configuration Extensions
|
||||
|
||||
// mmsystem.h excludes
|
||||
#define MMNODRV
|
||||
//#define MMNOSOUND
|
||||
//#define MMNOWAVE
|
||||
//#define MMNOMIDI
|
||||
#define MMNOAUX
|
||||
#define MMNOMIXER
|
||||
//#define MMNOTIMER
|
||||
#define MMNOJOY
|
||||
#define MMNOMCI
|
||||
//#define MMNOMMIO
|
||||
//#define MMNOMMSYSTEM
|
||||
|
||||
// mmreg.h excludes
|
||||
#define NOMMIDS
|
||||
//#define NONEWWAVE
|
||||
#define NONEWRIFF
|
||||
#define NOJPEGDIB
|
||||
#define NONEWIC
|
||||
#define NOBITMAP
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
// third-party library configuration
|
||||
|
||||
#ifdef MPT_WITH_STBVORBIS
|
||||
#ifndef STB_VORBIS_HEADER_ONLY
|
||||
#define STB_VORBIS_HEADER_ONLY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef MPT_WITH_VORBISFILE
|
||||
#ifndef OV_EXCLUDE_STATIC_CALLBACKS
|
||||
#define OV_EXCLUDE_STATIC_CALLBACKS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "mpt/base/namespace.hpp"
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
namespace mpt {
|
||||
|
||||
#ifndef MPT_NO_NAMESPACE
|
||||
using namespace ::mpt;
|
||||
#endif
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* BuildSettingsCompiler.h
|
||||
* -----------------------
|
||||
* Purpose: Global compiler setting overrides
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
#include "mpt/base/detect_compiler.hpp"
|
||||
|
||||
|
||||
|
||||
// compiler configuration
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
|
||||
#pragma warning(default:4800) // Implicit conversion from 'int' to bool. Possible information loss
|
||||
|
||||
#pragma warning(disable:4355) // 'this' : used in base member initializer list
|
||||
|
||||
// happens for immutable classes (i.e. classes containing const members)
|
||||
#pragma warning(disable:4512) // assignment operator could not be generated
|
||||
|
||||
#pragma warning(error:4309) // Treat "truncation of constant value"-warning as error.
|
||||
#pragma warning(error:4463) // Treat overflow; assigning value to bit-field that can only hold values from low_value to high_value"-warning as error.
|
||||
|
||||
#ifdef MPT_BUILD_ANALYZED
|
||||
// Disable Visual Studio static analyzer warnings that generate too many false positives in VS2010.
|
||||
//#pragma warning(disable:6246)
|
||||
//#pragma warning(disable:6262)
|
||||
#pragma warning(disable:6297) // 32-bit value is shifted, then cast to 64-bit value. Results might not be an expected value.
|
||||
#pragma warning(disable:6326) // Potential comparison of a constant with another constant
|
||||
//#pragma warning(disable:6385)
|
||||
//#pragma warning(disable:6386)
|
||||
#endif // MPT_BUILD_ANALYZED
|
||||
|
||||
#endif // MPT_COMPILER_MSVC
|
||||
|
||||
#if MPT_COMPILER_GCC
|
||||
|
||||
#ifdef MPT_COMPILER_SETTING_QUIRK_GCC_BROKEN_IPA
|
||||
// See <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115049>.
|
||||
#if MPT_GCC_BEFORE(9, 0, 0)
|
||||
// Earlier GCC get confused about setting a global function attribute.
|
||||
// We need to check for 9.0 instead of 9.1 because of
|
||||
// <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1028580>.
|
||||
// It also gets confused when setting global optimization -O1,
|
||||
// so we have no way of fixing GCC 8 or earlier.
|
||||
//#pragma GCC optimize("O1")
|
||||
#else
|
||||
#pragma GCC optimize("no-ipa-ra")
|
||||
#endif
|
||||
#endif // MPT_COMPILER_SETTING_QUIRK_GCC_BROKEN_IPA
|
||||
|
||||
#endif // MPT_COMPILER_GCC
|
||||
|
||||
#if MPT_COMPILER_CLANG
|
||||
|
||||
#if defined(MPT_BUILD_MSVC)
|
||||
#pragma clang diagnostic warning "-Wimplicit-fallthrough"
|
||||
#endif // MPT_BUILD_MSVC
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#pragma clang diagnostic ignored "-Wunused-local-typedef"
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
#endif // MPT_COMPILER_CLANG
|
||||
@@ -0,0 +1,469 @@
|
||||
/*
|
||||
* ComponentManager.cpp
|
||||
* --------------------
|
||||
* Purpose: Manages loading of optional components.
|
||||
* Notes : (currently none)
|
||||
* Authors: Joern Heusipp
|
||||
* OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "ComponentManager.h"
|
||||
|
||||
#include "mpt/mutex/mutex.hpp"
|
||||
|
||||
#include "Logging.h"
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
ComponentBase::ComponentBase(ComponentType type)
|
||||
: m_Type(type)
|
||||
, m_Initialized(false)
|
||||
, m_Available(false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ComponentBase::~ComponentBase()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void ComponentBase::SetInitialized()
|
||||
{
|
||||
m_Initialized = true;
|
||||
}
|
||||
|
||||
|
||||
void ComponentBase::SetAvailable()
|
||||
{
|
||||
m_Available = true;
|
||||
}
|
||||
|
||||
|
||||
ComponentType ComponentBase::GetType() const
|
||||
{
|
||||
return m_Type;
|
||||
}
|
||||
|
||||
|
||||
bool ComponentBase::IsInitialized() const
|
||||
{
|
||||
return m_Initialized;
|
||||
}
|
||||
|
||||
|
||||
bool ComponentBase::IsAvailable() const
|
||||
{
|
||||
return m_Initialized && m_Available;
|
||||
}
|
||||
|
||||
|
||||
mpt::ustring ComponentBase::GetVersion() const
|
||||
{
|
||||
return mpt::ustring();
|
||||
}
|
||||
|
||||
|
||||
void ComponentBase::Initialize()
|
||||
{
|
||||
if(IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(DoInitialize())
|
||||
{
|
||||
SetAvailable();
|
||||
}
|
||||
SetInitialized();
|
||||
}
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
|
||||
ComponentLibrary::ComponentLibrary(ComponentType type)
|
||||
: ComponentBase(type)
|
||||
, m_BindFailed(false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ComponentLibrary::~ComponentLibrary()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool ComponentLibrary::AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath)
|
||||
{
|
||||
if(m_Libraries[libName].IsValid())
|
||||
{
|
||||
// prefer previous
|
||||
return true;
|
||||
}
|
||||
mpt::Library lib(libPath);
|
||||
if(!lib.IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_Libraries[libName] = lib;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ComponentLibrary::ClearLibraries()
|
||||
{
|
||||
m_Libraries.clear();
|
||||
}
|
||||
|
||||
|
||||
void ComponentLibrary::SetBindFailed()
|
||||
{
|
||||
m_BindFailed = true;
|
||||
}
|
||||
|
||||
|
||||
void ComponentLibrary::ClearBindFailed()
|
||||
{
|
||||
m_BindFailed = false;
|
||||
}
|
||||
|
||||
|
||||
bool ComponentLibrary::HasBindFailed() const
|
||||
{
|
||||
return m_BindFailed;
|
||||
}
|
||||
|
||||
|
||||
mpt::Library ComponentLibrary::GetLibrary(const std::string &libName) const
|
||||
{
|
||||
const auto it = m_Libraries.find(libName);
|
||||
if(it == m_Libraries.end())
|
||||
{
|
||||
return mpt::Library();
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
#if MPT_COMPONENT_MANAGER
|
||||
|
||||
|
||||
ComponentFactoryBase::ComponentFactoryBase(const std::string &id, const std::string &settingsKey)
|
||||
: m_ID(id)
|
||||
, m_SettingsKey(settingsKey)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ComponentFactoryBase::~ComponentFactoryBase()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::string ComponentFactoryBase::GetID() const
|
||||
{
|
||||
return m_ID;
|
||||
}
|
||||
|
||||
|
||||
std::string ComponentFactoryBase::GetSettingsKey() const
|
||||
{
|
||||
return m_SettingsKey;
|
||||
}
|
||||
|
||||
|
||||
void ComponentFactoryBase::PreConstruct() const
|
||||
{
|
||||
MPT_LOG_GLOBAL(LogInformation, "Components",
|
||||
MPT_UFORMAT("Constructing Component {}")
|
||||
( mpt::ToUnicode(mpt::Charset::ASCII, m_ID)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void ComponentFactoryBase::Initialize(ComponentManager &componentManager, std::shared_ptr<IComponent> component) const
|
||||
{
|
||||
if(componentManager.IsComponentBlocked(GetSettingsKey()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
componentManager.InitializeComponent(component);
|
||||
}
|
||||
|
||||
|
||||
// Global list of component register functions.
|
||||
// We do not use a global scope static list head because the corresponding
|
||||
// mutex would be no POD type and would thus not be safe to be usable in
|
||||
// zero-initialized state.
|
||||
// Function scope static initialization is guaranteed to be thread safe
|
||||
// in C++11.
|
||||
// We use this implementation to be future-proof.
|
||||
// MSVC currently does not exploit the possibility of using multiple threads
|
||||
// for global lifetime object's initialization.
|
||||
// An implementation with a simple global list head and no mutex at all would
|
||||
// thus work fine for MSVC (currently).
|
||||
|
||||
static mpt::mutex & ComponentListMutex()
|
||||
{
|
||||
static mpt::mutex g_ComponentListMutex;
|
||||
return g_ComponentListMutex;
|
||||
}
|
||||
|
||||
static ComponentListEntry * & ComponentListHead()
|
||||
{
|
||||
static ComponentListEntry g_ComponentListHeadEmpty = {nullptr, nullptr};
|
||||
static ComponentListEntry *g_ComponentListHead = &g_ComponentListHeadEmpty;
|
||||
return g_ComponentListHead;
|
||||
}
|
||||
|
||||
bool ComponentListPush(ComponentListEntry *entry)
|
||||
{
|
||||
mpt::lock_guard<mpt::mutex> guard(ComponentListMutex());
|
||||
#if MPT_MSVC_BEFORE(2019,0)
|
||||
// Guard against VS2017 compiler bug causing repeated initialization of inline variables.
|
||||
// See <https://developercommunity.visualstudio.com/t/static-inline-variable-gets-destroyed-multiple-tim/297876>.
|
||||
if(entry->next)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
entry->next = ComponentListHead();
|
||||
ComponentListHead() = entry;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static std::shared_ptr<ComponentManager> g_ComponentManager;
|
||||
|
||||
|
||||
void ComponentManager::Init(const IComponentManagerSettings &settings)
|
||||
{
|
||||
MPT_LOG_GLOBAL(LogInformation, "Components", U_("Init"));
|
||||
// cannot use make_shared because the constructor is private
|
||||
g_ComponentManager = std::shared_ptr<ComponentManager>(new ComponentManager(settings));
|
||||
}
|
||||
|
||||
|
||||
void ComponentManager::Release()
|
||||
{
|
||||
MPT_LOG_GLOBAL(LogInformation, "Components", U_("Release"));
|
||||
g_ComponentManager = nullptr;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<ComponentManager> ComponentManager::Instance()
|
||||
{
|
||||
return g_ComponentManager;
|
||||
}
|
||||
|
||||
|
||||
ComponentManager::ComponentManager(const IComponentManagerSettings &settings)
|
||||
: m_Settings(settings)
|
||||
{
|
||||
mpt::lock_guard<mpt::mutex> guard(ComponentListMutex());
|
||||
for(ComponentListEntry *entry = ComponentListHead(); entry; entry = entry->next)
|
||||
{
|
||||
if(entry->reg)
|
||||
{
|
||||
entry->reg(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ComponentManager::Register(const IComponentFactory &componentFactory)
|
||||
{
|
||||
if(m_Components.find(componentFactory.GetID()) != m_Components.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
RegisteredComponent registeredComponent;
|
||||
registeredComponent.settingsKey = componentFactory.GetSettingsKey();
|
||||
registeredComponent.factoryMethod = componentFactory.GetStaticConstructor();
|
||||
registeredComponent.instance = nullptr;
|
||||
registeredComponent.weakInstance = std::weak_ptr<IComponent>();
|
||||
m_Components.insert(std::make_pair(componentFactory.GetID(), registeredComponent));
|
||||
}
|
||||
|
||||
|
||||
void ComponentManager::Startup()
|
||||
{
|
||||
MPT_LOG_GLOBAL(LogDebug, "Components", U_("Startup"));
|
||||
if(m_Settings.LoadOnStartup())
|
||||
{
|
||||
for(auto &it : m_Components)
|
||||
{
|
||||
it.second.instance = it.second.factoryMethod(*this);
|
||||
it.second.weakInstance = it.second.instance;
|
||||
}
|
||||
}
|
||||
if(!m_Settings.KeepLoaded())
|
||||
{
|
||||
for(auto &it : m_Components)
|
||||
{
|
||||
it.second.instance = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ComponentManager::IsComponentBlocked(const std::string &settingsKey) const
|
||||
{
|
||||
if(settingsKey.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return m_Settings.IsBlocked(settingsKey);
|
||||
}
|
||||
|
||||
|
||||
void ComponentManager::InitializeComponent(std::shared_ptr<IComponent> component) const
|
||||
{
|
||||
if(!component)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(component->IsInitialized())
|
||||
{
|
||||
return;
|
||||
}
|
||||
component->Initialize();
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const IComponent> ComponentManager::GetComponent(const IComponentFactory &componentFactory)
|
||||
{
|
||||
std::shared_ptr<IComponent> component = nullptr;
|
||||
auto it = m_Components.find(componentFactory.GetID());
|
||||
if(it != m_Components.end())
|
||||
{ // registered component
|
||||
if((*it).second.instance)
|
||||
{ // loaded
|
||||
component = (*it).second.instance;
|
||||
} else
|
||||
{ // not loaded
|
||||
component = (*it).second.weakInstance.lock();
|
||||
if(!component)
|
||||
{
|
||||
component = (*it).second.factoryMethod(*this);
|
||||
}
|
||||
if(m_Settings.KeepLoaded())
|
||||
{ // keep the component loaded
|
||||
(*it).second.instance = component;
|
||||
}
|
||||
(*it).second.weakInstance = component;
|
||||
}
|
||||
} else
|
||||
{ // unregistered component
|
||||
component = componentFactory.Construct(*this);
|
||||
}
|
||||
MPT_ASSERT(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<const IComponent> ComponentManager::ReloadComponent(const IComponentFactory &componentFactory)
|
||||
{
|
||||
std::shared_ptr<IComponent> component = nullptr;
|
||||
auto it = m_Components.find(componentFactory.GetID());
|
||||
if(it != m_Components.end())
|
||||
{ // registered component
|
||||
if((*it).second.instance)
|
||||
{ // loaded
|
||||
(*it).second.instance = nullptr;
|
||||
if(!(*it).second.weakInstance.expired())
|
||||
{
|
||||
throw std::runtime_error("Component not completely unloaded. Cannot reload.");
|
||||
}
|
||||
(*it).second.weakInstance = std::weak_ptr<IComponent>();
|
||||
}
|
||||
// not loaded
|
||||
component = (*it).second.factoryMethod(*this);
|
||||
if(m_Settings.KeepLoaded())
|
||||
{ // keep the component loaded
|
||||
(*it).second.instance = component;
|
||||
}
|
||||
(*it).second.weakInstance = component;
|
||||
} else
|
||||
{ // unregistered component
|
||||
component = componentFactory.Construct(*this);
|
||||
}
|
||||
MPT_ASSERT(component);
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> ComponentManager::GetRegisteredComponents() const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
result.reserve(m_Components.size());
|
||||
for(const auto &it : m_Components)
|
||||
{
|
||||
result.push_back(it.first);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
ComponentInfo ComponentManager::GetComponentInfo(std::string name) const
|
||||
{
|
||||
ComponentInfo result;
|
||||
result.name = name;
|
||||
result.state = ComponentStateUnregistered;
|
||||
result.settingsKey = "";
|
||||
result.type = ComponentTypeUnknown;
|
||||
const auto it = m_Components.find(name);
|
||||
if(it == m_Components.end())
|
||||
{
|
||||
result.state = ComponentStateUnregistered;
|
||||
return result;
|
||||
}
|
||||
result.settingsKey = it->second.settingsKey;
|
||||
if(IsComponentBlocked(it->second.settingsKey))
|
||||
{
|
||||
result.state = ComponentStateBlocked;
|
||||
return result;
|
||||
}
|
||||
std::shared_ptr<IComponent> component = it->second.instance;
|
||||
if(!component)
|
||||
{
|
||||
component = it->second.weakInstance.lock();
|
||||
}
|
||||
if(!component)
|
||||
{
|
||||
result.state = ComponentStateUnintialized;
|
||||
return result;
|
||||
}
|
||||
result.type = component->GetType();
|
||||
if(!component->IsInitialized())
|
||||
{
|
||||
result.state = ComponentStateUnintialized;
|
||||
return result;
|
||||
}
|
||||
if(!component->IsAvailable())
|
||||
{
|
||||
result.state = ComponentStateUnavailable;
|
||||
return result;
|
||||
}
|
||||
result.state = ComponentStateAvailable;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#endif // MPT_COMPONENT_MANAGER
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,506 @@
|
||||
/*
|
||||
* ComponentManager.h
|
||||
* ------------------
|
||||
* Purpose: Manages loading of optional components.
|
||||
* Notes : (currently none)
|
||||
* Authors: Joern Heusipp
|
||||
* 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 "mpt/mutex/mutex.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "../common/misc_util.h"
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include "../misc/mptLibrary.h"
|
||||
#endif
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
enum ComponentType
|
||||
{
|
||||
ComponentTypeUnknown = 0,
|
||||
ComponentTypeBuiltin, // PortAudio
|
||||
ComponentTypeSystem, // mf.dll
|
||||
ComponentTypeSystemInstallable, // acm mp3 codec
|
||||
ComponentTypeBundled, // libsoundtouch
|
||||
ComponentTypeForeign, // libmp3lame
|
||||
};
|
||||
|
||||
|
||||
class ComponentFactoryBase;
|
||||
|
||||
|
||||
class IComponent
|
||||
{
|
||||
|
||||
friend class ComponentFactoryBase;
|
||||
|
||||
protected:
|
||||
|
||||
IComponent() = default;
|
||||
|
||||
public:
|
||||
|
||||
virtual ~IComponent() = default;
|
||||
|
||||
public:
|
||||
|
||||
virtual ComponentType GetType() const = 0;
|
||||
|
||||
virtual bool IsInitialized() const = 0; // Initialize() has been called
|
||||
virtual bool IsAvailable() const = 0; // Initialize() has been successfull
|
||||
virtual mpt::ustring GetVersion() const = 0;
|
||||
|
||||
virtual void Initialize() = 0; // try to load the component
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ComponentBase
|
||||
: public IComponent
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
ComponentType m_Type;
|
||||
|
||||
bool m_Initialized;
|
||||
bool m_Available;
|
||||
|
||||
protected:
|
||||
|
||||
ComponentBase(ComponentType type);
|
||||
|
||||
public:
|
||||
|
||||
~ComponentBase() override;
|
||||
|
||||
protected:
|
||||
|
||||
void SetInitialized();
|
||||
void SetAvailable();
|
||||
|
||||
public:
|
||||
|
||||
ComponentType GetType() const override;
|
||||
bool IsInitialized() const override;
|
||||
bool IsAvailable() const override;
|
||||
|
||||
mpt::ustring GetVersion() const override;
|
||||
|
||||
public:
|
||||
|
||||
void Initialize() override;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool DoInitialize() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ComponentBuiltin : public ComponentBase
|
||||
{
|
||||
public:
|
||||
ComponentBuiltin()
|
||||
: ComponentBase(ComponentTypeBuiltin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool DoInitialize() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#define MPT_GLOBAL_BIND(lib, name) name = &::name;
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
|
||||
class ComponentLibrary
|
||||
: public ComponentBase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
using TLibraryMap = std::map<std::string, mpt::Library>;
|
||||
TLibraryMap m_Libraries;
|
||||
|
||||
bool m_BindFailed;
|
||||
|
||||
protected:
|
||||
|
||||
ComponentLibrary(ComponentType type);
|
||||
|
||||
public:
|
||||
|
||||
virtual ~ComponentLibrary();
|
||||
|
||||
protected:
|
||||
|
||||
bool AddLibrary(const std::string &libName, const mpt::LibraryPath &libPath);
|
||||
void ClearLibraries();
|
||||
void SetBindFailed();
|
||||
void ClearBindFailed();
|
||||
bool HasBindFailed() const;
|
||||
|
||||
public:
|
||||
|
||||
virtual mpt::Library GetLibrary(const std::string &libName) const;
|
||||
|
||||
template <typename Tfunc>
|
||||
bool Bind(Tfunc * & f, const std::string &libName, const std::string &symbol) const
|
||||
{
|
||||
return GetLibrary(libName).Bind(f, symbol);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool DoInitialize() override = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define MPT_COMPONENT_BIND(libName, func) do { if(!Bind( func , libName , #func )) { SetBindFailed(); } } while(0)
|
||||
#define MPT_COMPONENT_BIND_OPTIONAL(libName, func) Bind( func , libName , #func )
|
||||
#define MPT_COMPONENT_BIND_SYMBOL(libName, symbol, func) do { if(!Bind( func , libName , symbol )) { SetBindFailed(); } } while(0)
|
||||
#define MPT_COMPONENT_BIND_SYMBOL_OPTIONAL(libName, symbol, func) Bind( func , libName , symbol )
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
#ifdef UNICODE
|
||||
#define MPT_COMPONENT_BINDWIN_SUFFIX "W"
|
||||
#else
|
||||
#define MPT_COMPONENT_BINDWIN_SUFFIX "A"
|
||||
#endif
|
||||
#define MPT_COMPONENT_BINDWIN(libName, func) do { if(!Bind( func , libName , #func MPT_COMPONENT_BINDWIN_SUFFIX )) { SetBindFailed(); } } while(0)
|
||||
#define MPT_COMPONENT_BINDWIN_OPTIONAL(libName, func) Bind( func , libName , #func MPT_COMPONENT_BINDWIN_SUFFIX )
|
||||
#define MPT_COMPONENT_BINDWIN_SYMBOL(libName, symbol, func) do { if(!Bind( func , libName , symbol MPT_COMPONENT_BINDWIN_SUFFIX )) { SetBindFailed(); } } while(0)
|
||||
#define MPT_COMPONENT_BINDWIN_SYMBOL_OPTIONAL(libName, symbol, func) Bind( func , libName , symbol MPT_COMPONENT_BINDWIN_SUFFIX )
|
||||
#endif
|
||||
|
||||
|
||||
class ComponentSystemDLL : public ComponentLibrary
|
||||
{
|
||||
private:
|
||||
mpt::PathString m_BaseName;
|
||||
public:
|
||||
ComponentSystemDLL(const mpt::PathString &baseName)
|
||||
: ComponentLibrary(ComponentTypeSystem)
|
||||
, m_BaseName(baseName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool DoInitialize() override
|
||||
{
|
||||
AddLibrary(m_BaseName.ToUTF8(), mpt::LibraryPath::System(m_BaseName));
|
||||
return GetLibrary(m_BaseName.ToUTF8()).IsValid();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ComponentBundledDLL : public ComponentLibrary
|
||||
{
|
||||
private:
|
||||
mpt::PathString m_FullName;
|
||||
public:
|
||||
ComponentBundledDLL(const mpt::PathString &fullName)
|
||||
: ComponentLibrary(ComponentTypeBundled)
|
||||
, m_FullName(fullName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool DoInitialize() override
|
||||
{
|
||||
AddLibrary(m_FullName.ToUTF8(), mpt::LibraryPath::AppFullName(m_FullName));
|
||||
return GetLibrary(m_FullName.ToUTF8()).IsValid();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
#if MPT_COMPONENT_MANAGER
|
||||
|
||||
|
||||
class ComponentManager;
|
||||
|
||||
using ComponentFactoryMethod = std::shared_ptr<IComponent> (*)(ComponentManager &componentManager);
|
||||
|
||||
|
||||
class IComponentFactory
|
||||
{
|
||||
protected:
|
||||
IComponentFactory() = default;
|
||||
public:
|
||||
virtual ~IComponentFactory() = default;
|
||||
public:
|
||||
virtual std::string GetID() const = 0;
|
||||
virtual std::string GetSettingsKey() const = 0;
|
||||
virtual std::shared_ptr<IComponent> Construct(ComponentManager &componentManager) const = 0;
|
||||
virtual ComponentFactoryMethod GetStaticConstructor() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class ComponentFactoryBase
|
||||
: public IComponentFactory
|
||||
{
|
||||
private:
|
||||
std::string m_ID;
|
||||
std::string m_SettingsKey;
|
||||
protected:
|
||||
ComponentFactoryBase(const std::string &id, const std::string &settingsKey);
|
||||
void PreConstruct() const;
|
||||
void Initialize(ComponentManager &componentManager, std::shared_ptr<IComponent> component) const;
|
||||
public:
|
||||
virtual ~ComponentFactoryBase();
|
||||
std::string GetID() const override;
|
||||
std::string GetSettingsKey() const override;
|
||||
std::shared_ptr<IComponent> Construct(ComponentManager &componentManager) const override = 0;
|
||||
ComponentFactoryMethod GetStaticConstructor() const override = 0;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class ComponentFactory
|
||||
: public ComponentFactoryBase
|
||||
{
|
||||
public:
|
||||
ComponentFactory()
|
||||
: ComponentFactoryBase(T::g_ID, T::g_SettingsKey)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public:
|
||||
std::shared_ptr<IComponent> Construct(ComponentManager &componentManager) const override
|
||||
{
|
||||
PreConstruct();
|
||||
std::shared_ptr<IComponent> component = std::make_shared<T>();
|
||||
Initialize(componentManager, component);
|
||||
return component;
|
||||
}
|
||||
static std::shared_ptr<IComponent> StaticConstruct(ComponentManager &componentManager)
|
||||
{
|
||||
return ComponentFactory().Construct(componentManager);
|
||||
}
|
||||
virtual ComponentFactoryMethod GetStaticConstructor() const override
|
||||
{
|
||||
return &StaticConstruct;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class IComponentManagerSettings
|
||||
{
|
||||
public:
|
||||
virtual bool LoadOnStartup() const = 0;
|
||||
virtual bool KeepLoaded() const = 0;
|
||||
virtual bool IsBlocked(const std::string &key) const = 0;
|
||||
protected:
|
||||
virtual ~IComponentManagerSettings() = default;
|
||||
};
|
||||
|
||||
|
||||
class ComponentManagerSettingsDefault
|
||||
: public IComponentManagerSettings
|
||||
{
|
||||
public:
|
||||
bool LoadOnStartup() const override { return false; }
|
||||
bool KeepLoaded() const override { return true; }
|
||||
bool IsBlocked(const std::string & /*key*/ ) const override { return false; }
|
||||
};
|
||||
|
||||
|
||||
enum ComponentState
|
||||
{
|
||||
ComponentStateUnregistered,
|
||||
ComponentStateBlocked,
|
||||
ComponentStateUnintialized,
|
||||
ComponentStateUnavailable,
|
||||
ComponentStateAvailable,
|
||||
};
|
||||
|
||||
|
||||
struct ComponentInfo
|
||||
{
|
||||
std::string name;
|
||||
ComponentState state;
|
||||
std::string settingsKey;
|
||||
ComponentType type;
|
||||
};
|
||||
|
||||
|
||||
class ComponentManager
|
||||
{
|
||||
friend class ComponentFactoryBase;
|
||||
public:
|
||||
static void Init(const IComponentManagerSettings &settings);
|
||||
static void Release();
|
||||
static std::shared_ptr<ComponentManager> Instance();
|
||||
private:
|
||||
ComponentManager(const IComponentManagerSettings &settings);
|
||||
private:
|
||||
struct RegisteredComponent
|
||||
{
|
||||
std::string settingsKey;
|
||||
ComponentFactoryMethod factoryMethod;
|
||||
std::shared_ptr<IComponent> instance;
|
||||
std::weak_ptr<IComponent> weakInstance;
|
||||
};
|
||||
using TComponentMap = std::map<std::string, RegisteredComponent>;
|
||||
const IComponentManagerSettings &m_Settings;
|
||||
TComponentMap m_Components;
|
||||
private:
|
||||
bool IsComponentBlocked(const std::string &settingsKey) const;
|
||||
void InitializeComponent(std::shared_ptr<IComponent> component) const;
|
||||
public:
|
||||
void Register(const IComponentFactory &componentFactory);
|
||||
void Startup();
|
||||
std::shared_ptr<const IComponent> GetComponent(const IComponentFactory &componentFactory);
|
||||
std::shared_ptr<const IComponent> ReloadComponent(const IComponentFactory &componentFactory);
|
||||
std::vector<std::string> GetRegisteredComponents() const;
|
||||
ComponentInfo GetComponentInfo(std::string name) const;
|
||||
};
|
||||
|
||||
|
||||
struct ComponentListEntry
|
||||
{
|
||||
ComponentListEntry *next;
|
||||
void (*reg)(ComponentManager &componentManager);
|
||||
};
|
||||
|
||||
bool ComponentListPush(ComponentListEntry *entry);
|
||||
|
||||
template <typename TComponent>
|
||||
struct ComponentRegisterer
|
||||
{
|
||||
static inline void RegisterComponent(ComponentManager &componentManager)
|
||||
{
|
||||
componentManager.Register(ComponentFactory<TComponent>());
|
||||
}
|
||||
static inline ComponentListEntry &GetComponentListEntry()
|
||||
{
|
||||
static ComponentListEntry s_ComponentListEntry = {nullptr, &RegisterComponent};
|
||||
return s_ComponentListEntry;
|
||||
}
|
||||
static inline bool g_ComponentRegistered = ComponentListPush(&GetComponentListEntry());
|
||||
};
|
||||
|
||||
#define MPT_DECLARE_COMPONENT_MEMBERS(name, settingsKey) \
|
||||
public: \
|
||||
static constexpr const char *g_ID = #name ; \
|
||||
static constexpr const char *g_SettingsKey = settingsKey ; \
|
||||
static inline ComponentRegisterer< name > s_ComponentRegisterer; \
|
||||
/**/
|
||||
|
||||
|
||||
template <typename type>
|
||||
std::shared_ptr<const type> GetComponent()
|
||||
{
|
||||
return std::dynamic_pointer_cast<const type>(ComponentManager::Instance()->GetComponent(ComponentFactory<type>()));
|
||||
}
|
||||
|
||||
|
||||
template <typename type>
|
||||
std::shared_ptr<const type> ReloadComponent()
|
||||
{
|
||||
return std::dynamic_pointer_cast<const type>(ComponentManager::Instance()->ReloadComponent(ComponentFactory<type>()));
|
||||
}
|
||||
|
||||
|
||||
#else // !MPT_COMPONENT_MANAGER
|
||||
|
||||
|
||||
#define MPT_DECLARE_COMPONENT_MEMBERS(name, settingsKey)
|
||||
|
||||
|
||||
template <typename type>
|
||||
std::shared_ptr<const type> GetComponent()
|
||||
{
|
||||
#if MPT_COMPILER_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
#endif // MPT_COMPILER_CLANG
|
||||
static std::weak_ptr<type> cache;
|
||||
static mpt::mutex m;
|
||||
#if MPT_COMPILER_CLANG
|
||||
#pragma clang diagnostic pop
|
||||
#endif // MPT_COMPILER_CLANG mpt::lock_guard<mpt::mutex> l(m);
|
||||
mpt::lock_guard<mpt::mutex> l(m);
|
||||
std::shared_ptr<type> component = cache.lock();
|
||||
if(!component)
|
||||
{
|
||||
component = std::make_shared<type>();
|
||||
component->Initialize();
|
||||
cache = component;
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
|
||||
#endif // MPT_COMPONENT_MANAGER
|
||||
|
||||
|
||||
// Simple wrapper around std::shared_ptr<ComponentType> which automatically
|
||||
// gets a reference to the component (or constructs it) on initialization.
|
||||
template <typename T>
|
||||
class ComponentHandle
|
||||
{
|
||||
private:
|
||||
std::shared_ptr<const T> component;
|
||||
public:
|
||||
ComponentHandle()
|
||||
: component(GetComponent<T>())
|
||||
{
|
||||
return;
|
||||
}
|
||||
~ComponentHandle()
|
||||
{
|
||||
return;
|
||||
}
|
||||
bool IsAvailable() const
|
||||
{
|
||||
return component && component->IsAvailable();
|
||||
}
|
||||
const T *get() const
|
||||
{
|
||||
return component.get();
|
||||
}
|
||||
const T &operator*() const
|
||||
{
|
||||
return *component;
|
||||
}
|
||||
const T *operator->() const
|
||||
{
|
||||
return &*component;
|
||||
}
|
||||
#if MPT_COMPONENT_MANAGER
|
||||
void Reload()
|
||||
{
|
||||
component = nullptr;
|
||||
component = ReloadComponent<T>();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool IsComponentAvailable(const ComponentHandle<T> &handle)
|
||||
{
|
||||
return handle.IsAvailable();
|
||||
}
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,456 @@
|
||||
/*
|
||||
* FileReader.h
|
||||
* ------------
|
||||
* Purpose: A basic class for transparent reading of memory-based files.
|
||||
* 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 "mpt/io_read/filecursor.hpp"
|
||||
#include "mpt/io_read/filecursor_filename_traits.hpp"
|
||||
#include "mpt/io_read/filecursor_traits_filedata.hpp"
|
||||
#include "mpt/io_read/filecursor_traits_memory.hpp"
|
||||
#include "mpt/io_read/filereader.hpp"
|
||||
|
||||
#include "openmpt/base/Types.hpp"
|
||||
|
||||
#include "mptPathString.h"
|
||||
#include "mptStringBuffer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
#include "FileReaderFwd.h"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace FileReaderExt
|
||||
{
|
||||
|
||||
// Read a string of length srcSize into fixed-length char array destBuffer using a given read mode.
|
||||
// The file cursor is advanced by "srcSize" bytes.
|
||||
// Returns true if at least one byte could be read or 0 bytes were requested.
|
||||
template<mpt::String::ReadWriteMode mode, std::size_t destSize, typename TFileCursor>
|
||||
bool ReadString(TFileCursor &f, char (&destBuffer)[destSize], const std::size_t srcSize)
|
||||
{
|
||||
typename TFileCursor::PinnedView source = f.ReadPinnedView(srcSize); // Make sure the string is cached properly.
|
||||
std::size_t realSrcSize = source.size(); // In case fewer bytes are available
|
||||
mpt::String::WriteAutoBuf(destBuffer) = mpt::String::ReadBuf(mode, mpt::byte_cast<const char*>(source.data()), realSrcSize);
|
||||
return (realSrcSize > 0 || srcSize == 0);
|
||||
}
|
||||
|
||||
// Read a string of length srcSize into a std::string dest using a given read mode.
|
||||
// The file cursor is advanced by "srcSize" bytes.
|
||||
// Returns true if at least one character could be read or 0 characters were requested.
|
||||
template<mpt::String::ReadWriteMode mode, typename TFileCursor>
|
||||
bool ReadString(TFileCursor &f, std::string &dest, const std::size_t srcSize)
|
||||
{
|
||||
dest.clear();
|
||||
typename TFileCursor::PinnedView source = f.ReadPinnedView(srcSize); // Make sure the string is cached properly.
|
||||
std::size_t realSrcSize = source.size(); // In case fewer bytes are available
|
||||
dest = mpt::String::ReadBuf(mode, mpt::byte_cast<const char*>(source.data()), realSrcSize);
|
||||
return (realSrcSize > 0 || srcSize == 0);
|
||||
}
|
||||
|
||||
// Read a string of length srcSize into a mpt::charbuf dest using a given read mode.
|
||||
// The file cursor is advanced by "srcSize" bytes.
|
||||
// Returns true if at least one character could be read or 0 characters were requested.
|
||||
template<mpt::String::ReadWriteMode mode, std::size_t len, typename TFileCursor>
|
||||
bool ReadString(TFileCursor &f, mpt::charbuf<len> &dest, const std::size_t srcSize)
|
||||
{
|
||||
typename TFileCursor::PinnedView source = f.ReadPinnedView(srcSize); // Make sure the string is cached properly.
|
||||
std::size_t realSrcSize = source.size(); // In case fewer bytes are available
|
||||
dest = mpt::String::ReadBuf(mode, mpt::byte_cast<const char*>(source.data()), realSrcSize);
|
||||
return (realSrcSize > 0 || srcSize == 0);
|
||||
}
|
||||
|
||||
// Read a charset encoded string of length srcSize into a mpt::ustring dest using a given read mode.
|
||||
// The file cursor is advanced by "srcSize" bytes.
|
||||
// Returns true if at least one character could be read or 0 characters were requested.
|
||||
template<mpt::String::ReadWriteMode mode, typename TFileCursor>
|
||||
bool ReadString(TFileCursor &f, mpt::ustring &dest, mpt::Charset charset, const std::size_t srcSize)
|
||||
{
|
||||
dest.clear();
|
||||
typename TFileCursor::PinnedView source = f.ReadPinnedView(srcSize); // Make sure the string is cached properly.
|
||||
std::size_t realSrcSize = source.size(); // In case fewer bytes are available
|
||||
dest = mpt::ToUnicode(charset, mpt::String::ReadBuf(mode, mpt::byte_cast<const char*>(source.data()), realSrcSize));
|
||||
return (realSrcSize > 0 || srcSize == 0);
|
||||
}
|
||||
|
||||
// Read a string with a preprended length field of type Tsize (must be a packed<*,*> type) into a std::string dest using a given read mode.
|
||||
// The file cursor is advanced by the string length.
|
||||
// Returns true if the size field could be read and at least one character could be read or 0 characters were requested.
|
||||
template<typename Tsize, mpt::String::ReadWriteMode mode, std::size_t destSize, typename TFileCursor>
|
||||
bool ReadSizedString(TFileCursor &f, char (&destBuffer)[destSize], const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
static_assert(mpt::is_binary_safe<Tsize>::value);
|
||||
Tsize srcSize;
|
||||
if(!mpt::IO::FileReader::Read(f, srcSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return FileReaderExt::ReadString<mode>(f, destBuffer, std::min(static_cast<std::size_t>(srcSize), maxLength));
|
||||
}
|
||||
|
||||
// Read a string with a preprended length field of type Tsize (must be a packed<*,*> type) into a std::string dest using a given read mode.
|
||||
// The file cursor is advanced by the string length.
|
||||
// Returns true if the size field could be read and at least one character could be read or 0 characters were requested.
|
||||
template<typename Tsize, mpt::String::ReadWriteMode mode, typename TFileCursor>
|
||||
bool ReadSizedString(TFileCursor &f, std::string &dest, const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
static_assert(mpt::is_binary_safe<Tsize>::value);
|
||||
Tsize srcSize;
|
||||
if(!mpt::IO::FileReader::Read(f, srcSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return FileReaderExt::ReadString<mode>(f, dest, std::min(static_cast<std::size_t>(srcSize), maxLength));
|
||||
}
|
||||
|
||||
// Read a string with a preprended length field of type Tsize (must be a packed<*,*> type) into a mpt::charbuf dest using a given read mode.
|
||||
// The file cursor is advanced by the string length.
|
||||
// Returns true if the size field could be read and at least one character could be read or 0 characters were requested.
|
||||
template<typename Tsize, mpt::String::ReadWriteMode mode, std::size_t len, typename TFileCursor>
|
||||
bool ReadSizedString(TFileCursor &f, mpt::charbuf<len> &dest, const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
static_assert(mpt::is_binary_safe<Tsize>::value);
|
||||
Tsize srcSize;
|
||||
if(!mpt::IO::FileReader::Read(f, srcSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return FileReaderExt::ReadString<mode>(f, dest, std::min(static_cast<std::size_t>(srcSize), maxLength));
|
||||
}
|
||||
|
||||
} // namespace FileReaderExt
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
using FileCursor = mpt::IO::FileCursor<Ttraits, Tfilenametraits>;
|
||||
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
class FileReader
|
||||
: public FileCursor<Ttraits, Tfilenametraits>
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
using traits_type = Ttraits;
|
||||
using filename_traits_type = Tfilenametraits;
|
||||
|
||||
public:
|
||||
|
||||
using pos_type = typename traits_type::pos_type;
|
||||
|
||||
using data_type = typename traits_type::data_type;
|
||||
using ref_data_type = typename traits_type::ref_data_type;
|
||||
using shared_data_type = typename traits_type::shared_data_type;
|
||||
using value_data_type = typename traits_type::value_data_type;
|
||||
|
||||
using shared_filename_type = typename filename_traits_type::shared_filename_type;
|
||||
|
||||
public:
|
||||
|
||||
// Initialize invalid file reader object.
|
||||
FileReader()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FileReader(const FileCursor<Ttraits, Tfilenametraits> &other)
|
||||
: FileCursor<Ttraits, Tfilenametraits>(other)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FileReader(FileCursor<Ttraits, Tfilenametraits> &&other)
|
||||
: FileCursor<Ttraits, Tfilenametraits>(std::move(other))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize file reader object with pointer to data and data length.
|
||||
template <typename Tbyte>
|
||||
explicit FileReader(mpt::span<Tbyte> bytedata, shared_filename_type filename = shared_filename_type{})
|
||||
: FileCursor<Ttraits, Tfilenametraits>(bytedata, std::move(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize file reader object based on an existing file reader object window.
|
||||
explicit FileReader(value_data_type other, shared_filename_type filename = shared_filename_type{})
|
||||
: FileCursor<Ttraits, Tfilenametraits>(std::move(other), std::move(filename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
template <typename T>
|
||||
bool Read(T &target)
|
||||
{
|
||||
return mpt::IO::FileReader::Read(*this, target);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T ReadIntLE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadIntLE<T>(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T ReadIntBE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadIntLE<T>(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T ReadTruncatedIntLE(std::size_t size)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadTruncatedIntLE<T>(*this, size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T ReadSizedIntLE(std::size_t size)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadSizedIntLE<T>(*this, size);
|
||||
}
|
||||
|
||||
uint32 ReadUint32LE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint32LE(*this);
|
||||
}
|
||||
|
||||
uint32 ReadUint32BE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint32BE(*this);
|
||||
}
|
||||
|
||||
int32 ReadInt32LE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadInt32LE(*this);
|
||||
}
|
||||
|
||||
int32 ReadInt32BE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadInt32BE(*this);
|
||||
}
|
||||
|
||||
uint32 ReadUint24LE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint24LE(*this);
|
||||
}
|
||||
|
||||
uint32 ReadUint24BE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint24BE(*this);
|
||||
}
|
||||
|
||||
uint16 ReadUint16LE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint16LE(*this);
|
||||
}
|
||||
|
||||
uint16 ReadUint16BE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint16BE(*this);
|
||||
}
|
||||
|
||||
int16 ReadInt16LE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadInt16LE(*this);
|
||||
}
|
||||
|
||||
int16 ReadInt16BE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadInt16BE(*this);
|
||||
}
|
||||
|
||||
char ReadChar()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadChar(*this);
|
||||
}
|
||||
|
||||
uint8 ReadUint8()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadUint8(*this);
|
||||
}
|
||||
|
||||
int8 ReadInt8()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadInt8(*this);
|
||||
}
|
||||
|
||||
float ReadFloatLE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadFloatLE(*this);
|
||||
}
|
||||
|
||||
float ReadFloatBE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadFloatBE(*this);
|
||||
}
|
||||
|
||||
double ReadDoubleLE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadDoubleLE(*this);
|
||||
}
|
||||
|
||||
double ReadDoubleBE()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadDoubleBE(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool ReadStruct(T &target)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadStruct(*this, target);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::size_t ReadStructPartial(T &target, std::size_t partialSize = sizeof(T))
|
||||
{
|
||||
return mpt::IO::FileReader::ReadStructPartial(*this, target, partialSize);
|
||||
}
|
||||
|
||||
bool ReadNullString(std::string &dest, const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
return mpt::IO::FileReader::ReadNullString(*this, dest, maxLength);
|
||||
}
|
||||
|
||||
bool ReadLine(std::string &dest, const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
return mpt::IO::FileReader::ReadLine(*this, dest, maxLength);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t destSize>
|
||||
bool ReadArray(T (&destArray)[destSize])
|
||||
{
|
||||
return mpt::IO::FileReader::ReadArray(*this, destArray);
|
||||
}
|
||||
|
||||
template<typename T, std::size_t destSize>
|
||||
bool ReadArray(std::array<T, destSize> &destArray)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadArray(*this, destArray);
|
||||
}
|
||||
|
||||
template <typename T, std::size_t destSize>
|
||||
std::array<T, destSize> ReadArray()
|
||||
{
|
||||
return mpt::IO::FileReader::ReadArray<T, destSize>(*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ReadVector(std::vector<T> &destVector, std::size_t destSize)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadVector(*this, destVector, destSize);
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
bool ReadMagic(const char (&magic)[N])
|
||||
{
|
||||
return mpt::IO::FileReader::ReadMagic(*this, magic);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool ReadVarInt(T &target)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadVarInt(*this, target);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using Item = mpt::IO::FileReader::Chunk<T, FileReader>;
|
||||
|
||||
template <typename T>
|
||||
using ChunkList = mpt::IO::FileReader::ChunkList<T, FileReader>;
|
||||
|
||||
template<typename T>
|
||||
Item<T> ReadNextChunk(pos_type alignment)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadNextChunk<T, FileReader>(*this, alignment);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ChunkList<T> ReadChunks(pos_type alignment)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadChunks<T, FileReader>(*this, alignment);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ChunkList<T> ReadChunksUntil(pos_type alignment, decltype(T().GetID()) stopAtID)
|
||||
{
|
||||
return mpt::IO::FileReader::ReadChunksUntil<T, FileReader>(*this, alignment, stopAtID);
|
||||
}
|
||||
|
||||
template<mpt::String::ReadWriteMode mode, std::size_t destSize>
|
||||
bool ReadString(char (&destBuffer)[destSize], const std::size_t srcSize)
|
||||
{
|
||||
return FileReaderExt::ReadString<mode>(*this, destBuffer, srcSize);
|
||||
}
|
||||
|
||||
template<mpt::String::ReadWriteMode mode>
|
||||
bool ReadString(std::string &dest, const std::size_t srcSize)
|
||||
{
|
||||
return FileReaderExt::ReadString<mode>(*this, dest, srcSize);
|
||||
}
|
||||
|
||||
template<mpt::String::ReadWriteMode mode, std::size_t len>
|
||||
bool ReadString(mpt::charbuf<len> &dest, const std::size_t srcSize)
|
||||
{
|
||||
return FileReaderExt::ReadString<mode>(*this, dest, srcSize);
|
||||
}
|
||||
|
||||
template<mpt::String::ReadWriteMode mode>
|
||||
bool ReadString(mpt::ustring &dest, mpt::Charset charset, const std::size_t srcSize)
|
||||
{
|
||||
return FileReaderExt::ReadString<mode>(*this, dest, charset, srcSize);
|
||||
}
|
||||
|
||||
template<typename Tsize, mpt::String::ReadWriteMode mode, std::size_t destSize>
|
||||
bool ReadSizedString(char (&destBuffer)[destSize], const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
return FileReaderExt::ReadSizedString<Tsize, mode>(*this, destBuffer, maxLength);
|
||||
}
|
||||
|
||||
template<typename Tsize, mpt::String::ReadWriteMode mode>
|
||||
bool ReadSizedString(std::string &dest, const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
return FileReaderExt::ReadSizedString<Tsize, mode>(*this, dest, maxLength);
|
||||
}
|
||||
|
||||
template<typename Tsize, mpt::String::ReadWriteMode mode, std::size_t len>
|
||||
bool ReadSizedString(mpt::charbuf<len> &dest, const std::size_t maxLength = std::numeric_limits<std::size_t>::max())
|
||||
{
|
||||
return FileReaderExt::ReadSizedString<Tsize, mode, len>(*this, dest, maxLength);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
using FileCursor = detail::FileCursor<mpt::IO::FileCursorTraitsFileData, mpt::IO::FileCursorFilenameTraits<mpt::PathString>>;
|
||||
using FileReader = detail::FileReader<mpt::IO::FileCursorTraitsFileData, mpt::IO::FileCursorFilenameTraits<mpt::PathString>>;
|
||||
|
||||
using ChunkReader = FileReader;
|
||||
|
||||
using MemoryFileCursor = detail::FileCursor<mpt::IO::FileCursorTraitsMemory, mpt::IO::FileCursorFilenameTraitsNone>;
|
||||
using MemoryFileReader = detail::FileReader<mpt::IO::FileCursorTraitsMemory, mpt::IO::FileCursorFilenameTraitsNone>;
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* FileReaderFwd.h
|
||||
* ---------------
|
||||
* Purpose: Forward declaration for class FileReader.
|
||||
* 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 "mpt/base/namespace.hpp"
|
||||
|
||||
namespace mpt {
|
||||
inline namespace MPT_INLINE_NS {
|
||||
|
||||
template <typename Traits, bool allow_transcode_locale>
|
||||
class BasicPathString;
|
||||
struct NativePathTraits;
|
||||
struct Utf8PathTraits;
|
||||
using native_path = BasicPathString<NativePathTraits, true>;
|
||||
|
||||
namespace IO {
|
||||
|
||||
class FileCursorTraitsMemory;
|
||||
|
||||
class FileCursorTraitsFileData;
|
||||
|
||||
class FileCursorFilenameTraitsNone;
|
||||
|
||||
template <typename Tpath>
|
||||
class FileCursorFilenameTraits;
|
||||
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
class FileCursor;
|
||||
|
||||
} // namespace IO
|
||||
|
||||
} // inline namespace MPT_INLINE_NS
|
||||
} // namespace mpt
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
namespace mpt {
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
using FileCursor = mpt::IO::FileCursor<Ttraits, Tfilenametraits>;
|
||||
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
class FileReader;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
namespace mpt {
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
using PathString = mpt::native_path;
|
||||
#else
|
||||
using PathString = mpt::BasicPathString<mpt::Utf8PathTraits, false>;
|
||||
#endif
|
||||
} // namespace mpt
|
||||
|
||||
using FileCursor = detail::FileCursor<mpt::IO::FileCursorTraitsFileData, mpt::IO::FileCursorFilenameTraits<mpt::PathString>>;
|
||||
using FileReader = detail::FileReader<mpt::IO::FileCursorTraitsFileData, mpt::IO::FileCursorFilenameTraits<mpt::PathString>>;
|
||||
|
||||
using MemoryFileCursor = detail::FileCursor<mpt::IO::FileCursorTraitsMemory, mpt::IO::FileCursorFilenameTraitsNone>;
|
||||
using MemoryFileReader = detail::FileReader<mpt::IO::FileCursorTraitsMemory, mpt::IO::FileCursorFilenameTraitsNone>;
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* GzipWriter.h
|
||||
* ------------
|
||||
* Purpose: Simple wrapper around zlib's Gzip writer
|
||||
* Notes : miniz doesn't implement Gzip writing, so this is only compatible with zlib.
|
||||
* 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 "mpt/io/io.hpp"
|
||||
#include "mpt/io/io_stdstream.hpp"
|
||||
|
||||
#include "mptString.h"
|
||||
|
||||
#ifdef MPT_WITH_ZLIB
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
inline void WriteGzip(std::ostream &output, std::string &outData, const mpt::ustring &fileName)
|
||||
{
|
||||
z_stream strm{};
|
||||
int zlib_errc = Z_OK;
|
||||
strm.avail_in = static_cast<uInt>(outData.size());
|
||||
strm.next_in = reinterpret_cast<Bytef *>(outData.data());
|
||||
zlib_errc = deflateInit2(&strm, Z_BEST_COMPRESSION, Z_DEFLATED, 15 | 16, 9, Z_DEFAULT_STRATEGY);
|
||||
if(zlib_errc == Z_MEM_ERROR)
|
||||
{
|
||||
mpt::throw_out_of_memory();
|
||||
} else if(zlib_errc < Z_OK)
|
||||
{
|
||||
throw std::runtime_error{"zlib: deflateInit2() failed"};
|
||||
}
|
||||
gz_header gzHeader{};
|
||||
gzHeader.time = static_cast<uLong>(std::time(nullptr));
|
||||
std::string filenameISO = mpt::ToCharset(mpt::Charset::ISO8859_1, fileName);
|
||||
gzHeader.name = reinterpret_cast<Bytef *>(filenameISO.data());
|
||||
zlib_errc = deflateSetHeader(&strm, &gzHeader);
|
||||
if(zlib_errc == Z_MEM_ERROR)
|
||||
{
|
||||
deflateEnd(&strm);
|
||||
mpt::throw_out_of_memory();
|
||||
} else if(zlib_errc < Z_OK)
|
||||
{
|
||||
deflateEnd(&strm);
|
||||
throw std::runtime_error{"zlib: deflateSetHeader() failed"};
|
||||
}
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
std::array<Bytef, mpt::IO::BUFFERSIZE_TINY> buffer;
|
||||
strm.avail_out = static_cast<uInt>(buffer.size());
|
||||
strm.next_out = buffer.data();
|
||||
zlib_errc = deflate(&strm, Z_FINISH);
|
||||
if(zlib_errc == Z_BUF_ERROR)
|
||||
{
|
||||
// expected
|
||||
} else if(zlib_errc == Z_MEM_ERROR)
|
||||
{
|
||||
mpt::throw_out_of_memory();
|
||||
} else if(zlib_errc < Z_OK)
|
||||
{
|
||||
throw std::runtime_error{"zlib: deflate() failed"};
|
||||
}
|
||||
mpt::IO::WritePartial(output, buffer, buffer.size() - strm.avail_out);
|
||||
} while(strm.avail_out == 0);
|
||||
} catch(mpt::out_of_memory e)
|
||||
{
|
||||
deflateEnd(&strm);
|
||||
mpt::rethrow_out_of_memory(e);
|
||||
} catch(const std::exception &)
|
||||
{
|
||||
deflateEnd(&strm);
|
||||
throw;
|
||||
} catch(...)
|
||||
{
|
||||
deflateEnd(&strm);
|
||||
throw;
|
||||
}
|
||||
deflateEnd(&strm);
|
||||
}
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,442 @@
|
||||
/*
|
||||
* Logging.cpp
|
||||
* -----------
|
||||
* Purpose: General logging
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "Logging.h"
|
||||
|
||||
#include "mpt/base/macros.hpp"
|
||||
#include "mpt/io/base.hpp"
|
||||
#include "mpt/io/io.hpp"
|
||||
#include "mpt/io/io_stdstream.hpp"
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include "mpt/io_file/fstream.hpp"
|
||||
#endif
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include "mptFileIO.h"
|
||||
#endif
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include <atomic>
|
||||
#endif
|
||||
#include "version.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
namespace log
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if !defined(MPT_LOG_GLOBAL_LEVEL_STATIC)
|
||||
#if defined(MPT_LOG_GLOBAL_LEVEL)
|
||||
MPT_CONSTINIT int GlobalLogLevel = static_cast<int>(MPT_LOG_GLOBAL_LEVEL);
|
||||
#else
|
||||
MPT_CONSTINIT int GlobalLogLevel = static_cast<int>(LogDebug);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_LOG_IS_DISABLED)
|
||||
|
||||
MPT_CONSTINIT bool FileEnabled = false;
|
||||
MPT_CONSTINIT bool DebuggerEnabled = true;
|
||||
MPT_CONSTINIT bool ConsoleEnabled = false;
|
||||
|
||||
static MPT_CONSTINIT char g_FacilitySolo[1024] = {0};
|
||||
static MPT_CONSTINIT char g_FacilityBlocked[1024] = {0};
|
||||
|
||||
void SetFacilities(const std::string &solo, const std::string &blocked)
|
||||
{
|
||||
std::strcpy(g_FacilitySolo, solo.c_str());
|
||||
std::strcpy(g_FacilityBlocked, blocked.c_str());
|
||||
}
|
||||
|
||||
bool IsFacilityActive(const char *facility) noexcept
|
||||
{
|
||||
if(facility)
|
||||
{
|
||||
if(std::strlen(g_FacilitySolo) > 0)
|
||||
{
|
||||
if(std::strcmp(facility, g_FacilitySolo) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(std::strlen(g_FacilityBlocked) > 0)
|
||||
{
|
||||
if(std::strcmp(facility, g_FacilitySolo) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void GlobalLogger::SendLogMessage(const mpt::source_location &loc, LogLevel level, const char *facility, const mpt::ustring &text) const
|
||||
{
|
||||
#ifdef MPT_LOG_IS_DISABLED
|
||||
MPT_UNREFERENCED_PARAMETER(loc);
|
||||
MPT_UNREFERENCED_PARAMETER(level);
|
||||
MPT_UNREFERENCED_PARAMETER(facility);
|
||||
MPT_UNREFERENCED_PARAMETER(text);
|
||||
#else // !MPT_LOG_IS_DISABLED
|
||||
MPT_MAYBE_CONSTANT_IF(mpt::log::GlobalLogLevel < level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
if(!IsFacilityActive(facility))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#else // !MODPLUG_TRACKER
|
||||
MPT_UNREFERENCED_PARAMETER(facility);
|
||||
#endif // MODPLUG_TRACKER
|
||||
// remove eol if already present and add log level prefix
|
||||
const mpt::ustring message = LogLevelToString(level) + U_(": ") + mpt::trim_right(text, U_("\r\n"));
|
||||
const mpt::ustring file = mpt::transcode<mpt::ustring>(mpt::source_encoding, loc.file_name() ? loc.file_name() : "");
|
||||
const mpt::ustring function = mpt::transcode<mpt::ustring>(mpt::source_encoding, loc.function_name() ? loc.function_name() : "");
|
||||
const mpt::ustring line = mpt::ufmt::dec(loc.line());
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT)
|
||||
#if MPT_OS_WINDOWS
|
||||
static uint64 s_lastlogtime = 0;
|
||||
uint64 cur = mpt::Date::ANSI::Now();
|
||||
uint64 diff = cur/10000 - s_lastlogtime;
|
||||
s_lastlogtime = cur/10000;
|
||||
#else
|
||||
uint64 cur = 0;
|
||||
uint64 diff = 0;
|
||||
#endif
|
||||
if(mpt::log::FileEnabled)
|
||||
{
|
||||
static std::optional<mpt::IO::ofstream> s_logfile;
|
||||
if(!s_logfile)
|
||||
{
|
||||
s_logfile.emplace(P_("mptrack.log"), std::ios::app);
|
||||
}
|
||||
if(s_logfile)
|
||||
{
|
||||
mpt::IO::WriteText(*s_logfile, mpt::transcode<std::string>(mpt::logfile_encoding, MPT_UFORMAT("{}+{} {}({}): {} [{}]\n")
|
||||
( mpt::Date::ANSI::ToUString(cur)
|
||||
, mpt::ufmt::right(6, mpt::ufmt::dec(diff))
|
||||
, file
|
||||
, line
|
||||
, message
|
||||
, function
|
||||
)));
|
||||
mpt::IO::Flush(*s_logfile);
|
||||
}
|
||||
}
|
||||
if(mpt::log::DebuggerEnabled)
|
||||
{
|
||||
OutputDebugStringW(mpt::ToWide(MPT_UFORMAT("{}({}): +{} {} [{}]\n")
|
||||
( file
|
||||
, line
|
||||
, mpt::ufmt::right(6, mpt::ufmt::dec(diff))
|
||||
, message
|
||||
, function
|
||||
)).c_str());
|
||||
}
|
||||
if(mpt::log::ConsoleEnabled)
|
||||
{
|
||||
static bool consoleInited = false;
|
||||
if(!consoleInited)
|
||||
{
|
||||
AllocConsole();
|
||||
consoleInited = true;
|
||||
}
|
||||
std::wstring consoletext = mpt::ToWide(message) + L"\r\n";
|
||||
DWORD dummy = 0;
|
||||
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), consoletext.c_str(), mpt::saturate_cast<DWORD>(consoletext.length()), &dummy, NULL);
|
||||
}
|
||||
#elif defined(MODPLUG_TRACKER) && defined(MPT_BUILD_WINESUPPORT)
|
||||
std::clog
|
||||
<< "NativeSupport: "
|
||||
<< mpt::transcode<std::string>(mpt::stdio_encoding, file) << "(" << mpt::transcode<std::string>(mpt::stdio_encoding, line) << ")" << ": "
|
||||
<< mpt::transcode<std::string>(mpt::stdio_encoding, message)
|
||||
<< " [" << mpt::transcode<std::string>(mpt::stdio_encoding, function) << "]"
|
||||
<< std::endl;
|
||||
#else // !MODPLUG_TRACKER
|
||||
std::clog
|
||||
<< "libopenmpt: "
|
||||
<< mpt::transcode<std::string>(mpt::stdio_encoding, file) << "(" << mpt::transcode<std::string>(mpt::stdio_encoding, line) << ")" << ": "
|
||||
<< mpt::transcode<std::string>(mpt::stdio_encoding, message)
|
||||
<< " [" << mpt::transcode<std::string>(mpt::stdio_encoding, function) << "]"
|
||||
<< std::endl;
|
||||
#endif // MODPLUG_TRACKER
|
||||
#endif // MPT_LOG_IS_DISABLED
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
namespace Trace {
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
// Debugging functionality will use simple globals.
|
||||
|
||||
MPT_CONSTINIT std::atomic<bool> g_Enabled{false};
|
||||
|
||||
static MPT_CONSTINIT bool g_Sealed = false;
|
||||
|
||||
struct Entry {
|
||||
uint32 Index;
|
||||
uint32 ThreadId;
|
||||
uint64 Timestamp;
|
||||
const char * Function;
|
||||
const char * File;
|
||||
int Line;
|
||||
Direction Direction;
|
||||
};
|
||||
|
||||
static MPT_FORCEINLINE bool operator < (const Entry &a, const Entry &b) noexcept
|
||||
{
|
||||
/*
|
||||
return false
|
||||
|| (a.Timestamp < b.Timestamp)
|
||||
|| (a.ThreadID < b.ThreadID)
|
||||
|| (a.File < b.File)
|
||||
|| (a.Line < b.Line)
|
||||
|| (a.Function < b.Function)
|
||||
;
|
||||
*/
|
||||
return false
|
||||
|| (a.Index < b.Index)
|
||||
;
|
||||
}
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
// VS2022 still does nto have constexpr vector default ctor
|
||||
static /*MPT_CONSTINIT*/ std::vector<mpt::log::Trace::Entry> Entries;
|
||||
#else
|
||||
static MPT_CONSTINIT std::vector<mpt::log::Trace::Entry> Entries;
|
||||
#endif
|
||||
|
||||
static MPT_CONSTINIT std::atomic<uint32> NextIndex(0);
|
||||
|
||||
static MPT_CONSTINIT uint32 ThreadIdGUI = 0;
|
||||
static MPT_CONSTINIT uint32 ThreadIdAudio = 0;
|
||||
static MPT_CONSTINIT uint32 ThreadIdNotify = 0;
|
||||
static MPT_CONSTINIT uint32 ThreadIdWatchdir = 0;
|
||||
|
||||
void Enable(std::size_t numEntries)
|
||||
{
|
||||
if(g_Sealed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Entries.clear();
|
||||
Entries.resize(numEntries);
|
||||
NextIndex.store(0);
|
||||
g_Enabled = (numEntries > 0);
|
||||
}
|
||||
|
||||
void Disable()
|
||||
{
|
||||
if(g_Sealed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_Enabled = false;
|
||||
}
|
||||
|
||||
MPT_NOINLINE void Trace(const mpt::source_location & loc, Direction direction) noexcept
|
||||
{
|
||||
// This will get called in realtime contexts and hot paths.
|
||||
// No blocking allowed here.
|
||||
const uint32 index = NextIndex.fetch_add(1);
|
||||
const std::size_t numEntries = Entries.size();
|
||||
#if 1
|
||||
LARGE_INTEGER time;
|
||||
time.QuadPart = 0;
|
||||
QueryPerformanceCounter(&time);
|
||||
const uint64 timestamp = time.QuadPart;
|
||||
#else
|
||||
FILETIME time = FILETIME();
|
||||
GetSystemTimeAsFileTime(&time);
|
||||
const uint64 timestamp = (static_cast<uint64>(time.dwHighDateTime) << 32) | (static_cast<uint64>(time.dwLowDateTime) << 0);
|
||||
#endif
|
||||
const uint32 threadid = static_cast<uint32>(GetCurrentThreadId());
|
||||
mpt::log::Trace::Entry & entry = Entries[index % numEntries];
|
||||
entry.Index = index;
|
||||
entry.ThreadId = threadid;
|
||||
entry.Timestamp = timestamp;
|
||||
entry.Function = loc.function_name();
|
||||
entry.File = loc.file_name();
|
||||
entry.Line = loc.line();
|
||||
entry.Direction = direction;
|
||||
}
|
||||
|
||||
void Seal()
|
||||
{
|
||||
if(!g_Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
g_Enabled = false;
|
||||
g_Sealed = true;
|
||||
uint32 count = NextIndex.fetch_add(0);
|
||||
if(count < Entries.size())
|
||||
{
|
||||
Entries.resize(count);
|
||||
}
|
||||
}
|
||||
|
||||
bool Dump(const mpt::PathString &filename)
|
||||
{
|
||||
if(!g_Sealed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
LARGE_INTEGER qpcNow;
|
||||
qpcNow.QuadPart = 0;
|
||||
QueryPerformanceCounter(&qpcNow);
|
||||
uint64 ftNow = mpt::Date::ANSI::Now();
|
||||
|
||||
// sort according to index in case of overflows
|
||||
std::stable_sort(Entries.begin(), Entries.end());
|
||||
|
||||
mpt::IO::ofstream f(filename);
|
||||
|
||||
f << "Build: OpenMPT " << mpt::transcode<std::string>(mpt::logfile_encoding, Build::GetVersionStringExtended()) << std::endl;
|
||||
|
||||
bool qpcValid = false;
|
||||
|
||||
LARGE_INTEGER qpcFreq;
|
||||
qpcFreq.QuadPart = 0;
|
||||
QueryPerformanceFrequency(&qpcFreq);
|
||||
if(qpcFreq.QuadPart > 0)
|
||||
{
|
||||
qpcValid = true;
|
||||
}
|
||||
|
||||
f << "Dump: " << mpt::transcode<std::string>(mpt::logfile_encoding, mpt::Date::ANSI::ToUString(ftNow)) << std::endl;
|
||||
f << "Captured events: " << Entries.size() << std::endl;
|
||||
if(qpcValid && (Entries.size() > 0))
|
||||
{
|
||||
double period = static_cast<double>(Entries[Entries.size() - 1].Timestamp - Entries[0].Timestamp) / static_cast<double>(qpcFreq.QuadPart);
|
||||
double eventsPerSecond = Entries.size() / period;
|
||||
f << "Period [s]: " << mpt::afmt::fix(period) << std::endl;
|
||||
f << "Events/second: " << mpt::afmt::fix(eventsPerSecond) << std::endl;
|
||||
}
|
||||
|
||||
for(auto &entry : Entries)
|
||||
{
|
||||
if(!entry.Function) entry.Function = "";
|
||||
if(!entry.File) entry.File = "";
|
||||
std::string time;
|
||||
if(qpcValid)
|
||||
{
|
||||
time = mpt::transcode<std::string>(mpt::logfile_encoding, mpt::Date::ANSI::ToUString( ftNow - static_cast<int64>( static_cast<double>(qpcNow.QuadPart - entry.Timestamp) * (10000000.0 / static_cast<double>(qpcFreq.QuadPart) ) ) ) );
|
||||
} else
|
||||
{
|
||||
time = MPT_AFORMAT("0x{}")(mpt::afmt::hex0<16>(entry.Timestamp));
|
||||
}
|
||||
f << time;
|
||||
if(entry.ThreadId == ThreadIdGUI)
|
||||
{
|
||||
f << " -----GUI ";
|
||||
} else if(entry.ThreadId == ThreadIdAudio)
|
||||
{
|
||||
f << " ---Audio ";
|
||||
} else if(entry.ThreadId == ThreadIdNotify)
|
||||
{
|
||||
f << " --Notify ";
|
||||
} else if(entry.ThreadId == ThreadIdWatchdir)
|
||||
{
|
||||
f << " WatchDir ";
|
||||
} else
|
||||
{
|
||||
f << " " << mpt::afmt::hex0<8>(entry.ThreadId) << " ";
|
||||
}
|
||||
f << (entry.Direction == mpt::log::Trace::Direction::Enter ? ">" : entry.Direction == mpt::log::Trace::Direction::Leave ? "<" : " ") << " ";
|
||||
f << entry.File << "(" << entry.Line << "): " << entry.Function;
|
||||
f << std::endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetThreadId(mpt::log::Trace::ThreadKind kind, uint32 id)
|
||||
{
|
||||
if(id == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch(kind)
|
||||
{
|
||||
case ThreadKindGUI:
|
||||
ThreadIdGUI = id;
|
||||
break;
|
||||
case ThreadKindAudio:
|
||||
ThreadIdAudio = id;
|
||||
break;
|
||||
case ThreadKindNotify:
|
||||
ThreadIdNotify = id;
|
||||
break;
|
||||
case ThreadKindWatchdir:
|
||||
ThreadIdWatchdir = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 GetThreadId(mpt::log::Trace::ThreadKind kind)
|
||||
{
|
||||
uint32 result = 0;
|
||||
switch(kind)
|
||||
{
|
||||
case ThreadKindGUI:
|
||||
result = ThreadIdGUI;
|
||||
break;
|
||||
case ThreadKindAudio:
|
||||
result = ThreadIdAudio;
|
||||
break;
|
||||
case ThreadKindNotify:
|
||||
result = ThreadIdNotify;
|
||||
break;
|
||||
case ThreadKindWatchdir:
|
||||
result = ThreadIdWatchdir;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
} // namespace Trace
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
} // namespace log
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Logging.h
|
||||
* ---------
|
||||
* Purpose: General logging
|
||||
* 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 "openmpt/logging/Logger.hpp"
|
||||
|
||||
#include "mptPathString.h"
|
||||
#include "mptString.h"
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
#include <atomic>
|
||||
#endif
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
Build time logging configuration:
|
||||
|
||||
* #define MPT_LOG_GLOBAL_LEVEL_STATIC
|
||||
#define MPT_LOG_GLOBAL_LEVEL #
|
||||
Define the former (to anything) and the latter (to one of the log levels
|
||||
below) in order to statically select the verbosity of logging at build time.
|
||||
MPT_LOG calls that exceed the specified logging level will get dead-code
|
||||
eliminated at compile time.
|
||||
This especially means that, when setting MPT_LOG_GLOBAL_LEVEL to 0, no
|
||||
MPT_LOG call (with a constant level parameter) remains in the resulting
|
||||
binary, however, they still do get parsed and properly type checked by the
|
||||
compiler.
|
||||
|
||||
|
||||
Logging:
|
||||
|
||||
If the context is related to a particular CSoundfile instance, use
|
||||
CSoundfile::AddToLog.
|
||||
|
||||
Logging a simple message:
|
||||
MPT_LOG_GLOBAL(LogWarning, "sounddev", "some message");
|
||||
MPT_LOG_GLOBAL(LogWarning, "sounddev", U_("some message"));
|
||||
Facility is some course grained code section identifier (more coarse grained
|
||||
than the current file name probably), useful to do some selective logging.
|
||||
|
||||
Logging a more complex message:
|
||||
MPT_LOG_GLOBAL(LogWarning, "sounddev", MPT_UFORMAT("Some message: foo={}, bar=0x{}")(foo, mpt::ufmt::hex0<8>(bar)));
|
||||
|
||||
Note that even with full enabled logging and a runtime configurable logging
|
||||
level, the runtime overhead of a MPT_LOG_GLOBAL(level, facility, text) call is just a
|
||||
single conditional in case the verbosity does not require logging the respective
|
||||
message. Even the expression "text" is not evaluated.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
inline mpt::ustring LogLevelToString(LogLevel level)
|
||||
{
|
||||
switch(level)
|
||||
{
|
||||
case LogError: return U_("error"); break;
|
||||
case LogWarning: return U_("warning"); break;
|
||||
case LogNotification: return U_("notify"); break;
|
||||
case LogInformation: return U_("info"); break;
|
||||
case LogDebug: return U_("debug"); break;
|
||||
}
|
||||
return U_("unknown");
|
||||
}
|
||||
|
||||
|
||||
class ILog
|
||||
{
|
||||
protected:
|
||||
virtual ~ILog() { }
|
||||
public:
|
||||
virtual void AddToLog(LogLevel level, const mpt::ustring &text) const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
namespace log
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if defined(MPT_LOG_GLOBAL_LEVEL_STATIC)
|
||||
#if (MPT_LOG_GLOBAL_LEVEL <= 0)
|
||||
// All logging has beeen statically disabled.
|
||||
// All logging code gets compiled and immediately dead-code eliminated.
|
||||
#define MPT_LOG_IS_DISABLED
|
||||
#endif
|
||||
inline constexpr int GlobalLogLevel = MPT_LOG_GLOBAL_LEVEL ;
|
||||
#else
|
||||
extern int GlobalLogLevel;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_LOG_IS_DISABLED)
|
||||
extern bool FileEnabled;
|
||||
extern bool DebuggerEnabled;
|
||||
extern bool ConsoleEnabled;
|
||||
void SetFacilities(const std::string &solo, const std::string &blocked);
|
||||
bool IsFacilityActive(const char *facility) noexcept;
|
||||
#else
|
||||
MPT_FORCEINLINE bool IsFacilityActive(const char * /*facility*/ ) noexcept { return true; }
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class GlobalLogger final
|
||||
: public ILogger
|
||||
{
|
||||
public:
|
||||
GlobalLogger() = default;
|
||||
~GlobalLogger() final = default;
|
||||
public:
|
||||
bool IsLevelActive(LogLevel level) const noexcept override
|
||||
{
|
||||
return (mpt::log::GlobalLogLevel >= level);
|
||||
}
|
||||
bool IsFacilityActive(const char *facility) const noexcept override
|
||||
{
|
||||
return mpt::log::IsFacilityActive(facility);
|
||||
}
|
||||
void SendLogMessage(const mpt::source_location &loc, LogLevel level, const char *facility, const mpt::ustring &message) const override;
|
||||
};
|
||||
|
||||
|
||||
#define MPT_LOG_GLOBAL(level, facility, text) MPT_LOG(mpt::log::GlobalLogger{}, (level), (facility), (text))
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
|
||||
namespace Trace {
|
||||
|
||||
// This is not strictly thread safe in all corner cases because of missing barriers.
|
||||
// We do not care in order to not harm the fast path with additional barriers.
|
||||
// Enabled tracing incurs a runtime overhead with multiple threads as a global atomic variable
|
||||
// gets modified.
|
||||
// This cacheline bouncing does not matter at all
|
||||
// if there are not multiple thread adding trace points at high frequency (way greater than 1000Hz),
|
||||
// which, in OpenMPT, is only ever the case for just a single thread (the audio thread), if at all.
|
||||
extern std::atomic<bool> g_Enabled;
|
||||
inline bool IsEnabled() { return g_Enabled; }
|
||||
|
||||
enum class Direction : int8
|
||||
{
|
||||
Unknown = 0,
|
||||
Enter = 1,
|
||||
Leave = -1,
|
||||
};
|
||||
|
||||
MPT_NOINLINE void Trace(const mpt::source_location & loc, Direction direction = Direction::Unknown) noexcept;
|
||||
|
||||
enum ThreadKind {
|
||||
ThreadKindGUI,
|
||||
ThreadKindAudio,
|
||||
ThreadKindNotify,
|
||||
ThreadKindWatchdir,
|
||||
};
|
||||
|
||||
void Enable(std::size_t numEntries);
|
||||
void Disable();
|
||||
|
||||
void SetThreadId(mpt::log::Trace::ThreadKind kind, uint32 id);
|
||||
uint32 GetThreadId(mpt::log::Trace::ThreadKind kind);
|
||||
|
||||
void Seal();
|
||||
bool Dump(const mpt::PathString &filename);
|
||||
|
||||
class Scope
|
||||
{
|
||||
private:
|
||||
const mpt::source_location loc;
|
||||
public:
|
||||
MPT_FORCEINLINE Scope(mpt::source_location loc) noexcept
|
||||
: loc(loc)
|
||||
{
|
||||
if(mpt::log::Trace::g_Enabled)
|
||||
{
|
||||
mpt::log::Trace::Trace(loc, mpt::log::Trace::Direction::Enter);
|
||||
}
|
||||
}
|
||||
MPT_FORCEINLINE ~Scope() noexcept
|
||||
{
|
||||
if(mpt::log::Trace::g_Enabled)
|
||||
{
|
||||
mpt::log::Trace::Trace(loc, mpt::log::Trace::Direction::Leave);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#define MPT_TRACE_CONCAT_HELPER(x, y) x ## y
|
||||
#define MPT_TRACE_CONCAT(x, y) MPT_TRACE_CONCAT_HELPER(x, y)
|
||||
|
||||
#define MPT_TRACE_SCOPE() mpt::log::Trace::Scope MPT_TRACE_CONCAT(MPT_TRACE_VAR, __LINE__)(MPT_SOURCE_LOCATION_CURRENT())
|
||||
|
||||
#define MPT_TRACE() do { if(mpt::log::Trace::g_Enabled) { mpt::log::Trace::Trace(MPT_SOURCE_LOCATION_CURRENT()); } } while(0)
|
||||
|
||||
} // namespace Trace
|
||||
|
||||
#else // !MODPLUG_TRACKER
|
||||
|
||||
#define MPT_TRACE_SCOPE() do { } while(0)
|
||||
|
||||
#define MPT_TRACE() do { } while(0)
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
} // namespace log
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Profiler.cpp
|
||||
* ------------
|
||||
* Purpose: Performance measuring
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Profiler.h"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
#ifdef USE_PROFILER
|
||||
|
||||
|
||||
class Statistics
|
||||
{
|
||||
public:
|
||||
Profile &profile;
|
||||
Profile::Data data;
|
||||
double usage;
|
||||
Statistics(Profile &p) : profile(p)
|
||||
{
|
||||
usage = 0.0;
|
||||
Update();
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
data = profile.GetAndResetData();
|
||||
uint64 now = profile.GetTime();
|
||||
uint64 timewindow = now - data.Start;
|
||||
if(data.Calls > 0 && timewindow > 0)
|
||||
{
|
||||
usage = (double)data.Sum / (double)timewindow;
|
||||
} else
|
||||
{
|
||||
usage = 0.0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ProfileBlock
|
||||
{
|
||||
class Profile * profile;
|
||||
const char * name;
|
||||
class Statistics * stats;
|
||||
};
|
||||
|
||||
static constexpr std::size_t MAX_PROFILES = 1024;
|
||||
|
||||
static ProfileBlock Profiles[ MAX_PROFILES ];
|
||||
|
||||
static std::size_t NextProfile = 0;
|
||||
|
||||
|
||||
static void RegisterProfile(Profile *newprofile)
|
||||
{
|
||||
if(NextProfile < MAX_PROFILES)
|
||||
{
|
||||
Profiles[NextProfile].profile = newprofile;
|
||||
Profiles[NextProfile].stats = 0;
|
||||
NextProfile++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void UnregisterProfile(Profile *oldprofile)
|
||||
{
|
||||
for(std::size_t i=0; i<NextProfile; i++) {
|
||||
if(Profiles[i].profile == oldprofile) {
|
||||
Profiles[i].profile = 0;
|
||||
delete Profiles[i].stats;
|
||||
Profiles[i].stats = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Profiler::Update()
|
||||
{
|
||||
for(std::size_t i=0; i<NextProfile; i++)
|
||||
{
|
||||
if(!Profiles[i].stats)
|
||||
{
|
||||
Profiles[i].stats = new Statistics(*Profiles[i].profile);
|
||||
} else
|
||||
{
|
||||
Profiles[i].stats->Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string Profiler::DumpProfiles()
|
||||
{
|
||||
std::string ret;
|
||||
for(std::size_t i=0; i<NextProfile; i++)
|
||||
{
|
||||
if(Profiles[i].stats)
|
||||
{
|
||||
Statistics &stats = *Profiles[i].stats;
|
||||
std::string cat;
|
||||
switch(stats.profile.Category)
|
||||
{
|
||||
case Profiler::GUI: cat = "GUI"; break;
|
||||
case Profiler::Audio: cat = "Audio"; break;
|
||||
case Profiler::Notify: cat = "Notify"; break;
|
||||
}
|
||||
ret += cat + " " + std::string(stats.profile.Name) + ": " + mpt::afmt::right(6, mpt::afmt::fix(stats.usage * 100.0, 3)) + "%\r\n";
|
||||
}
|
||||
}
|
||||
ret += "\r\n";
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
std::vector<double> Profiler::DumpCategories()
|
||||
{
|
||||
std::vector<double> ret;
|
||||
ret.resize(Profiler::CategoriesCount);
|
||||
for(std::size_t i=0; i<NextProfile; i++)
|
||||
{
|
||||
if(Profiles[i].stats)
|
||||
{
|
||||
ret[Profiles[i].profile->Category] += Profiles[i].stats->usage;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
uint64 Profile::GetTime() const
|
||||
{
|
||||
LARGE_INTEGER ret;
|
||||
ret.QuadPart = 0;
|
||||
QueryPerformanceCounter(&ret);
|
||||
return ret.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
uint64 Profile::GetFrequency() const
|
||||
{
|
||||
LARGE_INTEGER ret;
|
||||
ret.QuadPart = 0;
|
||||
QueryPerformanceFrequency(&ret);
|
||||
return ret.QuadPart;
|
||||
}
|
||||
|
||||
|
||||
Profile::Profile(Profiler::Category category, const char *name) : Category(category), Name(name)
|
||||
{
|
||||
data.Calls = 0;
|
||||
data.Sum = 0;
|
||||
data.Overhead = 0;
|
||||
data.Start = GetTime();
|
||||
EnterTime = 0;
|
||||
RegisterProfile(this);
|
||||
}
|
||||
|
||||
|
||||
Profile::~Profile()
|
||||
{
|
||||
UnregisterProfile(this);
|
||||
}
|
||||
|
||||
|
||||
Profile::Data Profile::GetAndResetData()
|
||||
{
|
||||
Profile::Data ret;
|
||||
datamutex.lock();
|
||||
ret = data;
|
||||
data.Calls = 0;
|
||||
data.Sum = 0;
|
||||
data.Overhead = 0;
|
||||
data.Start = GetTime();
|
||||
datamutex.unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void Profile::Reset()
|
||||
{
|
||||
datamutex.lock();
|
||||
data.Calls = 0;
|
||||
data.Sum = 0;
|
||||
data.Overhead = 0;
|
||||
data.Start = GetTime();
|
||||
datamutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
void Profile::Enter()
|
||||
{
|
||||
EnterTime = GetTime();
|
||||
}
|
||||
|
||||
|
||||
void Profile::Leave()
|
||||
{
|
||||
uint64 LeaveTime = GetTime();
|
||||
datamutex.lock();
|
||||
data.Calls += 1;
|
||||
data.Sum += LeaveTime - EnterTime;
|
||||
datamutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
#else // !USE_PROFILER
|
||||
|
||||
MPT_MSVC_WORKAROUND_LNK4221(Profiler)
|
||||
|
||||
#endif // USE_PROFILER
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Profiler.h
|
||||
* ----------
|
||||
* Purpose: Performance measuring
|
||||
* 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 "mpt/mutex/mutex.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
//#define USE_PROFILER
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_PROFILER
|
||||
|
||||
class Profiler
|
||||
{
|
||||
public:
|
||||
enum Category
|
||||
{
|
||||
GUI,
|
||||
Audio,
|
||||
Notify,
|
||||
CategoriesCount
|
||||
};
|
||||
static std::vector<std::string> GetCategoryNames()
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
ret.push_back("GUI");
|
||||
ret.push_back("Audio");
|
||||
ret.push_back("Notify");
|
||||
return ret;
|
||||
}
|
||||
public:
|
||||
static void Update();
|
||||
static std::string DumpProfiles();
|
||||
static std::vector<double> DumpCategories();
|
||||
};
|
||||
|
||||
|
||||
class Profile
|
||||
{
|
||||
private:
|
||||
mutable mpt::mutex datamutex;
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
uint64 Calls;
|
||||
uint64 Sum;
|
||||
int64 Overhead;
|
||||
uint64 Start;
|
||||
};
|
||||
public:
|
||||
Data data;
|
||||
uint64 EnterTime;
|
||||
Profiler::Category Category;
|
||||
const char * const Name;
|
||||
uint64 GetTime() const;
|
||||
uint64 GetFrequency() const;
|
||||
public:
|
||||
Profile(Profiler::Category category, const char *name);
|
||||
~Profile();
|
||||
void Reset();
|
||||
void Enter();
|
||||
void Leave();
|
||||
class Scope
|
||||
{
|
||||
private:
|
||||
Profile &profile;
|
||||
public:
|
||||
Scope(Profile &p) : profile(p) { profile.Enter(); }
|
||||
~Scope() { profile.Leave(); }
|
||||
};
|
||||
public:
|
||||
Data GetAndResetData();
|
||||
};
|
||||
|
||||
|
||||
#define OPENMPT_PROFILE_SCOPE(cat, name) \
|
||||
static Profile OPENMPT_PROFILE_VAR(cat, name);\
|
||||
Profile::Scope OPENMPT_PROFILE_SCOPE_VAR(OPENMPT_PROFILE_VAR); \
|
||||
/**/
|
||||
|
||||
|
||||
#define OPENMPT_PROFILE_FUNCTION(cat) OPENMPT_PROFILE_SCOPE(cat, __func__)
|
||||
|
||||
|
||||
#else // !USE_PROFILER
|
||||
|
||||
|
||||
class Profiler
|
||||
{
|
||||
public:
|
||||
enum Category
|
||||
{
|
||||
CategoriesCount
|
||||
};
|
||||
static std::vector<std::string> GetCategoryNames() { return std::vector<std::string>(); }
|
||||
public:
|
||||
static void Update() { }
|
||||
static std::string DumpProfiles() { return std::string(); }
|
||||
static std::vector<double> DumpCategories() { return std::vector<double>(); }
|
||||
};
|
||||
#define OPENMPT_PROFILE_SCOPE(cat, name) do { } while(0)
|
||||
#define OPENMPT_PROFILE_FUNCTION(cat) do { } while(0)
|
||||
|
||||
|
||||
#endif // USE_PROFILER
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,220 @@
|
||||
/*
|
||||
* misc_util.h
|
||||
* -----------
|
||||
* Purpose: Various useful utility functions.
|
||||
* 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 "mpt/base/span.hpp"
|
||||
#include "mpt/exception/exception_text.hpp"
|
||||
|
||||
#include "mptAssert.h"
|
||||
#include "mptBaseMacros.h"
|
||||
#include "mptBaseTypes.h"
|
||||
#include "mptBaseUtils.h"
|
||||
#include "mptString.h"
|
||||
|
||||
// old
|
||||
#include "mptBaseUtils.h"
|
||||
#include "mptStringFormat.h"
|
||||
#include "mptTime.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace Util
|
||||
{
|
||||
|
||||
|
||||
|
||||
// Insert a range of items [insStart, insEnd], and possibly shift item fix to the left.
|
||||
template<typename T>
|
||||
void InsertItem(const T insStart, const T insEnd, T &fix)
|
||||
{
|
||||
MPT_ASSERT(insEnd >= insStart);
|
||||
if(fix >= insStart)
|
||||
{
|
||||
fix += (insEnd - insStart + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Insert a range of items [insStart, insEnd], and possibly shift items in range [fixStart, fixEnd] to the right.
|
||||
template<typename T>
|
||||
void InsertRange(const T insStart, const T insEnd, T &fixStart, T &fixEnd)
|
||||
{
|
||||
MPT_ASSERT(insEnd >= insStart);
|
||||
const T insLength = insEnd - insStart + 1;
|
||||
if(fixStart >= insEnd)
|
||||
{
|
||||
fixStart += insLength;
|
||||
}
|
||||
if(fixEnd >= insEnd)
|
||||
{
|
||||
fixEnd += insLength;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a range of items [delStart, delEnd], and possibly shift item fix to the left.
|
||||
template<typename T>
|
||||
void DeleteItem(const T delStart, const T delEnd, T &fix)
|
||||
{
|
||||
MPT_ASSERT(delEnd >= delStart);
|
||||
if(fix > delEnd)
|
||||
{
|
||||
fix -= (delEnd - delStart + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a range of items [delStart, delEnd], and possibly shift items in range [fixStart, fixEnd] to the left.
|
||||
template<typename T>
|
||||
void DeleteRange(const T delStart, const T delEnd, T &fixStart, T &fixEnd)
|
||||
{
|
||||
MPT_ASSERT(delEnd >= delStart);
|
||||
const T delLength = delEnd - delStart + 1;
|
||||
if(delStart < fixStart && delEnd < fixStart)
|
||||
{
|
||||
// cut part is before loop start
|
||||
fixStart -= delLength;
|
||||
fixEnd -= delLength;
|
||||
} else if(delStart < fixStart && delEnd < fixEnd)
|
||||
{
|
||||
// cut part is partly before loop start
|
||||
fixStart = delStart;
|
||||
fixEnd -= delLength;
|
||||
} else if(delStart >= fixStart && delEnd < fixEnd)
|
||||
{
|
||||
// cut part is in the loop
|
||||
fixEnd -= delLength;
|
||||
} else if(delStart >= fixStart && delStart < fixEnd && delEnd > fixEnd)
|
||||
{
|
||||
// cut part is partly before loop end
|
||||
fixEnd = delStart;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename T, std::size_t n>
|
||||
class fixed_size_queue
|
||||
{
|
||||
private:
|
||||
T buffer[n+1];
|
||||
std::size_t read_position;
|
||||
std::size_t write_position;
|
||||
public:
|
||||
fixed_size_queue() : read_position(0), write_position(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
read_position = 0;
|
||||
write_position = 0;
|
||||
}
|
||||
std::size_t read_size() const
|
||||
{
|
||||
if ( write_position > read_position )
|
||||
{
|
||||
return write_position - read_position;
|
||||
} else if ( write_position < read_position )
|
||||
{
|
||||
return write_position - read_position + n + 1;
|
||||
} else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
std::size_t write_size() const
|
||||
{
|
||||
if ( write_position > read_position )
|
||||
{
|
||||
return read_position - write_position + n;
|
||||
} else if ( write_position < read_position )
|
||||
{
|
||||
return read_position - write_position - 1;
|
||||
} else
|
||||
{
|
||||
return n;
|
||||
}
|
||||
}
|
||||
bool push( const T & v )
|
||||
{
|
||||
if ( !write_size() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
buffer[write_position] = v;
|
||||
write_position = ( write_position + 1 ) % ( n + 1 );
|
||||
return true;
|
||||
}
|
||||
bool pop() {
|
||||
if ( !read_size() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
read_position = ( read_position + 1 ) % ( n + 1 );
|
||||
return true;
|
||||
}
|
||||
T peek() {
|
||||
if ( !read_size() )
|
||||
{
|
||||
return T();
|
||||
}
|
||||
return buffer[read_position];
|
||||
}
|
||||
const T * peek_p()
|
||||
{
|
||||
if ( !read_size() )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return &(buffer[read_position]);
|
||||
}
|
||||
const T * peek_next_p()
|
||||
{
|
||||
if ( read_size() < 2 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
return &(buffer[(read_position+1)%(n+1)]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace Util
|
||||
|
||||
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
template <typename Tstring, typename Tbuf, typename Tsize>
|
||||
Tstring ParseMaybeNullTerminatedStringFromBufferWithSizeInBytes(const Tbuf *buf, Tsize sizeBytes)
|
||||
{
|
||||
// REG_SZ may contain a single NUL terminator, multiple NUL terminators, or no NUL terminator at all
|
||||
return Tstring(reinterpret_cast<const typename Tstring::value_type*>(buf), reinterpret_cast<const typename Tstring::value_type*>(buf) + (sizeBytes / sizeof(typename Tstring::value_type))).c_str();
|
||||
}
|
||||
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* mptAssert.h
|
||||
* -----------
|
||||
* Purpose: assert and static_assert
|
||||
* 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 "mpt/base/source_location.hpp"
|
||||
#include "mptBaseMacros.h"
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
// Static code checkers might need to get the knowledge of our assertions transferred to them.
|
||||
#define MPT_CHECKER_ASSUME_ASSERTIONS 1
|
||||
//#define MPT_CHECKER_ASSUME_ASSERTIONS 0
|
||||
|
||||
#ifdef MPT_BUILD_ANALYZED
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
|
||||
#if MPT_CHECKER_ASSUME_ASSERTIONS
|
||||
#define MPT_CHECKER_ASSUME(x) __analysis_assume(!!(x))
|
||||
#endif
|
||||
|
||||
#elif MPT_COMPILER_CLANG
|
||||
|
||||
#if MPT_CHECKER_ASSUME_ASSERTIONS
|
||||
#ifdef NDEBUG
|
||||
#error "Builds for static analyzers depend on assert() being enabled, but the current build has #define NDEBUG. This makes no sense."
|
||||
#endif
|
||||
OPENMPT_NAMESPACE_END
|
||||
#include <cassert>
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
#define MPT_CHECKER_ASSUME(x) assert(!!(x))
|
||||
#endif
|
||||
|
||||
#endif // MPT_COMPILER
|
||||
|
||||
#endif // MPT_BUILD_ANALYZED
|
||||
|
||||
#ifndef MPT_CHECKER_ASSUME
|
||||
#define MPT_CHECKER_ASSUME(x) do { } while(0)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if defined(MPT_WITH_MFC) && !defined(MPT_CPPCHECK_CUSTOM)
|
||||
|
||||
#if !defined(ASSERT)
|
||||
#error "MFC is expected to #define ASSERT"
|
||||
#endif // !defined(ASERRT)
|
||||
#define MPT_FRAMEWORK_ASSERT_IS_DEFINED
|
||||
|
||||
#if defined(_DEBUG)
|
||||
#define MPT_FRAMEWORK_ASSERT_IS_ACTIVE 1
|
||||
#else // !_DEBUG
|
||||
#define MPT_FRAMEWORK_ASSERT_IS_ACTIVE 0
|
||||
#endif // _DEBUG
|
||||
|
||||
// let MFC handle our asserts
|
||||
#define MPT_ASSERT_USE_FRAMEWORK 1
|
||||
|
||||
#else // !MPT_WITH_MFC
|
||||
|
||||
#if defined(ASSERT)
|
||||
#define MPT_FRAMEWORK_ASSERT_IS_DEFINED
|
||||
#if defined(_DEBUG)
|
||||
#define MPT_FRAMEWORK_ASSERT_IS_ACTIVE 1
|
||||
#else // !_DEBUG
|
||||
#define MPT_FRAMEWORK_ASSERT_IS_ACTIVE 0
|
||||
#endif // _DEBUG
|
||||
#endif // !defined(ASERRT)
|
||||
|
||||
// handle assert in our own way without relying on some platform-/framework-specific assert implementation
|
||||
#define MPT_ASSERT_USE_FRAMEWORK 0
|
||||
|
||||
#endif // MPT_WITH_MFC
|
||||
|
||||
#if defined(MPT_FRAMEWORK_ASSERT_IS_DEFINED) && (MPT_ASSERT_USE_FRAMEWORK == 1)
|
||||
|
||||
#define MPT_ASSERT_NOTREACHED() ASSERT(0)
|
||||
#define MPT_ASSERT(expr) ASSERT((expr))
|
||||
#define MPT_ASSERT_MSG(expr, msg) ASSERT((expr) && (msg))
|
||||
#if (MPT_FRAMEWORK_ASSERT_IS_ACTIVE == 1)
|
||||
#define MPT_ASSERT_ALWAYS(expr) ASSERT((expr))
|
||||
#define MPT_ASSERT_ALWAYS_MSG(expr, msg) ASSERT((expr) && (msg))
|
||||
#else
|
||||
#define MPT_ASSERT_ALWAYS(expr) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#define MPT_ASSERT_ALWAYS_MSG(expr, msg) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr, msg); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#ifndef MPT_ASSERT_HANDLER_NEEDED
|
||||
#define MPT_ASSERT_HANDLER_NEEDED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(NO_ASSERTS)
|
||||
|
||||
#define MPT_ASSERT_NOTREACHED() MPT_CHECKER_ASSUME(0)
|
||||
#define MPT_ASSERT(expr) MPT_CHECKER_ASSUME(expr)
|
||||
#define MPT_ASSERT_MSG(expr, msg) MPT_CHECKER_ASSUME(expr)
|
||||
#define MPT_ASSERT_ALWAYS(expr) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#define MPT_ASSERT_ALWAYS_MSG(expr, msg) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr, msg); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#ifndef MPT_ASSERT_HANDLER_NEEDED
|
||||
#define MPT_ASSERT_HANDLER_NEEDED
|
||||
#endif
|
||||
|
||||
#else // !NO_ASSERTS
|
||||
|
||||
#define MPT_ASSERT_NOTREACHED() do { if constexpr(!(0)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), "0"); } MPT_CHECKER_ASSUME(0); } while(0)
|
||||
#define MPT_ASSERT(expr) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#define MPT_ASSERT_MSG(expr, msg) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr, msg); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#define MPT_ASSERT_ALWAYS(expr) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#define MPT_ASSERT_ALWAYS_MSG(expr, msg) do { if(!(expr)) { OPENMPT_NAMESPACE::AssertHandler(MPT_SOURCE_LOCATION_CURRENT(), #expr, msg); } MPT_CHECKER_ASSUME(expr); } while(0)
|
||||
#ifndef MPT_ASSERT_HANDLER_NEEDED
|
||||
#define MPT_ASSERT_HANDLER_NEEDED
|
||||
#endif
|
||||
|
||||
#endif // NO_ASSERTS
|
||||
|
||||
|
||||
#if defined(MPT_ASSERT_HANDLER_NEEDED)
|
||||
// custom assert handler needed
|
||||
MPT_NOINLINE void AssertHandler(const mpt::source_location &loc, const char *expr, const char *msg=nullptr);
|
||||
#endif // MPT_ASSERT_HANDLER_NEEDED
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* mptBaseMacros.h
|
||||
* ---------------
|
||||
* Purpose: Basic assorted compiler-related helpers.
|
||||
* 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 "mpt/base/preprocessor.hpp"
|
||||
#include "mpt/base/compiletime_warning.hpp"
|
||||
#include "mpt/base/macros.hpp"
|
||||
|
||||
#if MPT_CXX_AT_LEAST(20)
|
||||
#include <version>
|
||||
#else // !C++20
|
||||
#include <array>
|
||||
#endif // C++20
|
||||
|
||||
#include <array>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
#define MPT_UNREFERENCED_PARAMETER(x) MPT_UNUSED(x)
|
||||
#define MPT_UNUSED_VARIABLE(x) MPT_UNUSED(x)
|
||||
|
||||
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
// warning LNK4221: no public symbols found; archive member will be inaccessible
|
||||
// There is no way to selectively disable linker warnings.
|
||||
// #pragma warning does not apply and a command line option does not exist.
|
||||
// Some options:
|
||||
// 1. Macro which generates a variable with a unique name for each file (which means we have to pass the filename to the macro)
|
||||
// 2. unnamed namespace containing any symbol (does not work for c++11 compilers because they actually have internal linkage now)
|
||||
// 3. An unused trivial inline function.
|
||||
// Option 3 does not actually solve the problem though, which leaves us with option 1.
|
||||
// In any case, for optimized builds, the linker will just remove the useless symbol.
|
||||
#define MPT_MSVC_WORKAROUND_LNK4221_CONCAT_DETAIL(x,y) x##y
|
||||
#define MPT_MSVC_WORKAROUND_LNK4221_CONCAT(x,y) MPT_MSVC_WORKAROUND_LNK4221_CONCAT_DETAIL(x,y)
|
||||
#define MPT_MSVC_WORKAROUND_LNK4221(x) int MPT_MSVC_WORKAROUND_LNK4221_CONCAT(mpt_msvc_workaround_lnk4221_,x) = 0;
|
||||
#endif
|
||||
|
||||
#ifndef MPT_MSVC_WORKAROUND_LNK4221
|
||||
#define MPT_MSVC_WORKAROUND_LNK4221(x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* mptBaseTypes.h
|
||||
* --------------
|
||||
* Purpose: Basic data type definitions.
|
||||
* 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 "mpt/base/check_platform.hpp"
|
||||
#include "mpt/base/float.hpp"
|
||||
#include "mpt/base/integer.hpp"
|
||||
#include "mpt/base/pointer.hpp"
|
||||
#include "mpt/base/size.hpp"
|
||||
#include "mpt/base/source_location.hpp"
|
||||
#include "openmpt/base/Types.hpp"
|
||||
|
||||
#include "mptBaseMacros.h"
|
||||
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
constexpr inline int8 int8_min = std::numeric_limits<int8>::min();
|
||||
constexpr inline int16 int16_min = std::numeric_limits<int16>::min();
|
||||
constexpr inline int32 int32_min = std::numeric_limits<int32>::min();
|
||||
constexpr inline int64 int64_min = std::numeric_limits<int64>::min();
|
||||
|
||||
constexpr inline int8 int8_max = std::numeric_limits<int8>::max();
|
||||
constexpr inline int16 int16_max = std::numeric_limits<int16>::max();
|
||||
constexpr inline int32 int32_max = std::numeric_limits<int32>::max();
|
||||
constexpr inline int64 int64_max = std::numeric_limits<int64>::max();
|
||||
|
||||
constexpr inline uint8 uint8_max = std::numeric_limits<uint8>::max();
|
||||
constexpr inline uint16 uint16_max = std::numeric_limits<uint16>::max();
|
||||
constexpr inline uint32 uint32_max = std::numeric_limits<uint32>::max();
|
||||
constexpr inline uint64 uint64_max = std::numeric_limits<uint64>::max();
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* mptBaseUtils.h
|
||||
* --------------
|
||||
* Purpose: Various useful utility functions.
|
||||
* 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 "mpt/base/algorithm.hpp"
|
||||
#include "mpt/base/arithmetic_shift.hpp"
|
||||
#include "mpt/base/array.hpp"
|
||||
#include "mpt/base/bit.hpp"
|
||||
#include "mpt/base/constexpr_throw.hpp"
|
||||
#include "mpt/base/detect_arch.hpp"
|
||||
#include "mpt/base/detect_compiler.hpp"
|
||||
#include "mpt/base/math.hpp"
|
||||
#include "mpt/base/memory.hpp"
|
||||
#include "mpt/base/numeric.hpp"
|
||||
#include "mpt/base/saturate_cast.hpp"
|
||||
#include "mpt/base/saturate_round.hpp"
|
||||
#include "mpt/base/utility.hpp"
|
||||
#include "mpt/base/wrapping_divide.hpp"
|
||||
|
||||
#include "mptBaseMacros.h"
|
||||
#include "mptBaseTypes.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline void Clear(T& x)
|
||||
{
|
||||
static_assert(!std::is_pointer<T>::value);
|
||||
mpt::reset(x);
|
||||
}
|
||||
|
||||
|
||||
// Memset given object to zero.
|
||||
template <class T>
|
||||
inline void MemsetZero(T& a)
|
||||
{
|
||||
static_assert(std::is_pointer<T>::value == false, "Won't memset pointers.");
|
||||
mpt::memclear(a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Limits 'val' to given range. If 'val' is less than 'lowerLimit', 'val' is set to value 'lowerLimit'.
|
||||
// Similarly if 'val' is greater than 'upperLimit', 'val' is set to value 'upperLimit'.
|
||||
// If 'lowerLimit' > 'upperLimit', 'val' won't be modified.
|
||||
template<class T, class C>
|
||||
inline void Limit(T& val, const C lowerLimit, const C upperLimit)
|
||||
{
|
||||
if(lowerLimit > upperLimit) return;
|
||||
if(val < lowerLimit) val = lowerLimit;
|
||||
else if(val > upperLimit) val = upperLimit;
|
||||
}
|
||||
|
||||
|
||||
// Like Limit, but returns value
|
||||
template<class T, class C>
|
||||
inline T Clamp(T val, const C lowerLimit, const C upperLimit)
|
||||
{
|
||||
if(val < lowerLimit) return lowerLimit;
|
||||
else if(val > upperLimit) return upperLimit;
|
||||
else return val;
|
||||
}
|
||||
|
||||
// Like Limit, but with upperlimit only.
|
||||
template<class T, class C>
|
||||
inline void LimitMax(T& val, const C upperLimit)
|
||||
{
|
||||
if(val > upperLimit)
|
||||
val = upperLimit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace Util
|
||||
{
|
||||
|
||||
// Returns maximum value of given integer type.
|
||||
template <class T> constexpr T MaxValueOfType(const T&) {static_assert(std::numeric_limits<T>::is_integer == true, "Only integer types are allowed."); return (std::numeric_limits<T>::max)();}
|
||||
|
||||
} // namespace Util
|
||||
|
||||
|
||||
|
||||
namespace Util {
|
||||
|
||||
// Multiply two 32-bit integers, receive 64-bit result.
|
||||
// MSVC generates unnecessarily complicated code for the unoptimized variant using _allmul.
|
||||
MPT_CONSTEXPR20_FUN int64 mul32to64(int32 a, int32 b)
|
||||
{
|
||||
#if MPT_COMPILER_MSVC && (MPT_ARCH_X86 || MPT_ARCH_AMD64)
|
||||
MPT_MAYBE_CONSTANT_IF(MPT_IS_CONSTANT_EVALUATED20())
|
||||
{
|
||||
return static_cast<int64>(a) * b;
|
||||
} else
|
||||
{
|
||||
return __emul(a, b);
|
||||
}
|
||||
#else
|
||||
return static_cast<int64>(a) * b;
|
||||
#endif
|
||||
}
|
||||
|
||||
MPT_CONSTEXPR20_FUN uint64 mul32to64_unsigned(uint32 a, uint32 b)
|
||||
{
|
||||
#if MPT_COMPILER_MSVC && (MPT_ARCH_X86 || MPT_ARCH_AMD64)
|
||||
MPT_MAYBE_CONSTANT_IF(MPT_IS_CONSTANT_EVALUATED20())
|
||||
{
|
||||
return static_cast<uint64>(a) * b;
|
||||
} else
|
||||
{
|
||||
return __emulu(a, b);
|
||||
}
|
||||
#else
|
||||
return static_cast<uint64>(a) * b;
|
||||
#endif
|
||||
}
|
||||
|
||||
MPT_CONSTEXPR20_FUN int32 muldiv(int32 a, int32 b, int32 c)
|
||||
{
|
||||
return mpt::saturate_cast<int32>( mul32to64( a, b ) / c );
|
||||
}
|
||||
|
||||
MPT_CONSTEXPR20_FUN int32 muldivr(int32 a, int32 b, int32 c)
|
||||
{
|
||||
return mpt::saturate_cast<int32>( ( mul32to64( a, b ) + ( c / 2 ) ) / c );
|
||||
}
|
||||
|
||||
// Do not use overloading because catching unsigned version by accident results in slower X86 code.
|
||||
MPT_CONSTEXPR20_FUN uint32 muldiv_unsigned(uint32 a, uint32 b, uint32 c)
|
||||
{
|
||||
return mpt::saturate_cast<uint32>( mul32to64_unsigned( a, b ) / c );
|
||||
}
|
||||
MPT_CONSTEXPR20_FUN uint32 muldivr_unsigned(uint32 a, uint32 b, uint32 c)
|
||||
{
|
||||
return mpt::saturate_cast<uint32>( ( mul32to64_unsigned( a, b ) + ( c / 2u ) ) / c );
|
||||
}
|
||||
|
||||
constexpr MPT_FORCEINLINE int32 muldivrfloor(int64 a, uint32 b, uint32 c)
|
||||
{
|
||||
a *= b;
|
||||
a += c / 2u;
|
||||
return (a >= 0) ? mpt::saturate_cast<int32>(a / c) : mpt::saturate_cast<int32>((a - (c - 1)) / c);
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* mptCPU.h
|
||||
* --------
|
||||
* Purpose: CPU feature detection.
|
||||
* 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 "mpt/base/macros.hpp"
|
||||
#ifdef MPT_ENABLE_ARCH_INTRINSICS
|
||||
#include "mpt/arch/arch.hpp"
|
||||
#endif
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace CPU
|
||||
{
|
||||
|
||||
|
||||
#ifdef MPT_ENABLE_ARCH_INTRINSICS
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT)
|
||||
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
inline MPT_CONSTINIT mpt::arch::current::feature_flags EnabledFeatures;
|
||||
inline MPT_CONSTINIT mpt::arch::current::mode_flags EnabledModes;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline void EnableAvailableFeatures() noexcept
|
||||
{
|
||||
CPU::detail::EnabledFeatures = mpt::arch::get_cpu_info().get_features();
|
||||
CPU::detail::EnabledModes = mpt::arch::get_cpu_info().get_modes();
|
||||
}
|
||||
|
||||
// enabled processor features for inline asm and intrinsics
|
||||
[[nodiscard]] MPT_FORCEINLINE mpt::arch::current::feature_flags GetEnabledFeatures() noexcept
|
||||
{
|
||||
return CPU::detail::EnabledFeatures;
|
||||
}
|
||||
[[nodiscard]] MPT_FORCEINLINE mpt::arch::current::mode_flags GetEnabledModes() noexcept
|
||||
{
|
||||
return CPU::detail::EnabledModes;
|
||||
}
|
||||
|
||||
struct Info
|
||||
{
|
||||
[[nodiscard]] MPT_FORCEINLINE bool HasFeatureSet(mpt::arch::current::feature_flags features) const noexcept
|
||||
{
|
||||
return features == (GetEnabledFeatures() & features);
|
||||
}
|
||||
[[nodiscard]] MPT_FORCEINLINE bool HasModesEnabled(mpt::arch::current::mode_flags modes) const noexcept
|
||||
{
|
||||
return modes == (GetEnabledModes() & modes);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#else // !MODPLUG_TRACKER
|
||||
|
||||
|
||||
struct Info
|
||||
{
|
||||
private:
|
||||
const mpt::arch::flags_cache m_flags{mpt::arch::get_cpu_info()};
|
||||
public:
|
||||
[[nodiscard]] MPT_FORCEINLINE bool HasFeatureSet(mpt::arch::current::feature_flags features) const noexcept
|
||||
{
|
||||
return m_flags[features];
|
||||
}
|
||||
[[nodiscard]] MPT_FORCEINLINE bool HasModesEnabled(mpt::arch::current::mode_flags modes) const noexcept
|
||||
{
|
||||
return m_flags[modes];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
namespace feature = mpt::arch::current::feature;
|
||||
namespace mode = mpt::arch::current::mode;
|
||||
|
||||
[[nodiscard]] MPT_FORCEINLINE bool HasFeatureSet(mpt::arch::current::feature_flags features) noexcept
|
||||
{
|
||||
return CPU::Info{}.HasFeatureSet(features);
|
||||
}
|
||||
|
||||
[[nodiscard]] MPT_FORCEINLINE bool HasModesEnabled(mpt::arch::current::mode_flags modes) noexcept
|
||||
{
|
||||
return CPU::Info{}.HasModesEnabled(modes);
|
||||
}
|
||||
|
||||
|
||||
#endif // MPT_ENABLE_ARCH_INTRINSICS
|
||||
|
||||
|
||||
} // namespace CPU
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* mptFileIO.h
|
||||
* -----------
|
||||
* Purpose:
|
||||
* Notes : You should only ever use these wrappers instead of plain std::fstream classes.
|
||||
* 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"
|
||||
|
||||
#if defined(MPT_ENABLE_FILEIO)
|
||||
|
||||
#include "mpt/io_file_read/inputfile_filecursor.hpp"
|
||||
|
||||
#include "../common/mptPathString.h"
|
||||
#include "../common/FileReaderFwd.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#endif // MPT_ENABLE_FILEIO
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
#if defined(MPT_ENABLE_FILEIO)
|
||||
|
||||
|
||||
template <typename Targ1>
|
||||
inline FileCursor GetFileReader(Targ1 &&arg1)
|
||||
{
|
||||
return mpt::IO::make_FileCursor<mpt::PathString>(std::forward<Targ1>(arg1));
|
||||
}
|
||||
|
||||
|
||||
template <typename Targ1, typename Targ2>
|
||||
inline FileCursor GetFileReader(Targ1 &&arg1, Targ2 &&arg2)
|
||||
{
|
||||
return mpt::IO::make_FileCursor<mpt::PathString>(std::forward<Targ1>(arg1), std::forward<Targ2>(arg2));
|
||||
}
|
||||
|
||||
|
||||
#endif // MPT_ENABLE_FILEIO
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* mptFileTemporary.h
|
||||
* ------------------
|
||||
* Purpose:
|
||||
* 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 "mpt/base/namespace.hpp"
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
|
||||
#include "mpt/fs/common_directories.hpp"
|
||||
#include "mpt/fs/fs.hpp"
|
||||
#include "mpt/io_file_unique/unique_basename.hpp"
|
||||
#include "mpt/io_file_unique/unique_tempfilename.hpp"
|
||||
#include "mpt/uuid/uuid.hpp"
|
||||
|
||||
#include "mptPathString.h"
|
||||
#include "mptRandom.h"
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#endif // MODPLUG_TRACKER && MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
// Returns a new unique absolute path.
|
||||
class TemporaryPathname
|
||||
{
|
||||
private:
|
||||
mpt::PathString m_Path;
|
||||
public:
|
||||
TemporaryPathname(const mpt::PathString &fileNameExtension = P_("tmp"))
|
||||
{
|
||||
mpt::PathString prefix;
|
||||
#if defined(LIBOPENMPT_BUILD)
|
||||
prefix = P_("libopenmpt");
|
||||
#else
|
||||
prefix = P_("OpenMPT");
|
||||
#endif
|
||||
m_Path = mpt::PathString::FromNative(mpt::IO::unique_tempfilename{mpt::IO::unique_basename{prefix, mpt::UUID::GenerateLocalUseOnly(mpt::global_prng())}, fileNameExtension});
|
||||
}
|
||||
public:
|
||||
mpt::PathString GetPathname() const
|
||||
{
|
||||
return m_Path;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Scoped temporary file guard. Deletes the file when going out of scope.
|
||||
// The file itself is not created automatically.
|
||||
class TempFileGuard
|
||||
{
|
||||
private:
|
||||
const mpt::PathString filename;
|
||||
public:
|
||||
TempFileGuard(const mpt::TemporaryPathname &pathname = mpt::TemporaryPathname{})
|
||||
: filename(pathname.GetPathname())
|
||||
{
|
||||
return;
|
||||
}
|
||||
mpt::PathString GetFilename() const
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
~TempFileGuard()
|
||||
{
|
||||
if(!filename.empty())
|
||||
{
|
||||
DeleteFile(mpt::support_long_path(filename.AsNative()).c_str());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Scoped temporary directory guard. Deletes the directory when going out of scope.
|
||||
// The directory itself is created automatically.
|
||||
class TempDirGuard
|
||||
{
|
||||
private:
|
||||
mpt::PathString dirname;
|
||||
public:
|
||||
TempDirGuard(const mpt::TemporaryPathname &pathname = mpt::TemporaryPathname{})
|
||||
: dirname(pathname.GetPathname().WithTrailingSlash())
|
||||
{
|
||||
if(dirname.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(::CreateDirectory(mpt::support_long_path(dirname.AsNative()).c_str(), NULL) == 0)
|
||||
{ // fail
|
||||
dirname = mpt::PathString();
|
||||
}
|
||||
}
|
||||
mpt::PathString GetDirname() const
|
||||
{
|
||||
return dirname;
|
||||
}
|
||||
~TempDirGuard()
|
||||
{
|
||||
if(!dirname.empty())
|
||||
{
|
||||
mpt::native_fs{}.delete_tree(dirname);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER && MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* mptFileType.cpp
|
||||
* ---------------
|
||||
* Purpose:
|
||||
* Notes : Currently none.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "mptFileType.h"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
#ifdef MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
mpt::PathString FileType::AsFilterString(FlagSet<FileTypeFormat> format) const
|
||||
{
|
||||
mpt::PathString filter;
|
||||
if(GetShortName().empty() || GetExtensions().empty())
|
||||
{
|
||||
return filter;
|
||||
}
|
||||
if(!GetDescription().empty())
|
||||
{
|
||||
filter += mpt::PathString::FromUnicode(GetDescription());
|
||||
} else
|
||||
{
|
||||
filter += mpt::PathString::FromUnicode(GetShortName());
|
||||
}
|
||||
const auto extensions = GetExtensions();
|
||||
if(format[FileTypeFormatShowExtensions])
|
||||
{
|
||||
filter += P_(" (");
|
||||
bool first = true;
|
||||
for(const auto &ext : extensions)
|
||||
{
|
||||
if(first)
|
||||
{
|
||||
first = false;
|
||||
} else
|
||||
{
|
||||
filter += P_(",");
|
||||
}
|
||||
filter += P_("*.");
|
||||
filter += ext;
|
||||
}
|
||||
filter += P_(")");
|
||||
}
|
||||
filter += P_("|");
|
||||
{
|
||||
bool first = true;
|
||||
for(const auto &ext : extensions)
|
||||
{
|
||||
if(first)
|
||||
{
|
||||
first = false;
|
||||
} else
|
||||
{
|
||||
filter += P_(";");
|
||||
}
|
||||
filter += P_("*.");
|
||||
filter += ext;
|
||||
}
|
||||
}
|
||||
filter += P_("|");
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
mpt::PathString FileType::AsFilterOnlyString() const
|
||||
{
|
||||
mpt::PathString filter;
|
||||
const auto extensions = GetExtensions();
|
||||
{
|
||||
bool first = true;
|
||||
for(const auto &ext : extensions)
|
||||
{
|
||||
if(first)
|
||||
{
|
||||
first = false;
|
||||
} else
|
||||
{
|
||||
filter += P_(";");
|
||||
}
|
||||
filter += P_("*.");
|
||||
filter += ext;
|
||||
}
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
mpt::PathString ToFilterString(const FileType &fileType, FlagSet<FileTypeFormat> format)
|
||||
{
|
||||
return fileType.AsFilterString(format);
|
||||
}
|
||||
|
||||
|
||||
mpt::PathString ToFilterString(const std::vector<FileType> &fileTypes, FlagSet<FileTypeFormat> format)
|
||||
{
|
||||
mpt::PathString filter;
|
||||
for(const auto &type : fileTypes)
|
||||
{
|
||||
filter += type.AsFilterString(format);
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
|
||||
mpt::PathString ToFilterOnlyString(const FileType &fileType, bool prependSemicolonWhenNotEmpty)
|
||||
{
|
||||
mpt::PathString filter = fileType.AsFilterOnlyString();
|
||||
return filter.empty() ? filter : (prependSemicolonWhenNotEmpty ? P_(";") : P_("")) + filter;
|
||||
}
|
||||
|
||||
|
||||
mpt::PathString ToFilterOnlyString(const std::vector<FileType> &fileTypes, bool prependSemicolonWhenNotEmpty)
|
||||
{
|
||||
mpt::PathString filter;
|
||||
for(const auto &type : fileTypes)
|
||||
{
|
||||
filter += type.AsFilterOnlyString();
|
||||
}
|
||||
return filter.empty() ? filter : (prependSemicolonWhenNotEmpty ? P_(";") : P_("")) + filter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else
|
||||
MPT_MSVC_WORKAROUND_LNK4221(mptFileType)
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* mptFileType.h
|
||||
* -------------
|
||||
* Purpose:
|
||||
* 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 "mpt/base/alloc.hpp"
|
||||
#include "mpt/base/namespace.hpp"
|
||||
#include "mpt/string/types.hpp"
|
||||
|
||||
#include "openmpt/base/FlagSet.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
enum FileTypeFormat
|
||||
{
|
||||
FileTypeFormatNone = 0 , // do not show extensions after description, i.e. "Foo Files"
|
||||
FileTypeFormatShowExtensions = 1<<0, // show extensions after descripten, i.e. "Foo Files (*.foo,*.bar)"
|
||||
};
|
||||
MPT_DECLARE_ENUM(FileTypeFormat)
|
||||
|
||||
class FileType
|
||||
{
|
||||
private:
|
||||
mpt::ustring m_ShortName; // "flac", "mod" (lowercase)
|
||||
mpt::ustring m_Description; // "FastTracker 2 Module"
|
||||
std::vector<std::string> m_MimeTypes; // "audio/ogg" (in ASCII)
|
||||
std::vector<mpt::PathString> m_Extensions; // "mod", "xm" (lowercase)
|
||||
std::vector<mpt::PathString> m_Prefixes; // "mod" for "mod.*"
|
||||
public:
|
||||
FileType() { }
|
||||
FileType(const std::vector<FileType> &group)
|
||||
{
|
||||
for(const auto &type : group)
|
||||
{
|
||||
mpt::append(m_MimeTypes, type.m_MimeTypes);
|
||||
mpt::append(m_Extensions, type.m_Extensions);
|
||||
mpt::append(m_Prefixes, type.m_Prefixes);
|
||||
}
|
||||
}
|
||||
static FileType Any()
|
||||
{
|
||||
return FileType().ShortName(U_("*")).Description(U_("All Files")).AddExtension(P_("*"));
|
||||
}
|
||||
public:
|
||||
FileType& ShortName(const mpt::ustring &shortName) { m_ShortName = shortName; return *this; }
|
||||
FileType& Description(const mpt::ustring &description) { m_Description = description; return *this; }
|
||||
FileType& MimeTypes(const std::vector<std::string> &mimeTypes) { m_MimeTypes = mimeTypes; return *this; }
|
||||
FileType& Extensions(const std::vector<mpt::PathString> &extensions) { m_Extensions = extensions; return *this; }
|
||||
FileType& Prefixes(const std::vector<mpt::PathString> &prefixes) { m_Prefixes = prefixes; return *this; }
|
||||
FileType& AddMimeType(const std::string &mimeType) { m_MimeTypes.push_back(mimeType); return *this; }
|
||||
FileType& AddExtension(const mpt::PathString &extension) { m_Extensions.push_back(extension); return *this; }
|
||||
FileType& AddPrefix(const mpt::PathString &prefix) { m_Prefixes.push_back(prefix); return *this; }
|
||||
public:
|
||||
mpt::ustring GetShortName() const { return m_ShortName; }
|
||||
mpt::ustring GetDescription() const { return m_Description; }
|
||||
std::vector<std::string> GetMimeTypes() const { return m_MimeTypes; }
|
||||
std::vector<mpt::PathString> GetExtensions() const { return m_Extensions; }
|
||||
std::vector<mpt::PathString> GetPrefixes() const { return m_Prefixes; }
|
||||
public:
|
||||
mpt::PathString AsFilterString(FlagSet<FileTypeFormat> format = FileTypeFormatNone) const;
|
||||
mpt::PathString AsFilterOnlyString() const;
|
||||
}; // class FileType
|
||||
|
||||
|
||||
// "Ogg Vorbis|*.ogg;*.oga|" // FileTypeFormatNone
|
||||
// "Ogg Vorbis (*.ogg,*.oga)|*.ogg;*.oga|" // FileTypeFormatShowExtensions
|
||||
mpt::PathString ToFilterString(const FileType &fileType, FlagSet<FileTypeFormat> format = FileTypeFormatNone);
|
||||
mpt::PathString ToFilterString(const std::vector<FileType> &fileTypes, FlagSet<FileTypeFormat> format = FileTypeFormatNone);
|
||||
|
||||
// "*.ogg;*.oga" / ";*.ogg;*.oga"
|
||||
mpt::PathString ToFilterOnlyString(const FileType &fileType, bool prependSemicolonWhenNotEmpty = false);
|
||||
mpt::PathString ToFilterOnlyString(const std::vector<FileType> &fileTypes, bool prependSemicolonWhenNotEmpty = false);
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* mptPathString.cpp
|
||||
* -----------------
|
||||
* Purpose: Wrapper class around the platform-native representation of path names. Should be the only type that is used to store path names.
|
||||
* Notes : Currently none.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "mptPathString.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
#include <tchar.h>
|
||||
#endif
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
// Convert an absolute path to a path that's relative to "&relativeTo".
|
||||
mpt::PathString AbsolutePathToRelative(const mpt::PathString &path, const mpt::PathString &relativeTo)
|
||||
{
|
||||
using namespace path_literals;
|
||||
using char_type = RawPathString::value_type;
|
||||
mpt::PathString result = path;
|
||||
if(path.empty() || relativeTo.empty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if(!_tcsncicmp(relativeTo.AsNative().c_str(), path.AsNative().c_str(), relativeTo.AsNative().length()))
|
||||
{
|
||||
// Path is OpenMPT's directory or a sub directory ("C:\OpenMPT\Somepath" => ".\Somepath")
|
||||
result = mpt::PathString::FromNative(L<char_type>(".\\")); // ".\"
|
||||
result += mpt::PathString::FromNative(path.AsNative().substr(relativeTo.AsNative().length()));
|
||||
} else if(!_tcsncicmp(relativeTo.AsNative().c_str(), path.AsNative().c_str(), 2))
|
||||
{
|
||||
// Path is on the same drive as OpenMPT ("C:\Somepath" => "\Somepath")
|
||||
result = mpt::PathString::FromNative(path.AsNative().substr(2));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Convert a path that is relative to "&relativeTo" to an absolute path.
|
||||
mpt::PathString RelativePathToAbsolute(const mpt::PathString &path, const mpt::PathString &relativeTo)
|
||||
{
|
||||
using namespace path_literals;
|
||||
using char_type = RawPathString::value_type;
|
||||
mpt::PathString result = path;
|
||||
if(path.empty() || relativeTo.empty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if(path.length() >= 2 && path.AsNative()[0] == L<char_type>('\\') && path.AsNative()[1] == L<char_type>('\\'))
|
||||
{
|
||||
// Network / UNC paths
|
||||
return result;
|
||||
} if(path.length() >= 1 && path.AsNative()[0] == L<char_type>('\\'))
|
||||
{
|
||||
// Path is on the same drive as relativeTo ("\Somepath\" => "C:\Somepath\")
|
||||
result = mpt::PathString::FromNative(relativeTo.AsNative().substr(0, 2));
|
||||
result += mpt::PathString(path);
|
||||
} else if(path.length() >= 2 && path.AsNative().substr(0, 2) == L<char_type>(".\\"))
|
||||
{
|
||||
// Path is in relativeTo or a sub directory (".\Somepath\" => "C:\OpenMPT\Somepath\")
|
||||
result = relativeTo; // "C:\OpenMPT\"
|
||||
result += mpt::PathString::FromNative(path.AsNative().substr(2));
|
||||
} else if(path.length() < 3 || path.AsNative()[1] != L<char_type>(':') || path.AsNative()[2] != L<char_type>('\\'))
|
||||
{
|
||||
// Any other path not starting with drive letter
|
||||
result = relativeTo; // "C:\OpenMPT\"
|
||||
result += mpt::PathString(path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER && MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* mptPathString.h
|
||||
* ---------------
|
||||
* Purpose: Wrapper class around the platform-native representation of path names. Should be the only type that is used to store path names.
|
||||
* 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 "mpt/base/detect.hpp"
|
||||
#include "mpt/base/namespace.hpp"
|
||||
#include "mpt/path/basic_path.hpp"
|
||||
#include "mpt/path/native_path.hpp"
|
||||
#include "mpt/path/os_path.hpp"
|
||||
#include "mpt/string/types.hpp"
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include "mpt/string_transcode/transcode.hpp"
|
||||
#endif
|
||||
|
||||
#include "mptString.h"
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
|
||||
using PathString = mpt::native_path;
|
||||
|
||||
#define MPT_PATHSTRING_LITERAL(x) MPT_OS_PATH_LITERAL( x )
|
||||
#define MPT_PATHSTRING(x) mpt::PathString::FromNative(MPT_OS_PATH_LITERAL( x ))
|
||||
|
||||
#else // !MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
using PathString = mpt::BasicPathString<mpt::Utf8PathTraits, false>;
|
||||
|
||||
#define MPT_PATHSTRING_LITERAL(x) ( x )
|
||||
#define MPT_PATHSTRING(x) mpt::PathString::FromNative( x )
|
||||
|
||||
#endif // MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
using RawPathString = PathString::raw_path_type;
|
||||
|
||||
#define PC_(x) MPT_PATHSTRING_LITERAL(x)
|
||||
#define PL_(x) MPT_PATHSTRING_LITERAL(x)
|
||||
#define P_(x) MPT_PATHSTRING(x)
|
||||
|
||||
|
||||
|
||||
template <typename T, typename std::enable_if<std::is_same<T, mpt::PathString>::value, bool>::type = true>
|
||||
inline mpt::ustring ToUString(const T &x)
|
||||
{
|
||||
return x.ToUnicode();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
// Relative / absolute paths conversion
|
||||
|
||||
mpt::PathString AbsolutePathToRelative(const mpt::PathString &p, const mpt::PathString &relativeTo); // similar to std::fs::path::lexically_approximate
|
||||
|
||||
mpt::PathString RelativePathToAbsolute(const mpt::PathString &p, const mpt::PathString &relativeTo);
|
||||
|
||||
|
||||
|
||||
#if !MPT_OS_WINDOWS_WINRT
|
||||
inline int PathCompareNoCase(const PathString &a, const PathString &b)
|
||||
{
|
||||
return lstrcmpi(a.AsNative().c_str(), b.AsNative().c_str());
|
||||
}
|
||||
#endif // !MPT_OS_WINDOWS_WINRT
|
||||
|
||||
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
|
||||
|
||||
template <typename Tstring>
|
||||
inline Tstring SanitizePathComponent(const Tstring &str)
|
||||
{
|
||||
return mpt::transcode<Tstring>(mpt::native_path::FromNative(mpt::transcode<mpt::native_path::raw_path_type>(str)).AsSanitizedComponent().AsNative());
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* mptRandom.cpp
|
||||
* -------------
|
||||
* Purpose: PRNG
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "mptRandom.h"
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT)
|
||||
|
||||
static mpt::random_device *g_rd = nullptr;
|
||||
static mpt::thread_safe_prng<mpt::default_prng> *g_global_prng = nullptr;
|
||||
|
||||
void set_global_random_device(mpt::random_device *rd)
|
||||
{
|
||||
g_rd = rd;
|
||||
}
|
||||
|
||||
void set_global_prng(mpt::thread_safe_prng<mpt::default_prng> *prng)
|
||||
{
|
||||
g_global_prng = prng;
|
||||
}
|
||||
|
||||
mpt::random_device & global_random_device()
|
||||
{
|
||||
return *g_rd;
|
||||
}
|
||||
|
||||
mpt::thread_safe_prng<mpt::default_prng> & global_prng()
|
||||
{
|
||||
return *g_global_prng;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
mpt::random_device & global_random_device()
|
||||
{
|
||||
#if MPT_COMPILER_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
#endif // MPT_COMPILER_CLANG
|
||||
static mpt::random_device g_rd;
|
||||
#if MPT_COMPILER_CLANG
|
||||
#pragma clang diagnostic pop
|
||||
#endif // MPT_COMPILER_CLANG
|
||||
return g_rd;
|
||||
}
|
||||
|
||||
mpt::thread_safe_prng<mpt::default_prng> & global_prng()
|
||||
{
|
||||
#if MPT_COMPILER_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
#endif // MPT_COMPILER_CLANG
|
||||
static mpt::thread_safe_prng<mpt::default_prng> g_global_prng(mpt::make_prng<mpt::default_prng>(global_random_device()));
|
||||
#if MPT_COMPILER_CLANG
|
||||
#pragma clang diagnostic pop
|
||||
#endif // MPT_COMPILER_CLANG
|
||||
return g_global_prng;
|
||||
}
|
||||
|
||||
#ifdef MPT_BUILD_FUZZER
|
||||
void reinit_global_random()
|
||||
{
|
||||
global_prng().~thread_safe_prng<mpt::default_prng>();
|
||||
global_random_device().~random_device();
|
||||
new(&global_random_device()) mpt::random_device{};
|
||||
new(&global_prng()) thread_safe_prng<mpt::default_prng>{global_random_device()};
|
||||
}
|
||||
#endif // MPT_BUILD_FUZZER
|
||||
|
||||
#endif // MODPLUG_TRACKER && !MPT_BUILD_WINESUPPORT
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* mptRandom.h
|
||||
* -----------
|
||||
* Purpose: PRNG
|
||||
* 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 "mpt/base/bit.hpp"
|
||||
#include "mpt/mutex/mutex.hpp"
|
||||
#ifdef MODPLUG_TRACKER
|
||||
#include "mpt/random/crand.hpp"
|
||||
#endif // MODPLUG_TRACKER
|
||||
#include "mpt/random/default_engines.hpp"
|
||||
#include "mpt/random/device.hpp"
|
||||
#include "mpt/random/engine.hpp"
|
||||
#include "mpt/random/engine_lcg.hpp"
|
||||
#include "mpt/random/seed.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <random>
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
// NOTE:
|
||||
// We implement our own PRNG and distribution functions as the implementations
|
||||
// of std::uniform_int_distribution is either wrong (not uniform in MSVC2010) or
|
||||
// not guaranteed to be livelock-free for bad PRNGs (in GCC, Clang, boost).
|
||||
// We resort to a simpler implementation with only power-of-2 result ranges for
|
||||
// both the underlying PRNG and our interface function. This saves us from
|
||||
// complicated code having to deal with partial bits of entropy.
|
||||
// Our interface still somewhat follows the mindset of C++11 <random> (with the
|
||||
// addition of a simple wrapper function mpt::random which saves the caller from
|
||||
// instantiating distribution objects for the common uniform distribution case.
|
||||
// We are still using std::random_device for initial seeding when avalable and
|
||||
// after working around its set of problems.
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
|
||||
template <typename Trng>
|
||||
class thread_safe_prng
|
||||
: private Trng
|
||||
{
|
||||
private:
|
||||
mpt::mutex m;
|
||||
public:
|
||||
using result_type = typename Trng::result_type;
|
||||
public:
|
||||
template <typename Trd>
|
||||
explicit thread_safe_prng(Trd & rd)
|
||||
: Trng(mpt::make_prng<Trng>(rd))
|
||||
{
|
||||
return;
|
||||
}
|
||||
thread_safe_prng(Trng rng)
|
||||
: Trng(rng)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public:
|
||||
static MPT_CONSTEXPRINLINE typename engine_traits<Trng>::result_type min()
|
||||
{
|
||||
return Trng::min();
|
||||
}
|
||||
static MPT_CONSTEXPRINLINE typename engine_traits<Trng>::result_type max()
|
||||
{
|
||||
return Trng::max();
|
||||
}
|
||||
static MPT_CONSTEXPRINLINE int result_bits()
|
||||
{
|
||||
return engine_traits<Trng>::result_bits();
|
||||
}
|
||||
public:
|
||||
typename engine_traits<Trng>::result_type operator()()
|
||||
{
|
||||
mpt::lock_guard<mpt::mutex> l(m);
|
||||
return Trng::operator()();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifdef MPT_BUILD_FUZZER
|
||||
|
||||
// Use deterministic seeding
|
||||
using random_device = deterministic_random_device;
|
||||
|
||||
#else // !MPT_BUILD_FUZZER
|
||||
|
||||
// mpt::random_device always generates 32 bits of entropy
|
||||
using random_device = mpt::sane_random_device;
|
||||
|
||||
#endif // MPT_BUILD_FUZZER
|
||||
|
||||
|
||||
#ifdef MPT_BUILD_FUZZER
|
||||
|
||||
// Use fast PRNGs in order to not waste time fuzzing more complex PRNG
|
||||
// implementations.
|
||||
using fast_prng = deterministic_fast_engine;
|
||||
using good_prng = deterministic_good_engine;
|
||||
|
||||
#else // !MPT_BUILD_FUZZER
|
||||
|
||||
// We cannot use std::minstd_rand here because it has not a power-of-2 sized
|
||||
// output domain which we rely upon.
|
||||
using fast_prng = fast_engine; // about 3 ALU operations, ~32bit of state, suited for inner loops
|
||||
using good_prng = good_engine;
|
||||
|
||||
#endif // MPT_BUILD_FUZZER
|
||||
|
||||
|
||||
using default_prng = mpt::good_prng;
|
||||
|
||||
|
||||
mpt::random_device & global_random_device();
|
||||
mpt::thread_safe_prng<mpt::default_prng> & global_prng();
|
||||
|
||||
#ifdef MPT_BUILD_FUZZER
|
||||
void reinit_global_random();
|
||||
#endif // MPT_BUILD_FUZZER
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_BUILD_WINESUPPORT)
|
||||
void set_global_random_device(mpt::random_device *rd);
|
||||
void set_global_prng(mpt::thread_safe_prng<mpt::default_prng> *rng);
|
||||
#endif // MODPLUG_TRACKER && !MPT_BUILD_WINESUPPORT
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,691 @@
|
||||
/*
|
||||
* mptString.h
|
||||
* ----------
|
||||
* Purpose: Small string-related utilities, number and message formatting.
|
||||
* 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 "mpt/string/types.hpp"
|
||||
#include "mpt/string/utility.hpp"
|
||||
#include "mpt/string_transcode/transcode.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include <cstddef>
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include <cwctype>
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
|
||||
enum class CharsetEnum {
|
||||
|
||||
UTF8,
|
||||
|
||||
ASCII, // strictly 7-bit ASCII
|
||||
|
||||
ISO8859_1,
|
||||
ISO8859_15,
|
||||
|
||||
CP437,
|
||||
CP737,
|
||||
CP775,
|
||||
CP850,
|
||||
CP852,
|
||||
CP855,
|
||||
CP857,
|
||||
CP860,
|
||||
CP861,
|
||||
CP862,
|
||||
CP863,
|
||||
CP864,
|
||||
CP865,
|
||||
CP866,
|
||||
CP869,
|
||||
CP874,
|
||||
|
||||
CP437AMS,
|
||||
CP437AMS2,
|
||||
|
||||
Windows1252,
|
||||
|
||||
Amiga,
|
||||
RISC_OS,
|
||||
AtariST,
|
||||
|
||||
ISO8859_1_no_C1,
|
||||
ISO8859_15_no_C1,
|
||||
Amiga_no_C1,
|
||||
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
Locale, // CP_ACP on windows, current C locale otherwise
|
||||
#endif // MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
};
|
||||
|
||||
namespace CharsetTable
|
||||
{
|
||||
|
||||
#define C(x) (mpt::char_value((x)))
|
||||
|
||||
// AMS1 actually only supports ASCII plus the modified control characters and no high chars at all.
|
||||
// Just default to CP437 for those to keep things simple.
|
||||
inline constexpr char32_t CP437AMS[256] = {
|
||||
C(' '),0x0001,0x0002,0x0003,0x00e4,0x0005,0x00e5,0x0007,0x0008,0x0009,0x000a,0x000b,0x000c,0x000d,0x00c4,0x00c5, // differs from CP437
|
||||
0x0010,0x0011,0x0012,0x0013,0x00f6,0x0015,0x0016,0x0017,0x0018,0x00d6,0x001a,0x001b,0x001c,0x001d,0x001e,0x001f, // differs from CP437
|
||||
0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
|
||||
0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
|
||||
0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
|
||||
0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
|
||||
0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
|
||||
0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x2302,
|
||||
0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5,
|
||||
0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20a7,0x0192,
|
||||
0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb,
|
||||
0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510,
|
||||
0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567,
|
||||
0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580,
|
||||
0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229,
|
||||
0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0
|
||||
};
|
||||
|
||||
// AMS2: Looking at Velvet Studio's bitmap font (TPIC32.PCX), these appear to be the only supported non-ASCII chars.
|
||||
inline constexpr char32_t CP437AMS2[256] = {
|
||||
C(' '),0x00a9,0x221a,0x00b7,C('0'),C('1'),C('2'),C('3'),C('4'),C('5'),C('6'),C('7'),C('8'),C('9'),C('A'),C('B'), // differs from CP437
|
||||
C('C'),C('D'),C('E'),C('F'),C(' '),0x00a7,C(' '),C(' '),C(' '),C(' '),C(' '),C(' '),C(' '),C(' '),C(' '),C(' '), // differs from CP437
|
||||
0x0020,0x0021,0x0022,0x0023,0x0024,0x0025,0x0026,0x0027,0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f,
|
||||
0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037,0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x003f,
|
||||
0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047,0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f,
|
||||
0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057,0x0058,0x0059,0x005a,0x005b,0x005c,0x005d,0x005e,0x005f,
|
||||
0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067,0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f,
|
||||
0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077,0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x2302,
|
||||
0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7,0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5,
|
||||
0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9,0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20a7,0x0192,
|
||||
0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba,0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb,
|
||||
0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556,0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510,
|
||||
0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f,0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567,
|
||||
0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b,0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580,
|
||||
0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x00b5,0x03c4,0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229,
|
||||
0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248,0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x00a0
|
||||
};
|
||||
|
||||
#undef C
|
||||
|
||||
} // namespace CharsetTable
|
||||
|
||||
|
||||
|
||||
struct CharsetTranscoder
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
CharsetEnum m_Charset;
|
||||
|
||||
public:
|
||||
|
||||
constexpr CharsetEnum GetCharset() const noexcept
|
||||
{
|
||||
return m_Charset;
|
||||
}
|
||||
|
||||
constexpr CharsetTranscoder(CharsetEnum charset) noexcept
|
||||
: m_Charset(charset)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr operator CharsetEnum() const noexcept
|
||||
{
|
||||
return m_Charset;
|
||||
}
|
||||
|
||||
// templated on 8bit strings because of type-safe variants
|
||||
template <typename Tdststring>
|
||||
inline Tdststring encode(const mpt::widestring &src) const
|
||||
{
|
||||
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char));
|
||||
static_assert(mpt::is_character<typename Tdststring::value_type>::value);
|
||||
switch(m_Charset)
|
||||
{
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
case CharsetEnum::Locale: return mpt::encode<Tdststring>(mpt::logical_encoding::locale, src); break;
|
||||
#endif
|
||||
case CharsetEnum::UTF8: return mpt::encode<Tdststring>(mpt::common_encoding::utf8, src); break;
|
||||
case CharsetEnum::ASCII: return mpt::encode<Tdststring>(mpt::common_encoding::ascii, src); break;
|
||||
case CharsetEnum::ISO8859_1: return mpt::encode<Tdststring>(mpt::common_encoding::iso8859_1, src); break;
|
||||
case CharsetEnum::ISO8859_15: return mpt::encode<Tdststring>(mpt::common_encoding::iso8859_15, src); break;
|
||||
case CharsetEnum::CP437: return mpt::encode<Tdststring>(mpt::common_encoding::cp437, src); break;
|
||||
case CharsetEnum::CP737: return mpt::encode<Tdststring>(mpt::common_encoding::cp737, src); break;
|
||||
case CharsetEnum::CP775: return mpt::encode<Tdststring>(mpt::common_encoding::cp775, src); break;
|
||||
case CharsetEnum::CP850: return mpt::encode<Tdststring>(mpt::common_encoding::cp850, src); break;
|
||||
case CharsetEnum::CP852: return mpt::encode<Tdststring>(mpt::common_encoding::cp852, src); break;
|
||||
case CharsetEnum::CP855: return mpt::encode<Tdststring>(mpt::common_encoding::cp855, src); break;
|
||||
case CharsetEnum::CP857: return mpt::encode<Tdststring>(mpt::common_encoding::cp857, src); break;
|
||||
case CharsetEnum::CP860: return mpt::encode<Tdststring>(mpt::common_encoding::cp860, src); break;
|
||||
case CharsetEnum::CP861: return mpt::encode<Tdststring>(mpt::common_encoding::cp861, src); break;
|
||||
case CharsetEnum::CP862: return mpt::encode<Tdststring>(mpt::common_encoding::cp862, src); break;
|
||||
case CharsetEnum::CP863: return mpt::encode<Tdststring>(mpt::common_encoding::cp863, src); break;
|
||||
case CharsetEnum::CP864: return mpt::encode<Tdststring>(mpt::common_encoding::cp864, src); break;
|
||||
case CharsetEnum::CP865: return mpt::encode<Tdststring>(mpt::common_encoding::cp865, src); break;
|
||||
case CharsetEnum::CP866: return mpt::encode<Tdststring>(mpt::common_encoding::cp866, src); break;
|
||||
case CharsetEnum::CP869: return mpt::encode<Tdststring>(mpt::common_encoding::cp869, src); break;
|
||||
case CharsetEnum::CP874: return mpt::encode<Tdststring>(mpt::common_encoding::cp874, src); break;
|
||||
case CharsetEnum::CP437AMS: return mpt::encode<Tdststring>(CharsetTable::CP437AMS, src); break;
|
||||
case CharsetEnum::CP437AMS2: return mpt::encode<Tdststring>(CharsetTable::CP437AMS2, src); break;
|
||||
case CharsetEnum::Windows1252: return mpt::encode<Tdststring>(mpt::common_encoding::windows1252, src); break;
|
||||
case CharsetEnum::Amiga: return mpt::encode<Tdststring>(mpt::common_encoding::amiga, src); break;
|
||||
case CharsetEnum::RISC_OS: return mpt::encode<Tdststring>(mpt::common_encoding::riscos, src); break;
|
||||
case CharsetEnum::AtariST: return mpt::encode<Tdststring>(mpt::common_encoding::atarist, src); break;
|
||||
case CharsetEnum::ISO8859_1_no_C1: return mpt::encode<Tdststring>(mpt::common_encoding::iso8859_1_no_c1, src); break;
|
||||
case CharsetEnum::ISO8859_15_no_C1: return mpt::encode<Tdststring>(mpt::common_encoding::iso8859_15_no_c1, src); break;
|
||||
case CharsetEnum::Amiga_no_C1: return mpt::encode<Tdststring>(mpt::common_encoding::amiga_no_c1, src); break;
|
||||
}
|
||||
return Tdststring();
|
||||
}
|
||||
|
||||
// templated on 8bit strings because of type-safe variants
|
||||
template <typename Tsrcstring>
|
||||
inline mpt::widestring decode(const Tsrcstring &src) const
|
||||
{
|
||||
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char));
|
||||
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value);
|
||||
switch(m_Charset)
|
||||
{
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
case CharsetEnum::Locale: return mpt::decode<Tsrcstring>(mpt::logical_encoding::locale, src); break;
|
||||
#endif
|
||||
case CharsetEnum::UTF8: return mpt::decode<Tsrcstring>(mpt::common_encoding::utf8, src); break;
|
||||
case CharsetEnum::ASCII: return mpt::decode<Tsrcstring>(mpt::common_encoding::ascii, src); break;
|
||||
case CharsetEnum::ISO8859_1: return mpt::decode<Tsrcstring>(mpt::common_encoding::iso8859_1, src); break;
|
||||
case CharsetEnum::ISO8859_15: return mpt::decode<Tsrcstring>(mpt::common_encoding::iso8859_15, src); break;
|
||||
case CharsetEnum::CP437: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp437, src); break;
|
||||
case CharsetEnum::CP737: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp737, src); break;
|
||||
case CharsetEnum::CP775: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp775, src); break;
|
||||
case CharsetEnum::CP850: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp850, src); break;
|
||||
case CharsetEnum::CP852: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp852, src); break;
|
||||
case CharsetEnum::CP855: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp855, src); break;
|
||||
case CharsetEnum::CP857: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp857, src); break;
|
||||
case CharsetEnum::CP860: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp860, src); break;
|
||||
case CharsetEnum::CP861: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp861, src); break;
|
||||
case CharsetEnum::CP862: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp862, src); break;
|
||||
case CharsetEnum::CP863: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp863, src); break;
|
||||
case CharsetEnum::CP864: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp864, src); break;
|
||||
case CharsetEnum::CP865: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp865, src); break;
|
||||
case CharsetEnum::CP866: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp866, src); break;
|
||||
case CharsetEnum::CP869: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp869, src); break;
|
||||
case CharsetEnum::CP874: return mpt::decode<Tsrcstring>(mpt::common_encoding::cp874, src); break;
|
||||
case CharsetEnum::CP437AMS: return mpt::decode<Tsrcstring>(CharsetTable::CP437AMS, src); break;
|
||||
case CharsetEnum::CP437AMS2: return mpt::decode<Tsrcstring>(CharsetTable::CP437AMS2, src); break;
|
||||
case CharsetEnum::Windows1252: return mpt::decode<Tsrcstring>(mpt::common_encoding::windows1252, src); break;
|
||||
case CharsetEnum::Amiga: return mpt::decode<Tsrcstring>(mpt::common_encoding::amiga, src); break;
|
||||
case CharsetEnum::RISC_OS: return mpt::decode<Tsrcstring>(mpt::common_encoding::riscos, src); break;
|
||||
case CharsetEnum::AtariST: return mpt::decode<Tsrcstring>(mpt::common_encoding::atarist, src); break;
|
||||
case CharsetEnum::ISO8859_1_no_C1: return mpt::decode<Tsrcstring>(mpt::common_encoding::iso8859_1_no_c1, src); break;
|
||||
case CharsetEnum::ISO8859_15_no_C1: return mpt::decode<Tsrcstring>(mpt::common_encoding::iso8859_15_no_c1, src); break;
|
||||
case CharsetEnum::Amiga_no_C1: return mpt::decode<Tsrcstring>(mpt::common_encoding::amiga_no_c1, src); break;
|
||||
}
|
||||
return mpt::widestring();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Charset
|
||||
: public CharsetTranscoder
|
||||
{
|
||||
|
||||
constexpr Charset(mpt::CharsetEnum charset) noexcept
|
||||
: CharsetTranscoder(charset)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr Charset(mpt::CharsetTranscoder charset) noexcept
|
||||
: CharsetTranscoder(charset.GetCharset())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static inline constexpr auto UTF8 = mpt::CharsetTranscoder{ mpt::CharsetEnum::UTF8 };
|
||||
static inline constexpr auto ASCII = mpt::CharsetTranscoder{ mpt::CharsetEnum::ASCII };
|
||||
static inline constexpr auto ISO8859_1 = mpt::CharsetTranscoder{ mpt::CharsetEnum::ISO8859_1 };
|
||||
static inline constexpr auto ISO8859_15 = mpt::CharsetTranscoder{ mpt::CharsetEnum::ISO8859_15 };
|
||||
static inline constexpr auto CP437 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP437 };
|
||||
static inline constexpr auto CP737 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP737 };
|
||||
static inline constexpr auto CP775 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP775 };
|
||||
static inline constexpr auto CP850 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP850 };
|
||||
static inline constexpr auto CP852 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP852 };
|
||||
static inline constexpr auto CP855 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP855 };
|
||||
static inline constexpr auto CP857 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP857 };
|
||||
static inline constexpr auto CP860 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP860 };
|
||||
static inline constexpr auto CP861 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP861 };
|
||||
static inline constexpr auto CP862 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP862 };
|
||||
static inline constexpr auto CP863 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP863 };
|
||||
static inline constexpr auto CP864 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP864 };
|
||||
static inline constexpr auto CP865 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP865 };
|
||||
static inline constexpr auto CP866 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP866 };
|
||||
static inline constexpr auto CP869 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP869 };
|
||||
static inline constexpr auto CP874 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP874 };
|
||||
static inline constexpr auto CP437AMS = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP437AMS };
|
||||
static inline constexpr auto CP437AMS2 = mpt::CharsetTranscoder{ mpt::CharsetEnum::CP437AMS2 };
|
||||
static inline constexpr auto Windows1252 = mpt::CharsetTranscoder{ mpt::CharsetEnum::Windows1252 };
|
||||
static inline constexpr auto Amiga = mpt::CharsetTranscoder{ mpt::CharsetEnum::Amiga };
|
||||
static inline constexpr auto RISC_OS = mpt::CharsetTranscoder{ mpt::CharsetEnum::RISC_OS };
|
||||
static inline constexpr auto AtariST = mpt::CharsetTranscoder{ mpt::CharsetEnum::AtariST };
|
||||
static inline constexpr auto ISO8859_1_no_C1 = mpt::CharsetTranscoder{ mpt::CharsetEnum::ISO8859_1_no_C1 };
|
||||
static inline constexpr auto ISO8859_15_no_C1 = mpt::CharsetTranscoder{ mpt::CharsetEnum::ISO8859_15_no_C1 };
|
||||
static inline constexpr auto Amiga_no_C1 = mpt::CharsetTranscoder{ mpt::CharsetEnum::Amiga_no_C1 };
|
||||
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
static inline constexpr auto Locale = mpt::CharsetTranscoder{ mpt::CharsetEnum::Locale };
|
||||
#endif // MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Checks if the std::string represents an UTF8 string.
|
||||
// This is currently implemented as converting to std::wstring and back assuming UTF8 both ways,
|
||||
// and comparing the result to the original string.
|
||||
// Caveats:
|
||||
// - can give false negatives because of possible unicode normalization during conversion
|
||||
// - can give false positives if the 8bit encoding contains high-ascii only in valid utf8 groups
|
||||
// - slow because of double conversion
|
||||
inline bool IsUTF8(const std::string &str)
|
||||
{
|
||||
return mpt::is_utf8(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename Tsrc>
|
||||
inline mpt::ustring ToUnicode(Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<mpt::ustring>(std::forward<Tsrc>(str));
|
||||
}
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline mpt::ustring ToUnicode(Tencoding &&from, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<mpt::ustring>(std::forward<Tencoding>(from), std::forward<Tsrc>(str));
|
||||
}
|
||||
|
||||
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
|
||||
// Convert to a wide character string.
|
||||
// The wide encoding is UTF-16 or UTF-32, based on sizeof(wchar_t).
|
||||
// If str does not contain any invalid characters, this conversion is lossless.
|
||||
// Invalid source bytes will be replaced by some replacement character or string.
|
||||
template <typename Tsrc>
|
||||
inline std::wstring ToWide(Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<std::wstring>(std::forward<Tsrc>(str));
|
||||
}
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline std::wstring ToWide(Tencoding &&from, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<std::wstring>(std::forward<Tencoding>(from), std::forward<Tsrc>(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Convert to a string encoded in the 'to'-specified character set.
|
||||
// If str does not contain any invalid characters,
|
||||
// this conversion will be lossless iff, and only iff,
|
||||
// 'to' is UTF8.
|
||||
// Invalid source bytes or characters that are not representable in the
|
||||
// destination charset will be replaced by some replacement character or string.
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline std::string ToCharset(Tencoding &&to, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<std::string>(std::forward<Tencoding>(to), std::forward<Tsrc>(str));
|
||||
}
|
||||
template <typename Tsrc, typename Tto, typename Tfrom>
|
||||
inline std::string ToCharset(Tto &&to, Tfrom &&from, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<std::string>(std::forward<Tto>(to), std::forward<Tfrom>(from), std::forward<Tsrc>(str));
|
||||
}
|
||||
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
template <typename Tsrc>
|
||||
inline mpt::lstring ToLocale(Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<mpt::lstring>(std::forward<Tsrc>(str));
|
||||
}
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline mpt::lstring ToLocale(Tencoding &&from, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<mpt::lstring>(std::forward<Tencoding>(from), std::forward<Tsrc>(str));
|
||||
}
|
||||
#endif // MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
template <typename Tsrc>
|
||||
inline mpt::winstring ToWin(Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<mpt::winstring>(std::forward<Tsrc>(str));
|
||||
}
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline mpt::winstring ToWin(Tencoding &&from, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<mpt::winstring>(std::forward<Tencoding>(from), std::forward<Tsrc>(str));
|
||||
}
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
#if defined(MPT_WITH_MFC)
|
||||
template <typename Tsrc>
|
||||
inline CString ToCString(Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<CString>(std::forward<Tsrc>(str));
|
||||
}
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline CString ToCString(Tencoding &&from, Tsrc &&str)
|
||||
{
|
||||
return mpt::transcode<CString>(std::forward<Tencoding>(from), std::forward<Tsrc>(str));
|
||||
}
|
||||
#endif // MPT_WITH_MFC
|
||||
|
||||
|
||||
|
||||
#define UC_(x) MPT_UCHAR(x)
|
||||
#define UL_(x) MPT_ULITERAL(x)
|
||||
#define UV_(x) MPT_USTRINGVIEW(x)
|
||||
#define U_(x) MPT_USTRING(x)
|
||||
|
||||
|
||||
|
||||
// The MPT_UTF8 allows specifying UTF8 char arrays.
|
||||
// The resulting type is mpt::ustring and the construction might require runtime translation,
|
||||
// i.e. it is NOT generally available at compile time.
|
||||
// Use explicit UTF8 encoding,
|
||||
// i.e. U+00FC (LATIN SMALL LETTER U WITH DIAERESIS) would be written as "\xC3\xBC".
|
||||
#define MPT_UTF8(x) mpt::transcode<mpt::ustring>(mpt::common_encoding::utf8, x)
|
||||
|
||||
|
||||
|
||||
template <typename Tsrc, typename Tencoding>
|
||||
inline mpt::ustring ToUnicode(uint16 codepage, Tencoding &&fallback, Tsrc &&str)
|
||||
{
|
||||
#if MPT_OS_WINDOWS && !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
|
||||
mpt::ustring result;
|
||||
std::optional<mpt::common_encoding> charset = mpt::optional_encoding_from_codepage(codepage);
|
||||
if(charset.has_value())
|
||||
{
|
||||
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
|
||||
result = mpt::transcode<mpt::ustring>(*charset, std::forward<Tsrc>(str));
|
||||
#else
|
||||
result = mpt::transcode<mpt::ustring>(charset.value(), std::forward<Tsrc>(str));
|
||||
#endif
|
||||
} else if(mpt::has_codepage(static_cast<UINT>(codepage)))
|
||||
{
|
||||
result = mpt::transcode<mpt::ustring>(static_cast<UINT>(codepage), std::forward<Tsrc>(str));
|
||||
} else
|
||||
{
|
||||
result = mpt::transcode<mpt::ustring>(std::forward<Tencoding>(fallback), std::forward<Tsrc>(str));
|
||||
}
|
||||
return result;
|
||||
#else // !MPT_OS_WINDOWS
|
||||
std::optional<mpt::common_encoding> charset = mpt::optional_encoding_from_codepage(codepage);
|
||||
#if defined(MPT_LIBCXX_QUIRK_NO_OPTIONAL_VALUE)
|
||||
return charset.has_value() ? mpt::transcode<mpt::ustring>(charset.value(), std::forward<Tsrc>(str)) : mpt::transcode<mpt::ustring>(std::forward<Tencoding>(fallback), std::forward<Tsrc>(str));
|
||||
#else
|
||||
return charset.has_value() ? mpt::transcode<mpt::ustring>(*charset, std::forward<Tsrc>(str)) : mpt::transcode<mpt::ustring>(std::forward<Tencoding>(fallback), std::forward<Tsrc>(str));
|
||||
#endif
|
||||
#endif // MPT_OS_WINDOWS
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline char ToLowerCaseAscii(char c)
|
||||
{
|
||||
return mpt::to_lower_ascii(c);
|
||||
}
|
||||
|
||||
inline char ToUpperCaseAscii(char c)
|
||||
{
|
||||
return mpt::to_upper_ascii(c);
|
||||
}
|
||||
|
||||
inline std::string ToLowerCaseAscii(std::string s)
|
||||
{
|
||||
std::transform(s.begin(), s.end(), s.begin(), static_cast<char(*)(char)>(&mpt::ToLowerCaseAscii));
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::string ToUpperCaseAscii(std::string s)
|
||||
{
|
||||
std::transform(s.begin(), s.end(), s.begin(), static_cast<char(*)(char)>(&mpt::ToUpperCaseAscii));
|
||||
return s;
|
||||
}
|
||||
|
||||
inline int CompareNoCaseAscii(const char *a, const char *b, std::size_t n)
|
||||
{
|
||||
while(n--)
|
||||
{
|
||||
unsigned char ac = mpt::char_value(mpt::ToLowerCaseAscii(*a));
|
||||
unsigned char bc = mpt::char_value(mpt::ToLowerCaseAscii(*b));
|
||||
if(ac != bc)
|
||||
{
|
||||
return ac < bc ? -1 : 1;
|
||||
} else if(!ac && !bc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
++a;
|
||||
++b;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int CompareNoCaseAscii(std::string_view a, std::string_view b)
|
||||
{
|
||||
for(std::size_t i = 0; i < std::min(a.length(), b.length()); ++i)
|
||||
{
|
||||
unsigned char ac = mpt::char_value(mpt::ToLowerCaseAscii(a[i]));
|
||||
unsigned char bc = mpt::char_value(mpt::ToLowerCaseAscii(b[i]));
|
||||
if(ac != bc)
|
||||
{
|
||||
return ac < bc ? -1 : 1;
|
||||
} else if(!ac && !bc)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(a.length() == b.length())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return a.length() < b.length() ? -1 : 1;
|
||||
}
|
||||
|
||||
inline int CompareNoCaseAscii(const std::string &a, const std::string &b)
|
||||
{
|
||||
return CompareNoCaseAscii(std::string_view(a), std::string_view(b));
|
||||
}
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
inline mpt::ustring ToLowerCase(const mpt::ustring &s)
|
||||
{
|
||||
#if defined(MPT_WITH_MFC)
|
||||
#if defined(UNICODE)
|
||||
return mpt::transcode<mpt::ustring>(mpt::transcode<CString>(s).MakeLower());
|
||||
#else // !UNICODE
|
||||
return mpt::transcode<mpt::ustring>(mpt::transcode<CStringW>(s).MakeLower());
|
||||
#endif // UNICODE
|
||||
#else // !MPT_WITH_MFC
|
||||
std::wstring ws = mpt::transcode<std::wstring>(s);
|
||||
std::transform(ws.begin(), ws.end(), ws.begin(), &std::towlower);
|
||||
return mpt::transcode<mpt::ustring>(ws);
|
||||
#endif // MPT_WITH_MFC
|
||||
}
|
||||
|
||||
inline mpt::ustring ToUpperCase(const mpt::ustring &s)
|
||||
{
|
||||
#if defined(MPT_WITH_MFC)
|
||||
#if defined(UNICODE)
|
||||
return mpt::transcode<mpt::ustring>(mpt::transcode<CString>(s).MakeUpper());
|
||||
#else // !UNICODE
|
||||
return mpt::transcode<mpt::ustring>(mpt::transcode<CStringW>(s).MakeUpper());
|
||||
#endif // UNICODE
|
||||
#else // !MPT_WITH_MFC
|
||||
std::wstring ws = mpt::transcode<std::wstring>(s);
|
||||
std::transform(ws.begin(), ws.end(), ws.begin(), &std::towupper);
|
||||
return mpt::transcode<mpt::ustring>(ws);
|
||||
#endif // MPT_WITH_MFC
|
||||
}
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// The AnyString types are meant to be used as function argument types only,
|
||||
// and only during the transition phase to all-unicode strings in the whole codebase.
|
||||
// Using an AnyString type as function argument avoids the need to overload a function for all the
|
||||
// different string types that we currently have.
|
||||
// Warning: These types will silently do charset conversions. Only use them when this can be tolerated.
|
||||
|
||||
// BasicAnyString is convertable to mpt::ustring and constructable from any string at all.
|
||||
template <mpt::CharsetEnum charset = mpt::Charset::UTF8, bool tryUTF8 = true>
|
||||
class BasicAnyString : public mpt::ustring
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
static mpt::ustring From8bit(std::string str)
|
||||
{
|
||||
if constexpr(charset == mpt::CharsetEnum::UTF8)
|
||||
{
|
||||
return mpt::transcode<mpt::ustring>(mpt::common_encoding::utf8, std::move(str));
|
||||
} else
|
||||
{
|
||||
// auto utf8 detection
|
||||
if constexpr(tryUTF8)
|
||||
{
|
||||
if(mpt::is_utf8(str))
|
||||
{
|
||||
return mpt::transcode<mpt::ustring>(mpt::common_encoding::utf8, std::move(str));
|
||||
} else
|
||||
{
|
||||
return mpt::transcode<mpt::ustring>(mpt::CharsetTranscoder(charset), std::move(str));
|
||||
}
|
||||
} else
|
||||
{
|
||||
return mpt::transcode<mpt::ustring>(mpt::CharsetTranscoder(charset), std::move(str));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// 8 bit
|
||||
BasicAnyString(const char *str)
|
||||
: mpt::ustring(From8bit(str ? str : std::string()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
BasicAnyString(std::string str)
|
||||
: mpt::ustring(From8bit(std::move(str)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
template <typename Tstring>
|
||||
BasicAnyString(Tstring &&str)
|
||||
: mpt::ustring(mpt::transcode<mpt::ustring>(std::forward<Tstring>(str)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// AnyUnicodeString is convertable to mpt::ustring and constructable from any known encoding
|
||||
class AnyUnicodeString : public mpt::ustring
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
template <typename Tstring>
|
||||
AnyUnicodeString(Tstring &&str)
|
||||
: mpt::ustring(mpt::transcode<mpt::ustring>(std::forward<Tstring>(str)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// AnyString
|
||||
// Try to do the smartest auto-magic we can do.
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
using AnyString = BasicAnyString<mpt::CharsetEnum::Locale, true>;
|
||||
#elif MPT_OS_WINDOWS
|
||||
using AnyString = BasicAnyString<mpt::CharsetEnum::Windows1252, true>;
|
||||
#else
|
||||
using AnyString = BasicAnyString<mpt::CharsetEnum::ISO8859_1, true>;
|
||||
#endif
|
||||
|
||||
// AnyStringLocale
|
||||
// char-based strings are assumed to be in locale encoding.
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
using AnyStringLocale = BasicAnyString<mpt::CharsetEnum::Locale, false>;
|
||||
#else
|
||||
using AnyStringLocale = BasicAnyString<mpt::CharsetEnum::UTF8, false>;
|
||||
#endif
|
||||
|
||||
// AnyStringUTF8orLocale
|
||||
// char-based strings are tried in UTF8 first, if this fails, locale is used.
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
using AnyStringUTF8orLocale = BasicAnyString<mpt::CharsetEnum::Locale, true>;
|
||||
#else
|
||||
using AnyStringUTF8orLocale = BasicAnyString<mpt::CharsetEnum::UTF8, false>;
|
||||
#endif
|
||||
|
||||
// AnyStringUTF8
|
||||
// char-based strings are assumed to be in UTF8.
|
||||
using AnyStringUTF8 = BasicAnyString<mpt::CharsetEnum::UTF8, false>;
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
|
||||
|
||||
template <OPENMPT_NAMESPACE::mpt::CharsetEnum charset, bool tryUTF8>
|
||||
struct mpt::make_string_type<OPENMPT_NAMESPACE::BasicAnyString<charset, tryUTF8>> {
|
||||
using type = mpt::ustring;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct mpt::make_string_type<OPENMPT_NAMESPACE::AnyUnicodeString> {
|
||||
using type = mpt::ustring;
|
||||
};
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* mptStringBuffer.cpp
|
||||
* -------------------
|
||||
* Purpose: Various functions for "fixing" char array strings for writing to or
|
||||
* reading from module files, or for securing char arrays in general.
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "mptStringBuffer.h"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
namespace String
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
std::string ReadStringBuffer(String::ReadWriteMode mode, const char *srcBuffer, std::size_t srcSize)
|
||||
{
|
||||
|
||||
std::string dest;
|
||||
const char *src = srcBuffer;
|
||||
|
||||
if(mode == nullTerminated || mode == spacePaddedNull)
|
||||
{
|
||||
// We assume that the last character of the source buffer is null.
|
||||
if(srcSize > 0)
|
||||
{
|
||||
srcSize -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(mode == nullTerminated || mode == maybeNullTerminated)
|
||||
{
|
||||
|
||||
// Copy null-terminated string, stopping at null.
|
||||
dest.assign(src, std::find(src, src + srcSize, '\0'));
|
||||
|
||||
} else if(mode == spacePadded || mode == spacePaddedNull)
|
||||
{
|
||||
|
||||
// Copy string over.
|
||||
dest.assign(src, src + srcSize);
|
||||
|
||||
// Convert null characters to spaces.
|
||||
std::transform(dest.begin(), dest.end(), dest.begin(), [] (char c) -> char { return (c != '\0') ? c : ' '; });
|
||||
|
||||
// Trim trailing spaces.
|
||||
dest = mpt::trim_right(dest, std::string(" "));
|
||||
|
||||
}
|
||||
|
||||
return dest;
|
||||
|
||||
}
|
||||
|
||||
void WriteStringBuffer(String::ReadWriteMode mode, char *destBuffer, const std::size_t destSize, const char *srcBuffer, const std::size_t srcSize)
|
||||
{
|
||||
|
||||
MPT_ASSERT(destSize > 0);
|
||||
|
||||
const size_t maxSize = std::min(destSize, srcSize);
|
||||
char *dst = destBuffer;
|
||||
const char *src = srcBuffer;
|
||||
|
||||
// First, copy over null-terminated string.
|
||||
size_t pos = maxSize;
|
||||
while(pos > 0)
|
||||
{
|
||||
if((*dst = *src) == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
pos--;
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
|
||||
if(mode == nullTerminated || mode == maybeNullTerminated)
|
||||
{
|
||||
// Fill rest of string with nulls.
|
||||
std::fill(dst, dst + destSize - maxSize + pos, '\0');
|
||||
} else if(mode == spacePadded || mode == spacePaddedNull)
|
||||
{
|
||||
// Fill the rest of the destination string with spaces.
|
||||
std::fill(dst, dst + destSize - maxSize + pos, ' ');
|
||||
}
|
||||
|
||||
if(mode == nullTerminated || mode == spacePaddedNull)
|
||||
{
|
||||
// Make sure that destination is really null-terminated.
|
||||
SetNullTerminator(destBuffer, destSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace String
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,322 @@
|
||||
/*
|
||||
* mptStringBuffer.h
|
||||
* -----------------
|
||||
* Purpose: Various functions for "fixing" char array strings for writing to or
|
||||
* reading from module files, or for securing char arrays in general.
|
||||
* 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 "mpt/string/buffer.hpp"
|
||||
|
||||
#include "mptString.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
namespace String
|
||||
{
|
||||
|
||||
|
||||
enum ReadWriteMode : uint8
|
||||
{
|
||||
// Reading / Writing: Standard null-terminated string handling.
|
||||
nullTerminated = 1,
|
||||
// Reading: Source string is not guaranteed to be null-terminated (if it fills the whole char array).
|
||||
// Writing: Destination string is not guaranteed to be null-terminated (if it fills the whole char array).
|
||||
maybeNullTerminated = 2,
|
||||
// Reading: String may contain null characters anywhere. They should be treated as spaces.
|
||||
// Writing: A space-padded string is written.
|
||||
spacePadded = 3,
|
||||
// Reading: String may contain null characters anywhere. The last character is ignored (it is supposed to be 0).
|
||||
// Writing: A space-padded string with a trailing null is written.
|
||||
spacePaddedNull = 4,
|
||||
};
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
std::string ReadStringBuffer(String::ReadWriteMode mode, const char *srcBuffer, std::size_t srcSize);
|
||||
|
||||
void WriteStringBuffer(String::ReadWriteMode mode, char *destBuffer, const std::size_t destSize, const char *srcBuffer, const std::size_t srcSize);
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
} // namespace String
|
||||
|
||||
|
||||
|
||||
namespace String {
|
||||
using mpt::ReadTypedBuf;
|
||||
using mpt::WriteTypedBuf;
|
||||
} // namespace String
|
||||
|
||||
namespace String {
|
||||
using mpt::ReadAutoBuf;
|
||||
using mpt::WriteAutoBuf;
|
||||
} // namespace String
|
||||
|
||||
|
||||
|
||||
template <typename Tchar>
|
||||
class StringModeBufRefImpl
|
||||
{
|
||||
private:
|
||||
Tchar * buf;
|
||||
std::size_t size;
|
||||
String::ReadWriteMode mode;
|
||||
public:
|
||||
// cppcheck false-positive
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
StringModeBufRefImpl(Tchar * buf_, std::size_t size_, String::ReadWriteMode mode_)
|
||||
: buf(buf_)
|
||||
, size(size_)
|
||||
, mode(mode_)
|
||||
{
|
||||
static_assert(sizeof(Tchar) == 1);
|
||||
}
|
||||
StringModeBufRefImpl(const StringModeBufRefImpl &) = delete;
|
||||
StringModeBufRefImpl(StringModeBufRefImpl &&) = default;
|
||||
StringModeBufRefImpl & operator = (const StringModeBufRefImpl &) = delete;
|
||||
StringModeBufRefImpl & operator = (StringModeBufRefImpl &&) = delete;
|
||||
operator std::string () const
|
||||
{
|
||||
return String::detail::ReadStringBuffer(mode, buf, size);
|
||||
}
|
||||
bool empty() const
|
||||
{
|
||||
return String::detail::ReadStringBuffer(mode, buf, size).empty();
|
||||
}
|
||||
StringModeBufRefImpl & operator = (const std::string & str)
|
||||
{
|
||||
String::detail::WriteStringBuffer(mode, buf, size, str.data(), str.size());
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tchar>
|
||||
class StringModeBufRefImpl<const Tchar>
|
||||
{
|
||||
private:
|
||||
const Tchar * buf;
|
||||
std::size_t size;
|
||||
String::ReadWriteMode mode;
|
||||
public:
|
||||
// cppcheck false-positive
|
||||
// cppcheck-suppress uninitMemberVar
|
||||
StringModeBufRefImpl(const Tchar * buf_, std::size_t size_, String::ReadWriteMode mode_)
|
||||
: buf(buf_)
|
||||
, size(size_)
|
||||
, mode(mode_)
|
||||
{
|
||||
static_assert(sizeof(Tchar) == 1);
|
||||
}
|
||||
StringModeBufRefImpl(const StringModeBufRefImpl &) = delete;
|
||||
StringModeBufRefImpl(StringModeBufRefImpl &&) = default;
|
||||
StringModeBufRefImpl & operator = (const StringModeBufRefImpl &) = delete;
|
||||
StringModeBufRefImpl & operator = (StringModeBufRefImpl &&) = delete;
|
||||
operator std::string () const
|
||||
{
|
||||
return String::detail::ReadStringBuffer(mode, buf, size);
|
||||
}
|
||||
bool empty() const
|
||||
{
|
||||
return String::detail::ReadStringBuffer(mode, buf, size).empty();
|
||||
}
|
||||
};
|
||||
|
||||
namespace String {
|
||||
template <typename Tchar, std::size_t size>
|
||||
inline StringModeBufRefImpl<typename std::add_const<Tchar>::type> ReadBuf(String::ReadWriteMode mode, const std::array<Tchar, size> &buf)
|
||||
{
|
||||
return StringModeBufRefImpl<typename std::add_const<Tchar>::type>(buf.data(), size, mode);
|
||||
}
|
||||
template <typename Tchar, std::size_t size>
|
||||
inline StringModeBufRefImpl<typename std::add_const<Tchar>::type> ReadBuf(String::ReadWriteMode mode, const Tchar (&buf)[size])
|
||||
{
|
||||
return StringModeBufRefImpl<typename std::add_const<Tchar>::type>(buf, size, mode);
|
||||
}
|
||||
template <typename Tchar>
|
||||
inline StringModeBufRefImpl<typename std::add_const<Tchar>::type> ReadBuf(String::ReadWriteMode mode, const Tchar * buf, std::size_t size)
|
||||
{
|
||||
return StringModeBufRefImpl<typename std::add_const<Tchar>::type>(buf, size, mode);
|
||||
}
|
||||
template <typename Tchar, std::size_t size>
|
||||
inline StringModeBufRefImpl<Tchar> WriteBuf(String::ReadWriteMode mode, std::array<Tchar, size> &buf)
|
||||
{
|
||||
return StringModeBufRefImpl<Tchar>(buf.data(), size, mode);
|
||||
}
|
||||
template <typename Tchar, std::size_t size>
|
||||
inline StringModeBufRefImpl<Tchar> WriteBuf(String::ReadWriteMode mode, Tchar (&buf)[size])
|
||||
{
|
||||
return StringModeBufRefImpl<Tchar>(buf, size, mode);
|
||||
}
|
||||
template <typename Tchar>
|
||||
inline StringModeBufRefImpl<Tchar> WriteBuf(String::ReadWriteMode mode, Tchar * buf, std::size_t size)
|
||||
{
|
||||
return StringModeBufRefImpl<Tchar>(buf, size, mode);
|
||||
}
|
||||
} // namespace String
|
||||
|
||||
template <std::size_t len, mpt::String::ReadWriteMode mode>
|
||||
struct modecharbuf
|
||||
{
|
||||
public:
|
||||
using Tchar = char;
|
||||
using char_type = Tchar;
|
||||
using string_type = std::basic_string<Tchar>;
|
||||
public:
|
||||
Tchar buf[len];
|
||||
public:
|
||||
modecharbuf() = default;
|
||||
modecharbuf(const modecharbuf &) = default;
|
||||
modecharbuf(modecharbuf &&) = default;
|
||||
modecharbuf & operator = (const modecharbuf &) = default;
|
||||
modecharbuf & operator = (modecharbuf &&) = default;
|
||||
operator string_type () const
|
||||
{
|
||||
return mpt::String::ReadBuf(mode, buf);
|
||||
}
|
||||
bool empty() const
|
||||
{
|
||||
return mpt::String::ReadBuf(mode, buf).empty();
|
||||
}
|
||||
modecharbuf & operator = (const string_type & str)
|
||||
{
|
||||
mpt::String::WriteBuf(mode, buf) = str;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// see MPT_BINARY_STRUCT
|
||||
template <std::size_t len, mpt::String::ReadWriteMode mode>
|
||||
constexpr bool declare_binary_safe(const typename mpt::modecharbuf<len, mode> &) { return true; }
|
||||
//struct is_binary_safe<typename mpt::modecharbuf<len, mode>> : public std::true_type { };
|
||||
static_assert(sizeof(mpt::modecharbuf<7, mpt::String::ReadWriteMode::nullTerminated>) == 7);
|
||||
static_assert(alignof(mpt::modecharbuf<7, mpt::String::ReadWriteMode::nullTerminated>) == 1);
|
||||
static_assert(std::is_standard_layout<mpt::modecharbuf<7, mpt::String::ReadWriteMode::nullTerminated>>::value);
|
||||
|
||||
|
||||
#ifdef MODPLUG_TRACKER
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
namespace String {
|
||||
using mpt::ReadWinBuf;
|
||||
using mpt::WriteWinBuf;
|
||||
} // namespace String
|
||||
|
||||
#if defined(MPT_WITH_MFC)
|
||||
|
||||
namespace String {
|
||||
using mpt::ReadCStringBuf;
|
||||
using mpt::WriteCStringBuf;
|
||||
} // namespace String
|
||||
|
||||
#endif // MPT_WITH_MFC
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace String
|
||||
{
|
||||
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127) // conditional expression is constant
|
||||
#endif // MPT_COMPILER_MSVC
|
||||
|
||||
|
||||
// Sets last character to null in given char array.
|
||||
// Size of the array must be known at compile time.
|
||||
template <size_t size>
|
||||
void SetNullTerminator(char (&buffer)[size])
|
||||
{
|
||||
static_assert(size > 0);
|
||||
buffer[size - 1] = 0;
|
||||
}
|
||||
|
||||
inline void SetNullTerminator(char *buffer, size_t size)
|
||||
{
|
||||
MPT_ASSERT(size > 0);
|
||||
buffer[size - 1] = 0;
|
||||
}
|
||||
|
||||
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
|
||||
|
||||
template <size_t size>
|
||||
void SetNullTerminator(wchar_t (&buffer)[size])
|
||||
{
|
||||
static_assert(size > 0);
|
||||
buffer[size - 1] = 0;
|
||||
}
|
||||
|
||||
inline void SetNullTerminator(wchar_t *buffer, size_t size)
|
||||
{
|
||||
MPT_ASSERT(size > 0);
|
||||
buffer[size - 1] = 0;
|
||||
}
|
||||
|
||||
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif // MPT_COMPILER_MSVC
|
||||
|
||||
|
||||
} // namespace String
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
|
||||
|
||||
|
||||
template <typename Tchar>
|
||||
struct mpt::make_string_type<OPENMPT_NAMESPACE::mpt::StringModeBufRefImpl<Tchar>> {
|
||||
using type = std::basic_string<typename std::remove_const<Tchar>::type>;
|
||||
};
|
||||
|
||||
template <typename Tchar>
|
||||
struct mpt::make_string_view_type<OPENMPT_NAMESPACE::mpt::StringModeBufRefImpl<Tchar>> {
|
||||
using type = std::basic_string_view<typename std::remove_const<Tchar>::type>;
|
||||
};
|
||||
|
||||
|
||||
template <std::size_t len, OPENMPT_NAMESPACE::mpt::String::ReadWriteMode mode>
|
||||
struct mpt::make_string_type<OPENMPT_NAMESPACE::mpt::modecharbuf<len, mode>> {
|
||||
using type = std::string;
|
||||
};
|
||||
|
||||
template <std::size_t len, OPENMPT_NAMESPACE::mpt::String::ReadWriteMode mode>
|
||||
struct mpt::make_string_view_type<OPENMPT_NAMESPACE::mpt::modecharbuf<len, mode>> {
|
||||
using type = std::string_view;
|
||||
};
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* mptStringFormat.h
|
||||
* -----------------
|
||||
* Purpose: Convert other types to strings.
|
||||
* 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 "mpt/base/detect.hpp"
|
||||
#include "mpt/endian/integer.hpp"
|
||||
#include "mpt/format/default_formatter.hpp"
|
||||
#include "mpt/format/message.hpp"
|
||||
#include "mpt/format/message_macros.hpp"
|
||||
#include "mpt/format/simple.hpp"
|
||||
#include "mpt/format/simple_spec.hpp"
|
||||
#include "mpt/string/types.hpp"
|
||||
#include "mpt/string_transcode/transcode.hpp"
|
||||
|
||||
#include "openmpt/base/FlagSet.hpp"
|
||||
|
||||
#include "mptString.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
|
||||
// The following section demands a rationale.
|
||||
// 1. mpt::afmt::val(), mpt::wfmt::val() and mpt::ufmt::val() mimic the semantics of c++11 std::to_string() and std::to_wstring().
|
||||
// There is an important difference though. The c++11 versions are specified in terms of sprintf formatting which in turn
|
||||
// depends on the current C locale. This renders these functions unusable in a library context because the current
|
||||
// C locale is set by the library-using application and could be anything. There is no way a library can get reliable semantics
|
||||
// out of these functions. It is thus better to just avoid them.
|
||||
// ToAString() and ToWString() are based on iostream internally, but the the locale of the stream is forced to std::locale::classic(),
|
||||
// which results in "C" ASCII locale behavior.
|
||||
// 2. The full suite of printf-like or iostream like number formatting is generally not required. Instead, a sane subset functionality
|
||||
// is provided here.
|
||||
// When formatting integers, it is recommended to use mpt::afmt::dec or mpt::afmt::hex. Appending a template argument '<n>' sets the width,
|
||||
// the same way as '%nd' would do. Appending a '0' to the function name causes zero-filling as print-like '%0nd' would do. Spelling 'HEX'
|
||||
// in upper-case generates upper-case hex digits. If these are not known at compile-time, a more verbose FormatValA(int, format) can be
|
||||
// used.
|
||||
// 3. mpt::format(format)(...) provides simplified and type-safe message and localization string formatting.
|
||||
// The only specifier allowed is '{}' enclosing a number n. It references to n-th parameter after the format string (1-based).
|
||||
// This mimics the behaviour of QString::arg() in QT4/5 or MFC AfxFormatString2(). C printf-like functions offer similar functionality
|
||||
// with a '%n$TYPE' syntax. In .NET, the syntax is '{n}'. This is useful to support localization strings that can change the parameter
|
||||
// ordering.
|
||||
// 4. Every function is available for std::string, std::wstring and mpt::ustring. std::string makes no assumption about the encoding, which
|
||||
// basically means, it should work for any 7-bit or 8-bit encoding, including for example ASCII, UTF8 or the current locale encoding.
|
||||
// std::string std::wstring mpt::ustring mpt::tsrtring CString
|
||||
// mpt::afmt mpt::wfmt mpt::ufmt mpt::tfmt mpt::cfmt
|
||||
// MPT_AFORMAT("{}") MPT_WFORMAT("{}") MPT_UFORMAT("{}") MPT_TFORMAT("{}") MPT_CFORMAT("{}")
|
||||
// 5. All functionality here delegates real work outside of the header file so that <sstream> and <locale> do not need to be included when
|
||||
// using this functionality.
|
||||
// Advantages:
|
||||
// - Avoids binary code bloat when too much of iostream operator << gets inlined at every usage site.
|
||||
// - Faster compile times because <sstream> and <locale> (2 very complex headers) are not included everywhere.
|
||||
// Disadvantages:
|
||||
// - Slightly more c++ code is required for delegating work.
|
||||
// - As the header does not use iostreams, custom types need to overload mpt::UString instead of iostream operator << to allow for custom type
|
||||
// formatting.
|
||||
// - std::string, std::wstring and mpt::ustring are returned from somewhat deep cascades of helper functions. Where possible, code is
|
||||
// written in such a way that return-value-optimization (RVO) or named-return-value-optimization (NRVO) should be able to eliminate
|
||||
// almost all these copies. This should not be a problem for any decent modern compiler (and even less so for a c++11 compiler where
|
||||
// move-semantics will kick in if RVO/NRVO fails).
|
||||
|
||||
|
||||
|
||||
namespace mpt {
|
||||
inline namespace MPT_INLINE_NS {
|
||||
template <typename Tstring, typename Tint, mpt::endian endian>
|
||||
inline auto format_value_default(const mpt::packed<Tint, endian> & x) -> decltype(mpt::default_formatter::format<Tstring, Tint>(x)) {
|
||||
return mpt::default_formatter::format<Tstring, Tint>(x);
|
||||
}
|
||||
} // namespace MPT_INLINE_NS
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
template <typename Tstring, typename T>
|
||||
inline auto format_value_default(const T & x) -> decltype(mpt::transcode<Tstring>(x.ToUString())) {
|
||||
return mpt::transcode<Tstring>(x.ToUString());
|
||||
}
|
||||
|
||||
|
||||
template <typename Tstring, typename T>
|
||||
inline auto format_value_default(const T & x) -> decltype(mpt::transcode<Tstring>(ToUString(x))) {
|
||||
return mpt::transcode<Tstring>(ToUString(x));
|
||||
}
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
|
||||
|
||||
template <typename Tstring, typename T>
|
||||
inline auto format_value_default(const T & x) -> decltype(mpt::transcode<Tstring>(x.ToUString())) {
|
||||
return mpt::transcode<Tstring>(x.ToUString());
|
||||
}
|
||||
|
||||
|
||||
template <typename Tstring, typename T>
|
||||
inline auto format_value_default(const T & x) -> decltype(mpt::transcode<Tstring>(ToUString(x))) {
|
||||
return mpt::transcode<Tstring>(ToUString(x));
|
||||
}
|
||||
|
||||
|
||||
template <typename Tstring>
|
||||
using fmtT = mpt::format<Tstring>;
|
||||
|
||||
using afmt = fmtT<std::string>;
|
||||
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
|
||||
using wfmt = fmtT<std::wstring>;
|
||||
#endif
|
||||
using ufmt = fmtT<mpt::ustring>;
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
using lfmt = fmtT<mpt::lstring>;
|
||||
#endif // MPT_ENABLE_CHARSET_LOCALE
|
||||
#if MPT_OS_WINDOWS
|
||||
using tfmt = fmtT<mpt::tstring>;
|
||||
#endif
|
||||
#if defined(MPT_WITH_MFC)
|
||||
using cfmt = fmtT<CString>;
|
||||
#endif // MPT_WITH_MFC
|
||||
|
||||
|
||||
#define MPT_AFORMAT(f) MPT_AFORMAT_MESSAGE(f)
|
||||
|
||||
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
|
||||
#define MPT_WFORMAT(f) MPT_WFORMAT_MESSAGE(f)
|
||||
#endif
|
||||
|
||||
#define MPT_UFORMAT(f) MPT_UFORMAT_MESSAGE(f)
|
||||
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
#define MPT_LFORMAT(f) MPT_LFORMAT_MESSAGE(f)
|
||||
#endif // MPT_ENABLE_CHARSET_LOCALE
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
#define MPT_TFORMAT(f) MPT_TFORMAT_MESSAGE(f)
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
#if defined(MPT_WITH_MFC)
|
||||
#define MPT_CFORMAT(f) MPT_CFORMAT_MESSAGE(f)
|
||||
#endif // MPT_WITH_MFC
|
||||
|
||||
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
template <typename enum_t, typename store_t>
|
||||
mpt::ustring ToUString(FlagSet<enum_t, store_t> flagset)
|
||||
{
|
||||
mpt::ustring str(flagset.size_bits(), UC_('0'));
|
||||
|
||||
for(std::size_t x = 0; x < flagset.size_bits(); ++x)
|
||||
{
|
||||
str[flagset.size_bits() - x - 1] = (flagset.value().as_bits() & (static_cast<typename FlagSet<enum_t>::store_type>(1) << x) ? UC_('1') : UC_('0'));
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,405 @@
|
||||
/*
|
||||
* mptTime.cpp
|
||||
* -----------
|
||||
* Purpose: Various time utility functions.
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "mptTime.h"
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
#include "mpt/osinfo/windows_wine_version.hpp"
|
||||
#endif // MODPLUG_TRACKER && MPT_OS_WINDOWS
|
||||
|
||||
#include "mptStringBuffer.h"
|
||||
|
||||
#if MPT_CXX_AT_LEAST(20) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO_DATE)
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && MPT_OS_WINDOWS
|
||||
#include <optional>
|
||||
#endif // MODPLUG_TRACKER && MPT_OS_WINDOWS
|
||||
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_C)
|
||||
#include <ctime>
|
||||
#endif // MPT_FALLBACK_TIMEZONE_C
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
namespace Date
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
namespace ANSI
|
||||
{
|
||||
|
||||
uint64 Now()
|
||||
{
|
||||
FILETIME filetime;
|
||||
#if MPT_WIN_AT_LEAST(MPT_WIN_8)
|
||||
GetSystemTimePreciseAsFileTime(&filetime);
|
||||
#else
|
||||
GetSystemTimeAsFileTime(&filetime);
|
||||
#endif
|
||||
return ((uint64)filetime.dwHighDateTime << 32 | filetime.dwLowDateTime);
|
||||
}
|
||||
|
||||
mpt::ustring ToUString(uint64 time100ns)
|
||||
{
|
||||
constexpr std::size_t bufsize = 256;
|
||||
|
||||
mpt::ustring result;
|
||||
|
||||
FILETIME filetime;
|
||||
SYSTEMTIME systime;
|
||||
filetime.dwHighDateTime = (DWORD)(((uint64)time100ns) >> 32);
|
||||
filetime.dwLowDateTime = (DWORD)((uint64)time100ns);
|
||||
FileTimeToSystemTime(&filetime, &systime);
|
||||
|
||||
TCHAR buf[bufsize];
|
||||
|
||||
GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, &systime, TEXT("yyyy-MM-dd"), buf, bufsize);
|
||||
result.append(mpt::ToUnicode(mpt::String::ReadWinBuf(buf)));
|
||||
|
||||
result.append(U_(" "));
|
||||
|
||||
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, TIME_FORCE24HOURFORMAT, &systime, TEXT("HH:mm:ss"), buf, bufsize);
|
||||
result.append(mpt::ToUnicode(mpt::String::ReadWinBuf(buf)));
|
||||
|
||||
result.append(U_("."));
|
||||
|
||||
result.append(mpt::ufmt::dec0<3>((unsigned)systime.wMilliseconds));
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
} // namespace ANSI
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
namespace nochrono
|
||||
{
|
||||
|
||||
static int32 ToDaynum(int32 year, int32 month, int32 day)
|
||||
{
|
||||
month = (month + 9) % 12;
|
||||
year = year - (month / 10);
|
||||
int32 daynum = year*365 + year/4 - year/100 + year/400 + (month*306 + 5)/10 + (day - 1);
|
||||
return daynum;
|
||||
}
|
||||
|
||||
static void FromDaynum(int32 d, int32 & year, int32 & month, int32 & day)
|
||||
{
|
||||
int64 g = d;
|
||||
int64 y,ddd,mi,mm,dd;
|
||||
|
||||
y = (10000*g + 14780)/3652425;
|
||||
ddd = g - (365*y + y/4 - y/100 + y/400);
|
||||
if(ddd < 0)
|
||||
{
|
||||
y = y - 1;
|
||||
ddd = g - (365*y + y/4 - y/100 + y/400);
|
||||
}
|
||||
mi = (100*ddd + 52)/3060;
|
||||
mm = (mi + 2)%12 + 1;
|
||||
y = y + (mi + 2)/12;
|
||||
dd = ddd - (mi*306 + 5)/10 + 1;
|
||||
|
||||
year = static_cast<int32>(y);
|
||||
month = static_cast<int32>(mm);
|
||||
day = static_cast<int32>(dd);
|
||||
}
|
||||
|
||||
Unix UnixFromUTC(UTC timeUtc)
|
||||
{
|
||||
int32 daynum = ToDaynum(timeUtc.year, timeUtc.month, timeUtc.day);
|
||||
int64 seconds = static_cast<int64>(daynum - ToDaynum(1970, 1, 1)) * 24 * 60 * 60 + timeUtc.hours * 60 * 60 + timeUtc.minutes * 60 + timeUtc.seconds;
|
||||
return Unix{seconds};
|
||||
}
|
||||
|
||||
UTC UnixAsUTC(Unix tp)
|
||||
{
|
||||
int64 tmp = tp.value;
|
||||
int64 seconds = tmp % 60; tmp /= 60;
|
||||
int64 minutes = tmp % 60; tmp /= 60;
|
||||
int64 hours = tmp % 24; tmp /= 24;
|
||||
int32 year = 0, month = 0, day = 0;
|
||||
FromDaynum(static_cast<int32>(tmp) + ToDaynum(1970,1,1), year, month, day);
|
||||
UTC result = {};
|
||||
result.year = year;
|
||||
result.month = month;
|
||||
result.day = day;
|
||||
result.hours = static_cast<int32>(hours);
|
||||
result.minutes = static_cast<int32>(minutes);
|
||||
result.seconds = seconds;
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
struct tz_error
|
||||
{
|
||||
};
|
||||
|
||||
Unix UnixFromLocal(Local timeLocal)
|
||||
{
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_WINDOWS_HISTORIC)
|
||||
try
|
||||
{
|
||||
if(mpt::osinfo::windows::current_is_wine())
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
SYSTEMTIME sys_local{};
|
||||
sys_local.wYear = static_cast<uint16>(timeLocal.year);
|
||||
sys_local.wMonth = static_cast<uint16>(timeLocal.month);
|
||||
sys_local.wDay = static_cast<uint16>(timeLocal.day);
|
||||
sys_local.wHour = static_cast<uint16>(timeLocal.hours);
|
||||
sys_local.wMinute = static_cast<uint16>(timeLocal.minutes);
|
||||
sys_local.wSecond = static_cast<uint16>(timeLocal.seconds);
|
||||
sys_local.wMilliseconds = 0;
|
||||
DYNAMIC_TIME_ZONE_INFORMATION dtzi{};
|
||||
if(GetDynamicTimeZoneInformation(&dtzi) == TIME_ZONE_ID_INVALID) // WinVista
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
SYSTEMTIME sys_utc{};
|
||||
if(TzSpecificLocalTimeToSystemTimeEx(&dtzi, &sys_local, &sys_utc) == FALSE) // Win7/Win8
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
FILETIME ft{};
|
||||
if(SystemTimeToFileTime(&sys_utc, &ft) == FALSE) // Win 2000
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
ULARGE_INTEGER time_value{};
|
||||
time_value.LowPart = ft.dwLowDateTime;
|
||||
time_value.HighPart = ft.dwHighDateTime;
|
||||
return UnixFromSeconds(static_cast<int64>((time_value.QuadPart - 116444736000000000LL) / 10000000LL));
|
||||
} catch(const tz_error &)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
#endif
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_WINDOWS_CURRENT)
|
||||
try
|
||||
{
|
||||
SYSTEMTIME sys_local{};
|
||||
sys_local.wYear = static_cast<uint16>(timeLocal.year);
|
||||
sys_local.wMonth = static_cast<uint16>(timeLocal.month);
|
||||
sys_local.wDay = static_cast<uint16>(timeLocal.day);
|
||||
sys_local.wHour = static_cast<uint16>(timeLocal.hours);
|
||||
sys_local.wMinute = static_cast<uint16>(timeLocal.minutes);
|
||||
sys_local.wSecond = static_cast<uint16>(timeLocal.seconds);
|
||||
sys_local.wMilliseconds = 0;
|
||||
SYSTEMTIME sys_utc{};
|
||||
if(TzSpecificLocalTimeToSystemTime(NULL, &sys_local, &sys_utc) == FALSE) // WinXP
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
FILETIME ft{};
|
||||
if(SystemTimeToFileTime(&sys_utc, &ft) == FALSE) // Win 2000
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
ULARGE_INTEGER time_value{};
|
||||
time_value.LowPart = ft.dwLowDateTime;
|
||||
time_value.HighPart = ft.dwHighDateTime;
|
||||
return UnixFromSeconds(static_cast<int64>((time_value.QuadPart - 116444736000000000LL) / 10000000LL));
|
||||
} catch(const tz_error &)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
#endif
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_C)
|
||||
std::tm tmp{};
|
||||
tmp.tm_year = timeLocal.year - 1900;
|
||||
tmp.tm_mon = timeLocal.month - 1;
|
||||
tmp.tm_mday = timeLocal.day;
|
||||
tmp.tm_hour = timeLocal.hours;
|
||||
tmp.tm_min = timeLocal.minutes;
|
||||
tmp.tm_sec = static_cast<int>(timeLocal.seconds);
|
||||
return UnixFromSeconds(static_cast<int64>(std::mktime(&tmp)));
|
||||
#endif
|
||||
}
|
||||
|
||||
Local UnixAsLocal(Unix tp)
|
||||
{
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_WINDOWS_HISTORIC)
|
||||
try
|
||||
{
|
||||
if(mpt::osinfo::windows::current_is_wine())
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
ULARGE_INTEGER time_value{};
|
||||
time_value.QuadPart = static_cast<int64>(UnixAsSeconds(tp)) * 10000000LL + 116444736000000000LL;
|
||||
FILETIME ft{};
|
||||
ft.dwLowDateTime = time_value.LowPart;
|
||||
ft.dwHighDateTime = time_value.HighPart;
|
||||
SYSTEMTIME sys_utc{};
|
||||
if(FileTimeToSystemTime(&ft, &sys_utc) == FALSE) // WinXP
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
DYNAMIC_TIME_ZONE_INFORMATION dtzi{};
|
||||
if(GetDynamicTimeZoneInformation(&dtzi) == TIME_ZONE_ID_INVALID) // WinVista
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
SYSTEMTIME sys_local{};
|
||||
if(SystemTimeToTzSpecificLocalTimeEx(&dtzi, &sys_utc, &sys_local) == FALSE) // Win7/Win8
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
Local result{};
|
||||
result.year = sys_local.wYear;
|
||||
result.month = sys_local.wMonth;
|
||||
result.day = sys_local.wDay;
|
||||
result.hours = sys_local.wHour;
|
||||
result.minutes = sys_local.wMinute;
|
||||
result.seconds = sys_local.wSecond;
|
||||
return result;
|
||||
} catch(const tz_error&)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
#endif
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_WINDOWS_CURRENT)
|
||||
try
|
||||
{
|
||||
ULARGE_INTEGER time_value{};
|
||||
time_value.QuadPart = static_cast<int64>(UnixAsSeconds(tp)) * 10000000LL + 116444736000000000LL;
|
||||
FILETIME ft{};
|
||||
ft.dwLowDateTime = time_value.LowPart;
|
||||
ft.dwHighDateTime = time_value.HighPart;
|
||||
SYSTEMTIME sys_utc{};
|
||||
if(FileTimeToSystemTime(&ft, &sys_utc) == FALSE) // WinXP
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
SYSTEMTIME sys_local{};
|
||||
if(SystemTimeToTzSpecificLocalTime(NULL, &sys_utc, &sys_local) == FALSE) // Win2000
|
||||
{
|
||||
throw tz_error{};
|
||||
}
|
||||
Local result{};
|
||||
result.year = sys_local.wYear;
|
||||
result.month = sys_local.wMonth;
|
||||
result.day = sys_local.wDay;
|
||||
result.hours = sys_local.wHour;
|
||||
result.minutes = sys_local.wMinute;
|
||||
result.seconds = sys_local.wSecond;
|
||||
return result;
|
||||
} catch(const tz_error&)
|
||||
{
|
||||
// nothing
|
||||
}
|
||||
#endif
|
||||
#if defined(MPT_FALLBACK_TIMEZONE_C)
|
||||
std::time_t time_tp = static_cast<std::time_t>(UnixAsSeconds(tp));
|
||||
std::tm *tmp = std::localtime(&time_tp);
|
||||
if(!tmp)
|
||||
{
|
||||
return Local{};
|
||||
}
|
||||
std::tm local = *tmp;
|
||||
Local result{};
|
||||
result.year = local.tm_year + 1900;
|
||||
result.month = local.tm_mon + 1;
|
||||
result.day = local.tm_mday;
|
||||
result.hours = local.tm_hour;
|
||||
result.minutes = local.tm_min;
|
||||
result.seconds = local.tm_sec;
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
} // namespace nochrono
|
||||
|
||||
template <LogicalTimezone TZ>
|
||||
static mpt::ustring ToShortenedISO8601Impl(mpt::Date::Gregorian<TZ> date)
|
||||
{
|
||||
mpt::ustring result;
|
||||
mpt::ustring tz;
|
||||
if constexpr(TZ == LogicalTimezone::Unspecified)
|
||||
{
|
||||
tz = U_("");
|
||||
} else if constexpr(TZ == LogicalTimezone::UTC)
|
||||
{
|
||||
tz = U_("Z");
|
||||
} else
|
||||
{
|
||||
tz = U_("");
|
||||
}
|
||||
if(date.year == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
result += mpt::ufmt::dec0<4>(date.year);
|
||||
result += U_("-") + mpt::ufmt::dec0<2>(date.month);
|
||||
result += U_("-") + mpt::ufmt::dec0<2>(date.day);
|
||||
if(date.hours == 0 && date.minutes == 0 && date.seconds)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
result += U_("T");
|
||||
result += mpt::ufmt::dec0<2>(date.hours) + U_(":") + mpt::ufmt::dec0<2>(date.minutes);
|
||||
if(date.seconds == 0)
|
||||
{
|
||||
return result + tz;
|
||||
}
|
||||
result += U_(":") + mpt::ufmt::dec0<2>(date.seconds);
|
||||
result += tz;
|
||||
return result;
|
||||
}
|
||||
|
||||
mpt::ustring ToShortenedISO8601(mpt::Date::AnyGregorian date)
|
||||
{
|
||||
return ToShortenedISO8601Impl(date);
|
||||
}
|
||||
|
||||
mpt::ustring ToShortenedISO8601(mpt::Date::UTC date)
|
||||
{
|
||||
return ToShortenedISO8601Impl(date);
|
||||
}
|
||||
|
||||
#ifdef MODPLUG_TRACKER
|
||||
mpt::ustring ToShortenedISO8601(Local date)
|
||||
{
|
||||
return ToShortenedISO8601Impl(date);
|
||||
}
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
} // namespace Date
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,376 @@
|
||||
/*
|
||||
* mptTime.h
|
||||
* ---------
|
||||
* Purpose: Various time utility functions.
|
||||
* 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"
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
#include "../misc/mptOS.h"
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
#if MPT_CXX_AT_LEAST(20) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO_DATE)
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
#elif MPT_CXX_AT_LEAST(17) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO) && defined(MODPLUG_TRACKER)
|
||||
#include <chrono>
|
||||
#endif
|
||||
|
||||
#if MPT_CXX_BEFORE(20) || defined(MPT_LIBCXX_QUIRK_NO_CHRONO) || defined(MPT_LIBCXX_QUIRK_NO_CHRONO_DATE)
|
||||
#include <ctime>
|
||||
#endif
|
||||
|
||||
#if MPT_WINNT_AT_LEAST(MPT_WIN_8)
|
||||
#define MPT_FALLBACK_TIMEZONE_WINDOWS_HISTORIC
|
||||
#define MPT_FALLBACK_TIMEZONE_WINDOWS_CURRENT
|
||||
#define MPT_FALLBACK_TIMEZONE_C
|
||||
#elif MPT_WINNT_AT_LEAST(MPT_WIN_XP)
|
||||
#define MPT_FALLBACK_TIMEZONE_WINDOWS_CURRENT
|
||||
#define MPT_FALLBACK_TIMEZONE_C
|
||||
#else
|
||||
#define MPT_FALLBACK_TIMEZONE_C
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO)
|
||||
|
||||
namespace mpt {
|
||||
namespace chrono {
|
||||
#if MPT_CXX_AT_LEAST(20)
|
||||
using days = std::chrono::days;
|
||||
using weeks = std::chrono::weeks;
|
||||
using years = std::chrono::years;
|
||||
using months = std::chrono::months;
|
||||
#else
|
||||
using days = std::chrono::duration<int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
|
||||
using weeks = std::chrono::duration<int, std::ratio_multiply<std::ratio<7>, mpt::chrono::days::period>>;
|
||||
using years = std::chrono::duration<int, std::ratio_multiply<std::ratio<146097, 400>, mpt::chrono::days::period>>;
|
||||
using months = std::chrono::duration<int, std::ratio_divide<mpt::chrono::years::period, std::ratio<12>>>;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !MPT_LIBCXX_QUIRK_NO_CHRONO
|
||||
|
||||
|
||||
|
||||
namespace mpt
|
||||
{
|
||||
namespace Date
|
||||
{
|
||||
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
namespace ANSI
|
||||
{
|
||||
// uint64 counts 100ns since 1601-01-01T00:00Z
|
||||
|
||||
uint64 Now();
|
||||
|
||||
mpt::ustring ToUString(uint64 time100ns); // i.e. 2015-01-15 18:32:01.718
|
||||
|
||||
} // namespacee ANSI
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
|
||||
enum class LogicalTimezone
|
||||
{
|
||||
Unspecified,
|
||||
UTC,
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
Local,
|
||||
#endif // MODPLUG_TRACKER
|
||||
};
|
||||
|
||||
template <LogicalTimezone tz>
|
||||
struct Gregorian
|
||||
{
|
||||
int year = 0;
|
||||
unsigned int month = 0;
|
||||
unsigned int day = 0;
|
||||
int32 hours = 0;
|
||||
int32 minutes = 0;
|
||||
int64 seconds = 0;
|
||||
friend bool operator==(const Gregorian<tz>& lhs, const Gregorian<tz>& rhs)
|
||||
{
|
||||
return std::tie(lhs.year, lhs.month, lhs.day, lhs.hours, lhs.minutes, lhs.seconds)
|
||||
== std::tie(rhs.year, rhs.month, rhs.day, rhs.hours, rhs.minutes, rhs.seconds);
|
||||
}
|
||||
friend bool operator!=(const Gregorian<tz>& lhs, const Gregorian<tz>& rhs)
|
||||
{
|
||||
return std::tie(lhs.year, lhs.month, lhs.day, lhs.hours, lhs.minutes, lhs.seconds)
|
||||
!= std::tie(rhs.year, rhs.month, rhs.day, rhs.hours, rhs.minutes, rhs.seconds);
|
||||
}
|
||||
friend bool operator<(const Gregorian<tz> &lhs, const Gregorian<tz> &rhs)
|
||||
{
|
||||
return std::tie(lhs.year, lhs.month, lhs.day, lhs.hours, lhs.minutes, lhs.seconds)
|
||||
< std::tie(rhs.year, rhs.month, rhs.day, rhs.hours, rhs.minutes, rhs.seconds);
|
||||
}
|
||||
};
|
||||
|
||||
using AnyGregorian = Gregorian<LogicalTimezone::Unspecified>;
|
||||
|
||||
using UTC = Gregorian<LogicalTimezone::UTC>;
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
using Local = Gregorian<LogicalTimezone::Local>;
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
template <LogicalTimezone TZ>
|
||||
inline Gregorian<TZ> interpret_as_timezone(AnyGregorian gregorian)
|
||||
{
|
||||
Gregorian<TZ> result;
|
||||
result.year = gregorian.year;
|
||||
result.month = gregorian.month;
|
||||
result.day = gregorian.day;
|
||||
result.hours = gregorian.hours;
|
||||
result.minutes = gregorian.minutes;
|
||||
result.seconds = gregorian.seconds;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <LogicalTimezone TZ>
|
||||
inline Gregorian<LogicalTimezone::Unspecified> forget_timezone(Gregorian<TZ> gregorian)
|
||||
{
|
||||
Gregorian<LogicalTimezone::Unspecified> result;
|
||||
result.year = gregorian.year;
|
||||
result.month = gregorian.month;
|
||||
result.day = gregorian.day;
|
||||
result.hours = gregorian.hours;
|
||||
result.minutes = gregorian.minutes;
|
||||
result.seconds = gregorian.seconds;
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace nochrono
|
||||
{
|
||||
|
||||
// int64 counts 1s since 1970-01-01T00:00Z
|
||||
struct Unix
|
||||
{
|
||||
int64 value{};
|
||||
friend bool operator==(const Unix &a, const Unix &b)
|
||||
{
|
||||
return a.value == b.value;
|
||||
}
|
||||
friend bool operator!=(const Unix &a, const Unix &b)
|
||||
{
|
||||
return a.value != b.value;
|
||||
}
|
||||
};
|
||||
|
||||
#if MPT_CXX_BEFORE(20) || defined(MPT_LIBCXX_QUIRK_NO_CHRONO) || defined(MPT_LIBCXX_QUIRK_NO_CHRONO_DATE)
|
||||
|
||||
inline Unix UnixNow()
|
||||
{
|
||||
return Unix{static_cast<int64>(std::time(nullptr))};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
inline int64 UnixAsSeconds(Unix tp)
|
||||
{
|
||||
return tp.value;
|
||||
}
|
||||
|
||||
inline Unix UnixFromSeconds(int64 seconds)
|
||||
{
|
||||
return Unix{seconds};
|
||||
}
|
||||
|
||||
Unix UnixFromUTC(UTC timeUtc);
|
||||
|
||||
UTC UnixAsUTC(Unix tp);
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
Unix UnixFromLocal(Local timeLocal);
|
||||
|
||||
Local UnixAsLocal(Unix tp);
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
} // namespace nochrono
|
||||
|
||||
#if MPT_CXX_AT_LEAST(20) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO) && !defined(MPT_LIBCXX_QUIRK_NO_CHRONO_DATE)
|
||||
|
||||
using Unix = std::chrono::system_clock::time_point;
|
||||
|
||||
inline Unix UnixNow()
|
||||
{
|
||||
return std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
inline int64 UnixAsSeconds(Unix tp)
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch()).count();
|
||||
}
|
||||
|
||||
inline Unix UnixFromSeconds(int64 seconds)
|
||||
{
|
||||
return std::chrono::system_clock::time_point{std::chrono::seconds{seconds}};
|
||||
}
|
||||
|
||||
inline mpt::Date::Unix UnixFromUTC(UTC utc)
|
||||
{
|
||||
try
|
||||
{
|
||||
return std::chrono::system_clock::time_point{
|
||||
std::chrono::sys_days {
|
||||
std::chrono::year{ utc.year } /
|
||||
std::chrono::month{ utc.month } /
|
||||
std::chrono::day{ utc.day }
|
||||
} +
|
||||
std::chrono::hours{ utc.hours } +
|
||||
std::chrono::minutes{ utc.minutes } +
|
||||
std::chrono::seconds{ utc.seconds }};
|
||||
} catch(const std::exception &)
|
||||
{
|
||||
return mpt::Date::UnixFromSeconds(mpt::Date::nochrono::UnixAsSeconds(mpt::Date::nochrono::UnixFromUTC(utc)));
|
||||
}
|
||||
}
|
||||
|
||||
inline mpt::Date::UTC UnixAsUTC(Unix tp)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::chrono::sys_days dp = std::chrono::floor<std::chrono::days>(tp);
|
||||
std::chrono::year_month_day ymd{dp};
|
||||
std::chrono::hh_mm_ss hms{tp - dp};
|
||||
mpt::Date::UTC result;
|
||||
result.year = static_cast<int>(ymd.year());
|
||||
result.month = static_cast<unsigned int>(ymd.month());
|
||||
result.day = static_cast<unsigned int>(ymd.day());
|
||||
result.hours = static_cast<int32>(hms.hours().count());
|
||||
result.minutes = static_cast<int32>(hms.minutes().count());
|
||||
result.seconds = static_cast<int64>(hms.seconds().count());
|
||||
return result;
|
||||
} catch(const std::exception &)
|
||||
{
|
||||
return mpt::Date::nochrono::UnixAsUTC(mpt::Date::nochrono::UnixFromSeconds(mpt::Date::UnixAsSeconds(tp)));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
inline mpt::Date::Unix UnixFromLocal(Local local)
|
||||
{
|
||||
#if !defined(MPT_LIBCXX_QUIRK_CHRONO_DATE_NO_ZONED_TIME)
|
||||
try
|
||||
{
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
if(mpt::OS::Windows::IsWine())
|
||||
{
|
||||
// <https://bugs.openmpt.org/view.php?id=1933>
|
||||
throw std::runtime_error("zoned_time is blacklisted on Wine");
|
||||
}
|
||||
#endif
|
||||
std::chrono::time_point<std::chrono::local_t, std::chrono::seconds> local_tp =
|
||||
std::chrono::local_days {
|
||||
std::chrono::year{ local.year } /
|
||||
std::chrono::month{ local.month } /
|
||||
std::chrono::day{ local.day }
|
||||
} +
|
||||
std::chrono::hours{ local.hours } +
|
||||
std::chrono::minutes{ local.minutes } +
|
||||
std::chrono::seconds{ local.seconds };
|
||||
#if defined(MPT_LIBCXX_QUIRK_CHRONO_DATE_BROKEN_ZONED_TIME)
|
||||
return std::chrono::zoned_time{std::chrono::current_zone(), std::chrono::current_zone()->to_sys(local_tp)}.get_sys_time();
|
||||
#else
|
||||
return std::chrono::zoned_time{std::chrono::current_zone(), local_tp}.get_sys_time();
|
||||
#endif
|
||||
} catch(const std::exception &)
|
||||
#endif
|
||||
{
|
||||
return mpt::Date::UnixFromSeconds(mpt::Date::nochrono::UnixAsSeconds(mpt::Date::nochrono::UnixFromLocal(local)));
|
||||
}
|
||||
}
|
||||
|
||||
inline mpt::Date::Local UnixAsLocal(Unix tp)
|
||||
{
|
||||
#if !defined(MPT_LIBCXX_QUIRK_CHRONO_DATE_NO_ZONED_TIME)
|
||||
try
|
||||
{
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
if(mpt::OS::Windows::IsWine())
|
||||
{
|
||||
// <https://bugs.openmpt.org/view.php?id=1933>
|
||||
throw std::runtime_error("zoned_time is blacklisted on Wine");
|
||||
}
|
||||
#endif
|
||||
std::chrono::zoned_time local_tp{ std::chrono::current_zone(), tp };
|
||||
std::chrono::local_days dp = std::chrono::floor<std::chrono::days>(local_tp.get_local_time());
|
||||
std::chrono::year_month_day ymd{dp};
|
||||
std::chrono::hh_mm_ss hms{local_tp.get_local_time() - dp};
|
||||
mpt::Date::Local result;
|
||||
result.year = static_cast<int>(ymd.year());
|
||||
result.month = static_cast<unsigned int>(ymd.month());
|
||||
result.day = static_cast<unsigned int>(ymd.day());
|
||||
result.hours = static_cast<int32>(hms.hours().count());
|
||||
result.minutes = static_cast<int32>(hms.minutes().count());
|
||||
result.seconds = static_cast<int64>(hms.seconds().count());
|
||||
return result;
|
||||
} catch(const std::exception &)
|
||||
#endif
|
||||
{
|
||||
return mpt::Date::nochrono::UnixAsLocal(mpt::Date::nochrono::UnixFromSeconds(mpt::Date::UnixAsSeconds(tp)));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
#else
|
||||
|
||||
using Unix = nochrono::Unix;
|
||||
|
||||
using nochrono::UnixNow;
|
||||
using nochrono::UnixAsSeconds;
|
||||
using nochrono::UnixFromSeconds;
|
||||
|
||||
using nochrono::UnixFromUTC;
|
||||
using nochrono::UnixAsUTC;
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
using nochrono::UnixFromLocal;
|
||||
using nochrono::UnixAsLocal;
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
#endif
|
||||
|
||||
mpt::ustring ToShortenedISO8601(AnyGregorian date); // i.e. 2015-01-15T18:32:01
|
||||
|
||||
mpt::ustring ToShortenedISO8601(UTC date); // i.e. 2015-01-15T18:32:01Z
|
||||
|
||||
#ifdef MODPLUG_TRACKER
|
||||
mpt::ustring ToShortenedISO8601(Local date); // i.e. 2015-01-15T18:32:01
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
} // namespace Date
|
||||
} // namespace mpt
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,714 @@
|
||||
/*
|
||||
* serialization_utils.cpp
|
||||
* -----------------------
|
||||
* Purpose: Serializing data to and from MPTM files.
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "serialization_utils.h"
|
||||
|
||||
#include "mpt/base/utility.hpp"
|
||||
#include "mpt/io/io.hpp"
|
||||
#include "mpt/io/io_stdstream.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "misc_util.h"
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
namespace srlztn
|
||||
{
|
||||
|
||||
|
||||
static const uint8 HeaderId_FlagByte = 0;
|
||||
|
||||
// Indexing starts from 0.
|
||||
static inline bool Testbit(uint8 val, uint8 bitindex) {return ((val & (1 << bitindex)) != 0);}
|
||||
|
||||
static inline void Setbit(uint8& val, uint8 bitindex, bool newval)
|
||||
{
|
||||
if(newval)
|
||||
{
|
||||
val |= static_cast<uint8>(1u << bitindex);
|
||||
} else
|
||||
{
|
||||
val &= static_cast<uint8>(~(1u << bitindex));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
bool ID::IsPrintable() const
|
||||
{
|
||||
for(std::size_t i = 0; i < m_ID.length(); ++i)
|
||||
{
|
||||
if(m_ID[i] <= 0 || isprint(static_cast<unsigned char>(m_ID[i])) == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//Format: First bit tells whether the size indicator is 1 or 2 bytes.
|
||||
static void WriteAdaptive12String(std::ostream& oStrm, const std::string& str)
|
||||
{
|
||||
uint16 s = static_cast<uint16>(str.size());
|
||||
LimitMax(s, uint16(std::numeric_limits<uint16>::max() / 2));
|
||||
mpt::IO::WriteAdaptiveInt16LE(oStrm, s);
|
||||
oStrm.write(str.c_str(), s);
|
||||
}
|
||||
|
||||
|
||||
void WriteItemString(std::ostream& oStrm, const std::string &str)
|
||||
{
|
||||
uint32 id = static_cast<uint32>(std::min(str.size(), static_cast<std::size_t>((std::numeric_limits<uint32>::max() >> 4)))) << 4;
|
||||
id |= 12; // 12 == 1100b
|
||||
Binarywrite<uint32>(oStrm, id);
|
||||
id >>= 4;
|
||||
if(id > 0)
|
||||
oStrm.write(str.data(), id);
|
||||
}
|
||||
|
||||
|
||||
void ReadItemString(std::istream& iStrm, std::string& str, const std::size_t)
|
||||
{
|
||||
// bits 0,1: Bytes per char type: 1,2,3,4.
|
||||
// bits 2,3: Bytes in size indicator, 1,2,3,4
|
||||
uint32 id = 0;
|
||||
Binaryread(iStrm, id, 1);
|
||||
const uint8 nSizeBytes = (id & 12) >> 2; // 12 == 1100b
|
||||
if (nSizeBytes > 0)
|
||||
{
|
||||
uint8 bytes = std::min(uint8(3), nSizeBytes);
|
||||
uint8 v2 = 0;
|
||||
uint8 v3 = 0;
|
||||
uint8 v4 = 0;
|
||||
if(bytes >= 1) Binaryread(iStrm, v2);
|
||||
if(bytes >= 2) Binaryread(iStrm, v3);
|
||||
if(bytes >= 3) Binaryread(iStrm, v4);
|
||||
id &= 0xff;
|
||||
id |= (v2 << 8) | (v3 << 16) | (v4 << 24);
|
||||
}
|
||||
// Limit to 1 MB.
|
||||
str.resize(std::min(id >> 4, uint32(1000000)));
|
||||
for(size_t i = 0; i < str.size(); i++)
|
||||
iStrm.read(&str[i], 1);
|
||||
|
||||
id = (id >> 4) - static_cast<uint32>(str.size());
|
||||
if(id > 0)
|
||||
iStrm.ignore(id);
|
||||
}
|
||||
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
mpt::ustring ID::AsString() const
|
||||
{
|
||||
if(IsPrintable())
|
||||
{
|
||||
return mpt::ToUnicode(mpt::Charset::ISO8859_1, m_ID);
|
||||
}
|
||||
if(m_ID.length() > 8)
|
||||
{
|
||||
return mpt::ustring();
|
||||
}
|
||||
uint64le val;
|
||||
val.set(0);
|
||||
std::memcpy(&val, m_ID.data(), m_ID.length());
|
||||
return mpt::ufmt::val(val);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
const char Ssb::s_EntryID[3] = {'2','2','8'};
|
||||
|
||||
|
||||
Ssb::Ssb()
|
||||
: m_Status(Status{})
|
||||
, m_nFixedEntrySize(0)
|
||||
, m_posStart(0)
|
||||
, m_nIdbytes(IdSizeVariable)
|
||||
, m_nCounter(0)
|
||||
, m_Flags((1 << RwfWMapStartPosEntry) + (1 << RwfWMapSizeEntry) + (1 << RwfWVersionNum))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SsbWrite::SsbWrite(std::ostream& os)
|
||||
: oStrm(os)
|
||||
, m_posEntrycount(0)
|
||||
, m_posMapPosField(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SsbRead::SsbRead(std::istream& is)
|
||||
: iStrm(is)
|
||||
, m_nReadVersion(0)
|
||||
, m_rposMapBegin(0)
|
||||
, m_posMapEnd(0)
|
||||
, m_posDataBegin(0)
|
||||
, m_rposEndofHdrData(0)
|
||||
, m_nReadEntrycount(0)
|
||||
, m_nNextReadHint(0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void SsbWrite::AddWriteNote(const Status s)
|
||||
{
|
||||
m_Status.level = static_cast<StatusLevel>(mpt::to_underlying(m_Status.level) | mpt::to_underlying(s.level));
|
||||
m_Status.messages = static_cast<StatusMessages>(mpt::to_underlying(m_Status.messages) | mpt::to_underlying(s.messages));
|
||||
SSB_LOG(MPT_UFORMAT("{}: 0x{} 0x{}")(U_("Write note: "), mpt::ufmt::hex(mpt::to_underlying(s.level)), mpt::ufmt::hex(mpt::to_underlying(s.messages))));
|
||||
}
|
||||
|
||||
void SsbRead::AddReadNote(const Status s)
|
||||
{
|
||||
m_Status.level = static_cast<StatusLevel>(mpt::to_underlying(m_Status.level) | mpt::to_underlying(s.level));
|
||||
m_Status.messages = static_cast<StatusMessages>(mpt::to_underlying(m_Status.messages) | mpt::to_underlying(s.messages));
|
||||
SSB_LOG(MPT_UFORMAT("{}: 0x{} 0x{}")(U_("Read note: "), mpt::ufmt::hex(mpt::to_underlying(s.level)), mpt::ufmt::hex(mpt::to_underlying(s.messages))));
|
||||
}
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
void SsbRead::LogReadEntry(const ReadEntry &pRe, const std::size_t nNum)
|
||||
{
|
||||
SSB_LOG(MPT_UFORMAT("Read entry: {{num, id, rpos, size, desc}} = {{{}, {}, {}, {}, {}}}")(
|
||||
nNum,
|
||||
(pRe.nIdLength < 30 && m_Idarray.size() > 0) ? ID(&m_Idarray[pRe.nIdpos], pRe.nIdLength).AsString() : U_(""),
|
||||
pRe.rposStart,
|
||||
(pRe.nSize != invalidDatasize) ? mpt::ufmt::val(pRe.nSize) : U_(""),
|
||||
U_("")));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
// Called after writing an entry.
|
||||
void SsbWrite::LogWriteEntry(const ID &id, const std::size_t nEntryNum, const std::size_t nBytecount, const std::streamoff rposStart)
|
||||
{
|
||||
SSB_LOG(MPT_UFORMAT("Wrote entry: {{num, id, rpos, size}} = {{{}, {}, {}, {}}}")(nEntryNum, id.AsString(), rposStart, nBytecount));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void SsbRead::ResetReadstatus()
|
||||
{
|
||||
m_Status = Status{};
|
||||
m_Idarray.reserve(32);
|
||||
m_Idarray.push_back(0);
|
||||
}
|
||||
|
||||
|
||||
void SsbWrite::WriteMapItem(const ID &id,
|
||||
const std::streamoff& rposDataStart,
|
||||
const std::size_t& nDatasize,
|
||||
const std::string &pszDesc)
|
||||
{
|
||||
SSB_LOG(MPT_UFORMAT("Writing map entry: id={}, rpos={}, size={}")(
|
||||
(id.GetSize() > 0) ? id.AsString() : U_(""),
|
||||
rposDataStart,
|
||||
nDatasize));
|
||||
|
||||
std::ostringstream mapStream;
|
||||
|
||||
if(m_nIdbytes > 0)
|
||||
{
|
||||
if (m_nIdbytes != IdSizeVariable && id.GetSize() != m_nIdbytes)
|
||||
{ AddWriteNote(SNW_CHANGING_IDSIZE_WITH_FIXED_IDSIZESETTING); return; }
|
||||
|
||||
if (m_nIdbytes == IdSizeVariable) //Variablesize ID?
|
||||
mpt::IO::WriteAdaptiveInt16LE(mapStream, static_cast<uint16>(id.GetSize()));
|
||||
|
||||
if(id.GetSize() > 0)
|
||||
mapStream.write(id.AsSpan().data(), id.AsSpan().size());
|
||||
}
|
||||
|
||||
if(m_Flags[RwfWMapStartPosEntry]) // Startpos
|
||||
mpt::IO::WriteAdaptiveInt64LE(mapStream, rposDataStart);
|
||||
if(m_Flags[RwfWMapSizeEntry]) // Entrysize
|
||||
mpt::IO::WriteAdaptiveInt64LE(mapStream, nDatasize);
|
||||
if(m_Flags[RwfWMapDescEntry]) // Entry descriptions
|
||||
WriteAdaptive12String(mapStream, pszDesc);
|
||||
|
||||
m_MapStreamString.append(mapStream.str());
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SsbWrite::BeginWrite(const ID &id, const uint64& nVersion)
|
||||
{
|
||||
SSB_LOG(MPT_UFORMAT("Write header with ID = {}")(id.AsString()));
|
||||
|
||||
ResetWritestatus();
|
||||
|
||||
if(!oStrm.good())
|
||||
{ AddWriteNote(SNRW_BADGIVEN_STREAM); return; }
|
||||
|
||||
// Start bytes.
|
||||
oStrm.write(s_EntryID, sizeof(s_EntryID));
|
||||
|
||||
m_posStart = static_cast<std::streamoff>(oStrm.tellp()) - static_cast<std::streamoff>(sizeof(s_EntryID));
|
||||
|
||||
// Object ID.
|
||||
{
|
||||
uint8 idsize = static_cast<uint8>(id.GetSize());
|
||||
Binarywrite<uint8>(oStrm, idsize);
|
||||
if(idsize > 0) oStrm.write(id.AsSpan().data(), id.AsSpan().size());
|
||||
}
|
||||
|
||||
// Form header.
|
||||
uint8 header = 0;
|
||||
|
||||
m_Flags[RwfWMapStartPosEntry] = m_Flags[RwfWMapStartPosEntry] && m_nFixedEntrySize == 0;
|
||||
m_Flags[RwfWMapSizeEntry] = m_Flags[RwfWMapSizeEntry] && m_nFixedEntrySize == 0;
|
||||
|
||||
header = (m_nIdbytes != 4) ? (m_nIdbytes & 3) : 3; //0,1 : Bytes per IDtype, 0,1,2,4
|
||||
Setbit(header, 2, m_Flags[RwfWMapStartPosEntry]); //2 : Startpos in map?
|
||||
Setbit(header, 3, m_Flags[RwfWMapSizeEntry]); //3 : Datasize in map?
|
||||
Setbit(header, 4, m_Flags[RwfWVersionNum]); //4 : Version numeric field?
|
||||
Setbit(header, 7, m_Flags[RwfWMapDescEntry]); //7 : Entrydescriptions in map?
|
||||
|
||||
// Write header
|
||||
Binarywrite<uint8>(oStrm, header);
|
||||
|
||||
// Additional options.
|
||||
uint8 tempU8 = 0;
|
||||
Setbit(tempU8, 0, (m_nIdbytes == IdSizeVariable) || (m_nIdbytes == 3) || (m_nIdbytes > 4));
|
||||
Setbit(tempU8, 1, m_nFixedEntrySize != 0);
|
||||
|
||||
const uint8 flags = tempU8;
|
||||
if(flags != s_DefaultFlagbyte)
|
||||
{
|
||||
mpt::IO::WriteAdaptiveInt32LE(oStrm, 2); //Headersize - now it is 2.
|
||||
Binarywrite<uint8>(oStrm, HeaderId_FlagByte);
|
||||
Binarywrite<uint8>(oStrm, flags);
|
||||
}
|
||||
else
|
||||
mpt::IO::WriteAdaptiveInt32LE(oStrm, 0);
|
||||
|
||||
if(Testbit(header, 4)) // Version(numeric)?
|
||||
mpt::IO::WriteAdaptiveInt64LE(oStrm, nVersion);
|
||||
|
||||
if(Testbit(flags, 0)) // Custom IDbytecount?
|
||||
{
|
||||
uint8 n = (m_nIdbytes == IdSizeVariable) ? 1 : static_cast<uint8>((m_nIdbytes << 1));
|
||||
Binarywrite<uint8>(oStrm, n);
|
||||
}
|
||||
|
||||
if(Testbit(flags, 1)) // Fixedsize entries?
|
||||
mpt::IO::WriteAdaptiveInt32LE(oStrm, m_nFixedEntrySize);
|
||||
|
||||
//Entrycount. Reserve two bytes(max uint16_max / 4 entries), actual value is written after writing data.
|
||||
m_posEntrycount = static_cast<std::streamoff>(oStrm.tellp());
|
||||
Binarywrite<uint16>(oStrm, 0);
|
||||
|
||||
m_Flags[RwfRwHasMap] = (m_nIdbytes != 0 || m_Flags[RwfWMapStartPosEntry] || m_Flags[RwfWMapSizeEntry] || m_Flags[RwfWMapDescEntry]);
|
||||
|
||||
m_posMapPosField = static_cast<std::streamoff>(oStrm.tellp());
|
||||
if(m_Flags[RwfRwHasMap]) // Mapping begin pos(reserve space - actual value is written after writing data)
|
||||
Binarywrite<uint64>(oStrm, 0);
|
||||
}
|
||||
|
||||
|
||||
void SsbRead::OnReadEntry(const ReadEntry* pE, const ID &id, const std::streamoff& posReadBegin)
|
||||
{
|
||||
#ifdef SSB_LOGGING
|
||||
if(pE)
|
||||
{
|
||||
LogReadEntry(*pE, m_nCounter);
|
||||
} else if(!m_Flags[RwfRMapHasId]) // Not ID's in map.
|
||||
{
|
||||
ReadEntry e;
|
||||
e.rposStart = posReadBegin - m_posStart;
|
||||
e.nSize = mpt::saturate_cast<std::size_t>(static_cast<std::streamoff>(static_cast<std::streamoff>(iStrm.tellg()) - posReadBegin));
|
||||
LogReadEntry(e, m_nCounter);
|
||||
} else // Entry not found.
|
||||
{
|
||||
SSB_LOG(MPT_UFORMAT("No entry with id {} found.")(id.AsString()));
|
||||
}
|
||||
#else
|
||||
MPT_UNREFERENCED_PARAMETER(id);
|
||||
MPT_UNREFERENCED_PARAMETER(posReadBegin);
|
||||
#endif
|
||||
const bool entryFound = (pE || !m_Flags[RwfRMapHasId]);
|
||||
if(entryFound)
|
||||
{
|
||||
m_nCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SsbWrite::OnWroteItem(const ID &id, const std::streamoff& posBeforeWrite)
|
||||
{
|
||||
const std::streamoff nRawEntrySize = static_cast<std::streamoff>(oStrm.tellp()) - posBeforeWrite;
|
||||
|
||||
MPT_MAYBE_CONSTANT_IF(!mpt::in_range<std::size_t>(nRawEntrySize))
|
||||
{
|
||||
AddWriteNote(SNW_INSUFFICIENT_DATASIZETYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
if(m_Flags[RwfRMapHasSize] && (static_cast<uint64>(nRawEntrySize) > (std::numeric_limits<std::size_t>::max() >> 2)))
|
||||
{ AddWriteNote(SNW_DATASIZETYPE_OVERFLOW); return; }
|
||||
|
||||
std::size_t nEntrySize = static_cast<std::size_t>(nRawEntrySize);
|
||||
|
||||
// Handle fixed size entries:
|
||||
if (m_nFixedEntrySize > 0)
|
||||
{
|
||||
if(nEntrySize <= m_nFixedEntrySize)
|
||||
{
|
||||
for(uint32 i = 0; i<m_nFixedEntrySize-nEntrySize; i++)
|
||||
oStrm.put(0);
|
||||
nEntrySize = m_nFixedEntrySize;
|
||||
}
|
||||
else
|
||||
{ AddWriteNote(SNW_INSUFFICIENT_FIXEDSIZE); return; }
|
||||
}
|
||||
if(m_Flags[RwfRwHasMap])
|
||||
WriteMapItem(id, posBeforeWrite - m_posStart, nEntrySize, "");
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
LogWriteEntry(id, m_nCounter, nEntrySize, posBeforeWrite - m_posStart);
|
||||
#endif
|
||||
|
||||
m_nCounter++;
|
||||
if(m_nCounter >= static_cast<uint16>(std::numeric_limits<uint16>::max() >> 2))
|
||||
{
|
||||
FinishWrite();
|
||||
AddWriteNote(SNW_MAX_WRITE_COUNT_REACHED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SsbRead::BeginRead(const ID &id, const uint64& nVersion)
|
||||
{
|
||||
SSB_LOG(MPT_UFORMAT("Read header with expected ID = {}")(id.AsString()));
|
||||
|
||||
ResetReadstatus();
|
||||
|
||||
if (!iStrm.good())
|
||||
{ AddReadNote(SNRW_BADGIVEN_STREAM); return; }
|
||||
|
||||
m_posStart = static_cast<std::streamoff>(iStrm.tellg());
|
||||
|
||||
// Start bytes.
|
||||
{
|
||||
char temp[sizeof(s_EntryID)];
|
||||
ArrayReader<char>(sizeof(s_EntryID))(iStrm, temp, sizeof(s_EntryID));
|
||||
if(std::memcmp(temp, s_EntryID, sizeof(s_EntryID)))
|
||||
{
|
||||
AddReadNote(SNR_STARTBYTE_MISMATCH);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Compare IDs.
|
||||
uint8 storedIdLen = 0;
|
||||
Binaryread<uint8>(iStrm, storedIdLen);
|
||||
std::array<char, 256> storedIdBuf;
|
||||
storedIdBuf = {};
|
||||
if(storedIdLen > 0)
|
||||
{
|
||||
iStrm.read(storedIdBuf.data(), storedIdLen);
|
||||
}
|
||||
if(!(id == ID(storedIdBuf.data(), storedIdLen)))
|
||||
{
|
||||
AddReadNote(SNR_OBJECTCLASS_IDMISMATCH);
|
||||
}
|
||||
if(HasFailed())
|
||||
{
|
||||
SSB_LOG(U_("ID mismatch, terminating read."));
|
||||
return;
|
||||
}
|
||||
|
||||
SSB_LOG(U_("ID match, continuing reading."));
|
||||
|
||||
// Header
|
||||
uint8 tempU8;
|
||||
Binaryread<uint8>(iStrm, tempU8);
|
||||
const uint8 header = tempU8;
|
||||
m_nIdbytes = ((header & 3) == 3) ? 4 : (header & 3);
|
||||
if (Testbit(header, 6))
|
||||
m_Flags[RwfRTwoBytesDescChar] = true;
|
||||
|
||||
// Read headerdata size
|
||||
uint32 tempU32 = 0;
|
||||
mpt::IO::ReadAdaptiveInt32LE(iStrm, tempU32);
|
||||
const uint32 headerdatasize = tempU32;
|
||||
|
||||
// If headerdatasize != 0, read known headerdata and ignore rest.
|
||||
uint8 flagbyte = s_DefaultFlagbyte;
|
||||
if(headerdatasize >= 2)
|
||||
{
|
||||
Binaryread<uint8>(iStrm, tempU8);
|
||||
if(tempU8 == HeaderId_FlagByte)
|
||||
Binaryread<uint8>(iStrm, flagbyte);
|
||||
|
||||
iStrm.ignore( (tempU8 == HeaderId_FlagByte) ? headerdatasize - 2 : headerdatasize - 1);
|
||||
}
|
||||
|
||||
uint64 tempU64 = 0;
|
||||
|
||||
// Read version numeric if available.
|
||||
if (Testbit(header, 4))
|
||||
{
|
||||
mpt::IO::ReadAdaptiveInt64LE(iStrm, tempU64);
|
||||
m_nReadVersion = tempU64;
|
||||
if(tempU64 > nVersion)
|
||||
AddReadNote(SNR_LOADING_OBJECT_WITH_LARGER_VERSION);
|
||||
}
|
||||
|
||||
if (Testbit(header, 5))
|
||||
{
|
||||
Binaryread<uint8>(iStrm, tempU8);
|
||||
iStrm.ignore(tempU8);
|
||||
}
|
||||
|
||||
if(Testbit(flagbyte, 0)) // Custom ID?
|
||||
{
|
||||
Binaryread<uint8>(iStrm, tempU8);
|
||||
if ((tempU8 & 1) != 0)
|
||||
m_nIdbytes = IdSizeVariable;
|
||||
else
|
||||
m_nIdbytes = (tempU8 >> 1);
|
||||
if(m_nIdbytes == 0)
|
||||
AddReadNote(SNR_NO_ENTRYIDS_WITH_CUSTOMID_DEFINED);
|
||||
}
|
||||
|
||||
m_nFixedEntrySize = 0;
|
||||
if(Testbit(flagbyte, 1)) // Fixedsize entries?
|
||||
mpt::IO::ReadAdaptiveInt32LE(iStrm, m_nFixedEntrySize);
|
||||
|
||||
m_Flags[RwfRMapHasStartpos] = Testbit(header, 2);
|
||||
m_Flags[RwfRMapHasSize] = Testbit(header, 3);
|
||||
m_Flags[RwfRMapHasId] = (m_nIdbytes > 0);
|
||||
m_Flags[RwfRMapHasDesc] = Testbit(header, 7);
|
||||
m_Flags[RwfRwHasMap] = m_Flags[RwfRMapHasId] || m_Flags[RwfRMapHasStartpos] || m_Flags[RwfRMapHasSize] || m_Flags[RwfRMapHasDesc];
|
||||
|
||||
if(!m_Flags[RwfRwHasMap])
|
||||
{
|
||||
SSB_LOG(U_("No map in the file."));
|
||||
}
|
||||
|
||||
if (Testbit(flagbyte, 2)) // Object description?
|
||||
{
|
||||
uint16 size = 0;
|
||||
mpt::IO::ReadAdaptiveInt16LE(iStrm, size);
|
||||
iStrm.ignore(size * (m_Flags[RwfRTwoBytesDescChar] ? 2 : 1));
|
||||
}
|
||||
|
||||
if(Testbit(flagbyte, 3))
|
||||
iStrm.ignore(5);
|
||||
|
||||
// Read entrycount
|
||||
mpt::IO::ReadAdaptiveInt64LE(iStrm, tempU64);
|
||||
if(tempU64 > 16000)
|
||||
// The current code can only write 16383 entries because it uses a Adaptive64LE with a fixed size=2
|
||||
// Additionally, 16000 is an arbitrary limit to avoid an out-of-memory DoS when caching the map.
|
||||
{ AddReadNote(SNR_TOO_MANY_ENTRIES_TO_READ); return; }
|
||||
|
||||
m_nReadEntrycount = static_cast<std::size_t>(tempU64);
|
||||
if(m_nReadEntrycount == 0)
|
||||
AddReadNote(SNR_ZEROENTRYCOUNT);
|
||||
|
||||
// Read map rpos if map exists.
|
||||
if(m_Flags[RwfRwHasMap])
|
||||
{
|
||||
mpt::IO::ReadAdaptiveInt64LE(iStrm, tempU64);
|
||||
if(!mpt::in_range<std::streamoff>(tempU64))
|
||||
{ AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; }
|
||||
}
|
||||
|
||||
const std::streamoff rawEndOfHdrData = static_cast<std::streamoff>(iStrm.tellg()) - m_posStart;
|
||||
|
||||
if(rawEndOfHdrData < 0)
|
||||
{
|
||||
AddReadNote(SNR_INSUFFICIENT_RPOSTYPE);
|
||||
return;
|
||||
}
|
||||
|
||||
m_rposEndofHdrData = rawEndOfHdrData;
|
||||
m_rposMapBegin = (m_Flags[RwfRwHasMap]) ? static_cast<std::streamoff>(tempU64) : m_rposEndofHdrData;
|
||||
|
||||
if(!m_Flags[RwfRwHasMap])
|
||||
m_posMapEnd = m_posStart + m_rposEndofHdrData;
|
||||
|
||||
m_Flags[RwfRHeaderIsRead] = true;
|
||||
}
|
||||
|
||||
|
||||
void SsbRead::CacheMap()
|
||||
{
|
||||
if(m_Flags[RwfRwHasMap] || m_nFixedEntrySize > 0)
|
||||
{
|
||||
iStrm.seekg(m_posStart + m_rposMapBegin, std::ios::beg);
|
||||
|
||||
if(iStrm.fail())
|
||||
{ AddReadNote(SNR_BADSTREAM_AFTER_MAPHEADERSEEK); return; }
|
||||
|
||||
SSB_LOG(MPT_UFORMAT("Reading map from rpos: {}")(m_rposMapBegin));
|
||||
|
||||
mapData.resize(m_nReadEntrycount);
|
||||
m_Idarray.reserve(m_nReadEntrycount * 4);
|
||||
|
||||
//Read map
|
||||
for(std::size_t i = 0; i<m_nReadEntrycount; i++)
|
||||
{
|
||||
if(iStrm.fail())
|
||||
{ AddReadNote(SNR_BADSTREAM_AT_MAP_READ); return; }
|
||||
|
||||
// Read ID.
|
||||
uint16 nIdsize = m_nIdbytes;
|
||||
if(nIdsize == IdSizeVariable) //Variablesize ID
|
||||
mpt::IO::ReadAdaptiveInt16LE(iStrm, nIdsize);
|
||||
const size_t nOldEnd = m_Idarray.size();
|
||||
if (nIdsize > 0 && (Util::MaxValueOfType(nOldEnd) - nOldEnd >= nIdsize))
|
||||
{
|
||||
m_Idarray.resize(nOldEnd + nIdsize);
|
||||
iStrm.read(&m_Idarray[nOldEnd], nIdsize);
|
||||
}
|
||||
mapData[i].nIdLength = nIdsize;
|
||||
mapData[i].nIdpos = nOldEnd;
|
||||
|
||||
// Read position.
|
||||
if(m_Flags[RwfRMapHasStartpos])
|
||||
{
|
||||
uint64 tempU64;
|
||||
mpt::IO::ReadAdaptiveInt64LE(iStrm, tempU64);
|
||||
if(!mpt::in_range<std::streamoff>(tempU64))
|
||||
{ AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; }
|
||||
mapData[i].rposStart = static_cast<std::streamoff>(tempU64);
|
||||
}
|
||||
|
||||
// Read entry size.
|
||||
if (m_nFixedEntrySize > 0)
|
||||
mapData[i].nSize = m_nFixedEntrySize;
|
||||
else if(m_Flags[RwfRMapHasSize]) // Map has datasize field.
|
||||
{
|
||||
uint64 tempU64;
|
||||
mpt::IO::ReadAdaptiveInt64LE(iStrm, tempU64);
|
||||
if(!mpt::in_range<std::streamoff>(tempU64))
|
||||
{ AddReadNote(SNR_INSUFFICIENT_STREAM_OFFTYPE); return; }
|
||||
mapData[i].nSize = static_cast<std::size_t>(tempU64);
|
||||
}
|
||||
|
||||
// If there's no entry startpos in map, count start pos from datasizes.
|
||||
// Here readentry.rposStart is set to relative position from databegin.
|
||||
if(mapData[i].nSize != invalidDatasize && !m_Flags[RwfRMapHasStartpos])
|
||||
mapData[i].rposStart = (i > 0) ? mapData[i-1].rposStart + mapData[i-1].nSize : 0;
|
||||
|
||||
if(m_Flags[RwfRMapHasDesc]) // Map has entrydescriptions?
|
||||
{
|
||||
uint16 size = 0;
|
||||
mpt::IO::ReadAdaptiveInt16LE(iStrm, size);
|
||||
if(m_Flags[RwfRTwoBytesDescChar])
|
||||
iStrm.ignore(size * 2);
|
||||
else
|
||||
iStrm.ignore(size);
|
||||
}
|
||||
}
|
||||
m_posMapEnd = static_cast<std::streamoff>(iStrm.tellg());
|
||||
SSB_LOG(MPT_UFORMAT("End of map(rpos): {}")(m_posMapEnd - m_posStart));
|
||||
}
|
||||
|
||||
m_Flags[RwfRMapCached] = true;
|
||||
m_posDataBegin = (m_rposMapBegin == m_rposEndofHdrData) ? m_posMapEnd : m_posStart + m_rposEndofHdrData;
|
||||
iStrm.seekg(m_posDataBegin, std::ios::beg);
|
||||
|
||||
// If there are no positions in the map but there are entry sizes, rposStart will
|
||||
// be relative to data start. Now that posDataBegin is known, make them relative to
|
||||
// startpos.
|
||||
if(!m_Flags[RwfRMapHasStartpos] && (m_Flags[RwfRMapHasSize] || m_nFixedEntrySize > 0))
|
||||
{
|
||||
const std::streamoff offset = m_posDataBegin - m_posStart;
|
||||
for(size_t i = 0; i < m_nReadEntrycount; i++)
|
||||
mapData[i].rposStart += offset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const ReadEntry* SsbRead::Find(const ID &id)
|
||||
{
|
||||
iStrm.clear();
|
||||
if(!m_Flags[RwfRMapCached])
|
||||
CacheMap();
|
||||
|
||||
if(m_nFixedEntrySize > 0 && !m_Flags[RwfRMapHasStartpos] && !m_Flags[RwfRMapHasSize])
|
||||
iStrm.seekg(m_posDataBegin + static_cast<std::streamoff>(m_nFixedEntrySize * m_nCounter), std::ios::beg);
|
||||
|
||||
if(m_Flags[RwfRMapHasId])
|
||||
{
|
||||
const size_t nEntries = mapData.size();
|
||||
for(size_t i0 = 0; i0 < nEntries; i0++)
|
||||
{
|
||||
const size_t i = (i0 + m_nNextReadHint) % nEntries;
|
||||
if(mapData[i].nIdpos < m_Idarray.size() && id == ID(&m_Idarray[mapData[i].nIdpos], mapData[i].nIdLength))
|
||||
{
|
||||
m_nNextReadHint = (i + 1) % nEntries;
|
||||
if (mapData[i].rposStart != 0)
|
||||
iStrm.seekg(m_posStart + mapData[i].rposStart, std::ios::beg);
|
||||
return &mapData[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void SsbWrite::FinishWrite()
|
||||
{
|
||||
const std::streamoff posDataEnd = static_cast<std::streamoff>(oStrm.tellp());
|
||||
|
||||
std::streamoff posMapStart = static_cast<std::streamoff>(oStrm.tellp());
|
||||
|
||||
SSB_LOG(MPT_UFORMAT("Writing map to rpos: {}")(posMapStart - m_posStart));
|
||||
|
||||
if(m_Flags[RwfRwHasMap]) // Write map
|
||||
{
|
||||
oStrm.write(m_MapStreamString.c_str(), m_MapStreamString.length());
|
||||
}
|
||||
|
||||
const std::streamoff posMapEnd = static_cast<std::streamoff>(oStrm.tellp());
|
||||
|
||||
// Write entry count.
|
||||
oStrm.seekp(m_posEntrycount, std::ios::beg);
|
||||
|
||||
// Write a fixed size=2 Adaptive64LE because space for this value has already been reserved berforehand.
|
||||
mpt::IO::WriteAdaptiveInt64LE(oStrm, m_nCounter, 2);
|
||||
|
||||
if(m_Flags[RwfRwHasMap])
|
||||
{ // Write map start position.
|
||||
oStrm.seekp(m_posMapPosField, std::ios::beg);
|
||||
const uint64 rposMap = posMapStart - m_posStart;
|
||||
|
||||
// Write a fixed size=8 Adaptive64LE because space for this value has already been reserved berforehand.
|
||||
mpt::IO::WriteAdaptiveInt64LE(oStrm, rposMap, 8);
|
||||
|
||||
}
|
||||
|
||||
// Seek to end.
|
||||
oStrm.seekp(std::max(posMapEnd, posDataEnd), std::ios::beg);
|
||||
|
||||
SSB_LOG(MPT_UFORMAT("End of stream(rpos): {}")(static_cast<std::streamoff>(oStrm.tellp()) - m_posStart));
|
||||
}
|
||||
|
||||
} // namespace srlztn
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,589 @@
|
||||
/*
|
||||
* serialization_utils.h
|
||||
* ---------------------
|
||||
* Purpose: Serializing data to and from MPTM files.
|
||||
* 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 "mpt/base/alloc.hpp"
|
||||
#include "mpt/io/io.hpp"
|
||||
#include "mpt/io/io_stdstream.hpp"
|
||||
#include "openmpt/base/Endian.hpp"
|
||||
|
||||
#include "../common/mptBaseTypes.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bitset>
|
||||
#include <ios>
|
||||
#include <iosfwd>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
#ifdef MPT_ALL_LOGGING
|
||||
#define SSB_LOGGING
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
#define SSB_LOG(x) MPT_LOG_GLOBAL(LogDebug, "serialization", (x))
|
||||
#else
|
||||
#define SSB_LOG(x) do { } while(0)
|
||||
#endif
|
||||
|
||||
|
||||
namespace srlztn //SeRiaLiZaTioN
|
||||
{
|
||||
|
||||
|
||||
constexpr inline std::size_t invalidDatasize = static_cast<std::size_t>(0) - 1;
|
||||
|
||||
|
||||
enum class StatusLevel : uint8
|
||||
{
|
||||
Failure = 0x2,
|
||||
Note = 0x1,
|
||||
None = 0x0,
|
||||
};
|
||||
|
||||
enum class StatusMessages : uint32
|
||||
{
|
||||
None = 0,
|
||||
|
||||
// Read notes and warnings.
|
||||
SNR_ZEROENTRYCOUNT = 0x00'00'00'01,
|
||||
SNR_NO_ENTRYIDS_WITH_CUSTOMID_DEFINED = 0x00'00'00'02,
|
||||
SNR_LOADING_OBJECT_WITH_LARGER_VERSION = 0x00'00'00'04,
|
||||
|
||||
// Read failures.
|
||||
SNR_BADSTREAM_AFTER_MAPHEADERSEEK = 0x00'00'01'00,
|
||||
SNR_STARTBYTE_MISMATCH = 0x00'00'02'00,
|
||||
SNR_BADSTREAM_AT_MAP_READ = 0x00'00'04'00,
|
||||
SNR_INSUFFICIENT_STREAM_OFFTYPE = 0x00'00'08'00,
|
||||
SNR_OBJECTCLASS_IDMISMATCH = 0x00'00'10'00,
|
||||
SNR_TOO_MANY_ENTRIES_TO_READ = 0x00'00'20'00,
|
||||
SNR_INSUFFICIENT_RPOSTYPE = 0x00'00'40'00,
|
||||
|
||||
// Write failures.
|
||||
SNW_INSUFFICIENT_FIXEDSIZE = 0x00'01'00'00,
|
||||
SNW_CHANGING_IDSIZE_WITH_FIXED_IDSIZESETTING = 0x00'02'00'00,
|
||||
SNW_DATASIZETYPE_OVERFLOW = 0x00'04'00'00,
|
||||
SNW_MAX_WRITE_COUNT_REACHED = 0x00'08'00'00,
|
||||
SNW_INSUFFICIENT_DATASIZETYPE = 0x00'10'00'00,
|
||||
|
||||
SNRW_BADGIVEN_STREAM = 0x01'00'00'00,
|
||||
};
|
||||
|
||||
struct Status
|
||||
{
|
||||
StatusLevel level = StatusLevel::None;
|
||||
StatusMessages messages = StatusMessages::None;
|
||||
};
|
||||
|
||||
constexpr inline Status SNR_ZEROENTRYCOUNT = {StatusLevel::Note, StatusMessages::SNR_ZEROENTRYCOUNT};
|
||||
constexpr inline Status SNR_NO_ENTRYIDS_WITH_CUSTOMID_DEFINED = {StatusLevel::Note, StatusMessages::SNR_NO_ENTRYIDS_WITH_CUSTOMID_DEFINED};
|
||||
constexpr inline Status SNR_LOADING_OBJECT_WITH_LARGER_VERSION = {StatusLevel::Note, StatusMessages::SNR_LOADING_OBJECT_WITH_LARGER_VERSION};
|
||||
|
||||
constexpr inline Status SNR_BADSTREAM_AFTER_MAPHEADERSEEK = {StatusLevel::Failure, StatusMessages::SNR_BADSTREAM_AFTER_MAPHEADERSEEK};
|
||||
constexpr inline Status SNR_STARTBYTE_MISMATCH = {StatusLevel::Failure, StatusMessages::SNR_STARTBYTE_MISMATCH};
|
||||
constexpr inline Status SNR_BADSTREAM_AT_MAP_READ = {StatusLevel::Failure, StatusMessages::SNR_BADSTREAM_AT_MAP_READ};
|
||||
constexpr inline Status SNR_INSUFFICIENT_STREAM_OFFTYPE = {StatusLevel::Failure, StatusMessages::SNR_INSUFFICIENT_STREAM_OFFTYPE};
|
||||
constexpr inline Status SNR_OBJECTCLASS_IDMISMATCH = {StatusLevel::Failure, StatusMessages::SNR_OBJECTCLASS_IDMISMATCH};
|
||||
constexpr inline Status SNR_TOO_MANY_ENTRIES_TO_READ = {StatusLevel::Failure, StatusMessages::SNR_TOO_MANY_ENTRIES_TO_READ};
|
||||
constexpr inline Status SNR_INSUFFICIENT_RPOSTYPE = {StatusLevel::Failure, StatusMessages::SNR_INSUFFICIENT_RPOSTYPE};
|
||||
|
||||
constexpr inline Status SNW_INSUFFICIENT_FIXEDSIZE = {StatusLevel::Failure, StatusMessages::SNW_INSUFFICIENT_FIXEDSIZE};
|
||||
constexpr inline Status SNW_CHANGING_IDSIZE_WITH_FIXED_IDSIZESETTING = {StatusLevel::Failure, StatusMessages::SNW_CHANGING_IDSIZE_WITH_FIXED_IDSIZESETTING};
|
||||
constexpr inline Status SNW_DATASIZETYPE_OVERFLOW = {StatusLevel::Failure, StatusMessages::SNW_DATASIZETYPE_OVERFLOW};
|
||||
constexpr inline Status SNW_MAX_WRITE_COUNT_REACHED = {StatusLevel::Failure, StatusMessages::SNW_MAX_WRITE_COUNT_REACHED};
|
||||
constexpr inline Status SNW_INSUFFICIENT_DATASIZETYPE = {StatusLevel::Failure, StatusMessages::SNW_INSUFFICIENT_DATASIZETYPE};
|
||||
|
||||
constexpr inline Status SNRW_BADGIVEN_STREAM = {StatusLevel::Failure, StatusMessages::SNRW_BADGIVEN_STREAM};
|
||||
|
||||
|
||||
enum : uint16
|
||||
{
|
||||
IdSizeVariable = std::numeric_limits<uint16>::max(),
|
||||
IdSizeMaxFixedSize = (std::numeric_limits<uint8>::max() >> 1)
|
||||
};
|
||||
|
||||
struct ReadEntry
|
||||
{
|
||||
std::size_t nIdpos = 0; // Index of id start in ID array.
|
||||
std::streamoff rposStart = 0; // Entry start position.
|
||||
std::size_t nSize = invalidDatasize; // Entry size.
|
||||
uint16 nIdLength = 0; // Length of id.
|
||||
};
|
||||
|
||||
|
||||
enum Rwf
|
||||
{
|
||||
RwfWMapStartPosEntry, // Write. True to include data start pos entry to map.
|
||||
RwfWMapSizeEntry, // Write. True to include data size entry to map.
|
||||
RwfWMapDescEntry, // Write. True to include description entry to map.
|
||||
RwfWVersionNum, // Write. True to include version numeric.
|
||||
RwfRMapCached, // Read. True if map has been cached.
|
||||
RwfRMapHasId, // Read. True if map has IDs
|
||||
RwfRMapHasStartpos, // Read. True if map data start pos.
|
||||
RwfRMapHasSize, // Read. True if map has entry size.
|
||||
RwfRMapHasDesc, // Read. True if map has entry description.
|
||||
RwfRTwoBytesDescChar, // Read. True if map description characters are two bytes.
|
||||
RwfRHeaderIsRead, // Read. True when header is read.
|
||||
RwfRwHasMap, // Read/write. True if map exists.
|
||||
|
||||
RwfNumFlags
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Binarywrite(std::ostream& oStrm, const T& data)
|
||||
{
|
||||
mpt::IO::WriteIntLE(oStrm, data);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Binarywrite(std::ostream& oStrm, const float& data)
|
||||
{
|
||||
IEEE754binary32LE tmp = IEEE754binary32LE(data);
|
||||
mpt::IO::Write(oStrm, tmp);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Binarywrite(std::ostream& oStrm, const double& data)
|
||||
{
|
||||
IEEE754binary64LE tmp = IEEE754binary64LE(data);
|
||||
mpt::IO::Write(oStrm, tmp);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline void WriteItem(std::ostream& oStrm, const T& data)
|
||||
{
|
||||
static_assert(std::is_trivially_default_constructible<T>::value && std::is_trivially_copyable<T>::value, "");
|
||||
Binarywrite(oStrm, data);
|
||||
}
|
||||
|
||||
void WriteItemString(std::ostream& oStrm, const std::string &str);
|
||||
|
||||
template <>
|
||||
inline void WriteItem<std::string>(std::ostream& oStrm, const std::string& str) {WriteItemString(oStrm, str);}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Binaryread(std::istream& iStrm, T& data)
|
||||
{
|
||||
mpt::IO::ReadIntLE(iStrm, data);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Binaryread(std::istream& iStrm, float& data)
|
||||
{
|
||||
IEEE754binary32LE tmp = IEEE754binary32LE(0.0f);
|
||||
mpt::IO::Read(iStrm, tmp);
|
||||
data = tmp;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Binaryread(std::istream& iStrm, double& data)
|
||||
{
|
||||
IEEE754binary64LE tmp = IEEE754binary64LE(0.0);
|
||||
mpt::IO::Read(iStrm, tmp);
|
||||
data = tmp;
|
||||
}
|
||||
|
||||
//Read only given number of bytes to the beginning of data; data bytes are memset to 0 before reading.
|
||||
template <class T>
|
||||
inline void Binaryread(std::istream& iStrm, T& data, const std::size_t bytecount)
|
||||
{
|
||||
mpt::IO::ReadBinaryTruncatedLE(iStrm, data, bytecount);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Binaryread<float>(std::istream& iStrm, float& data, const std::size_t bytecount)
|
||||
{
|
||||
using T = IEEE754binary32LE;
|
||||
mpt::IO::SeekRelative(iStrm, std::min(bytecount, sizeof(T)));
|
||||
// There is not much we can sanely do for truncated floats,
|
||||
// thus we ignore what we could read and return 0.
|
||||
data = 0.0f;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Binaryread<double>(std::istream& iStrm, double& data, const std::size_t bytecount)
|
||||
{
|
||||
using T = IEEE754binary64LE;
|
||||
mpt::IO::SeekRelative(iStrm, std::min(bytecount, sizeof(T)));
|
||||
// There is not much we can sanely do for truncated floats,
|
||||
// thus we ignore what we could read and return 0.
|
||||
data = 0.0;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
inline void ReadItem(std::istream& iStrm, T& data, const std::size_t nSize)
|
||||
{
|
||||
static_assert(std::is_trivially_default_constructible<T>::value && std::is_trivially_copyable<T>::value, "");
|
||||
if (nSize == sizeof(T) || nSize == invalidDatasize)
|
||||
Binaryread(iStrm, data);
|
||||
else
|
||||
Binaryread(iStrm, data, nSize);
|
||||
}
|
||||
|
||||
void ReadItemString(std::istream& iStrm, std::string& str, const std::size_t);
|
||||
|
||||
template <>
|
||||
inline void ReadItem<std::string>(std::istream& iStrm, std::string& str, const std::size_t nSize)
|
||||
{
|
||||
ReadItemString(iStrm, str, nSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ID
|
||||
{
|
||||
private:
|
||||
std::string m_ID; // NOTE: can contain null characters ('\0')
|
||||
public:
|
||||
ID() = default;
|
||||
ID(const std::string &id) : m_ID(id) { }
|
||||
ID(const char *id) : m_ID(id ? id : "") { }
|
||||
ID(const char * str, std::size_t len) : m_ID(str, len) { }
|
||||
template <typename T>
|
||||
static ID FromInt(const T &val)
|
||||
{
|
||||
static_assert(std::numeric_limits<T>::is_integer);
|
||||
typename mpt::make_le<T>::type valle;
|
||||
valle = val;
|
||||
return ID(mpt::byte_cast<const char*>(mpt::as_raw_memory(valle).data()), mpt::as_raw_memory(valle).size());
|
||||
}
|
||||
#ifdef SSB_LOGGING
|
||||
bool IsPrintable() const;
|
||||
mpt::ustring AsString() const;
|
||||
#endif
|
||||
std::size_t GetSize() const
|
||||
{
|
||||
return m_ID.size();
|
||||
}
|
||||
mpt::span<const char> AsSpan() const
|
||||
{
|
||||
return mpt::as_span(m_ID);
|
||||
}
|
||||
bool operator == (const ID &other) const { return m_ID == other.m_ID; }
|
||||
bool operator != (const ID &other) const { return m_ID != other.m_ID; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Ssb
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
Ssb();
|
||||
|
||||
public:
|
||||
|
||||
bool HasFailed() const
|
||||
{
|
||||
return (m_Status.level >= StatusLevel::Failure);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
Status m_Status;
|
||||
|
||||
uint32 m_nFixedEntrySize; // Read/write: If > 0, data entries have given fixed size.
|
||||
|
||||
std::streamoff m_posStart; // Read/write: Stream position at the beginning of object.
|
||||
|
||||
uint16 m_nIdbytes; // Read/Write: Tells map ID entry size in bytes. If size is variable, value is IdSizeVariable.
|
||||
std::size_t m_nCounter; // Read/write: Keeps count of entries written/read.
|
||||
|
||||
std::bitset<RwfNumFlags> m_Flags; // Read/write: Various flags.
|
||||
|
||||
protected:
|
||||
|
||||
enum : uint8 { s_DefaultFlagbyte = 0 };
|
||||
static const char s_EntryID[3];
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SsbRead
|
||||
: public Ssb
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
using ReadIterator = std::vector<ReadEntry>::const_iterator;
|
||||
|
||||
SsbRead(std::istream& iStrm);
|
||||
|
||||
// Call this to begin reading: must be called before other read functions.
|
||||
void BeginRead(const ID &id, const uint64& nVersion);
|
||||
|
||||
// After calling BeginRead(), this returns number of entries in the file.
|
||||
std::size_t GetNumEntries() const {return m_nReadEntrycount;}
|
||||
|
||||
// Returns read iterator to the beginning of entries.
|
||||
// The behaviour of read iterators is undefined if map doesn't
|
||||
// contain entry ids or data begin positions.
|
||||
ReadIterator GetReadBegin();
|
||||
|
||||
// Returns read iterator to the end(one past last) of entries.
|
||||
ReadIterator GetReadEnd();
|
||||
|
||||
// Compares given id with read entry id
|
||||
bool MatchesId(const ReadIterator& iter, const ID &id);
|
||||
|
||||
uint64 GetReadVersion() {return m_nReadVersion;}
|
||||
|
||||
// Read item using default read implementation.
|
||||
template <class T>
|
||||
bool ReadItem(T& obj, const ID &id) {return ReadItem(obj, id, srlztn::ReadItem<T>);}
|
||||
|
||||
// Read item using given function.
|
||||
template <class T, class FuncObj>
|
||||
bool ReadItem(T& obj, const ID &id, FuncObj);
|
||||
|
||||
// Read item using read iterator.
|
||||
template <class T>
|
||||
bool ReadIterItem(const ReadIterator& iter, T& obj) {return ReadIterItem(iter, obj, srlztn::ReadItem<T>);}
|
||||
template <class T, class FuncObj>
|
||||
bool ReadIterItem(const ReadIterator& iter, T& obj, FuncObj func);
|
||||
|
||||
private:
|
||||
|
||||
// Reads map to cache.
|
||||
void CacheMap();
|
||||
|
||||
// Searches for entry with given ID. If found, returns pointer to corresponding entry, else
|
||||
// returns nullptr.
|
||||
const ReadEntry* Find(const ID &id);
|
||||
|
||||
// Called after reading an object.
|
||||
void OnReadEntry(const ReadEntry* pE, const ID &id, const std::streamoff& posReadBegin);
|
||||
|
||||
void AddReadNote(const Status s);
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
// Called after reading entry. pRe is a pointer to associated map entry if exists.
|
||||
void LogReadEntry(const ReadEntry &pRe, const std::size_t nNum);
|
||||
#endif
|
||||
|
||||
void ResetReadstatus();
|
||||
|
||||
private:
|
||||
|
||||
// mapData is a cache that facilitates faster access to the stored data
|
||||
// without having to reparse on every access.
|
||||
// Iterator invalidation in CacheMap() is not a problem because every code
|
||||
// path that ever returns an iterator into mapData does CacheMap exactly once
|
||||
// beforehand. Following calls use this already cached map. As the data is
|
||||
// immutable when reading, there is no need to ever invalidate the cache and
|
||||
// redo CacheMap().
|
||||
|
||||
std::istream& iStrm;
|
||||
|
||||
std::vector<char> m_Idarray; // Read: Holds entry ids.
|
||||
|
||||
std::vector<ReadEntry> mapData; // Read: Contains map information.
|
||||
uint64 m_nReadVersion; // Read: Version is placed here when reading.
|
||||
std::streamoff m_rposMapBegin; // Read: If map exists, rpos of map begin, else m_rposEndofHdrData.
|
||||
std::streamoff m_posMapEnd; // Read: If map exists, map end position, else pos of end of hdrData.
|
||||
std::streamoff m_posDataBegin; // Read: Data begin position.
|
||||
std::streamoff m_rposEndofHdrData; // Read: rpos of end of header data.
|
||||
std::size_t m_nReadEntrycount; // Read: Number of entries.
|
||||
|
||||
std::size_t m_nNextReadHint; // Read: Hint where to start looking for the next read entry.
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SsbWrite
|
||||
: public Ssb
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
SsbWrite(std::ostream& oStrm);
|
||||
|
||||
// Write header
|
||||
void BeginWrite(const ID &id, const uint64& nVersion);
|
||||
|
||||
// Write item using default write implementation.
|
||||
template <class T>
|
||||
void WriteItem(const T& obj, const ID &id) {WriteItem(obj, id, &srlztn::WriteItem<T>);}
|
||||
|
||||
// Write item using given function.
|
||||
template <class T, class FuncObj>
|
||||
void WriteItem(const T& obj, const ID &id, FuncObj);
|
||||
|
||||
// Writes mapping.
|
||||
void FinishWrite();
|
||||
|
||||
private:
|
||||
|
||||
// Called after writing an item.
|
||||
void OnWroteItem(const ID &id, const std::streamoff& posBeforeWrite);
|
||||
|
||||
void AddWriteNote(const Status s);
|
||||
|
||||
#ifdef SSB_LOGGING
|
||||
void LogWriteEntry(const ID &id,
|
||||
const std::size_t nEntryNum,
|
||||
const std::size_t nBytecount,
|
||||
const std::streamoff rposStart);
|
||||
#endif
|
||||
|
||||
// Writes mapping item to mapstream.
|
||||
void WriteMapItem(const ID &id,
|
||||
const std::streamoff& rposDataStart,
|
||||
const std::size_t& nDatasize,
|
||||
const std::string &pszDesc);
|
||||
|
||||
void ResetWritestatus()
|
||||
{
|
||||
m_Status = Status{};
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::ostream& oStrm;
|
||||
|
||||
std::streamoff m_posEntrycount; // Write: Pos of entrycount field.
|
||||
std::streamoff m_posMapPosField; // Write: Pos of map position field.
|
||||
std::string m_MapStreamString; // Write: Map stream string.
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class T, class FuncObj>
|
||||
void SsbWrite::WriteItem(const T& obj, const ID &id, FuncObj Func)
|
||||
{
|
||||
const std::streamoff pos = static_cast<std::streamoff>(oStrm.tellp());
|
||||
Func(oStrm, obj);
|
||||
OnWroteItem(id, pos);
|
||||
}
|
||||
|
||||
template <class T, class FuncObj>
|
||||
bool SsbRead::ReadItem(T& obj, const ID &id, FuncObj Func)
|
||||
{
|
||||
const ReadEntry* pE = Find(id);
|
||||
const std::streamoff pos = static_cast<std::streamoff>(iStrm.tellg());
|
||||
const bool entryFound = (pE || !m_Flags[RwfRMapHasId]);
|
||||
if(entryFound)
|
||||
{
|
||||
Func(iStrm, obj, (pE) ? (pE->nSize) : invalidDatasize);
|
||||
}
|
||||
OnReadEntry(pE, id, pos);
|
||||
return entryFound;
|
||||
}
|
||||
|
||||
|
||||
template <class T, class FuncObj>
|
||||
bool SsbRead::ReadIterItem(const ReadIterator& iter, T& obj, FuncObj func)
|
||||
{
|
||||
iStrm.clear();
|
||||
if (iter->rposStart != 0)
|
||||
iStrm.seekg(m_posStart + iter->rposStart);
|
||||
const std::streamoff pos = static_cast<std::streamoff>(iStrm.tellg());
|
||||
func(iStrm, obj, iter->nSize);
|
||||
OnReadEntry(&(*iter), ID(&m_Idarray[iter->nIdpos], iter->nIdLength), pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool SsbRead::MatchesId(const ReadIterator& iter, const ID &id)
|
||||
{
|
||||
if(iter->nIdpos >= m_Idarray.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (id == ID(&m_Idarray[iter->nIdpos], iter->nIdLength));
|
||||
}
|
||||
|
||||
|
||||
inline SsbRead::ReadIterator SsbRead::GetReadBegin()
|
||||
{
|
||||
MPT_ASSERT(m_Flags[RwfRMapHasId] && (m_Flags[RwfRMapHasStartpos] || m_Flags[RwfRMapHasSize] || m_nFixedEntrySize > 0));
|
||||
if(!m_Flags[RwfRMapCached])
|
||||
CacheMap();
|
||||
return mapData.begin();
|
||||
}
|
||||
|
||||
|
||||
inline SsbRead::ReadIterator SsbRead::GetReadEnd()
|
||||
{
|
||||
if(!m_Flags[RwfRMapCached])
|
||||
CacheMap();
|
||||
return mapData.end();
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
struct VectorWriter
|
||||
{
|
||||
VectorWriter(size_t nCount) : m_nCount(nCount) {}
|
||||
void operator()(std::ostream &oStrm, const std::vector<T> &vec)
|
||||
{
|
||||
for(size_t i = 0; i < m_nCount; i++)
|
||||
{
|
||||
Binarywrite(oStrm, vec[i]);
|
||||
}
|
||||
}
|
||||
size_t m_nCount;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct VectorReader
|
||||
{
|
||||
VectorReader(size_t nCount) : m_nCount(nCount) {}
|
||||
void operator()(std::istream& iStrm, std::vector<T> &vec, const size_t)
|
||||
{
|
||||
vec.resize(m_nCount);
|
||||
for(std::size_t i = 0; i < m_nCount; ++i)
|
||||
{
|
||||
Binaryread(iStrm, vec[i]);
|
||||
}
|
||||
}
|
||||
size_t m_nCount;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct ArrayReader
|
||||
{
|
||||
ArrayReader(size_t nCount) : m_nCount(nCount) {}
|
||||
void operator()(std::istream& iStrm, T* pData, const size_t)
|
||||
{
|
||||
for(std::size_t i=0; i<m_nCount; ++i)
|
||||
{
|
||||
Binaryread(iStrm, pData[i]);
|
||||
}
|
||||
}
|
||||
size_t m_nCount;
|
||||
};
|
||||
|
||||
|
||||
|
||||
} //namespace srlztn.
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* StdAfx.h
|
||||
* --------
|
||||
* Purpose: Include file for standard system include files, or project specific include files that are used frequently, but are changed infrequently. Also includes the global build settings from openmpt/all/BuildSettings.hpp.
|
||||
* Notes : (currently none)
|
||||
* Authors: Olivier Lapicque
|
||||
* OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
// has to be first
|
||||
#include "openmpt/all/BuildSettings.hpp"
|
||||
#include "openmpt/all/PlatformFixes.hpp"
|
||||
|
||||
|
||||
#if defined(MODPLUG_TRACKER)
|
||||
|
||||
#if defined(MPT_WITH_MFC)
|
||||
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afx.h> // MFC core
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxwin.h> // MFC standard components
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxext.h> // MFC extensions
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxcmn.h> // MFC support for Windows Common Controls
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxcview.h>
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxdlgs.h>
|
||||
#ifndef _AFX_NO_MFC_CONTROLS_IN_DIALOGS
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxlistctrl.h>
|
||||
#endif // !_AFX_NO_MFC_CONTROLS_IN_DIALOGS
|
||||
// cppcheck-suppress missingInclude
|
||||
#include <afxole.h>
|
||||
|
||||
#endif // MPT_WITH_MFC
|
||||
|
||||
#if MPT_OS_WINDOWS
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <shlwapi.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#endif // MPT_OS_WINDOWS
|
||||
|
||||
#endif // MODPLUG_TRACKER
|
||||
|
||||
|
||||
#if MPT_COMPILER_MSVC
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include "mpt/check/compiler.hpp"
|
||||
#include "mpt/check/libc.hpp"
|
||||
#include "mpt/check/libcxx.hpp"
|
||||
#if defined(MPT_WITH_MFC)
|
||||
#include "mpt/check/mfc.hpp"
|
||||
#endif
|
||||
#if MPT_OS_WINDOWS
|
||||
#include "mpt/check/windows.hpp"
|
||||
#endif
|
||||
|
||||
#include "mpt/base/span.hpp"
|
||||
#include "mpt/exception/exception.hpp"
|
||||
#include "mpt/exception/exception_text.hpp"
|
||||
#include "mpt/out_of_memory/out_of_memory.hpp"
|
||||
#include "mpt/string/types.hpp"
|
||||
#include "mpt/system_error/system_error.hpp"
|
||||
|
||||
#include "openmpt/base/Types.hpp"
|
||||
#include "openmpt/logging/Logger.hpp"
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
|
||||
|
||||
// this will be available everywhere
|
||||
|
||||
#include "../common/mptBaseMacros.h"
|
||||
// <version>
|
||||
// <array>
|
||||
// <iterator>
|
||||
// <type_traits>
|
||||
// <cstddef>
|
||||
// <cstdint>
|
||||
|
||||
#include "../common/mptBaseTypes.h"
|
||||
// "openmpt/base/Types.hpp"
|
||||
// "mptBaseMacros.h"
|
||||
// <array>
|
||||
// <limits>
|
||||
// <type_traits>
|
||||
// <cstdint>
|
||||
|
||||
#include "../common/mptAssert.h"
|
||||
// "mptBaseMacros.h"
|
||||
|
||||
#include "../common/mptBaseUtils.h"
|
||||
// <algorithm>
|
||||
// <bit>
|
||||
// <limits>
|
||||
// <numeric>
|
||||
// <utility>
|
||||
|
||||
#include "../common/mptString.h"
|
||||
// <algorithm>
|
||||
// <limits>
|
||||
// <string>
|
||||
// <string_view>
|
||||
// <type_traits>
|
||||
// <cstring>
|
||||
|
||||
#include "../common/mptStringBuffer.h"
|
||||
|
||||
#include "../common/mptStringFormat.h"
|
||||
// <stdexcept>
|
||||
|
||||
#include "../common/mptPathString.h"
|
||||
|
||||
#include "../common/Logging.h"
|
||||
// "openmpt/logging/Logger.hpp"
|
||||
// <atomic>
|
||||
|
||||
#include "../common/misc_util.h"
|
||||
// <stdexcept>
|
||||
// <optional>
|
||||
// <vector>
|
||||
|
||||
// for std::abs
|
||||
#include <cstdlib>
|
||||
#include <stdlib.h>
|
||||
#include <cmath>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
|
||||
@@ -0,0 +1,838 @@
|
||||
/*
|
||||
* version.cpp
|
||||
* -----------
|
||||
* Purpose: OpenMPT version handling.
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "mpt/format/join.hpp"
|
||||
#include "mpt/parse/parse.hpp"
|
||||
#include "mpt/string/utility.hpp"
|
||||
|
||||
#include "mptString.h"
|
||||
#include "mptStringFormat.h"
|
||||
|
||||
#include "versionNumber.h"
|
||||
|
||||
#if __has_include("svn_version.h")
|
||||
#include "svn_version.h"
|
||||
#else
|
||||
#include "../build/svn_version/svn_version.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
|
||||
#define MPT_MAKE_VERSION_NUMERIC_HELPER(prefix,v0,v1,v2,v3) Version( prefix ## v0 , prefix ## v1 , prefix ## v2 , prefix ## v3 )
|
||||
#define MPT_MAKE_VERSION_NUMERIC(v0,v1,v2,v3) MPT_MAKE_VERSION_NUMERIC_HELPER(0x, v0, v1, v2, v3)
|
||||
|
||||
#define MPT_VERSION_CURRENT MPT_MAKE_VERSION_NUMERIC(VER_MAJORMAJOR,VER_MAJOR,VER_MINOR,VER_MINORMINOR)
|
||||
|
||||
|
||||
|
||||
static_assert((MPT_VERSION_CURRENT.GetRawVersion() & 0xffffu) != 0x0000u, "Version numbers ending in .00.00 shall never exist again, as they make interpreting the version number ambiguous for file formats which can only store the two major parts of the version number (e.g. IT and S3M).");
|
||||
|
||||
|
||||
|
||||
Version Version::Current() noexcept
|
||||
{
|
||||
return MPT_VERSION_CURRENT;
|
||||
}
|
||||
|
||||
mpt::ustring Version::GetOpenMPTVersionString() const
|
||||
{
|
||||
return U_("OpenMPT ") + ToUString();
|
||||
}
|
||||
|
||||
Version Version::Parse(const mpt::ustring &s)
|
||||
{
|
||||
uint32 result = 0;
|
||||
std::vector<mpt::ustring> numbers = mpt::split(s, U_("."));
|
||||
for (std::size_t i = 0; i < numbers.size() && i < 4; ++i)
|
||||
{
|
||||
result |= (mpt::parse_hex<unsigned int>(numbers[i]) & 0xff) << ((3 - i) * 8);
|
||||
}
|
||||
return Version(result);
|
||||
}
|
||||
|
||||
mpt::ustring Version::ToUString() const
|
||||
{
|
||||
uint32 v = m_Version;
|
||||
if(v == 0)
|
||||
{
|
||||
// Unknown version
|
||||
return U_("Unknown");
|
||||
} else if((v & 0xFFFF) == 0)
|
||||
{
|
||||
// Only parts of the version number are known (e.g. when reading the version from the IT or S3M file header)
|
||||
return MPT_UFORMAT("{}.{}")(mpt::ufmt::HEX((v >> 24) & 0xFF), mpt::ufmt::HEX0<2>((v >> 16) & 0xFF));
|
||||
} else
|
||||
{
|
||||
// Full version info available
|
||||
return MPT_UFORMAT("{}.{}.{}.{}")(mpt::ufmt::HEX((v >> 24) & 0xFF), mpt::ufmt::HEX0<2>((v >> 16) & 0xFF), mpt::ufmt::HEX0<2>((v >> 8) & 0xFF), mpt::ufmt::HEX0<2>((v) & 0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
Version Version::WithoutTestNumber() const noexcept
|
||||
{
|
||||
return Version(m_Version & 0xFFFFFF00u);
|
||||
}
|
||||
|
||||
Version Version::WithoutPatchOrTestNumbers() const noexcept
|
||||
{
|
||||
return Version(m_Version & 0xFFFF0000u);
|
||||
}
|
||||
|
||||
bool Version::IsTestVersion() const noexcept
|
||||
{
|
||||
return (
|
||||
// Legacy
|
||||
(*this > MPT_V("1.17.02.54") && *this < MPT_V("1.18.02.00") && *this != MPT_V("1.18.00.00"))
|
||||
||
|
||||
// Test builds have non-zero VER_MINORMINOR
|
||||
(*this > MPT_V("1.18.02.00") && ((m_Version & 0xFFFFFF00u) != m_Version))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace Source {
|
||||
|
||||
static mpt::ustring GetUrl()
|
||||
{
|
||||
#ifdef OPENMPT_VERSION_URL
|
||||
return mpt::ToUnicode(mpt::Charset::ASCII, OPENMPT_VERSION_URL);
|
||||
#else
|
||||
return mpt::ustring();
|
||||
#endif
|
||||
}
|
||||
|
||||
static int GetRevision()
|
||||
{
|
||||
#if defined(OPENMPT_VERSION_REVISION)
|
||||
return OPENMPT_VERSION_REVISION;
|
||||
#elif defined(OPENMPT_VERSION_SVNVERSION)
|
||||
std::string svnversion = OPENMPT_VERSION_SVNVERSION;
|
||||
if(svnversion.length() == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if(svnversion.find(":") != std::string::npos)
|
||||
{
|
||||
svnversion = svnversion.substr(svnversion.find(":") + 1);
|
||||
}
|
||||
if(svnversion.find("-") != std::string::npos)
|
||||
{
|
||||
svnversion = svnversion.substr(svnversion.find("-") + 1);
|
||||
}
|
||||
if(svnversion.find("M") != std::string::npos)
|
||||
{
|
||||
svnversion = svnversion.substr(0, svnversion.find("M"));
|
||||
}
|
||||
if(svnversion.find("S") != std::string::npos)
|
||||
{
|
||||
svnversion = svnversion.substr(0, svnversion.find("S"));
|
||||
}
|
||||
if(svnversion.find("P") != std::string::npos)
|
||||
{
|
||||
svnversion = svnversion.substr(0, svnversion.find("P"));
|
||||
}
|
||||
return mpt::parse<int>(svnversion);
|
||||
#else
|
||||
MPT_WARNING_STATEMENT("SVN revision unknown. Please check your build system.");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool IsDirty()
|
||||
{
|
||||
#if defined(OPENMPT_VERSION_DIRTY)
|
||||
return OPENMPT_VERSION_DIRTY != 0;
|
||||
#elif defined(OPENMPT_VERSION_SVNVERSION)
|
||||
std::string svnversion = OPENMPT_VERSION_SVNVERSION;
|
||||
if(svnversion.length() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(svnversion.find("M") != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool HasMixedRevisions()
|
||||
{
|
||||
#if defined(OPENMPT_VERSION_MIXEDREVISIONS)
|
||||
return OPENMPT_VERSION_MIXEDREVISIONS != 0;
|
||||
#elif defined(OPENMPT_VERSION_SVNVERSION)
|
||||
std::string svnversion = OPENMPT_VERSION_SVNVERSION;
|
||||
if(svnversion.length() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(svnversion.find(":") != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(svnversion.find("-") != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(svnversion.find("S") != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(svnversion.find("P") != std::string::npos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool IsPackage()
|
||||
{
|
||||
#if defined(OPENMPT_VERSION_IS_PACKAGE)
|
||||
return OPENMPT_VERSION_IS_PACKAGE != 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static mpt::ustring GetSourceDate()
|
||||
{
|
||||
#if defined(OPENMPT_VERSION_DATE)
|
||||
return mpt::ToUnicode(mpt::Charset::ASCII, OPENMPT_VERSION_DATE);
|
||||
#else
|
||||
return mpt::ustring();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace Source
|
||||
|
||||
SourceInfo::SourceInfo()
|
||||
: m_Url(Source::GetUrl())
|
||||
, m_Revision(Source::GetRevision())
|
||||
, m_IsDirty(Source::IsDirty())
|
||||
, m_HasMixedRevisions(Source::HasMixedRevisions())
|
||||
, m_IsPackage(Source::IsPackage())
|
||||
, m_Date(Source::GetSourceDate())
|
||||
{
|
||||
}
|
||||
|
||||
mpt::ustring SourceInfo::GetUrlWithRevision() const
|
||||
{
|
||||
if(m_Url.empty() || (m_Revision == 0))
|
||||
{
|
||||
return mpt::ustring();
|
||||
}
|
||||
return m_Url + UL_("@") + mpt::ufmt::val(m_Revision);
|
||||
}
|
||||
|
||||
mpt::ustring SourceInfo::GetStateString() const
|
||||
{
|
||||
mpt::ustring retval;
|
||||
if(m_IsDirty)
|
||||
{
|
||||
retval += UL_("+dirty");
|
||||
}
|
||||
if(m_HasMixedRevisions)
|
||||
{
|
||||
retval += UL_("+mixed");
|
||||
}
|
||||
if(retval.empty())
|
||||
{
|
||||
retval += UL_("clean");
|
||||
}
|
||||
if(m_IsPackage)
|
||||
{
|
||||
retval += UL_("-pkg");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
SourceInfo SourceInfo::Current()
|
||||
{
|
||||
return SourceInfo();
|
||||
}
|
||||
|
||||
|
||||
|
||||
VersionWithRevision VersionWithRevision::Current()
|
||||
{
|
||||
return {Version::Current(), static_cast<uint64>(SourceInfo::Current().Revision())};
|
||||
}
|
||||
|
||||
VersionWithRevision VersionWithRevision::Parse(const mpt::ustring &s)
|
||||
{
|
||||
Version version = Version::Parse(mpt::ustring());
|
||||
uint64 revision = 0;
|
||||
const auto tokens = mpt::split(s, U_("-"));
|
||||
if(tokens.size() >= 1)
|
||||
{
|
||||
version = Version::Parse(tokens[0]);
|
||||
}
|
||||
if(tokens.size() >= 2)
|
||||
{
|
||||
revision = mpt::parse<uint64>(tokens[1].substr(1));
|
||||
}
|
||||
return {version, revision};
|
||||
}
|
||||
|
||||
mpt::ustring VersionWithRevision::ToUString() const
|
||||
{
|
||||
if(!HasRevision())
|
||||
{
|
||||
return mpt::ufmt::val(version);
|
||||
}
|
||||
if(!version.IsTestVersion())
|
||||
{
|
||||
return mpt::ufmt::val(version);
|
||||
}
|
||||
return MPT_UFORMAT("{}-r{}")(version, revision);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Build {
|
||||
|
||||
bool IsReleasedBuild()
|
||||
{
|
||||
return !(Version::Current().IsTestVersion() || IsDebugBuild() || Source::IsDirty() || Source::HasMixedRevisions());
|
||||
}
|
||||
|
||||
bool IsDebugBuild()
|
||||
{
|
||||
#if defined(MPT_BUILD_DEBUG) || defined(DEBUG) || defined(_DEBUG)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
mpt::ustring GetBuildDateString()
|
||||
{
|
||||
mpt::ustring result;
|
||||
#ifdef MODPLUG_TRACKER
|
||||
#if defined(OPENMPT_BUILD_DATE)
|
||||
result = mpt::ToUnicode(mpt::Charset::ASCII, OPENMPT_BUILD_DATE );
|
||||
#else
|
||||
result = mpt::ToUnicode(mpt::Charset::ASCII, __DATE__ " " __TIME__ );
|
||||
#endif
|
||||
#else // !MODPLUG_TRACKER
|
||||
result = SourceInfo::Current().Date();
|
||||
#endif // MODPLUG_TRACKER
|
||||
return result;
|
||||
}
|
||||
|
||||
static mpt::ustring GetBuildFlagsString()
|
||||
{
|
||||
mpt::ustring retval;
|
||||
#ifdef MODPLUG_TRACKER
|
||||
#if defined(MPT_BUILD_RETRO)
|
||||
retval += UL_(" RETRO");
|
||||
#endif // MPT_BUILD_RETRO
|
||||
if(Version::Current().IsTestVersion())
|
||||
{
|
||||
retval += UL_(" TEST");
|
||||
}
|
||||
#endif // MODPLUG_TRACKER
|
||||
if(IsDebugBuild())
|
||||
{
|
||||
retval += UL_(" DEBUG");
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
mpt::ustring GetBuildFeaturesString()
|
||||
{
|
||||
mpt::ustring retval;
|
||||
#ifdef LIBOPENMPT_BUILD
|
||||
retval = UL_("")
|
||||
#if defined(MPT_WITH_ZLIB)
|
||||
UL_(" +ZLIB")
|
||||
#endif
|
||||
#if defined(MPT_WITH_MINIZ)
|
||||
UL_(" +MINIZ")
|
||||
#endif
|
||||
#if !defined(MPT_WITH_ZLIB) && !defined(MPT_WITH_MINIZ)
|
||||
UL_(" -INFLATE")
|
||||
#endif
|
||||
#if defined(MPT_WITH_MPG123)
|
||||
UL_(" +MPG123")
|
||||
#endif
|
||||
#if defined(MPT_WITH_MINIMP3)
|
||||
UL_(" +MINIMP3")
|
||||
#endif
|
||||
#if defined(MPT_WITH_MEDIAFOUNDATION)
|
||||
UL_(" +MF")
|
||||
#endif
|
||||
#if !defined(MPT_WITH_MPG123) && !defined(MPT_WITH_MINIMP3) && !defined(MPT_WITH_MEDIAFOUNDATION)
|
||||
UL_(" -MP3")
|
||||
#endif
|
||||
#if defined(MPT_WITH_OGG) && defined(MPT_WITH_VORBIS) && defined(MPT_WITH_VORBISFILE)
|
||||
UL_(" +VORBIS")
|
||||
#endif
|
||||
#if defined(MPT_WITH_STBVORBIS)
|
||||
UL_(" +STBVORBIS")
|
||||
#endif
|
||||
#if !(defined(MPT_WITH_OGG) && defined(MPT_WITH_VORBIS) && defined(MPT_WITH_VORBISFILE)) && !defined(MPT_WITH_STBVORBIS)
|
||||
UL_(" -VORBIS")
|
||||
#endif
|
||||
#if !defined(NO_PLUGINS)
|
||||
UL_(" +PLUGINS")
|
||||
#else
|
||||
UL_(" -PLUGINS")
|
||||
#endif
|
||||
#if defined(MPT_WITH_DMO)
|
||||
UL_(" +DMO")
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
#ifdef MODPLUG_TRACKER
|
||||
retval += UL_("")
|
||||
#if defined(UNICODE)
|
||||
UL_(" UNICODE")
|
||||
#else
|
||||
UL_(" ANSI")
|
||||
#endif
|
||||
#ifndef MPT_WITH_VST
|
||||
UL_(" NO_VST")
|
||||
#endif
|
||||
#ifndef MPT_WITH_DMO
|
||||
UL_(" NO_DMO")
|
||||
#endif
|
||||
#ifdef NO_PLUGINS
|
||||
UL_(" NO_PLUGINS")
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
mpt::ustring GetBuildCompilerString()
|
||||
{
|
||||
mpt::ustring retval;
|
||||
#if MPT_COMPILER_GENERIC
|
||||
retval += U_("Generic C++11 Compiler");
|
||||
#elif MPT_COMPILER_MSVC
|
||||
#if defined(_MSC_FULL_VER) && defined(_MSC_BUILD) && (_MSC_BUILD > 0)
|
||||
retval += MPT_UFORMAT("Microsoft Compiler {}.{}.{}.{}")
|
||||
( _MSC_FULL_VER / 10000000
|
||||
, mpt::ufmt::dec0<2>((_MSC_FULL_VER / 100000) % 100)
|
||||
, mpt::ufmt::dec0<5>(_MSC_FULL_VER % 100000)
|
||||
, mpt::ufmt::dec0<2>(_MSC_BUILD)
|
||||
);
|
||||
#elif defined(_MSC_FULL_VER)
|
||||
retval += MPT_UFORMAT("Microsoft Compiler {}.{}.{}")
|
||||
( _MSC_FULL_VER / 10000000
|
||||
, mpt::ufmt::dec0<2>((_MSC_FULL_VER / 100000) % 100)
|
||||
, mpt::ufmt::dec0<5>(_MSC_FULL_VER % 100000)
|
||||
);
|
||||
#else
|
||||
retval += MPT_UFORMAT("Microsoft Compiler {}.{}")(MPT_COMPILER_MSVC_VERSION / 100, MPT_COMPILER_MSVC_VERSION % 100);
|
||||
#endif
|
||||
#elif MPT_COMPILER_GCC
|
||||
retval += MPT_UFORMAT("GNU Compiler Collection {}.{}.{}")(MPT_COMPILER_GCC_VERSION / 10000, (MPT_COMPILER_GCC_VERSION / 100) % 100, MPT_COMPILER_GCC_VERSION % 100);
|
||||
#elif MPT_COMPILER_CLANG
|
||||
retval += MPT_UFORMAT("Clang {}.{}.{}")(MPT_COMPILER_CLANG_VERSION / 10000, (MPT_COMPILER_CLANG_VERSION / 100) % 100, MPT_COMPILER_CLANG_VERSION % 100);
|
||||
#else
|
||||
retval += U_("unknown");
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
||||
static mpt::ustring GetRevisionString()
|
||||
{
|
||||
mpt::ustring result;
|
||||
if(Source::GetRevision() == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
result = U_("-r") + mpt::ufmt::val(Source::GetRevision());
|
||||
if(Source::HasMixedRevisions())
|
||||
{
|
||||
result += UL_("!");
|
||||
}
|
||||
if(Source::IsDirty())
|
||||
{
|
||||
result += UL_("+");
|
||||
}
|
||||
if(Source::IsPackage())
|
||||
{
|
||||
result += UL_("p");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
mpt::ustring GetVersionString(FlagSet<Build::Strings> strings)
|
||||
{
|
||||
std::vector<mpt::ustring> result;
|
||||
if(strings[StringVersion])
|
||||
{
|
||||
result.push_back(mpt::ufmt::val(Version::Current()));
|
||||
}
|
||||
if(strings[StringRevision])
|
||||
{
|
||||
if(!IsReleasedBuild())
|
||||
{
|
||||
result.push_back(GetRevisionString());
|
||||
}
|
||||
}
|
||||
if(strings[StringSourceInfo])
|
||||
{
|
||||
const SourceInfo sourceInfo = SourceInfo::Current();
|
||||
if(!sourceInfo.GetUrlWithRevision().empty())
|
||||
{
|
||||
result.push_back(MPT_UFORMAT(" {}")(sourceInfo.GetUrlWithRevision()));
|
||||
}
|
||||
if(!sourceInfo.Date().empty())
|
||||
{
|
||||
result.push_back(MPT_UFORMAT(" ({})")(sourceInfo.Date()));
|
||||
}
|
||||
if(!sourceInfo.GetStateString().empty())
|
||||
{
|
||||
result.push_back(MPT_UFORMAT(" {}")(sourceInfo.GetStateString()));
|
||||
}
|
||||
}
|
||||
if(strings[StringBuildFlags])
|
||||
{
|
||||
if(!IsReleasedBuild())
|
||||
{
|
||||
result.push_back(GetBuildFlagsString());
|
||||
}
|
||||
}
|
||||
if(strings[StringBuildFeatures])
|
||||
{
|
||||
result.push_back(GetBuildFeaturesString());
|
||||
}
|
||||
return mpt::trim(mpt::join_format<mpt::ustring>(result, U_("")));
|
||||
}
|
||||
|
||||
mpt::ustring GetVersionStringPure()
|
||||
{
|
||||
FlagSet<Build::Strings> strings;
|
||||
strings |= Build::StringVersion;
|
||||
strings |= Build::StringRevision;
|
||||
return GetVersionString(strings);
|
||||
}
|
||||
|
||||
mpt::ustring GetVersionStringSimple()
|
||||
{
|
||||
FlagSet<Build::Strings> strings;
|
||||
strings |= Build::StringVersion;
|
||||
strings |= Build::StringRevision;
|
||||
strings |= Build::StringBuildFlags;
|
||||
return GetVersionString(strings);
|
||||
}
|
||||
|
||||
mpt::ustring GetVersionStringExtended()
|
||||
{
|
||||
FlagSet<Build::Strings> strings;
|
||||
strings |= Build::StringVersion;
|
||||
strings |= Build::StringRevision;
|
||||
#ifndef MODPLUG_TRACKER
|
||||
strings |= Build::StringSourceInfo;
|
||||
#endif
|
||||
strings |= Build::StringBuildFlags;
|
||||
#ifdef MODPLUG_TRACKER
|
||||
strings |= Build::StringBuildFeatures;
|
||||
#endif
|
||||
return GetVersionString(strings);
|
||||
}
|
||||
|
||||
mpt::ustring GetURL(Build::Url key)
|
||||
{
|
||||
mpt::ustring result;
|
||||
switch(key)
|
||||
{
|
||||
case Url::Website:
|
||||
#ifdef LIBOPENMPT_BUILD
|
||||
result = U_("https://lib.openmpt.org/");
|
||||
#else
|
||||
result = U_("https://openmpt.org/");
|
||||
#endif
|
||||
break;
|
||||
case Url::Download:
|
||||
#ifdef MODPLUG_TRACKER
|
||||
result = IsReleasedBuild() ? U_("https://openmpt.org/download") : U_("https://builds.openmpt.org/builds/");
|
||||
#else
|
||||
result = U_("https://lib.openmpt.org/libopenmpt/download/");
|
||||
#endif
|
||||
break;
|
||||
case Url::Forum:
|
||||
result = U_("https://forum.openmpt.org/");
|
||||
break;
|
||||
case Url::Bugtracker:
|
||||
result = U_("https://bugs.openmpt.org/");
|
||||
break;
|
||||
case Url::Updates:
|
||||
result = U_("https://openmpt.org/download");
|
||||
break;
|
||||
case Url::TopPicks:
|
||||
result = U_("https://openmpt.org/top_picks");
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
mpt::ustring GetFullCreditsString()
|
||||
{
|
||||
return mpt::ToUnicode(mpt::Charset::UTF8,
|
||||
#ifdef MODPLUG_TRACKER
|
||||
"OpenMPT / Open ModPlug Tracker\n"
|
||||
#else
|
||||
"libopenmpt (based on OpenMPT / Open ModPlug Tracker)\n"
|
||||
#endif
|
||||
"\n"
|
||||
"Copyright \xC2\xA9 2004-2026 OpenMPT Project Developers and Contributors\n"
|
||||
"Copyright \xC2\xA9 1997-2003 Olivier Lapicque\n"
|
||||
"\n"
|
||||
"Developers:\n"
|
||||
"Johannes Schultz (2008-2026)\n"
|
||||
"J\xC3\xB6rn Heusipp (2012-2026)\n"
|
||||
"Ahti Lepp\xC3\xA4nen (2005-2011)\n"
|
||||
"Robin Fernandes (2004-2007)\n"
|
||||
"Sergiy Pylypenko (2007)\n"
|
||||
"Eric Chavanon (2004-2005)\n"
|
||||
"Trevor Nunes (2004)\n"
|
||||
"Olivier Lapicque (1997-2003)\n"
|
||||
"\n"
|
||||
"Additional contributors:\n"
|
||||
"coda (https://coda.s3m.us/)\n"
|
||||
"cs127 (https://cs127.github.io/)\n"
|
||||
"Jo\xC3\xA3o Baptista de Paula e Silva (https://joaobapt.com/)\n"
|
||||
"kode54 (https://kode54.net/)\n"
|
||||
"Revenant (https://revenant1.net/)\n"
|
||||
"SYRiNX\n"
|
||||
"xaimus (http://xaimus.com/)\n"
|
||||
"zersal\n"
|
||||
"\n"
|
||||
"Thanks to:\n"
|
||||
"\n"
|
||||
"Konstanty for the XMMS-ModPlug resampling implementation\n"
|
||||
"https://modplug-xmms.sourceforge.net/\n"
|
||||
"\n"
|
||||
#ifdef MODPLUG_TRACKER
|
||||
"Geraint Luff for Signalsmith Stretch\n"
|
||||
"https://signalsmith-audio.co.uk/code/stretch/\n"
|
||||
"\n"
|
||||
"Aleksey Vaneev of Voxengo for r8brain sample rate converter\n"
|
||||
"https://github.com/avaneev/r8brain-free-src\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_VST
|
||||
"Hermann Seib for his example VST Host implementation\n"
|
||||
"https://www.hermannseib.com/english/vsthost.htm\n"
|
||||
"\n"
|
||||
"Benjamin \"BeRo\" Rosseaux for his independent VST header\n"
|
||||
"https://blog.rosseaux.net/\n"
|
||||
"\n"
|
||||
#endif
|
||||
"Storlek for all the IT compatibility hints and testcases\n"
|
||||
"as well as the IMF, MDL, OKT and ULT loaders\n"
|
||||
"https://schismtracker.org/\n"
|
||||
"\n"
|
||||
"Sergei \"x0r\" Kolzun for various hints on Scream Tracker 2 compatibility\n"
|
||||
"https://github.com/viiri/st2play\n"
|
||||
"\n"
|
||||
"Laurent Cl\xc3\xA9vy for unofficial MO3 documentation and decompression code\n"
|
||||
"https://github.com/lclevy/unmo3\n"
|
||||
"\n"
|
||||
"Ben \"GreaseMonkey\" Russell for IT sample compression code\n"
|
||||
"https://github.com/iamgreaser/it2everything/\n"
|
||||
"\n"
|
||||
"Antti S. Lankila for Amiga resampler implementation\n"
|
||||
"https://web.archive.org/web/20221228071135/https://bel.fi/alankila/modguide/\n"
|
||||
"\n"
|
||||
"Shayde / Reality Productions for Opal OPL3 emulator\n"
|
||||
"https://www.3eality.com/\n"
|
||||
"\n"
|
||||
"Ryuhei Mori for TinyFFT\n"
|
||||
"https://github.com/ryuhei-mori/tinyfft\n"
|
||||
"\n"
|
||||
#ifdef MPT_WITH_ZLIB
|
||||
"Jean-loup Gailly and Mark Adler for zlib\n"
|
||||
"https://zlib.net/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_MINIZ
|
||||
"Rich Geldreich et al. for miniz\n"
|
||||
"https://github.com/richgel999/miniz\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_LHASA
|
||||
"Simon Howard for lhasa\n"
|
||||
"https://fragglet.github.io/lhasa/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_UNRAR
|
||||
"Alexander L. Roshal for UnRAR\n"
|
||||
"https://rarlab.com/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_ANCIENT
|
||||
"Teemu Suutari for ancient\n"
|
||||
"https://github.com/temisu/ancient\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_PORTAUDIO
|
||||
"PortAudio contributors\n"
|
||||
"https://www.portaudio.com/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_RTAUDIO
|
||||
"Gary P. Scavone, McGill University for RtAudio\n"
|
||||
"https://www.music.mcgill.ca/~gary/rtaudio/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_FLAC
|
||||
"Josh Coalson / Xiph.Org Foundation for libFLAC\n"
|
||||
"https://xiph.org/flac/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_MPG123)
|
||||
"The mpg123 project for libmpg123\n"
|
||||
"https://mpg123.de/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_MINIMP3
|
||||
"Lion (github.com/lieff) for minimp3\n"
|
||||
"https://github.com/lieff/minimp3/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_STBVORBIS
|
||||
"Sean Barrett for stb_vorbis\n"
|
||||
"https://github.com/nothings/stb/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_OGG
|
||||
"Xiph.Org Foundation for libogg\n"
|
||||
"https://xiph.org/ogg/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_VORBIS) || defined(MPT_WITH_LIBVORBISFILE)
|
||||
"Xiph.Org Foundation for libvorbis\n"
|
||||
"https://xiph.org/vorbis/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_OPUS)
|
||||
"Xiph.Org, Skype Limited, Octasic, Jean-Marc Valin, Timothy B. Terriberry,\n"
|
||||
"CSIRO, Gregory Maxwell, Mark Borgerding, Erik de Castro Lopo,\n"
|
||||
"Xiph.Org Foundation, Microsoft Corporation, Broadcom Corporation for libopus\n"
|
||||
"https://opus-codec.org/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_OPUSFILE)
|
||||
"Xiph.Org Foundation and contributors for libopusfile\n"
|
||||
"https://opus-codec.org/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_OPUSENC)
|
||||
"Xiph.Org Foundation, Jean-Marc Valin and contributors for libopusenc\n"
|
||||
"https://opus-codec.org/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_LAME)
|
||||
"The LAME project for LAME\n"
|
||||
"https://lame.sourceforge.io/\n"
|
||||
"\n"
|
||||
#endif
|
||||
#if defined(MPT_WITH_NLOHMANNJSON)
|
||||
"Niels Lohmann et al. for nlohmann-json\n"
|
||||
"https://github.com/nlohmann/json\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MODPLUG_TRACKER
|
||||
"Lennart Poettering and David Henningsson for RealtimeKit\n"
|
||||
"http://git.0pointer.net/rtkit.git/\n"
|
||||
"\n"
|
||||
"Gary P. Scavone for RtMidi\n"
|
||||
"https://www.music.mcgill.ca/~gary/rtmidi/\n"
|
||||
"\n"
|
||||
"Alexander Uckun for decimal input field\n"
|
||||
"https://www.codeproject.com/Articles/21257/_\n"
|
||||
"\n"
|
||||
"\xc3\x9alfur Kolka for application icon, splash and about screen\n"
|
||||
"https://www.behance.net/ulfurkolka\n"
|
||||
"\n"
|
||||
"Nobuyuki for file icon\n"
|
||||
"https://github.com/nobuyukinyuu/\n"
|
||||
"\n"
|
||||
"ESI Audiotechnik GmbH for testing hardware\n"
|
||||
"https://www.esi-audio.com/\n"
|
||||
"\n"
|
||||
#endif
|
||||
"Daniel Collin (emoon/TBL) for providing test infrastructure\n"
|
||||
"https://mastodon.gamedev.place/@daniel_collin\n"
|
||||
"\n"
|
||||
"The people in the ModPlug community for crucial contribution\n"
|
||||
"in the form of ideas, testing and support;\n"
|
||||
"thanks particularly to:\n"
|
||||
"33, 8bitbubsy, AliceLR, Anboi, BooT-SectoR-ViruZ, Bvanoudtshoorn\n"
|
||||
"a11cf0, christofori, cubaxd, Diamond, Ganja, Georg, Goor00,\n"
|
||||
"Harbinger, jmkz, KrazyKatz, LPChip, MiDoRi, Nofold, Rakib, Sam Zen\n"
|
||||
"Skaven, Skilletaudio, Snu, Squirrel Havoc, Teimoso, Waxhead\n"
|
||||
"\n"
|
||||
#ifdef MPT_WITH_VST
|
||||
"VST PlugIn Technology by Steinberg Media Technologies GmbH\n"
|
||||
"\n"
|
||||
#endif
|
||||
#ifdef MPT_WITH_ASIO
|
||||
"ASIO Technology by Steinberg Media Technologies GmbH\n"
|
||||
"\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
mpt::ustring GetLicenseString()
|
||||
{
|
||||
return MPT_UTF8(
|
||||
"Copyright (c) 2004-2026, OpenMPT Project Developers and Contributors" "\n"
|
||||
"Copyright (c) 1997-2003, Olivier Lapicque" "\n"
|
||||
"All rights reserved." "\n"
|
||||
"" "\n"
|
||||
"Redistribution and use in source and binary forms, with or without" "\n"
|
||||
"modification, are permitted provided that the following conditions are met:" "\n"
|
||||
" * Redistributions of source code must retain the above copyright" "\n"
|
||||
" notice, this list of conditions and the following disclaimer." "\n"
|
||||
" * Redistributions in binary form must reproduce the above copyright" "\n"
|
||||
" notice, this list of conditions and the following disclaimer in the" "\n"
|
||||
" documentation and/or other materials provided with the distribution." "\n"
|
||||
" * Neither the name of the OpenMPT project nor the" "\n"
|
||||
" names of its contributors may be used to endorse or promote products" "\n"
|
||||
" derived from this software without specific prior written permission." "\n"
|
||||
"" "\n"
|
||||
"THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"" "\n"
|
||||
"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE" "\n"
|
||||
"IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE" "\n"
|
||||
"DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE" "\n"
|
||||
"FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL" "\n"
|
||||
"DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR" "\n"
|
||||
"SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER" "\n"
|
||||
"CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY," "\n"
|
||||
"OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE" "\n"
|
||||
"OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." "\n"
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace Build
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,397 @@
|
||||
/*
|
||||
* version.h
|
||||
* ---------
|
||||
* Purpose: OpenMPT version handling.
|
||||
* 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 "mptString.h"
|
||||
#include "openmpt/base/FlagSet.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
class Version
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
uint32 m_Version; // e.g. 0x01170208
|
||||
|
||||
public:
|
||||
|
||||
enum class Field
|
||||
{
|
||||
Major,
|
||||
Minor,
|
||||
Patch,
|
||||
Test,
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
static Version Current() noexcept;
|
||||
|
||||
public:
|
||||
|
||||
MPT_CONSTEXPRINLINE Version() noexcept
|
||||
: m_Version(0)
|
||||
{}
|
||||
|
||||
explicit MPT_CONSTEXPRINLINE Version(uint32 version) noexcept
|
||||
: m_Version(version)
|
||||
{}
|
||||
|
||||
explicit MPT_CONSTEXPRINLINE Version(uint8 v1, uint8 v2, uint8 v3, uint8 v4) noexcept
|
||||
: m_Version((static_cast<uint32>(v1) << 24) | (static_cast<uint32>(v2) << 16) | (static_cast<uint32>(v3) << 8) | (static_cast<uint32>(v4) << 0))
|
||||
{}
|
||||
|
||||
public:
|
||||
|
||||
mpt::ustring ToUString() const; // e.g "1.17.02.08"
|
||||
|
||||
// Returns numerical version value from given version string.
|
||||
static Version Parse(const mpt::ustring &s);
|
||||
|
||||
public:
|
||||
|
||||
explicit MPT_CONSTEXPRINLINE operator bool () const noexcept
|
||||
{
|
||||
return m_Version != 0;
|
||||
}
|
||||
MPT_CONSTEXPRINLINE bool operator ! () const noexcept
|
||||
{
|
||||
return m_Version == 0;
|
||||
}
|
||||
|
||||
MPT_CONSTEXPRINLINE uint32 GetRawVersion() const noexcept
|
||||
{
|
||||
return m_Version;
|
||||
}
|
||||
|
||||
MPT_CONSTEXPRINLINE Version Masked(uint32 mask) const noexcept
|
||||
{
|
||||
return Version(m_Version & mask);
|
||||
}
|
||||
|
||||
MPT_CONSTEXPRINLINE uint8 GetField(Field field) const noexcept
|
||||
{
|
||||
return
|
||||
(field == Field::Major) ? static_cast<uint8>((m_Version >> 24) & 0xffu) :
|
||||
(field == Field::Minor) ? static_cast<uint8>((m_Version >> 16) & 0xffu) :
|
||||
(field == Field::Patch) ? static_cast<uint8>((m_Version >> 8) & 0xffu) :
|
||||
(field == Field::Test ) ? static_cast<uint8>((m_Version >> 0) & 0xffu) :
|
||||
0u;
|
||||
}
|
||||
|
||||
// Return a version without build number (the last number in the version).
|
||||
// The current versioning scheme uses this number only for test builds, and it should be 00 for official builds,
|
||||
// So sometimes it might be wanted to do comparisons without the build number.
|
||||
Version WithoutTestNumber() const noexcept;
|
||||
|
||||
Version WithoutPatchOrTestNumbers() const noexcept;
|
||||
|
||||
public:
|
||||
|
||||
// Return a OpenMPT version string suitable for file format tags
|
||||
mpt::ustring GetOpenMPTVersionString() const; // e.g. "OpenMPT 1.17.02.08"
|
||||
|
||||
// Returns true if a given version number is from a test build, false if it's a release build.
|
||||
bool IsTestVersion() const noexcept;
|
||||
|
||||
public:
|
||||
|
||||
struct LiteralParser
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Work-around for GCC 5 which complains about instanciating non-literal type inside a constexpr function when using mpt::constexpr_throw(std::runtime_error("")).
|
||||
struct ParseException {};
|
||||
|
||||
private:
|
||||
|
||||
static MPT_CONSTEXPRINLINE uint8 NibbleFromChar(char x)
|
||||
{
|
||||
return
|
||||
('0' <= x && x <= '9') ? static_cast<uint8>(x - '0' + 0) :
|
||||
('a' <= x && x <= 'z') ? static_cast<uint8>(x - 'a' + 10) :
|
||||
('A' <= x && x <= 'Z') ? static_cast<uint8>(x - 'A' + 10) :
|
||||
mpt::constexpr_throw<uint8>(std::domain_error(""));
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static MPT_CONSTEXPRINLINE Version Parse(const char * str, std::size_t len)
|
||||
{
|
||||
// 0123456789
|
||||
// 1.23.45.67
|
||||
uint8 v[4] = {0, 0, 0, 0};
|
||||
std::size_t field = 0;
|
||||
std::size_t fieldlen = 0;
|
||||
for(std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
char c = str[i];
|
||||
if(c == '.')
|
||||
{
|
||||
if(field >= 3)
|
||||
{
|
||||
mpt::constexpr_throw(ParseException());
|
||||
}
|
||||
if(fieldlen == 0)
|
||||
{
|
||||
mpt::constexpr_throw(ParseException());
|
||||
}
|
||||
field++;
|
||||
fieldlen = 0;
|
||||
} else if(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))
|
||||
{
|
||||
fieldlen++;
|
||||
if(fieldlen > 2)
|
||||
{
|
||||
mpt::constexpr_throw(ParseException());
|
||||
}
|
||||
v[field] <<= 4;
|
||||
v[field] |= NibbleFromChar(c);
|
||||
} else
|
||||
{
|
||||
mpt::constexpr_throw(ParseException());
|
||||
}
|
||||
}
|
||||
if(fieldlen == 0)
|
||||
{
|
||||
mpt::constexpr_throw(ParseException());
|
||||
}
|
||||
return Version(v[0], v[1], v[2], v[3]);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
MPT_CONSTEXPRINLINE bool operator == (const Version &a, const Version &b) noexcept
|
||||
{
|
||||
return a.GetRawVersion() == b.GetRawVersion();
|
||||
}
|
||||
MPT_CONSTEXPRINLINE bool operator != (const Version &a, const Version &b) noexcept
|
||||
{
|
||||
return a.GetRawVersion() != b.GetRawVersion();
|
||||
}
|
||||
MPT_CONSTEXPRINLINE bool operator <= (const Version &a, const Version &b) noexcept
|
||||
{
|
||||
return a.GetRawVersion() <= b.GetRawVersion();
|
||||
}
|
||||
MPT_CONSTEXPRINLINE bool operator >= (const Version &a, const Version &b) noexcept
|
||||
{
|
||||
return a.GetRawVersion() >= b.GetRawVersion();
|
||||
}
|
||||
MPT_CONSTEXPRINLINE bool operator < (const Version &a, const Version &b) noexcept
|
||||
{
|
||||
return a.GetRawVersion() < b.GetRawVersion();
|
||||
}
|
||||
MPT_CONSTEXPRINLINE bool operator > (const Version &a, const Version &b) noexcept
|
||||
{
|
||||
return a.GetRawVersion() > b.GetRawVersion();
|
||||
}
|
||||
|
||||
|
||||
MPT_CONSTEVAL Version operator ""_LiteralVersionImpl (const char * str, std::size_t len)
|
||||
{
|
||||
return Version::LiteralParser::Parse(str, len);
|
||||
}
|
||||
|
||||
// Create Version object from version string and check syntax, all at compile time.
|
||||
// cppcheck false-positive
|
||||
// cppcheck-suppress preprocessorErrorDirective
|
||||
#define MPT_V(strver) MPT_FORCE_CONSTEVAL_VALUE(Version{( strver ## _LiteralVersionImpl ).GetRawVersion()})
|
||||
|
||||
|
||||
|
||||
class SourceInfo
|
||||
{
|
||||
private:
|
||||
mpt::ustring m_Url; // svn repository url (or empty string)
|
||||
int m_Revision; // svn revision (or 0)
|
||||
bool m_IsDirty; // svn working copy is dirty (or false)
|
||||
bool m_HasMixedRevisions; // svn working copy has mixed revisions (or false)
|
||||
bool m_IsPackage; // source code originates from a packaged version of the source code
|
||||
mpt::ustring m_Date; // svn date (or empty string)
|
||||
private:
|
||||
SourceInfo();
|
||||
public:
|
||||
static SourceInfo Current();
|
||||
public:
|
||||
const mpt::ustring & Url() const { return m_Url; }
|
||||
int Revision() const { return m_Revision; }
|
||||
bool IsDirty() const { return m_IsDirty; }
|
||||
bool HasMixedRevisions() const { return m_HasMixedRevisions; }
|
||||
bool IsPackage() const { return m_IsPackage; }
|
||||
const mpt::ustring & Date() const { return m_Date; }
|
||||
public:
|
||||
mpt::ustring GetUrlWithRevision() const; // i.e. "https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@1234" or empty string
|
||||
mpt::ustring GetStateString() const; // i.e. "+dirty" or "clean"
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct VersionWithRevision
|
||||
{
|
||||
Version version;
|
||||
uint64 revision;
|
||||
static VersionWithRevision Current();
|
||||
static VersionWithRevision Parse(const mpt::ustring &s);
|
||||
mpt::ustring ToUString() const;
|
||||
constexpr bool HasRevision() const noexcept
|
||||
{
|
||||
return revision != 0;
|
||||
}
|
||||
constexpr bool IsEqualTo(VersionWithRevision other) const noexcept
|
||||
{
|
||||
return version == other.version && revision == other.revision;
|
||||
}
|
||||
constexpr bool IsEquivalentTo(VersionWithRevision other) const noexcept
|
||||
{
|
||||
if(version == other.version && revision == other.revision)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(HasRevision() && other.HasRevision())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return version == other.version;
|
||||
}
|
||||
constexpr bool IsNewerThan(VersionWithRevision other) const noexcept
|
||||
{
|
||||
if(version < other.version)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(version > other.version)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!HasRevision() && !other.HasRevision())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(HasRevision() && other.HasRevision())
|
||||
{
|
||||
if(revision < other.revision)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(revision > other.revision)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
constexpr bool IsOlderThan(VersionWithRevision other) const noexcept
|
||||
{
|
||||
if(version < other.version)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(version > other.version)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(!HasRevision() && !other.HasRevision())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(HasRevision() && other.HasRevision())
|
||||
{
|
||||
if(revision < other.revision)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(revision > other.revision)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace Build
|
||||
{
|
||||
|
||||
// Returns true if all conditions for an official release build are met
|
||||
bool IsReleasedBuild();
|
||||
|
||||
// Return true if this is a debug build with no optimizations
|
||||
bool IsDebugBuild();
|
||||
|
||||
// Return a string decribing the time of the build process (if built from a svn working copy and tsvn was available during build, otherwise it returns the time version.cpp was last rebuild which could be unreliable as it does not get rebuild every time without tsvn)
|
||||
mpt::ustring GetBuildDateString();
|
||||
|
||||
// Return a string decribing some of the build features
|
||||
mpt::ustring GetBuildFeaturesString(); // e.g. " NO_VST NO_DSOUND"
|
||||
|
||||
// Return a string describing the compiler version used for building.
|
||||
mpt::ustring GetBuildCompilerString(); // e.g. "Microsoft Compiler 15.00.20706.01"
|
||||
|
||||
enum Strings
|
||||
{
|
||||
StringsNone = 0,
|
||||
StringVersion = 1<<0, // "1.23.35.45"
|
||||
StringRevision = 1<<2, // "-r1234+"
|
||||
StringSourceInfo = 1<<5, // "https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@1234 (2016-01-02) +dirty"
|
||||
StringBuildFlags = 1<<6, // "TEST DEBUG"
|
||||
StringBuildFeatures = 1<<7, // "NO_VST NO_DSOUND"
|
||||
};
|
||||
MPT_DECLARE_ENUM(Strings)
|
||||
|
||||
// Returns a versions string with the fields selected via @strings.
|
||||
mpt::ustring GetVersionString(FlagSet<Build::Strings> strings);
|
||||
|
||||
// Returns a pure version string
|
||||
mpt::ustring GetVersionStringPure(); // e.g. "1.17.02.08-r1234+"
|
||||
|
||||
// Returns a simple version string
|
||||
mpt::ustring GetVersionStringSimple(); // e.g. "1.17.02.08-r1234+ TEST"
|
||||
|
||||
// Returns Version::CurrentAsString() if the build is a clean release build straight from the repository or an extended string otherwise (if built from a svn working copy and tsvn was available during build)
|
||||
mpt::ustring GetVersionStringExtended(); // e.g. "1.17.02.08-r1234+ DEBUG"
|
||||
|
||||
enum class Url
|
||||
{
|
||||
Website,
|
||||
Download,
|
||||
Forum,
|
||||
Bugtracker,
|
||||
Updates,
|
||||
TopPicks,
|
||||
};
|
||||
// Returns a URL for the respective key.
|
||||
mpt::ustring GetURL(Build::Url key);
|
||||
|
||||
// Returns a multi-line string containing the full credits for the code base
|
||||
mpt::ustring GetFullCreditsString();
|
||||
|
||||
// Returns the OpenMPT license text
|
||||
mpt::ustring GetLicenseString();
|
||||
|
||||
} //namespace Build
|
||||
|
||||
|
||||
|
||||
OPENMPT_NAMESPACE_END
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* versionNumber.h
|
||||
* ---------------
|
||||
* Purpose: OpenMPT version number.
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
|
||||
// Version definitions. The only thing that needs to be changed when changing version number.
|
||||
#define VER_MAJORMAJOR 1
|
||||
#define VER_MAJOR 32
|
||||
#define VER_MINOR 10
|
||||
#define VER_MINORMINOR 00
|
||||
Vendored
+29017
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,368 @@
|
||||
AC_INIT([libopenmpt], [0.8.7+release.autotools], [https://bugs.openmpt.org/], [libopenmpt], [https://lib.openmpt.org/])
|
||||
AC_PREREQ([2.69])
|
||||
# we do want 2.70, but distributions are not ready yet
|
||||
#AC_PREREQ([2.70])
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_FILES([Makefile libopenmpt/libopenmpt.pc Doxyfile])
|
||||
|
||||
AM_INIT_AUTOMAKE([1.11 -Wall -Werror foreign subdir-objects])
|
||||
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
|
||||
AM_PROG_AR
|
||||
|
||||
LT_INIT
|
||||
|
||||
AC_SYS_LARGEFILE
|
||||
|
||||
PKG_PROG_PKG_CONFIG([0.24])
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
AC_PROG_CXX
|
||||
AC_PROG_INSTALL
|
||||
|
||||
# We need C++17 support.
|
||||
AX_CXX_COMPILE_STDCXX([23], [noext], [optional])
|
||||
AS_IF([test "x$HAVE_CXX23" != "x1"],
|
||||
[
|
||||
AX_CXX_COMPILE_STDCXX([20], [noext], [optional])
|
||||
AS_IF([test "x$HAVE_CXX20" != "x1"],
|
||||
[
|
||||
AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
|
||||
],[]
|
||||
)
|
||||
],[]
|
||||
)
|
||||
|
||||
GLOBAL_CPPFLAGS=
|
||||
GLOBAL_CFLAGS=
|
||||
GLOBAL_CXXFLAGS=
|
||||
|
||||
AC_LANG_PUSH([C])
|
||||
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [GLOBAL_CFLAGS="$GLOBAL_CFLAGS -fvisibility=hidden"])
|
||||
AX_CFLAGS_WARN_ALL
|
||||
AC_LANG_POP([C])
|
||||
|
||||
AC_LANG_PUSH([C++])
|
||||
AX_CHECK_COMPILE_FLAG([-fvisibility=hidden], [GLOBAL_CXXFLAGS="$GLOBAL_CXXFLAGS -fvisibility=hidden"])
|
||||
AX_CXXFLAGS_WARN_ALL
|
||||
AC_LANG_POP([C++])
|
||||
|
||||
AX_CXX_EXCEPTIONS
|
||||
AX_CXX_RTTI
|
||||
|
||||
AX_PTHREAD([
|
||||
LIBS="$PTHREAD_LIBS $LIBS"
|
||||
GLOBAL_CFLAGS="$GLOBAL_CFLAGS $PTHREAD_CFLAGS"
|
||||
GLOBAL_CXXFLAGS="$GLOBAL_CXXFLAGS $PTHREAD_CFLAGS"
|
||||
#CC="$PTHREAD_CC"
|
||||
#CXX="$PTHREAD_CXX"
|
||||
],
|
||||
[]
|
||||
)
|
||||
|
||||
# work-around <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115049>
|
||||
# This is somewhat pessimistic, but necessary for GCC 8 or earlier,
|
||||
# which we still support and where we cannot use #pragma GCC optimize.
|
||||
AC_LANG_PUSH([C])
|
||||
AX_CHECK_COMPILE_FLAG([-fno-ipa-ra], [GLOBAL_CFLAGS="$GLOBAL_CFLAGS -fno-ipa-ra"])
|
||||
AX_CFLAGS_WARN_ALL
|
||||
AC_LANG_POP([C])
|
||||
AC_LANG_PUSH([C++])
|
||||
AX_CHECK_COMPILE_FLAG([-fno-ipa-ra], [GLOBAL_CXXFLAGS="$GLOBAL_CXXFLAGS -fno-ipa-ra"])
|
||||
AX_CXXFLAGS_WARN_ALL
|
||||
AC_LANG_POP([C++])
|
||||
|
||||
|
||||
AC_SUBST([GLOBAL_CPPFLAGS])
|
||||
AC_SUBST([GLOBAL_CFLAGS])
|
||||
AC_SUBST([GLOBAL_CXXFLAGS])
|
||||
|
||||
|
||||
LIBOPENMPT_LTVER_CURRENT=5
|
||||
LIBOPENMPT_LTVER_REVISION=5
|
||||
LIBOPENMPT_LTVER_AGE=5
|
||||
AC_SUBST([LIBOPENMPT_LTVER_CURRENT])
|
||||
AC_SUBST([LIBOPENMPT_LTVER_REVISION])
|
||||
AC_SUBST([LIBOPENMPT_LTVER_AGE])
|
||||
|
||||
AC_DEFINE([MPT_SVNURL], ["https://source.openmpt.org/svn/openmpt/tags/libopenmpt-0.8.7"], [svn version])
|
||||
AC_DEFINE([MPT_SVNVERSION], ["25325"], [svn version])
|
||||
AC_DEFINE([MPT_SVNDATE], ["2026-05-17T11:08:12.701337Z"], [svn date])
|
||||
AC_DEFINE([MPT_PACKAGE], [true], [is package])
|
||||
|
||||
|
||||
AC_ARG_VAR(CXXSTDLIB_PCLIBSPRIVATE, [C++ standard library (or libraries) required for static linking. This will be put in the pkg-config file libopenmpt.pc Libs.private field and used for nothing else.])
|
||||
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
# work-around NetBSD toolchain not understanding transitive shared object dependencies at all
|
||||
AS_CASE([$host_os],
|
||||
[netbsd*], [LIBS="$LIBS -lstdc++"],
|
||||
[]
|
||||
)
|
||||
|
||||
AS_CASE([$host_os],
|
||||
[mingw32*],[
|
||||
LIBOPENMPT_WIN32_LIBS=
|
||||
LIBOPENMPT_LIBS_PRIVATE_WIN32=
|
||||
LIBOPENMPTTEST_WIN32_LIBS="-lole32 -lrpcrt4"
|
||||
OPENMPT123_WIN32_LIBS=-lwinmm
|
||||
WIN32_CPPFLAGS="-D_UNICODE -DNOMINMAX"
|
||||
WIN32_CXXFLAGS="-municode -mthreads"
|
||||
WIN32_CFLAGS="-municode -mthreads"
|
||||
WIN32_CONSOLE_CXXFLAGS=-mconsole
|
||||
WIN32_CONSOLE_CFLAGS=-mconsole
|
||||
],
|
||||
[
|
||||
LIBOPENMPT_WIN32_LIBS=
|
||||
LIBOPENMPT_LIBS_PRIVATE_WIN32=
|
||||
LIBOPENMPTTEST_WIN32_LIBS=
|
||||
OPENMPT123_WIN32_LIBS=
|
||||
WIN32_CPPFLAGS=
|
||||
WIN32_CXXFLAGS=
|
||||
WIN32_CFLAGS=
|
||||
WIN32_CONSOLE_CXXFLAGS=
|
||||
WIN32_CONSOLE_CFLAGS=
|
||||
]
|
||||
)
|
||||
AC_SUBST([LIBOPENMPT_WIN32_LIBS])
|
||||
AC_SUBST([LIBOPENMPTTEST_WIN32_LIBS])
|
||||
AC_SUBST([OPENMPT123_WIN32_LIBS])
|
||||
AC_SUBST([WIN32_CPPFLAGS])
|
||||
AC_SUBST([WIN32_CXXFLAGS])
|
||||
AC_SUBST([WIN32_CFLAGS])
|
||||
AC_SUBST([WIN32_CONSOLE_CXXFLAGS])
|
||||
AC_SUBST([WIN32_CONSOLE_CFLAGS])
|
||||
|
||||
LIBOPENMPT_REQUIRES_PRIVATE=
|
||||
LIBOPENMPT_LIBS_PRIVATE=
|
||||
|
||||
# Required libopenmpt dependency: zlib
|
||||
ZLIB_PKG=
|
||||
AC_ARG_WITH([zlib], AS_HELP_STRING([--without-zlib], [Disable use of zlib.]))
|
||||
AS_IF([test "x$with_zlib" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([ZLIB], [zlib],
|
||||
[
|
||||
ZLIB_PKG=zlib
|
||||
ZLIB_CFLAGS="-DMPT_WITH_ZLIB $ZLIB_CFLAGS"
|
||||
], [AC_MSG_ERROR([Unable to find zlib.])])
|
||||
]
|
||||
)
|
||||
|
||||
# Required libopenmpt dependency: mpg123
|
||||
MPG123_PKG=
|
||||
AC_ARG_WITH([mpg123], AS_HELP_STRING([--without-mpg123], [Disable use of libmpg123.]))
|
||||
AS_IF([test "x$with_mpg123" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([MPG123], [libmpg123 >= 1.14.0],
|
||||
[
|
||||
MPG123_PKG=libmpg123
|
||||
MPG123_CFLAGS="-DMPT_WITH_MPG123 $MPG123_CFLAGS"
|
||||
], [AC_MSG_ERROR([Unable to find libmpg123.])])
|
||||
]
|
||||
)
|
||||
|
||||
# Required libopenmpt dependency: ogg
|
||||
OGG_PKG=
|
||||
AC_ARG_WITH([ogg], AS_HELP_STRING([--without-ogg], [Disable use of libogg.]))
|
||||
AS_IF([test "x$with_ogg" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([OGG], [ogg],
|
||||
[
|
||||
OGG_PKG=ogg
|
||||
OGG_CFLAGS="-DMPT_WITH_OGG $OGG_CFLAGS"
|
||||
], [AC_MSG_ERROR([Unable to find libogg.])])
|
||||
]
|
||||
)
|
||||
|
||||
# Required libopenmpt dependency: vorbis
|
||||
VORBIS_PKG=
|
||||
AC_ARG_WITH([vorbis], AS_HELP_STRING([--without-vorbis], [Disable use of libvorbis.]))
|
||||
AS_IF([test "x$with_vorbis" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([VORBIS], [vorbis],
|
||||
[
|
||||
VORBIS_PKG=vorbis
|
||||
VORBIS_CFLAGS="-DMPT_WITH_VORBIS $VORBIS_CFLAGS"
|
||||
], [AC_MSG_ERROR([Unable to find libvorbis.])])
|
||||
]
|
||||
)
|
||||
|
||||
# Required libopenmpt dependency: vorbisfile
|
||||
VORBISFILE_PKG=
|
||||
AC_ARG_WITH([vorbisfile], AS_HELP_STRING([--without-vorbisfile], [Disable use of libvorbisfile.]))
|
||||
AS_IF([test "x$with_vorbisfile" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([VORBISFILE], [vorbisfile],
|
||||
[
|
||||
VORBISFILE_PKG=vorbisfile
|
||||
VORBISFILE_CFLAGS="-DMPT_WITH_VORBISFILE $VORBISFILE_CFLAGS"
|
||||
], [AC_MSG_ERROR([Unable to find libvorbisfile.])])
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
LIBOPENMPT_REQUIRES_PRIVATE="$ZLIB_PKG $MPG123_PKG $OGG_PKG $VORBIS_PKG $VORBISFILE_PKG"
|
||||
LIBOPENMPT_LIBS_PRIVATE="$CXXSTDLIB_PCLIBSPRIVATE $LIBOPENMPT_LIBS_PRIVATE_WIN32"
|
||||
AC_SUBST([LIBOPENMPT_REQUIRES_PRIVATE])
|
||||
AC_SUBST([LIBOPENMPT_LIBS_PRIVATE])
|
||||
|
||||
|
||||
# openmpt123
|
||||
AC_ARG_ENABLE([openmpt123], AS_HELP_STRING([--disable-openmpt123], [Disable the openmpt123 command line player.]))
|
||||
AM_CONDITIONAL([ENABLE_OPENMPT123], [test "x$enable_openmpt123" != "xno"])
|
||||
|
||||
|
||||
# examples
|
||||
AC_ARG_ENABLE([examples], AS_HELP_STRING([--disable-examples], [Disable the example programs.]))
|
||||
AM_CONDITIONAL([ENABLE_EXAMPLES], [test "x$enable_examples" != "xno"])
|
||||
|
||||
|
||||
# tests
|
||||
AC_ARG_ENABLE([tests], AS_HELP_STRING([--disable-tests], [Disable the test suite.]))
|
||||
AM_CONDITIONAL([ENABLE_TESTS], [test "x$enable_tests" != "xno"])
|
||||
|
||||
|
||||
# Optional openmpt123 dependency
|
||||
AC_ARG_WITH([pulseaudio], AS_HELP_STRING([--with-pulseaudio], [Enable use of libpulse and libpulse-simple (enabled by default on Linux).]))
|
||||
AS_IF([test "x$enable_openmpt123" != "xno"],[
|
||||
AS_CASE([$host_os],
|
||||
[linux*],[
|
||||
AS_IF([test "x$with_pulseaudio" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([PULSEAUDIO], [libpulse libpulse-simple],
|
||||
[
|
||||
have_pulseaudio=1
|
||||
PULSEAUDIO_CFLAGS="-DMPT_WITH_PULSEAUDIO $PULSEAUDIO_CFLAGS"
|
||||
],
|
||||
[
|
||||
have_pulseaudio=0
|
||||
AC_MSG_ERROR([Unable to find libpulse and/or libpulse-simple.])
|
||||
]
|
||||
)
|
||||
],
|
||||
[
|
||||
have_pulseaudio=0
|
||||
]
|
||||
)
|
||||
;;
|
||||
*)
|
||||
AS_IF([test "x$with_pulseaudio" = "xyes"],
|
||||
[
|
||||
PKG_CHECK_MODULES([PULSEAUDIO], [libpulse libpulse-simple],
|
||||
[
|
||||
have_pulseaudio=1
|
||||
PULSEAUDIO_CFLAGS="-DMPT_WITH_PULSEAUDIO $PULSEAUDIO_CFLAGS"
|
||||
],
|
||||
[
|
||||
have_pulseaudio=0
|
||||
AC_MSG_ERROR([Unable to find libpulse and/or libpulse-simple.])
|
||||
]
|
||||
)
|
||||
],
|
||||
[
|
||||
have_pulseaudio=0
|
||||
]
|
||||
)
|
||||
],
|
||||
[]
|
||||
)
|
||||
],[have_pulseaudio=0])
|
||||
|
||||
# Optional openmpt123 and examples dependency
|
||||
AC_ARG_WITH([portaudio], AS_HELP_STRING([--without-portaudio], [Disable use of libportaudio.]))
|
||||
AS_IF([test "x$enable_openmpt123$enable_examples" != "xnono"],[
|
||||
AS_IF([test "x$with_portaudio" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([PORTAUDIO], [portaudio-2.0],
|
||||
[
|
||||
have_portaudio=1
|
||||
PORTAUDIO_CFLAGS="-DMPT_WITH_PORTAUDIO $PORTAUDIO_CFLAGS"
|
||||
],
|
||||
[
|
||||
have_portaudio=0
|
||||
AC_MSG_ERROR([Unable to find libportaudio.])
|
||||
]
|
||||
)
|
||||
],
|
||||
[
|
||||
have_portaudio=0
|
||||
]
|
||||
)
|
||||
],[have_portaudio=0])
|
||||
AM_CONDITIONAL([HAVE_PORTAUDIO], [test x$have_portaudio = x1])
|
||||
|
||||
# Optional examples dependency: PortAudio C++
|
||||
AC_ARG_WITH([portaudiocpp], AS_HELP_STRING([--without-portaudiocpp], [Disable use of libportaudiocpp.]))
|
||||
AS_IF([test "x$enable_examples" != "xno"],[
|
||||
AS_IF([test "x$with_portaudiocpp" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([PORTAUDIOCPP], [portaudiocpp],
|
||||
[
|
||||
have_portaudiocpp=1
|
||||
PORTAUDIOCPP_CFLAGS="-DMPT_WITH_PORTAUDIOCPP $PORTAUDIOCPP_CFLAGS"
|
||||
],
|
||||
[
|
||||
have_portaudiocpp=0
|
||||
AC_MSG_WARN([Unable to find libportaudiocpp.])
|
||||
]
|
||||
)
|
||||
],
|
||||
[
|
||||
have_portaudiocpp=0
|
||||
]
|
||||
)
|
||||
],[have_portaudiocpp=0])
|
||||
AM_CONDITIONAL([HAVE_PORTAUDIOCPP], [test x$have_portaudiocpp = x1])
|
||||
|
||||
# Optional disabled openmpt123 dependency: libsdl2
|
||||
AC_ARG_WITH([sdl2], AS_HELP_STRING([--with-sdl2], [Enable use of libsdl2.]))
|
||||
AS_IF([test "x$enable_openmpt123" != "xno"],[
|
||||
AS_IF([test "x$with_sdl2" = "xyes"],
|
||||
[
|
||||
PKG_CHECK_MODULES([SDL2], [sdl2 >= 2.0.4], [SDL2_CFLAGS="-DMPT_WITH_SDL2 $SDL2_CFLAGS"], [AC_MSG_ERROR([Unable to find libsdl2.])])
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
# Optional openmpt123 dependency: libsndfile
|
||||
AC_ARG_WITH([sndfile], AS_HELP_STRING([--without-sndfile], [Disable use of libsndfile.]))
|
||||
AS_IF([test "x$enable_openmpt123" != "xno"],[
|
||||
AS_IF([test "x$with_sndfile" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([SNDFILE], [sndfile], [SNDFILE_CFLAGS="-DMPT_WITH_SNDFILE $SNDFILE_CFLAGS"], [AC_MSG_ERROR([Unable to find libsndfile.])])
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
# Optional openmpt123 dependency: libFLAC
|
||||
AC_ARG_WITH([flac], AS_HELP_STRING([--without-flac], [Disable use of libflac.]))
|
||||
AS_IF([test "x$enable_openmpt123" != "xno"],[
|
||||
AS_IF([test "x$with_flac" != "xno"],
|
||||
[
|
||||
PKG_CHECK_MODULES([FLAC], [flac >= 1.3.0], [FLAC_CFLAGS="-DMPT_WITH_FLAC $FLAC_CFLAGS"], [AC_MSG_ERROR([Unable to find libflac >= 1.3.0.])])
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
DX_DOXYGEN_FEATURE(ON)
|
||||
DX_DOT_FEATURE(OFF)
|
||||
DX_HTML_FEATURE(ON)
|
||||
|
||||
DX_MAN_FEATURE(OFF)
|
||||
DX_CHM_FEATURE(OFF)
|
||||
DX_CHI_FEATURE(OFF)
|
||||
DX_RTF_FEATURE(OFF)
|
||||
DX_XML_FEATURE(OFF)
|
||||
DX_PDF_FEATURE(OFF)
|
||||
DX_PS_FEATURE(OFF)
|
||||
|
||||
DX_INIT_DOXYGEN([libopenmpt], [Doxyfile], [doxygen-doc])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
+29017
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,43 @@
|
||||
|
||||
Contributing
|
||||
============
|
||||
|
||||
OpenMPT, libopenmpt, openmpt123, xmp-openmpt and in_openmpt are developed in
|
||||
the Subversion repository at
|
||||
[https://source.openmpt.org/browse/openmpt/trunk/OpenMPT/](https://source.openmpt.org/browse/openmpt/trunk/OpenMPT/).
|
||||
Patches can be provided either against this Subversion repository or against our
|
||||
GitHub mirror at
|
||||
[https://github.com/OpenMPT/openmpt/](https://github.com/OpenMPT/openmpt/).
|
||||
|
||||
We do not have a developer mailing list. Discussions about new features or
|
||||
problems can happen at:
|
||||
* [Issue Tracker](https://bugs.openmpt.org/), preferred for specific bug
|
||||
reports or bug fixes and feature development discussion
|
||||
* [Forum](https://forum.openmpt.org/), preferred for long-term discussion of
|
||||
new features or specific questions about development
|
||||
* [IRC channel (`Libera.Chat/#openmpt`)](ircs://irc.libera.chat:6697/#openmpt),
|
||||
preferred for shorter questions
|
||||
* [GitHub pull requests](https://github.com/OpenMPT/openmpt/pulls), please
|
||||
only use for rather tiny fixes, see below
|
||||
|
||||
For patch submissions, please also see
|
||||
[OpenMPT style guide](openmpt_styleguide.md) and
|
||||
[libopenmpt style guide](libopenmpt_styleguide.md).
|
||||
|
||||
### Contributing via GitHub
|
||||
|
||||
As OpenMPT is developed in a Subversion repository and the GitHub repository is
|
||||
just mirrored from that, we cannot directly take pull requests via GitHub. We
|
||||
recognize that, especially for tiny bug fixes, the burden to choose a different
|
||||
way than GitHub for contributing can be too high. Thus, we will of course react,
|
||||
give feedback, and take patches also via GitHub pull requests. However, as the
|
||||
GitHub repository is strictly downstream from our Subversion repository (and
|
||||
this will not change, due to considerable complications when synchronizing this
|
||||
two-way), we cannot directly merge pull requests on GitHub. We will merge
|
||||
contributions to our Subversion repository, which will then in turn be mirrored
|
||||
to GitHub automatically, after which we will close the pull request. Authorship
|
||||
attribution in git relies on the email address used in the commit header, which
|
||||
is not how it usually works in Subversion. We will thus add an additional line
|
||||
to the commit message in the form of `Patch-by: John Doe <[email protected]>`. If
|
||||
you prefer to be attributed with your nickname and/or without your email
|
||||
address, that would also be fine for us.
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,126 @@
|
||||
|
||||
Dependencies {#dependencies}
|
||||
============
|
||||
|
||||
|
||||
Dependencies
|
||||
------------
|
||||
|
||||
### libopenmpt
|
||||
|
||||
* Supported compilers for building libopenmpt:
|
||||
* **Microsoft Visual Studio 2019** or higher, running on a amd64 build
|
||||
system (other target systems are supported)
|
||||
|
||||
Please note that we do not support building with a later Visual Studio
|
||||
installation with an earlier compiler version. This is because, while
|
||||
later Visual Studio versions allow installing earlier compilers to be
|
||||
available via the later version's environment, in this configuration,
|
||||
the earlier compiler will still use the later C and C++ runtime's
|
||||
headers and implementation, which significantly increases the matrix of
|
||||
possible configurations to test.
|
||||
|
||||
* **Microsoft Visual Studio 2017 XP targeting toolset**
|
||||
* **GCC 7.1** or higher
|
||||
* **Clang 6** or higher
|
||||
* **MinGW-W64 7.1 (posix threading model)** or higher
|
||||
* **MinGW-W64 13.1 (mcfgthread threading model)** or higher
|
||||
* **MinGW-W64 7.1 (win32 threading model)** up to
|
||||
**MinGW-W64 13.0 (win32 threading model)**
|
||||
* **emscripten 3.1.51** or higher
|
||||
* **DJGPP GCC 7.1** or higher
|
||||
* any other **C++23, C++20, or C++17 compliant** compiler
|
||||
|
||||
libopenmpt makes the following assumptions about the C++ implementation
|
||||
used for building:
|
||||
* `std::numeric_limits<unsigned char>::digits == 8` (enforced by
|
||||
static_assert)
|
||||
* existence of `std::uintptr_t` (enforced by static_assert)
|
||||
* in C++23/C++20 mode, `std::endian::little != std::endian::big`
|
||||
(enforced by static_assert)
|
||||
* `wchar_t` encoding is either UTF-16 or UTF-32 (implicitly assumed)
|
||||
* representation of basic source character set is ASCII (implicitly
|
||||
assumed)
|
||||
* representation of basic source character set is identical in char
|
||||
and `wchar_t` (implicitly assumed)
|
||||
|
||||
libopenmpt does not rely on any specific implementation defined or
|
||||
undefined behaviour (if it does, that's a bug in libopenmpt). In
|
||||
particular:
|
||||
* `char` can be `signed` or `unsigned`
|
||||
* shifting signed values is implementation defined
|
||||
* `signed` integer overflow is undefined
|
||||
* `float` and `double` can be non-IEEE754
|
||||
|
||||
libopenmpt can optionally support certain incomplete C++
|
||||
implementations:
|
||||
* platforms without `wchar_t` support (like DJGPP)
|
||||
* platforms without working `std::random_device` (like Emscripten when
|
||||
running in `AudioWorkletProcessor` context)
|
||||
* platforms without working `std::high_resolution_clock` (like
|
||||
Emscripten when running in `AudioWorkletProcessor` context)
|
||||
|
||||
* Required compilers to use libopenmpt:
|
||||
* Any **C89** / **C99** / **C11** / **C17** / **C23** compatible compiler
|
||||
should work with the C API as long as a **C99** compatible **stdint.h**
|
||||
is available.
|
||||
* Any **C++23**, **C++20**, or **C++17** compatible compiler should work
|
||||
with the C++ API.
|
||||
* **J2B** support requires an inflate (deflate decompression) implementation:
|
||||
* **zlib** (or **miniz** can be used internally)
|
||||
* **MO3** support requires:
|
||||
* **libmpg123 >= 1.14.0** (or **minimp3** can be used internally)
|
||||
* **libogg**, **libvorbis**, and **libvorbisfile** (or **stb_vorbis** can
|
||||
be used internally)
|
||||
* Building on Unix-like systems requires:
|
||||
* **GNU make**
|
||||
* **pkg-config**
|
||||
* The Autotools-based build system requires:
|
||||
* **pkg-config 0.24** or higher
|
||||
* **zlib**
|
||||
* **doxygen**
|
||||
|
||||
### openmpt123
|
||||
|
||||
* Live sound output requires one of:
|
||||
* **PulseAudio**
|
||||
* **SDL 2**
|
||||
* **PortAudio v19**
|
||||
* **Win32**
|
||||
* **liballegro 4.2** on DJGPP/DOS
|
||||
|
||||
|
||||
Optional dependencies
|
||||
---------------------
|
||||
|
||||
### libopenmpt
|
||||
|
||||
* **doxygen 1.8** or higher is required to build the documentation.
|
||||
|
||||
### openmpt123
|
||||
|
||||
* Rendering to PCM files can use:
|
||||
* **FLAC 1.3** or higher
|
||||
* **libsndfile**
|
||||
* **Win32** for WAVE
|
||||
* raw PCM has no external dependencies
|
||||
* **help2man** is required to build the documentation.
|
||||
|
||||
|
||||
Source packages
|
||||
---------------
|
||||
|
||||
Building the source packages additionally requires:
|
||||
* 7z (7-zip)
|
||||
* autoconf
|
||||
* autoconf-archive
|
||||
* automake
|
||||
* awk (mawk)
|
||||
* git
|
||||
* gzip
|
||||
* help2man
|
||||
* libtool
|
||||
* subversion
|
||||
* tar
|
||||
* xpath (libxml-xpath-perl)
|
||||
* zip
|
||||
@@ -0,0 +1,283 @@
|
||||
|
||||
Getting Started {#gettingstarted}
|
||||
===============
|
||||
|
||||
|
||||
How to compile
|
||||
--------------
|
||||
|
||||
|
||||
### libopenmpt and openmpt123
|
||||
|
||||
- Autotools
|
||||
|
||||
Grab a `libopenmpt-VERSION-autotools.tar.gz` tarball.
|
||||
|
||||
./configure
|
||||
make
|
||||
make check
|
||||
sudo make install
|
||||
|
||||
Cross-compilation is generally supported (although only tested for
|
||||
targetting MinGW-w64).
|
||||
|
||||
Note that some MinGW-w64 distributions come with the `win32` threading model
|
||||
enabled by default instead of the `posix` threading model. The `win32`
|
||||
threading model lacks proper support for C++11 `<thread>` and `<mutex>` as
|
||||
well as thread-safe magic statics. It is recommended to use the `posix`
|
||||
threading model for libopenmpt for this reason. On Debian, the appropriate
|
||||
configure command is
|
||||
`./configure --host=x86_64-w64-mingw32 CC=x86_64-w64-mingw32-gcc-posix CXX=x86_64-w64-mingw32-g++-posix`
|
||||
for 64bit, or
|
||||
`./configure --host=i686-w64-mingw32 CC=i686-w64-mingw32-gcc-posix CXX=i686-w64-mingw32-g++-posix`
|
||||
for 32bit. Other MinGW-w64 distributions may differ.
|
||||
|
||||
- Visual Studio:
|
||||
|
||||
- You will find solutions for Visual Studio in the matching
|
||||
`build/vsVERSIONwinWINDOWSVERSION/` folder.
|
||||
Minimal projects that target Windows 10 UWP are available in
|
||||
`build/vsVERSIONuwp/`.
|
||||
Most projects are supported with any of the mentioned Visual Studio
|
||||
verions, with the following exceptions:
|
||||
|
||||
- in_openmpt: Requires Visual Studio with MFC.
|
||||
|
||||
- xmp-openmpt: Requires Visual Studio with MFC.
|
||||
|
||||
- libopenmpt requires the compile host system to be amd64 or ARM64 when
|
||||
building with Visual Studio.
|
||||
|
||||
- In order to build libopenmpt for Windows XP, the Visual Studio 2017 XP
|
||||
targeting toolset as well as the Windows 8.1 SDK need to be installed.
|
||||
The SDK is optionally included with Visual Studio 2017, but must be
|
||||
separately installed with later Visual Studio versions.
|
||||
|
||||
The Windows 8.1 SDK is available from
|
||||
<https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/>
|
||||
or directly from
|
||||
<https://download.microsoft.com/download/B/0/C/B0C80BA3-8AD6-4958-810B-6882485230B5/standalonesdk/sdksetup.exe>
|
||||
.
|
||||
|
||||
- You will need the Winamp 5 SDK and the XMPlay SDK if you want to
|
||||
compile the plugins for these 2 players. They can be downloaded
|
||||
automatically on Windows 7 or later by just running the
|
||||
`build/download_externals.cmd` script.
|
||||
|
||||
If you do not want to or cannot use this script, you may follow these
|
||||
manual steps instead:
|
||||
|
||||
- Winamp 5 SDK:
|
||||
|
||||
To build libopenmpt as a winamp input plugin, copy the contents of
|
||||
`WA5.55_SDK.exe` to include/winamp/.
|
||||
|
||||
Please visit
|
||||
[winamp.com](http://wiki.winamp.com/wiki/Plug-in_Developer) to
|
||||
download the SDK.
|
||||
You can disable in_openmpt in the solution configuration.
|
||||
|
||||
- XMPlay SDK:
|
||||
|
||||
To build libopenmpt with XMPlay input plugin support, copy the
|
||||
contents of xmp-sdk.zip into include/xmplay/.
|
||||
|
||||
Please visit [un4seen.com](https://www.un4seen.com/xmplay.html) to
|
||||
download the SDK.
|
||||
You can disable xmp-openmpt in the solution configuration.
|
||||
|
||||
- Makefile
|
||||
|
||||
The makefile supports different build environments and targets via the
|
||||
`CONFIG=` parameter directly to the make invocation.
|
||||
Use `make CONFIG=$newconfig clean` when switching between different configs
|
||||
because the makefile cleans only intermediates and target that are active
|
||||
for the current config and no configuration state is kept around across
|
||||
invocations.
|
||||
|
||||
- native build:
|
||||
|
||||
Simply run
|
||||
|
||||
make
|
||||
|
||||
which will try to guess the compiler based on your operating system.
|
||||
|
||||
- gcc or clang (on Unix-like systems, including Mac OS X with MacPorts,
|
||||
and Haiku (32-bit Hybrid and 64-bit)):
|
||||
|
||||
The Makefile requires pkg-config for native builds.
|
||||
For sound output in openmpt123, PortAudio or SDL is required.
|
||||
openmpt123 can optionally use libflac and libsndfile to render PCM
|
||||
files to disk.
|
||||
|
||||
When you want to use gcc, run:
|
||||
|
||||
make CONFIG=gcc
|
||||
|
||||
When you want to use clang, it is recommended to do:
|
||||
|
||||
make CONFIG=clang
|
||||
|
||||
- MinGW-w64:
|
||||
|
||||
make CONFIG=mingw-w64 \
|
||||
MINGW_FLAVOUR=[|-posix|-win32] \
|
||||
WINDOWS_ARCH=[x86|amd64] \
|
||||
WINDOWS_FAMILY=[|desktop-app|app|phone-app|pc-app] \
|
||||
WINDOWS_VERSION=[win95|win98|winme|winnt4|win2000|winxp|winxp64|winvista|win7|win8|win8.1|win10]
|
||||
|
||||
- emscripten (on Unix-like systems):
|
||||
|
||||
Run:
|
||||
|
||||
# generates WebAssembly with JavaScript fallback
|
||||
make CONFIG=emscripten EMSCRIPTEN_TARGET=all
|
||||
|
||||
or
|
||||
|
||||
# generates WebAssembly
|
||||
make CONFIG=emscripten EMSCRIPTEN_TARGET=wasm
|
||||
|
||||
or
|
||||
|
||||
# generates JavaScript with compatibility for older VMs
|
||||
make CONFIG=emscripten EMSCRIPTEN_TARGET=js
|
||||
|
||||
Running the test suite on the command line is also supported by using
|
||||
node.js. Depending on how your distribution calls the `node.js` binary,
|
||||
you might have to edit `build/make/config-emscripten.mk`.
|
||||
|
||||
- DJGPP / DOS
|
||||
|
||||
Cross-compilation from Linux systems is supported with DJGPP GCC via
|
||||
|
||||
make CONFIG=djgpp
|
||||
|
||||
`openmpt123` can use liballegro 4.2 for sound output on DJGPP/DOS.
|
||||
liballegro needs to be downloaded into the `libopenmpt` source tree.
|
||||
|
||||
./build/download_externals.sh # download liballegro source
|
||||
make CONFIG=djgpp USE_ALLEGRO42=1
|
||||
|
||||
- afl++:
|
||||
|
||||
To compile libopenmpt with fuzzing instrumentation using afl++, run:
|
||||
|
||||
make CONFIG=afl
|
||||
|
||||
For more detailed instructions, read `contrib/fuzzing/readme.md`.
|
||||
|
||||
- other compilers:
|
||||
|
||||
To compile libopenmpt with other compliant compilers, run:
|
||||
|
||||
make CONFIG=generic
|
||||
|
||||
|
||||
The `Makefile` supports some customizations. You might want to read the top
|
||||
which should get you some possible make settings, like e.g.
|
||||
`make DYNLINK=0` or similar. Cross compiling or different compiler would
|
||||
best be implemented via new `config-*.mk` files.
|
||||
|
||||
The `Makefile` also supports building doxygen documentation by using
|
||||
|
||||
make doc
|
||||
|
||||
Binaries and documentation can be installed systen-wide with
|
||||
|
||||
make PREFIX=/yourprefix install
|
||||
make PREFIX=/yourprefix install-doc
|
||||
|
||||
Some systems (i.e. Linux) require running
|
||||
|
||||
sudo ldconfig
|
||||
|
||||
in order for the system linker to be able to pick up newly installed
|
||||
libraries.
|
||||
|
||||
`PREFIX` defaults to `/usr/local`. A `DESTDIR=` parameter is also
|
||||
supported.
|
||||
|
||||
- Android NDK
|
||||
|
||||
See `build/android_ndk/README.AndroidNDK.txt`.
|
||||
|
||||
|
||||
|
||||
### Building libopenmpt with any other build system
|
||||
|
||||
libopenmpt is very simple to build with any build system of your choice. The
|
||||
only required information is listed below. We currently only support building
|
||||
libopenmpt itself this way, but the test suite and openmpt123 may follow later.
|
||||
|
||||
- language:
|
||||
- C++17 / C++20 / C++23
|
||||
|
||||
- defines:
|
||||
- LIBOPENMPT_BUILD
|
||||
|
||||
- private include directories:
|
||||
- .
|
||||
- common
|
||||
- src
|
||||
|
||||
- files:
|
||||
- common/*.cpp
|
||||
- sounddsp/*.cpp
|
||||
- soundlib/*.cpp
|
||||
- soundlib/plugins/*.cpp
|
||||
- soundlib/plugins/dmo/*.cpp
|
||||
- libopenmpt/*.cpp
|
||||
|
||||
- public include directories:
|
||||
- .
|
||||
|
||||
- public header files:
|
||||
- libopenmpt/libopenmpt.h
|
||||
- libopenmpt/libopenmpt.hpp
|
||||
- libopenmpt/libopenmpt_config.h
|
||||
- libopenmpt/libopenmpt_ext.h
|
||||
- libopenmpt/libopenmpt_ext.hpp
|
||||
- libopenmpt/libopenmpt_version.h
|
||||
- libopenmpt/libopenmpt_stream_callbacks_buffer.h
|
||||
- libopenmpt/libopenmpt_stream_callbacks_fd.h
|
||||
- libopenmpt/libopenmpt_stream_callbacks_file_mingw.h
|
||||
- libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h
|
||||
- libopenmpt/libopenmpt_stream_callbacks_file_posix.h
|
||||
- libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h
|
||||
|
||||
- dependencies:
|
||||
- zlib:
|
||||
- pkg-config
|
||||
- zlib
|
||||
- defines
|
||||
- MPT_WITH_ZLIB
|
||||
- libmpg123:
|
||||
- pkg-config
|
||||
- mpg123
|
||||
- defines
|
||||
- MPT_WITH_MPG123
|
||||
- libogg:
|
||||
- pkg-config
|
||||
- ogg
|
||||
- defines
|
||||
- MPT_WITH_OGG
|
||||
- libvorbis:
|
||||
- pkg-config
|
||||
- vorbis
|
||||
- defines
|
||||
- MPT_WITH_VORBIS
|
||||
- libvorbisfile:
|
||||
- pkg-config
|
||||
- vorbisfile
|
||||
- defines
|
||||
- MPT_WITH_VORBISFILE
|
||||
|
||||
- dll:
|
||||
- build:
|
||||
- defines
|
||||
- LIBOPENMPT_BUILD_DLL
|
||||
- use:
|
||||
- defines
|
||||
- LIBOPENMPT_USE_DLL
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
/*!
|
||||
* \mainpage Contents
|
||||
*
|
||||
* libopenmpt is a cross-platform C++ and C library to decode <a href="https://en.wikipedia.org/wiki/Module_file">tracked music files (modules)</a> into a raw PCM audio stream.
|
||||
*
|
||||
* libopenmpt is based on the player code of the OpenMPT project (Open ModPlug Tracker, <a href="https://openmpt.org/">https://openmpt.org/</a>)
|
||||
*
|
||||
* \section toc Contents
|
||||
* - \ref md_README "README"
|
||||
* - \ref dependencies "Dependencies"
|
||||
* - \ref gettingstarted "Getting Started"
|
||||
* - \ref packaging "Packaging"
|
||||
* - \ref md_doc_contributing "Contributing"
|
||||
* - \ref md_doc_libopenmpt_styleguide "libopenmpt Style Guide"
|
||||
* - \ref md_doc_openmpt_styleguide "OpenMPT Style Guide"
|
||||
* - \ref tests "Tests"
|
||||
* - \ref changelog "Changelog"
|
||||
* - \ref md_doc_module_formats "Implementing new Module Formats"
|
||||
* - <a href="https://bugs.openmpt.org/">Issue Tracker</a>
|
||||
* \subsection toc_apis APIs
|
||||
* - libopenmpt
|
||||
* - \ref libopenmpt "Common Details"
|
||||
* - libopenmpt C++
|
||||
* - \ref libopenmpt_cpp_overview "Overview"
|
||||
* - \ref libopenmpt_cpp "Details"
|
||||
* - libopenmpt C
|
||||
* - \ref libopenmpt_c_overview "Overview"
|
||||
* - \ref libopenmpt_c "Details"
|
||||
* - libopenmpt_ext C++
|
||||
* - \ref libopenmpt_ext_cpp_overview "Overview"
|
||||
* - \ref libopenmpt_ext_cpp "Details"
|
||||
* - libopenmpt_ext C
|
||||
* - \ref libopenmpt_ext_c_overview "Overview"
|
||||
* - \ref libopenmpt_ext_c "Details"
|
||||
*
|
||||
* \section toc_website Website
|
||||
* https://lib.openmpt.org/
|
||||
*
|
||||
* \section toc_license License
|
||||
* \include LICENSE
|
||||
*
|
||||
*/
|
||||
@@ -0,0 +1,38 @@
|
||||
Packaging {#packaging}
|
||||
=========
|
||||
|
||||
|
||||
Packaging
|
||||
---------
|
||||
|
||||
|
||||
### Packaging recommendations for distribution package maintainers
|
||||
|
||||
* libopenmpt (since 0.3) uses SemVer 2.0.0 versioning. See
|
||||
[semver.org](https://semver.org/spec/v2.0.0.html). Clause 4 is ignored for
|
||||
libopenmpt, which means that libopenmpt will also provide API/ABI
|
||||
compatibility semantics for pre-1.0.0 versions as required by SemVer 2.0.0
|
||||
only for post-1.0.0 versions. The SemVer versioning scheme is incompatible
|
||||
with Debian/Ubuntu package versions, however it can easily be processed to
|
||||
be compatible by replacing '-' (hyphen) with '~' (tilde). It is recommended
|
||||
that you use this exact transformation if required.
|
||||
* Use the autotools source package.
|
||||
* Use the default set of dependencies required by the autotools package.
|
||||
* Read \ref libopenmpt_c_staticlinking and thus possibly pass
|
||||
`CXXSTDLIB_PCLIBSPRIVATE` variable to `configure` if appropriate and/or
|
||||
desired.
|
||||
* Run the test suite in your build process.
|
||||
* Send any build system improvement patches upstream.
|
||||
* Do not include the libmodplug emulation layer in the default libopenmpt
|
||||
binary package. Either do not package it at all, or provide a separate
|
||||
package named libopenmpt-modplug or libmodplug-openmpt (or similar), which
|
||||
depends on libopenmpt, provides libmodplug, and conflicts with original
|
||||
libmodplug.
|
||||
* Split openmpt123 into its own binary package because it has more
|
||||
dependencies than libopenmpt itself.
|
||||
* Consider providing an additional openmpt123 package (in addition to the
|
||||
default openmpt123 package with all audio output drivers), built with fewer
|
||||
audio output drivers so it does not transitively depend on X11. Name that
|
||||
package and its executable openmpt123-nox (or whatever else may be common
|
||||
practice in your distribution).
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
|
||||
Tests {#tests}
|
||||
=====
|
||||
|
||||
|
||||
libopenmpt provides some basic unit tests that check the platform for general
|
||||
sanity and do some basic internal functionality testing. The test suite
|
||||
requires a special libopenmpt build that includes file saving functionality
|
||||
which is not included in normal builds. This is handled by all provided build
|
||||
systems automatically.
|
||||
|
||||
### Running Tests
|
||||
|
||||
#### On Unix-like systems
|
||||
|
||||
Compile with
|
||||
|
||||
make $YOURMAKEOPTIONS clean
|
||||
make $YOURMAKEOPTIONS
|
||||
|
||||
and run
|
||||
|
||||
make $YOURMAKEOPTIONS check
|
||||
|
||||
As the build system retains no state between make invocations, you have to
|
||||
provide your make options on every make invocation.
|
||||
|
||||
#### Autotools-based build system
|
||||
|
||||
./configure
|
||||
make check
|
||||
|
||||
#### On Windows
|
||||
|
||||
Using Visual Studio 20??, compile
|
||||
|
||||
build\vs20??\libopenmpt_test.sln
|
||||
|
||||
and run
|
||||
|
||||
bin\$ARCH\libopenmpt_test.exe
|
||||
|
||||
from the root of the source tree.
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
|
||||
libopenmpt Style Guide
|
||||
======================
|
||||
|
||||
|
||||
### libopenmpt
|
||||
|
||||
**Note:**
|
||||
**This applies to `libopenmpt/` and `openmpt123/` directories only.**
|
||||
**Use OpenMPT style otherwise.**
|
||||
|
||||
The code generally tries to follow these conventions, but they are not
|
||||
strictly enforced and there are valid reasons to diverge from these
|
||||
conventions. Using common sense is recommended.
|
||||
|
||||
- In general, the most important thing is to keep style consistent with
|
||||
directly surrounding code.
|
||||
- Use C++ std types when possible, prefer `std::size_t` and `std::int32_t`
|
||||
over `long` or `int`. Do not use C99 std types (e.g. no pure `int32_t`)
|
||||
- Qualify namespaces explicitly, do not use `using`.
|
||||
Members of `namespace openmpt` can be named without full namespace
|
||||
qualification.
|
||||
- Prefer the C++ version in `namespace std` if the same functionality is
|
||||
provided by the C standard library as well. Also, include the C++
|
||||
version of C standard library headers (e.g. use `<cstdio>` instead of
|
||||
`<stdio.h>`.
|
||||
- Do not use ANY locale-dependant C functions. For locale-dependant C++
|
||||
functionaly (especially iostream), always imbue the
|
||||
`std::locale::classic()` locale.
|
||||
- Prefer kernel_style_names over CamelCaseNames.
|
||||
- If a folder (or one of its parent folders) contains .clang-format,
|
||||
use clang-format v3.5 for indenting C++ and C files, otherwise:
|
||||
- `{` are placed at the end of the opening line.
|
||||
- Enclose even single statements in curly braces.
|
||||
- Avoid placing single statements on the same line as the `if`.
|
||||
- Opening parentheses are separated from keywords with a space.
|
||||
- Opening parentheses are not separated from function names.
|
||||
- Place spaces around operators and inside parentheses.
|
||||
- Align `:` and `,` when inheriting or initializing members in a
|
||||
constructor.
|
||||
- The pointer `*` is separated from both the type and the variable name.
|
||||
- Use tabs for identation, spaces for formatting.
|
||||
Tabs should only appear at the very beginning of a line.
|
||||
Do not assume any particular width of the TAB character. If width is
|
||||
important for formatting reasons, use spaces.
|
||||
- Use empty lines at will.
|
||||
- API documentation is done with doxygen.
|
||||
Use general C doxygen for the C API.
|
||||
Use QT-style doxygen for the C++ API.
|
||||
|
||||
#### libopenmpt indentation example
|
||||
|
||||
~~~~{.cpp}
|
||||
namespace openmpt {
|
||||
|
||||
// This is totally meaningless code and just illustrates indentation.
|
||||
|
||||
class foo
|
||||
: public base
|
||||
, public otherbase
|
||||
{
|
||||
|
||||
private:
|
||||
|
||||
std::int32_t x;
|
||||
std::int16_t y;
|
||||
|
||||
public:
|
||||
|
||||
foo()
|
||||
: x(0)
|
||||
, y(-1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int bar() const;
|
||||
|
||||
}; // class foo
|
||||
|
||||
int foo::bar() const {
|
||||
|
||||
for ( int i = 0; i < 23; ++i ) {
|
||||
switch ( x ) {
|
||||
case 2:
|
||||
something( y );
|
||||
break;
|
||||
default:
|
||||
something( ( y - 1 ) * 2 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( x == 12 ) {
|
||||
return -1;
|
||||
} else if ( x == 42 ) {
|
||||
return 1;
|
||||
}
|
||||
return 42;
|
||||
|
||||
}
|
||||
|
||||
} // namespace openmpt
|
||||
~~~~
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
Adding support for new module formats
|
||||
=====================================
|
||||
|
||||
This document describes the basics of writing a new module loader and related
|
||||
work that has to be done. We will not discuss in detail how to write the loader,
|
||||
have a look at existing loaders to get an idea how they work in general.
|
||||
|
||||
General hints
|
||||
-------------
|
||||
* We strive for quality over quantity. The goal is not to support as many module
|
||||
formats as possible, but to support them as well as possible.
|
||||
* Write defensive code. Guard against out-of-bound values, division by zero and
|
||||
similar stuff. libopenmpt is constantly fuzz-tested to catch any crashes, but
|
||||
of course we want our code to be reliable from the start.
|
||||
* Every format should have its own `MODTYPE` flag, unless it can be reasonably
|
||||
represented as a subset of another format (like Ice Tracker ICE files being
|
||||
a subset of ProTracker MOD).
|
||||
* When reading binary structs from the file, use our data types with defined
|
||||
endianness, which can be found in `common/Endianness.h`:
|
||||
* Big-Endian: (u)int8/16/24/32/64be, float32be, float64be
|
||||
* Little-Endian: (u)int8/16/24/32/64le, float32le, float64le
|
||||
|
||||
Entire structs containing integers with defined endianness can be read in one
|
||||
go if they are tagged with `MPT_BINARY_STRUCT` (see existing loaders for an
|
||||
example).
|
||||
* `CSoundFile::ChnSettings` **MUST NOT** be resized after a pattern has been
|
||||
created, as existing patterns will be interpreted incorrectly. For module
|
||||
formats that support per-pattern channel amounts, the maximum number of
|
||||
channels must be determined beforehand.
|
||||
* Strings can be safely handled using:
|
||||
* `FileReader::ReadString` and friends for reading them directly from a file
|
||||
* `mpt::String::ReadBuf` for reading them from a struct or char array
|
||||
|
||||
These functions take care of string padding (zero / space padding) and will
|
||||
avoid reading past the end of the string if there is no terminating null
|
||||
character.
|
||||
* Do not use non-const static variables in your loader. Loaders need to be
|
||||
thread-safe for libopenmpt.
|
||||
* `FileReader` instances may be used to treat a portion of a file as its own
|
||||
independent file (through `FileReader::ReadChunk`). This can be useful with
|
||||
"embedded files" such as WAV or Ogg samples (see MO3 or SymMOD for examples).
|
||||
Container formats such as UMX are another good example for this usage.
|
||||
* Samples *either* use middle-C frequency *or* finetune + transpose. For the few
|
||||
weird formats that use both, it may make sense to translate everything into
|
||||
middle-C frequency.
|
||||
* Add the new `MODTYPE` to `CSoundFile::UseFinetuneAndTranspose` if applicable,
|
||||
and see if any effect handlers in `soundlib/Snd_fx.cpp` need to know the new
|
||||
`MODTYPE`.
|
||||
* Do not rely on hard-coded magic numbers. For example, when comparing if an
|
||||
index is valid for a given array, do not hard-code the array size but rather
|
||||
use `std::size` (or `mpt::array_size` in contexts where `std::size` is not
|
||||
usable) or, for ensuring that char arrays are null-terminated,
|
||||
`mpt::String::SetNullTerminator`. Similarly, do not assume any specific
|
||||
quantities for OpenMPT's constants like MAX_SAMPLES, MAX_PATTERN_ROWS, etc.
|
||||
These may change at any time.
|
||||
* Pay attention to off-by-one errors when comparing against MAX_SAMPLES and
|
||||
MAX_INSTRUMENTS, since sample and instrument numbers are 1-based. Prefer using
|
||||
`CSoundFile::CanAddMoreSamples` and `CSoundFile::CanAddMoreInstruments` to
|
||||
check if a given amount of samples or instruments can be added to the file
|
||||
rather than doing the calculations yourself.
|
||||
* Placement of the loader function in the `ModuleFormatLoaders` array in
|
||||
Sndfile.cpp depends on various factors. In general, module formats that have
|
||||
very bad magic numbers (and thus might cause other formats to get
|
||||
mis-interpreted) should be placed at the bottom of the list. Two notable
|
||||
examples are 669 files, where the first two bytes of the file are "if"
|
||||
(which may e.g. cause a song title starting with if ..." in various other
|
||||
formats to be interpreted as a 669 module), and of course
|
||||
Ultimate SoundTracker modules, which have no magic bytes at all.
|
||||
* Avoid use of functions tagged with `[[deprecated]]`.
|
||||
|
||||
Probing
|
||||
-------
|
||||
libopenmpt provides fast probing functions that can be used by library users
|
||||
to quickly check if a file is most likely playable with libopenmpt, even if only
|
||||
a fraction of the file is available (e.g. when streaming from the internet).
|
||||
|
||||
In order to satisfy these requirements, probing functions should do as little
|
||||
work as possible (e.g. only parse the header of the file), but as much as
|
||||
required to tell with some certainty that the file is really of a certain mod
|
||||
format. However, probing functions should not rely on having access to more than
|
||||
the first `CSoundFile::ProbeRecommendedSize` bytes of the file.
|
||||
|
||||
* Probing functions **must not** allocate any memory on the heap.
|
||||
* Probing functions **must not** return ProbeFailure or ProbeWantMoreData for
|
||||
any file that would normally be accepted by the loader. In particular, this
|
||||
means that any header checks must not be any more aggressive than they would
|
||||
be in the real loader (hence it is a good idea to not copy-paste this code but
|
||||
rather put it in a reusable function), and the minimum additional size passed
|
||||
to `CSoundFile::ProbeAdditionalSize` must not be higher than the biggest size
|
||||
that would cause a hard failure (i.e. returning `false`) in the module loader.
|
||||
* Probing functions **may** return ProbeSuccess for files that would be rejected
|
||||
by a loader after a more thorough inspection. For example, probing functions
|
||||
do not need to verify that all required chunks of an IFF-like file format are
|
||||
actually present, if the header makes it obvious enough that the file is
|
||||
highly likely to be a module.
|
||||
|
||||
Adding loader to the build systems and various other locations
|
||||
--------------------------------------------------------------
|
||||
Apart from writing the module loader itself, there are a couple of other places
|
||||
that need to be updated:
|
||||
* Add loader file to `build/android_ndk/Android.mk`.
|
||||
* Add loader file to `build/autotools/Makefile.am`.
|
||||
* Run `build/regenerate_vs_projects.sh` / `build/regenerate_vs_projects.cmd`
|
||||
(depending on your platform)
|
||||
* Add file extension to `installer/filetypes-*.iss`.
|
||||
* Add file extension to `CTrackApp::OpenModulesDialog` in `mptrack/Mptrack.cpp`
|
||||
as required (e.g. if it's a compressed container format or if it's relevant
|
||||
enough to be mentioned).
|
||||
* Add format information to `soundlib/Tables.cpp`.
|
||||
* Add magic bytes to `contrib/fuzzing/all_formats.dict`.
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
OpenMPT Style Guide
|
||||
===================
|
||||
|
||||
|
||||
### OpenMPT
|
||||
|
||||
**Note:**
|
||||
**This applies to all source code *except* for `libopenmpt/` and `openmpt123/`**
|
||||
**directories.**
|
||||
**Use libopenmpt style otherwise.**
|
||||
|
||||
(see below for an example)
|
||||
|
||||
* Place curly braces at the beginning of the line, not at the end
|
||||
* Generally make use of the custom index types like `SAMPLEINDEX` or
|
||||
`ORDERINDEX` when referring to samples, orders, etc.
|
||||
* When changing playback behaviour, make sure that you use the function
|
||||
`CSoundFile::IsCompatibleMode()` so that modules made with previous versions
|
||||
of MPT still sound correct (if the change is extremely small, this might be
|
||||
unnecessary)
|
||||
* `CamelCase` function and variable names are preferred.
|
||||
|
||||
#### OpenMPT code example
|
||||
|
||||
~~~~{.cpp}
|
||||
void Foo::Bar(int foobar)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
// some code
|
||||
}
|
||||
}
|
||||
~~~~
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
# clang-format 14
|
||||
|
||||
Language: Cpp
|
||||
Standard: c++20
|
||||
|
||||
AccessModifierOffset: -2 #?
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveBitFields: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveMacros: true
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros: []
|
||||
BinPackArguments: true
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: false
|
||||
AfterControlStatement: MultiLine
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
#AfterObjCDeclaration
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: true
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
#BreakAfterJavaFieldAnnotations
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: '' #?
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 2 #?
|
||||
ContinuationIndentWidth: 2 #?
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
EmptyLineAfterAccessModifier: Leave
|
||||
EmptyLineBeforeAccessModifier: Leave
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros: []
|
||||
IfMacros: ['MPT_MAYBE_CONSTANT_IF']
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories: [] #?
|
||||
IncludeIsMainRegex: '' #?
|
||||
IncludeIsMainSourceRegex: '' #?
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: NoIndent
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
#IndentRequiresClause: true
|
||||
#BeforeHash
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: true
|
||||
InsertTrailingCommas: None
|
||||
#JavaImportGroups
|
||||
#JavaScriptQuotes
|
||||
#JavaScriptWrapImports
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
LambdaBodyIndentation: OuterScope
|
||||
MacroBlockBegin: '' #?
|
||||
MacroBlockEnd: '' #?
|
||||
MaxEmptyLinesToKeep: 3
|
||||
NamespaceIndentation: None
|
||||
NamespaceMacros: [] #?
|
||||
#ObjCBinPackProtocolList
|
||||
#ObjCBlockIndentWidth
|
||||
#ObjCBreakBeforeNestedBlockParam
|
||||
#ObjCSpaceAfterProperty
|
||||
#ObjCSpaceBeforeProtocolList
|
||||
PackConstructorInitializers: Never
|
||||
#PenaltyBreakAssignment
|
||||
#PenaltyBreakBeforeFirstCallParameter
|
||||
#PenaltyBreakComment
|
||||
#PenaltyBreakFirstLessLess
|
||||
#PenaltyBreakOpenParenthesis
|
||||
#PenaltyBreakString
|
||||
#PenaltyBreakTemplateDeclaration
|
||||
#PenaltyExcessCharacter
|
||||
#PenaltyIndentedWhitespace
|
||||
#PenaltyReturnTypeOnItsOwnLine
|
||||
PointerAlignment: Middle
|
||||
PPIndentWidth: -1
|
||||
#RawStringFormats
|
||||
QualifierAlignment: Leave
|
||||
#QualifierOrder: ['static', 'inline', 'constexpr', 'volatile', 'const', 'restrict', 'type']
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: false
|
||||
RemoveBracesLLVM: false
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: false
|
||||
#SortJavaStaticImport
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
#AfterRequiresInClause: false
|
||||
#AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: true
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: true
|
||||
SpacesInSquareBrackets: false
|
||||
StatementAttributeLikeMacros: []
|
||||
StatementMacros: [ 'MPT_WARNING', 'MPT_TEST_GROUP_INLINE_IDENTIFIER', 'MPT_TEST_GROUP_INLINE', 'MPT_TEST_GROUP_STATIC' ] #?
|
||||
TabWidth: 2
|
||||
TypenameMacros: [] #?
|
||||
UseCRLF: false
|
||||
UseTab: ForContinuationAndIndentation
|
||||
WhitespaceSensitiveMacros:
|
||||
- MPT_PP_STRINGIFY
|
||||
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* libopenmpt_example_c.c
|
||||
* ----------------------
|
||||
* Purpose: libopenmpt C API example
|
||||
* Notes : PortAudio is used for sound output.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: libopenmpt_example_c SOMEMODULE
|
||||
*/
|
||||
|
||||
#if defined( unix ) || defined( __unix__ ) || defined( __unix )
|
||||
#include <unistd.h>
|
||||
#if defined( _POSIX_VERSION )
|
||||
#if ( _POSIX_VERSION > 0 )
|
||||
#ifndef POSIX
|
||||
#define POSIX
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined( __MINGW32__ ) && !defined( __MINGW64__ )
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libopenmpt/libopenmpt.h>
|
||||
#if OPENMPT_API_VERSION_AT_LEAST( 0, 7, 0 )
|
||||
#if defined( LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW ) && defined( __MINGW32__ )
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file_mingw.h>
|
||||
#elif defined( LIBOPENMPT_STREAM_CALLBACKS_FILE_MSVCRT ) && ( defined( _MSC_VER ) || ( defined( __clang__ ) && defined( _WIN32 ) ) )
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h>
|
||||
#elif defined( LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX ) && defined( POSIX ) && defined( _POSIX_C_SOURCE )
|
||||
#if ( _POSIX_C_SOURCE > 200112L )
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file_posix.h>
|
||||
#else
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
#endif
|
||||
#else
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
#endif
|
||||
#else
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
#endif
|
||||
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wstrict-prototypes"
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
|
||||
#endif
|
||||
#include <portaudio.h>
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
#define BUFFERSIZE 480
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static float left[BUFFERSIZE];
|
||||
static float right[BUFFERSIZE];
|
||||
static float * const buffers[2] = { left, right };
|
||||
static float interleaved_buffer[BUFFERSIZE * 2];
|
||||
static int is_interleaved = 0;
|
||||
|
||||
static void libopenmpt_example_logfunc( const char * message, void * userdata ) {
|
||||
(void)userdata;
|
||||
if ( message ) {
|
||||
fprintf( stderr, "openmpt: %s\n", message );
|
||||
}
|
||||
}
|
||||
|
||||
static int libopenmpt_example_errfunc( int error, void * userdata ) {
|
||||
(void)userdata;
|
||||
(void)error;
|
||||
return OPENMPT_ERROR_FUNC_RESULT_DEFAULT & ~OPENMPT_ERROR_FUNC_RESULT_LOG;
|
||||
}
|
||||
|
||||
static void libopenmpt_example_print_error( const char * func_name, int mod_err, const char * mod_err_str ) {
|
||||
if ( !func_name ) {
|
||||
func_name = "unknown function";
|
||||
}
|
||||
if ( mod_err == OPENMPT_ERROR_OUT_OF_MEMORY ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s\n", "OPENMPT_ERROR_OUT_OF_MEMORY" );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s\n", mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
} else {
|
||||
if ( !mod_err_str ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s failed.\n", func_name );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __clang__ ) && !defined( _MSC_VER )
|
||||
int wmain( int argc, wchar_t * argv[] );
|
||||
#endif
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
int result = 0;
|
||||
FILE * file = 0;
|
||||
openmpt_module * mod = 0;
|
||||
int mod_err = OPENMPT_ERROR_OK;
|
||||
const char * mod_err_str = NULL;
|
||||
size_t count = 0;
|
||||
PaError pa_error = paNoError;
|
||||
int pa_initialized = 0;
|
||||
PaStream * stream = 0;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
if ( wcslen( argv[1] ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
file = _wfopen( argv[1], L"rb" );
|
||||
#else
|
||||
if ( strlen( argv[1] ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
file = fopen( argv[1], "rb" );
|
||||
#endif
|
||||
if ( !file ) {
|
||||
fprintf( stderr, "Error: %s\n", "fopen() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if OPENMPT_API_VERSION_AT_LEAST( 0, 7, 0 )
|
||||
#if defined( LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW ) && defined( __MINGW32__ )
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_mingw_callbacks(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
#elif defined( LIBOPENMPT_STREAM_CALLBACKS_FILE_MSVCRT ) && ( defined( _MSC_VER ) || ( defined( __clang__ ) && defined( _WIN32 ) ) )
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_msvcrt_callbacks(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
#elif defined( LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX ) && defined( POSIX ) && defined( _POSIX_C_SOURCE )
|
||||
#if ( _POSIX_C_SOURCE > 200112L )
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_posix_callbacks(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
#else
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_callbacks2(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
#endif
|
||||
#else
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_callbacks2(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
#endif
|
||||
#else
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_callbacks(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
#endif
|
||||
|
||||
if ( !mod ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_create2()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
goto fail;
|
||||
}
|
||||
openmpt_module_set_error_func( mod, NULL, NULL );
|
||||
|
||||
pa_error = Pa_Initialize();
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_Initialize() failed." );
|
||||
goto fail;
|
||||
}
|
||||
pa_initialized = 1;
|
||||
|
||||
pa_error = Pa_OpenDefaultStream( &stream, 0, 2, paFloat32 | paNonInterleaved, SAMPLERATE, paFramesPerBufferUnspecified, NULL, NULL );
|
||||
if ( pa_error == paSampleFormatNotSupported ) {
|
||||
is_interleaved = 1;
|
||||
pa_error = Pa_OpenDefaultStream( &stream, 0, 2, paFloat32, SAMPLERATE, paFramesPerBufferUnspecified, NULL, NULL );
|
||||
}
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_OpenStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
if ( !stream ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_OpenStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_error = Pa_StartStream( stream );
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_StartStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while ( 1 ) {
|
||||
|
||||
openmpt_module_error_clear( mod );
|
||||
count = is_interleaved ? openmpt_module_read_interleaved_float_stereo( mod, SAMPLERATE, BUFFERSIZE, interleaved_buffer ) : openmpt_module_read_float_stereo( mod, SAMPLERATE, BUFFERSIZE, left, right );
|
||||
mod_err = openmpt_module_error_get_last( mod );
|
||||
mod_err_str = openmpt_module_error_get_last_message( mod );
|
||||
if ( mod_err != OPENMPT_ERROR_OK ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_read_stereo()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
if ( count == 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
pa_error = is_interleaved ? Pa_WriteStream( stream, interleaved_buffer, (unsigned long)count ) : Pa_WriteStream( stream, buffers, (unsigned long)count );
|
||||
if ( pa_error == paOutputUnderflowed ) {
|
||||
pa_error = paNoError;
|
||||
}
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_WriteStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
result = 1;
|
||||
|
||||
cleanup:
|
||||
|
||||
if ( stream ) {
|
||||
if ( Pa_IsStreamActive( stream ) == 1 ) {
|
||||
Pa_StopStream( stream );
|
||||
}
|
||||
Pa_CloseStream( stream );
|
||||
stream = 0;
|
||||
}
|
||||
|
||||
if ( pa_initialized ) {
|
||||
Pa_Terminate();
|
||||
pa_initialized = 0;
|
||||
(void)pa_initialized;
|
||||
}
|
||||
|
||||
if ( mod ) {
|
||||
openmpt_module_destroy( mod );
|
||||
mod = 0;
|
||||
}
|
||||
|
||||
if ( file ) {
|
||||
fclose( file );
|
||||
file = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
/*
|
||||
* libopenmpt_example_c_mem.c
|
||||
* --------------------------
|
||||
* Purpose: libopenmpt C API example
|
||||
* Notes : PortAudio is used for sound output.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: libopenmpt_example_c_mem SOMEMODULE
|
||||
*/
|
||||
|
||||
#if defined( __MINGW32__ ) && !defined( __MINGW64__ )
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libopenmpt/libopenmpt.h>
|
||||
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wstrict-prototypes"
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
|
||||
#endif
|
||||
#include <portaudio.h>
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
#define BUFFERSIZE 480
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static float left[BUFFERSIZE];
|
||||
static float right[BUFFERSIZE];
|
||||
static float * const buffers[2] = { left, right };
|
||||
static float interleaved_buffer[BUFFERSIZE * 2];
|
||||
static int is_interleaved = 0;
|
||||
|
||||
static void libopenmpt_example_logfunc( const char * message, void * userdata ) {
|
||||
(void)userdata;
|
||||
if ( message ) {
|
||||
fprintf( stderr, "openmpt: %s\n", message );
|
||||
}
|
||||
}
|
||||
|
||||
static int libopenmpt_example_errfunc( int error, void * userdata ) {
|
||||
(void)userdata;
|
||||
(void)error;
|
||||
return OPENMPT_ERROR_FUNC_RESULT_DEFAULT & ~OPENMPT_ERROR_FUNC_RESULT_LOG;
|
||||
}
|
||||
|
||||
static void libopenmpt_example_print_error( const char * func_name, int mod_err, const char * mod_err_str ) {
|
||||
if ( !func_name ) {
|
||||
func_name = "unknown function";
|
||||
}
|
||||
if ( mod_err == OPENMPT_ERROR_OUT_OF_MEMORY ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s\n", "OPENMPT_ERROR_OUT_OF_MEMORY" );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s\n", mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
} else {
|
||||
if ( !mod_err_str ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s failed.\n", func_name );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct blob_t {
|
||||
size_t size;
|
||||
void * data;
|
||||
} blob_t;
|
||||
|
||||
static void free_blob( blob_t * blob ) {
|
||||
if ( blob ) {
|
||||
if ( blob->data ) {
|
||||
free( blob->data );
|
||||
blob->data = 0;
|
||||
}
|
||||
blob->size = 0;
|
||||
free( blob );
|
||||
}
|
||||
}
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
static blob_t * load_file( const wchar_t * filename ) {
|
||||
#else
|
||||
static blob_t * load_file( const char * filename ) {
|
||||
#endif
|
||||
blob_t * result = 0;
|
||||
|
||||
blob_t * blob = 0;
|
||||
FILE * file = 0;
|
||||
long tell_result = 0;
|
||||
|
||||
blob = malloc( sizeof( blob_t ) );
|
||||
if ( !blob ) {
|
||||
goto fail;
|
||||
}
|
||||
memset( blob, 0, sizeof( blob_t ) );
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
file = _wfopen( filename, L"rb" );
|
||||
#else
|
||||
file = fopen( filename, "rb" );
|
||||
#endif
|
||||
if ( !file ) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ( fseek( file, 0, SEEK_END ) != 0 ) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
tell_result = ftell( file );
|
||||
if ( tell_result < 0 ) {
|
||||
goto fail;
|
||||
}
|
||||
if ( (unsigned long)(size_t)(unsigned long)tell_result != (unsigned long)tell_result ) {
|
||||
goto fail;
|
||||
}
|
||||
blob->size = (size_t)tell_result;
|
||||
|
||||
if ( fseek( file, 0, SEEK_SET ) != 0 ) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
blob->data = malloc( blob->size );
|
||||
if ( !blob->data ) {
|
||||
goto fail;
|
||||
}
|
||||
memset( blob->data, 0, blob->size );
|
||||
|
||||
if ( fread( blob->data, 1, blob->size, file ) != blob->size ) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
result = blob;
|
||||
blob = 0;
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
result = 0;
|
||||
|
||||
cleanup:
|
||||
|
||||
if ( blob ) {
|
||||
free_blob( blob );
|
||||
blob = 0;
|
||||
}
|
||||
|
||||
if ( file ) {
|
||||
fclose( file );
|
||||
file = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __clang__ ) && !defined( _MSC_VER )
|
||||
int wmain( int argc, wchar_t * argv[] );
|
||||
#endif
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
int result = 0;
|
||||
blob_t * blob = 0;
|
||||
openmpt_module * mod = 0;
|
||||
int mod_err = OPENMPT_ERROR_OK;
|
||||
const char * mod_err_str = NULL;
|
||||
size_t count = 0;
|
||||
PaError pa_error = paNoError;
|
||||
int pa_initialized = 0;
|
||||
PaStream * stream = 0;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_mem SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
if ( wcslen( argv[1] ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_mem SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
if ( strlen( argv[1] ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_mem SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
blob = load_file( argv[1] );
|
||||
if ( !blob ) {
|
||||
fprintf( stderr, "Error: %s\n", "load_file() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
mod = openmpt_module_create_from_memory2( blob->data, blob->size, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
if ( !mod ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_create_from_memory2()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_error = Pa_Initialize();
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_Initialize() failed." );
|
||||
goto fail;
|
||||
}
|
||||
pa_initialized = 1;
|
||||
|
||||
is_interleaved = 0;
|
||||
pa_error = Pa_OpenDefaultStream( &stream, 0, 2, paFloat32 | paNonInterleaved, SAMPLERATE, paFramesPerBufferUnspecified, NULL, NULL );
|
||||
if ( pa_error == paSampleFormatNotSupported ) {
|
||||
is_interleaved = 1;
|
||||
pa_error = Pa_OpenDefaultStream( &stream, 0, 2, paFloat32, SAMPLERATE, paFramesPerBufferUnspecified, NULL, NULL );
|
||||
}
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_OpenStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
if ( !stream ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_OpenStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_error = Pa_StartStream( stream );
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_StartStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while ( 1 ) {
|
||||
|
||||
openmpt_module_error_clear( mod );
|
||||
count = is_interleaved ? openmpt_module_read_interleaved_float_stereo( mod, SAMPLERATE, BUFFERSIZE, interleaved_buffer ) : openmpt_module_read_float_stereo( mod, SAMPLERATE, BUFFERSIZE, left, right );
|
||||
mod_err = openmpt_module_error_get_last( mod );
|
||||
mod_err_str = openmpt_module_error_get_last_message( mod );
|
||||
if ( mod_err != OPENMPT_ERROR_OK ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_read_stereo()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
if ( count == 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
pa_error = is_interleaved ? Pa_WriteStream( stream, interleaved_buffer, (unsigned long)count ) : Pa_WriteStream( stream, buffers, (unsigned long)count );
|
||||
if ( pa_error == paOutputUnderflowed ) {
|
||||
pa_error = paNoError;
|
||||
}
|
||||
if ( pa_error != paNoError ) {
|
||||
fprintf( stderr, "Error: %s\n", "Pa_WriteStream() failed." );
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
result = 1;
|
||||
|
||||
cleanup:
|
||||
|
||||
if ( stream ) {
|
||||
if ( Pa_IsStreamActive( stream ) == 1 ) {
|
||||
Pa_StopStream( stream );
|
||||
}
|
||||
Pa_CloseStream( stream );
|
||||
stream = 0;
|
||||
}
|
||||
|
||||
if ( pa_initialized ) {
|
||||
Pa_Terminate();
|
||||
pa_initialized = 0;
|
||||
(void)pa_initialized;
|
||||
}
|
||||
|
||||
if ( mod ) {
|
||||
openmpt_module_destroy( mod );
|
||||
mod = 0;
|
||||
}
|
||||
|
||||
if ( blob ) {
|
||||
free_blob( blob );
|
||||
blob = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* libopenmpt_example_c_pipe.c
|
||||
* ---------------------------
|
||||
* Purpose: libopenmpt C API simple pipe example
|
||||
* Notes : This example writes raw 48000Hz / stereo / 16bit native endian PCM data to stdout.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: cat SOMEMODULE | libopenmpt_example_c_pipe | aplay --file-type raw --format=dat
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libopenmpt/libopenmpt.h>
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_fd.h>
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
#define BUFFERSIZE 480
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static void libopenmpt_example_logfunc( const char * message, void * userdata ) {
|
||||
(void)userdata;
|
||||
if ( message ) {
|
||||
fprintf( stderr, "openmpt: %s\n", message );
|
||||
}
|
||||
}
|
||||
|
||||
static int libopenmpt_example_errfunc( int error, void * userdata ) {
|
||||
(void)userdata;
|
||||
(void)error;
|
||||
return OPENMPT_ERROR_FUNC_RESULT_DEFAULT & ~OPENMPT_ERROR_FUNC_RESULT_LOG;
|
||||
}
|
||||
|
||||
static void libopenmpt_example_print_error( const char * func_name, int mod_err, const char * mod_err_str ) {
|
||||
if ( !func_name ) {
|
||||
func_name = "unknown function";
|
||||
}
|
||||
if ( mod_err == OPENMPT_ERROR_OUT_OF_MEMORY ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s\n", "OPENMPT_ERROR_OUT_OF_MEMORY" );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s\n", mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
} else {
|
||||
if ( !mod_err_str ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s failed.\n", func_name );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t xwrite( int fd, const void * buffer, size_t size ) {
|
||||
size_t written = 0;
|
||||
ssize_t retval = 0;
|
||||
while ( written < size ) {
|
||||
retval = write( fd, (const char *)buffer + written, size - written );
|
||||
if ( retval < 0 ) {
|
||||
if ( errno != EINTR ) {
|
||||
break;
|
||||
}
|
||||
retval = 0;
|
||||
}
|
||||
written += retval;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
static int16_t buffer[BUFFERSIZE * 2];
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __clang__ ) && !defined( _MSC_VER )
|
||||
int wmain( int argc, wchar_t * argv[] );
|
||||
#endif
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
int result = 0;
|
||||
openmpt_module * mod = 0;
|
||||
int mod_err = OPENMPT_ERROR_OK;
|
||||
const char * mod_err_str = NULL;
|
||||
size_t count = 0;
|
||||
size_t written = 0;
|
||||
(void)argv;
|
||||
|
||||
if ( argc != 1 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_pipe' and connect stdin and stdout." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
mod = openmpt_module_create2( openmpt_stream_get_fd_callbacks(), (void *)(uintptr_t)STDIN_FILENO, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
if ( !mod ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_create2()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while ( 1 ) {
|
||||
|
||||
openmpt_module_error_clear( mod );
|
||||
count = openmpt_module_read_interleaved_stereo( mod, SAMPLERATE, BUFFERSIZE, buffer );
|
||||
mod_err = openmpt_module_error_get_last( mod );
|
||||
mod_err_str = openmpt_module_error_get_last_message( mod );
|
||||
if ( mod_err != OPENMPT_ERROR_OK ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_read_interleaved_stereo()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
if ( count == 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
written = xwrite( STDOUT_FILENO, buffer, count * 2 * sizeof( int16_t ) );
|
||||
if ( written == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "write() failed." );
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
result = 1;
|
||||
|
||||
cleanup:
|
||||
|
||||
if ( mod ) {
|
||||
openmpt_module_destroy( mod );
|
||||
mod = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* libopenmpt_example_c_probe.c
|
||||
* ----------------------------
|
||||
* Purpose: libopenmpt C API probing example
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: libopenmpt_example_c_probe SOMEMODULE ...
|
||||
* Returns 0 on successful probing for all files.
|
||||
* Returns 1 on failed probing for 1 or more files.
|
||||
* Returns 2 on error.
|
||||
*/
|
||||
|
||||
#define LIBOPENMPT_EXAMPLE_PROBE_RESULT_BINARY 1
|
||||
#define LIBOPENMPT_EXAMPLE_PROBE_RESULT_FLOAT 2
|
||||
|
||||
#define LIBOPENMPT_EXAMPLE_PROBE_RESULT LIBOPENMPT_EXAMPLE_PROBE_RESULT_BINARY
|
||||
|
||||
#if defined( __MINGW32__ ) && !defined( __MINGW64__ )
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libopenmpt/libopenmpt.h>
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
static void libopenmpt_example_logfunc( const char * message, void * userdata ) {
|
||||
(void)userdata;
|
||||
|
||||
if ( message ) {
|
||||
fprintf( stderr, "%s\n", message );
|
||||
}
|
||||
}
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
static int probe_file( const wchar_t * filename ) {
|
||||
#else
|
||||
static int probe_file( const char * filename ) {
|
||||
#endif
|
||||
|
||||
int result = 0;
|
||||
int mod_err = OPENMPT_ERROR_OK;
|
||||
FILE * file = NULL;
|
||||
|
||||
#if ( LIBOPENMPT_EXAMPLE_PROBE_RESULT == LIBOPENMPT_EXAMPLE_PROBE_RESULT_BINARY )
|
||||
int result_binary = 0;
|
||||
int probe_file_header_result = OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE;
|
||||
const char * probe_file_header_result_str = NULL;
|
||||
#endif
|
||||
#if ( LIBOPENMPT_EXAMPLE_PROBE_RESULT == LIBOPENMPT_EXAMPLE_PROBE_RESULT_FLOAT )
|
||||
double probability = 0.0;
|
||||
#endif
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
if ( wcslen( filename ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_probe SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
if ( strlen( filename ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_probe SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
file = _wfopen( filename, L"rb" );
|
||||
#else
|
||||
file = fopen( filename, "rb" );
|
||||
#endif
|
||||
if ( !file ) {
|
||||
fprintf( stderr, "Error: %s\n", "fopen() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if ( LIBOPENMPT_EXAMPLE_PROBE_RESULT == LIBOPENMPT_EXAMPLE_PROBE_RESULT_BINARY )
|
||||
probe_file_header_result = openmpt_probe_file_header_from_stream( OPENMPT_PROBE_FILE_HEADER_FLAGS_DEFAULT, openmpt_stream_get_file_callbacks2(), file, &libopenmpt_example_logfunc, NULL, &openmpt_error_func_default, NULL, &mod_err, NULL );
|
||||
probe_file_header_result_str = NULL;
|
||||
switch ( probe_file_header_result ) {
|
||||
case OPENMPT_PROBE_FILE_HEADER_RESULT_SUCCESS:
|
||||
probe_file_header_result_str = "Success ";
|
||||
result_binary = 1;
|
||||
break;
|
||||
case OPENMPT_PROBE_FILE_HEADER_RESULT_FAILURE:
|
||||
probe_file_header_result_str = "Failure ";
|
||||
result_binary = 0;
|
||||
break;
|
||||
case OPENMPT_PROBE_FILE_HEADER_RESULT_WANTMOREDATA:
|
||||
probe_file_header_result_str = "WantMoreData";
|
||||
result_binary = 0;
|
||||
break;
|
||||
case OPENMPT_PROBE_FILE_HEADER_RESULT_ERROR:
|
||||
result_binary = 0;
|
||||
(void)result_binary;
|
||||
fprintf( stderr, "Error: %s\n", "openmpt_probe_file_header() failed." );
|
||||
goto fail;
|
||||
break;
|
||||
default:
|
||||
result_binary = 0;
|
||||
(void)result_binary;
|
||||
fprintf( stderr, "Error: %s\n", "openmpt_probe_file_header() failed." );
|
||||
goto fail;
|
||||
break;
|
||||
}
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
fprintf( stdout, "%s - %ls\n", probe_file_header_result_str, filename );
|
||||
#else
|
||||
fprintf( stdout, "%s - %s\n", probe_file_header_result_str, filename );
|
||||
#endif
|
||||
if ( result_binary ) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = 1;
|
||||
}
|
||||
#elif ( LIBOPENMPT_EXAMPLE_PROBE_RESULT == LIBOPENMPT_EXAMPLE_PROBE_RESULT_FLOAT )
|
||||
probability = openmpt_could_open_probability2( openmpt_stream_get_file_callbacks2(), file, 0.25, &libopenmpt_example_logfunc, NULL, &openmpt_error_func_default, NULL, &mod_err, NULL );
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
fprintf( stdout, "%s: %f - %ls\n", "Result", probability, filename );
|
||||
#else
|
||||
fprintf( stdout, "%s: %f - %s\n", "Result", probability, filename );
|
||||
#endif
|
||||
if ( probability >= 0.5 ) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = 1;
|
||||
}
|
||||
#else
|
||||
#error "LIBOPENMPT_EXAMPLE_PROBE_RESULT is wrong"
|
||||
#endif
|
||||
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
result = 2;
|
||||
|
||||
cleanup:
|
||||
|
||||
if ( file ) {
|
||||
fclose( file );
|
||||
file = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __clang__ ) && !defined( _MSC_VER )
|
||||
int wmain( int argc, wchar_t * argv[] );
|
||||
#endif
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
int global_result = 0;
|
||||
|
||||
if ( argc <= 1 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_probe SOMEMODULE ...'." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
for ( int i = 1; i < argc; ++i ) {
|
||||
int result = probe_file( argv[i] );
|
||||
if ( result > global_result ) {
|
||||
global_result = result;
|
||||
}
|
||||
}
|
||||
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
global_result = 2;
|
||||
|
||||
cleanup:
|
||||
|
||||
return global_result;
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* libopenmpt_example_c_stdout.c
|
||||
* -----------------------------
|
||||
* Purpose: libopenmpt C API simple example
|
||||
* Notes : This example writes raw 48000Hz / stereo / 16bit native endian PCM data to stdout.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: libopenmpt_example_c_stdout SOMEMODULE | aplay --file-type raw --format=dat
|
||||
*/
|
||||
|
||||
#if defined( __MINGW32__ ) && !defined( __MINGW64__ )
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <libopenmpt/libopenmpt.h>
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
#define BUFFERSIZE 480
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static void libopenmpt_example_logfunc( const char * message, void * userdata ) {
|
||||
(void)userdata;
|
||||
if ( message ) {
|
||||
fprintf( stderr, "openmpt: %s\n", message );
|
||||
}
|
||||
}
|
||||
|
||||
static int libopenmpt_example_errfunc( int error, void * userdata ) {
|
||||
(void)userdata;
|
||||
(void)error;
|
||||
return OPENMPT_ERROR_FUNC_RESULT_DEFAULT & ~OPENMPT_ERROR_FUNC_RESULT_LOG;
|
||||
}
|
||||
|
||||
static void libopenmpt_example_print_error( const char * func_name, int mod_err, const char * mod_err_str ) {
|
||||
if ( !func_name ) {
|
||||
func_name = "unknown function";
|
||||
}
|
||||
if ( mod_err == OPENMPT_ERROR_OUT_OF_MEMORY ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s\n", "OPENMPT_ERROR_OUT_OF_MEMORY" );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s\n", mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
} else {
|
||||
if ( !mod_err_str ) {
|
||||
mod_err_str = openmpt_error_string( mod_err );
|
||||
if ( !mod_err_str ) {
|
||||
fprintf( stderr, "Error: %s failed.\n", func_name );
|
||||
} else {
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
fprintf( stderr, "Error: %s failed: %s\n", func_name, mod_err_str );
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t xwrite( int fd, const void * buffer, size_t size ) {
|
||||
size_t written = 0;
|
||||
ssize_t retval = 0;
|
||||
while ( written < size ) {
|
||||
retval = write( fd, (const char *)buffer + written, size - written );
|
||||
if ( retval < 0 ) {
|
||||
if ( errno != EINTR ) {
|
||||
break;
|
||||
}
|
||||
retval = 0;
|
||||
}
|
||||
written += retval;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
static int16_t buffer[BUFFERSIZE * 2];
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __clang__ ) && !defined( _MSC_VER )
|
||||
int wmain( int argc, wchar_t * argv[] );
|
||||
#endif
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
int result = 0;
|
||||
FILE * file = 0;
|
||||
openmpt_module * mod = 0;
|
||||
int mod_err = OPENMPT_ERROR_OK;
|
||||
const char * mod_err_str = NULL;
|
||||
size_t count = 0;
|
||||
size_t written = 0;
|
||||
|
||||
if ( argc != 2 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_stdout SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
if ( wcslen( argv[1] ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_stdout SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
file = _wfopen( argv[1], L"rb" );
|
||||
#else
|
||||
if ( strlen( argv[1] ) == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "Wrong invocation. Use 'libopenmpt_example_c_stdout SOMEMODULE'." );
|
||||
goto fail;
|
||||
}
|
||||
file = fopen( argv[1], "rb" );
|
||||
#endif
|
||||
if ( !file ) {
|
||||
fprintf( stderr, "Error: %s\n", "fopen() failed." );
|
||||
goto fail;
|
||||
}
|
||||
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_callbacks2(), file, &libopenmpt_example_logfunc, NULL, &libopenmpt_example_errfunc, NULL, &mod_err, &mod_err_str, NULL );
|
||||
if ( !mod ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_create2()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
while ( 1 ) {
|
||||
|
||||
openmpt_module_error_clear( mod );
|
||||
count = openmpt_module_read_interleaved_stereo( mod, SAMPLERATE, BUFFERSIZE, buffer );
|
||||
mod_err = openmpt_module_error_get_last( mod );
|
||||
mod_err_str = openmpt_module_error_get_last_message( mod );
|
||||
if ( mod_err != OPENMPT_ERROR_OK ) {
|
||||
libopenmpt_example_print_error( "openmpt_module_read_interleaved_stereo()", mod_err, mod_err_str );
|
||||
openmpt_free_string( mod_err_str );
|
||||
mod_err_str = NULL;
|
||||
}
|
||||
if ( count == 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
written = xwrite( STDOUT_FILENO, buffer, count * 2 * sizeof( int16_t ) );
|
||||
if ( written == 0 ) {
|
||||
fprintf( stderr, "Error: %s\n", "write() failed." );
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
result = 0;
|
||||
|
||||
goto cleanup;
|
||||
|
||||
fail:
|
||||
|
||||
result = 1;
|
||||
|
||||
cleanup:
|
||||
|
||||
if ( mod ) {
|
||||
openmpt_module_destroy( mod );
|
||||
mod = 0;
|
||||
}
|
||||
|
||||
if ( file ) {
|
||||
fclose( file );
|
||||
file = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* libopenmpt_example_c_unsafe.c
|
||||
* -----------------------------
|
||||
* Purpose: libopenmpt C API simplified example
|
||||
* Notes : PortAudio is used for sound output.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: libopenmpt_example_c_unsafe SOMEMODULE
|
||||
* CAUTION: This simple example does no error cheking at all.
|
||||
*/
|
||||
|
||||
#if defined( __MINGW32__ ) && !defined( __MINGW64__ )
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <libopenmpt/libopenmpt.h>
|
||||
#include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wstrict-prototypes"
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
|
||||
#endif
|
||||
#include <portaudio.h>
|
||||
#if defined( __clang__ )
|
||||
#pragma clang diagnostic pop
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
#define BUFFERSIZE 480
|
||||
#define SAMPLERATE 48000
|
||||
|
||||
static float left[BUFFERSIZE];
|
||||
static float right[BUFFERSIZE];
|
||||
static float * const buffers[2] = { left, right };
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __clang__ ) && !defined( _MSC_VER )
|
||||
int wmain( int argc, wchar_t * argv[] );
|
||||
#endif
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
FILE * file = 0;
|
||||
openmpt_module * mod = 0;
|
||||
size_t count = 0;
|
||||
PaStream * stream = 0;
|
||||
(void)argc;
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
file = _wfopen( argv[1], L"rb" );
|
||||
#else
|
||||
file = fopen( argv[1], "rb" );
|
||||
#endif
|
||||
mod = openmpt_module_create2( openmpt_stream_get_file_callbacks2(), file, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
|
||||
#if defined( __clang__ ) && defined( __clang_analyzer__ )
|
||||
[[clang::suppress]]
|
||||
#endif
|
||||
fclose( file );
|
||||
Pa_Initialize();
|
||||
Pa_OpenDefaultStream( &stream, 0, 2, paFloat32 | paNonInterleaved, SAMPLERATE, paFramesPerBufferUnspecified, NULL, NULL );
|
||||
Pa_StartStream( stream );
|
||||
while ( 1 ) {
|
||||
count = openmpt_module_read_float_stereo( mod, SAMPLERATE, BUFFERSIZE, left, right );
|
||||
if ( count == 0 ) {
|
||||
break;
|
||||
}
|
||||
Pa_WriteStream( stream, buffers, (unsigned long)count );
|
||||
}
|
||||
Pa_StopStream( stream );
|
||||
Pa_CloseStream( stream );
|
||||
Pa_Terminate();
|
||||
openmpt_module_destroy( mod );
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* libopenmpt_example_cxx.cpp
|
||||
* --------------------------
|
||||
* Purpose: libopenmpt C++ API example
|
||||
* Notes : PortAudio C++ is used for sound output.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Usage: libopenmpt_example_cxx SOMEMODULE
|
||||
*/
|
||||
|
||||
#if defined( __MINGW32__ ) && !defined( __MINGW64__ )
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <new>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
#include <libopenmpt/libopenmpt.hpp>
|
||||
|
||||
#if defined( __clang__ )
|
||||
#if ( ( __clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__ ) >= 40000 )
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
|
||||
#endif
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsuggest-override"
|
||||
#endif
|
||||
#include <portaudiocpp/PortAudioCpp.hxx>
|
||||
#if defined( __clang__ )
|
||||
#if ( ( __clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__ ) >= 40000 )
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
#elif defined( __GNUC__ ) && !defined( __clang__ ) && !defined( _MSC_VER )
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
#include <crt0.h>
|
||||
#endif /* __DJGPP__ */
|
||||
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
extern "C" int _crt0_startup_flags = 0
|
||||
| _CRT0_FLAG_NONMOVE_SBRK /* force interrupt compatible allocation */
|
||||
| _CRT0_DISABLE_SBRK_ADDRESS_WRAP /* force NT compatible allocation */
|
||||
| _CRT0_FLAG_LOCK_MEMORY /* lock all code and data at program startup */
|
||||
| 0;
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
#if ( defined( _WIN32 ) || defined( WIN32 ) ) && ( defined( _UNICODE ) || defined( UNICODE ) )
|
||||
#if defined( __GNUC__ ) || ( defined( __clang__ ) && !defined( _MSC_VER ) )
|
||||
// mingw-w64 g++ does only default to special C linkage for "main", but not for "wmain" (see <https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/>).
|
||||
extern "C" int wmain( int /*argc*/, wchar_t * /*argv*/[] );
|
||||
extern "C" int wmain( int argc, wchar_t * argv[] ) {
|
||||
#else
|
||||
int wmain( int argc, wchar_t * argv[] ) {
|
||||
#endif
|
||||
#else
|
||||
int main( int argc, char * argv[] ) {
|
||||
#endif
|
||||
#if defined( __DJGPP__ )
|
||||
/* clang-format off */
|
||||
_crt0_startup_flags &= ~_CRT0_FLAG_LOCK_MEMORY; /* disable automatic locking for all further memory allocations */
|
||||
/* clang-format on */
|
||||
#endif /* __DJGPP__ */
|
||||
try {
|
||||
if ( argc != 2 ) {
|
||||
throw std::runtime_error( "Usage: libopenmpt_example_cxx SOMEMODULE" );
|
||||
}
|
||||
constexpr std::size_t buffersize = 480;
|
||||
constexpr std::int32_t samplerate = 48000;
|
||||
std::ifstream file( argv[1], std::ios::binary );
|
||||
openmpt::module mod( file );
|
||||
portaudio::AutoSystem portaudio_initializer;
|
||||
portaudio::System & portaudio = portaudio::System::instance();
|
||||
std::vector<float> left( buffersize );
|
||||
std::vector<float> right( buffersize );
|
||||
std::vector<float> interleaved_buffer( buffersize * 2 );
|
||||
bool is_interleaved = false;
|
||||
#if defined( _MSC_VER ) && defined( _PREFAST_ )
|
||||
// work-around bug in VS2019 MSVC 16.5.5 static analyzer
|
||||
is_interleaved = false;
|
||||
portaudio::DirectionSpecificStreamParameters outputstream_parameters( portaudio.defaultOutputDevice(), 2, portaudio::FLOAT32, false, portaudio.defaultOutputDevice().defaultHighOutputLatency(), 0 );
|
||||
portaudio::StreamParameters stream_parameters( portaudio::DirectionSpecificStreamParameters::null(), outputstream_parameters, samplerate, paFramesPerBufferUnspecified, paNoFlag );
|
||||
portaudio::BlockingStream stream( stream_parameters );
|
||||
#else
|
||||
portaudio::BlockingStream stream = [&]()
|
||||
{
|
||||
try {
|
||||
is_interleaved = false;
|
||||
portaudio::DirectionSpecificStreamParameters outputstream_parameters( portaudio.defaultOutputDevice(), 2, portaudio::FLOAT32, false, portaudio.defaultOutputDevice().defaultHighOutputLatency(), 0 );
|
||||
portaudio::StreamParameters stream_parameters( portaudio::DirectionSpecificStreamParameters::null(), outputstream_parameters, samplerate, paFramesPerBufferUnspecified, paNoFlag );
|
||||
return portaudio::BlockingStream( stream_parameters );
|
||||
} catch ( const portaudio::PaException & e ) {
|
||||
if ( e.paError() != paSampleFormatNotSupported ) {
|
||||
throw;
|
||||
}
|
||||
is_interleaved = true;
|
||||
portaudio::DirectionSpecificStreamParameters outputstream_parameters( portaudio.defaultOutputDevice(), 2, portaudio::FLOAT32, true, portaudio.defaultOutputDevice().defaultHighOutputLatency(), 0 );
|
||||
portaudio::StreamParameters stream_parameters( portaudio::DirectionSpecificStreamParameters::null(), outputstream_parameters, samplerate, paFramesPerBufferUnspecified, paNoFlag );
|
||||
return portaudio::BlockingStream( stream_parameters );
|
||||
}
|
||||
}();
|
||||
#endif
|
||||
stream.start();
|
||||
while ( true ) {
|
||||
std::size_t count = is_interleaved ? mod.read_interleaved_stereo( samplerate, buffersize, interleaved_buffer.data() ) : mod.read( samplerate, buffersize, left.data(), right.data() );
|
||||
if ( count == 0 ) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
if ( is_interleaved ) {
|
||||
stream.write( interleaved_buffer.data(), static_cast<unsigned long>( count ) );
|
||||
} else {
|
||||
const float * const buffers[2] = { left.data(), right.data() };
|
||||
stream.write( buffers, static_cast<unsigned long>( count ) );
|
||||
}
|
||||
} catch ( const portaudio::PaException & pa_exception ) {
|
||||
if ( pa_exception.paError() != paOutputUnderflowed ) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.stop();
|
||||
} catch ( const std::bad_alloc & ) {
|
||||
std::cerr << "Error: " << std::string( "out of memory" ) << std::endl;
|
||||
return 1;
|
||||
} catch ( const std::exception & e ) {
|
||||
std::cerr << "Error: " << std::string( e.what() ? e.what() : "unknown error" ) << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
# clang-format 14
|
||||
|
||||
Language: Cpp
|
||||
Standard: c++20
|
||||
|
||||
AccessModifierOffset: -2 #?
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveBitFields: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignConsecutiveMacros: true
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: AlignAfterOperator
|
||||
AlignTrailingComments: true
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllConstructorInitializersOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: true
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AttributeMacros: []
|
||||
BinPackArguments: true
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: Both
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: true
|
||||
AfterClass: false
|
||||
AfterControlStatement: MultiLine
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
#AfterObjCDeclaration
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: true
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
#BreakAfterJavaFieldAnnotations
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeConceptDeclarations: true
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 0
|
||||
CommentPragmas: '' #?
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
ConstructorInitializerIndentWidth: 2 #?
|
||||
ContinuationIndentWidth: 2 #?
|
||||
Cpp11BracedListStyle: true
|
||||
DeriveLineEnding: true
|
||||
DerivePointerAlignment: false
|
||||
EmptyLineAfterAccessModifier: Leave
|
||||
EmptyLineBeforeAccessModifier: Leave
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros: []
|
||||
IfMacros: ['MPT_MAYBE_CONSTANT_IF']
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories: [] #?
|
||||
IncludeIsMainRegex: '' #?
|
||||
IncludeIsMainSourceRegex: '' #?
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: true
|
||||
IndentCaseLabels: true
|
||||
IndentExternBlock: NoIndent
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
#IndentRequiresClause: true
|
||||
#BeforeHash
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: true
|
||||
InsertTrailingCommas: None
|
||||
#JavaImportGroups
|
||||
#JavaScriptQuotes
|
||||
#JavaScriptWrapImports
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
LambdaBodyIndentation: OuterScope
|
||||
MacroBlockBegin: '' #?
|
||||
MacroBlockEnd: '' #?
|
||||
MaxEmptyLinesToKeep: 3
|
||||
NamespaceIndentation: None
|
||||
NamespaceMacros: [] #?
|
||||
#ObjCBinPackProtocolList
|
||||
#ObjCBlockIndentWidth
|
||||
#ObjCBreakBeforeNestedBlockParam
|
||||
#ObjCSpaceAfterProperty
|
||||
#ObjCSpaceBeforeProtocolList
|
||||
PackConstructorInitializers: Never
|
||||
#PenaltyBreakAssignment
|
||||
#PenaltyBreakBeforeFirstCallParameter
|
||||
#PenaltyBreakComment
|
||||
#PenaltyBreakFirstLessLess
|
||||
#PenaltyBreakOpenParenthesis
|
||||
#PenaltyBreakString
|
||||
#PenaltyBreakTemplateDeclaration
|
||||
#PenaltyExcessCharacter
|
||||
#PenaltyIndentedWhitespace
|
||||
#PenaltyReturnTypeOnItsOwnLine
|
||||
PointerAlignment: Middle
|
||||
PPIndentWidth: -1
|
||||
#RawStringFormats
|
||||
QualifierAlignment: Leave
|
||||
#QualifierOrder: ['static', 'inline', 'constexpr', 'volatile', 'const', 'restrict', 'type']
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: false
|
||||
RemoveBracesLLVM: false
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SortIncludes: false
|
||||
#SortJavaStaticImport
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterIfMacros: true
|
||||
AfterOverloadedOperator: false
|
||||
#AfterRequiresInClause: false
|
||||
#AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBlock: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 2
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInConditionalStatement: true
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParentheses: true
|
||||
SpacesInSquareBrackets: false
|
||||
StatementAttributeLikeMacros: []
|
||||
StatementMacros: [ 'MPT_WARNING', 'MPT_TEST_GROUP_INLINE_IDENTIFIER', 'MPT_TEST_GROUP_INLINE', 'MPT_TEST_GROUP_STATIC' ] #?
|
||||
TabWidth: 2
|
||||
TypenameMacros: [] #?
|
||||
UseCRLF: false
|
||||
UseTab: ForContinuationAndIndentation
|
||||
WhitespaceSensitiveMacros:
|
||||
- MPT_PP_STRINGIFY
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,426 @@
|
||||
/'
|
||||
' libopenmpt_ext.bi
|
||||
' -----------------
|
||||
' Purpose: libopenmpt public FreeBASIC interface for libopenmpt extensions
|
||||
' Notes : (currently none)
|
||||
' Authors: Johannes Schultz
|
||||
' OpenMPT Devs
|
||||
' The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
'/
|
||||
|
||||
#Pragma Once
|
||||
|
||||
#Include Once "libopenmpt.bi"
|
||||
|
||||
Extern "C"
|
||||
|
||||
'* \brief Opaque type representing a libopenmpt extension module
|
||||
Type openmpt_module_ext
|
||||
opaque As Any Ptr
|
||||
End Type
|
||||
|
||||
/'* \brief Construct an openmpt_module_ext
|
||||
|
||||
\param stream_callbacks Input stream callback operations.
|
||||
\param stream Input stream to load the module from.
|
||||
\param logfunc Logging function where warning and errors are written. The logging function may be called throughout the lifetime of openmpt_module_ext. May be NULL.
|
||||
\param loguser User-defined data associated with this module. This value will be passed to the logging callback function (logfunc)
|
||||
\param errfunc Error function to define error behaviour. May be NULL.
|
||||
\param erruser Error function user context.
|
||||
\param errorcode Pointer to an integer where an error may get stored. May be NULL.
|
||||
\param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
|
||||
\param ctls A map of initial ctl values, see openmpt_module_get_ctls.
|
||||
\return A pointer to the constructed openmpt_module_ext, or NULL on failure.
|
||||
\remarks The input data can be discarded after an openmpt_module_ext has been constructed successfully.
|
||||
\sa openmpt_stream_callbacks
|
||||
\since 0.3.0
|
||||
'/
|
||||
Declare Function openmpt_module_ext_create(ByVal stream_callbacks As openmpt_stream_callbacks, ByVal stream As Any Ptr, ByVal logfunc As openmpt_log_func, ByVal loguser As Any Ptr, ByVal errfunc As openmpt_error_func, ByVal erruser As Any Ptr, ByVal Error As Long Ptr, ByVal error_message As Const ZString Ptr Ptr, ByVal ctls As Const openmpt_module_initial_ctl Ptr) As openmpt_module_ext Ptr
|
||||
|
||||
/'* \brief Construct an openmpt_module_ext
|
||||
|
||||
\param filedata Data to load the module from.
|
||||
\param filesize Amount of data available.
|
||||
\param logfunc Logging function where warning and errors are written. The logging function may be called throughout the lifetime of openmpt_module_ext.
|
||||
\param loguser User-defined data associated with this module. This value will be passed to the logging callback function (logfunc)
|
||||
\param errfunc Error function to define error behaviour. May be NULL.
|
||||
\param erruser Error function user context.
|
||||
\param errorcode Pointer to an integer where an error may get stored. May be NULL.
|
||||
\param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
|
||||
\param ctls A map of initial ctl values, see openmpt_module_get_ctls.
|
||||
\return A pointer to the constructed openmpt_module_ext, or NULL on failure.
|
||||
\remarks The input data can be discarded after an openmpt_module_ext has been constructed successfully.
|
||||
\since 0.3.0
|
||||
'/
|
||||
Declare Function openmpt_module_ext_create_from_memory(ByVal filedata As Const Any Ptr, ByVal filesize As UInteger, ByVal logfunc As openmpt_log_func, ByVal loguser As Any Ptr, ByVal errfunc As openmpt_error_func, ByVal erruser As Any Ptr, ByVal Error As Long Ptr, ByVal error_message As Const ZString Ptr Ptr, ByVal ctls As Const openmpt_module_initial_ctl Ptr) As openmpt_module_ext Ptr
|
||||
|
||||
/'* \brief Unload a previously created openmpt_module_ext from memory.
|
||||
|
||||
\param mod_ext The module to unload.
|
||||
\since 0.3.0
|
||||
'/
|
||||
Declare Sub openmpt_module_ext_destroy(ByVal mod_ext As openmpt_module_ext Ptr)
|
||||
|
||||
/'* \brief Retrieve the openmpt_module handle from an openmpt_module_ext handle.
|
||||
|
||||
\param mod_ext The extension module handle to convert
|
||||
\return An equivalent openmpt_module handle to pass to standard libopenmpt functions
|
||||
\since 0.3.0
|
||||
'/
|
||||
Declare Function openmpt_module_ext_get_module(ByVal mod_ext As openmpt_module_ext Ptr) As openmpt_module Ptr
|
||||
|
||||
/'* Retrieve a libopenmpt extension.
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param interface_id The name of the extension interface to retrieve (e.g. LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS).
|
||||
\param interface Appropriate structure of interface function pointers which is to be filled by this function (e.g. a pointer to a openmpt_module_ext_interface_pattern_vis structure).
|
||||
\param interface_size Size of the interface's structure of function pointers (e.g. sizeof(openmpt_module_ext_interface_pattern_vis)).
|
||||
\return 1 on success, 0 if the interface was not found.
|
||||
\since 0.3.0
|
||||
'/
|
||||
Declare Function openmpt_module_ext_get_interface(ByVal mod_ext As openmpt_module_ext Ptr, ByVal interface_id As Const ZString Ptr, ByVal interface As Any Ptr, ByVal interface_size As UInteger) As Long
|
||||
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS "pattern_vis"
|
||||
|
||||
'* Pattern command type
|
||||
Const OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_UNKNOWN = 0
|
||||
Const OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_GENERAL = 1
|
||||
Const OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_GLOBAL = 2
|
||||
Const OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_VOLUME = 3
|
||||
Const OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_PANNING = 4
|
||||
Const OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_PITCH = 5
|
||||
|
||||
Type openmpt_module_ext_interface_pattern_vis
|
||||
/'* Get pattern command type for pattern highlighting
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param pattern The pattern whose data should be retrieved.
|
||||
\param row The row from which the data should be retrieved.
|
||||
\param channel The channel from which the data should be retrieved.
|
||||
\return The command type in the effect column at the given pattern position (see OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_*)
|
||||
\sa get_pattern_row_channel_effect_type
|
||||
'/
|
||||
get_pattern_row_channel_volume_effect_type As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal pattern As Long, ByVal row As Long, ByVal channel As Long) As Long
|
||||
|
||||
/'* Get pattern command type for pattern highlighting
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param pattern The pattern whose data should be retrieved.
|
||||
\param row The row from which the data should be retrieved.
|
||||
\param channel The channel from which the data should be retrieved.
|
||||
\return The command type in the effect column at the given pattern position (see OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_*)
|
||||
\sa get_pattern_row_channel_volume_effect_type
|
||||
'/
|
||||
get_pattern_row_channel_effect_type As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal pattern As Long, ByVal row As Long, ByVal channel As Long) As Long
|
||||
End Type
|
||||
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE "interactive"
|
||||
|
||||
Type openmpt_module_ext_interface_interactive
|
||||
/'* Set the current ticks per row (speed)
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param speed The new tick count in range [1, 65535].
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the speed is outside the specified range.
|
||||
\return 1 on success, 0 on failure.
|
||||
\sa openmpt_module_get_current_speed
|
||||
'/
|
||||
set_current_speed As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal speed As Long) As Long
|
||||
|
||||
/'* Set the current module tempo
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
|
||||
\return 1 on success, 0 on failure.
|
||||
\remarks The tempo may be reset by pattern commands at any time. Use set_tempo_factor to apply a tempo factor that is independent of pattern commands.
|
||||
\sa openmpt_module_get_current_tempo
|
||||
\deprecated Please use openmpt_module_ext_interface_interactive3.set_current_tempo2().
|
||||
'/
|
||||
set_current_tempo As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal tempo As Long) As Long
|
||||
|
||||
/'* Set the current module tempo factor without affecting playback pitch
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param factor The new tempo factor in range ]0.0, 4.0] - 1.0 means unmodified tempo.
|
||||
\return 1 on success, 0 on failure.
|
||||
\remarks Modifying the tempo without applying the same pitch factor using set_pitch_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
|
||||
\sa openmpt_module_ext_interface_interactive.get_tempo_factor
|
||||
'/
|
||||
set_tempo_factor As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal factor As Double) As Long
|
||||
|
||||
/'* Gets the current module tempo factor
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\return The current tempo factor.
|
||||
\sa openmpt_module_ext_interface_interactive.set_tempo_factor
|
||||
'/
|
||||
get_tempo_factor As Function(ByVal mod_ext As openmpt_module_ext Ptr) As Double
|
||||
|
||||
/'* Set the current module pitch factor without affecting playback speed
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param factor The new pitch factor in range ]0.0, 4.0] - 1.0 means unmodified pitch.
|
||||
\return 1 on success, 0 on failure.
|
||||
\remarks Modifying the pitch without applying the the same tempo factor using set_tempo_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
|
||||
\remarks To shift the pich by `n` semitones, the parameter can be calculated as follows: `2.0 ^ ( n / 12.0 )`
|
||||
\sa openmpt_module_ext_interface_interactive.get_pitch_factor
|
||||
'/
|
||||
set_pitch_factor As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal factor As Double) As Long
|
||||
|
||||
/'* Gets the current module pitch factor
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\return The current pitch factor.
|
||||
\sa openmpt_module_ext_interface_interactive.set_pitch_factor
|
||||
'/
|
||||
get_pitch_factor As Function(ByVal mod_ext As openmpt_module_ext Ptr) As Double
|
||||
|
||||
/'* Set the current global volume
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param volume The new global volume in range [0.0, 1.0]
|
||||
\return 1 on success, 0 on failure.
|
||||
\remarks The global volume may be reset by pattern commands at any time. Use openmpt_module_set_render_param to apply a global overall volume factor that is independent of pattern commands.
|
||||
\sa openmpt_module_ext_interface_interactive.get_global_volume
|
||||
'/
|
||||
set_global_volume As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal volume As Double) As Long
|
||||
|
||||
/'* Get the current global volume
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\return The current global volume in range [0.0, 1.0]
|
||||
\sa openmpt_module_ext_interface_interactive.set_global_volume
|
||||
'/
|
||||
get_global_volume As Function(ByVal mod_ext As openmpt_module_ext Ptr) As Double
|
||||
|
||||
/'* Set the current channel volume for a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose volume should be set, in range [0, openmpt_module_get_num_channels()[
|
||||
\param volume The new channel volume in range [0.0, 1.0]
|
||||
\return 1 on success, 0 on failure (channel out of range).
|
||||
\remarks The channel volume may be reset by pattern commands at any time.
|
||||
\sa openmpt_module_ext_interface_interactive.get_channel_volume
|
||||
'/
|
||||
set_channel_volume As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long, ByVal volume As Double) As Long
|
||||
|
||||
/'* Get the current channel volume for a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose volume should be retrieved, in range [0, openmpt_module_get_num_channels()[
|
||||
\return The current channel volume in range [0.0, 1.0]
|
||||
\sa openmpt_module_ext_interface_interactive.set_channel_volume
|
||||
'/
|
||||
get_channel_volume As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Double
|
||||
|
||||
/'* Set the current mute status for a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose mute status should be set, in range [0, openmpt_module_get_num_channels()[
|
||||
\param mute The new mute status. true is muted, false is unmuted.
|
||||
\return 1 on success, 0 on failure (channel out of range).
|
||||
\sa openmpt_module_ext_interface_interactive.get_channel_mute_status
|
||||
'/
|
||||
set_channel_mute_status As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long, ByVal mute As Long) As Long
|
||||
|
||||
/'* Get the current mute status for a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose mute status should be retrieved, in range [0, openmpt_module_get_num_channels()[
|
||||
\return The current channel mute status. true is muted, false is unmuted.
|
||||
\sa openmpt_module_ext_interface_interactive.set_channel_mute_status
|
||||
'/
|
||||
get_channel_mute_status As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Long
|
||||
|
||||
/'* Set the current mute status for an instrument
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param instrument The instrument whose mute status should be set, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
|
||||
\param mute The new mute status. true is muted, false is unmuted.
|
||||
\return 1 on success, 0 on failure (instrument out of range).
|
||||
\sa openmpt_module_ext_interface_interactive.get_instrument_mute_status
|
||||
'/
|
||||
set_instrument_mute_status As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal instrument As Long, ByVal mute As Long) As Long
|
||||
|
||||
/'* Get the current mute status for an instrument
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param instrument The instrument whose mute status should be retrieved, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
|
||||
\return The current instrument mute status. 1 is muted, 0 is unmuted, -1 means the instrument was out of range.
|
||||
\sa openmpt_module_ext_interface_interactive.set_instrument_mute_status
|
||||
'/
|
||||
get_instrument_mute_status As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal instrument As Long) As Long
|
||||
|
||||
/'* Play a note using the specified instrument
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param instrument The instrument that should be played, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
|
||||
\param note The note to play, in rage [0, 119]. 60 is the middle C.
|
||||
\param volume The volume at which the note should be triggered, in range [0.0, 1.0]
|
||||
\param panning The panning position at which the note should be triggered, in range [-1.0, 1.0], 0.0 is center.
|
||||
\return The channel on which the note is played. This can pe be passed to stop_note to stop the note. -1 means that no channel could be allocated and the note is not played.
|
||||
\sa openmpt_module_ext_interface_interactive.stop_note
|
||||
\sa openmpt_module_ext_interface_interactive2.note_off
|
||||
\sa openmpt_module_ext_interface_interactive2.note_fade
|
||||
'/
|
||||
play_note As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal instrument As Long, ByVal note As Long, ByVal volume As Double, ByVal panning As Double) As Long
|
||||
|
||||
/'* Stop the note playing on the specified channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel on which the note should be stopped. This is the value returned by a previous play_note call.
|
||||
\return 1 on success, 0 on failure (channel out of range).
|
||||
\sa openmpt_module_ext_interface_interactive.play_note
|
||||
\sa openmpt_module_ext_interface_interactive.note_off
|
||||
\sa openmpt_module_ext_interface_interactive2.note_fade
|
||||
'/
|
||||
stop_note As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Long
|
||||
End Type
|
||||
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE2 "interactive2"
|
||||
|
||||
Type openmpt_module_ext_interface_interactive2
|
||||
|
||||
/'* Sends a key-off command for the note playing on the specified channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel on which the key-off event should be triggered. This is the value returned by a previous play_note call.
|
||||
\return 1 on success, 0 on failure (channel out of range).
|
||||
\remarks This method releases envelopes and sample sustain loops. If the sample has no sustain loop, or if the module does not use instruments, it does nothing.
|
||||
\sa openmpt_module_ext_interface_interactive.play_note
|
||||
\sa openmpt_module_ext_interface_interactive.stop_note
|
||||
\sa note_fade
|
||||
'/
|
||||
note_off As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Long
|
||||
|
||||
/'* Sends a note fade command for the note playing on the specified channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel on which the note should be faded. This is the value returned by a previous play_note call.
|
||||
\return 1 on success, 0 on failure (channel out of range).
|
||||
\remarks This method uses the instrument's fade-out value. If the module does not use instruments, or the instrument's fade-out value is 0, it does nothing.
|
||||
\sa openmpt_module_ext_interface_interactive.play_note
|
||||
\sa openmpt_module_ext_interface_interactive.stop_note
|
||||
\sa note_fade
|
||||
'/
|
||||
note_fade As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Long
|
||||
|
||||
/'* Set the current panning for a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel that should be panned. This is the value returned by a previous play_note call.
|
||||
\param panning The panning position to set on the channel, in range [-1.0, 1.0], 0.0 is center.
|
||||
\return 1 on success, 0 on failure (channel out of range).
|
||||
\remarks This command affects subsequent notes played on the same channel, and may itself be overridden by subsequent panning commands encountered in the module itself.
|
||||
\sa openmpt_module_ext_interface_interactive2.get_channel_panning
|
||||
'/
|
||||
set_channel_panning As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long, ByVal panning As Double) As Long
|
||||
|
||||
/'* Get the current panning position for a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose panning should be retrieved. This is the value returned by a previous play_note call.
|
||||
\return The current channel panning, in range [-1.0, 1.0], 0.0 is center.
|
||||
\sa openmpt_module_ext_interface_interactive2.set_channel_panning
|
||||
'/
|
||||
get_channel_panning As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Double
|
||||
|
||||
/'* Set the finetune for the currently playing note on a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose finetune will be changed, in range [0, openmpt::module::get_num_channels()[
|
||||
\param finetune The finetune to set on the channel, in range [-1.0, 1.0], 0.0 is center.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
\remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
|
||||
\remarks This command does not affect subsequent notes played on the same channel, but may itself be overridden by subsequent finetune commands encountered in the module itself.
|
||||
\sa openmpt_module_ext_interface_interactive2.get_note_finetune
|
||||
'/
|
||||
set_note_finetune As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long, ByVal finetune As Double) As Long
|
||||
|
||||
/'* Get the finetune for the currently playing note on a channel
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param channel The channel whose finetune should be retrieved, in range [0, openmpt::module::get_num_channels()[
|
||||
\return The current channel finetune, in range [-1.0, 1.0], 0.0 is center.
|
||||
\remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
\sa openmpt_module_ext_interface_interactive2.set_note_finetune
|
||||
'/
|
||||
get_note_finetune As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal channel As Long) As Double
|
||||
End Type
|
||||
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE3 "interactive3"
|
||||
|
||||
Type openmpt_module_ext_interface_interactive3
|
||||
|
||||
/'* Set the current module tempo
|
||||
|
||||
\param mod_ext The module handle to work on.
|
||||
\param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
|
||||
\return 1 on success, 0 on failure.
|
||||
\remarks The tempo may be reset by pattern commands at any time. Use set_tempo_factor to apply a tempo factor that is independent of pattern commands.
|
||||
\sa openmpt_module_get_current_tempo2
|
||||
\since 0.7.0
|
||||
'/
|
||||
set_current_tempo As Function(ByVal mod_ext As openmpt_module_ext Ptr, ByVal tempo As Double) As Long
|
||||
|
||||
End Type
|
||||
|
||||
End Extern
|
||||
|
||||
/'* \brief Construct an openmpt_module_ext
|
||||
|
||||
\param file The FreeBASIC file handle to load from.
|
||||
\param logfunc Logging function where warning and errors are written. May be NULL.
|
||||
\param loguser Logging function user context. Used to pass any user-defined data associated with this module to the logging function.
|
||||
\param errfunc Error function to define error behaviour. May be NULL.
|
||||
\param erruser Error function user context. Used to pass any user-defined data associated with this module to the error function.
|
||||
\param errorcode Pointer to an integer where an error may get stored. May be NULL.
|
||||
\param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
|
||||
\param ctls A map of initial ctl values, see openmpt_module_get_ctls.
|
||||
\return A pointer to the constructed openmpt_module, or NULL on failure.
|
||||
\remarks The file handle can be closed after an openmpt_module has been constructed successfully.
|
||||
\sa openmpt_module_ext_create
|
||||
'/
|
||||
Function openmpt_module_ext_create_from_fbhandle(_
|
||||
ByVal file As Integer,_
|
||||
ByVal logfunc As openmpt_log_func = 0,_
|
||||
ByVal loguser As Any Ptr = 0,_
|
||||
ByVal errfunc As openmpt_error_func = 0,_
|
||||
ByVal erruser As Any Ptr = 0,_
|
||||
ByVal errorcode As Long Ptr = 0,_
|
||||
ByVal error_message As Const ZString Ptr Ptr = 0,_
|
||||
ByVal ctls As Const openmpt_module_initial_ctl Ptr = 0) As openmpt_module_ext Ptr
|
||||
Return openmpt_module_ext_create(openmpt_stream_get_file_callbacks(), Cast(FILE Ptr, FileAttr(file, fbFileAttrHandle)), logfunc, loguser, errfunc, erruser, errorcode, error_message, ctls)
|
||||
End Function
|
||||
|
||||
/'* \brief Construct an openmpt_module_ext
|
||||
|
||||
\param filename The file to load from.
|
||||
\param logfunc Logging function where warning and errors are written. May be NULL.
|
||||
\param loguser Logging function user context. Used to pass any user-defined data associated with this module to the logging function.
|
||||
\param errfunc Error function to define error behaviour. May be NULL.
|
||||
\param erruser Error function user context. Used to pass any user-defined data associated with this module to the error function.
|
||||
\param errorcode Pointer to an integer where an error may get stored. May be NULL.
|
||||
\param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
|
||||
\param ctls A map of initial ctl values, see openmpt_module_get_ctls.
|
||||
\return A pointer to the constructed openmpt_module, or NULL on failure.
|
||||
\sa openmpt_module_ext_create
|
||||
'/
|
||||
Function openmpt_module_ext_create_from_filename(_
|
||||
ByRef filename As String,_
|
||||
ByVal logfunc As openmpt_log_func = 0,_
|
||||
ByVal loguser As Any Ptr = 0,_
|
||||
ByVal errfunc As openmpt_error_func = 0,_
|
||||
ByVal erruser As Any Ptr = 0,_
|
||||
ByVal errorcode As Long Ptr = 0,_
|
||||
ByVal error_message As Const ZString Ptr Ptr = 0,_
|
||||
ByVal ctls As Const openmpt_module_initial_ctl Ptr = 0) As openmpt_module_ext Ptr
|
||||
Var file = fopen(filename, "rb")
|
||||
Var retval = CPtr(openmpt_module Ptr, 0)
|
||||
If(file <> 0) Then
|
||||
retval = openmpt_module_ext_create(openmpt_stream_get_file_callbacks(), file, logfunc, loguser, errfunc, erruser, errorcode, error_message, ctls)
|
||||
fclose(file)
|
||||
EndIf
|
||||
Return retval
|
||||
End Function
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
includedir=@includedir@
|
||||
libdir=@libdir@
|
||||
|
||||
Name: libopenmpt
|
||||
Description: Tracker module player based on OpenMPT
|
||||
URL: https://lib.openmpt.org/
|
||||
Version: @VERSION@
|
||||
Requires.private: @LIBOPENMPT_REQUIRES_PRIVATE@
|
||||
Libs: -L${libdir} -lopenmpt
|
||||
Libs.private: @LIBOPENMPT_LIBS_PRIVATE@
|
||||
Cflags: -I${includedir}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
* libopenmpt_config.h
|
||||
* -------------------
|
||||
* Purpose: libopenmpt public interface configuration
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENMPT_CONFIG_H
|
||||
#define LIBOPENMPT_CONFIG_H
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/*! \defgroup libopenmpt libopenmpt */
|
||||
|
||||
/*! \addtogroup libopenmpt
|
||||
@{
|
||||
*/
|
||||
|
||||
/* provoke warnings if already defined */
|
||||
#define LIBOPENMPT_API
|
||||
#undef LIBOPENMPT_API
|
||||
#define LIBOPENMPT_CXX_API
|
||||
#undef LIBOPENMPT_CXX_API
|
||||
|
||||
/*!
|
||||
@}
|
||||
*/
|
||||
|
||||
/*! \addtogroup libopenmpt_c
|
||||
@{
|
||||
*/
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_buffer.h exists.
|
||||
* \remarks
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_BUFFER)
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_buffer.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_BUFFER
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_fd.h exists.
|
||||
* \since 0.3.0
|
||||
* \remarks
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_FD) || ((OPENMPT_API_VERSION_MAJOR == 0) && ((OPENMPT_API_VERSION_MINOR == 2) || (OPENMPT_API_VERSION_MINOR == 1)))
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_fd.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_FD
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_file.h exists.
|
||||
* \since 0.3.0
|
||||
* \remarks
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_FILE) || ((OPENMPT_API_VERSION_MAJOR == 0) && ((OPENMPT_API_VERSION_MINOR == 2) || (OPENMPT_API_VERSION_MINOR == 1)))
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_file.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_FILE
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_file_mingw.h exists.
|
||||
* \since 0.7.0
|
||||
* \remarks
|
||||
* This macro does not determine if the interfaces required to use libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h are available.
|
||||
* It is the libopenmpt user's responsibility to check for availability of the _off64_t, _ftelli64(), and _fseeki64().
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW)
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_file_mingw.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h exists.
|
||||
* \since 0.7.0
|
||||
* \remarks
|
||||
* This macro does not determine if the interfaces required to use libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h are available.
|
||||
* It is the libopenmpt user's responsibility to check for availability of the __int64, _ftelli64(), and _fseeki64().
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_FILE_MSVCRT)
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_file_msvcrt.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_FILE_MSVCRT
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_file_posix.h exists.
|
||||
* \since 0.7.0
|
||||
* \remarks
|
||||
* This macro does not determine if the interfaces required to use libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h are available.
|
||||
* It is the libopenmpt user's responsibility to check for availability of the _off_t, ftello(), and fseeko().
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_FILE_MINGW)
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_file_mingw.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX
|
||||
|
||||
/*! \brief Defined if libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h exists.
|
||||
* \since 0.7.0
|
||||
* \remarks
|
||||
* This macro does not determine if the interfaces required to use libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h are available.
|
||||
* It is the libopenmpt user's responsibility to check for availability of the off64_t, ftello64(), and fseeko64().
|
||||
* Use the following to check for availability:
|
||||
* \code
|
||||
* #include <libopenmpt/libopenmpt.h>
|
||||
* #if defined(LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX_LFS64)
|
||||
* #include <libopenmpt/libopenmpt_stream_callbacks_file_posix_lfs64.h>
|
||||
* #endif
|
||||
* \endcode
|
||||
*/
|
||||
#define LIBOPENMPT_STREAM_CALLBACKS_FILE_POSIX_LFS64
|
||||
|
||||
/*!
|
||||
@}
|
||||
*/
|
||||
|
||||
/*! \addtogroup libopenmpt
|
||||
@{
|
||||
*/
|
||||
|
||||
#if defined(__DOXYGEN__)
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT __declspec(dllexport)
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT __declspec(dllimport)
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_CLASS __declspec(dllexport)
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_CLASS __declspec(dllimport)
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_CLASS
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_CLASS
|
||||
#endif
|
||||
|
||||
#elif defined(__EMSCRIPTEN__)
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT __attribute__((visibility("default"))) __attribute__((used))
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT __attribute__((visibility("default"))) __attribute__((used))
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC __attribute__((visibility("default"))) __attribute__((used))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL __attribute__((visibility("hidden")))
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_CLASS __attribute__((visibility("hidden")))
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_MEMBER __attribute__((visibility("default"))) __attribute__((used))
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_MEMBER __attribute__((visibility("default"))) __attribute__((used))
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_MEMBER __attribute__((visibility("default"))) __attribute__((used))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_MEMBER __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#elif (defined(__GNUC__) || defined(__clang__)) && defined(_WIN32)
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT __declspec(dllexport)
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT __declspec(dllimport)
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL __attribute__((visibility("hidden")))
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_CLASS __declspec(dllexport)
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_CLASS __declspec(dllimport)
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_CLASS __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL __attribute__((visibility("hidden")))
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_CLASS __attribute__((visibility("default")))
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_CLASS __attribute__((visibility("hidden")))
|
||||
#endif
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT __declspec(dllexport)
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT __declspec(dllimport)
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_CLASS __declspec(dllexport)
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_CLASS __declspec(dllimport)
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_CLASS
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_CLASS
|
||||
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#ifndef LIBOPENMPT_API_HELPER_EXPORT_CLASS
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_CLASS
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_EXPORT_MEMBER
|
||||
#define LIBOPENMPT_API_HELPER_EXPORT_MEMBER
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_IMPORT_CLASS
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_CLASS
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_IMPORT_MEMBER
|
||||
#define LIBOPENMPT_API_HELPER_IMPORT_MEMBER
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_PUBLIC_CLASS
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_CLASS
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_PUBLIC_MEMBER
|
||||
#define LIBOPENMPT_API_HELPER_PUBLIC_MEMBER
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_LOCAL_CLASS
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_CLASS
|
||||
#endif
|
||||
#ifndef LIBOPENMPT_API_HELPER_LOCAL_MEMBER
|
||||
#define LIBOPENMPT_API_HELPER_LOCAL_MEMBER
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LIBOPENMPT_BUILD_DLL)
|
||||
#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_EXPORT
|
||||
#elif defined(LIBOPENMPT_USE_DLL)
|
||||
#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_IMPORT
|
||||
#else
|
||||
#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_PUBLIC
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#if defined(LIBOPENMPT_BUILD_DLL)
|
||||
#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_EXPORT
|
||||
#define LIBOPENMPT_CXX_API_CLASS LIBOPENMPT_API_HELPER_EXPORT_CLASS
|
||||
#define LIBOPENMPT_CXX_API_MEMBER LIBOPENMPT_API_HELPER_EXPORT_MEMBER
|
||||
#elif defined(LIBOPENMPT_USE_DLL)
|
||||
#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_IMPORT
|
||||
#define LIBOPENMPT_CXX_API_CLASS LIBOPENMPT_API_HELPER_IMPORT_CLASS
|
||||
#define LIBOPENMPT_CXX_API_MEMBER LIBOPENMPT_API_HELPER_IMPORT_MEMBER
|
||||
#else
|
||||
#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_PUBLIC
|
||||
#define LIBOPENMPT_CXX_API_CLASS LIBOPENMPT_API_HELPER_PUBLIC_CLASS
|
||||
#define LIBOPENMPT_CXX_API_MEMBER LIBOPENMPT_API_HELPER_PUBLIC_MEMBER
|
||||
#endif
|
||||
|
||||
#if defined(LIBOPENMPT_USE_DLL)
|
||||
#if defined(_MSC_VER) && !defined(_DLL)
|
||||
#error "C++ interface is disabled if libopenmpt is built as a DLL and the runtime is statically linked. This is not supported by microsoft and cannot possibly work. Ever."
|
||||
#undef LIBOPENMPT_CXX_API
|
||||
#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_LOCAL
|
||||
#undef LIBOPENMPT_CXX_API_CLASS
|
||||
#define LIBOPENMPT_CXX_API_CLASS LIBOPENMPT_API_HELPER_LOCAL_CLASS
|
||||
#undef LIBOPENMPT_CXX_API_MEMBER
|
||||
#define LIBOPENMPT_CXX_API_MEMBER LIBOPENMPT_API_HELPER_LOCAL_MEMBER
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@}
|
||||
*/
|
||||
|
||||
|
||||
/* C */
|
||||
|
||||
#if !defined(LIBOPENMPT_NO_DEPRECATE)
|
||||
#if defined(__clang__)
|
||||
#define LIBOPENMPT_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(__GNUC__)
|
||||
#define LIBOPENMPT_DEPRECATED __attribute__((deprecated))
|
||||
#elif defined(_MSC_VER)
|
||||
#define LIBOPENMPT_DEPRECATED __declspec(deprecated)
|
||||
#else
|
||||
#define LIBOPENMPT_DEPRECATED
|
||||
#endif
|
||||
#else
|
||||
#define LIBOPENMPT_DEPRECATED
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#if !defined(LIBOPENMPT_NO_DEPRECATE)
|
||||
LIBOPENMPT_DEPRECATED static const int LIBOPENMPT_DEPRECATED_STRING_CONSTANT = 0;
|
||||
#define LIBOPENMPT_DEPRECATED_STRING( str ) ( LIBOPENMPT_DEPRECATED_STRING_CONSTANT ? ( str ) : ( str ) )
|
||||
#else
|
||||
#define LIBOPENMPT_DEPRECATED_STRING( str ) str
|
||||
#endif
|
||||
#else
|
||||
#define LIBOPENMPT_DEPRECATED_STRING( str ) str
|
||||
#endif
|
||||
|
||||
#if defined(__STDC__) && (__STDC__ == 1)
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
||||
#define LIBOPENMPT_C_INLINE inline
|
||||
#else
|
||||
#define LIBOPENMPT_C_INLINE
|
||||
#endif
|
||||
#else
|
||||
#define LIBOPENMPT_C_INLINE
|
||||
#endif
|
||||
|
||||
|
||||
/* C++ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#if defined(LIBOPENMPT_ASSUME_CPLUSPLUS)
|
||||
#endif
|
||||
|
||||
#if !defined(LIBOPENMPT_NO_DEPRECATE)
|
||||
#define LIBOPENMPT_ATTR_DEPRECATED [[deprecated]]
|
||||
#else
|
||||
#define LIBOPENMPT_ATTR_DEPRECATED
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* clang-format on */
|
||||
|
||||
#include "libopenmpt_version.h"
|
||||
|
||||
#endif /* LIBOPENMPT_CONFIG_H */
|
||||
@@ -0,0 +1,540 @@
|
||||
/*
|
||||
* libopenmpt_cxx.cpp
|
||||
* ------------------
|
||||
* Purpose: libopenmpt C++ interface implementation
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "openmpt/all/BuildSettings.hpp"
|
||||
|
||||
#if defined(__MINGW32__) && !defined(__MINGW64__)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "libopenmpt_internal.h"
|
||||
#include "libopenmpt.hpp"
|
||||
#include "libopenmpt_ext.hpp"
|
||||
|
||||
#include "libopenmpt_impl.hpp"
|
||||
#include "libopenmpt_ext_impl.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace openmpt {
|
||||
|
||||
exception::exception( const std::string & text_ ) noexcept
|
||||
: std::exception()
|
||||
, text(0)
|
||||
{
|
||||
text = static_cast<char*>( std::malloc( text_.length() + 1 ) );
|
||||
if ( text ) {
|
||||
std::memcpy( text, text_.c_str(), text_.length() + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
exception::exception( const exception & other ) noexcept
|
||||
: std::exception()
|
||||
, text(0)
|
||||
{
|
||||
const char * const text_ = ( other.what() ? other.what() : "" );
|
||||
text = static_cast<char*>( std::malloc( std::strlen( text_ ) + 1 ) );
|
||||
if ( text ) {
|
||||
std::memcpy( text, text_, std::strlen( text_ ) + 1 );
|
||||
}
|
||||
}
|
||||
|
||||
exception::exception( exception && other ) noexcept
|
||||
: std::exception()
|
||||
, text(0)
|
||||
{
|
||||
text = std::move( other.text );
|
||||
other.text = 0;
|
||||
}
|
||||
|
||||
exception & exception::operator = ( const exception & other ) noexcept {
|
||||
if ( this == &other ) {
|
||||
return *this;
|
||||
}
|
||||
if ( text ) {
|
||||
std::free( text );
|
||||
text = 0;
|
||||
}
|
||||
const char * const text_ = ( other.what() ? other.what() : "" );
|
||||
text = static_cast<char*>( std::malloc( std::strlen( text_ ) + 1 ) );
|
||||
if ( text ) {
|
||||
std::memcpy( text, text_, std::strlen( text_ ) + 1 );
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
exception & exception::operator = ( exception && other ) noexcept {
|
||||
if ( this == &other ) {
|
||||
return *this;
|
||||
}
|
||||
if ( text ) {
|
||||
std::free( text );
|
||||
text = 0;
|
||||
}
|
||||
text = std::move( other.text );
|
||||
other.text = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
exception::~exception() noexcept {
|
||||
if ( text ) {
|
||||
std::free( text );
|
||||
text = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const char * exception::what() const noexcept {
|
||||
if ( text ) {
|
||||
return text;
|
||||
} else {
|
||||
return "out of memory";
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t get_library_version() {
|
||||
return openmpt::version::get_library_version();
|
||||
}
|
||||
|
||||
std::uint32_t get_core_version() {
|
||||
return openmpt::version::get_core_version();
|
||||
}
|
||||
|
||||
namespace string {
|
||||
|
||||
std::string get( const std::string & key ) {
|
||||
return openmpt::version::get_string( key );
|
||||
}
|
||||
|
||||
} // namespace string
|
||||
|
||||
} // namespace openmpt
|
||||
|
||||
namespace openmpt {
|
||||
|
||||
std::vector<std::string> get_supported_extensions() {
|
||||
return openmpt::module_impl::get_supported_extensions();
|
||||
}
|
||||
|
||||
bool is_extension_supported( const std::string & extension ) {
|
||||
return openmpt::module_impl::is_extension_supported( extension );
|
||||
}
|
||||
bool is_extension_supported2( std::string_view extension ) {
|
||||
return openmpt::module_impl::is_extension_supported( extension );
|
||||
}
|
||||
|
||||
double could_open_probability( std::istream & stream, double effort, std::ostream & log ) {
|
||||
return openmpt::module_impl::could_open_probability( stream, effort, openmpt::helper::make_unique<std_ostream_log>( log ) );
|
||||
}
|
||||
double could_open_propability( std::istream & stream, double effort, std::ostream & log ) {
|
||||
return openmpt::module_impl::could_open_probability( stream, effort, openmpt::helper::make_unique<std_ostream_log>( log ) );
|
||||
}
|
||||
|
||||
std::size_t probe_file_header_get_recommended_size() {
|
||||
return openmpt::module_impl::probe_file_header_get_recommended_size();
|
||||
}
|
||||
int probe_file_header( std::uint64_t flags, const std::byte * data, std::size_t size, std::uint64_t filesize ) {
|
||||
return openmpt::module_impl::probe_file_header( flags, data, size, filesize );
|
||||
}
|
||||
int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size, std::uint64_t filesize ) {
|
||||
return openmpt::module_impl::probe_file_header( flags, data, size, filesize );
|
||||
}
|
||||
int probe_file_header( std::uint64_t flags, const std::byte * data, std::size_t size ) {
|
||||
return openmpt::module_impl::probe_file_header( flags, data, size );
|
||||
}
|
||||
int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size ) {
|
||||
return openmpt::module_impl::probe_file_header( flags, data, size );
|
||||
}
|
||||
int probe_file_header( std::uint64_t flags, std::istream & stream ) {
|
||||
return openmpt::module_impl::probe_file_header( flags, stream );
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4702) // unreachable code
|
||||
#endif // _MSC_VER
|
||||
|
||||
module::module( const module & ) : impl(nullptr) {
|
||||
throw exception("openmpt::module is non-copyable");
|
||||
}
|
||||
|
||||
// cppcheck-suppress operatorEqVarError
|
||||
void module::operator = ( const module & ) {
|
||||
throw exception("openmpt::module is non-copyable");
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
|
||||
module::module() : impl(0) {
|
||||
return;
|
||||
}
|
||||
|
||||
void module::set_impl( module_impl * i ) {
|
||||
impl = i;
|
||||
}
|
||||
|
||||
module::module( std::istream & stream, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( stream, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::vector<std::byte> & data, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::byte * beg, const std::byte * end, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( beg, end - beg, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::byte * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::vector<std::uint8_t> & data, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::uint8_t * beg, const std::uint8_t * end, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( beg, end - beg, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::uint8_t * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const std::vector<char> & data, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const char * beg, const char * end, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( beg, end - beg, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const char * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::module( const void * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : impl(0) {
|
||||
impl = new module_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
}
|
||||
|
||||
module::~module() {
|
||||
delete impl;
|
||||
impl = 0;
|
||||
}
|
||||
|
||||
void module::select_subsong( std::int32_t subsong ) {
|
||||
impl->select_subsong( subsong );
|
||||
}
|
||||
std::int32_t module::get_selected_subsong() const {
|
||||
return impl->get_selected_subsong();
|
||||
}
|
||||
|
||||
std::int32_t module::get_restart_order( std::int32_t subsong ) const {
|
||||
return impl->get_restart_order( subsong );
|
||||
}
|
||||
std::int32_t module::get_restart_row( std::int32_t subsong ) const {
|
||||
return impl->get_restart_row( subsong );
|
||||
}
|
||||
|
||||
void module::set_repeat_count( std::int32_t repeat_count ) {
|
||||
impl->set_repeat_count( repeat_count );
|
||||
}
|
||||
std::int32_t module::get_repeat_count() const {
|
||||
return impl->get_repeat_count();
|
||||
}
|
||||
|
||||
double module::get_duration_seconds() const {
|
||||
return impl->get_duration_seconds();
|
||||
}
|
||||
|
||||
double module::get_time_at_position( std::int32_t order, std::int32_t row ) const {
|
||||
return impl->get_time_at_position( order, row );
|
||||
}
|
||||
|
||||
double module::set_position_seconds( double seconds ) {
|
||||
return impl->set_position_seconds( seconds );
|
||||
}
|
||||
double module::get_position_seconds() const {
|
||||
return impl->get_position_seconds();
|
||||
}
|
||||
|
||||
double module::set_position_order_row( std::int32_t order, std::int32_t row ) {
|
||||
return impl->set_position_order_row( order, row );
|
||||
}
|
||||
|
||||
std::int32_t module::get_render_param( int param ) const {
|
||||
return impl->get_render_param( param );
|
||||
}
|
||||
void module::set_render_param( int param, std::int32_t value ) {
|
||||
impl->set_render_param( param, value );
|
||||
}
|
||||
|
||||
std::size_t module::read( std::int32_t samplerate, std::size_t count, std::int16_t * mono ) {
|
||||
return impl->read( samplerate, count, mono );
|
||||
}
|
||||
std::size_t module::read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right ) {
|
||||
return impl->read( samplerate, count, left, right );
|
||||
}
|
||||
std::size_t module::read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right ) {
|
||||
return impl->read( samplerate, count, left, right, rear_left, rear_right );
|
||||
}
|
||||
std::size_t module::read( std::int32_t samplerate, std::size_t count, float * mono ) {
|
||||
return impl->read( samplerate, count, mono );
|
||||
}
|
||||
std::size_t module::read( std::int32_t samplerate, std::size_t count, float * left, float * right ) {
|
||||
return impl->read( samplerate, count, left, right );
|
||||
}
|
||||
std::size_t module::read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right ) {
|
||||
return impl->read( samplerate, count, left, right, rear_left, rear_right );
|
||||
}
|
||||
std::size_t module::read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo ) {
|
||||
return impl->read_interleaved_stereo( samplerate, count, interleaved_stereo );
|
||||
}
|
||||
std::size_t module::read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad ) {
|
||||
return impl->read_interleaved_quad( samplerate, count, interleaved_quad );
|
||||
}
|
||||
std::size_t module::read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo ) {
|
||||
return impl->read_interleaved_stereo( samplerate, count, interleaved_stereo );
|
||||
}
|
||||
std::size_t module::read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad ) {
|
||||
return impl->read_interleaved_quad( samplerate, count, interleaved_quad );
|
||||
}
|
||||
|
||||
std::vector<std::string> module::get_metadata_keys() const {
|
||||
return impl->get_metadata_keys();
|
||||
}
|
||||
std::string module::get_metadata( const std::string & key ) const {
|
||||
return impl->get_metadata( key );
|
||||
}
|
||||
|
||||
double module::get_current_estimated_bpm() const {
|
||||
return impl->get_current_estimated_bpm();
|
||||
}
|
||||
std::int32_t module::get_current_speed() const {
|
||||
return impl->get_current_speed();
|
||||
}
|
||||
std::int32_t module::get_current_tempo() const {
|
||||
return impl->get_current_tempo();
|
||||
}
|
||||
double module::get_current_tempo2() const {
|
||||
return impl->get_current_tempo2();
|
||||
}
|
||||
std::int32_t module::get_current_order() const {
|
||||
return impl->get_current_order();
|
||||
}
|
||||
std::int32_t module::get_current_pattern() const {
|
||||
return impl->get_current_pattern();
|
||||
}
|
||||
std::int32_t module::get_current_row() const {
|
||||
return impl->get_current_row();
|
||||
}
|
||||
std::int32_t module::get_current_playing_channels() const {
|
||||
return impl->get_current_playing_channels();
|
||||
}
|
||||
|
||||
float module::get_current_channel_vu_mono( std::int32_t channel ) const {
|
||||
return impl->get_current_channel_vu_mono( channel );
|
||||
}
|
||||
float module::get_current_channel_vu_left( std::int32_t channel ) const {
|
||||
return impl->get_current_channel_vu_left( channel );
|
||||
}
|
||||
float module::get_current_channel_vu_right( std::int32_t channel ) const {
|
||||
return impl->get_current_channel_vu_right( channel );
|
||||
}
|
||||
float module::get_current_channel_vu_rear_left( std::int32_t channel ) const {
|
||||
return impl->get_current_channel_vu_rear_left( channel );
|
||||
}
|
||||
float module::get_current_channel_vu_rear_right( std::int32_t channel ) const {
|
||||
return impl->get_current_channel_vu_rear_right( channel );
|
||||
}
|
||||
|
||||
std::int32_t module::get_num_subsongs() const {
|
||||
return impl->get_num_subsongs();
|
||||
}
|
||||
std::int32_t module::get_num_channels() const {
|
||||
return impl->get_num_channels();
|
||||
}
|
||||
std::int32_t module::get_num_orders() const {
|
||||
return impl->get_num_orders();
|
||||
}
|
||||
std::int32_t module::get_num_patterns() const {
|
||||
return impl->get_num_patterns();
|
||||
}
|
||||
std::int32_t module::get_num_instruments() const {
|
||||
return impl->get_num_instruments();
|
||||
}
|
||||
std::int32_t module::get_num_samples() const {
|
||||
return impl->get_num_samples();
|
||||
}
|
||||
|
||||
std::vector<std::string> module::get_subsong_names() const {
|
||||
return impl->get_subsong_names();
|
||||
}
|
||||
std::vector<std::string> module::get_channel_names() const {
|
||||
return impl->get_channel_names();
|
||||
}
|
||||
std::vector<std::string> module::get_order_names() const {
|
||||
return impl->get_order_names();
|
||||
}
|
||||
std::vector<std::string> module::get_pattern_names() const {
|
||||
return impl->get_pattern_names();
|
||||
}
|
||||
std::vector<std::string> module::get_instrument_names() const {
|
||||
return impl->get_instrument_names();
|
||||
}
|
||||
std::vector<std::string> module::get_sample_names() const {
|
||||
return impl->get_sample_names();
|
||||
}
|
||||
|
||||
std::int32_t module::get_order_pattern( std::int32_t order ) const {
|
||||
return impl->get_order_pattern( order );
|
||||
}
|
||||
|
||||
bool module::is_order_skip_entry(std::int32_t order) const {
|
||||
return impl->is_order_skip_entry( order );
|
||||
}
|
||||
bool module::is_pattern_skip_item( std::int32_t pattern ) const {
|
||||
return module_impl::is_pattern_skip_item( pattern );
|
||||
}
|
||||
bool module::is_order_stop_entry( std::int32_t order ) const {
|
||||
return impl->is_order_stop_entry( order );
|
||||
}
|
||||
bool module::is_pattern_stop_item( std::int32_t pattern ) const {
|
||||
return module_impl::is_pattern_stop_item( pattern );
|
||||
}
|
||||
|
||||
std::int32_t module::get_pattern_num_rows( std::int32_t pattern ) const {
|
||||
return impl->get_pattern_num_rows( pattern );
|
||||
}
|
||||
|
||||
std::int32_t module::get_pattern_rows_per_beat( std::int32_t pattern ) const {
|
||||
return impl->get_pattern_rows_per_beat( pattern );
|
||||
}
|
||||
|
||||
std::int32_t module::get_pattern_rows_per_measure( std::int32_t pattern ) const {
|
||||
return impl->get_pattern_rows_per_measure( pattern );
|
||||
}
|
||||
|
||||
std::uint8_t module::get_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const {
|
||||
return impl->get_pattern_row_channel_command( pattern, row, channel, command );
|
||||
}
|
||||
|
||||
std::string module::format_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const {
|
||||
return impl->format_pattern_row_channel_command( pattern, row, channel, command );
|
||||
}
|
||||
std::string module::highlight_pattern_row_channel_command( std::int32_t pattern, std::int32_t row, std::int32_t channel, int command ) const {
|
||||
return impl->highlight_pattern_row_channel_command( pattern, row, channel, command );
|
||||
}
|
||||
|
||||
std::string module::format_pattern_row_channel( std::int32_t pattern, std::int32_t row, std::int32_t channel, std::size_t width, bool pad ) const {
|
||||
return impl->format_pattern_row_channel( pattern, row, channel, width, pad );
|
||||
}
|
||||
std::string module::highlight_pattern_row_channel( std::int32_t pattern, std::int32_t row, std::int32_t channel, std::size_t width, bool pad ) const {
|
||||
return impl->highlight_pattern_row_channel( pattern, row, channel, width, pad );
|
||||
}
|
||||
|
||||
std::vector<std::string> module::get_ctls() const {
|
||||
return impl->get_ctls();
|
||||
}
|
||||
|
||||
std::string module::ctl_get( const std::string & ctl ) const {
|
||||
return impl->ctl_get( ctl );
|
||||
}
|
||||
bool module::ctl_get_boolean( std::string_view ctl ) const {
|
||||
return impl->ctl_get_boolean( ctl );
|
||||
}
|
||||
std::int64_t module::ctl_get_integer( std::string_view ctl ) const {
|
||||
return impl->ctl_get_integer( ctl );
|
||||
}
|
||||
double module::ctl_get_floatingpoint( std::string_view ctl ) const {
|
||||
return impl->ctl_get_floatingpoint( ctl );
|
||||
}
|
||||
std::string module::ctl_get_text( std::string_view ctl ) const {
|
||||
return impl->ctl_get_text( ctl );
|
||||
}
|
||||
|
||||
void module::ctl_set( const std::string & ctl, const std::string & value ) {
|
||||
impl->ctl_set( ctl, value );
|
||||
}
|
||||
void module::ctl_set_boolean( std::string_view ctl, bool value ) {
|
||||
impl->ctl_set_boolean( ctl, value );
|
||||
}
|
||||
void module::ctl_set_integer( std::string_view ctl, std::int64_t value ) {
|
||||
impl->ctl_set_integer( ctl, value );
|
||||
}
|
||||
void module::ctl_set_floatingpoint( std::string_view ctl, double value ) {
|
||||
impl->ctl_set_floatingpoint( ctl, value );
|
||||
}
|
||||
void module::ctl_set_text( std::string_view ctl, std::string_view value ) {
|
||||
impl->ctl_set_text( ctl, value );
|
||||
}
|
||||
|
||||
module_ext::module_ext( std::istream & stream, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( stream, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const std::vector<std::uint8_t> & data, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const std::vector<char> & data, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const std::vector<std::byte> & data, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const std::uint8_t * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const char * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const std::byte * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::module_ext( const void * data, std::size_t size, std::ostream & log, const std::map< std::string, std::string > & ctls ) : ext_impl(0) {
|
||||
ext_impl = new module_ext_impl( data, size, openmpt::helper::make_unique<std_ostream_log>( log ), ctls );
|
||||
set_impl( ext_impl );
|
||||
}
|
||||
module_ext::~module_ext() {
|
||||
set_impl( 0 );
|
||||
delete ext_impl;
|
||||
ext_impl = 0;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4702) // unreachable code
|
||||
#endif // _MSC_VER
|
||||
module_ext::module_ext( const module_ext & other ) : module(other), ext_impl(nullptr) {
|
||||
throw std::runtime_error("openmpt::module_ext is non-copyable");
|
||||
}
|
||||
// cppcheck-suppress operatorEqVarError
|
||||
void module_ext::operator = ( const module_ext & ) {
|
||||
throw std::runtime_error("openmpt::module_ext is non-copyable");
|
||||
}
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
|
||||
void * module_ext::get_interface( const std::string & interface_id ) {
|
||||
return ext_impl->get_interface( interface_id );
|
||||
}
|
||||
|
||||
} // namespace openmpt
|
||||
@@ -0,0 +1,426 @@
|
||||
/*
|
||||
* libopenmpt_ext.h
|
||||
* ----------------
|
||||
* Purpose: libopenmpt public c interface for libopenmpt extensions
|
||||
* Notes :
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_H
|
||||
#define LIBOPENMPT_EXT_H
|
||||
|
||||
#include "libopenmpt_config.h"
|
||||
#include "libopenmpt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \page libopenmpt_ext_c_overview libopenmpt_ext C API
|
||||
*
|
||||
* libopenmpt_ext is included in all builds by default.
|
||||
*
|
||||
* \section libopenmpt-ext-c-detailed Detailed documentation
|
||||
*
|
||||
* \ref libopenmpt_ext_c
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \defgroup libopenmpt_ext_c libopenmpt_ext C */
|
||||
|
||||
/*! \addtogroup libopenmpt_ext_c
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*! \brief Opaque type representing a libopenmpt extension module
|
||||
*/
|
||||
typedef struct openmpt_module_ext openmpt_module_ext;
|
||||
|
||||
/*! \brief Construct an openmpt_module_ext
|
||||
*
|
||||
* \param stream_callbacks Input stream callback operations.
|
||||
* \param stream Input stream to load the module from.
|
||||
* \param logfunc Logging function where warning and errors are written. The logging function may be called throughout the lifetime of openmpt_module_ext. May be NULL.
|
||||
* \param loguser User-defined data associated with this module. This value will be passed to the logging callback function (logfunc)
|
||||
* \param errfunc Error function to define error behaviour. May be NULL.
|
||||
* \param erruser Error function user context. Used to pass any user-defined data associated with this module to the logging function.
|
||||
* \param error Pointer to an integer where an error may get stored. May be NULL.
|
||||
* \param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
|
||||
* \param ctls A map of initial ctl values, see openmpt_module_get_ctls.
|
||||
* \return A pointer to the constructed openmpt_module_ext, or NULL on failure.
|
||||
* \remarks The input data can be discarded after an openmpt_module_ext has been constructed successfully.
|
||||
* \sa openmpt_stream_callbacks
|
||||
* \sa \ref libopenmpt_c_fileio
|
||||
* \since 0.3.0
|
||||
*/
|
||||
LIBOPENMPT_API openmpt_module_ext * openmpt_module_ext_create( openmpt_stream_callbacks stream_callbacks, void * stream, openmpt_log_func logfunc, void * loguser, openmpt_error_func errfunc, void * erruser, int * error, const char * * error_message, const openmpt_module_initial_ctl * ctls );
|
||||
|
||||
/*! \brief Construct an openmpt_module_ext
|
||||
*
|
||||
* \param filedata Data to load the module from.
|
||||
* \param filesize Amount of data available.
|
||||
* \param logfunc Logging function where warning and errors are written. The logging function may be called throughout the lifetime of openmpt_module_ext.
|
||||
* \param loguser User-defined data associated with this module. This value will be passed to the logging callback function (logfunc)
|
||||
* \param errfunc Error function to define error behaviour. May be NULL.
|
||||
* \param erruser Error function user context. Used to pass any user-defined data associated with this module to the logging function.
|
||||
* \param error Pointer to an integer where an error may get stored. May be NULL.
|
||||
* \param error_message Pointer to a string pointer where an error message may get stored. May be NULL.
|
||||
* \param ctls A map of initial ctl values, see openmpt_module_get_ctls.
|
||||
* \return A pointer to the constructed openmpt_module_ext, or NULL on failure.
|
||||
* \remarks The input data can be discarded after an openmpt_module_ext has been constructed successfully.
|
||||
* \sa \ref libopenmpt_c_fileio
|
||||
* \since 0.3.0
|
||||
*/
|
||||
LIBOPENMPT_API openmpt_module_ext * openmpt_module_ext_create_from_memory( const void * filedata, size_t filesize, openmpt_log_func logfunc, void * loguser, openmpt_error_func errfunc, void * erruser, int * error, const char * * error_message, const openmpt_module_initial_ctl * ctls );
|
||||
|
||||
/*! \brief Unload a previously created openmpt_module_ext from memory.
|
||||
*
|
||||
* \param mod_ext The module to unload.
|
||||
*/
|
||||
LIBOPENMPT_API void openmpt_module_ext_destroy( openmpt_module_ext * mod_ext );
|
||||
|
||||
/*! \brief Retrieve the openmpt_module handle from an openmpt_module_ext handle.
|
||||
*
|
||||
* \param mod_ext The extension module handle to convert
|
||||
* \return An equivalent openmpt_module handle to pass to standard libopenmpt functions
|
||||
* \since 0.3.0
|
||||
*/
|
||||
LIBOPENMPT_API openmpt_module * openmpt_module_ext_get_module( openmpt_module_ext * mod_ext );
|
||||
|
||||
/*! Retrieve a libopenmpt extension.
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param interface_id The name of the extension interface to retrieve (e.g. LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS).
|
||||
* \param interface Appropriate structure of interface function pointers which is to be filled by this function (e.g. a pointer to a openmpt_module_ext_interface_pattern_vis structure).
|
||||
* \param interface_size Size of the interface's structure of function pointers (e.g. sizeof(openmpt_module_ext_interface_pattern_vis)).
|
||||
* \return 1 on success, 0 if the interface was not found.
|
||||
* \since 0.3.0
|
||||
*/
|
||||
LIBOPENMPT_API int openmpt_module_ext_get_interface( openmpt_module_ext * mod_ext, const char * interface_id, void * interface, size_t interface_size );
|
||||
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_PATTERN_VIS "pattern_vis"
|
||||
#endif
|
||||
|
||||
/*! Pattern command type */
|
||||
#define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_UNKNOWN 0
|
||||
#define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_GENERAL 1
|
||||
#define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_GLOBAL 2
|
||||
#define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_VOLUME 3
|
||||
#define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_PANNING 4
|
||||
#define OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_PITCH 5
|
||||
|
||||
typedef struct openmpt_module_ext_interface_pattern_vis {
|
||||
/*! Get pattern command type for pattern highlighting
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param pattern The pattern whose data should be retrieved.
|
||||
* \param row The row from which the data should be retrieved.
|
||||
* \param channel The channel from which the data should be retrieved.
|
||||
* \return The command type in the effect column at the given pattern position (see OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_*)
|
||||
* \sa openmpt_module_ext_interface_pattern_vis::get_pattern_row_channel_volume_effect_type
|
||||
*/
|
||||
int ( * get_pattern_row_channel_volume_effect_type ) ( openmpt_module_ext * mod_ext, int32_t pattern, int32_t row, int32_t channel );
|
||||
|
||||
/*! Get pattern command type for pattern highlighting
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param pattern The pattern whose data should be retrieved.
|
||||
* \param row The row from which the data should be retrieved.
|
||||
* \param channel The channel from which the data should be retrieved.
|
||||
* \return The command type in the effect column at the given pattern position (see OPENMPT_MODULE_EXT_INTERFACE_PATTERN_VIS_EFFECT_TYPE_*)
|
||||
* \sa openmpt_module_ext_interface_pattern_vis::get_pattern_row_channel_volume_effect_type
|
||||
*/
|
||||
int ( * get_pattern_row_channel_effect_type ) ( openmpt_module_ext * mod_ext, int32_t pattern, int32_t row, int32_t channel );
|
||||
} openmpt_module_ext_interface_pattern_vis;
|
||||
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE "interactive"
|
||||
#endif
|
||||
|
||||
typedef struct openmpt_module_ext_interface_interactive {
|
||||
/*! Set the current ticks per row (speed)
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param speed The new tick count in range [1, 65535].
|
||||
* \return 1 on success, 0 on failure.
|
||||
* \remarks The tick count may be reset by pattern commands at any time.
|
||||
* \sa openmpt_module_get_current_speed
|
||||
*/
|
||||
int ( * set_current_speed ) ( openmpt_module_ext * mod_ext, int32_t speed );
|
||||
|
||||
/*! Set the current module tempo
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
|
||||
* \return 1 on success, 0 on failure.
|
||||
* \remarks The tempo may be reset by pattern commands at any time. Use openmpt_module_ext_interface_interactive::set_tempo_factor to apply a tempo factor that is independent of pattern commands.
|
||||
* \sa openmpt_module_get_current_tempo
|
||||
* \deprecated Please use openmpt_module_ext_interface_interactive3::set_current_tempo2().
|
||||
*/
|
||||
LIBOPENMPT_DEPRECATED int ( * set_current_tempo ) ( openmpt_module_ext * mod_ext, int32_t tempo );
|
||||
|
||||
/*! Set the current module tempo factor without affecting playback pitch
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param factor The new tempo factor in range ]0.0, 4.0] - 1.0 means unmodified tempo.
|
||||
* \return 1 on success, 0 on failure.
|
||||
* \remarks Modifying the tempo without applying the same pitch factor using openmpt_module_ext_interface_interactive::set_pitch_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
|
||||
* \sa openmpt_module_ext_interface_interactive::get_tempo_factor
|
||||
*/
|
||||
int ( * set_tempo_factor ) ( openmpt_module_ext * mod_ext, double factor );
|
||||
|
||||
/*! Gets the current module tempo factor
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \return The current tempo factor.
|
||||
* \sa openmpt_module_ext_interface_interactive::set_tempo_factor
|
||||
*/
|
||||
double ( * get_tempo_factor ) ( openmpt_module_ext * mod_ext );
|
||||
|
||||
/*! Set the current module pitch factor without affecting playback speed
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param factor The new pitch factor in range ]0.0, 4.0] - 1.0 means unmodified pitch.
|
||||
* \return 1 on success, 0 on failure.
|
||||
* \remarks Modifying the pitch without applying the the same tempo factor using openmpt_module_ext_interface_interactive::set_tempo_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
|
||||
* \remarks To shift the pich by `n` semitones, the parameter can be calculated as follows: `pow( 2.0, n / 12.0 )`
|
||||
* \sa openmpt_module_ext_interface_interactive::get_pitch_factor
|
||||
*/
|
||||
int ( * set_pitch_factor ) ( openmpt_module_ext * mod_ext, double factor );
|
||||
|
||||
/*! Gets the current module pitch factor
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \return The current pitch factor.
|
||||
* \sa openmpt_module_ext_interface_interactive::set_pitch_factor
|
||||
*/
|
||||
double ( * get_pitch_factor ) ( openmpt_module_ext * mod_ext );
|
||||
|
||||
/*! Set the current global volume
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param volume The new global volume in range [0.0, 1.0]
|
||||
* \return 1 on success, 0 on failure.
|
||||
* \remarks The global volume may be reset by pattern commands at any time. Use openmpt_module_set_render_param to apply a global overall volume factor that is independent of pattern commands.
|
||||
* \sa openmpt_module_ext_interface_interactive::get_global_volume
|
||||
*/
|
||||
int ( * set_global_volume ) ( openmpt_module_ext * mod_ext, double volume );
|
||||
|
||||
/*! Get the current global volume
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \return The current global volume in range [0.0, 1.0]
|
||||
* \sa openmpt_module_ext_interface_interactive::set_global_volume
|
||||
*/
|
||||
double ( * get_global_volume ) ( openmpt_module_ext * mod_ext );
|
||||
|
||||
/*! Set the current channel volume for a channel
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose volume should be set, in range [0, openmpt_module_get_num_channels()[
|
||||
* \param volume The new channel volume in range [0.0, 1.0]
|
||||
* \return 1 on success, 0 on failure (channel out of range).
|
||||
* \remarks The channel volume may be reset by pattern commands at any time.
|
||||
* \sa openmpt_module_ext_interface_interactive::get_channel_volume
|
||||
*/
|
||||
int ( * set_channel_volume ) ( openmpt_module_ext * mod_ext, int32_t channel, double volume );
|
||||
|
||||
/*! Get the current channel volume for a channel
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose volume should be retrieved, in range [0, openmpt_module_get_num_channels()[
|
||||
* \return The current channel volume in range [0.0, 1.0]
|
||||
* \sa openmpt_module_ext_interface_interactive::set_channel_volume
|
||||
*/
|
||||
double ( * get_channel_volume ) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
/*! Set the current mute status for a channel
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose mute status should be set, in range [0, openmpt_module_get_num_channels()[
|
||||
* \param mute The new mute status. true is muted, false is unmuted.
|
||||
* \return 1 on success, 0 on failure (channel out of range).
|
||||
* \sa openmpt_module_ext_interface_interactive::get_channel_mute_status
|
||||
*/
|
||||
int ( * set_channel_mute_status ) ( openmpt_module_ext * mod_ext, int32_t channel, int mute );
|
||||
|
||||
/*! Get the current mute status for a channel
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose mute status should be retrieved, in range [0, openmpt_module_get_num_channels()[
|
||||
* \return The current channel mute status. 1 is muted, 0 is unmuted, -1 means the instrument was out of range
|
||||
* \sa openmpt_module_ext_interface_interactive::set_channel_mute_status
|
||||
*/
|
||||
int ( * get_channel_mute_status ) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
/*! Set the current mute status for an instrument
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param instrument The instrument whose mute status should be set, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
|
||||
* \param mute The new mute status. true is muted, false is unmuted.
|
||||
* \return 1 on success, 0 on failure (instrument out of range).
|
||||
* \sa openmpt_module_ext_interface_interactive::get_instrument_mute_status
|
||||
*/
|
||||
int ( * set_instrument_mute_status ) ( openmpt_module_ext * mod_ext, int32_t instrument, int mute );
|
||||
|
||||
/*! Get the current mute status for an instrument
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param instrument The instrument whose mute status should be retrieved, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
|
||||
* \return The current instrument mute status. 1 is muted, 0 is unmuted, -1 means the instrument was out of range
|
||||
* \sa openmpt_module_ext_interface_interactive::set_instrument_mute_status
|
||||
*/
|
||||
int ( * get_instrument_mute_status ) ( openmpt_module_ext * mod_ext, int32_t instrument );
|
||||
|
||||
/*! Play a note using the specified instrument
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param instrument The instrument that should be played, in range [0, openmpt_module_get_num_instruments()[ if openmpt_module_get_num_instruments is not 0, otherwise in [0, openmpt_module_get_num_samples()[
|
||||
* \param note The note to play, in rage [0, 119]. 60 is the middle C.
|
||||
* \param volume The volume at which the note should be triggered, in range [0.0, 1.0]
|
||||
* \param panning The panning position at which the note should be triggered, in range [-1.0, 1.0], 0.0 is center.
|
||||
* \return The channel on which the note is played. This can pe be passed to openmpt_module_ext_interface_interactive::stop_note to stop the note. -1 means that no channel could be allocated and the note is not played.
|
||||
* \sa openmpt_module_ext_interface_interactive::stop_note
|
||||
* \sa openmpt_module_ext_interface_interactive2::note_off
|
||||
* \sa openmpt_module_ext_interface_interactive2::note_fade
|
||||
*/
|
||||
int32_t ( * play_note ) ( openmpt_module_ext * mod_ext, int32_t instrument, int32_t note, double volume, double panning );
|
||||
|
||||
/*! Stop the note playing on the specified channel
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel on which the note should be stopped. This is the value returned by a previous play_note call.
|
||||
* \return 1 on success, 0 on failure (channel out of range).
|
||||
* \sa openmpt_module_ext_interface_interactive::play_note
|
||||
* \sa openmpt_module_ext_interface_interactive2::note_off
|
||||
* \sa openmpt_module_ext_interface_interactive2::note_fade
|
||||
*/
|
||||
int ( * stop_note ) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
} openmpt_module_ext_interface_interactive;
|
||||
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE2
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE2 "interactive2"
|
||||
#endif
|
||||
|
||||
typedef struct openmpt_module_ext_interface_interactive2 {
|
||||
//! Sends a key-off command for the note playing on the specified channel
|
||||
/*!
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel on which the key-off event should be triggered. This is the value returned by a previous play_note call.
|
||||
* \return 1 on success, 0 on failure (channel out of range).
|
||||
* \remarks This method releases envelopes and sample sustain loops. If the sample has no sustain loop, or if the module does not use instruments, it does nothing.
|
||||
* \sa openmpt_module_ext_interface_interactive::play_note
|
||||
* \sa openmpt_module_ext_interface_interactive::stop_note
|
||||
* \sa openmpt_module_ext_interface_interactive2::note_fade
|
||||
* \since 0.6.0
|
||||
*/
|
||||
int ( *note_off ) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
//! Sends a note fade command for the note playing on the specified channel
|
||||
/*!
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel on which the note should be faded. This is the value returned by a previous play_note call.
|
||||
* \return 1 on success, 0 on failure (channel out of range).
|
||||
* \remarks This method uses the instrument's fade-out value. If the module does not use instruments, or the instrument's fade-out value is 0, it does nothing.
|
||||
* \sa openmpt_module_ext_interface_interactive::play_note
|
||||
* \sa openmpt_module_ext_interface_interactive::stop_note
|
||||
* \sa openmpt_module_ext_interface_interactive2::note_fade
|
||||
* \since 0.6.0
|
||||
*/
|
||||
int ( *note_fade ) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
//! Set the current panning for a channel
|
||||
/*!
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel that should be panned. This is the value returned by a previous play_note call.
|
||||
* \param panning The panning position to set on the channel, in range [-1.0, 1.0], 0.0 is center.
|
||||
* \return 1 on success, 0 on failure (channel out of range).
|
||||
* \remarks This command affects subsequent notes played on the same channel, and may itself be overridden by subsequent panning commands encountered in the module itself.
|
||||
* \sa openmpt_module_ext_interface_interactive2::get_channel_panning
|
||||
* \since 0.6.0
|
||||
*/
|
||||
int ( *set_channel_panning) ( openmpt_module_ext * mod_ext, int32_t channel, double panning );
|
||||
|
||||
//! Get the current panning position for a channel
|
||||
/*!
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose panning should be retrieved. This is the value returned by a previous play_note call.
|
||||
* \return The current channel panning, in range [-1.0, 1.0], 0.0 is center.
|
||||
* \sa openmpt_module_ext_interface_interactive2::set_channel_panning
|
||||
* \since 0.6.0
|
||||
*/
|
||||
double (*get_channel_panning) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
//! Set the finetune for the currently playing note on a channel
|
||||
/*!
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose finetune will be changed, in range [0, openmpt::module::get_num_channels()[
|
||||
* \param finetune The finetune to set on the channel, in range [-1.0, 1.0], 0.0 is center.
|
||||
* \throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
* \remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
|
||||
* \remarks This command does not affect subsequent notes played on the same channel, but may itself be overridden by subsequent finetune commands encountered in the module itself.
|
||||
* \sa openmpt_module_ext_interface_interactive2::get_note_finetune
|
||||
* \since 0.6.0
|
||||
*/
|
||||
int ( *set_note_finetune) ( openmpt_module_ext * mod_ext, int32_t channel, double finetune );
|
||||
|
||||
//! Get the finetune for the currently playing note on a channel
|
||||
/*!
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param channel The channel whose finetune should be retrieved, in range [0, openmpt::module::get_num_channels()[
|
||||
* \return The current channel finetune, in range [-1.0, 1.0], 0.0 is center.
|
||||
* \remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
|
||||
* \throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
* \sa openmpt_module_ext_interface_interactive2::set_note_finetune
|
||||
* \since 0.6.0
|
||||
*/
|
||||
double (*get_note_finetune) ( openmpt_module_ext * mod_ext, int32_t channel );
|
||||
|
||||
} openmpt_module_ext_interface_interactive2;
|
||||
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE3
|
||||
#define LIBOPENMPT_EXT_C_INTERFACE_INTERACTIVE3 "interactive3"
|
||||
#endif
|
||||
|
||||
typedef struct openmpt_module_ext_interface_interactive3 {
|
||||
|
||||
/*! Set the current module tempo
|
||||
*
|
||||
* \param mod_ext The module handle to work on.
|
||||
* \param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
|
||||
* \return 1 on success, 0 on failure.
|
||||
* \remarks The tempo may be reset by pattern commands at any time. Use openmpt_module_ext_interface_interactive::set_tempo_factor to apply a tempo factor that is independent of pattern commands.
|
||||
* \sa openmpt_module_get_current_tempo2
|
||||
*/
|
||||
int ( * set_current_tempo2 ) ( openmpt_module_ext * mod_ext, double tempo );
|
||||
|
||||
} openmpt_module_ext_interface_interactive3;
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#endif /* LIBOPENMPT_EXT_H */
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* libopenmpt_ext.hpp
|
||||
* ------------------
|
||||
* Purpose: libopenmpt public c++ interface for libopenmpt extensions
|
||||
* Notes :
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_HPP
|
||||
#define LIBOPENMPT_EXT_HPP
|
||||
|
||||
#include "libopenmpt_config.h"
|
||||
#include "libopenmpt.hpp"
|
||||
|
||||
/*!
|
||||
* \page libopenmpt_ext_cpp_overview libopenmpt_ext C++ API
|
||||
*
|
||||
* libopenmpt_ext is now included in all builds by default.
|
||||
*
|
||||
* \section libopenmpt-ext-cpp-detailed Detailed documentation
|
||||
*
|
||||
* \ref libopenmpt_ext_cpp
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \defgroup libopenmpt_ext_cpp libopenmpt_ext C++ */
|
||||
|
||||
namespace openmpt {
|
||||
|
||||
/*! \addtogroup libopenmpt_ext_cpp
|
||||
@{
|
||||
*/
|
||||
|
||||
class module_ext_impl;
|
||||
|
||||
class LIBOPENMPT_CXX_API_CLASS module_ext : public module {
|
||||
|
||||
private:
|
||||
module_ext_impl * ext_impl;
|
||||
private:
|
||||
// non-copyable
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const module_ext & );
|
||||
LIBOPENMPT_CXX_API_MEMBER void operator = ( const module_ext & );
|
||||
public:
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( std::istream & stream, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const std::vector<std::byte> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const std::vector<std::uint8_t> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const std::vector<char> & data, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const std::byte * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const std::uint8_t * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const char * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER module_ext( const void * data, std::size_t size, std::ostream & log = std::clog, const std::map< std::string, std::string > & ctls = detail::initial_ctls_map() );
|
||||
LIBOPENMPT_CXX_API_MEMBER virtual ~module_ext();
|
||||
|
||||
public:
|
||||
|
||||
//! Retrieve a libopenmpt extension.
|
||||
/*! Example: Retrieving the interactive extension to change the tempo of a module:
|
||||
\code{.cpp}
|
||||
openmpt::module_ext *mod = new openmpt::module_ext( stream );
|
||||
#ifdef LIBOPENMPT_EXT_INTERFACE_INTERACTIVE
|
||||
openmpt::ext::interactive *interactive = static_cast<openmpt::ext::interactive *>( self->mod->get_interface( openmpt::ext::interactive_id ) );
|
||||
if ( interactive ) {
|
||||
interactive->set_tempo_factor( 2.0 ); // play module at double speed
|
||||
} else {
|
||||
// interface not available
|
||||
}
|
||||
#else
|
||||
// interfae not available
|
||||
#endif
|
||||
\endcode
|
||||
\param interface_id The name of the extension interface to retrieve.
|
||||
\return The interface object. This may be a nullptr if the extension was not found.
|
||||
*/
|
||||
LIBOPENMPT_CXX_API_MEMBER void * get_interface( const std::string & interface_id );
|
||||
|
||||
}; // class module_ext
|
||||
|
||||
/*!
|
||||
@}
|
||||
*/
|
||||
|
||||
namespace ext {
|
||||
|
||||
/*! \addtogroup libopenmpt_ext_cpp
|
||||
@{
|
||||
*/
|
||||
|
||||
#define LIBOPENMPT_DECLARE_EXT_CXX_INTERFACE(name) \
|
||||
static const char name ## _id [] = # name ; \
|
||||
class name; \
|
||||
/**/
|
||||
|
||||
#define LIBOPENMPT_EXT_CXX_INTERFACE(name) \
|
||||
protected: \
|
||||
name () {} \
|
||||
virtual ~ name () {} \
|
||||
public: \
|
||||
/**/
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_INTERFACE_PATTERN_VIS
|
||||
#define LIBOPENMPT_EXT_INTERFACE_PATTERN_VIS
|
||||
#endif
|
||||
|
||||
LIBOPENMPT_DECLARE_EXT_CXX_INTERFACE(pattern_vis)
|
||||
|
||||
class pattern_vis {
|
||||
|
||||
LIBOPENMPT_EXT_CXX_INTERFACE(pattern_vis)
|
||||
|
||||
//! Pattern command type
|
||||
enum effect_type {
|
||||
|
||||
effect_unknown = 0,
|
||||
effect_general = 1,
|
||||
effect_global = 2,
|
||||
effect_volume = 3,
|
||||
effect_panning = 4,
|
||||
effect_pitch = 5
|
||||
|
||||
}; // enum effect_type
|
||||
|
||||
//! Get pattern command type for pattern highlighting
|
||||
/*!
|
||||
\param pattern The pattern whose data should be retrieved.
|
||||
\param row The row from which the data should be retrieved.
|
||||
\param channel The channel from which the data should be retrieved.
|
||||
\return The command type in the effect column at the given pattern position (see openmpt::ext::pattern_vis::effect_type)
|
||||
\sa openmpt::ext::pattern_vis::get_pattern_row_channel_effect_type
|
||||
*/
|
||||
virtual effect_type get_pattern_row_channel_volume_effect_type( std::int32_t pattern, std::int32_t row, std::int32_t channel ) const = 0;
|
||||
|
||||
//! Get pattern command type for pattern highlighting
|
||||
/*!
|
||||
\param pattern The pattern whose data should be retrieved.
|
||||
\param row The row from which the data should be retrieved.
|
||||
\param channel The channel from which the data should be retrieved.
|
||||
\return The command type in the volume column at the given pattern position (see openmpt::ext::pattern_vis::effect_type)
|
||||
\sa openmpt::ext::pattern_vis::get_pattern_row_channel_volume_effect_type
|
||||
*/
|
||||
virtual effect_type get_pattern_row_channel_effect_type( std::int32_t pattern, std::int32_t row, std::int32_t channel ) const = 0;
|
||||
|
||||
}; // class pattern_vis
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_INTERFACE_INTERACTIVE
|
||||
#define LIBOPENMPT_EXT_INTERFACE_INTERACTIVE
|
||||
#endif
|
||||
|
||||
LIBOPENMPT_DECLARE_EXT_CXX_INTERFACE(interactive)
|
||||
|
||||
class interactive {
|
||||
|
||||
LIBOPENMPT_EXT_CXX_INTERFACE(interactive)
|
||||
|
||||
//! Set the current ticks per row (speed)
|
||||
/*!
|
||||
\param speed The new tick count in range [1, 65535].
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the speed is outside the specified range.
|
||||
\remarks The tick count may be reset by pattern commands at any time.
|
||||
\sa openmpt::module::get_current_speed
|
||||
*/
|
||||
virtual void set_current_speed( std::int32_t speed ) = 0;
|
||||
|
||||
//! Set the current module tempo
|
||||
/*!
|
||||
\param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the tempo is outside the specified range.
|
||||
\remarks The tempo may be reset by pattern commands at any time. Use openmpt::ext:interactive::set_tempo_factor to apply a tempo factor that is independent of pattern commands.
|
||||
\sa openmpt::module::get_current_tempo
|
||||
\deprecated Please use openmpt::ext::interactive3::set_current_tempo2().
|
||||
*/
|
||||
LIBOPENMPT_ATTR_DEPRECATED virtual void set_current_tempo( std::int32_t tempo ) = 0;
|
||||
|
||||
//! Set the current module tempo factor without affecting playback pitch
|
||||
/*!
|
||||
\param factor The new tempo factor in range ]0.0, 4.0] - 1.0 means unmodified tempo.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the factor is outside the specified range.
|
||||
\remarks Modifying the tempo without applying the same pitch factor using openmpt::ext::interactive::set_pitch_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
|
||||
\sa openmpt::ext::interactive::get_tempo_factor
|
||||
*/
|
||||
virtual void set_tempo_factor( double factor ) = 0;
|
||||
|
||||
//! Gets the current module tempo factor
|
||||
/*!
|
||||
\return The current tempo factor.
|
||||
\sa openmpt::ext::interactive::set_tempo_factor
|
||||
*/
|
||||
virtual double get_tempo_factor( ) const = 0;
|
||||
|
||||
//! Set the current module pitch factor without affecting playback speed
|
||||
/*!
|
||||
\param factor The new pitch factor in range ]0.0, 4.0] - 1.0 means unmodified pitch.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the factor is outside the specified range.
|
||||
\remarks Modifying the pitch without applying the the same tempo factor using openmpt::ext::interactive::set_tempo_factor may cause rhythmic samples (e.g. drum loops) to go out of sync.
|
||||
\remarks To shift the pich by `n` semitones, the parameter can be calculated as follows: `pow( 2.0, n / 12.0 )`
|
||||
\sa openmpt::ext::interactive::get_pitch_factor
|
||||
*/
|
||||
virtual void set_pitch_factor( double factor ) = 0;
|
||||
|
||||
//! Gets the current module pitch factor
|
||||
/*!
|
||||
\return The current pitch factor.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the pitch is outside the specified range.
|
||||
\sa openmpt::ext::interactive::set_pitch_factor
|
||||
*/
|
||||
virtual double get_pitch_factor( ) const = 0;
|
||||
|
||||
//! Set the current global volume
|
||||
/*!
|
||||
\param volume The new global volume in range [0.0, 1.0]
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the volume is outside the specified range.
|
||||
\remarks The global volume may be reset by pattern commands at any time. Use openmpt::module::set_render_param to apply a global overall volume factor that is independent of pattern commands.
|
||||
\sa openmpt::ext::interactive::get_global_volume
|
||||
*/
|
||||
virtual void set_global_volume( double volume ) = 0;
|
||||
|
||||
//! Get the current global volume
|
||||
/*!
|
||||
\return The current global volume in range [0.0, 1.0]
|
||||
\sa openmpt::ext::interactive::set_global_volume
|
||||
*/
|
||||
virtual double get_global_volume( ) const = 0;
|
||||
|
||||
//! Set the current channel volume for a channel
|
||||
/*!
|
||||
\param channel The channel whose volume should be set, in range [0, openmpt::module::get_num_channels()[
|
||||
\param volume The new channel volume in range [0.0, 1.0]
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel or volume is outside the specified range.
|
||||
\remarks The channel volume may be reset by pattern commands at any time.
|
||||
\sa openmpt::ext::interactive::get_channel_volume
|
||||
*/
|
||||
virtual void set_channel_volume( std::int32_t channel, double volume ) = 0;
|
||||
|
||||
//! Get the current channel volume for a channel
|
||||
/*!
|
||||
\param channel The channel whose volume should be retrieved, in range [0, openmpt::module::get_num_channels()[
|
||||
\return The current channel volume in range [0.0, 1.0]
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
\sa openmpt::ext::interactive::set_channel_volume
|
||||
*/
|
||||
virtual double get_channel_volume( std::int32_t channel ) const = 0;
|
||||
|
||||
//! Set the current mute status for a channel
|
||||
/*!
|
||||
\param channel The channel whose mute status should be set, in range [0, openmpt::module::get_num_channels()[
|
||||
\param mute The new mute status. true is muted, false is unmuted.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
\sa openmpt::ext::interactive::get_channel_mute_status
|
||||
*/
|
||||
virtual void set_channel_mute_status( std::int32_t channel, bool mute ) = 0;
|
||||
|
||||
//! Get the current mute status for a channel
|
||||
/*!
|
||||
\param channel The channel whose mute status should be retrieved, in range [0, openmpt::module::get_num_channels()[
|
||||
\return The current channel mute status. true is muted, false is unmuted.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
\sa openmpt::ext::interactive::set_channel_mute_status
|
||||
*/
|
||||
virtual bool get_channel_mute_status( std::int32_t channel ) const = 0;
|
||||
|
||||
//! Set the current mute status for an instrument
|
||||
/*!
|
||||
\param instrument The instrument whose mute status should be set, in range [0, openmpt::module::get_num_instruments()[ if openmpt::module::get_num_instruments is not 0, otherwise in [0, openmpt::module::get_num_samples()[
|
||||
\param mute The new mute status. true is muted, false is unmuted.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the instrument is outside the specified range.
|
||||
\sa openmpt::ext::interactive::get_instrument_mute_status
|
||||
*/
|
||||
virtual void set_instrument_mute_status( std::int32_t instrument, bool mute ) = 0;
|
||||
|
||||
//! Get the current mute status for an instrument
|
||||
/*!
|
||||
\param instrument The instrument whose mute status should be retrieved, in range [0, openmpt::module::get_num_instruments()[ if openmpt::module::get_num_instruments is not 0, otherwise in [0, openmpt::module::get_num_samples()[
|
||||
\return The current instrument mute status. true is muted, false is unmuted.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the instrument is outside the specified range.
|
||||
\sa openmpt::ext::interactive::set_instrument_mute_status
|
||||
*/
|
||||
virtual bool get_instrument_mute_status( std::int32_t instrument ) const = 0;
|
||||
|
||||
//! Play a note using the specified instrument
|
||||
/*!
|
||||
\param instrument The instrument that should be played, in range [0, openmpt::module::get_num_instruments()[ if openmpt::module::get_num_instruments is not 0, otherwise in [0, openmpt::module::get_num_samples()[
|
||||
\param note The note to play, in rage [0, 119]. 60 is the middle C.
|
||||
\param volume The volume at which the note should be triggered, in range [0.0, 1.0]
|
||||
\param panning The panning position at which the note should be triggered, in range [-1.0, 1.0], 0.0 is center.
|
||||
\return The channel on which the note is played. This can pe be passed to openmpt::ext::interactive::stop_note to stop the note.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the instrument or note is outside the specified range.
|
||||
\sa openmpt::ext::interactive::stop_note
|
||||
\sa openmpt::ext::interactive2::note_off
|
||||
\sa openmpt::ext::interactive2::note_fade
|
||||
*/
|
||||
virtual std::int32_t play_note( std::int32_t instrument, std::int32_t note, double volume, double panning ) = 0;
|
||||
|
||||
//! Stop the note playing on the specified channel
|
||||
/*!
|
||||
\param channel The channel on which the note should be stopped. This is the value returned by a previous play_note call.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
\sa openmpt::ext::interactive::play_note
|
||||
\sa openmpt::ext::interactive2::note_off
|
||||
\sa openmpt::ext::interactive2::note_fade
|
||||
*/
|
||||
virtual void stop_note( std::int32_t channel ) = 0;
|
||||
|
||||
}; // class interactive
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_INTERFACE_INTERACTIVE2
|
||||
#define LIBOPENMPT_EXT_INTERFACE_INTERACTIVE2
|
||||
#endif
|
||||
|
||||
LIBOPENMPT_DECLARE_EXT_CXX_INTERFACE(interactive2)
|
||||
|
||||
class interactive2 {
|
||||
|
||||
LIBOPENMPT_EXT_CXX_INTERFACE(interactive2)
|
||||
|
||||
//! Sends a key-off command for the note playing on the specified channel
|
||||
/*!
|
||||
\param channel The channel on which the key-off event should be triggered. This is the value returned by a previous play_note call.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
\remarks This method releases envelopes and sample sustain loops. If the sample has no sustain loop, or if the module does not use instruments, it does nothing.
|
||||
\sa openmpt::ext::interactive::play_note
|
||||
\sa openmpt::ext::interactive::stop_note
|
||||
\sa openmpt::ext::interactive2::note_fade
|
||||
\since 0.6.0
|
||||
*/
|
||||
virtual void note_off(int32_t channel ) = 0;
|
||||
|
||||
//! Sends a note fade command for the note playing on the specified channel
|
||||
/*!
|
||||
\param channel The channel on which the note should be faded. This is the value returned by a previous play_note call.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
\remarks This method uses the instrument's fade-out value. If the module does not use instruments, or the instrument's fade-out value is 0, it does nothing.
|
||||
\sa openmpt::ext::interactive::play_note
|
||||
\sa openmpt::ext::interactive::stop_note
|
||||
\sa openmpt::ext::interactive2::note_off
|
||||
\since 0.6.0
|
||||
*/
|
||||
virtual void note_fade(int32_t channel) = 0;
|
||||
|
||||
//! Set the current panning position for a channel
|
||||
/*!
|
||||
\param channel The channel whose panning will be changed, in range [0, openmpt::module::get_num_channels()[
|
||||
\param panning The panning position to set on the channel, in range [-1.0, 1.0], 0.0 is center.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
\remarks This command affects subsequent notes played on the same channel, and may itself be overridden by subsequent panning commands encountered in the module itself.
|
||||
\sa openmpt::ext::interactive2::get_channel_panning
|
||||
\since 0.6.0
|
||||
*/
|
||||
virtual void set_channel_panning(int32_t channel, double panning ) = 0;
|
||||
|
||||
//! Get the current panning position for a channel
|
||||
/*!
|
||||
\param channel The channel whose panning should be retrieved, in range [0, openmpt::module::get_num_channels()[
|
||||
\return The current channel panning, in range [-1.0, 1.0], 0.0 is center.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
\sa openmpt::ext::interactive2::set_channel_panning
|
||||
\since 0.6.0
|
||||
*/
|
||||
virtual double get_channel_panning( int32_t channel ) = 0;
|
||||
|
||||
//! Set the finetune for the currently playing note on a channel
|
||||
/*!
|
||||
\param channel The channel whose finetune will be changed, in range [0, openmpt::module::get_num_channels()[
|
||||
\param finetune The finetune to set on the channel, in range [-1.0, 1.0], 0.0 is center.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel index is invalid.
|
||||
\remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
|
||||
\remarks This command does not affect subsequent notes played on the same channel, but may itself be overridden by subsequent finetune commands encountered in the module itself.
|
||||
\sa openmpt::ext::interactive2::get_note_finetune
|
||||
\since 0.6.0
|
||||
*/
|
||||
virtual void set_note_finetune(int32_t channel, double finetune ) = 0;
|
||||
|
||||
//! Get the finetune for the currently playing note on a channel
|
||||
/*!
|
||||
\param channel The channel whose finetune should be retrieved, in range [0, openmpt::module::get_num_channels()[
|
||||
\return The current channel finetune, in range [-1.0, 1.0], 0.0 is center.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the channel is outside the specified range.
|
||||
\remarks The finetune range depends on the pitch wheel depth of the instrument playing on the current channel; for sample-based modules, the depth of this command is fixed to +/-1 semitone.
|
||||
\sa openmpt::ext::interactive2::set_note_finetune
|
||||
\since 0.6.0
|
||||
*/
|
||||
virtual double get_note_finetune( int32_t channel ) = 0;
|
||||
|
||||
}; // class interactive2
|
||||
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_INTERFACE_INTERACTIVE3
|
||||
#define LIBOPENMPT_EXT_INTERFACE_INTERACTIVE3
|
||||
#endif
|
||||
|
||||
LIBOPENMPT_DECLARE_EXT_CXX_INTERFACE(interactive3)
|
||||
|
||||
class interactive3 {
|
||||
|
||||
LIBOPENMPT_EXT_CXX_INTERFACE(interactive3)
|
||||
|
||||
//! Set the current module tempo
|
||||
/*!
|
||||
\param tempo The new tempo in range [32, 512]. The exact meaning of the value depends on the tempo mode used by the module.
|
||||
\throws openmpt::exception Throws an exception derived from openmpt::exception if the tempo is outside the specified range.
|
||||
\remarks The tempo may be reset by pattern commands at any time. Use openmpt::ext:interactive::set_tempo_factor to apply a tempo factor that is independent of pattern commands.
|
||||
\sa openmpt::module::get_current_tempo2
|
||||
\since 0.7.0
|
||||
*/
|
||||
virtual void set_current_tempo2( double tempo ) = 0;
|
||||
|
||||
}; // class interactive3
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
#undef LIBOPENMPT_DECLARE_EXT_CXX_INTERFACE
|
||||
#undef LIBOPENMPT_EXT_CXX_INTERFACE
|
||||
|
||||
/*!
|
||||
@}
|
||||
*/
|
||||
|
||||
} // namespace ext
|
||||
|
||||
} // namespace openmpt
|
||||
|
||||
#endif // LIBOPENMPT_EXT_HPP
|
||||
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
* libopenmpt_ext_impl.cpp
|
||||
* -----------------------
|
||||
* Purpose: libopenmpt extensions - implementation
|
||||
* Notes :
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#include "common/stdafx.h"
|
||||
|
||||
#include "libopenmpt_internal.h"
|
||||
#include "libopenmpt_ext.hpp"
|
||||
|
||||
#include "libopenmpt_ext_impl.hpp"
|
||||
|
||||
#include "mpt/base/saturate_round.hpp"
|
||||
|
||||
#include "soundlib/Sndfile.h"
|
||||
|
||||
// assume OPENMPT_NAMESPACE is OpenMPT
|
||||
|
||||
namespace openmpt {
|
||||
|
||||
module_ext_impl::module_ext_impl( callback_stream_wrapper stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( stream, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( std::istream & stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( stream, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const std::vector<std::byte> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const std::vector<std::uint8_t> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const std::vector<char> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const std::byte * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, size, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const std::uint8_t * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, size, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const char * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, size, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
module_ext_impl::module_ext_impl( const void * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls ) : module_impl( data, size, std::move(log), ctls ) {
|
||||
ctor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void module_ext_impl::ctor() {
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
module_ext_impl::~module_ext_impl() {
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void * module_ext_impl::get_interface( const std::string & interface_id ) {
|
||||
if ( interface_id.empty() ) {
|
||||
return 0;
|
||||
} else if ( interface_id == ext::pattern_vis_id ) {
|
||||
return dynamic_cast< ext::pattern_vis * >( this );
|
||||
} else if ( interface_id == ext::interactive_id ) {
|
||||
return dynamic_cast< ext::interactive * >( this );
|
||||
} else if ( interface_id == ext::interactive2_id ) {
|
||||
return dynamic_cast< ext::interactive2 * >( this );
|
||||
} else if ( interface_id == ext::interactive3_id ) {
|
||||
return dynamic_cast< ext::interactive3 * >( this );
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// pattern_vis
|
||||
|
||||
module_ext_impl::effect_type module_ext_impl::get_pattern_row_channel_volume_effect_type( std::int32_t pattern, std::int32_t row, std::int32_t channel ) const {
|
||||
auto volcmd = static_cast<OpenMPT::VolumeCommand>( get_pattern_row_channel_command( pattern, row, channel, module::command_volumeffect ) );
|
||||
switch ( OpenMPT::ModCommand::GetVolumeEffectType( volcmd ) ) {
|
||||
case OpenMPT::EffectType::Normal : return effect_general; break;
|
||||
case OpenMPT::EffectType::Global : return effect_global ; break;
|
||||
case OpenMPT::EffectType::Volume : return effect_volume ; break;
|
||||
case OpenMPT::EffectType::Panning: return effect_panning; break;
|
||||
case OpenMPT::EffectType::Pitch : return effect_pitch ; break;
|
||||
default: return effect_unknown; break;
|
||||
}
|
||||
}
|
||||
|
||||
module_ext_impl::effect_type module_ext_impl::get_pattern_row_channel_effect_type( std::int32_t pattern, std::int32_t row, std::int32_t channel ) const {
|
||||
auto command = static_cast<OpenMPT::EffectCommand>( get_pattern_row_channel_command( pattern, row, channel, module::command_effect ) );
|
||||
switch (OpenMPT::ModCommand::GetEffectType( command ) ) {
|
||||
case OpenMPT::EffectType::Normal : return effect_general; break;
|
||||
case OpenMPT::EffectType::Global : return effect_global ; break;
|
||||
case OpenMPT::EffectType::Volume : return effect_volume ; break;
|
||||
case OpenMPT::EffectType::Panning: return effect_panning; break;
|
||||
case OpenMPT::EffectType::Pitch : return effect_pitch ; break;
|
||||
default: return effect_unknown; break;
|
||||
}
|
||||
}
|
||||
|
||||
// interactive
|
||||
|
||||
void module_ext_impl::set_current_speed( std::int32_t speed ) {
|
||||
if ( speed < 1 || speed > 65535 ) {
|
||||
throw openmpt::exception("invalid tick count");
|
||||
}
|
||||
m_sndFile->m_PlayState.m_nMusicSpeed = speed;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_current_tempo( std::int32_t tempo ) {
|
||||
if ( tempo < 32 || tempo > 512 ) {
|
||||
throw openmpt::exception("invalid tempo");
|
||||
}
|
||||
m_sndFile->m_PlayState.m_nMusicTempo.Set( tempo );
|
||||
}
|
||||
|
||||
void module_ext_impl::set_tempo_factor( double factor ) {
|
||||
if ( factor <= 0.0 || factor > 4.0 ) {
|
||||
throw openmpt::exception("invalid tempo factor");
|
||||
}
|
||||
m_sndFile->m_nTempoFactor = mpt::saturate_round<uint32_t>( 65536.0 / factor );
|
||||
m_sndFile->RecalculateSamplesPerTick();
|
||||
}
|
||||
|
||||
double module_ext_impl::get_tempo_factor( ) const {
|
||||
return 65536.0 / m_sndFile->m_nTempoFactor;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_pitch_factor( double factor ) {
|
||||
if ( factor <= 0.0 || factor > 4.0 ) {
|
||||
throw openmpt::exception("invalid pitch factor");
|
||||
}
|
||||
m_sndFile->m_nFreqFactor = mpt::saturate_round<uint32_t>( 65536.0 * factor );
|
||||
m_sndFile->RecalculateSamplesPerTick();
|
||||
}
|
||||
|
||||
double module_ext_impl::get_pitch_factor( ) const {
|
||||
return m_sndFile->m_nFreqFactor / 65536.0;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_global_volume( double volume ) {
|
||||
if ( volume < 0.0 || volume > 1.0 ) {
|
||||
throw openmpt::exception("invalid global volume");
|
||||
}
|
||||
m_sndFile->m_PlayState.m_nGlobalVolume = mpt::saturate_round<uint32_t>( volume * OpenMPT::MAX_GLOBAL_VOLUME );
|
||||
}
|
||||
|
||||
double module_ext_impl::get_global_volume( ) const {
|
||||
return m_sndFile->m_PlayState.m_nGlobalVolume / static_cast<double>( OpenMPT::MAX_GLOBAL_VOLUME );
|
||||
}
|
||||
|
||||
void module_ext_impl::set_channel_volume( std::int32_t channel, double volume ) {
|
||||
if ( channel < 0 || channel >= get_num_channels() ) {
|
||||
throw openmpt::exception("invalid channel");
|
||||
}
|
||||
if ( volume < 0.0 || volume > 1.0 ) {
|
||||
throw openmpt::exception("invalid global volume");
|
||||
}
|
||||
m_sndFile->m_PlayState.Chn[channel].nGlobalVol = mpt::saturate_round<std::uint8_t>(volume * 64.0);
|
||||
}
|
||||
|
||||
double module_ext_impl::get_channel_volume( std::int32_t channel ) const {
|
||||
if ( channel < 0 || channel >= get_num_channels() ) {
|
||||
throw openmpt::exception("invalid channel");
|
||||
}
|
||||
return m_sndFile->m_PlayState.Chn[channel].nGlobalVol / 64.0;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_channel_mute_status( std::int32_t channel, bool mute ) {
|
||||
if ( channel < 0 || channel >= get_num_channels() ) {
|
||||
throw openmpt::exception("invalid channel");
|
||||
}
|
||||
m_sndFile->ChnSettings[channel].dwFlags.set( OpenMPT::CHN_MUTE | OpenMPT::CHN_SYNCMUTE , mute );
|
||||
m_sndFile->m_PlayState.Chn[channel].dwFlags.set( OpenMPT::CHN_MUTE | OpenMPT::CHN_SYNCMUTE , mute );
|
||||
|
||||
// Also update NNA channels
|
||||
for ( OpenMPT::CHANNELINDEX i = m_sndFile->GetNumChannels(); i < OpenMPT::MAX_CHANNELS; i++)
|
||||
{
|
||||
if ( m_sndFile->m_PlayState.Chn[i].nMasterChn == channel + 1)
|
||||
{
|
||||
m_sndFile->m_PlayState.Chn[i].dwFlags.set( OpenMPT::CHN_MUTE | OpenMPT::CHN_SYNCMUTE, mute );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool module_ext_impl::get_channel_mute_status( std::int32_t channel ) const {
|
||||
if ( channel < 0 || channel >= get_num_channels() ) {
|
||||
throw openmpt::exception("invalid channel");
|
||||
}
|
||||
return m_sndFile->m_PlayState.Chn[channel].dwFlags[OpenMPT::CHN_MUTE | OpenMPT::CHN_SYNCMUTE];
|
||||
}
|
||||
|
||||
void module_ext_impl::set_instrument_mute_status( std::int32_t instrument, bool mute ) {
|
||||
const bool instrument_mode = get_num_instruments() != 0;
|
||||
const std::int32_t max_instrument = instrument_mode ? get_num_instruments() : get_num_samples();
|
||||
if ( instrument < 0 || instrument >= max_instrument ) {
|
||||
throw openmpt::exception("invalid instrument");
|
||||
}
|
||||
if ( instrument_mode ) {
|
||||
if ( m_sndFile->Instruments[instrument + 1] != nullptr ) {
|
||||
m_sndFile->Instruments[instrument + 1]->dwFlags.set( OpenMPT::INS_MUTE, mute );
|
||||
}
|
||||
} else {
|
||||
m_sndFile->GetSample( static_cast<OpenMPT::SAMPLEINDEX>( instrument + 1 ) ).uFlags.set( OpenMPT::CHN_MUTE, mute ) ;
|
||||
}
|
||||
}
|
||||
|
||||
bool module_ext_impl::get_instrument_mute_status( std::int32_t instrument ) const {
|
||||
const bool instrument_mode = get_num_instruments() != 0;
|
||||
const std::int32_t max_instrument = instrument_mode ? get_num_instruments() : get_num_samples();
|
||||
if ( instrument < 0 || instrument >= max_instrument ) {
|
||||
throw openmpt::exception("invalid instrument");
|
||||
}
|
||||
if ( instrument_mode ) {
|
||||
if ( m_sndFile->Instruments[instrument + 1] != nullptr ) {
|
||||
return m_sndFile->Instruments[instrument + 1]->dwFlags[OpenMPT::INS_MUTE];
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return m_sndFile->GetSample( static_cast<OpenMPT::SAMPLEINDEX>( instrument + 1 ) ).uFlags[OpenMPT::CHN_MUTE];
|
||||
}
|
||||
}
|
||||
|
||||
std::int32_t module_ext_impl::play_note( std::int32_t instrument, std::int32_t note, double volume, double panning ) {
|
||||
const bool instrument_mode = get_num_instruments() != 0;
|
||||
const std::int32_t max_instrument = instrument_mode ? get_num_instruments() : get_num_samples();
|
||||
if ( instrument < 0 || instrument >= max_instrument ) {
|
||||
throw openmpt::exception("invalid instrument");
|
||||
}
|
||||
note += OpenMPT::NOTE_MIN;
|
||||
if ( note < OpenMPT::NOTE_MIN || note > OpenMPT::NOTE_MAX ) {
|
||||
throw openmpt::exception("invalid note");
|
||||
}
|
||||
|
||||
// Find a free channel
|
||||
OpenMPT::CHANNELINDEX free_channel = m_sndFile->GetNNAChannel( OpenMPT::CHANNELINDEX_INVALID );
|
||||
if ( free_channel == OpenMPT::CHANNELINDEX_INVALID ) {
|
||||
free_channel = OpenMPT::MAX_CHANNELS - 1;
|
||||
}
|
||||
|
||||
OpenMPT::ModChannel &chn = m_sndFile->m_PlayState.Chn[free_channel];
|
||||
chn.Reset( OpenMPT::ModChannel::resetTotal, *m_sndFile, OpenMPT::CHANNELINDEX_INVALID, OpenMPT::CHN_MUTE );
|
||||
chn.nMasterChn = 0; // remove NNA association
|
||||
chn.nNewNote = chn.nLastNote = static_cast<std::uint8_t>(note);
|
||||
chn.ResetEnvelopes();
|
||||
m_sndFile->InstrumentChange(chn, instrument + 1);
|
||||
chn.nFadeOutVol = 0x10000;
|
||||
m_sndFile->NoteChange(chn, note, false, true, true);
|
||||
chn.nPan = mpt::saturate_round<std::int32_t>( OpenMPT::Clamp( panning * 128.0, -128.0, 128.0 ) + 128.0 );
|
||||
chn.nVolume = mpt::saturate_round<std::int32_t>( OpenMPT::Clamp( volume * 256.0, 0.0, 256.0 ) );
|
||||
|
||||
// Remove channel from list of mixed channels to fix https://bugs.openmpt.org/view.php?id=209
|
||||
// This is required because a previous note on the same channel might have just stopped playing,
|
||||
// but the channel is still in the mix list.
|
||||
// Since the channel volume / etc is only updated every tick in CSoundFile::ReadNote, and we
|
||||
// do not want to duplicate mixmode-dependant logic here, CSoundFile::CreateStereoMix may already
|
||||
// try to mix our newly set up channel at volume 0 if we don't remove it from the list.
|
||||
auto mix_begin = std::begin( m_sndFile->m_PlayState.ChnMix );
|
||||
auto mix_end = std::remove( mix_begin, mix_begin + m_sndFile->m_nMixChannels, free_channel );
|
||||
m_sndFile->m_nMixChannels = static_cast<OpenMPT::CHANNELINDEX>( std::distance( mix_begin, mix_end ) );
|
||||
|
||||
return free_channel;
|
||||
}
|
||||
|
||||
void module_ext_impl::stop_note( std::int32_t channel ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception("invalid channel");
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
chn.nLength = 0;
|
||||
chn.pCurrentSample = nullptr;
|
||||
}
|
||||
|
||||
void module_ext_impl::note_off(int32_t channel ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception( "invalid channel" );
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
chn.dwFlags |= OpenMPT::CHN_KEYOFF;
|
||||
}
|
||||
|
||||
void module_ext_impl::note_fade(int32_t channel ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception( "invalid channel" );
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
chn.dwFlags |= OpenMPT::CHN_NOTEFADE;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_channel_panning( int32_t channel, double panning ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception( "invalid channel" );
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
chn.nPan = mpt::saturate_round<int32_t>( std::clamp( panning, -1.0, 1.0 ) * 128.0 + 128.0 );
|
||||
}
|
||||
|
||||
double module_ext_impl::get_channel_panning( int32_t channel ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception( "invalid channel" );
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
return ( chn.nPan - 128 ) / 128.0;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_note_finetune( int32_t channel, double finetune ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception( "invalid channel" );
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
chn.microTuning = mpt::saturate_round<int16_t>( finetune * 32768.0 );
|
||||
}
|
||||
|
||||
double module_ext_impl::get_note_finetune( int32_t channel ) {
|
||||
if ( channel < 0 || channel >= OpenMPT::MAX_CHANNELS ) {
|
||||
throw openmpt::exception( "invalid channel" );
|
||||
}
|
||||
auto & chn = m_sndFile->m_PlayState.Chn[channel];
|
||||
return chn.microTuning / 32768.0;
|
||||
}
|
||||
|
||||
void module_ext_impl::set_current_tempo2( double tempo ) {
|
||||
if ( tempo < 32.0 || tempo > 512.0 ) {
|
||||
throw openmpt::exception("invalid tempo");
|
||||
}
|
||||
m_sndFile->m_PlayState.m_nMusicTempo = decltype( m_sndFile->m_PlayState.m_nMusicTempo )( tempo );
|
||||
}
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
} // namespace openmpt
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* libopenmpt_ext_impl.hpp
|
||||
* -----------------------
|
||||
* Purpose: libopenmpt extensions - implementation header
|
||||
* Notes :
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENMPT_EXT_IMPL_HPP
|
||||
#define LIBOPENMPT_EXT_IMPL_HPP
|
||||
|
||||
#include "libopenmpt_internal.h"
|
||||
#include "libopenmpt_impl.hpp"
|
||||
#include "libopenmpt_ext.hpp"
|
||||
|
||||
namespace openmpt {
|
||||
|
||||
class module_ext_impl
|
||||
: public module_impl
|
||||
, public ext::pattern_vis
|
||||
, public ext::interactive
|
||||
, public ext::interactive2
|
||||
, public ext::interactive3
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
{
|
||||
public:
|
||||
module_ext_impl( callback_stream_wrapper stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( std::istream & stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const std::vector<std::byte> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const std::vector<std::uint8_t> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const std::vector<char> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const std::byte * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const std::uint8_t * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const char * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_ext_impl( const void * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void ctor();
|
||||
|
||||
public:
|
||||
|
||||
~module_ext_impl();
|
||||
|
||||
public:
|
||||
|
||||
void * get_interface( const std::string & interface_id );
|
||||
|
||||
// pattern_vis
|
||||
|
||||
effect_type get_pattern_row_channel_volume_effect_type( std::int32_t pattern, std::int32_t row, std::int32_t channel ) const override;
|
||||
|
||||
effect_type get_pattern_row_channel_effect_type( std::int32_t pattern, std::int32_t row, std::int32_t channel ) const override;
|
||||
|
||||
// interactive
|
||||
|
||||
void set_current_speed( std::int32_t speed ) override;
|
||||
|
||||
void set_current_tempo( std::int32_t tempo ) override;
|
||||
|
||||
void set_tempo_factor( double factor ) override;
|
||||
|
||||
double get_tempo_factor( ) const override;
|
||||
|
||||
void set_pitch_factor( double factor ) override;
|
||||
|
||||
double get_pitch_factor( ) const override;
|
||||
|
||||
void set_global_volume( double volume ) override;
|
||||
|
||||
double get_global_volume( ) const override;
|
||||
|
||||
void set_channel_volume( std::int32_t channel, double volume ) override;
|
||||
|
||||
double get_channel_volume( std::int32_t channel ) const override;
|
||||
|
||||
void set_channel_mute_status( std::int32_t channel, bool mute ) override;
|
||||
|
||||
bool get_channel_mute_status( std::int32_t channel ) const override;
|
||||
|
||||
void set_instrument_mute_status( std::int32_t instrument, bool mute ) override;
|
||||
|
||||
bool get_instrument_mute_status( std::int32_t instrument ) const override;
|
||||
|
||||
std::int32_t play_note( std::int32_t instrument, std::int32_t note, double volume, double panning ) override;
|
||||
|
||||
void stop_note( std::int32_t channel ) override;
|
||||
|
||||
void note_off( std::int32_t channel ) override;
|
||||
|
||||
void note_fade( std::int32_t channel ) override;
|
||||
|
||||
void set_channel_panning( std::int32_t channel, double panning ) override;
|
||||
|
||||
double get_channel_panning( std::int32_t channel ) override;
|
||||
|
||||
void set_note_finetune( std::int32_t channel, double finetune ) override;
|
||||
|
||||
double get_note_finetune( std::int32_t channel ) override;
|
||||
|
||||
void set_current_tempo2(double tempo) override;
|
||||
|
||||
/* add stuff here */
|
||||
|
||||
}; // class module_ext_impl
|
||||
|
||||
} // namespace openmpt
|
||||
|
||||
#endif // LIBOPENMPT_EXT_IMPL_HPP
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* libopenmpt_impl.hpp
|
||||
* -------------------
|
||||
* Purpose: libopenmpt private interface
|
||||
* Notes : This is not a public header. Do NOT ship in distributions dev packages.
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENMPT_IMPL_HPP
|
||||
#define LIBOPENMPT_IMPL_HPP
|
||||
|
||||
#include "libopenmpt_internal.h"
|
||||
#include "libopenmpt.hpp"
|
||||
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4512) // assignment operator could not be generated
|
||||
#endif
|
||||
|
||||
// forward declarations
|
||||
namespace mpt {
|
||||
inline namespace mpt_libopenmpt {
|
||||
template <typename Traits, bool allow_transcode_locale>
|
||||
class BasicPathString;
|
||||
struct NativePathTraits;
|
||||
struct Utf8PathTraits;
|
||||
using native_path = BasicPathString<NativePathTraits, true>;
|
||||
namespace IO {
|
||||
class FileCursorTraitsFileData;
|
||||
template <typename Tpath>
|
||||
class FileCursorFilenameTraits;
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
class FileCursor;
|
||||
} // namespace IO
|
||||
} // namespace mpt_libopenmpt
|
||||
} // namespace mpt
|
||||
namespace OpenMPT {
|
||||
namespace detail {
|
||||
template <typename Ttraits, typename Tfilenametraits>
|
||||
using FileCursor = mpt::IO::FileCursor<Ttraits, Tfilenametraits>;
|
||||
} // namespace detail
|
||||
namespace mpt {
|
||||
#if defined(MPT_ENABLE_CHARSET_LOCALE)
|
||||
using PathString = mpt::native_path;
|
||||
#else
|
||||
using PathString = mpt::BasicPathString<mpt::Utf8PathTraits, false>;
|
||||
#endif
|
||||
} // namespace mpt
|
||||
using FileCursor = detail::FileCursor<mpt::IO::FileCursorTraitsFileData, mpt::IO::FileCursorFilenameTraits<mpt::PathString>>;
|
||||
class CSoundFile;
|
||||
struct DithersWrapperOpenMPT;
|
||||
} // namespace OpenMPT
|
||||
|
||||
namespace openmpt {
|
||||
|
||||
namespace version {
|
||||
|
||||
std::uint32_t get_library_version();
|
||||
std::uint32_t get_core_version();
|
||||
std::string get_string( const std::string & key );
|
||||
|
||||
} // namespace version
|
||||
|
||||
class log_interface {
|
||||
protected:
|
||||
log_interface();
|
||||
public:
|
||||
virtual ~log_interface();
|
||||
virtual void log( const std::string & message ) const = 0;
|
||||
}; // class log_interface
|
||||
|
||||
class std_ostream_log : public log_interface {
|
||||
private:
|
||||
std::ostream & destination;
|
||||
public:
|
||||
std_ostream_log( std::ostream & dst );
|
||||
virtual ~std_ostream_log();
|
||||
void log( const std::string & message ) const override;
|
||||
}; // class CSoundFileLog_std_ostream
|
||||
|
||||
class log_forwarder;
|
||||
|
||||
struct callback_stream_wrapper {
|
||||
void * stream;
|
||||
std::size_t (*read)( void * stream, void * dst, std::size_t bytes );
|
||||
int (*seek)( void * stream, std::int64_t offset, int whence );
|
||||
std::int64_t (*tell)( void * stream );
|
||||
}; // struct callback_stream_wrapper
|
||||
|
||||
class module_impl {
|
||||
public:
|
||||
enum class amiga_filter_type {
|
||||
a500,
|
||||
a1200,
|
||||
unfiltered,
|
||||
auto_filter,
|
||||
};
|
||||
|
||||
protected:
|
||||
struct subsong_data {
|
||||
double duration;
|
||||
std::int32_t start_row;
|
||||
std::int32_t start_order;
|
||||
std::int32_t sequence;
|
||||
std::int32_t restart_row;
|
||||
std::int32_t restart_order;
|
||||
subsong_data( double duration, std::int32_t start_row, std::int32_t start_order, std::int32_t sequence, std::int32_t restart_row, std::int32_t restart_order );
|
||||
}; // struct subsong_data
|
||||
|
||||
typedef std::vector<subsong_data> subsongs_type;
|
||||
|
||||
enum class song_end_action {
|
||||
fadeout_song,
|
||||
continue_song,
|
||||
stop_song,
|
||||
};
|
||||
|
||||
static constexpr std::int32_t all_subsongs = -1;
|
||||
|
||||
enum class ctl_type {
|
||||
boolean,
|
||||
integer,
|
||||
floatingpoint,
|
||||
text,
|
||||
};
|
||||
struct ctl_info {
|
||||
const char * name;
|
||||
ctl_type type;
|
||||
};
|
||||
|
||||
std::unique_ptr<log_interface> m_Log;
|
||||
std::unique_ptr<log_forwarder> m_LogForwarder;
|
||||
std::int32_t m_current_subsong;
|
||||
double m_currentPositionSeconds;
|
||||
std::unique_ptr<OpenMPT::CSoundFile> m_sndFile;
|
||||
bool m_loaded;
|
||||
bool m_mixer_initialized;
|
||||
std::unique_ptr<OpenMPT::DithersWrapperOpenMPT> m_Dithers;
|
||||
subsongs_type m_subsongs;
|
||||
float m_Gain;
|
||||
song_end_action m_ctl_play_at_end;
|
||||
amiga_filter_type m_ctl_render_resampler_emulate_amiga_type = amiga_filter_type::auto_filter;
|
||||
bool m_ctl_load_skip_samples;
|
||||
bool m_ctl_load_skip_patterns;
|
||||
bool m_ctl_load_skip_plugins;
|
||||
bool m_ctl_load_skip_subsongs_init;
|
||||
bool m_ctl_seek_sync_samples;
|
||||
std::vector<std::string> m_loaderMessages;
|
||||
public:
|
||||
void PushToCSoundFileLog( const std::string & text ) const;
|
||||
void PushToCSoundFileLog( int loglevel, const std::string & text ) const;
|
||||
protected:
|
||||
std::string mod_string_to_utf8( const std::string & encoded ) const;
|
||||
void apply_mixer_settings( std::int32_t samplerate, int channels );
|
||||
void apply_libopenmpt_defaults();
|
||||
subsongs_type get_subsongs() const;
|
||||
void init_subsongs( subsongs_type & subsongs ) const;
|
||||
bool has_subsongs_inited() const;
|
||||
void ctor( const std::map< std::string, std::string > & ctls );
|
||||
void load( const OpenMPT::FileCursor & file, const std::map< std::string, std::string > & ctls );
|
||||
bool is_loaded() const;
|
||||
std::size_t read_wrapper( std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right );
|
||||
std::size_t read_wrapper( std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
|
||||
std::size_t read_interleaved_wrapper( std::size_t count, std::size_t channels, std::int16_t * interleaved );
|
||||
std::size_t read_interleaved_wrapper( std::size_t count, std::size_t channels, float * interleaved );
|
||||
std::string get_message_instruments() const;
|
||||
std::string get_message_samples() const;
|
||||
std::pair< std::string, std::string > format_and_highlight_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int command ) const;
|
||||
std::pair< std::string, std::string > format_and_highlight_pattern_row_channel( std::int32_t p, std::int32_t r, std::int32_t c, std::size_t width, bool pad ) const;
|
||||
static double could_open_probability( const OpenMPT::FileCursor & file, double effort, std::unique_ptr<log_interface> log );
|
||||
public:
|
||||
static std::vector<std::string> get_supported_extensions();
|
||||
static bool is_extension_supported( std::string_view extension );
|
||||
static double could_open_probability( callback_stream_wrapper stream, double effort, std::unique_ptr<log_interface> log );
|
||||
static double could_open_probability( std::istream & stream, double effort, std::unique_ptr<log_interface> log );
|
||||
static std::size_t probe_file_header_get_recommended_size();
|
||||
static int probe_file_header( std::uint64_t flags, const std::byte * data, std::size_t size, std::uint64_t filesize );
|
||||
static int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size, std::uint64_t filesize );
|
||||
static int probe_file_header( std::uint64_t flags, const void * data, std::size_t size, std::uint64_t filesize );
|
||||
static int probe_file_header( std::uint64_t flags, const std::byte * data, std::size_t size );
|
||||
static int probe_file_header( std::uint64_t flags, const std::uint8_t * data, std::size_t size );
|
||||
static int probe_file_header( std::uint64_t flags, const void * data, std::size_t size );
|
||||
static int probe_file_header( std::uint64_t flags, std::istream & stream );
|
||||
static int probe_file_header( std::uint64_t flags, callback_stream_wrapper stream );
|
||||
module_impl( callback_stream_wrapper stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( std::istream & stream, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const std::vector<std::byte> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const std::vector<std::uint8_t> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const std::vector<char> & data, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const std::byte * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const std::uint8_t * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const char * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
module_impl( const void * data, std::size_t size, std::unique_ptr<log_interface> log, const std::map< std::string, std::string > & ctls );
|
||||
~module_impl();
|
||||
public:
|
||||
void select_subsong( std::int32_t subsong );
|
||||
std::int32_t get_selected_subsong() const;
|
||||
|
||||
std::int32_t get_restart_order( std::int32_t subsong ) const;
|
||||
std::int32_t get_restart_row( std::int32_t subsong ) const;
|
||||
|
||||
void set_repeat_count( std::int32_t repeat_count );
|
||||
std::int32_t get_repeat_count() const;
|
||||
double get_duration_seconds() const;
|
||||
double get_time_at_position( std::int32_t order, std::int32_t row ) const;
|
||||
double set_position_seconds( double seconds );
|
||||
double get_position_seconds() const;
|
||||
double set_position_order_row( std::int32_t order, std::int32_t row );
|
||||
std::int32_t get_render_param( int param ) const;
|
||||
void set_render_param( int param, std::int32_t value );
|
||||
std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono );
|
||||
std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right );
|
||||
std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right );
|
||||
std::size_t read( std::int32_t samplerate, std::size_t count, float * mono );
|
||||
std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right );
|
||||
float get_channel_waveform( std::int32_t channel_idx, float * output ) const;
|
||||
std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right );
|
||||
std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_stereo );
|
||||
std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, std::int16_t * interleaved_quad );
|
||||
std::size_t read_interleaved_stereo( std::int32_t samplerate, std::size_t count, float * interleaved_stereo );
|
||||
std::size_t read_interleaved_quad( std::int32_t samplerate, std::size_t count, float * interleaved_quad );
|
||||
std::vector<std::string> get_metadata_keys() const;
|
||||
std::string get_metadata( const std::string & key ) const;
|
||||
double get_current_estimated_bpm() const;
|
||||
std::int32_t get_current_speed() const;
|
||||
std::int32_t get_current_tempo() const;
|
||||
double get_current_tempo2() const;
|
||||
std::int32_t get_current_order() const;
|
||||
std::int32_t get_current_pattern() const;
|
||||
std::int32_t get_current_row() const;
|
||||
std::int32_t get_current_playing_channels() const;
|
||||
float get_current_channel_vu_mono( std::int32_t channel ) const;
|
||||
float get_current_channel_vu_left( std::int32_t channel ) const;
|
||||
float get_current_channel_vu_right( std::int32_t channel ) const;
|
||||
float get_current_channel_vu_rear_left( std::int32_t channel ) const;
|
||||
float get_current_channel_vu_rear_right( std::int32_t channel ) const;
|
||||
std::int32_t get_num_subsongs() const;
|
||||
std::int32_t get_num_channels() const;
|
||||
std::int32_t get_num_orders() const;
|
||||
std::int32_t get_num_patterns() const;
|
||||
std::int32_t get_num_instruments() const;
|
||||
std::int32_t get_num_samples() const;
|
||||
std::vector<std::string> get_subsong_names() const;
|
||||
std::vector<std::string> get_channel_names() const;
|
||||
std::vector<std::string> get_order_names() const;
|
||||
std::vector<std::string> get_pattern_names() const;
|
||||
std::vector<std::string> get_instrument_names() const;
|
||||
std::vector<std::string> get_sample_names() const;
|
||||
std::int32_t get_order_pattern( std::int32_t o ) const;
|
||||
bool is_order_skip_entry( std::int32_t order ) const;
|
||||
static bool is_pattern_skip_item( std::int32_t pattern );
|
||||
bool is_order_stop_entry( std::int32_t order ) const;
|
||||
static bool is_pattern_stop_item( std::int32_t pattern );
|
||||
std::int32_t get_pattern_num_rows( std::int32_t p ) const;
|
||||
std::int32_t get_pattern_rows_per_beat( std::int32_t pattern ) const;
|
||||
std::int32_t get_pattern_rows_per_measure( std::int32_t pattern ) const;
|
||||
std::uint8_t get_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const;
|
||||
std::string format_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const;
|
||||
std::string highlight_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const;
|
||||
std::string format_pattern_row_channel( std::int32_t p, std::int32_t r, std::int32_t c, std::size_t width, bool pad ) const;
|
||||
std::string highlight_pattern_row_channel( std::int32_t p, std::int32_t r, std::int32_t c, std::size_t width, bool pad ) const;
|
||||
std::pair<const module_impl::ctl_info *, const module_impl::ctl_info *> get_ctl_infos() const;
|
||||
std::vector<std::string> get_ctls() const;
|
||||
std::string ctl_get( std::string ctl, bool throw_if_unknown = true ) const;
|
||||
bool ctl_get_boolean( std::string_view ctl, bool throw_if_unknown = true ) const;
|
||||
std::int64_t ctl_get_integer( std::string_view ctl, bool throw_if_unknown = true ) const;
|
||||
double ctl_get_floatingpoint( std::string_view ctl, bool throw_if_unknown = true ) const;
|
||||
std::string ctl_get_text( std::string_view ctl, bool throw_if_unknown = true ) const;
|
||||
void ctl_set( std::string ctl, const std::string & value, bool throw_if_unknown = true );
|
||||
void ctl_set_boolean( std::string_view ctl, bool value, bool throw_if_unknown = true );
|
||||
void ctl_set_integer( std::string_view ctl, std::int64_t value, bool throw_if_unknown = true );
|
||||
void ctl_set_floatingpoint( std::string_view ctl, double value, bool throw_if_unknown = true );
|
||||
void ctl_set_text( std::string_view ctl, std::string_view value, bool throw_if_unknown = true );
|
||||
}; // class module_impl
|
||||
|
||||
namespace helper {
|
||||
|
||||
template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args&&... args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
} // namespace helper
|
||||
|
||||
} // namespace openmpt
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // LIBOPENMPT_IMPL_HPP
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* libopenmpt_internal.h
|
||||
* ---------------------
|
||||
* Purpose: libopenmpt internal interface configuration, overruling the public interface configuration (only used and needed when building libopenmpt)
|
||||
* Notes : (currently none)
|
||||
* Authors: OpenMPT Devs
|
||||
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
|
||||
*/
|
||||
|
||||
#ifndef LIBOPENMPT_INTERNAL_H
|
||||
#define LIBOPENMPT_INTERNAL_H
|
||||
|
||||
#include "libopenmpt_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if defined(LIBOPENMPT_BUILD_DLL) || defined(LIBOPENMPT_USE_DLL)
|
||||
#if defined(_MSC_VER) && !defined(_DLL)
|
||||
/* #pragma message( "libopenmpt C++ interface is disabled if libopenmpt is built as a DLL and the runtime is statically linked. This is not supported by microsoft and cannot possibly work. Ever." ) */
|
||||
#undef LIBOPENMPT_CXX_API
|
||||
#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_LOCAL
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* LIBOPENMPT_INTERNAL_H */
|
||||
Loaded 100 of 780 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user