Skip to content

Commit

Permalink
Correctly pass variables into abstractions
Browse files Browse the repository at this point in the history
Correctly identify when a subgraph is being made versus when an
abstraction is being added. Correctly handle/interpret graph arguments
in these two cases.
  • Loading branch information
mhroth committed Aug 9, 2012
1 parent 0277503 commit 16f1237
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/PdFileParser.cpp
Expand Up @@ -118,10 +118,10 @@ PdGraph *PdFileParser::execute(PdContext *context) {
return NULL;
}
*/
return execute(NULL, NULL, context);
return execute(NULL, NULL, context, true);
}

PdGraph *PdFileParser::execute(PdMessage *initMsg, PdGraph *graph, PdContext *context) {
PdGraph *PdFileParser::execute(PdMessage *initMsg, PdGraph *graph, PdContext *context, bool isSubPatch) {
#define OBJECT_LABEL_RESOLUTION_BUFFER_LENGTH 32
#define RESOLUTION_BUFFER_LENGTH 512
#define INIT_MESSAGE_MAX_ELEMENTS 32
Expand Down Expand Up @@ -150,7 +150,12 @@ PdGraph *PdFileParser::execute(PdMessage *initMsg, PdGraph *graph, PdContext *co
newGraph->addDeclarePath(rootPath.c_str());
}
} else {
newGraph = new PdGraph(graph->getArguments(), graph, context, graph->getGraphId());
if (isSubPatch) {
newGraph = new PdGraph(graph->getArguments(), graph, context, graph->getGraphId());
} else {
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 Expand Up @@ -199,7 +204,7 @@ PdGraph *PdFileParser::execute(PdMessage *initMsg, PdGraph *graph, PdContext *co
}
}
PdFileParser *parser = new PdFileParser(directory, filename);
messageObject = parser->execute(initMessage, graph, context);
messageObject = parser->execute(initMessage, graph, context, false);
// set graph name according to abstraction. useful for debugging.
reinterpret_cast<PdGraph *>(messageObject)->setName(objectLabel);
delete parser;
Expand Down
2 changes: 1 addition & 1 deletion src/PdFileParser.h
Expand Up @@ -50,7 +50,7 @@ class PdFileParser {
PdGraph *execute(PdContext *context);

private:
PdGraph *execute(PdMessage *initMsg, PdGraph *graph, PdContext *context);
PdGraph *execute(PdMessage *initMsg, PdGraph *graph, PdContext *context, bool isSubPatch);

/**
* Returns the next logical message in the file, or <code>NULL</code> if the end of the file
Expand Down
12 changes: 9 additions & 3 deletions src/PdMessage.cpp
Expand Up @@ -89,14 +89,14 @@ void PdMessage::resolveString(char *initString, PdMessage *arguments, unsigned i
default: continue;
}
argumentIndex -= offset;
if (argumentIndex >= 0 && argumentIndex < numArguments) {
if (argumentIndex >= 0 && argumentIndex < numArguments) { // bounds check
switch (arguments->getType(argumentIndex)) {
case FLOAT: {
numCharsWritten = snprintf(buffer + bufferPos, bufferLength - bufferPos,
"%g", arguments->getFloat(argumentIndex));
bufferPos += numCharsWritten;
if (bufferPos >= bufferLength-1) {
printf("WTF: %s", buffer);
printf("WTF: %s\n", buffer);
}
break;
}
Expand All @@ -105,12 +105,18 @@ void PdMessage::resolveString(char *initString, PdMessage *arguments, unsigned i
"%s", arguments->getSymbol(argumentIndex));
bufferPos += numCharsWritten;
if (bufferPos >= bufferLength-1) {
printf("WTF: %s", buffer);
printf("WTF: %s\n", buffer);
}
break;
}
default: break;
}
} else {
// index is out of bounds. Something has gone terribly wrong.
// just write a zero. That's what pd seems to do?
numCharsWritten = snprintf(buffer + bufferPos, bufferLength - bufferPos, "0");
bufferPos += numCharsWritten;
printf("$var is out of bounds. WTF are you doing?\n");
}
}

Expand Down

0 comments on commit 16f1237

Please sign in to comment.