Remove header dependency Parser from Synth

This commit is contained in:
Jean Pierre Cimalando 2021-04-25 05:31:26 +02:00
parent 8551caebf6
commit 41ab126549
12 changed files with 71 additions and 18 deletions

View file

@ -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)

View file

@ -28,6 +28,7 @@
#include "utility/XmlHelpers.h"
#include "Voice.h"
#include "Interpolators.h"
#include "parser/Parser.h"
#include <absl/algorithm/container.h>
#include <absl/memory/memory.h>
#include <absl/strings/str_replace.h>
@ -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<config::numCCs>& Synth::getUsedCCs() const noexcept
{
Impl& impl = *impl_;

View file

@ -10,7 +10,6 @@
#include "Messaging.h"
#include "utility/NumericId.h"
#include "utility/LeakDetector.h"
#include "parser/Parser.h"
#include <ghc/fs_std.hpp>
#include <absl/strings/string_view.h>
#include <memory>
@ -22,6 +21,7 @@ template <size_t> 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<uint16_t, std::string>;
using NoteNamePair = std::pair<uint8_t, std::string>;
/**
* @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.
*

View file

@ -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 {

View file

@ -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 <cassert>

View file

@ -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<Opcode>& /*opcodes*/) {}
};
using Listener = ParserListener;
void setListener(Listener* listener) noexcept { _listener = listener; }

View file

@ -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 <string>
#include <vector>
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<Opcode>& /*opcodes*/) {}
};
} // namespace sfz

View file

@ -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

View file

@ -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)

View file

@ -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"

View file

@ -6,6 +6,7 @@
#include "sfizz/SfzHelpers.h"
#include "sfizz/parser/Parser.h"
#include "sfizz/parser/ParserListener.h"
#include <iostream>
#include "catch2/catch.hpp"
#include "absl/strings/string_view.h"

View file

@ -6,6 +6,7 @@
#include "TestHelpers.h"
#include "sfizz/modulations/ModId.h"
#include <absl/strings/str_cat.h>
size_t RegionCCView::size() const
{