Skip to content

Commit

Permalink
Merge pull request #44 from Kyew/master
Browse files Browse the repository at this point in the history
Patch name are now registered when parsing a patch
  • Loading branch information
mhroth committed Oct 23, 2014
2 parents bdc76ee + f694ff6 commit 6b6e407
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/PdFileParser.cpp
Expand Up @@ -125,23 +125,29 @@ PdGraph *PdFileParser::execute(PdMessage *initMsg, PdGraph *graph, PdContext *co
if (!strcmp(hashType, "#N")) {
char *objectType = strtok(NULL, " ");
if (!strcmp(objectType, "canvas")) {
int canvasX = atoi(strtok(NULL, " "));
int canvasY = atoi(strtok(NULL, " "));
int canvasW = atoi(strtok(NULL, " "));
int canvasH = atoi(strtok(NULL, " "));
const char *canvasName = strtok(NULL, " ");

// A new graph is defined inline. No arguments are passed (from this line)
// the graphId is not incremented as this is a subpatch, not an abstraction
// NOTE(mhroth): pixel location is not recorded
PdGraph *newGraph = NULL;
if (graph == NULL) { // if no parent graph exists
initMessage->initWithTimestampAndNumElements(0.0, 0); // make a dummy initMessage
newGraph = new PdGraph(initMessage, NULL, context, context->getNextGraphId());
newGraph = new PdGraph(initMessage, NULL, context, context->getNextGraphId(), "root");
if (!rootPath.empty()) {
// inform the root graph of where it is in the file system, if this information exists.
// This will allow abstractions to be correctly loaded.
newGraph->addDeclarePath(rootPath.c_str());
}
} else {
if (isSubPatch) {
newGraph = new PdGraph(graph->getArguments(), graph, context, graph->getGraphId());
newGraph = new PdGraph(graph->getArguments(), graph, context, graph->getGraphId(), canvasName);
} else {
newGraph = new PdGraph(initMsg, graph, context, context->getNextGraphId());
newGraph = new PdGraph(initMsg, graph, context, context->getNextGraphId(), "???");
isSubPatch = true;
}
graph->addObject(0, 0, newGraph); // add the new graph to the current one as an object
Expand Down
3 changes: 2 additions & 1 deletion src/PdGraph.cpp
Expand Up @@ -40,7 +40,7 @@

// a PdGraph begins with zero inlets and zero outlets. These will be added as inlet/~ and outlet/~
// objects are added to the graph
PdGraph::PdGraph(PdMessage *initMessage, PdGraph *parentGraph, PdContext *context, int graphId) :
PdGraph::PdGraph(PdMessage *initMessage, PdGraph *parentGraph, PdContext *context, int graphId, const char *graphName) :
DspObject(0, 0, 0, 0, (parentGraph == NULL) ? context->getBlockSize() : parentGraph->getBlockSize(), parentGraph) {
this->parentGraph = parentGraph; // == NULL if this is a root graph
this->context = context;
Expand All @@ -62,6 +62,7 @@ PdGraph::PdGraph(PdMessage *initMessage, PdGraph *parentGraph, PdContext *contex
graphArguments->setFloat(0, (float) graphId); // $0
memcpy(graphArguments->getElement(1), initMessage->getElement(0), numInitElements * sizeof(MessageAtom));
graphArguments = graphArguments->copyToHeap();
name = graphName;
}

PdGraph::~PdGraph() {
Expand Down
2 changes: 1 addition & 1 deletion src/PdGraph.h
Expand Up @@ -45,7 +45,7 @@ class PdGraph : public DspObject {

public:
/** Instantiate an empty graph. */
PdGraph(PdMessage *initMessage, PdGraph *graph, PdContext *context, int graphId);
PdGraph(PdMessage *initMessage, PdGraph *graph, PdContext *context, int graphId, const char *graphName);
~PdGraph();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/ZenGarden.cpp
Expand Up @@ -152,7 +152,7 @@ ZGGraph *zg_context_new_empty_graph(PdContext *context) {
PdMessage *initMessage = PD_MESSAGE_ON_STACK(0); // create an empty message to use for initialisation
initMessage->initWithTimestampAndNumElements(0.0, 0);
// the new graph has no parent graph and is created in the given context with a unique id
PdGraph *graph = new PdGraph(initMessage, NULL, context, context->getNextGraphId());
PdGraph *graph = new PdGraph(initMessage, NULL, context, context->getNextGraphId(), "root");
return graph;
}

Expand Down

0 comments on commit 6b6e407

Please sign in to comment.