From e7c79a9b5fad7617518a5ac23f91740c79e3daff Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 6 Oct 2020 02:11:03 +0200 Subject: [PATCH] jack: use sfizz public API only --- clients/CMakeLists.txt | 2 +- clients/jack_client.cpp | 35 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/clients/CMakeLists.txt b/clients/CMakeLists.txt index 9192234d..80502f42 100644 --- a/clients/CMakeLists.txt +++ b/clients/CMakeLists.txt @@ -7,7 +7,7 @@ if (SFIZZ_JACK) add_executable (sfizz_jack MidiHelpers.h jack_client.cpp) target_include_directories (sfizz_jack PRIVATE ${JACK_INCLUDE_DIRS}) - target_link_libraries (sfizz_jack PRIVATE sfizz::sfizz absl::flags_parse sfizz-sndfile ${JACK_LIBRARIES}) + target_link_libraries (sfizz_jack PRIVATE sfizz::sfizz absl::flags_parse ${JACK_LIBRARIES}) sfizz_enable_lto_if_needed (sfizz_jack) install (TARGETS sfizz_jack DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT "jack" OPTIONAL) diff --git a/clients/jack_client.cpp b/clients/jack_client.cpp index 941d4120..b135166b 100644 --- a/clients/jack_client.cpp +++ b/clients/jack_client.cpp @@ -21,8 +21,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "sfizz/Synth.h" -#include "sfizz/Macros.h" +#include "sfizz.hpp" #include "MidiHelpers.h" #include #include @@ -47,9 +46,9 @@ static jack_client_t* client; int process(jack_nframes_t numFrames, void* arg) { - auto synth = reinterpret_cast(arg); + auto* synth = reinterpret_cast(arg); - auto buffer = jack_port_get_buffer(midiInputPort, numFrames); + auto* buffer = jack_port_get_buffer(midiInputPort, numFrames); assert(buffer); auto numMidiEvents = jack_midi_get_event_count(buffer); @@ -97,9 +96,11 @@ int process(jack_nframes_t numFrames, void* arg) } } - auto leftOutput = reinterpret_cast(jack_port_get_buffer(outputPort1, numFrames)); - auto rightOutput = reinterpret_cast(jack_port_get_buffer(outputPort2, numFrames)); - synth->renderBlock({ { leftOutput, rightOutput }, numFrames }); + auto* leftOutput = reinterpret_cast(jack_port_get_buffer(outputPort1, numFrames)); + auto* rightOutput = reinterpret_cast(jack_port_get_buffer(outputPort2, numFrames)); + + float* stereoOutput[] = { leftOutput, rightOutput }; + synth->renderBlock(stereoOutput, numFrames); return 0; } @@ -109,7 +110,7 @@ int sampleBlockChanged(jack_nframes_t nframes, void* arg) if (arg == nullptr) return 0; - auto synth = reinterpret_cast(arg); + auto* synth = reinterpret_cast(arg); // DBG("Sample per block changed to " << nframes); synth->setSamplesPerBlock(nframes); return 0; @@ -120,7 +121,7 @@ int sampleRateChanged(jack_nframes_t nframes, void* arg) if (arg == nullptr) return 0; - auto synth = reinterpret_cast(arg); + auto* synth = reinterpret_cast(arg); // DBG("Sample rate changed to " << nframes); synth->setSampleRate(nframes); return 0; @@ -132,7 +133,7 @@ static void done(int sig) { std::cout << "Signal received" << '\n'; shouldClose = true; - UNUSED(sig); + (void)sig; // if (client != nullptr) // exit(0); @@ -163,11 +164,11 @@ int main(int argc, char** argv) std::cout << "- Oversampling: " << oversampling << '\n'; std::cout << "- Preloaded Size: " << preload_size << '\n'; const auto factor = [&]() { - if (oversampling == "x1") return sfz::Oversampling::x1; - if (oversampling == "x2") return sfz::Oversampling::x2; - if (oversampling == "x4") return sfz::Oversampling::x4; - if (oversampling == "x8") return sfz::Oversampling::x8; - return sfz::Oversampling::x1; + if (oversampling == "x1") return 1; + if (oversampling == "x2") return 2; + if (oversampling == "x4") return 4; + if (oversampling == "x8") return 8; + return 1; }(); std::cout << "Positional arguments:"; @@ -175,7 +176,7 @@ int main(int argc, char** argv) std::cout << " " << file << ','; std::cout << '\n'; - sfz::Synth synth; + sfz::Sfizz synth; synth.setOversamplingFactor(factor); synth.setPreloadSize(preload_size); synth.loadSfzFile(filesToParse[0]); @@ -186,6 +187,7 @@ int main(int argc, char** argv) std::cout << "\tRegions: " << synth.getNumRegions() << '\n'; std::cout << "\tCurves: " << synth.getNumCurves() << '\n'; std::cout << "\tPreloadedSamples: " << synth.getNumPreloadedSamples() << '\n'; +#if 0 // not currently in public API std::cout << "==========" << '\n'; std::cout << "Included files:" << '\n'; for (auto& file : synth.getParser().getIncludedFiles()) @@ -194,6 +196,7 @@ int main(int argc, char** argv) std::cout << "Defines:" << '\n'; for (auto& define : synth.getParser().getDefines()) std::cout << '\t' << define.first << '=' << define.second << '\n'; +#endif std::cout << "==========" << '\n'; std::cout << "Unknown opcodes:"; for (auto& opcode : synth.getUnknownOpcodes())