Skip to content

Commit

Permalink
ocpp ondemand plus new FIRs/IIRs
Browse files Browse the repository at this point in the history
  • Loading branch information
orlarey committed Jan 20, 2025
1 parent b6bd59f commit f20c15a
Show file tree
Hide file tree
Showing 82 changed files with 8,619 additions and 4,167 deletions.
2 changes: 1 addition & 1 deletion compiler/DirectedGraph/DirectedGraphAlgorythm.hh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Tarjan {
explicit Tarjan(const digraph<N>& g) : fGraph(g)
{
for (const auto& n : fGraph.nodes()) {
if (fAux.find(n) == fAux.end()) {
if (!fAux.contains(n)) {
visit(n);
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/DirectedGraph/Schedule.hh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ inline schedule<N> dfschedule(const digraph<N>& G)

// recursive deep first visit (pseudo local function using a lambda)
std::function<void(const N&)> dfvisit = [&](const N& n) {
if (V.find(n) == V.end()) {
if (!V.contains(n)) {
V.insert(n);
for (const auto& p : G.destinations(n)) {
dfvisit(p.first);
Expand Down
4 changes: 4 additions & 0 deletions compiler/boxes/boxcomplexity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ static int computeBoxComplexity(Tree box)
return BC(t1);
}

else if (isBoxOndemand(box, t1)) {
return 1 + BC(t1);
}

else if (isBoxRoute(box, t1, t2, t3)) {
return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions compiler/boxes/boxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@ LIBFAUST_API bool isBoxOutputs(Tree t, Tree& x)
return isTree(t, gGlobal->BOXOUTPUTS, x);
}

/*****************************************************************************
On Demand Boxes
*****************************************************************************/

Tree boxOndemand(Tree x)
{
return tree(gGlobal->BOXONDEMAND, x);
}

LIBFAUST_API bool isBoxOndemand(Tree t, Tree& x)
{
return isTree(t, gGlobal->BOXONDEMAND, x);
}

/*****************************************************************************
Lambda-Calculus of Boxes
*****************************************************************************/
Expand Down
7 changes: 7 additions & 0 deletions compiler/boxes/boxes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ Tree boxOutputs(Tree x);
LIBFAUST_API bool isBoxInputs(Tree t, Tree& x);
LIBFAUST_API bool isBoxOutputs(Tree t, Tree& x);

/*****************************************************************************
On Demand Boxes
*****************************************************************************/

Tree boxOndemand(Tree x);
LIBFAUST_API bool isBoxOndemand(Tree t, Tree& x);

/*****************************************************************************
Lambda-Calculus of Boxes
*****************************************************************************/
Expand Down
26 changes: 18 additions & 8 deletions compiler/boxes/boxtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ static bool inferBoxType(Tree box, int* inum, int* onum)
return false;
}

if ((v == 0) || (x == 0) || (x % v != 0)) {
if ((v == x) || ((v != 0) && (x % v == 0))) {
*inum = u;
*onum = y;
} else {
throw faustexception((computeTypeErrorMessage(a, b, v, x, "<:", "split composition",
" must be a divisor of ")));
}

*inum = u;
*onum = y;

} else if (isBoxMerge(box, a, b)) {
int u, v, x, y;
if (!getBoxType(a, &u, &v)) {
Expand All @@ -335,14 +335,14 @@ static bool inferBoxType(Tree box, int* inum, int* onum)
return false;
}

if ((v == 0) || (x == 0) || (v % x != 0)) {
if ((v == x) || ((x != 0) && (v % x == 0))) {
*inum = u;
*onum = y;
} else {
throw faustexception(computeTypeErrorMessage(a, b, v, x, ":>", "merge composition",
" must be a multiple of "));
}

*inum = u;
*onum = y;

} else if (isBoxRec(box, a, b)) {
int u, v, x, y;
if (!getBoxType(a, &u, &v)) {
Expand All @@ -367,6 +367,16 @@ static bool inferBoxType(Tree box, int* inum, int* onum)
} else if (isBoxRoute(box, ins, outs, lroutes)) {
return isBoxInt(ins, inum) && isBoxInt(outs, onum);

} else if (isBoxOndemand(box, a)) {
int u, v;
if (getBoxType(a, &u, &v)) {
*inum = u + 1;
*onum = v;
return true;
} else {
return false;
}

} else {
stringstream error;
error << "ERROR : boxType() internal error, unrecognized box expression : " << boxpp(box)
Expand Down
4 changes: 4 additions & 0 deletions compiler/boxes/ppbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ ostream& boxpp::print(ostream& fout) const
fout << "route(" << boxpp(ins) << "," << boxpp(outs) << "," << boxpp(lroutes) << ")";
}

else if (isBoxOndemand(fBox, body)) {
fout << "ondemand(" << boxpp(body) << ")";
}

else if (isBoxModulation(fBox, ident, body)) {
fout << "modulate(" << *(ident) << ").(" << boxpp(body) << ")";
}
Expand Down
7 changes: 6 additions & 1 deletion compiler/draw/drawschema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "names.hh"
#include "occur.hh"
#include "occurrences.hh"
#include "ondemandSchema.h"
#include "ppbox.hh"
#include "prim2.hh"
#include "property.hh"
Expand Down Expand Up @@ -236,7 +237,7 @@ static void writeSchemaFile(Tree bd)

char temp[1024];

gGlobal->gOccurrences = new Occur(bd);
// gGlobal->gOccurrences = new Occur(bd);
getBoxType(bd, &ins, &outs);

bool hasname = getDefNameProperty(bd, id);
Expand Down Expand Up @@ -528,6 +529,10 @@ static schema* generateInsideSchema(Tree t)
<< ", invalid route expression : " << boxpp(t) << endl;
throw faustexception(error.str());
}

} else if (isBoxOndemand(t, a)) {
return makeOndemandSchema(generateDiagramSchema(a));

} else {
stringstream error;
error << "ERROR in generateInsideSchema, box expression not recognized : ";
Expand Down
14 changes: 7 additions & 7 deletions compiler/draw/schema/mergeSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ void mergeSchema::collectTraits(collector& c)
fSchema2->collectTraits(c);

unsigned int r = fSchema2->inputs();
faustassert(r > 0);

// draw the connections between them
for (unsigned int i = 0; i < fSchema1->outputs(); i++) {
point p = fSchema1->outputPoint(i);
point q = fSchema2->inputPoint(i % r);
c.addTrait(trait(p, q));
if (r > 0) {
// draw the connections between them
for (unsigned int i = 0; i < fSchema1->outputs(); i++) {
point p = fSchema1->outputPoint(i);
point q = fSchema2->inputPoint(i % r);
c.addTrait(trait(p, q));
}
}
}
204 changes: 204 additions & 0 deletions compiler/draw/schema/ondemandSchema.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/************************************************************************
************************************************************************
FAUST compiler
Copyright (C) 2003-2018 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program 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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
************************************************************************
************************************************************************/

#include <iostream>

#include "exception.hh"
#include "ondemandSchema.h"

using namespace std;

const double ondemandSchema::fTopMargin(30); // gap between the top and the top of the inside schema
const double ondemandSchema::fHorMargin(10); // left and right gap
const double ondemandSchema::fBotMargin(10); // gap between the bottom and the bottom of the inside schema
const double ondemandSchema::fMinWidth(50); // Minimal width of an ondemand block
const string ondemandSchema::fText("ondemand"); // Test to display, tipically "ondemand"

/**
* Returns an enlarged schema, but only if really needed
* that is if the required width is greater that the schema width.
*/
schema* makeOndemandSchema(schema* s)
{
return new ondemandSchema(s);
}

/**
* Put additional space left and right of a schema so that the result has
* a certain width. The wires are prolonged accordingly.
*/
ondemandSchema::ondemandSchema(schema* s)
: schema(s->inputs() + 1, s->outputs(), max(fMinWidth, s->width() + 2 * fHorMargin), s->height() + fTopMargin + fBotMargin), fSchema(s)
{
for (unsigned int i = 0; i < inputs(); i++) fInputPoint.push_back(point(0, 0));
for (unsigned int i = 0; i < outputs(); i++) fOutputPoint.push_back(point(0, 0));
}

/**
* Define the graphic position of the schema. Computes the graphic
* position of all the elements, in particular the inputs and outputs.
* This method must be called before draw(), otherwise draw is not allowed
*/
void ondemandSchema::place(double ox, double oy, int orientation)
{
double hmargin = (width() - fSchema->width()) / 2;

if (orientation == kLeftRight) {
beginPlace(ox, oy, orientation);

fSchema->place(ox + hmargin, oy + fTopMargin, orientation);

fInputPoint[0] = point(ox + fHorMargin / 2, oy + 2 * fTopMargin / 3); // this is the clock entry
for (unsigned int i = 1; i < inputs(); i++) {
point p = fSchema->inputPoint(i - 1);
fInputPoint[i] = point(ox + fHorMargin / 2, p.y);
}

for (unsigned int i = 0; i < outputs(); i++) {
point p = fSchema->outputPoint(i);
fOutputPoint[i] = point(ox + width() + fHorMargin / 2, p.y);
}

endPlace();

} else {
beginPlace(ox, oy, orientation);
fSchema->place(ox + hmargin, oy + fBotMargin, orientation);

fInputPoint[0] = point(ox + width() - fHorMargin / 2, oy + height() - 2 * fTopMargin / 3);
for (unsigned int i = 1; i < inputs(); i++) {
point p = fSchema->inputPoint(i - 1);
fInputPoint[i] = point(ox + width() - fHorMargin / 2, p.y);
}
for (unsigned int i = 0; i < outputs(); i++) {
point p = fSchema->outputPoint(i);
fOutputPoint[i] = point(ox, p.y);
}
endPlace();
}
}

/**
* Returns an input point
*/
point ondemandSchema::inputPoint(unsigned int i) const
{
faustassert(placed());
faustassert(i < inputs());
return fInputPoint[i];
}

/**
* Returns an output point
*/
point ondemandSchema::outputPoint(unsigned int i) const
{
faustassert(placed());
faustassert(i < outputs());
return fOutputPoint[i];
}

/**
* Draw the enlarged schema. This methods can only
* be called after the block have been placed
*/
void ondemandSchema::draw(device& dev)
{
faustassert(placed());

fSchema->draw(dev);

// define the coordinates of the frame
double tw = (2 + fText.size()) * dLetter;
double x0 = x() + fHorMargin / 2; // left
double y0 = y() + fHorMargin / 2; // top
double x1 = x() + width() - fHorMargin / 2; // right
double y1 = y() + height() - fHorMargin / 2; // bottom
// double tl = x0 + 2*dWire; // left of text zone
// double tl = x() + fHorMargin; // left of text zone
// double tr = min(tl + tw, x1); // right of text zone

// draw the surronding frame
dev.trait(x0, y0, x0, y1); // left line
dev.trait(x0, y1, x1, y1); // bottom line
dev.trait(x1, y1, x1, y0); // right line
dev.trait(x0, y0, x1, y0); // top segment

// draw orientation mark
if (orientation() == kLeftRight) {
dev.markSens(x0, y0, orientation());
} else {
dev.markSens(x1, y1, orientation());
}

// draw clock arrow
double dx = (orientation() == kLeftRight) ? dHorz : -dHorz;
// for (unsigned int i = 0; i < inputs(); i++) {
point p = fInputPoint[0];
dev.fleche(p.x, p.y, 0, orientation());
//}

// draw the ondemand label
// dev.label(tl, y0, fText.c_str()); //
// draw text
if (orientation() == kLeftRight) {
dev.label(x0 + (width() - tw) / 2, y0 + 5, "ondemand");
} else {
dev.label(x0 + (width() - tw) / 2, y1 - 5, "ondemand");
}

// draw clock label
point p0 = fInputPoint[0];
// dev.label(p0.x - 32 - dx, p0.y, "run"); //
if (orientation() == kLeftRight) {
dev.label(p0.x + 2, p0.y, "run"); //
} else {
dev.label(p0.x - 16 - dx, p0.y, "run"); //
}
}

/**
* Draw the enlarged schema. This methos can only
* be called after the block have been placed
*/
void ondemandSchema::collectTraits(collector& c)
{
faustassert(placed());

fSchema->collectTraits(c);

c.addInput(inputPoint(0));
// draw enlarge input wires
for (unsigned int i = 1; i < inputs(); i++) {
point p = inputPoint(i);
point q = fSchema->inputPoint(i - 1);
c.addInput(q);
c.addTrait(trait(p, q)); // in->out direction
}

// draw enlarge output wires
for (unsigned int i = 0; i < outputs(); i++) {
point q = fSchema->outputPoint(i);
point p = outputPoint(i);
c.addOutput(q);
c.addTrait(trait(q, p)); // in->out direction
}
}
Loading

0 comments on commit f20c15a

Please sign in to comment.