/usr/include/faust/dsp/faust-poly-engine.h is in faust-common 0.9.95~repack1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | /************************************************************************
************************************************************************
FAUST Polyphonic Architecture File
Copyright (C) 2013 GRAME, Romain Michon, CCRMA - Stanford University
Copyright (C) 2003-2015 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This is sample code. This file is provided as an example of minimal
FAUST architecture file. Redistribution and use in source and binary
forms, with or without modification, in part or in full are permitted.
In particular you can create a derived work of this FAUST architecture
and distribute that work under terms of your choice.
This sample code 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.
************************************************************************
************************************************************************/
#ifndef __faust_poly_engine__
#define __faust_poly_engine__
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "faust/misc.h"
#include "faust/dsp/dsp.h"
#include "faust/audio/audio.h"
#include "faust/gui/meta.h"
#include "faust/gui/JSONUI.h"
#include "faust/gui/APIUI.h"
#include "faust/dsp/poly-dsp.h"
#include "faust/dsp/faust-engine.h"
#include "faust/dsp/dsp-combiner.h"
//**************************************************************
// Mono or polyphonic audio DSP engine
//**************************************************************
#ifndef POLY_VOICES
#define POLY_VOICES 0 // default is no polyphony (mono)
#endif
using namespace std;
class FaustPolyEngine {
protected:
mydsp_poly* fPolyDSP; // the polyphonic Faust object
dsp* fFinalDSP; // the "final" dsp object submitted to the audio driver
APIUI fAPIUI; // the UI description
string fJSONUI;
string fJSONMeta;
bool fRunning;
audio* fDriver;
midi_handler fMidiHandler;
MidiUI fMidiUI;
public:
FaustPolyEngine(audio* driver = NULL):fMidiUI(&fMidiHandler)
{
fDriver = driver;
fRunning = false;
mydsp* mono_dsp = new mydsp();
// Getting the UI JSON
JSONUI jsonui1(mono_dsp->getNumInputs(), mono_dsp->getNumOutputs());
mono_dsp->buildUserInterface(&jsonui1);
fJSONUI = jsonui1.JSON();
// Getting the metadata JSON
JSONUI jsonui1M(mono_dsp->getNumInputs(), mono_dsp->getNumOutputs());
mono_dsp->metadata(&jsonui1M);
fJSONMeta = jsonui1M.JSON();
if (fJSONUI.find("keyboard") != std::string::npos
|| fJSONUI.find("poly") != std::string::npos
|| POLY_VOICES != 0) {
int poly_max = (POLY_VOICES != 0) ? POLY_VOICES : 10; // default number of poly voices
fPolyDSP = new mydsp_poly(mono_dsp, poly_max, true);
#if POLY2
fFinalDSP = new dsp_sequencer(fPolyDSP, new effect());
#else
fFinalDSP = fPolyDSP;
#endif
// Update JSONs with Poly version
JSONUI jsonui2(mono_dsp->getNumInputs(), mono_dsp->getNumOutputs());
fFinalDSP->buildUserInterface(&jsonui2);
fJSONUI = jsonui2.JSON();
JSONUI jsonui2M(mono_dsp->getNumInputs(), mono_dsp->getNumOutputs());
fFinalDSP->metadata(&jsonui2M);
fJSONMeta = jsonui2M.JSON();
} else {
fPolyDSP = NULL;
fFinalDSP = mono_dsp;
}
fFinalDSP->buildUserInterface(&fMidiUI);
fFinalDSP->buildUserInterface(&fAPIUI);
fDriver->init("Dummy", fFinalDSP);
}
virtual ~FaustPolyEngine()
{
delete fDriver;
delete fFinalDSP;
}
/*
* start()
* Begins the processing and return true if the connection
* with the audio device was successful and false if not.
*/
bool start()
{
if (!fRunning) {
fRunning = fDriver->start();
}
return fRunning;
}
/*
* isRunning()
* Returns true if the DSP frames are being computed and
* false if not.
*/
bool isRunning()
{
return fRunning;
}
/*
* stop()
* Stops the processing, closes the audio engine.
*/
void stop()
{
if (fRunning) {
fRunning = false;
fDriver->stop();
}
}
/*
* keyOn(pitch, velocity)
* Instantiates a new polyphonic voice where velocity
* and pitch are MIDI numbers (0-127). keyOn can only
* be used if the [style:poly] metadata is used in the
* Faust code. keyOn will return 0 if the object is not
* polyphonic and the allocated voice otherwise.
*/
MapUI* keyOn(int pitch, int velocity)
{
if (fPolyDSP) {
return fPolyDSP->keyOn(0, pitch, velocity); // MapUI* passed to Java as an integer
} else {
return 0;
}
}
/*
* keyOff(pitch)
* De-instantiates a polyphonic voice where pitch is the
* MIDI number of the note (0-127). keyOff can only be
* used if the [style:poly] metadata is used in the Faust
* code. keyOn will return 0 if the object is not polyphonic
* and 1 otherwise.
*/
int keyOff(int pitch, int velocity = 127)
{
if (fPolyDSP) {
fPolyDSP->keyOff(0, pitch, velocity);
return 1;
} else {
return 0;
}
}
/*
* newVoice()
* Instantiate a new voice and returns the corresponding mapUI.
*/
MapUI* newVoice()
{
if (fPolyDSP) {
return fPolyDSP->newVoice();
} else {
return 0;
}
}
/*
* deleteVoice(MapUI* voice)
* Delete a voice based on its MapUI*.
*/
int deleteVoice(MapUI* voice)
{
if (fPolyDSP) {
fPolyDSP->deleteVoice(voice);
return 1;
} else {
return 0;
}
}
/*
* deleteVoice(long voice)
* Delete a voice based on its MapUI* casted as a long.
*/
int deleteVoice(long voice)
{
return deleteVoice(reinterpret_cast<MapUI*>(voice));
}
/*
* allNotesOff()
* Gently terminates all the active voices.
*/
void allNotesOff()
{
if (fPolyDSP) {
fPolyDSP->allNotesOff();
}
}
/*
* Propagate MIDI data to the Faust object.
*/
void propagateMidi(int count, double time, int type, int channel, int data1, int data2)
{
if (count == 3) fMidiHandler.handleData2(time, type, channel, data1, data2);
else if (count == 2) fMidiHandler.handleData1(time, type, channel, data1);
else if (count == 1) fMidiHandler.handleSync(time, type);
GUI::updateAllGuis();
}
/*
* getJSONUI()
* Returns a string containing a JSON description of the
* UI of the Faust object.
*/
const char* getJSONUI()
{
return fJSONUI.c_str();
}
/*
* getJSONMeta()
* Returns a string containing a JSON description of the
* metadata of the Faust object.
*/
const char* getJSONMeta()
{
return fJSONMeta.c_str();
}
/*
* buildUserInterface(ui)
* Calls the polyphonic of monophonic buildUserInterface with the ui parameter.
*/
void buildUserInterface(UI* ui_interface)
{
fFinalDSP->buildUserInterface(ui_interface);
}
/*
* getParamsCount()
* Returns the number of control parameters of the Faust object.
*/
int getParamsCount()
{
return fAPIUI.getParamsCount();
}
/*
* setParamValue(address, value)
* Sets the value of the parameter associated with address.
*/
void setParamValue(const char* address, float value)
{
int id = fAPIUI.getParamIndex(address);
if (id >= 0) {
fAPIUI.setParamValue(id, value);
// In POLY mode, update all voices
GUI::updateAllGuis();
}
}
/*
* getParamValue(address)
* Takes the address of a parameter and returns its current
* value.
*/
float getParamValue(const char* address)
{
int id = fAPIUI.getParamIndex(address);
return (id >= 0) ? fAPIUI.getParamValue(id) : 0.f;
}
/*
* setParamValue(id, value)
* Sets the value of the parameter associated with id.
*/
void setParamValue(int id, float value)
{
fAPIUI.setParamValue(id, value);
// In POLY mode, update all voices
GUI::updateAllGuis();
}
/*
* getParamValue(id)
* Takes the id of a parameter and returns its current
* value.
*/
float getParamValue(int id)
{
return fAPIUI.getParamValue(id);
}
/*
* setVoiceParamValue(address, voice, value)
* Sets the value of the parameter associated with address for
* the voice. setVoiceParamValue can only be
* used if the [style:poly] metadata is used in the Faust code.
*/
void setVoiceParamValue(const char* address, long voice, float value)
{
reinterpret_cast<MapUI*>(voice)->setParamValue(address, value);
}
/*
* setVoiceParamValue(id, voice, value)
* Sets the value of the parameter associated with the id for
* the voice. setVoiceParamValue can only be
* used if the [style:poly] metadata is used in the Faust code.
*/
void setVoiceParamValue(int id, long voice, float value)
{
reinterpret_cast<MapUI*>(voice)->setParamValue(reinterpret_cast<MapUI*>(voice)->getParamAddress(id), value);
}
/*
* getVoiceParamValue(address, voice)
* Gets the parameter value associated with address for the voice.
* getVoiceParamValue can only be used if the [style:poly] metadata
* is used in the Faust code.
*/
float getVoiceParamValue(const char* address, long voice)
{
return reinterpret_cast<MapUI*>(voice)->getParamValue(address);
}
/*
* getVoiceParamValue(id, voice)
* Gets the parameter value associated with the id for the voice.
* getVoiceParamValue can only be used if the [style:poly] metadata
* is used in the Faust code.
*/
float getVoiceParamValue(int id, long voice)
{
return reinterpret_cast<MapUI*>(voice)->getParamValue(reinterpret_cast<MapUI*>(voice)->getParamAddress(id));
}
/*
* getParamAddress(id)
* Returns the address of a parameter in function of its "id".
*/
const char* getParamAddress(int id)
{
return fAPIUI.getParamAddress(id);
}
/*
* getVoiceParamAddress(id, voice)
* Returns the address of a parameter for a specific voice
* in function of its "id".
*/
const char* getVoiceParamAddress(int id, long voice)
{
return reinterpret_cast<MapUI*>(voice)->getParamAddress(id).c_str();
}
/*
* propagateAcc(int acc, float v)
* Propage accelerometer value to the curve conversion layer.
*/
void propagateAcc(int acc, float v)
{
fAPIUI.propagateAcc(acc, v);
GUI::updateAllGuis();
}
/*
* setAccConverter(int p, int acc, int curve, float amin, float amid, float amax)
* Change accelerometer curve mapping.
*/
void setAccConverter(int p, int acc, int curve, float amin, float amid, float amax)
{
fAPIUI.setAccConverter(p, acc, curve, amin, amid, amax);
}
/*
* propagateGyr(int gyr, float v)
* Propage gyroscope value to the curve conversion layer.
*/
void propagateGyr(int gyr, float v)
{
fAPIUI.propagateGyr(gyr, v);
GUI::updateAllGuis();
}
/*
* setGyrConverter(int p, int acc, int curve, float amin, float amid, float amax)
* Change gyroscope curve mapping.
*/
void setGyrConverter(int p, int gyr, int curve, float amin, float amid, float amax)
{
fAPIUI.setGyrConverter(p, gyr, curve, amin, amid, amax);
}
/*
* getCPULoad()
* Return DSP CPU load.
*/
float getCPULoad() { return fDriver->get_cpu_load(); }
/*
* getScreenColor() -> c:int
* Get the requested screen color c :
* c < 0 : no screen color requested (keep regular UI)
* c >= 0 : requested color (no UI but a colored screen)
*/
int getScreenColor()
{
return fAPIUI.getScreenColor();
}
};
// Public C API
#ifdef __cplusplus
extern "C" {
#endif
void destroy(void* dsp) { delete reinterpret_cast<FaustPolyEngine*>(dsp); }
bool start(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->start(); }
void stop(void* dsp) { reinterpret_cast<FaustPolyEngine*>(dsp)->stop(); }
bool isRunning(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->isRunning(); }
long keyOn(void* dsp, int pitch, int velocity) { return (long)reinterpret_cast<FaustPolyEngine*>(dsp)->keyOn(pitch, velocity); }
int keyOff(void* dsp, int pitch) { return reinterpret_cast<FaustPolyEngine*>(dsp)->keyOff(pitch); }
void propagateMidi(void* dsp, int count, double time, int type, int channel, int data1, int data2)
{
reinterpret_cast<FaustPolyEngine*>(dsp)->propagateMidi(count, time, type, channel, data1, data2);
}
const char* getJSONUI(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getJSONUI(); }
const char* getJSONMeta(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getJSONMeta(); }
int getParamsCount(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getParamsCount(); }
void setParamValue(void* dsp, const char* address, float value) { reinterpret_cast<FaustPolyEngine*>(dsp)->setParamValue(address, value); }
float getParamValue(void* dsp, const char* address) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getParamValue(address); }
void setParamIdValue(void* dsp, int id, float value) { reinterpret_cast<FaustPolyEngine*>(dsp)->setParamValue(id, value); }
float getParamIdValue(void* dsp, int id) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getParamValue(id); }
void setVoiceParamValue(void* dsp, const char* address, long voice, float value)
{
reinterpret_cast<FaustPolyEngine*>(dsp)->setVoiceParamValue(address, voice, value);
}
float getVoiceParamValue(void* dsp, const char* address, long voice) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getVoiceParamValue(address, voice); }
const char* getParamAddress(void* dsp, int id) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getParamAddress(id); }
void propagateAcc(void* dsp, int acc, float v) { reinterpret_cast<FaustPolyEngine*>(dsp)->propagateAcc(acc, v); }
void setAccConverter(void* dsp, int p, int acc, int curve, float amin, float amid, float amax)
{
reinterpret_cast<FaustPolyEngine*>(dsp)->setAccConverter(p, acc, curve, amin, amid, amax);
}
void propagateGyr(void* dsp, int acc, float v) { reinterpret_cast<FaustPolyEngine*>(dsp)->propagateGyr(acc, v); }
void setGyrConverter(void* dsp, int p, int gyr, int curve, float amin, float amid, float amax)
{
reinterpret_cast<FaustPolyEngine*>(dsp)->setGyrConverter(p, gyr, curve, amin, amid, amax);
}
float getCPULoad(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getCPULoad(); }
int getScreenColor(void* dsp) { return reinterpret_cast<FaustPolyEngine*>(dsp)->getScreenColor(); }
#ifdef __cplusplus
}
#endif
#endif // __faust_poly_engine__
|