From 41ab126549806b4b456fa20e8437fa1ffc753652 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Sun, 25 Apr 2021 05:31:26 +0200 Subject: [PATCH] Remove header dependency Parser from Synth --- src/CMakeLists.txt | 1 + src/sfizz/Synth.cpp | 13 +++++++++++++ src/sfizz/Synth.h | 17 ++++++++++++++++- src/sfizz/SynthPrivate.h | 2 ++ src/sfizz/parser/Parser.cpp | 1 + src/sfizz/parser/Parser.h | 15 ++------------- src/sfizz/parser/ParserListener.h | 29 +++++++++++++++++++++++++++++ src/sfizz/sfizz.cpp | 4 ++-- src/sfizz/sfizz_wrapper.cpp | 4 ++-- tests/FilesT.cpp | 1 + tests/ParsingT.cpp | 1 + tests/TestHelpers.cpp | 1 + 12 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 src/sfizz/parser/ParserListener.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 96eed54c..1d4d1dff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -202,6 +202,7 @@ set(SFIZZ_PARSER_HEADERS sfizz/Range.h sfizz/Opcode.h sfizz/parser/Parser.h + sfizz/parser/ParserListener.h sfizz/parser/ParserPrivate.h sfizz/parser/ParserPrivate.hpp sfizz/SfzHelpers.h) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index c992d239..c76de616 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -28,6 +28,7 @@ #include "utility/XmlHelpers.h" #include "Voice.h" #include "Interpolators.h" +#include "parser/Parser.h" #include #include #include @@ -1996,6 +1997,18 @@ void Synth::allSoundOff() noexcept effectBus->clear(); } +void Synth::addExternalDefinition(const std::string& id, const std::string& value) +{ + Impl& impl = *impl_; + impl.parser_.addExternalDefinition(id, value); +} + +void Synth::clearExternalDefinitions() +{ + Impl& impl = *impl_; + impl.parser_.clearExternalDefinitions(); +} + const BitArray& Synth::getUsedCCs() const noexcept { Impl& impl = *impl_; diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 0722ecd4..3ffaedab 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -10,7 +10,6 @@ #include "Messaging.h" #include "utility/NumericId.h" #include "utility/LeakDetector.h" -#include "parser/Parser.h" #include #include #include @@ -22,6 +21,7 @@ template class BitArray; namespace sfz { // Forward declarations for the introspection methods +class Parser; class RegionSet; class PolyphonyGroup; class EffectBus; @@ -29,6 +29,9 @@ struct Region; struct Layer; class Voice; +using CCNamePair = std::pair; +using NoteNamePair = std::pair; + /** * @brief This class is the core of the sfizz library. In C++ it is the main point * of entry and in C the interface basically maps the functions of the class into @@ -642,6 +645,18 @@ public: */ void allSoundOff() noexcept; + /** + * @brief Add external definitions prior to loading. + * + */ + void addExternalDefinition(const std::string& id, const std::string& value); + + /** + * @brief Clears external definitions for the next file loading. + * + */ + void clearExternalDefinitions(); + /** * @brief Get the parser. * diff --git a/src/sfizz/SynthPrivate.h b/src/sfizz/SynthPrivate.h index 157bba4b..4b244649 100644 --- a/src/sfizz/SynthPrivate.h +++ b/src/sfizz/SynthPrivate.h @@ -13,6 +13,8 @@ #include "modulations/sources/ChannelAftertouch.h" #include "modulations/sources/PolyAftertouch.h" #include "modulations/sources/LFO.h" +#include "parser/Parser.h" +#include "parser/ParserListener.h" namespace sfz { diff --git a/src/sfizz/parser/Parser.cpp b/src/sfizz/parser/Parser.cpp index 40306431..5ae4aef8 100644 --- a/src/sfizz/parser/Parser.cpp +++ b/src/sfizz/parser/Parser.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "Parser.h" +#include "ParserListener.h" #include "ParserPrivate.h" #include "absl/memory/memory.h" #include diff --git a/src/sfizz/parser/Parser.h b/src/sfizz/parser/Parser.h index 1be51361..e83fc1ad 100644 --- a/src/sfizz/parser/Parser.h +++ b/src/sfizz/parser/Parser.h @@ -16,6 +16,7 @@ namespace sfz { class Reader; +class ParserListener; struct SourceLocation; struct SourceRange; @@ -50,19 +51,7 @@ public: size_t getErrorCount() const noexcept { return _errorCount; } size_t getWarningCount() const noexcept { return _warningCount; } - class Listener { - public: - // low-level parsing - virtual void onParseBegin() {} - virtual void onParseEnd() {} - virtual void onParseHeader(const SourceRange& /*range*/, const std::string& /*header*/) {} - virtual void onParseOpcode(const SourceRange& /*rangeOpcode*/, const SourceRange& /*rangeValue*/, const std::string& /*name*/, const std::string& /*value*/) {} - virtual void onParseError(const SourceRange& /*range*/, const std::string& /*message*/) {} - virtual void onParseWarning(const SourceRange& /*range*/, const std::string& /*message*/) {} - - // high-level parsing - virtual void onParseFullBlock(const std::string& /*header*/, const std::vector& /*opcodes*/) {} - }; + using Listener = ParserListener; void setListener(Listener* listener) noexcept { _listener = listener; } diff --git a/src/sfizz/parser/ParserListener.h b/src/sfizz/parser/ParserListener.h new file mode 100644 index 00000000..fa208ff9 --- /dev/null +++ b/src/sfizz/parser/ParserListener.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: BSD-2-Clause + +// This code is part of the sfizz library and is licensed under a BSD 2-clause +// license. You should have receive a LICENSE.md file along with the code. +// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz + +#pragma once +#include +#include + +namespace sfz { +struct SourceRange; +struct Opcode; + +class ParserListener { +public: + // low-level parsing + virtual void onParseBegin() {} + virtual void onParseEnd() {} + virtual void onParseHeader(const SourceRange& /*range*/, const std::string& /*header*/) {} + virtual void onParseOpcode(const SourceRange& /*rangeOpcode*/, const SourceRange& /*rangeValue*/, const std::string& /*name*/, const std::string& /*value*/) {} + virtual void onParseError(const SourceRange& /*range*/, const std::string& /*message*/) {} + virtual void onParseWarning(const SourceRange& /*range*/, const std::string& /*message*/) {} + + // high-level parsing + virtual void onParseFullBlock(const std::string& /*header*/, const std::vector& /*opcodes*/) {} +}; + +} // namespace sfz diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index 2a1d2d9d..2d7d58c0 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -353,12 +353,12 @@ void sfz::Sfizz::allSoundOff() noexcept void sfz::Sfizz::addExternalDefinition(const std::string& id, const std::string& value) { - synth->synth.getParser().addExternalDefinition(id, value); + synth->synth.addExternalDefinition(id, value); } void sfz::Sfizz::clearExternalDefinitions() { - synth->synth.getParser().clearExternalDefinitions(); + synth->synth.clearExternalDefinitions(); } std::string sfz::Sfizz::exportMidnam(const std::string& model) const diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 5166081d..4b191ab5 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -335,12 +335,12 @@ void sfizz_all_sound_off(sfizz_synth_t* synth) void sfizz_add_external_definitions(sfizz_synth_t* synth, const char* id, const char* value) { - synth->synth.getParser().addExternalDefinition(id, value); + synth->synth.addExternalDefinition(id, value); } void sfizz_clear_external_definitions(sfizz_synth_t* synth) { - synth->synth.getParser().clearExternalDefinitions(); + synth->synth.clearExternalDefinitions(); } unsigned int sfizz_get_num_key_labels(sfizz_synth_t* synth) diff --git a/tests/FilesT.cpp b/tests/FilesT.cpp index 50c73414..69f178f9 100644 --- a/tests/FilesT.cpp +++ b/tests/FilesT.cpp @@ -8,6 +8,7 @@ #include "sfizz/Synth.h" #include "sfizz/Voice.h" #include "sfizz/SfzHelpers.h" +#include "sfizz/parser/Parser.h" #include "sfizz/modulations/ModId.h" #include "sfizz/modulations/ModKey.h" #include "catch2/catch.hpp" diff --git a/tests/ParsingT.cpp b/tests/ParsingT.cpp index cb1096ce..3b6859cf 100644 --- a/tests/ParsingT.cpp +++ b/tests/ParsingT.cpp @@ -6,6 +6,7 @@ #include "sfizz/SfzHelpers.h" #include "sfizz/parser/Parser.h" +#include "sfizz/parser/ParserListener.h" #include #include "catch2/catch.hpp" #include "absl/strings/string_view.h" diff --git a/tests/TestHelpers.cpp b/tests/TestHelpers.cpp index 3e1f7715..78e6cb85 100644 --- a/tests/TestHelpers.cpp +++ b/tests/TestHelpers.cpp @@ -6,6 +6,7 @@ #include "TestHelpers.h" #include "sfizz/modulations/ModId.h" +#include size_t RegionCCView::size() const {