Skip to content

Instantly share code, notes, and snippets.

@Simon-L
Created May 1, 2025 15:14
Show Gist options
  • Save Simon-L/12e7ab7951c7baaef114311d9810df0a to your computer and use it in GitHub Desktop.
Save Simon-L/12e7ab7951c7baaef114311d9810df0a to your computer and use it in GitHub Desktop.
Testing the rework-DspFaust branch
cmake_minimum_required(VERSION 3.10)
project (rework-dspfaust)
add_executable(linux-jack DspFaust.cpp main.cpp)
target_include_directories (linux-jack PRIVATE /tmp/tmp.YnNSb9bh8V/faust/build/faustpfx/include)
target_compile_definitions(linux-jack PUBLIC JACK_DRIVER=1 MIDICTRL=1 DYNAMIC_DSP=1)
target_link_libraries(linux-jack PRIVATE
/tmp/tmp.YnNSb9bh8V/faust/build/faustpfx/lib/libfaustwithllvm.a
jack
z
zstd
tinfo
)
/* ------------------------------------------------------------
name: "mydsp"
Code generated with Faust 2.80.5 (https://faust.grame.fr)
Compilation options: -a ../architecture/api/DspFaust.cpp -lang cpp -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0
------------------------------------------------------------ */
#ifndef __mydsp_H__
#define __mydsp_H__
/************************************************************************
************************************************************************
FAUST API Architecture File
Copyright (C) 2016 GRAME, Romain Michon, CCRMA - Stanford University
Copyright (C) 2014-2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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 3 of
the License, 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 <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
#include <cmath>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include "faust/misc.h"
#include "faust/gui/DecoratorUI.h"
#include "faust/gui/JSONUIDecoder.h"
#include "faust/dsp/dsp.h"
#include "faust/dsp/dsp-adapter.h"
#include "faust/gui/meta.h"
// we require macro declarations
#define FAUST_UIMACROS
// but we will ignore most of them
#define FAUST_ADDBUTTON(l,f)
#define FAUST_ADDCHECKBOX(l,f)
#define FAUST_ADDVERTICALSLIDER(l,f,i,a,b,s)
#define FAUST_ADDHORIZONTALSLIDER(l,f,i,a,b,s)
#define FAUST_ADDNUMENTRY(l,f,i,a,b,s)
#define FAUST_ADDVERTICALBARGRAPH(l,f,a,b)
#define FAUST_ADDHORIZONTALBARGRAPH(l,f,a,b)
// To force correct miniaudio include
#if MINIAUDIO_DRIVER
#define MINIAUDIO_IMPLEMENTATION
#include "faust/miniaudio.h"
#endif
//**************************************************************
// Soundfile handling
//**************************************************************
// Must be done before <<includeclass>> otherwise the 'Soundfile' type is not known
#if SOUNDFILE
// So that the code uses JUCE audio file loading code
#if JUCE_DRIVER
#define JUCE_64BIT 1
#elif MINIAUDIO_DRIVER
#define MINIAUDIO_READER
#endif
#include "faust/gui/SoundUI.h"
#endif
//**************************************************************
// OSC configuration (hardcoded for now...)
//**************************************************************
#define OSC_IP_ADDRESS "192.168.1.112"
#define OSC_IN_PORT "5510"
#define OSC_OUT_PORT "5511"
//**************************************************************
// Intrinsic
//**************************************************************
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
#include <algorithm>
#include <cmath>
#include <cstdint>
#ifndef FAUSTCLASS
#define FAUSTCLASS mydsp
#endif
#ifdef __APPLE__
#define exp10f __exp10f
#define exp10 __exp10
#endif
#if defined(_WIN32)
#define RESTRICT __restrict
#else
#define RESTRICT __restrict__
#endif
class mydsp : public dsp {
private:
int fSampleRate;
public:
mydsp() {
}
void metadata(Meta* m) {
m->declare("compile_options", "-a ../architecture/api/DspFaust.cpp -lang cpp -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0");
m->declare("filename", "mydsp.dsp");
m->declare("name", "mydsp");
}
virtual int getNumInputs() {
return 0;
}
virtual int getNumOutputs() {
return 1;
}
static void classInit(int sample_rate) {
}
virtual void instanceConstants(int sample_rate) {
fSampleRate = sample_rate;
}
virtual void instanceResetUserInterface() {
}
virtual void instanceClear() {
}
virtual void init(int sample_rate) {
classInit(sample_rate);
instanceInit(sample_rate);
}
virtual void instanceInit(int sample_rate) {
instanceConstants(sample_rate);
instanceResetUserInterface();
instanceClear();
}
virtual mydsp* clone() {
return new mydsp();
}
virtual int getSampleRate() {
return fSampleRate;
}
virtual void buildUserInterface(UI* ui_interface) {
ui_interface->openVerticalBox("mydsp");
ui_interface->closeBox();
}
virtual void compute(int count, FAUSTFLOAT** RESTRICT inputs, FAUSTFLOAT** RESTRICT outputs) {
FAUSTFLOAT* output0 = outputs[0];
for (int i0 = 0; i0 < count; i0 = i0 + 1) {
output0[i0] = FAUSTFLOAT(0);
}
}
};
//**************************************************************
// Polyphony
//**************************************************************
#include "faust/dsp/faust-poly-engine.h"
//**************************************************************
// Audio driver
//**************************************************************
#if COREAUDIO_DRIVER
#include "faust/audio/coreaudio-dsp.h"
#elif IOS_DRIVER
#include "faust/audio/coreaudio-ios-dsp.h"
#elif ANDROID_DRIVER
#include "faust/audio/oboe-dsp.h"
#elif ALSA_DRIVER
#include "faust/audio/alsa-dsp.h"
#elif JACK_DRIVER
#include "faust/audio/jack-dsp.h"
#elif PORTAUDIO_DRIVER
#include "faust/audio/portaudio-dsp.h"
#elif RTAUDIO_DRIVER
#include "faust/audio/rtaudio-dsp.h"
#elif MINIAUDIO_DRIVER
#include "faust/audio/miniaudio-dsp.h"
#elif OPEN_FRAMEWORK_DRIVER
#include "faust/audio/ofaudio-dsp.h"
#elif JUCE_DRIVER
#include "faust/audio/juce-dsp.h"
#elif DUMMY_DRIVER
#include "faust/audio/dummy-audio.h"
#elif TEENSY_DRIVER
#include "faust/audio/teensy-dsp.h"
#elif ESP32_DRIVER
#include "faust/audio/esp32-dsp.h"
#endif
//**************************************************************
// Interface
//**************************************************************
#if MIDICTRL
#if JACK_DRIVER
// Nothing to add since jack-dsp.h contains MIDI
#elif JUCE_DRIVER
#include "faust/midi/juce-midi.h"
#elif TEENSY_DRIVER
#include "faust/midi/teensy-midi.h"
#elif ESP32_DRIVER
#include "faust/midi/esp32-midi.h"
#else
#include "faust/midi/rt-midi.h"
#include "faust/midi/RtMidi.cpp"
#endif
#endif
#if OSCCTRL
#if JUCE_DRIVER
#include "faust/gui/JuceOSCUI.h"
#else
#include "faust/gui/OSCUI.h"
#endif
#endif
#if DYNAMIC_DSP
#include "faust/dsp/llvm-dsp.h"
#endif
#include "DspFaust.h"
using namespace std;
std::list<GUI*> GUI::fGuiList;
ztimedmap GUI::gTimedZoneMap;
static bool hasCompileOption(const string& options, const char* option)
{
const char* sep = " ";
string options_copy = options; // strtok modifies the string in-place
for (char* token = strtok(&options_copy[0], sep); token; token = strtok(nullptr, sep)) {
if (strcmp(token, option) == 0) return true;
}
return false;
}
DspFaust::DspFaust(bool auto_connect)
{
#if JACK_DRIVER
// JACK has its own sample rate and buffer size
#if MIDICTRL
fDriver = new jackaudio_midi(auto_connect);
#else
fDriver = new jackaudio(auto_connect);
#endif
#elif JUCE_DRIVER
// JUCE audio device has its own sample rate and buffer size
fDriver = new juceaudio();
#elif ANDROID_DRIVER
fDriver = new oboeaudio(-1);
#else
printf("You are not setting 'sample_rate' and 'buffer_size', but the audio driver needs it !\n");
throw std::bad_alloc();
#endif
init(new mydsp(), fDriver);
}
DspFaust::DspFaust(int sample_rate, int buffer_size, bool auto_connect)
{
fDriver = createDriver(sample_rate, buffer_size, auto_connect);
init(new mydsp(), fDriver);
}
#if DYNAMIC_DSP
DspFaust::DspFaust(const string& dsp_content, int sample_rate, int buffer_size, bool auto_connect)
{
string error_msg;
// Is dsp_content a filename ?
fFactory = createDSPFactoryFromFile(dsp_content, 0, nullptr, "", error_msg, -1);
if (!fFactory) {
fprintf(stderr, "ERROR : %s", error_msg.c_str());
// Is dsp_content a string ?
fFactory = createDSPFactoryFromString("FaustDSP", dsp_content, 0, nullptr, "", error_msg);
if (!fFactory) {
fprintf(stderr, "ERROR : %s", error_msg.c_str());
throw bad_alloc();
}
}
dsp* dsp = fFactory->createDSPInstance();
if (!dsp) {
fprintf(stderr, "Cannot allocate DSP instance\n");
deleteDSPFactory(fFactory);
throw bad_alloc();
}
fDriver = createDriver(sample_rate, buffer_size, auto_connect);
init(dsp, fDriver);
}
#endif
audio* DspFaust::createDriver(int sample_rate, int buffer_size, bool auto_connect)
{
audio* driver;
#if COREAUDIO_DRIVER
driver = new coreaudio(sample_rate, buffer_size);
#elif IOS_DRIVER
driver = new iosaudio(sample_rate, buffer_size);
#elif ANDROID_DRIVER
// OBOE has its own and buffer size
fprintf(stderr, "You are setting 'buffer_size' with a driver that does not need it !\n");
driver = new oboeaudio(-1);
#elif ALSA_DRIVER
driver = new alsaaudio(sample_rate, buffer_size);
#elif JACK_DRIVER
// JACK has its own sample rate and buffer size
fprintf(stderr, "You are setting 'sample_rate' and 'buffer_size' with a driver that does not need it !\n");
#if MIDICTRL
driver = new jackaudio_midi(auto_connect);
#else
driver = new jackaudio(auto_connect);
#endif
#elif PORTAUDIO_DRIVER
driver = new portaudio(sample_rate, buffer_size);
#elif RTAUDIO_DRIVER
driver = new rtaudio(sample_rate, buffer_size);
#elif MINIAUDIO_DRIVER
driver = new miniaudio(sample_rate, buffer_size);
#elif OPEN_FRAMEWORK_DRIVER
driver = new ofaudio(sample_rate, buffer_size);
#elif JUCE_DRIVER
// JUCE audio device has its own sample rate and buffer size
fprintf(stderr, "You are setting 'sample_rate' and 'buffer_size' with a driver that does not need it !\n");
driver = new juceaudio();
#elif ESP32_DRIVER
driver = new esp32audio(sample_rate, buffer_size);
#elif DUMMY_DRIVER
driver = new dummyaudio(sample_rate, buffer_size);
#endif
return driver;
}
void DspFaust::init(dsp* mono_dsp, audio* driver)
{
#if MIDICTRL
#if JACK_DRIVER
fMidiHandler = static_cast<jackaudio_midi*>(driver);
fMidiInterface = new MidiUI(fMidiHandler);
#elif JUCE_DRIVER
fMidiHandler = new juce_midi();
fMidiInterface = new MidiUI(fMidiHandler);
#elif TEENSY_DRIVER
fMidiHandler = new teensy_midi();
fMidiInterface = new MidiUI(fMidiHandler);
#elif ESP32_DRIVER
fMidiHandler = new esp32_midi();
fMidiInterface = new MidiUI(fMidiHandler);
#else
fMidiHandler = new rt_midi();
fMidiInterface = new MidiUI(fMidiHandler);
#endif
fPolyEngine = new FaustPolyEngine(mono_dsp, driver, fMidiHandler);
fPolyEngine->buildUserInterface(fMidiInterface);
#else
fPolyEngine = new FaustPolyEngine(mono_dsp, driver);
#endif
#if OSCCTRL
#if JUCE_DRIVER
fOSCInterface = new JuceOSCUI(OSC_IP_ADDRESS, atoi(OSC_IN_PORT), atoi(OSC_OUT_PORT));
#else
const char* argv[9];
argv[0] = "Faust"; // TODO may be should retrieve the actual name
argv[1] = "-xmit";
argv[2] = "1"; // TODO retrieve that from command line or somewhere
argv[3] = "-desthost";
argv[4] = OSC_IP_ADDRESS; // TODO same
argv[5] = "-port";
argv[6] = OSC_IN_PORT; // TODO same
argv[7] = "-outport";
argv[8] = OSC_OUT_PORT; // TODO same
/*
Deactivated for now (sometimes crashing)
argv[9] = "-bundle";
argv[10] = "1"; // TODO same
*/
fOSCInterface = new OSCUI("Faust", 9, (char**)argv); // TODO fix name
#endif
fPolyEngine->buildUserInterface(fOSCInterface);
#endif
// Retrieving DSP object 'compile_options'
struct MyMeta : public Meta
{
string fCompileOptions;
void declare(const char* key, const char* value)
{
if (strcmp(key, "compile_options") == 0) fCompileOptions = value;
}
MyMeta(){}
};
MyMeta meta;
mono_dsp->metadata(&meta);
bool is_double = hasCompileOption(meta.fCompileOptions, "-double");
#if SOUNDFILE
#if JUCE_DRIVER
auto file = juce::File::getSpecialLocation(juce::File::currentExecutableFile)
.getParentDirectory().getParentDirectory().getChildFile("Resources");
fSoundInterface = new SoundUI(file.getFullPathName().toStdString(), -1, nullptr, is_double);
#else
// Use bundle path
fSoundInterface = new SoundUI(SoundUI::getBinaryPath(), -1, nullptr, is_double);
#endif
fPolyEngine->buildUserInterface(fSoundInterface);
#endif
}
DspFaust::~DspFaust()
{
#if OSCCTRL
delete fOSCInterface;
#endif
#if SOUNDFILE
delete fSoundInterface;
#endif
delete fPolyEngine;
#if DYNAMIC_DSP
deleteDSPFactory(static_cast<llvm_dsp_factory*>(fFactory));
#endif
#if MIDICTRL
delete fMidiInterface; // after deleting fPolyEngine;
#if JACK_DRIVER
// JACK has its own MIDI interface, don't delete fMidiHandler
#else
delete fMidiHandler; // after deleting fMidiInterface;
#endif
#endif
delete fDriver;
}
bool DspFaust::start()
{
#if OSCCTRL
fOSCInterface->run();
#endif
#if MIDICTRL
if (!fMidiInterface->run()) {
fprintf(stderr, "MIDI run error...\n");
}
#endif
return fPolyEngine->start();
}
void DspFaust::stop()
{
#if OSCCTRL
fOSCInterface->stop();
#endif
#if MIDICTRL
fMidiInterface->stop();
#endif
fPolyEngine->stop();
}
bool DspFaust::configureOSC(int xmit, int inport, int outport, int errport, const char* address)
{
#if OSCCTRL
#if JUCE_DRIVER
// Nothing for now
return false;
#else
if (isRunning()) {
return false;
} else {
oscfaust::OSCControler::gXmit = xmit;
fOSCInterface->setUDPPort(inport);
fOSCInterface->setUDPOut(outport);
fOSCInterface->setUDPErr(errport);
fOSCInterface->setDestAddress(address);
return true;
}
#endif
#else
return false;
#endif
}
bool DspFaust::isOSCOn()
{
#if OSCCTRL
return true;
#else
return false;
#endif
}
bool DspFaust::isRunning()
{
return fPolyEngine->isRunning();
}
uintptr_t DspFaust::keyOn(int pitch, int velocity)
{
return (uintptr_t)fPolyEngine->keyOn(pitch, velocity);
}
int DspFaust::keyOff(int pitch)
{
return fPolyEngine->keyOff(pitch);
}
uintptr_t DspFaust::newVoice()
{
return (uintptr_t)fPolyEngine->newVoice();
}
int DspFaust::deleteVoice(uintptr_t voice)
{
return fPolyEngine->deleteVoice(voice);
}
void DspFaust::allNotesOff(bool hard)
{
fPolyEngine->allNotesOff(hard);
}
void DspFaust::propagateMidi(int count, double time, int type, int channel, int data1, int data2)
{
fPolyEngine->propagateMidi(count, time, type, channel, data1, data2);
}
const char* DspFaust::getJSONUI()
{
return fPolyEngine->getJSONUI();
}
const char* DspFaust::getJSONMeta()
{
return fPolyEngine->getJSONMeta();
}
void DspFaust::buildUserInterface(UI* ui_interface)
{
fPolyEngine->buildUserInterface(ui_interface);
}
int DspFaust::getParamsCount()
{
return fPolyEngine->getParamsCount();
}
void DspFaust::setParamValue(const char* address, float value)
{
fPolyEngine->setParamValue(address, value);
}
void DspFaust::setParamValue(int id, float value)
{
fPolyEngine->setParamValue(id, value);
}
float DspFaust::getParamValue(const char* address)
{
return fPolyEngine->getParamValue(address);
}
float DspFaust::getParamValue(int id)
{
return fPolyEngine->getParamValue(id);
}
void DspFaust::setVoiceParamValue(const char* address, uintptr_t voice, float value)
{
fPolyEngine->setVoiceParamValue(address, voice, value);
}
void DspFaust::setVoiceParamValue(int id, uintptr_t voice, float value)
{
fPolyEngine->setVoiceParamValue(id, voice, value);
}
float DspFaust::getVoiceParamValue(const char* address, uintptr_t voice)
{
return fPolyEngine->getVoiceParamValue(address, voice);
}
float DspFaust::getVoiceParamValue(int id, uintptr_t voice)
{
return fPolyEngine->getVoiceParamValue(id, voice);
}
const char* DspFaust::getParamAddress(int id)
{
return fPolyEngine->getParamAddress(id);
}
const char* DspFaust::getVoiceParamAddress(int id, uintptr_t voice)
{
return fPolyEngine->getVoiceParamAddress(id, voice);
}
float DspFaust::getParamMin(const char* address)
{
return fPolyEngine->getParamMin(address);
}
float DspFaust::getParamMin(int id)
{
return fPolyEngine->getParamMin(id);
}
float DspFaust::getParamMax(const char* address)
{
return fPolyEngine->getParamMax(address);
}
float DspFaust::getParamMax(int id)
{
return fPolyEngine->getParamMax(id);
}
float DspFaust::getParamInit(const char* address)
{
return fPolyEngine->getParamInit(address);
}
float DspFaust::getParamInit(int id)
{
return fPolyEngine->getParamInit(id);
}
const char* DspFaust::getMetadata(const char* address, const char* key)
{
return fPolyEngine->getMetadata(address, key);
}
const char* DspFaust::getMetadata(int id, const char* key)
{
return fPolyEngine->getMetadata(id, key);
}
void DspFaust::propagateAcc(int acc, float v)
{
fPolyEngine->propagateAcc(acc, v);
}
void DspFaust::setAccConverter(int p, int acc, int curve, float amin, float amid, float amax)
{
fPolyEngine->setAccConverter(p, acc, curve, amin, amid, amax);
}
void DspFaust::propagateGyr(int acc, float v)
{
fPolyEngine->propagateGyr(acc, v);
}
void DspFaust::setGyrConverter(int p, int gyr, int curve, float amin, float amid, float amax)
{
fPolyEngine->setGyrConverter(p, gyr, curve, amin, amid, amax);
}
float DspFaust::getCPULoad()
{
return fPolyEngine->getCPULoad();
}
int DspFaust::getScreenColor()
{
return fPolyEngine->getScreenColor();
}
#ifdef BUILD
#include <unistd.h>
int main(int argc, char* argv[])
{
try {
#ifdef DYNAMIC_DSP
if (argc == 1) {
printf("./dynamic-api <foo.dsp> \n");
exit(-1);
}
DspFaust* dsp = new DspFaust(argv[1], 44100, 512);
#else
DspFaust* dsp = new DspFaust(44100, 512);
#endif
dsp->start();
printf("Type 'q' to quit\n");
char c;
while ((c = getchar()) && (c != 'q')) { usleep(100000); }
dsp->stop();
delete dsp;
} catch (...) {
fprintf(stderr, "Cannot allocate or start DspFaust\n");
}
}
#endif
#endif
/************************************************************************
************************************************************************
FAUST API Architecture File
Copyright (C) 2016 GRAME, Romain Michon, CCRMA - Stanford University
Copyright (C) 2014-2016 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section 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 3 of
the License, 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 <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
#ifndef __faust_api__
#define __faust_api__
#include <cstdint>
#include <string>
//===============API Reference==============
//==========================================
class FaustPolyEngine;
class MidiUI;
class OSCUI;
class JuceOSCUI;
class SoundUI;
class audio;
class dsp;
class UI;
class dsp_factory;
class DspFaust
{
private:
FaustPolyEngine* fPolyEngine;
audio* fDriver;
#if OSCCTRL
#if JUCE_DRIVER
JuceOSCUI* fOSCInterface;
#else
OSCUI* fOSCInterface;
#endif
#endif
#if MIDICTRL
MidiUI* fMidiInterface;
midi_handler* fMidiHandler;
#endif
#if SOUNDFILE
SoundUI* fSoundInterface;
#endif
#if DYNAMIC_DSP
llvm_dsp_factory* fFactory;
#endif
void init(dsp* mono_dsp, audio* driver);
audio* createDriver(int sample_rate, int buffer_size, bool auto_connect = true);
public:
//--------------`DspFaust(bool auto_connect = true)`----------------
// Default constructor for the static model, to be used wih audio drivers that impose their sample rate and buffer size (like JACK and JUCE).
//
// #### Arguments
//
// * `auto_connect`: whether to automatically connect audio outputs to the hardware (usable with JACK)
//----
DspFaust(bool auto_connect = true);
//--------------`DspFaust(int SR, int BS, bool auto_connect = true)`----------------
// Constructor for the static model.
//
// #### Arguments
//
// * `SR`: sampling rate
// * `BS`: buffer size
// * `auto_connect`: whether to automatically connect audio outputs to the hardware (usable with JACK)
//--------------------------------------------------------
DspFaust(int SR, int BS, bool auto_connect = true);
//--------------`DspFaust(const string& dsp_content, int SR, int BS, bool auto_connect = true)`----------------
// Constructor for the dynamic model, using LLVM + JIT compilation.
//
// #### Arguments
//
// * `dsp_content`: the DSP as a file or string
// * `SR`: sampling rate
// * `BS`: buffer size
// * `auto_connect`: whether to automatically connect audio outputs to the hardware (usable with JACK)
//--------------------------------------------------------
#if DYNAMIC_DSP
DspFaust(const std::string& dsp_content, int SR, int BS, bool auto_connect = true);
#endif
// No virtual destructor since DspFaust does not have any virtual methods and is not supposed to be subclassed
~DspFaust();
//---------------------`bool start()`---------------------
// Start the audio processing.
//
// Returns `true` if successful and `false` if not.
//--------------------------------------------------------
bool start();
//-----------------`void stop()`--------------------------
// Stop the audio processing.
//--------------------------------------------------------
void stop();
//---------------------`bool isRunning()`-----------------
// Returns `true` if audio is running.
//--------------------------------------------------------
bool isRunning();
//--------`uintptr_t keyOn(int pitch, int velocity)`-----------
// Instantiate a new polyphonic voice. This method can
// only be used if the `-nvoices` flag has been
// provided before compilation.
//
// `keyOn` will return 0 if the Faust object is not
// polyphonic or the address to the allocated voice as
// an `uintptr_t` otherwise. This value can be used later with
// [`setVoiceParamValue`](#setvoiceparamvalue) or
// [`getVoiceParamValue`](#getvoiceparamvalue) to access
// the parameters of a specific voice.
//
// #### Arguments
//
// * `pitch`: MIDI note number (0-127)
// * `velocity`: MIDI velocity (0-127)
//--------------------------------------------------------
uintptr_t keyOn(int pitch, int velocity);
//----------------`int keyOff(int pitch)`-----------------
// De-instantiate a polyphonic voice. This method can
// only be used if the `-nvoices` flag has been
// provided before compilation.
//
// `keyOff` will return 0 if the object is not polyphonic
// and 1 otherwise.
//
// #### Arguments
//
// * `pitch`: MIDI note number (0-127), should be the same
// as the one used for `keyOn`
//--------------------------------------------------------
int keyOff(int pitch);
//-------------------`uintptr_t newVoice()`--------------------
// Instantiate a new polyphonic voice. This method can
// only be used if `-nvoices` flag has been
// provided before compilation.
//
// `newVoice` will return 0 if the Faust object is not
// polyphonic or the address to the allocated voice as
// a `uintptr_t` otherwise. This value can be used later with
// `setVoiceParamValue`, `getVoiceParamValue` or
// `deleteVoice` to access the parameters of a specific
// voice.
//--------------------------------------------------------
uintptr_t newVoice();
//---------`int deleteVoice(uintptr_t voice)`------------------
// De-instantiate a polyphonic voice. This method can
// only be used if `-nvoices` flag has been
// provided before compilation.
//
// `deleteVoice` will return 0 if the object is not polyphonic
// and 1 otherwise.
//
// #### Arguments
//
// * `voice`: the address of the voice given by `newVoice` or `keyOn`
//--------------------------------------------------------
int deleteVoice(uintptr_t voice);
//-----------------`void allNotesOff(bool hard = false)`----------------
// Terminates all the active voices, gently (with release when hard = false or immediately when hard = true).
//--------------------------------------------------------
void allNotesOff(bool hard = false);
//-------`void propagateMidi(int count, double time, int type, int channel, int data1, int data2)`--------
// Take a raw MIDI message and propagate it to the Faust
// DSP object. This method can be used concurrently with
// [`keyOn`](#keyOn) and [`keyOff`](#keyOff).
//
// `propagateMidi` can only be used if `-nvoices` flag has been
// provided before compilation.
//
// #### Arguments
//
// * `count`: size of the message (1-3)
// * `time`: time stamp in usec
// * `type`: message type (byte)
// * `channel`: channel number
// * `data1`: first data byte (should be `null` if `count<2`)
// * `data2`: second data byte (should be `null` if `count<3`)
//--------------------------------------------------------
void propagateMidi(int count, double time, int type, int channel, int data1, int data2);
//-----------------`const char* getJSONUI()`----------------
// Returns the JSON description of the UI of the Faust object.
//--------------------------------------------------------
const char* getJSONUI();
//-----------------`const char* getJSONMeta()`----------------
// Returns the JSON description of the metadata of the Faust object.
//--------------------------------------------------------
const char* getJSONMeta();
//--------------`void buildUserInterface(UI* ui_interface)`---------------
// Calls the polyphonic or monophonic buildUserInterface with the ui_interface parameter.
//
// #### Arguments
//
// * `ui_interface`: an UI* object
//--------------------------------------------------------
void buildUserInterface(UI* ui_interface);
//-----------------`int getParamsCount()`-----------------
// Returns the number of parameters of the Faust object.
//--------------------------------------------------------
int getParamsCount();
//----`void setParamValue(const char* address, float value)`------
// Set the value of one of the parameters of the Faust
// object in function of its address (label/shortname/path).
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
// * `value`: value of the parameter
//--------------------------------------------------------
void setParamValue(const char* address, float value);
//----`void setParamValue(int id, float value)`---
// Set the value of one of the parameters of the Faust
// object in function of its id.
//
// #### Arguments
//
// * `id`: id of the parameter
// * `value`: value of the parameter
//--------------------------------------------------------
void setParamValue(int id, float value);
//----`float getParamValue(const char* address)`----------
// Returns the value of a parameter in function of its
// address (label/shortname/path).
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
//--------------------------------------------------------
float getParamValue(const char* address);
//---------`float getParamValue(int id)`----------
// Returns the value of a parameter in function of its id.
//
// #### Arguments
//
// * `id`: id of the parameter
//--------------------------------------------------------
float getParamValue(int id);
//----`void setVoiceParamValue(const char* address, uintptr_t voice, float value)`-----
// Set the value of one of the parameters of the Faust
// object in function of its address (label/shortname/path) for a specific voice.
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
// * `voice`: address of the polyphonic voice (retrieved from `keyOn`)
// * `value`: value of the parameter
//--------------------------------------------------------
void setVoiceParamValue(const char* address, uintptr_t voice, float value);
//----`void setVoiceParamValue(int id, uintptr_t voice, float value)`-----
// Set the value of one of the parameters of the Faust
// object in function of its id for a specific voice.
//
// #### Arguments
//
// * `id`: id of the parameter
// * `voice`: address of the polyphonic voice (retrieved from `keyOn`)
// * `value`: value of the parameter
//--------------------------------------------------------
void setVoiceParamValue(int id, uintptr_t voice, float value);
//----`float getVoiceParamValue(const char* address, uintptr_t voice)`----
// Returns the value of a parameter in function of its
// address (label/shortname/path) for a specific voice.
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
// * `voice`: address of the polyphonic voice (retrieved from `keyOn`)
//--------------------------------------------------------
float getVoiceParamValue(const char* address, uintptr_t voice);
//----`float getVoiceParamValue(int id, uintptr_t voice)`----
// Returns the value of a parameter in function of its
// id for a specific voice.
//
// #### Arguments
//
// * `id`: id of the parameter
// * `voice`: address of the polyphonic voice (retrieved from `keyOn`)
//--------------------------------------------------------
float getVoiceParamValue(int id, uintptr_t voice);
//----`const char* getParamAddress(int id)`---------------
// Returns the address (label/shortname/path) of a parameter in function of its ID.
//
// #### Arguments
//
// * `id`: id of the parameter
//--------------------------------------------------------
const char* getParamAddress(int id);
//----`const char* getVoiceParamAddress(int id, uintptr_t voice)`-----
// Returns the address (label/shortname/path) of a parameter in function of its ID.
//
// #### Arguments
//
// * `id`: id of the parameter
// * `voice`: address of the polyphonic voice (retrieved from `keyOn`)
//--------------------------------------------------------
const char* getVoiceParamAddress(int id, uintptr_t voice);
//-------`float getParamMin(const char* address)`---------
// Returns the minimum value of a parameter in function of
// its address (label/shortname/path).
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
//--------------------------------------------------------
float getParamMin(const char* address);
//--------------`float getParamMin(int id)`---------------
// Returns the minimum value of a parameter in function
// of its ID.
//
// #### Arguments
//
// * `id`: id of the parameter
//--------------------------------------------------------
float getParamMin(int id);
//-------`float getParamMax(const char* address)`---------
// Returns the maximum value of a parameter in function of
// its address (label/shortname/path).
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
//--------------------------------------------------------
float getParamMax(const char* address);
//--------------`float getParamMax(int id)`---------------
// Returns the maximum value of a parameter in function
// of its ID.
//
// #### Arguments
//
// * `id`: id of the parameter
//--------------------------------------------------------
float getParamMax(int id);
//-------`float getParamInit(const char* address)`---------
// Returns the default value of a parameter in function of
// its address (label/shortname/path).
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
//--------------------------------------------------------
float getParamInit(const char* address);
//--------------`float getParamInit(int id)`---------------
// Returns the default value of a parameter in function
// of its ID.
//
// #### Arguments
//
// * `id`: id of the parameter
//--------------------------------------------------------
float getParamInit(int id);
//-----`const char* getMetadata(const char* address, const char* key)`-----
// Returns the metadata of a parameter in function of
// its address (label/shortname/path) and the metadata key.
//
// #### Arguments
//
// * `address`: address (label/shortname/path) of the parameter
// * `key`: the metadata key
//--------------------------------------------------------
const char* getMetadata(const char* address, const char* key);
//----`const char* getMetadata(int id, const char* key)`---------------
// Returns the metadata of a parameter in function of
// its iD and the metadata key.
//
// #### Arguments
//
// * `id`: id of the parameter
// * `key`: the metadata key
//--------------------------------------------------------
const char* getMetadata(int id, const char*);
//----`void propagateAcc(int acc, float v)`---------------
// Propagate the RAW value of a specific accelerometer
// axis to the Faust object.
//
// #### Arguments
//
// * `acc`: the accelerometer axis (**0**: x, **1**: y, **2**: z)
// * `v`: the RAW accelerometer value in m/s
//--------------------------------------------------------
void propagateAcc(int acc, float v);
//----`void setAccConverter(int id, int acc, int curve, float amin, float amid, float amax)`-----
// Set the conversion curve for the accelerometer.
//
// #### Arguments
//
// * `id`: the UI parameter id
// * `acc`: the accelerometer axis (**0**: x, **1**: y, **2**: z)
// * `curve`: the curve (**0**: up, **1**: down, **2**: up and down, **2**: down and up)
// * `amin`: mapping min point
// * `amid`: mapping middle point
// * `amax`: mapping max point
//--------------------------------------------------------
void setAccConverter(int id, int acc, int curve, float amin, float amid, float amax);
//----`void propagateGyr(int gyr, float v)`---------------
// Propagate the RAW value of a specific gyroscope
// axis to the Faust object.
//
// #### Arguments
//
// * `gyr`: the gyroscope axis (**0**: x, **1**: y, **2**: z)
// * `v`: the RAW gyroscope value in m/s
//--------------------------------------------------------
void propagateGyr(int gyr, float v);
//----`void setGyrConverter(int id, int gyr, int curve, float amin, float amid, float amax)`-----
// Set the conversion curve for the gyroscope.
//
// #### Arguments
//
// * `id`: the UI parameter id
// * `gyr`: the gyroscope axis (**0**: x, **1**: y, **2**: z)
// * `curve`: the curve (**0**: up, **1**: down, **2**: up and down, **2**: down and up)
// * `amin`: mapping min point
// * `amid`: mapping middle point
// * `amax`: mapping max point
//--------------------------------------------------------
void setGyrConverter(int id, int gyr, int curve, float amin, float amid, float amax);
//------------------`float getCPULoad()`------------------
// Returns the CPU load (between 0 and 1.0).
//--------------------------------------------------------
float getCPULoad();
//----`void configureOSC(int xmit, int inport, int outport, int errport, const char* address)`---------------
// Change the OSC configuration.
//
// #### Arguments
//
// * `xmit`: the xmit state (off-0 all-1 alias-2)
// * `inport`: the input port number
// * `outport`: the output port number
// * `errport`: the error port number
// * `address`: the destination IP address
//--------------------------------------------------------
bool configureOSC(int xmit, int inport, int outport, int errport, const char* address);
//----------`bool isOSCOn()`---------------
// Return OSC Status.
//-----------------------------------------
bool isOSCOn();
//----------`int getScreenColor()`---------------
// Get the requested screen color.
// -1 means no screen color control (no screencolor metadata found)
// otherwise return 0x00RRGGBB a ready to use color
//-----------------------------------------
int getScreenColor();
};
#endif
// pw-jack ./build/linux-jack mydsp.dsp
#include <unistd.h>
#include "faust/midi/midi.h"
#include "faust/dsp/llvm-dsp.h"
#include "DspFaust.h"
#include <cstdio>
#include <cstdlib>
int main(int argc, char* argv[])
{
try {
if (argc == 1) {
printf("./dynamic-api <foo.dsp> \n");
exit(-1);
}
DspFaust* dsp;
char c;
dsp = new DspFaust(argv[1], 44100, 512);
dsp->start();
printf("1- Running for 2 seconds\n");
usleep(2e6);
dsp->stop();
delete dsp;
usleep(0.1e6);
dsp = new DspFaust(argv[1], 44100, 512);
dsp->start();
printf("2- Running for 2 seconds\n");
usleep(2e6);
dsp->stop();
delete dsp;
} catch (...) {
fprintf(stderr, "Cannot allocate or start DspFaust\n");
}
}
process = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment